1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
27 #include <libxml/tree.h>
28 #include <libxml/parser.h>
29 #include <libxml/xpath.h>
30 #include <libxml/xpathInternals.h>
36 #include "MEDMEM_Utilities.hxx"
39 #include "MEDMEM_DriversDef.hxx"
40 #include "MEDMEM_Mesh.hxx"
41 #include "MEDMEM_Field.hxx"
42 #include "MEDMEM_Meshing.hxx"
43 #include "MEDMEM_CellModel.hxx"
44 #include "MEDMEM_SkyLineArray.hxx"
45 #include "MEDMEM_ConnectZone.hxx"
47 //MEDSPLITTER includes
48 #include "MEDSPLITTER_Topology.hxx"
49 #include "MEDSPLITTER_ParallelTopology.hxx"
50 #include "MEDSPLITTER_SequentialTopology.hxx"
51 #include "MEDSPLITTER_MESHCollectionDriver.hxx"
52 #include "MEDSPLITTER_MESHCollection.hxx"
53 #include "MEDSPLITTER_MESHCollectionMedAsciiDriver.hxx"
54 #include "MEDSPLITTER_ParaDomainSelector.hxx"
56 using namespace MEDSPLITTER;
59 #include "MEDSPLITTER_MESHCollectionMedAsciiDriver.H"
62 MESHCollectionMedAsciiDriver::MESHCollectionMedAsciiDriver(MESHCollection* collection):MESHCollectionDriver(collection)
66 /*!reads a MED File v>=2.3
67 * and mounts the corresponding meshes in memory
68 * the connect zones are created from the joints
70 *\param filename ascii file containing the list of MED v2.3 files
73 int MESHCollectionMedAsciiDriver::read(char* filename, ParaDomainSelector* domainSelector)
76 const char* LOC = "MEDSPLITTER::MESHCollectionDriver::read()";
80 vector<int*> cellglobal;
81 vector<int*> nodeglobal;
82 vector<int*> faceglobal;
86 // reading ascii master file
88 MESSAGE_MED("Start reading");
89 ifstream asciiinput(filename);
92 throw MEDEXCEPTION("MEDSPLITTER read - Master File does not exist");
95 asciiinput.getline(charbuffer,512);
97 while (charbuffer[0]=='#')
99 asciiinput.getline(charbuffer,512);
102 //reading number of domains
103 nbdomain=atoi(charbuffer);
104 cout << "nb domain "<<nbdomain<<endl;
105 // asciiinput>>nbdomain;
106 _filename.resize(nbdomain);
107 _meshname.resize(nbdomain);
108 (_collection->getMesh()).resize(nbdomain);
109 cellglobal.resize(nbdomain);
110 nodeglobal.resize(nbdomain);
111 faceglobal.resize(nbdomain);
114 throw MEDEXCEPTION("Empty ASCII master file");
115 for (int i=0; i<nbdomain;i++)
118 //reading information about the domain
126 asciiinput >> mesh >> idomain >> _meshname[i] >> host >> _filename[i];
128 //Setting the name of the global mesh (which is the same
129 //for all the subdomains)
131 _collection->setName(mesh);
135 cerr<<"Error : domain must be written from 1 to N in asciifile descriptor"<<endl;
138 if ( !domainSelector || domainSelector->isMyDomain(i))
139 readSubdomain(cellglobal,faceglobal,nodeglobal, i);
142 MESSAGE_MED("end of read");
146 cerr << "I/O error reading parallel MED file"<<endl;
150 //creation of topology from mesh and connect zones
151 ParallelTopology* aPT = new ParallelTopology
152 ((_collection->getMesh()), (_collection->getCZ()), cellglobal, nodeglobal, faceglobal);
153 _collection->setTopology(aPT);
155 for (int i=0; i<nbdomain; i++)
157 if (cellglobal[i]!=0) delete[] cellglobal[i];
158 if (nodeglobal[i]!=0) delete[] nodeglobal[i];
159 if (faceglobal[i]!=0) delete[] faceglobal[i];
167 /*! writes the collection of meshes in a
169 * with the connect zones being written as joints
170 * \param filename name of the ascii file containing the meshes description
172 void MESHCollectionMedAsciiDriver::write(char* filename, ParaDomainSelector* domainSelector)
175 const char* LOC = "MEDSPLITTER::MESHCollectionDriver::write()";
178 int nbdomains= _collection->getMesh().size();
179 _filename.resize(nbdomains);
181 //loop on the domains
182 for (int idomain=0; idomain<nbdomains;idomain++)
184 char distfilename[256];
186 ostringstream suffix;
187 suffix << filename<< idomain+1 <<".med";
189 strcpy(distfilename,suffix.str().c_str());
191 _filename[idomain]=string(distfilename);
193 MESSAGE_MED("File name "<<string(distfilename));
195 if ( !domainSelector || domainSelector->isMyDomain( idomain ) )
197 if ( !_collection->getMesh()[idomain]->getConnectivityptr() ) continue;//empty domain
199 int id=(_collection->getMesh())[idomain]->addDriver(MEDMEM::MED_DRIVER,distfilename,(_collection->getMesh())[idomain]->getName(),MED_EN::WRONLY);
201 MESSAGE_MED("Start writing");
202 (_collection->getMesh())[idomain]->write(id);
204 writeSubdomain(idomain, nbdomains, distfilename, domainSelector);
209 if ( !domainSelector || domainSelector->rank() == 0 )
211 ofstream file(filename);
213 file <<"#MED Fichier V 2.3"<<" "<<endl;
214 file <<"#"<<" "<<endl;
215 file<<_collection->getMesh().size()<<" "<<endl;
217 for (int idomain=0; idomain<nbdomains;idomain++)
218 file << _collection->getName() <<" "<< idomain+1 << " "
219 << (_collection->getMesh())[idomain]->getName() << " localhost "
220 << _filename[idomain] << " "<<endl;