Back to index

salome-med  6.5.0
Public Member Functions | Private Attributes
MEDPARTITIONER::MeshCollectionMedXmlDriver Class Reference

#include <MEDPARTITIONER_MeshCollectionMedXmlDriver.hxx>

Collaboration diagram for MEDPARTITIONER::MeshCollectionMedXmlDriver:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 MeshCollectionMedXmlDriver (MeshCollection *)
virtual ~MeshCollectionMedXmlDriver ()
int read (const char *, ParaDomainSelector *sel=0)
 reads a MED File Xml Master File v>=2.3 and mounts the corresponding meshes in memory the connect zones are created from the joints
void write (const char *, ParaDomainSelector *sel=0) const
 writes the collection of meshes in a MED v2.3 Xml file with the connect zones being written as joints

Private Attributes

std::string _master_filename

Detailed Description

Definition at line 28 of file MEDPARTITIONER_MeshCollectionMedXmlDriver.hxx.


Constructor & Destructor Documentation

Definition at line 66 of file MEDPARTITIONER_MeshCollectionMedXmlDriver.cxx.

                                                                                :MeshCollectionDriver(collection)
{
}

Definition at line 32 of file MEDPARTITIONER_MeshCollectionMedXmlDriver.hxx.

{ }

Member Function Documentation

int MeshCollectionMedXmlDriver::read ( const char *  filename,
ParaDomainSelector *  domainSelector = 0 
)

reads a MED File Xml Master File v>=2.3 and mounts the corresponding meshes in memory the connect zones are created from the joints

Parameters:
filenameXml file containing the list of MED v2.3 files

Definition at line 77 of file MEDPARTITIONER_MeshCollectionMedXmlDriver.cxx.

