Esempio n. 1
0
void test_empty()
{
	IntVec v;
	CYBOZU_TEST_EQUAL((int)v.size(), 0);
	CYBOZU_TEST_ASSERT(v.empty());
	for (typename IntVec::const_iterator i = v.begin(); i != v.end(); ++i) {
		printf("%d\n", i->val());
	}
	v.push_back(3, 1);
	CYBOZU_TEST_EQUAL((int)v.size(), 1);
	CYBOZU_TEST_ASSERT(!v.empty());
	for (typename IntVec::const_iterator i = v.begin(); i != v.end(); ++i) {
		CYBOZU_TEST_EQUAL(i->pos(), (size_t)3);
		CYBOZU_TEST_EQUAL(i->val(), 1);
	}
	v.push_back(4, 2);
	CYBOZU_TEST_EQUAL((int)v.size(), 2);
	int j = 0;
	for (typename IntVec::const_iterator i = v.begin(); i != v.end(); ++i) {
		CYBOZU_TEST_EQUAL(i->pos(), size_t(j + 3));
		CYBOZU_TEST_EQUAL(i->val(), j + 1);
		j++;
	}
	v.clear();
	CYBOZU_TEST_EQUAL((int)v.size(), 0);
	CYBOZU_TEST_ASSERT(v.empty());
	IntVec v1, v2;
	for (int i = 0; i < 3; i++) {
		v1.push_back(i, i);
		v2.push_back(i, i);
	}
	CYBOZU_TEST_ASSERT(v1 == v2);
	v2.push_back(10, 10);
	CYBOZU_TEST_ASSERT(v1 != v2);
}
Esempio n. 2
0
bool SIMoutput::dumpVector (const Vector& vsol, const char* fname,
                            utl::LogStream& os, std::streamsize precision) const
{
  if (vsol.empty() || myPoints.empty())
    return true;

  size_t i, j, k;
  Matrix sol1;
  Vector lsol;

  for (i = 0; i < myModel.size(); i++)
  {
    if (myModel[i]->empty()) continue; // skip empty patches

    std::vector<ResPtPair>::const_iterator pit;
    ResPointVec::const_iterator p;
    std::array<RealArray,3> params;
    IntVec points;

    // Find all evaluation points within this patch, if any
    for (j = 0, pit = myPoints.begin(); pit != myPoints.end(); ++pit)
      for (p = pit->second.begin(); p != pit->second.end(); j++, ++p)
        if (this->getLocalPatchIndex(p->patch) == (int)(i+1))
          if (opt.discretization >= ASM::Spline)
          {
            points.push_back(p->inod > 0 ? p->inod : -(j+1));
            for (k = 0; k < myModel[i]->getNoParamDim(); k++)
              params[k].push_back(p->u[k]);
          }
          else if (p->inod > 0)
            points.push_back(p->inod);

    if (points.empty()) continue; // no points in this patch

    // Evaluate/extracto nodal solution variables
    myModel[i]->extractNodeVec(vsol,lsol);
    if (opt.discretization >= ASM::Spline)
    {
      if (!myModel[i]->evalSolution(sol1,lsol,params.data(),false))
        return false;
    }
    else
    {
      if (!myModel[i]->getSolution(sol1,lsol,points))
        return false;
    }

    // Formatted output, use scientific notation with fixed field width
    std::streamsize flWidth = 8 + precision;
    std::streamsize oldPrec = os.precision(precision);
    std::ios::fmtflags oldF = os.flags(std::ios::scientific | std::ios::right);
    for (j = 0; j < points.size(); j++)
    {
      if (points[j] < 0)
        os <<"  Point #"<< -points[j];
      else
      {
        points[j] = myModel[i]->getNodeID(points[j]);
        os <<"  Node #"<< points[j];
      }

      os <<":\t"<< fname <<" =";
      for (k = 1; k <= sol1.rows(); k++)
        os << std::setw(flWidth) << utl::trunc(sol1(k,j+1));

      os << std::endl;
    }
    os.precision(oldPrec);
    os.flags(oldF);
  }

  return true;
}
Esempio n. 3
0
bool SIMoutput::dumpResults (const Vector& psol, double time,
                             utl::LogStream& os, const ResPointVec& gPoints,
                             bool formatted, std::streamsize precision) const
{
  if (gPoints.empty())
    return true;

  size_t i, j, k;
  Matrix sol1, sol2;
  Vector reactionFS;
  const Vector* reactionForces = myEqSys->getReactions();

  for (i = 0; i < myModel.size(); i++)
  {
    if (myModel[i]->empty()) continue; // skip empty patches

    ResPointVec::const_iterator p;
    std::array<RealArray,3> params;
    IntVec points;

    // Find all evaluation points within this patch, if any
    for (j = 0, p = gPoints.begin(); p != gPoints.end(); j++, p++)
      if (this->getLocalPatchIndex(p->patch) == (int)(i+1))
        if (opt.discretization >= ASM::Spline)
        {
          points.push_back(p->inod > 0 ? p->inod : -(j+1));
          for (k = 0; k < myModel[i]->getNoParamDim(); k++)
            params[k].push_back(p->u[k]);
        }
        else if (p->inod > 0)
          points.push_back(p->inod);

    if (points.empty()) continue; // no points in this patch

    myModel[i]->extractNodeVec(psol,myProblem->getSolution());
    if (opt.discretization >= ASM::Spline)
    {
      // Evaluate the primary solution variables
      if (!myModel[i]->evalSolution(sol1,myProblem->getSolution(),
                                    params.data(),false))
        return false;

      // Evaluate the secondary solution variables
      LocalSystem::patch = i;
      if (myProblem->getNoFields(2) > 0)
      {
        const_cast<SIMoutput*>(this)->setPatchMaterial(i+1);
        if (!myModel[i]->evalSolution(sol2,*myProblem,params.data(),false))
          return false;
      }
    }
    else
      // Extract nodal primary solution variables
      if (!myModel[i]->getSolution(sol1,myProblem->getSolution(),points))
        return false;

    // Formatted output, use scientific notation with fixed field width
    std::streamsize flWidth = 8 + precision;
    std::streamsize oldPrec = os.precision(precision);
    std::ios::fmtflags oldF = os.flags(std::ios::scientific | std::ios::right);
    for (j = 0; j < points.size(); j++)
    {
      if (!formatted)
        os << time <<" ";
      else if (points[j] < 0)
        os <<"  Point #"<< -points[j] <<":\tsol1 =";
      else
      {
        points[j] = myModel[i]->getNodeID(points[j]);
        os <<"  Node #"<< points[j] <<":\tsol1 =";
      }

      for (k = 1; k <= sol1.rows(); k++)
        os << std::setw(flWidth) << utl::trunc(sol1(k,j+1));

      if (opt.discretization >= ASM::Spline)
      {
        if (formatted && sol2.rows() > 0)
          os <<"\n\t\tsol2 =";
        for (k = 1; k <= sol2.rows(); k++)
          os << std::setw(flWidth) << utl::trunc(sol2(k,j+1));
      }

      if (reactionForces && points[j] > 0)
        // Print nodal reaction forces for nodes with prescribed DOFs
        if (mySam->getNodalReactions(points[j],*reactionForces,reactionFS))
        {
          if (formatted)
            os <<"\n\t\treac =";
          for (k = 0; k < reactionFS.size(); k++)
            os << std::setw(flWidth) << utl::trunc(reactionFS[k]);
        }

      os << std::endl;
    }
    os.precision(oldPrec);
    os.flags(oldF);
  }

  return true;
}