[Insight-users] node.push_back(FEMP<Node>(n))

du Bois d Aische Aloys duboisda at bwh . harvard . edu
Wed, 25 Jun 2003 18:35:31 +0200


 Hi,

      I have a memory problem with node.push_back(FEMP<Node>(n)). I create a regular hexahedron mesh. Then I try to create inside this mesh new nodes. After the 256th node placed in the solver by a push_back, I have some problems: the Gn values of the nodes of the initial mesh become crazy.
Has someone an idea about this problem? I let some code if it could help. 
   thanks

         aloys




   // Clear existing elements and nodes in Solver
    solver->el.clear();
    solver->node.clear();

    // Number of nodes in each dimension
    VectorType Nel(SpaceDimension);
    for (int i=0; i<SpaceDimension; i++)
      Nel[i]=floor((m_MeshBB2[i] - m_MeshBB1[i])
		   / m_NumberOfPixelsPerElement[i]);
    
    double Ni=static_cast<double>(Nel[0]);
    double Nj=static_cast<double>(Nel[1]);
    double Nk=static_cast<double>(Nel[2]);

    // Create nodes
    fem::Node::Pointer n;
    gnnode=0; // number of node
    double xx,yy,zz;
    for(double k=0; k<=Nk; k++)
      for(double j=0; j<=Nj; j++)
	for(double i=0; i<=Ni; i++)
	  {
	    xx=m_MeshBB1[0]+i*m_MeshBB2[0] / Nel[0];
	    yy=m_MeshBB1[1]+j*m_MeshBB2[1] / Nel[1];
	    zz=m_MeshBB1[2]+k*m_MeshBB2[2] / Nel[2];
	    n=new fem::Node(xx,yy,zz);
	    n->GN=gnnode;
	    gnnode++;
	    solver->node.push_back(fem::FEMP<fem::Node>(n));
	  }
    
    
    // Create elements  
    gn=0; // global number of the element
    fem::Element3DC0LinearHexahedron::Pointer e;
    for(unsigned int k=0; k<Nk; k++)
      for(unsigned int j=0; j<Nj; j++)
	for(unsigned int i=0; i<Ni; i++)
	  {
	    //Take the n0 coordinates, then
	    //check the label at this point
	    VectorType coord(SpaceDimension);
	    coord[0]=m_MeshBB1[0]+i*m_MeshBB2[0] / Nel[0];
	    coord[1]=m_MeshBB1[1]+j*m_MeshBB2[1] / Nel[1];
	    coord[2]=m_MeshBB1[2]+k*m_MeshBB2[2] / Nel[2];
	    fem::Element::Pointer e0;
	    e0 = GetStandardElementAtPoint(coord);

	    e=dynamic_cast<fem::Element3DC0LinearHexahedron*>(e0->Clone());
	    
	    e->SetNode(0,solver->node.Find((unsigned int) (i+  (Ni+1)*(j  +(Nj+1)*k) )));
	    e->SetNode(1,solver->node.Find((unsigned int) (i+1+(Ni+1)*(j  +(Nj+1)*k) )));
	    e->SetNode(2,solver->node.Find((unsigned int) (i+1+(Ni+1)*(j+1+(Nj+1)*k) )));
	    e->SetNode(3,solver->node.Find((unsigned int) (i+  (Ni+1)*(j+1+(Nj+1)*k) )));
	    e->SetNode(4,solver->node.Find((unsigned int) (i+  (Ni+1)*(j  +(Nj+1)*(k+1)) )));
	    e->SetNode(5,solver->node.Find((unsigned int) (i+1+(Ni+1)*(j  +(Nj+1)*(k+1)) )));
	    e->SetNode(6,solver->node.Find((unsigned int) (i+1+(Ni+1)*(j+1+(Nj+1)*(k+1)) )));
	    e->SetNode(7,solver->node.Find((unsigned int) (i+  (Ni+1)*(j+1+(Nj+1)*(k+1)) )));
	    
	    e->GN=gn;
	    gn++;
	    solver->el.push_back(fem::FEMP<fem::Element>(e));

	  }

    for(fem::Element::ArrayType::iterator e = solver->el.begin(); e!= solver->el.end(); e++)
 	{   
	    double distx = ((*e)->GetNode(1)->GetCoordinates()[0]-(*e)->GetNode(0)->GetCoordinates()[0])/3;
	    double disty = ((*e)->GetNode(3)->GetCoordinates()[1]-(*e)->GetNode(0)->GetCoordinates()[1])/3;
	    double distz = ((*e)->GetNode(4)->GetCoordinates()[2]-(*e)->GetNode(0)->GetCoordinates()[2])/3;	

		fem::Node::Pointer n0;
		for (int sousdivz = 0; sousdivz < 4; sousdivz++)
		  for (int sousdivy = 0; sousdivy < 4; sousdivy++)
		    for (int sousdivx = 0; sousdivx < 4; sousdivx++) 
		      {
			//node coordinates:
			xx = (*e)->GetNode(0)->GetCoordinates()[0] + sousdivx * distx;
			yy = (*e)->GetNode(0)->GetCoordinates()[1] + sousdivy * disty;
			zz = (*e)->GetNode(0)->GetCoordinates()[2] + sousdivz * distz;
		
			if (nonexistingnode)
			  {
			    n0 = new fem::Node(xx,yy,zz);
			    n0->GN=gnnode;
			    gnnode++;
			    solver->node.push_back(fem::FEMP<fem::Node>(n0)); //problem after the 256th node
			  }
		      }
	}	
}