{
  //distributed meshes
  int nbdomain;
  _master_filename=filename;

  //reading ascii master file
  try
    {
      //Setting up the Xml tree corresponding to filename
      xmlDocPtr master_doc=xmlParseFile(filename);

      if (!master_doc)
        throw INTERP_KERNEL::Exception("Xml Master File does not exist or is not compliant with Xml scheme");

      //number of domains
      xmlXPathContextPtr xpathCtx = xmlXPathNewContext(master_doc);
      xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression(BAD_CAST "//splitting/subdomain", xpathCtx);
      if (xpathObj==0 || xpathObj->nodesetval->nodeNr ==0)
        throw INTERP_KERNEL::Exception("Xml Master File does not contain /MED/splitting/subdomain node");

      //as subdomain has only one property which is "number"
      //it suffices to take the content of its first child 
      const char* mystring = (const char*)xpathObj->nodesetval->nodeTab[0]->properties->children->content;
      sscanf(mystring, "%d", &nbdomain);

      //mesh name
      xmlXPathFreeObject(xpathObj);
      xpathObj = xmlXPathEvalExpression(BAD_CAST "//content/mesh", xpathCtx);
      if (xpathObj==0 || xpathObj->nodesetval->nodeNr ==0)
        throw INTERP_KERNEL::Exception("Xml Master File does not contain /MED/content/mesh node");
      _collection->setName( (const char*)xpathObj->nodesetval->nodeTab[0]->properties->children->content);

      //cout << "nb domain " << nbdomain << endl;
      MyGlobals::_File_Names.resize(nbdomain);
      MyGlobals::_Mesh_Names.resize(nbdomain);
      (_collection->getMesh()).resize(nbdomain);
      (_collection->getFaceMesh()).resize(nbdomain);
      (_collection->getCellFamilyIds()).resize(nbdomain);
      (_collection->getFaceFamilyIds()).resize(nbdomain);

      //retrieving the node which contains the file names
      const char filechar[]="//files/subfile";
      xmlXPathFreeObject(xpathObj);
      xpathObj = xmlXPathEvalExpression(BAD_CAST filechar, xpathCtx);
      if (xpathObj==0 || xpathObj->nodesetval->nodeNr ==0)
        throw INTERP_KERNEL::Exception("Xml Master File does not contain /MED/files/subfile nodes");
      int nbfiles = xpathObj->nodesetval ->nodeNr;
    
      for (int i=0; i<nbfiles;i++)
        {
          //reading information about the domain
          std::string host;
          //reading file names 
          std::ostringstream name_search_string;
          name_search_string<<"//files/subfile[@id=\""<<i+1<<"\"]/name";
          xmlXPathObjectPtr xpathObjfilename =
            xmlXPathEvalExpression(BAD_CAST name_search_string.str().c_str(),xpathCtx);
          if (xpathObjfilename->nodesetval ==0)
            throw INTERP_KERNEL::Exception("Error retrieving a file name from subfile of Xml Master File");
          MyGlobals::_File_Names[i]=(const char*)xpathObjfilename->nodesetval->nodeTab[0]->children->content;

          //reading the local mesh names
          std::ostringstream mesh_search_string;
          mesh_search_string<<"//mapping/mesh/chunk[@subdomain=\""<<i+1<<"\"]/name";

          xmlXPathObjectPtr xpathMeshObj = xmlXPathEvalExpression(BAD_CAST mesh_search_string.str().c_str(),xpathCtx);
          if (xpathMeshObj->nodesetval ==0)
            throw INTERP_KERNEL::Exception("Error retrieving mesh name from chunk of Xml Master File");
          MyGlobals::_Mesh_Names[i]=(const char*)xpathMeshObj->nodesetval->nodeTab[0]->children->content;

          if ( !domainSelector || domainSelector->isMyDomain(i))
            readSubdomain(i);
          xmlXPathFreeObject(xpathObjfilename);
          xmlXPathFreeObject(xpathMeshObj);
        } //loop on domains

      //LIBXML cleanup
      xmlXPathFreeObject(xpathObj); 
      xmlXPathFreeContext(xpathCtx); 
      xmlFreeDoc(master_doc); 

    } //of try
  catch(...)
    {
      throw INTERP_KERNEL::Exception("I/O error reading parallel MED file");
    }

  ParallelTopology* aPT = new ParallelTopology(_collection->getMesh());
  //creation of topology from mesh and connect zones
  if ( _collection->isParallelMode() )
    {
      //to know nb of cells on each proc to compute global cell ids from locally global
      domainSelector->gatherNbOf(_collection->getMesh());
    }
  _collection->setTopology(aPT);
  _collection->setDomainNames(_collection->getName());
  return 0;
}
void MeshCollectionMedXmlDriver::write ( const char *  filename,
ParaDomainSelector *  domainSelector = 0 
) const

writes the collection of meshes in a MED v2.3 Xml file with the connect zones being written as joints

Parameters:
filenamename of the Xml file containing the meshes description

Definition at line 183 of file MEDPARTITIONER_MeshCollectionMedXmlDriver.cxx.

