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,
245 //cout << "INSERT PARTS BEFORE: " << endl;
246 //cout << (*this) << endl;
248 MeshDisPart* part = new MeshDisPart();
259 mParts.insert(mParts.begin() + pPosition, part);
261 // rename id of following parts
262 for (unsigned i = pPosition + 1 ; i < mParts.size() ; i++)
268 //cout << "INSERT PARTS AFTER: " << endl;
269 //cout << (*this) << endl;
273 void MeshDis::removeParts(const char* pPrefixPartName)
276 //cout << "REMOVE PARTS BEFORE: " << endl;
277 //cout << (*this) << endl;
279 if (pPrefixPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__);
282 sprintf(strPrefix, "%s_", pPrefixPartName);
284 for (vector<MeshDisPart*>::iterator itPart = mParts.begin() ; itPart != mParts.end() ; itPart++)
286 MeshDisPart* currentPart = (*itPart);
288 // remove part which have the same name and all sub_parts
289 // e.g. if pPrefixPartName="PART_4" => remove "PART_4" and "PART_4_*", but not "PART41"
290 if ((strcmp(currentPart->getPartName(), pPrefixPartName) == 0) ||
291 startWith(currentPart->getPartName(), strPrefix))
293 mParts.erase(itPart);
295 // decrement id of following parts
296 for (vector<MeshDisPart*>::iterator itPart2 = itPart ; itPart2 != mParts.end() ; itPart2++)
302 if (currentPart->mMEDFileName != NULL)
304 remove(currentPart->mMEDFileName);
312 //cout << "REMOVE PARTS AFTER: " << endl;
313 //cout << (*this) << endl;
317 MeshDisPart* MeshDis::findPart(const char* pPartName)
319 if (pPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__);
321 MeshDisPart* part = NULL;
323 for (unsigned itPart = 0 ; itPart < mParts.size() ; itPart++)
325 MeshDisPart* currentPart = mParts[itPart];
327 if (strcmp(currentPart->getPartName(), pPartName) == 0)
339 vector<string> MeshDis::getMeshes() const
343 if (mParts.size() > 0)
345 MeshDisPart* part = mParts[0];
346 const char* meshName = part->getMeshName();
347 res.push_back(meshName);
354 vector<string> MeshDis::getFields() const
358 if (mParts.size() == 0)
363 // all the parts of the distributed MED file should have the same fields
364 // => just return the name of fields of the first part
365 switch (mParts[0]->mToDoOnNextWrite)
367 case MeshDisPart::MULTIPR_KEEP_AS_IT:
368 case MeshDisPart::MULTIPR_WRITE_PARTS:
370 vector<pair<string, int> > tmp = multipr::getListScalarFields(mParts[0]->getMEDFileName());
372 for (int i = 0 ; i < tmp.size() ; i++)
374 res.push_back(tmp[i].first);
379 case MeshDisPart::MULTIPR_WRITE_MESH:
380 return mParts[0]->mMesh->getNameScalarFields();
383 throw IllegalStateException("", __FILE__, __LINE__);
388 int MeshDis::getTimeStamps(const char* pFieldName) const
390 if (mParts.size() == 0)
392 // no parts in this distributed MED file => no fields => #iteration = 0
396 // all the parts of the distributed MED file should have the same fields
397 // => just return the number of iteration found in the field of the first part
398 switch (mParts[0]->mToDoOnNextWrite)
400 case MeshDisPart::MULTIPR_KEEP_AS_IT:
401 case MeshDisPart::MULTIPR_WRITE_PARTS:
403 vector<pair<string, int> > tmp = multipr::getListScalarFields(mParts[0]->getMEDFileName());
405 for (int i = 0 ; i < tmp.size() ; i++)
407 if (strcmp(tmp[i].first.c_str(), pFieldName) == 0)
409 return tmp[i].second;
413 // pFieldName not found in the list of fields
417 case MeshDisPart::MULTIPR_WRITE_MESH:
418 return mParts[0]->mMesh->getTimeStamps(pFieldName);
421 throw IllegalStateException("", __FILE__, __LINE__);
426 string MeshDis::getPartInfo(const char* pPartName)
428 MeshDisPart* part = findPart(pPartName);
433 sprintf(num, "%d", part->mId);
436 string(part->mMeshName) +
440 string(part->mPartName) +
442 string(part->mPath) +
444 string(part->mMEDFileName);
450 // part not found => return empty string
456 void MeshDis::splitPart(const char* pPartName, int pNbParts, int pPartitionner)
458 if (pPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__);
459 if (pNbParts < 2) throw IllegalArgumentException("", __FILE__, __LINE__);
460 if ((pPartitionner != MULTIPR_METIS) && (pPartitionner != MULTIPR_SCOTCH)) throw IllegalArgumentException("should be 0=METIS or 1=SCOTCH", __FILE__, __LINE__);
462 //---------------------------------------------------------------------
463 // Find the MED file corresponding to the given part
464 //---------------------------------------------------------------------
465 MeshDisPart* part = findPart(pPartName);
469 throw IllegalArgumentException("part not found in this distributed MED file", __FILE__, __LINE__);
472 //---------------------------------------------------------------------
473 // Load the sequential MED file
474 //---------------------------------------------------------------------
475 MEDSPLITTER::MESHCollection* collection;
476 collection = new MEDSPLITTER::MESHCollection(part->getMEDFileName(), part->getMeshName());
478 //---------------------------------------------------------------------
479 // Partition the group
480 //---------------------------------------------------------------------
481 MEDSPLITTER::Topology* topology;
482 if (pPartitionner == MULTIPR_METIS)
486 topology = collection->createPartition(pNbParts, MEDSPLITTER::Graph::METIS);
490 throw RuntimeException("MEDSPLITTER error: createPartition(), using METIS", __FILE__, __LINE__);
493 else if (pPartitionner == MULTIPR_SCOTCH)
497 topology = collection->createPartition(pNbParts, MEDSPLITTER::Graph::SCOTCH);
501 throw RuntimeException("MEDSPLITTER error: createPartition(), using SCOTCH", __FILE__, __LINE__);
506 throw IllegalStateException("unknown partitionner", __FILE__, __LINE__);
511 MEDSPLITTER::MESHCollection* newCollection = new MEDSPLITTER::MESHCollection(*collection, topology);
513 part->mToDoOnNextWrite = MeshDisPart::MULTIPR_WRITE_PARTS;
514 part->mSplit = pNbParts;
515 part->mOldCollection = collection;
516 part->mCollection = newCollection;
520 throw RuntimeException("MEDSPLITTER error: new MESHCollection()", __FILE__, __LINE__);
525 void MeshDis::decimatePart(
526 const char* pPartName,
527 const char* pFieldName,
529 const char* pFilterName,
535 //---------------------------------------------------------------------
537 //---------------------------------------------------------------------
538 if (pPartName == NULL) throw NullArgumentException("partname should not be NULL", __FILE__, __LINE__);
539 if (pFieldName == NULL) throw NullArgumentException("fieldname should not be NULL", __FILE__, __LINE__);
540 if (pFieldIt < med_int(1)) throw IllegalArgumentException("invalid field iteration; should be >= 1", __FILE__, __LINE__);
541 if (pTMed < 0.0) throw IllegalArgumentException("med res.: threshold must be > 0", __FILE__, __LINE__);
542 if (pTMed >= pTLow) throw IllegalArgumentException("threshold for med res. must be < threshold for low res.", __FILE__, __LINE__);
543 if (pRadius <= med_float(0.0)) throw IllegalArgumentException("radius should be > 0", __FILE__, __LINE__);
544 if ((pBoxing < 1) || (pBoxing > 200)) throw IllegalArgumentException("boxing should be in [1..200]", __FILE__, __LINE__);
546 //---------------------------------------------------------------------
547 // Find the MED file corresponding to the given part
548 //---------------------------------------------------------------------
549 MeshDisPart* part = findPart(pPartName);
552 throw IllegalArgumentException("part not found in the given distributed MED file", __FILE__, __LINE__);
555 //---------------------------------------------------------------------
556 // Load the associated sequential MED file
557 //---------------------------------------------------------------------
558 if (part->mMesh == NULL)
563 Mesh* meshFull = part->mMesh;
564 cout << (*meshFull) << endl;
566 const char* originalFilename = part->getMEDFileName();
567 string strPrefix = removeExtension(originalFilename, ".med");
570 //cout << (*this) << endl;
572 //---------------------------------------------------------------------
573 // Decimates the given mesh
574 //---------------------------------------------------------------------
575 // arguments for decimation are passed as a string for genericity
577 char newPartName[MED_TAILLE_NOM + 1];
578 char newMEDFileName[256];
580 // *** create a new mesh = MEDIUM resolution ***
581 sprintf(argv, "%s %d %lf %lf %d", pFieldName, pFieldIt, pTMed, pRadius, pBoxing);
582 sprintf(newPartName, "%s_MED", pPartName);
583 sprintf(newMEDFileName, "%s_gradmoy-med-%s-%s.med",
585 realToString(pTMed).c_str(),
586 realToString(pRadius).c_str());
589 Mesh* meshMedium = meshFull->decimate(pFilterName, argv, part->getMeshName());
590 cout << (*meshMedium) << endl;
593 MeshDisPart::MULTIPR_WRITE_MESH,
603 // *** create a new mesh = LOW resolution ***
604 sprintf(argv, "%s %d %lf %lf %d", pFieldName, pFieldIt, pTLow, pRadius, pBoxing);
605 sprintf(newPartName, "%s_LOW", pPartName);
606 sprintf(newMEDFileName, "%s_gradmoy-low-%s-%s.med",
608 realToString(pTLow).c_str(),
609 realToString(pRadius).c_str());
612 Mesh* meshLow = meshFull->decimate(pFilterName, argv, part->getMeshName());
613 cout << (*meshLow) << endl;
616 MeshDisPart::MULTIPR_WRITE_MESH,
627 //cout << (*this) << endl;
631 string MeshDis::evalDecimationParams(
632 const char* pPartName,
633 const char* pFieldName,
635 const char* pFilterName,
636 const char* pFilterParams)
638 MeshDisPart* part = findPart(pPartName);
639 if (part == NULL) return "";
643 if (part->mMesh == NULL)
648 multipr::DecimationFilter* filter = multipr::DecimationFilter::create(pFilterName);
649 if (filter == NULL) return "";
651 multipr::DecimationFilterGradAvg* filterGrad = dynamic_cast<multipr::DecimationFilterGradAvg*>(filter);
653 if (filterGrad != NULL)
657 int ret = sscanf(pFilterParams, "%d", &mode);
659 // mode 2 = GET RADIUS
660 if ((ret == 1) && (mode == 2))
662 double radius = part->mMesh->evalDefaultRadius(8);
664 sprintf(res, "%f", radius);
671 ret = sscanf(pFilterParams, "%d %f %d", &mode, &radius, &boxing);
673 // mode 1 = GET GRADIENT MIN, MAX and AVG
674 if ((ret == 3) && (mode == 1))
676 double gradMin = 0.1, gradAvg = 0.15, gradMax = 0.2;
678 filterGrad->getGradientInfo(
689 sprintf(res, "%f %f %f", gradMin, gradAvg, gradMax);
703 int MeshDis::computeNumParts()
707 for (unsigned itPart = 0 ; itPart < mParts.size() ; itPart++)
709 switch (mParts[itPart]->mToDoOnNextWrite)
711 case MeshDisPart::MULTIPR_KEEP_AS_IT:
712 case MeshDisPart::MULTIPR_WRITE_MESH:
716 case MeshDisPart::MULTIPR_WRITE_PARTS:
717 numParts += mParts[itPart]->mSplit;
720 default: throw IllegalStateException("", __FILE__, __LINE__);
728 void MeshDis::readDistributedMED(const char* pMEDfilename)
730 //cout << "DBG: readDistributedMED" << endl;
731 if (pMEDfilename == NULL) throw NullArgumentException("filename should not be NULL", __FILE__, __LINE__);
733 const int MAX_SIZEOF_LINE = 1024;
736 strcpy(mMEDfilename, pMEDfilename);
738 //---------------------------------------------------------------------
739 // Open master file (ASCII file)
740 //---------------------------------------------------------------------
741 ifstream fileMaster(mMEDfilename);
742 if (fileMaster.fail()) throw IOException("i/o error while opening MED master file", __FILE__, __LINE__);
744 //cout << "DBG: readDistributedMED: open" << endl;
746 //---------------------------------------------------------------------
748 //---------------------------------------------------------------------
749 char charbuffer[MAX_SIZEOF_LINE];
750 fileMaster.getline(charbuffer, MAX_SIZEOF_LINE);
751 if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__);
754 if ((charbuffer[0] != '#') ||
755 (charbuffer[1] != ' ') ||
756 (charbuffer[2] != 'M') ||
757 (charbuffer[3] != 'E') ||
758 (charbuffer[4] != 'D'))
759 throw IOException("not a valid distributed MED file", __FILE__, __LINE__);
761 while ((charbuffer[0] == '#') || (strlen(charbuffer) == 0))
763 fileMaster.getline(charbuffer, MAX_SIZEOF_LINE);
764 if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__);
767 // read number of parts
768 int nbParts = atoi(charbuffer);
769 //cout << "DBG: readDistributedMED: #parts=" << nbParts << endl;
771 //---------------------------------------------------------------------
772 // Read infos about sub-parts
773 //---------------------------------------------------------------------
774 char lMeshName[MED_TAILLE_NOM + 1];
776 char lPartName[MED_TAILLE_NOM + 1];
778 char lMEDFileName[256];
780 for (int i = 0 ; i < nbParts ; i++)
782 fileMaster.getline(charbuffer, MAX_SIZEOF_LINE);
783 if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__);
785 while ((charbuffer[0] == '#') || (strlen(charbuffer) == 0))
787 fileMaster.getline(charbuffer, MAX_SIZEOF_LINE);
788 if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__);
795 lMEDFileName[0] = '\0';
797 int ret = sscanf(charbuffer, "%s %d %s %s %s",
804 if (ret != 5) throw IOException("i/o error while reading MED master file; bad format", __FILE__, __LINE__);
806 //cout << "DBG: read: " << lMeshName << " " << lId << " " << lPartName << endl;
808 MeshDisPart::MULTIPR_KEEP_AS_IT,
817 //---------------------------------------------------------------------
819 //---------------------------------------------------------------------
821 if (fileMaster.fail()) throw IOException("i/o error while closing MED master file", __FILE__, __LINE__);
822 //cout << "DBG: readDistributedMED: close" << endl;
827 * Retrieves the output of MEDSPLITTER and convert it for MULTIPR.
829 int convertMedsplitterToMultipr(ofstream& pFileMaster, const char* pTmpFilename, int pId, MeshDisPart* pPart)
831 MULTIPR_LOG("convert" << endl);
833 const int MAX_SIZEOF_LINE = 1024;
834 char charbuffer[MAX_SIZEOF_LINE];
836 // Open medsplitter master file (ASCII file)
837 ifstream fileMasterMedsplitter(pTmpFilename);
838 if (fileMasterMedsplitter.fail()) throw IOException("i/o error while opening MEDSPLITTER master file", __FILE__, __LINE__);
840 fileMasterMedsplitter.getline(charbuffer, MAX_SIZEOF_LINE);
841 if (fileMasterMedsplitter.fail()) throw IOException("i/o error while reading MEDSPLITTER master file", __FILE__, __LINE__);
843 while ((charbuffer[0] == '#') || (strlen(charbuffer) == 0))
845 fileMasterMedsplitter.getline(charbuffer, MAX_SIZEOF_LINE);
846 if (fileMasterMedsplitter.fail()) throw IOException("i/o error while reading MEDSPLITTER master file", __FILE__, __LINE__);
849 // read number of parts
850 int nbParts = atoi(charbuffer);
851 //cout << "nb parts=" << nbParts << endl;
853 char lMeshName[MED_TAILLE_NOM + 1];
855 char lPartName[MED_TAILLE_NOM + 1];
857 char lMEDFileName[256];
859 for (int i = 0 ; i < nbParts ; i++)
861 fileMasterMedsplitter.getline(charbuffer, MAX_SIZEOF_LINE);
862 if (fileMasterMedsplitter.fail()) throw IOException("", __FILE__, __LINE__);
864 // parses the current line
869 lMEDFileName[0] = '\0';
871 int ret = sscanf(charbuffer, "%s %d %s %s %s",
878 if (ret != 5) throw IOException("i/o error while reading MEDSPLITTER master file; bad format", __FILE__, __LINE__);
880 //cout << lMeshName << " " << (pId + i) << " " << pPart->getPartName() << "_" << (i + 1) << " " << lPath << " " << lMEDFileName << endl;
882 pFileMaster << lMeshName << " " << (pId + i) << " " << pPart->getPartName() << "_" << (i + 1) << " " << lPath << " " << lMEDFileName << endl;
885 fileMasterMedsplitter.close();
886 if (fileMasterMedsplitter.fail()) throw IOException("i/o error while closing MEDSPLITTER master file", __FILE__, __LINE__);
888 // remove master file generated by MEDSPLITTER
889 remove(pTmpFilename);
895 void MeshDis::writeDistributedMED(const char* pMEDfilenamePrefix)
897 if (pMEDfilenamePrefix == NULL) throw NullArgumentException("", __FILE__, __LINE__);
899 //---------------------------------------------------------------------
900 // Build master filename
901 //---------------------------------------------------------------------
902 string strPrefix = string(pMEDfilenamePrefix);
903 const char* strExtension = ".med";
904 string strMasterFilename;
906 // add suffix "_grains_maitre" iff it is not yet in the filename
907 if (strstr(pMEDfilenamePrefix, "_grains_maitre") == 0)
909 strMasterFilename= strPrefix + "_grains_maitre" + strExtension;
913 strMasterFilename = strPrefix + strExtension;
916 MULTIPR_LOG("Create master: " << strMasterFilename << endl);
917 strcpy(mMEDfilename, strMasterFilename.c_str());
919 //---------------------------------------------------------------------
920 // Create an ASCII master file for the resulting distributed mesh and write header
921 //---------------------------------------------------------------------
922 remove(strMasterFilename.c_str());
923 ofstream fileMaster(strMasterFilename.c_str());
925 if (fileMaster == 0) throw IOException("i/o error while creating MED master file", __FILE__, __LINE__);
927 fileMaster << "# MED file v2.3 - Master file created by MULTIPR v" << getVersion() << endl;
928 fileMaster << "#" << " " << endl;
930 fileMaster << computeNumParts() << endl;
931 if (fileMaster.fail()) throw IOException("i/o error while writing MED master file", __FILE__, __LINE__);
933 //---------------------------------------------------------------------
934 // Create a new MED file (v2.3)
935 //---------------------------------------------------------------------
938 if (gProgressCallback != NULL) gProgressCallback->start("Save mesh", mParts.size());
943 // for each sub-meshes
944 for (unsigned itPart = 0 ; itPart < mParts.size() ; itPart++)
946 switch (mParts[itPart]->mToDoOnNextWrite)
948 case MeshDisPart::MULTIPR_KEEP_AS_IT:
950 mParts[itPart]->mId = id;
952 fileMaster << (*mParts[itPart]) << endl;
953 cout << (*mParts[itPart]) << endl;
957 case MeshDisPart::MULTIPR_WRITE_MESH:
959 if (strlen(mParts[itPart]->getMEDFileName()) == 0) throw IOException("MED filename is empty", __FILE__, __LINE__);
960 if (mParts[itPart]->mMesh == NULL) throw IllegalStateException("invalid mesh (shoult not be NULL)", __FILE__, __LINE__);
961 mParts[itPart]->mMesh->writeMED(mParts[itPart]->getMEDFileName());
962 mParts[itPart]->mId = id;
964 fileMaster << (*mParts[itPart]) << endl;
965 cout << (*mParts[itPart]) << endl;
969 case MeshDisPart::MULTIPR_WRITE_PARTS:
971 // split this part using medsplitter
972 if (mParts[itPart]->mOldCollection == NULL) throw IllegalStateException("", __FILE__, __LINE__);
973 string strPrefix = removeExtension(mParts[itPart]->getMEDFileName(), ".med");
974 char tmpFilename[256];
975 sprintf(tmpFilename, "%s_part", strPrefix.c_str());
976 mParts[itPart]->mCollection->write(tmpFilename);
977 mParts[itPart]->mCollection->castAllFields(*(mParts[itPart]->mOldCollection));
978 int ret = convertMedsplitterToMultipr(fileMaster, tmpFilename, id, mParts[itPart]);
980 remove(mParts[itPart]->getMEDFileName());
984 default: throw IllegalStateException("should not be there", __FILE__, __LINE__);
987 if (gProgressCallback != NULL) gProgressCallback->moveOn();
991 catch (RuntimeException& e)
993 if (gProgressCallback != NULL) gProgressCallback->done();
997 if (gProgressCallback != NULL) gProgressCallback->done();
999 //---------------------------------------------------------------------
1000 // Close master file
1001 //---------------------------------------------------------------------
1003 if (fileMaster.fail()) throw IOException("i/o error while closing MED master file", __FILE__, __LINE__);
1007 ostream& operator<<(ostream& pOs, MeshDis& pM)
1009 pOs << "Mesh Dis.:" << endl;
1010 pOs << " Filename =|" << pM.mMEDfilename << "|" << endl;
1011 pOs << " #Sub-meshes=" << pM.mParts.size() << endl;
1013 for (unsigned itPart = 0 ; itPart < pM.mParts.size() ; itPart++)
1015 cout << " " << (itPart + 1) << ": " << (*(pM.mParts[itPart])) << endl;
1022 } // namespace multipr