Back to index

salome-med  6.5.0
Public Member Functions | Private Member Functions | Private Attributes
MEDSPLITTER::MESHCollectionMedXMLDriver Class Reference

#include <MEDSPLITTER_MESHCollectionMedXMLDriver.hxx>

Collaboration diagram for MEDSPLITTER::MESHCollectionMedXMLDriver:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 MESHCollectionMedXMLDriver (MESHCollection *)
virtual ~MESHCollectionMedXMLDriver ()
int read (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 (char *, ParaDomainSelector *sel=0)
 writes the collection of meshes in a MED v2.3 XML file with the connect zones being written as joints
void readFields (vector< MEDMEM::FIELD< int > * > &filenames, char *fieldname, int itnumber, int ordernumber)
void readFields (vector< MEDMEM::FIELD< double > * > &filenames, char *fieldname, int itnumber, int ordernumber)
void writeFields (vector< MEDMEM::FIELD< double > * > &filenames, char *fieldname)
void writeFields (vector< MEDMEM::FIELD< int > * > &filenames, char *fieldname)

Private Member Functions

template<class T >
void _readFields (vector< MEDMEM::FIELD< T > * > &filenames, char *fieldname, int itnumber, int ordernumber)
template<class T >
void _writeFields (vector< MEDMEM::FIELD< T > * > &filenames, char *fieldname)

Private Attributes

std::string _master_filename

Detailed Description

Definition at line 28 of file MEDSPLITTER_MESHCollectionMedXMLDriver.hxx.


Constructor & Destructor Documentation

Definition at line 78 of file MEDSPLITTER_MESHCollectionMedXMLDriver.cxx.

                                                                                :MESHCollectionDriver(collection)
{
}

Definition at line 33 of file MEDSPLITTER_MESHCollectionMedXMLDriver.hxx.

{}

Member Function Documentation

template<class T >
void MEDSPLITTER::MESHCollectionMedXMLDriver::_readFields ( vector< MEDMEM::FIELD< T > * > &  filenames,
char *  fieldname,
int  itnumber,
int  ordernumber 
) [private]

Here is the caller graph for this function:

template<class T >
void MEDSPLITTER::MESHCollectionMedXMLDriver::_writeFields ( vector< MEDMEM::FIELD< T > * > &  filenames,
char *  fieldname 
) [private]

Here is the caller graph for this function:

int MESHCollectionMedXMLDriver::read ( 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 89 of file MEDSPLITTER_MESHCollectionMedXMLDriver.cxx.

{
  const char* LOC = "MEDSPLITTER::MESHCollectionDriver::read()";
  BEGIN_OF_MED(LOC);

  //ditributed meshes
  vector<int*> cellglobal;
  vector<int*> nodeglobal;
  vector<int*> faceglobal;

  int nbdomain;

  _master_filename=filename;

  // reading ascii master file
  try
    {
      MESSAGE_MED("Start reading");

      // Setting up the XML tree corresponding to filename
      xmlDocPtr master_doc=xmlParseFile(filename);

      if (!master_doc)    
        throw MEDEXCEPTION("MEDSPLITTER XML read - Master File does not exist o r 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)
        {
          xmlXPathFreeObject(xpathObj);
          throw MEDEXCEPTION("MEDSPLITTER read - 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)
        {
          xmlXPathFreeObject(xpathObj);
          throw MEDEXCEPTION("MEDSPLITTER read - 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;
      _filename.resize(nbdomain);
      _meshname.resize(nbdomain);
      (_collection->getMesh()).resize(nbdomain);
      cellglobal.resize(nbdomain);
      nodeglobal.resize(nbdomain);
      faceglobal.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)
        {
          xmlXPathFreeObject(xpathObj);
          throw MEDEXCEPTION("MEDSPLITTER read - 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

          string host;

          cellglobal[i]=0;
          faceglobal[i]=0;
          nodeglobal[i]=0;

          //reading file names 
          ostringstream name_search_string;
          name_search_string<<"//files/subfile[@id=\""<<i+1<<"\"]/name";
          //cout <<name_search_string.str()<<endl;
          xmlXPathObjectPtr xpathObjfilename =
            xmlXPathEvalExpression(BAD_CAST name_search_string.str().c_str(),xpathCtx);
          if (xpathObjfilename->nodesetval ==0)
            throw MEDEXCEPTION("MED XML reader : Error retrieving file name ");
          _filename[i]=(const char*)xpathObjfilename->nodesetval->nodeTab[0]->children->content;

          //reading the local mesh names
          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 MEDEXCEPTION("MED XML reader : Error retrieving mesh name ");
          _meshname[i]=(const char*)xpathMeshObj->nodesetval->nodeTab[0]->children->content;

          if ( !domainSelector || domainSelector->isMyDomain(i))
            readSubdomain(cellglobal, faceglobal, nodeglobal, i);
          xmlXPathFreeObject(xpathObjfilename);

          xmlXPathFreeObject(xpathMeshObj);
        }//loop on domains

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

      MESSAGE_MED("end of read");
    }//of try
  catch(...)
    {
      throw MEDEXCEPTION("I/O error reading parallel MED file");
    }

  //creation of topology from mesh and connect zones
  ParallelTopology* aPT = new ParallelTopology
    ((_collection->getMesh()), (_collection->getCZ()), cellglobal, nodeglobal, faceglobal);
  _collection->setTopology(aPT);

  for (int i=0; i<nbdomain; i++)
    {
      if (cellglobal[i]!=0) delete[] cellglobal[i];
      if (nodeglobal[i]!=0) delete[] nodeglobal[i];
      if (faceglobal[i]!=0) delete[] faceglobal[i];
    }

  END_OF_MED(LOC);
  return 0;
}
void MEDSPLITTER::MESHCollectionMedXMLDriver::readFields ( vector< MEDMEM::FIELD< int > * > &  filenames,
char *  fieldname,
int  itnumber,
int  ordernumber 
) [inline]

Definition at line 40 of file MEDSPLITTER_MESHCollectionMedXMLDriver.hxx.

    {
      _readFields(filenames,fieldname,itnumber,ordernumber);
    }

Here is the call graph for this function:

void MEDSPLITTER::MESHCollectionMedXMLDriver::readFields ( vector< MEDMEM::FIELD< double > * > &  filenames,
char *  fieldname,
int  itnumber,
int  ordernumber 
) [inline]

Definition at line 45 of file MEDSPLITTER_MESHCollectionMedXMLDriver.hxx.

    {
      _readFields(filenames,fieldname,itnumber,ordernumber);
    }

Here is the call graph for this function:

void MESHCollectionMedXMLDriver::write ( char *  filename,
ParaDomainSelector *  domainSelector = 0 
)

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 235 of file MEDSPLITTER_MESHCollectionMedXMLDriver.cxx.

{
  const char* LOC = "MEDSPLITTER::MESHCollectionDriver::writeXML()";
  BEGIN_OF_MED(LOC);

  xmlDocPtr master_doc = 0;
  xmlNodePtr root_node = 0, node, node2;
  //  xmlDTDPtr dtd = 0;

  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
  char date[1024];
#ifndef WIN32
  time_t present;
  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();
  _filename.resize(nbdomains);

  //loop on the domains
  for (int idomain=nbdomains-1; idomain>=0;idomain--)
    {
      char distfilename[256];

      ostringstream suffix;
      suffix << filename<< idomain+1 <<".med";

      strcpy(distfilename,suffix.str().c_str());

      _filename[idomain]=string(distfilename);

      MESSAGE_MED("File name "<<string(distfilename));

      if ( !domainSelector || domainSelector->isMyDomain( idomain ) )
        {
          if ( !_collection->getMesh()[idomain]->getConnectivityptr() ) continue;//empty domain

          int id=(_collection->getMesh())[idomain]->addDriver(MEDMEM::MED_DRIVER,distfilename,(_collection->getMesh())[idomain]->getName(),MED_EN::WRONLY);

          MESSAGE_MED("Start writing");
          (_collection->getMesh())[idomain]->write(id);
          (_collection->getMesh())[idomain]->rmDriver(id);

          writeSubdomain(idomain, nbdomains, distfilename, domainSelector);
        }
      //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);
      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 (_collection->getMesh())[idomain]->getName().c_str());
    }
  strcat(filename,".xml");
  _master_filename=filename;
  if ( !domainSelector || domainSelector->rank() == 0 )
    xmlSaveFormatFileEnc(filename, master_doc, "UTF-8", 1);
  xmlFreeDoc(master_doc);
  //xmlCleanupParser();

  END_OF_MED(LOC);
}
void MEDSPLITTER::MESHCollectionMedXMLDriver::writeFields ( vector< MEDMEM::FIELD< double > * > &  filenames,
char *  fieldname 
) [inline]

Definition at line 51 of file MEDSPLITTER_MESHCollectionMedXMLDriver.hxx.

    {
      _writeFields( filenames, fieldname);
    }

Here is the call graph for this function:

void MEDSPLITTER::MESHCollectionMedXMLDriver::writeFields ( vector< MEDMEM::FIELD< int > * > &  filenames,
char *  fieldname 
) [inline]

Definition at line 55 of file MEDSPLITTER_MESHCollectionMedXMLDriver.hxx.

    {
      _writeFields( filenames, fieldname);
    }

Here is the call graph for this function:


Member Data Documentation

Definition at line 70 of file MEDSPLITTER_MESHCollectionMedXMLDriver.hxx.


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