{
  xmlDocPtr master_doc = 0;
  xmlNodePtr root_node = 0, node, node2;
  char buff[256];

  //Creating the Xml document
  master_doc = xmlNewDoc(BAD_CAST "1.0");
  root_node = xmlNewNode(0, BAD_CAST "root");
  xmlDocSetRootElement(master_doc,root_node);

  //Creating child nodes
  // Version tag
  node = xmlNewChild(root_node, 0, BAD_CAST "version",0);
  xmlNewProp(node, BAD_CAST "maj", BAD_CAST "2");
  xmlNewProp(node, BAD_CAST "min", BAD_CAST "3");
  xmlNewProp(node, BAD_CAST "ver", BAD_CAST "1");

  //Description tag
  time_t present; 
  char date[6];
#ifndef WIN32
  time( &present);
  struct tm *time_asc = localtime(&present);
  sprintf(date,"%02d%02d%02d",time_asc->tm_year
          ,time_asc->tm_mon+1
          ,time_asc->tm_mday);
#else
  SYSTEMTIME    st;
  GetLocalTime ( &st );
  sprintf(date,"%02d%02d%02d",
          st.wYear
          ,st.wMonth
          ,st.wDay);
#endif

  node = xmlNewChild(root_node,0, BAD_CAST "description",0);

  xmlNewProp(node, BAD_CAST "what", BAD_CAST _collection->getDescription().c_str());
  xmlNewProp(node, BAD_CAST "when", BAD_CAST date);

  //Content tag
  node =xmlNewChild(root_node,0, BAD_CAST "content",0);
  node2 = xmlNewChild(node, 0, BAD_CAST "mesh",0);
  xmlNewProp(node2, BAD_CAST "name", BAD_CAST _collection->getName().c_str());

  //Splitting tag
  node=xmlNewChild(root_node,0,BAD_CAST "splitting",0);
  node2=xmlNewChild(node,0,BAD_CAST "subdomain",0);
  sprintf(buff, "%d", (int)_collection->getMesh().size());
  xmlNewProp(node2, BAD_CAST "number", BAD_CAST buff);
  node2=xmlNewChild(node,0,BAD_CAST "global_numbering",0);
  xmlNewProp(node2, BAD_CAST "present", BAD_CAST "yes");

  //Files tag
  xmlNodePtr file_node=xmlNewChild(root_node,0,BAD_CAST "files",0);

  //Mapping tag
  node = xmlNewChild(root_node,0,BAD_CAST "mapping",0);
  xmlNodePtr mesh_node = xmlNewChild(node, 0, BAD_CAST "mesh",0);
  xmlNewProp(mesh_node, BAD_CAST "name", BAD_CAST _collection->getName().c_str());

  int nbdomains= _collection->getMesh().size();

  //loop on the domains
  std::string finalMeshName=ExtractFromDescription(MyGlobals::_General_Informations[0], "finalMeshName=");
  for (int idomain=nbdomains-1; idomain>=0;idomain--)
    {
      std::string distfilename;
      std::ostringstream suffix;
      suffix<<filename<<idomain+1<<".med";
      distfilename=suffix.str();

      if ( !domainSelector || domainSelector->isMyDomain( idomain ) )
        {
          if ( (_collection->getMesh())[idomain]->getNumberOfCells()==0 )
            continue; //empty domain
          if (MyGlobals::_Verbose>1)
            std::cout << "proc "<< domainSelector->rank() << " : writeMedFile " << distfilename
                      << " "<< (_collection->getMesh())[idomain]->getNumberOfCells() << " cells"
                      << " " << (_collection->getFaceMesh())[idomain]->getNumberOfCells() << " faces"
                      << " " << (_collection->getMesh())[idomain]->getNumberOfNodes()<<" nodes" << std::endl;
          writeMedFile(idomain,distfilename);
        }

      if (domainSelector->rank()==0)
        {
          //updating the ascii description file
          node = xmlNewChild(file_node, 0, BAD_CAST "subfile",0);
          sprintf (buff,"%d",idomain+1);
          xmlNewProp(node, BAD_CAST "id", BAD_CAST buff);
          xmlNewChild(node,0,BAD_CAST "name",BAD_CAST distfilename.c_str());
          xmlNewChild(node,0,BAD_CAST "machine",BAD_CAST "localhost");

          node = xmlNewChild(mesh_node,0, BAD_CAST "chunk",0);
          xmlNewProp(node, BAD_CAST "subdomain", BAD_CAST buff);
          xmlNewChild(node,0,BAD_CAST "name", BAD_CAST finalMeshName.c_str());
          //xmlNewChild(node,0,BAD_CAST "name", BAD_CAST (_collection->getMesh())[idomain]->getName());
        }
    }
  
  //create the ascii description file
  if (domainSelector->rank()==0)
    {
      std::string myfile(filename);
      myfile.append(".xml");
      if ( !domainSelector || domainSelector->rank() == 0 )
        xmlSaveFormatFileEnc(myfile.c_str(), master_doc, "UTF-8", 1);
    }
  xmlFreeDoc(master_doc);
  xmlCleanupParser();
}

Here is the call graph for this function:


Member Data Documentation


The documentation for this class was generated from the following files: