Back to index

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

#include <MEDPARTITIONER_MeshCollectionMedAsciiDriver.hxx>

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

List of all members.

Public Member Functions

 MeshCollectionMedAsciiDriver (MeshCollection *)
virtual ~MeshCollectionMedAsciiDriver ()
int read (const char *, ParaDomainSelector *sel=0)
 reads a MED 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 file with the connect zones being written as joints

Private Attributes

std::string _master_filename

Detailed Description

Definition at line 28 of file MEDPARTITIONER_MeshCollectionMedAsciiDriver.hxx.


Constructor & Destructor Documentation

Definition at line 44 of file MEDPARTITIONER_MeshCollectionMedAsciiDriver.cxx.

                                                                                    :MeshCollectionDriver(collection)
{
}

Definition at line 32 of file MEDPARTITIONER_MeshCollectionMedAsciiDriver.hxx.

{ }

Member Function Documentation

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

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

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

Definition at line 55 of file MEDPARTITIONER_MeshCollectionMedAsciiDriver.cxx.

{
  //distributed meshes
  std::vector<int*> cellglobal;
  std::vector<int*> nodeglobal;
  std::vector<int*> faceglobal;
  int nbdomain;

  //reading ascii master file
  try
    {
      std::ifstream asciiinput(filename);
      if (!asciiinput)
        throw INTERP_KERNEL::Exception("Master ASCII File does not exist");
      char charbuffer[512];
      asciiinput.getline(charbuffer,512);

      while (charbuffer[0]=='#')
        {
          asciiinput.getline(charbuffer,512);
        }

      //reading number of domains
      nbdomain=atoi(charbuffer);
      MyGlobals::_File_Names.resize(nbdomain);
      MyGlobals::_Mesh_Names.resize(nbdomain);
      (_collection->getMesh()).resize(nbdomain);
      cellglobal.resize(nbdomain);
      nodeglobal.resize(nbdomain);
      faceglobal.resize(nbdomain);

      if (nbdomain == 0)
        throw INTERP_KERNEL::Exception("Empty ASCII master file");
      for (int i=0; i<nbdomain;i++)
        {
          //reading information about the domain
          std::string mesh,host;
          int idomain;
          cellglobal[i]=0;
          faceglobal[i]=0;
          nodeglobal[i]=0;

          asciiinput >> mesh >> idomain >> MyGlobals::_Mesh_Names[i] >> host >> MyGlobals::_File_Names[i];

          //Setting the name of the global mesh (which should be is the same for all the subdomains)
          if (i==0)
            _collection->setName(mesh);

          if (idomain!=i+1)
            {
              throw INTERP_KERNEL::Exception("domain must be written from 1 to N in ASCII file descriptor");
            }
          if ( !domainSelector || domainSelector->isMyDomain(i))
            readSubdomain(cellglobal,faceglobal,nodeglobal, i);

        } //loop on domains
    } //of try
  catch(...)
    {
      throw INTERP_KERNEL::Exception("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++)
    {
      delete [] cellglobal[i];
      delete [] nodeglobal[i];
      delete [] faceglobal[i];
    }
  return 0;
}
void MeshCollectionMedAsciiDriver::write ( const char *  filename,
ParaDomainSelector *  domainSelector = 0 
) const

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

Parameters:
filenamename of the ascii file containing the meshes description

Definition at line 135 of file MEDPARTITIONER_MeshCollectionMedAsciiDriver.cxx.

{
  int nbdomains=_collection->getMesh().size();
  std::vector<std::string> filenames;
  filenames.resize(nbdomains);

  //loop on the domains
  for (int idomain=0; idomain<nbdomains; idomain++)
    {
      std::string distfilename;
      std::ostringstream suffix;
      suffix << filename << idomain+1 << ".med";
      distfilename=suffix.str();
      filenames[idomain]=distfilename;

      if ( !domainSelector || domainSelector->isMyDomain( idomain ) )
        {
          if ( !_collection->getMesh()[idomain]->getNumberOfCells()==0 ) continue;//empty domain
          MEDLoader::WriteUMesh(distfilename.c_str(),(_collection->getMesh())[idomain],true);
          //writeSubdomain(idomain, nbdomains, distfilename.c_str(), domainSelector);
        }
    }

  //write master file
  if ( !domainSelector || domainSelector->rank() == 0 )
    {
      std::ofstream file(filename);
      file << "#MED Fichier V 2.3"<<" " << std::endl;
      file << "#" << " " << std::endl;
      file << _collection->getMesh().size() << " " << std::endl;

      for (int idomain=0; idomain<nbdomains; idomain++)
        file << _collection->getName() <<" "<< idomain+1 << " "
             << (_collection->getMesh())[idomain]->getName() << " localhost "
             << filenames[idomain] << " "<< std::endl;
    }

}

Member Data Documentation


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