1 // Project MULTIPR, IOLS WP1.2.1 - EDF/CS
2 // Partitioning/decimation module for the SALOME v3.2 platform
5 * \file MULTIPR_MeshDis.cxx
7 * \brief see MULTIPR_MeshDis.hxx
9 * \author Olivier LE ROUX - CS, Virtual Reality Dpt
14 //*****************************************************************************
16 //*****************************************************************************
18 #include "MULTIPR_MeshDis.hxx"
19 #include "MULTIPR_Mesh.hxx"
20 #include "MULTIPR_DecimationFilter.hxx"
21 #include "MULTIPR_Utils.hxx"
22 #include "MULTIPR_Globals.hxx"
23 #include "MULTIPR_API.hxx"
24 #include "MULTIPR_Exceptions.hxx"
25 #include "MULTIPR_ProgressCallback.hxx"
27 #include "MEDSPLITTER_API.hxx"
39 //*****************************************************************************
40 // Global variables (exported)
41 //*****************************************************************************
43 MULTIPR_ProgressCallback* gProgressCallback = NULL;
46 //*****************************************************************************
47 // Class MeshDisEntry implementation
48 //*****************************************************************************
50 MeshDisPart::MeshDisPart()
54 mOldCollection = NULL;
60 MeshDisPart::~MeshDisPart()
66 void MeshDisPart::reset()
68 mToDoOnNextWrite = MULTIPR_UNDEFINED;
74 mMEDFileName[0] = '\0';
84 if (mCollection != NULL)
90 if (mOldCollection != NULL)
92 delete mOldCollection;
93 mOldCollection = NULL;
98 const char* MeshDisPart::getMEDFileNameSuffix() const
100 // "agregat100grains_12pas_grain97.med" -> "grain97"
101 // "agregat100grains_12pas_grain100_part2.med" -> "grain100_part2"
102 // "aagregat100grains_12pas_grain98_gradmoy-low-25.0-0.3.med" -> "grain98_gradmoy-low-25-0.3"
104 string prefix = removeExtension(mMEDFileName, ".med");
105 prefix.erase(0, prefix.rfind("grain"));
106 return prefix.c_str();
110 void MeshDisPart::create(
111 OnNextWrite pToDoOnNextWrite,
112 const char* pMeshName,
114 const char* pPartName,
116 const char* pMEDFileName,
119 if (pToDoOnNextWrite == MULTIPR_UNDEFINED) throw IllegalArgumentException("", __FILE__, __LINE__);
120 if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__);
121 if (pId < 1) throw IllegalArgumentException("", __FILE__, __LINE__);
122 if (pPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__);
123 if (pPath == NULL) throw NullArgumentException("", __FILE__, __LINE__);
124 if (pMEDFileName == NULL) throw NullArgumentException("", __FILE__, __LINE__);
128 mToDoOnNextWrite = pToDoOnNextWrite;
129 strcpy(mMeshName, pMeshName);
131 strcpy(mPartName, pPartName);
132 strcpy(mPath, pPath);
133 strcpy(mMEDFileName, pMEDFileName);
139 void MeshDisPart::readMED()
141 if (mMesh != NULL) throw IllegalStateException("", __FILE__, __LINE__);
142 if (mCollection != NULL) throw IllegalStateException("", __FILE__, __LINE__);
143 if (mOldCollection != NULL) throw IllegalStateException("", __FILE__, __LINE__);
145 //cout << "read MED : mesh=" << mMEDfilename << endl;
148 mMesh->readSequentialMED(mMEDFileName, mMeshName);
152 ostream& operator<<(ostream& pOs, MeshDisPart& pM)
154 switch (pM.mToDoOnNextWrite)
156 case MeshDisPart::MULTIPR_UNDEFINED:
160 case MeshDisPart::MULTIPR_KEEP_AS_IT:
161 pOs << pM.mMeshName << " " << pM.mId << " " << pM.mPartName << " " << pM.mPath << " " << pM.mMEDFileName;
164 case MeshDisPart::MULTIPR_WRITE_MESH:
165 pOs << pM.mMeshName << " " << pM.mId << " " << pM.mPartName << " " << pM.mPath << " " << pM.mMEDFileName;
168 case MeshDisPart::MULTIPR_WRITE_PARTS:
169 pOs << pM.mMeshName << " " << pM.mId << " " << pM.mPartName << " " << pM.mPath << " " << pM.mMEDFileName << " SPLIT " << pM.mSplit;
172 default: throw IllegalStateException("", __FILE__, __LINE__);
179 //*****************************************************************************
180 // Class MeshDis implementation
181 //*****************************************************************************
195 void MeshDis::reset()
197 mMEDfilename[0] = '\0';
199 for (unsigned itPart = 0 ; itPart != mParts.size() ; itPart++)
201 MeshDisPart* part = mParts[itPart];
206 //mProgressCallback = NULL;
210 void MeshDis::addMesh(
211 MeshDisPart::OnNextWrite pToDoOnNextWrite,
212 const char* pMeshName,
214 const char* pPartName,
216 const char* pMEDFileName,
219 MeshDisPart* part = new MeshDisPart();
230 mParts.push_back(part);
234 void MeshDis::insertMesh(
235 MeshDisPart::OnNextWrite pToDoOnNextWrite,
236 const char* pMeshName,
238 const char* pPartName,
240 const char* pMEDFileName,
244 MeshDisPart* part = new MeshDisPart();
255 mParts.insert(mParts.begin() + pPosition, part);
257 // rename id of following parts
258 for (unsigned i = pPosition + 1 ; i < mParts.size() ; i++)
265 void MeshDis::removeParts(const char* pPrefixPartName)
267 if (pPrefixPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__);
270 sprintf(strPrefix, "%s_", pPrefixPartName);
272 for (vector<MeshDisPart*>::iterator itPart = mParts.begin() ; itPart != mParts.end() ; itPart++)
274 MeshDisPart* currentPart = (*itPart);
276 // remove part which have the same name and all sub_parts
277 // e.g. if pPrefixPartName="PART_4" => remove "PART_4" and "PART_4_*", but not "PART41"
278 if ((strcmp(currentPart->getPartName(), pPrefixPartName) == 0) ||
279 startsWith(currentPart->getPartName(), strPrefix))
281 mParts.erase(itPart);
283 // decrement id of following parts
284 for (vector<MeshDisPart*>::iterator itPart2 = itPart ; itPart2 != mParts.end() ; itPart2++)
290 if (currentPart->mMEDFileName != NULL)
292 remove(currentPart->mMEDFileName);
301 MeshDisPart* MeshDis::findPart(const char* pPartName)
303 if (pPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__);
305 MeshDisPart* part = NULL;
307 for (unsigned itPart = 0 ; itPart < mParts.size() ; itPart++)
309 MeshDisPart* currentPart = mParts[itPart];
311 if (strcmp(currentPart->getPartName(), pPartName) == 0)
323 vector<string> MeshDis::getMeshes() const
327 if (mParts.size() > 0)
329 MeshDisPart* part = mParts[0];
330 const char* meshName = part->getMeshName();
331 res.push_back(meshName);
338 vector<string> MeshDis::getFields() const
342 if (mParts.size() == 0)
347 // all the parts of the distributed MED file should have the same fields
348 // => just return the name of fields of the first part
349 switch (mParts[0]->mToDoOnNextWrite)
351 case MeshDisPart::MULTIPR_KEEP_AS_IT:
352 case MeshDisPart::MULTIPR_WRITE_PARTS:
354 vector<pair<string, int> > tmp = multipr::getListScalarFields(mParts[0]->getMEDFileName());
356 for (int i = 0 ; i < tmp.size() ; i++)
358 res.push_back(tmp[i].first);
363 case MeshDisPart::MULTIPR_WRITE_MESH:
364 return mParts[0]->mMesh->getNameScalarFields();
367 throw IllegalStateException("", __FILE__, __LINE__);
372 int MeshDis::getTimeStamps(const char* pFieldName) const
374 if (mParts.size() == 0)
376 // no parts in this distributed MED file => no fields => #iteration = 0
380 // all the parts of the distributed MED file should have the same fields
381 // => just return the number of iteration found in the field of the first part
382 switch (mParts[0]->mToDoOnNextWrite)
384 case MeshDisPart::MULTIPR_KEEP_AS_IT:
385 case MeshDisPart::MULTIPR_WRITE_PARTS:
387 vector<pair<string, int> > tmp = multipr::getListScalarFields(mParts[0]->getMEDFileName());
389 for (int i = 0 ; i < tmp.size() ; i++)
391 if (strcmp(tmp[i].first.c_str(), pFieldName) == 0)
393 return tmp[i].second;
397 // pFieldName not found in the list of fields
401 case MeshDisPart::MULTIPR_WRITE_MESH:
402 return mParts[0]->mMesh->getTimeStamps(pFieldName);
405 throw IllegalStateException("", __FILE__, __LINE__);
410 string MeshDis::getPartInfo(const char* pPartName)
412 MeshDisPart* part = findPart(pPartName);
417 sprintf(num, "%d", part->mId);
420 string(part->mMeshName) +
424 string(part->mPartName) +
426 string(part->mPath) +
428 string(part->mMEDFileName);
434 // part not found => return empty string
440 void MeshDis::splitPart(const char* pPartName, int pNbParts, int pPartitionner)
442 if (pPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__);
443 if (pNbParts < 2) throw IllegalArgumentException("", __FILE__, __LINE__);
444 if ((pPartitionner != MULTIPR_METIS) && (pPartitionner != MULTIPR_SCOTCH)) throw IllegalArgumentException("should be 0=METIS or 1=SCOTCH", __FILE__, __LINE__);
446 //---------------------------------------------------------------------
447 // Find the MED file corresponding to the given part
448 //---------------------------------------------------------------------
449 MeshDisPart* part = findPart(pPartName);
453 throw IllegalArgumentException("part not found in this distributed MED file", __FILE__, __LINE__);
456 //---------------------------------------------------------------------
457 // Load the sequential MED file
458 //---------------------------------------------------------------------
459 MEDSPLITTER::MESHCollection* collection;
460 collection = new MEDSPLITTER::MESHCollection(part->getMEDFileName(), part->getMeshName());
462 //---------------------------------------------------------------------
463 // Partition the group
464 //---------------------------------------------------------------------
465 MEDSPLITTER::Topology* topology;
466 if (pPartitionner == MULTIPR_METIS)
470 topology = collection->createPartition(pNbParts, MEDSPLITTER::Graph::METIS);
474 throw RuntimeException("MEDSPLITTER error: createPartition(), using METIS", __FILE__, __LINE__);
477 else if (pPartitionner == MULTIPR_SCOTCH)
481 topology = collection->createPartition(pNbParts, MEDSPLITTER::Graph::SCOTCH);
485 throw RuntimeException("MEDSPLITTER error: createPartition(), using SCOTCH", __FILE__, __LINE__);
490 throw IllegalStateException("unknown partitionner", __FILE__, __LINE__);
495 MEDSPLITTER::MESHCollection* newCollection = new MEDSPLITTER::MESHCollection(*collection, topology);
497 part->mToDoOnNextWrite = MeshDisPart::MULTIPR_WRITE_PARTS;
498 part->mSplit = pNbParts;
499 part->mOldCollection = collection;
500 part->mCollection = newCollection;
504 throw RuntimeException("MEDSPLITTER error: new MESHCollection()", __FILE__, __LINE__);
509 void MeshDis::decimatePart(
510 const char* pPartName,
511 const char* pFieldName,
513 const char* pFilterName,
519 //---------------------------------------------------------------------
521 //---------------------------------------------------------------------
522 if (pPartName == NULL) throw NullArgumentException("partname should not be NULL", __FILE__, __LINE__);
523 if (pFieldName == NULL) throw NullArgumentException("fieldname should not be NULL", __FILE__, __LINE__);
524 if (pFieldIt < med_int(1)) throw IllegalArgumentException("invalid field iteration; should be >= 1", __FILE__, __LINE__);
525 if (pTMed < 0.0) throw IllegalArgumentException("med res.: threshold must be > 0", __FILE__, __LINE__);
526 if (pTMed >= pTLow) throw IllegalArgumentException("threshold for med res. must be < threshold for low res.", __FILE__, __LINE__);
527 if (pRadius <= med_float(0.0)) throw IllegalArgumentException("radius should be > 0", __FILE__, __LINE__);
528 if ((pBoxing < 1) || (pBoxing > 200)) throw IllegalArgumentException("boxing should be in [1..200]", __FILE__, __LINE__);
530 //---------------------------------------------------------------------
531 // Find the MED file corresponding to the given part
532 //---------------------------------------------------------------------
533 MeshDisPart* part = findPart(pPartName);
536 throw IllegalArgumentException("part not found in the given distributed MED file", __FILE__, __LINE__);
539 //---------------------------------------------------------------------
540 // Load the associated sequential MED file
541 //---------------------------------------------------------------------
542 if (part->mMesh == NULL)
547 Mesh* meshFull = part->mMesh;
548 cout << (*meshFull) << endl;
550 const char* originalFilename = part->getMEDFileName();
551 string strPrefix = removeExtension(originalFilename, ".med");
554 //cout << (*this) << endl;
556 //---------------------------------------------------------------------
557 // Decimates the given mesh
558 //---------------------------------------------------------------------
559 // arguments for decimation are passed as a string for genericity
561 char newPartName[MED_TAILLE_NOM + 1];
562 char newMEDFileName[256];
564 // *** create a new mesh = MEDIUM resolution ***
565 sprintf(argv, "%s %d %lf %lf %d", pFieldName, pFieldIt, pTMed, pRadius, pBoxing);
566 sprintf(newPartName, "%s_MED", pPartName);
567 sprintf(newMEDFileName, "%s_gradmoy-med-%s-%s.med",
569 realToString(pTMed).c_str(),
570 realToString(pRadius).c_str());
573 Mesh* meshMedium = meshFull->decimate(pFilterName, argv, part->getMeshName());
574 cout << (*meshMedium) << endl;
577 MeshDisPart::MULTIPR_WRITE_MESH,
587 // *** create a new mesh = LOW resolution ***
588 sprintf(argv, "%s %d %lf %lf %d", pFieldName, pFieldIt, pTLow, pRadius, pBoxing);
589 sprintf(newPartName, "%s_LOW", pPartName);
590 sprintf(newMEDFileName, "%s_gradmoy-low-%s-%s.med",
592 realToString(pTLow).c_str(),
593 realToString(pRadius).c_str());
596 Mesh* meshLow = meshFull->decimate(pFilterName, argv, part->getMeshName());
597 cout << (*meshLow) << endl;
600 MeshDisPart::MULTIPR_WRITE_MESH,
611 //cout << (*this) << endl;
615 string MeshDis::evalDecimationParams(
616 const char* pPartName,
617 const char* pFieldName,
619 const char* pFilterName,
620 const char* pFilterParams)
622 MeshDisPart* part = findPart(pPartName);
630 if (part->mMesh == NULL)
635 multipr::DecimationFilter* filter = multipr::DecimationFilter::create(pFilterName);
641 multipr::DecimationFilterGradAvg* filterGrad = dynamic_cast<multipr::DecimationFilterGradAvg*>(filter);
643 if (filterGrad != NULL)
647 int ret = sscanf(pFilterParams, "%d", &mode);
649 // mode 2 = GET RADIUS
650 if ((ret == 1) && (mode == 2))
652 double radius = part->mMesh->evalDefaultRadius(8);
654 sprintf(res, "%f", radius);
661 ret = sscanf(pFilterParams, "%d %f %d", &mode, &radius, &boxing);
663 // mode 1 = GET GRADIENT MIN, MAX and AVG
664 if ((ret == 3) && (mode == 1))
666 double gradMin = 0.1, gradAvg = 0.15, gradMax = 0.2;
668 filterGrad->getGradientInfo(
679 sprintf(res, "%f %f %f", gradMin, gradAvg, gradMax);
694 int MeshDis::computeNumParts()
698 for (unsigned itPart = 0 ; itPart < mParts.size() ; itPart++)
700 switch (mParts[itPart]->mToDoOnNextWrite)
702 case MeshDisPart::MULTIPR_KEEP_AS_IT:
703 case MeshDisPart::MULTIPR_WRITE_MESH:
707 case MeshDisPart::MULTIPR_WRITE_PARTS:
708 numParts += mParts[itPart]->mSplit;
711 default: throw IllegalStateException("", __FILE__, __LINE__);
719 void MeshDis::readDistributedMED(const char* pMEDfilename)
721 //cout << "DBG: readDistributedMED" << endl;
722 if (pMEDfilename == NULL) throw NullArgumentException("filename should not be NULL", __FILE__, __LINE__);
724 const int MAX_SIZEOF_LINE = 1024;
727 strcpy(mMEDfilename, pMEDfilename);
729 //---------------------------------------------------------------------
730 // Open master file (ASCII file)
731 //---------------------------------------------------------------------
732 ifstream fileMaster(mMEDfilename);
733 if (fileMaster.fail()) throw IOException("i/o error while opening MED master file", __FILE__, __LINE__);
735 //cout << "DBG: readDistributedMED: open" << endl;
737 //---------------------------------------------------------------------
739 //---------------------------------------------------------------------
740 char charbuffer[MAX_SIZEOF_LINE];
741 fileMaster.getline(charbuffer, MAX_SIZEOF_LINE);
742 if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__);
745 if ((charbuffer[0] != '#') ||
746 (charbuffer[1] != ' ') ||
747 (charbuffer[2] != 'M') ||
748 (charbuffer[3] != 'E') ||
749 (charbuffer[4] != 'D'))
750 throw IOException("not a valid distributed MED file", __FILE__, __LINE__);
752 while ((charbuffer[0] == '#') || (strlen(charbuffer) == 0))
754 fileMaster.getline(charbuffer, MAX_SIZEOF_LINE);
755 if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__);
758 // read number of parts
759 int nbParts = atoi(charbuffer);
760 //cout << "readDistributedMED: #parts=" << nbParts << endl;
762 //---------------------------------------------------------------------
763 // Read infos about sub-parts
764 //---------------------------------------------------------------------
765 char lMeshName[MED_TAILLE_NOM + 1];
767 char lPartName[MED_TAILLE_NOM + 1];
769 char lMEDFileName[256];
771 for (int i = 0 ; i < nbParts ; i++)
773 fileMaster.getline(charbuffer, MAX_SIZEOF_LINE);
774 if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__);
776 while ((charbuffer[0] == '#') || (strlen(charbuffer) == 0))
778 fileMaster.getline(charbuffer, MAX_SIZEOF_LINE);
779 if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__);
786 lMEDFileName[0] = '\0';
788 int ret = sscanf(charbuffer, "%s %d %s %s %s",
795 if (ret != 5) throw IOException("i/o error while reading MED master file; bad format", __FILE__, __LINE__);
797 //cout << "DBG: read: " << lMeshName << " " << lId << " " << lPartName << endl;
799 MeshDisPart::MULTIPR_KEEP_AS_IT,
808 //---------------------------------------------------------------------
810 //---------------------------------------------------------------------
812 if (fileMaster.fail()) throw IOException("i/o error while closing MED master file", __FILE__, __LINE__);
817 * Retrieves the output of MEDSPLITTER and convert it for MULTIPR.
819 int convertMedsplitterToMultipr(ofstream& pFileMaster, const char* pTmpFilename, int pId, MeshDisPart* pPart)
821 MULTIPR_LOG("convert" << endl);
823 const int MAX_SIZEOF_LINE = 1024;
824 char charbuffer[MAX_SIZEOF_LINE];
826 // Open medsplitter master file (ASCII file)
827 ifstream fileMasterMedsplitter(pTmpFilename);
828 if (fileMasterMedsplitter.fail()) throw IOException("i/o error while opening MEDSPLITTER master file", __FILE__, __LINE__);
830 fileMasterMedsplitter.getline(charbuffer, MAX_SIZEOF_LINE);
831 if (fileMasterMedsplitter.fail()) throw IOException("i/o error while reading MEDSPLITTER master file", __FILE__, __LINE__);
833 while ((charbuffer[0] == '#') || (strlen(charbuffer) == 0))
835 fileMasterMedsplitter.getline(charbuffer, MAX_SIZEOF_LINE);
836 if (fileMasterMedsplitter.fail()) throw IOException("i/o error while reading MEDSPLITTER master file", __FILE__, __LINE__);
839 // read number of parts
840 int nbParts = atoi(charbuffer);
841 //cout << "nb parts=" << nbParts << endl;
843 char lMeshName[MED_TAILLE_NOM + 1];
845 char lPartName[MED_TAILLE_NOM + 1];
847 char lMEDFileName[256];
849 for (int i = 0 ; i < nbParts ; i++)
851 fileMasterMedsplitter.getline(charbuffer, MAX_SIZEOF_LINE);
852 if (fileMasterMedsplitter.fail()) throw IOException("", __FILE__, __LINE__);
854 // parses the current line
859 lMEDFileName[0] = '\0';
861 int ret = sscanf(charbuffer, "%s %d %s %s %s",
868 if (ret != 5) throw IOException("i/o error while reading MEDSPLITTER master file; bad format", __FILE__, __LINE__);
870 //cout << lMeshName << " " << (pId + i) << " " << pPart->getPartName() << "_" << (i + 1) << " " << lPath << " " << lMEDFileName << endl;
872 pFileMaster << lMeshName << " " << (pId + i) << " " << pPart->getPartName() << "_" << (i + 1) << " " << lPath << " " << lMEDFileName << endl;
875 fileMasterMedsplitter.close();
876 if (fileMasterMedsplitter.fail()) throw IOException("i/o error while closing MEDSPLITTER master file", __FILE__, __LINE__);
878 // remove master file generated by MEDSPLITTER
879 remove(pTmpFilename);
885 void MeshDis::writeDistributedMED(const char* pMEDfilenamePrefix)
887 if (pMEDfilenamePrefix == NULL) throw NullArgumentException("", __FILE__, __LINE__);
889 //---------------------------------------------------------------------
890 // Build master filename
891 //---------------------------------------------------------------------
892 string strPrefix = string(pMEDfilenamePrefix);
893 const char* strExtension = ".med";
894 string strMasterFilename;
896 // add suffix "_grains_maitre" iff it is not yet in the filename
897 if (strstr(pMEDfilenamePrefix, "_grains_maitre") == 0)
899 strMasterFilename= strPrefix + "_grains_maitre" + strExtension;
903 strMasterFilename = strPrefix + strExtension;
906 MULTIPR_LOG("Create master: " << strMasterFilename << endl);
907 strcpy(mMEDfilename, strMasterFilename.c_str());
909 //---------------------------------------------------------------------
910 // Create an ASCII master file for the resulting distributed mesh and write header
911 //---------------------------------------------------------------------
912 remove(strMasterFilename.c_str());
913 ofstream fileMaster(strMasterFilename.c_str());
915 if (fileMaster == 0) throw IOException("i/o error while creating MED master file", __FILE__, __LINE__);
917 fileMaster << "# MED file v2.3 - Master file created by MULTIPR v" << getVersion() << endl;
918 fileMaster << "#" << " " << endl;
920 fileMaster << computeNumParts() << endl;
921 if (fileMaster.fail()) throw IOException("i/o error while writing MED master file", __FILE__, __LINE__);
923 //---------------------------------------------------------------------
924 // Create a new MED file (v2.3)
925 //---------------------------------------------------------------------
928 if (gProgressCallback != NULL) gProgressCallback->start("Save mesh", mParts.size());
933 // for each sub-meshes
934 for (unsigned itPart = 0 ; itPart < mParts.size() ; itPart++)
936 switch (mParts[itPart]->mToDoOnNextWrite)
938 case MeshDisPart::MULTIPR_KEEP_AS_IT:
940 mParts[itPart]->mId = id;
942 fileMaster << (*mParts[itPart]) << endl;
943 cout << (*mParts[itPart]) << endl;
947 case MeshDisPart::MULTIPR_WRITE_MESH:
949 if (strlen(mParts[itPart]->getMEDFileName()) == 0) throw IOException("MED filename is empty", __FILE__, __LINE__);
950 if (mParts[itPart]->mMesh == NULL) throw IllegalStateException("invalid mesh (shoult not be NULL)", __FILE__, __LINE__);
951 mParts[itPart]->mMesh->writeMED(mParts[itPart]->getMEDFileName());
952 mParts[itPart]->mId = id;
954 fileMaster << (*mParts[itPart]) << endl;
955 cout << (*mParts[itPart]) << endl;
959 case MeshDisPart::MULTIPR_WRITE_PARTS:
961 // split this part using medsplitter
962 if (mParts[itPart]->mOldCollection == NULL) throw IllegalStateException("", __FILE__, __LINE__);
963 string strPrefix = removeExtension(mParts[itPart]->getMEDFileName(), ".med");
964 char tmpFilename[256];
965 sprintf(tmpFilename, "%s_part", strPrefix.c_str());
966 mParts[itPart]->mCollection->write(tmpFilename);
967 mParts[itPart]->mCollection->castAllFields(*(mParts[itPart]->mOldCollection));
968 int ret = convertMedsplitterToMultipr(fileMaster, tmpFilename, id, mParts[itPart]);
970 remove(mParts[itPart]->getMEDFileName());
974 default: throw IllegalStateException("should not be there", __FILE__, __LINE__);
977 if (gProgressCallback != NULL) gProgressCallback->moveOn();
981 catch (RuntimeException& e)
983 if (gProgressCallback != NULL) gProgressCallback->done();
987 if (gProgressCallback != NULL) gProgressCallback->done();
989 //---------------------------------------------------------------------
991 //---------------------------------------------------------------------
993 if (fileMaster.fail()) throw IOException("i/o error while closing MED master file", __FILE__, __LINE__);
997 ostream& operator<<(ostream& pOs, MeshDis& pM)
999 pOs << "Mesh Dis.:" << endl;
1000 pOs << " Filename =|" << pM.mMEDfilename << "|" << endl;
1001 pOs << " #Sub-meshes=" << pM.mParts.size() << endl;
1003 for (unsigned itPart = 0 ; itPart < pM.mParts.size() ; itPart++)
1005 cout << " " << (itPart + 1) << ": " << (*(pM.mParts[itPart])) << endl;
1012 } // namespace multipr