"Problem on a third party library using within YADE"

Asked by burak er

Dear Yade-Dev,

I try to use libgmsh with YADE but having different behavior with the same lines of code which work very well when compiled without YADE.

Did you ever have this kind of behavior? What should I do to overcome this different behavior?

Thank you in advance.

Burak

Question information

Language:
English Edit question
Status:
Answered
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Anton Gladky (gladky-anton) said :
#1

Hi,
13/12/1 burak er <email address hidden>

> I try to use libgmsh with YADE but having different behavior with the same
> lines of code which work very well when compiled without YADE.
> <https://help.launchpad.net/ListHelp>

Could you, please, be more specific?

Thanks,

Anton

Revision history for this message
burak er (burak-er) said :
#2

Hi Anton,

I created a class[1] which I use to import mesh file than create elements using gmsh by its releated structure GModel. When I use this class gmshModel variable does not load mesh file(without giving error). If I compile the same lines [2] without yade the mesh loading goes very well.

[1]class GMshMesh:public Serializable{

public:
 shared_ptr<GModel> gmshModel;
 void initfunc(void){
  gmshModel=shared_ptr<GModel>(new GModel);
 }

 void LoadMesh(std::string filename)
 {

  boost::filesystem::path mypath(filename);

     if(mypath.extension()!=boost::filesystem::path(".msh")){
     std::string errormessage ="A .msh file must be specified for the input";
     throw std::invalid_argument(errormessage);
  }
  else
  {

    std::cout<<"model is created "<<std::endl;
    gmshModel->readMSH("/home/burak/boxcly.msh");
    std::cout<<"model is read "<<std::endl;
    gmshModel->getMeshStatus();
    // Create domain
    elems.clear();// clear our vector
    std::cout<<"elements are cleared "<<std::endl;

    interfacingpairs.clear();
    std::cout<<"interfacing pairs are cleared "<<std::endl;

    size_t numberofelements=gmshModel->getNumMeshElements();//get number of mesh elements
    std::cout<<"getting number of elements as"<<numberofelements<<std::endl;

    elems.resize(numberofelements); // resize it as the new number of elements

    std::cout<<"resizing elements "<<std::endl;

    for(size_t iter=0;iter<numberofelements;iter++){

     //We can check element type here if required but for now we assume it to be tetrahedral element
     //if(Ng_GetElementType(iter)==NG_ELEMENT_TYPE.NG_TET)
     {std::cout<<"getting element "<< iter<<std::endl;
      int vertindex[4];
      MElement* element=gmshModel->getMeshElementByTag(iter);

      std::vector<MVertex*> vertices;
      element->getVertices(vertices);

      //Create new elements
      Vector3r vertex0;
         vertex0<<vertices[0]->x(),vertices[0]->y(),vertices[0]->z();

         Vector3r vertex1;
        vertex1<<vertices[1]->x(),vertices[1]->y(),vertices[1]->z();

        Vector3r vertex2;
        vertex2<<vertices[2]->x(),vertices[2]->y(),vertices[2]->z();

        Vector3r vertex3;
        vertex3<<vertices[3]->x(),vertices[3]->y(),vertices[3]->z();

     //share_ptr handles deletion of the newly created element
         elems[iter]=shared_ptr<MeshElement>(new Linear4NodeTetMeshElem(vertex0,vertex1,vertex2,vertex3));

     }
    }
}
}
public:
 YADE_CLASS_BASE_DOC_ATTRS_INIT_CTOR_PY(GMshMesh,Serializable,"An interfacing pair",
     ,
   initfunc();
    ,

   /* ctor */,
   /* py */
   .def("doMeshing",&GMshMesh::LoadMesh,"Does meshing")
   .def("getElements",&GMshMesh::getElements,"Return a reference to element object")
   .def("getPairs",&GMshMesh::getPairs,"Return a reference to element object")

  );
private:
 MeshElementContainer elems;//Mesh Elements
 ElementPairContainer interfacingpairs;//Interacing pairs

};
REGISTER_SERIALIZABLE(GMshMesh);

[2]#include <iostream>
#include<set>
#include<boost/shared_ptr.hpp>

int main(void)
{

boost::shared_ptr<GModel> gmshModel=boost::shared_ptr<GModel>(new GModel());
   std::cout<<"model is created "<<std::endl;
   gmshModel->readMSH("/home/burak/boxcly.msh");
   std::cout<<"model is read "<<std::endl;
   gmshModel->getMeshStatus();
   // Create domain

 size_t numberofelements=gmshModel->getMaxElementNumber();//get number of mesh elements
        std::cout<<numberofelements;
        return 0;
}

Revision history for this message
Anton Gladky (gladky-anton) said :
#3

> When I use this class gmshModel variable does not load mesh file(without giving error).
> If I compile the same lines [2] without yade the mesh loading goes very well.

Well, difficult to say, what is wrong here. Try to set "checkpoints" to define, where
it stops. Maybe, you will find the problem.

Are you sure, your code is compiled during Yade compilation?

> gmshModel->readMSH("/home/burak/boxcly.msh");

Why do you use absolute path?

Anton

Can you help with this problem?

Provide an answer of your own, or ask burak er for more information if necessary.

To post a message you must log in.