Salome HOME
Indices are stored as mcIdType type instead of int to support switch to 64bits indexing
[tools/medcoupling.git] / src / MEDPartitioner / MEDPARTITIONER_MeshCollectionMedAsciiDriver.cxx
index b1ab04cd81a6255c37729146bfbe7c5ab6b7cfe9..0fd977b0613bf181af280b46e1e9664795ba4d17 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -33,6 +33,7 @@
 #include <string>
 #include <fstream>
 #include <iostream>
+#include <sstream>
 
 #include <libxml/tree.h>
 #include <libxml/parser.h>
@@ -52,12 +53,46 @@ MeshCollectionMedAsciiDriver::MeshCollectionMedAsciiDriver(MeshCollection* colle
  *\param filename ascii file containing the list of MED v2.3 files
  * */
 
+int MeshCollectionMedAsciiDriver::read(MEDCoupling::MEDFileData* filedata)
+{
+  readMEDFileData(filedata);
+
+  std::vector<MEDPARTITIONER::ConnectZone*> cz; // to fill from filedata
+  std::vector<mcIdType*> cellglobal;
+  std::vector<mcIdType*> nodeglobal;
+  std::vector<mcIdType*> faceglobal;
+  std::size_t size = _collection->getMesh().size();
+  cellglobal.resize(size);
+  nodeglobal.resize(size);
+  faceglobal.resize(size);
+  for ( unsigned int idomain = 0; idomain < size; ++idomain )
+    {
+      cellglobal[idomain]=0;
+      faceglobal[idomain]=0;
+      nodeglobal[idomain]=0;
+      if ( (_collection->getMesh())[idomain] && (_collection->getMesh())[idomain]->getNumberOfNodes() > 0 )
+        _collection->setNonEmptyMesh(idomain);
+    }
+  //creation of topology from mesh and connect zones
+  ParallelTopology* aPT = new ParallelTopology((_collection->getMesh()), cz, cellglobal, nodeglobal, faceglobal);
+  _collection->setTopology(aPT,true);
+
+  return 0;
+}
+
+/*!reads a MED File v>=2.3
+ * and mounts the corresponding meshes in memory
+ * the connect zones are created from the joints
+ *
+ *\param filename ascii file containing the list of MED v2.3 files
+ * */
+
 int MeshCollectionMedAsciiDriver::read(const char* filename, ParaDomainSelector* domainSelector)
 {
   //distributed meshes
-  std::vector<int*> cellglobal;
-  std::vector<int*> nodeglobal;
-  std::vector<int*> faceglobal;
+  std::vector<mcIdType*> cellglobal;
+  std::vector<mcIdType*> nodeglobal;
+  std::vector<mcIdType*> faceglobal;
   int nbdomain;
 
   //reading ascii master file
@@ -105,7 +140,7 @@ int MeshCollectionMedAsciiDriver::read(const char* filename, ParaDomainSelector*
               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);
+            readSubdomain(i);
 
         } //loop on domains
     } //of try
@@ -116,7 +151,7 @@ int MeshCollectionMedAsciiDriver::read(const char* filename, ParaDomainSelector*
 
   //creation of topology from mesh and connect zones
   ParallelTopology* aPT = new ParallelTopology((_collection->getMesh()), (_collection->getCZ()), cellglobal, nodeglobal, faceglobal);
-  _collection->setTopology(aPT);
+  _collection->setTopology(aPT, true);
 
   for (int i=0; i<nbdomain; i++)
     {
@@ -127,19 +162,18 @@ int MeshCollectionMedAsciiDriver::read(const char* filename, ParaDomainSelector*
   return 0;
 }
 
-
 /*! writes the collection of meshes in a MED v2.3 file
  * with the connect zones being written as joints
  * \param filename name of the ascii file containing the meshes description
  */
 void MeshCollectionMedAsciiDriver::write(const char* filename, ParaDomainSelector* domainSelector) const
 {
-  int nbdomains=_collection->getMesh().size();
+  std::size_t nbdomains=_collection->getMesh().size();
   std::vector<std::string> filenames;
   filenames.resize(nbdomains);
 
   //loop on the domains
-  for (int idomain=0; idomain<nbdomains; idomain++)
+  for (unsigned idomain=0; idomain<nbdomains; idomain++)
     {
       std::string distfilename;
       std::ostringstream suffix;
@@ -149,8 +183,9 @@ void MeshCollectionMedAsciiDriver::write(const char* filename, ParaDomainSelecto
 
       if ( !domainSelector || domainSelector->isMyDomain( idomain ) )
         {
-          if ( !_collection->getMesh()[idomain]->getNumberOfCells()==0 ) continue;//empty domain
-          MEDLoader::WriteUMesh(distfilename.c_str(),(_collection->getMesh())[idomain],true);
+          // [ABN] spurious test in 8.2 - fixed as I think it should be:
+          if ( _collection->getMesh()[idomain]->getNumberOfCells() == 0 ) continue;
+          WriteUMesh(distfilename.c_str(),(_collection->getMesh())[idomain],true);
           //writeSubdomain(idomain, nbdomains, distfilename.c_str(), domainSelector);
         }
     }
@@ -163,7 +198,7 @@ void MeshCollectionMedAsciiDriver::write(const char* filename, ParaDomainSelecto
       file << "#" << " " << std::endl;
       file << _collection->getMesh().size() << " " << std::endl;
 
-      for (int idomain=0; idomain<nbdomains; idomain++)
+      for (std::size_t idomain=0; idomain<nbdomains; idomain++)
         file << _collection->getName() <<" "<< idomain+1 << " "
              << (_collection->getMesh())[idomain]->getName() << " localhost "
              << filenames[idomain] << " "<< std::endl;