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");
569 cout << (*this) << endl;
570 //---------------------------------------------------------------------
571 // Decimates the given mesh
572 //---------------------------------------------------------------------
573 // arguments for decimation are passed as a string for genericity
575 char newPartName[MED_TAILLE_NOM + 1];
576 char newMEDFileName[256];
578 // *** create a new mesh = MEDIUM resolution ***
579 sprintf(argv, "%s %d %lf %lf %d", pFieldName, pFieldIt, pTMed, pRadius, pBoxing);
580 sprintf(newPartName, "%s_MED", pPartName);
581 sprintf(newMEDFileName, "%s_gradmoy-med-%s-%s.med",
583 realToString(pTMed).c_str(),
584 realToString(pRadius).c_str());
587 Mesh* meshMedium = meshFull->decimate(pFilterName, argv, part->getMeshName());
588 cout << (*meshMedium) << endl;
591 MeshDisPart::MULTIPR_WRITE_MESH,
601 // *** create a new mesh = LOW resolution ***
602 sprintf(argv, "%s %d %lf %lf %d", pFieldName, pFieldIt, pTLow, pRadius, pBoxing);
603 sprintf(newPartName, "%s_LOW", pPartName);
604 sprintf(newMEDFileName, "%s_gradmoy-low-%s-%s.med",
606 realToString(pTLow).c_str(),
607 realToString(pRadius).c_str());
610 Mesh* meshLow = meshFull->decimate(pFilterName, argv, part->getMeshName());
611 cout << (*meshLow) << endl;
614 MeshDisPart::MULTIPR_WRITE_MESH,
625 //cout << (*this) << endl;
629 string MeshDis::evalDecimationParams(
630 const char* pPartName,
631 const char* pFieldName,
633 const char* pFilterName,
634 const char* pFilterParams)
636 MeshDisPart* part = findPart(pPartName);
637 if (part == NULL) return "";
641 if (part->mMesh == NULL)
646 multipr::DecimationFilter* filter = multipr::DecimationFilter::create(pFilterName);
647 if (filter == NULL) return "";
649 multipr::DecimationFilterGradAvg* filterGrad = dynamic_cast<multipr::DecimationFilterGradAvg*>(filter);
651 if (filterGrad != NULL)
655 int ret = sscanf(pFilterParams, "%d", &mode);
657 // mode 2 = GET RADIUS
658 if ((ret == 1) && (mode == 2))
660 double radius = part->mMesh->evalDefaultRadius(8);
662 sprintf(res, "%f", radius);
669 ret = sscanf(pFilterParams, "%d %f %d", &mode, &radius, &boxing);
671 // mode 1 = GET GRADIENT MIN, MAX and AVG
672 if ((ret == 3) && (mode == 1))
674 double gradMin = 0.1, gradAvg = 0.15, gradMax = 0.2;
676 filterGrad->getGradientInfo(
687 sprintf(res, "%f %f %f", gradMin, gradAvg, gradMax);
701 int MeshDis::computeNumParts()
705 for (unsigned itPart = 0 ; itPart < mParts.size() ; itPart++)
707 switch (mParts[itPart]->mToDoOnNextWrite)
709 case MeshDisPart::MULTIPR_KEEP_AS_IT:
710 case MeshDisPart::MULTIPR_WRITE_MESH:
714 case MeshDisPart::MULTIPR_WRITE_PARTS:
715 numParts += mParts[itPart]->mSplit;
718 default: throw IllegalStateException("", __FILE__, __LINE__);
726 void MeshDis::readDistributedMED(const char* pMEDfilename)
728 //cout << "DBG: readDistributedMED" << endl;
729 if (pMEDfilename == NULL) throw NullArgumentException("filename should not be NULL", __FILE__, __LINE__);
731 const int MAX_SIZEOF_LINE = 1024;
734 strcpy(mMEDfilename, pMEDfilename);
736 //---------------------------------------------------------------------
737 // Open master file (ASCII file)
738 //---------------------------------------------------------------------
739 ifstream fileMaster(mMEDfilename);
740 if (fileMaster.fail()) throw IOException("i/o error while opening MED master file", __FILE__, __LINE__);
742 //cout << "DBG: readDistributedMED: open" << endl;
744 //---------------------------------------------------------------------
746 //---------------------------------------------------------------------
747 char charbuffer[MAX_SIZEOF_LINE];
748 fileMaster.getline(charbuffer, MAX_SIZEOF_LINE);
749 if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__);
752 if ((charbuffer[0] != '#') ||
753 (charbuffer[1] != ' ') ||
754 (charbuffer[2] != 'M') ||
755 (charbuffer[3] != 'E') ||
756 (charbuffer[4] != 'D'))
757 throw IOException("not a valid distributed MED file", __FILE__, __LINE__);
759 while ((charbuffer[0] == '#') || (strlen(charbuffer) == 0))
761 fileMaster.getline(charbuffer, MAX_SIZEOF_LINE);
762 if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__);
765 // read number of parts
766 int nbParts = atoi(charbuffer);
767 //cout << "DBG: readDistributedMED: #parts=" << nbParts << endl;
769 //---------------------------------------------------------------------
770 // Read infos about sub-parts
771 //---------------------------------------------------------------------
772 char lMeshName[MED_TAILLE_NOM + 1];
774 char lPartName[MED_TAILLE_NOM + 1];
776 char lMEDFileName[256];
778 for (int i = 0 ; i < nbParts ; i++)
780 fileMaster.getline(charbuffer, MAX_SIZEOF_LINE);
781 if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__);
783 while ((charbuffer[0] == '#') || (strlen(charbuffer) == 0))
785 fileMaster.getline(charbuffer, MAX_SIZEOF_LINE);
786 if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__);
793 lMEDFileName[0] = '\0';
795 int ret = sscanf(charbuffer, "%s %d %s %s %s",
802 if (ret != 5) throw IOException("i/o error while reading MED master file; bad format", __FILE__, __LINE__);
804 //cout << "DBG: read: " << lMeshName << " " << lId << " " << lPartName << endl;
806 MeshDisPart::MULTIPR_KEEP_AS_IT,
815 //---------------------------------------------------------------------
817 //---------------------------------------------------------------------
819 if (fileMaster.fail()) throw IOException("i/o error while closing MED master file", __FILE__, __LINE__);
820 //cout << "DBG: readDistributedMED: close" << endl;
825 * Retrieves the output of MEDSPLITTER and convert it for MULTIPR.
827 int convertMedsplitterToMultipr(ofstream& pFileMaster, const char* pTmpFilename, int pId, MeshDisPart* pPart)
829 MULTIPR_LOG("convert" << endl);
831 const int MAX_SIZEOF_LINE = 1024;
832 char charbuffer[MAX_SIZEOF_LINE];
834 // Open medsplitter master file (ASCII file)
835 ifstream fileMasterMedsplitter(pTmpFilename);
836 if (fileMasterMedsplitter.fail()) throw IOException("i/o error while opening MEDSPLITTER master file", __FILE__, __LINE__);
838 fileMasterMedsplitter.getline(charbuffer, MAX_SIZEOF_LINE);
839 if (fileMasterMedsplitter.fail()) throw IOException("i/o error while reading MEDSPLITTER master file", __FILE__, __LINE__);
841 while ((charbuffer[0] == '#') || (strlen(charbuffer) == 0))
843 fileMasterMedsplitter.getline(charbuffer, MAX_SIZEOF_LINE);
844 if (fileMasterMedsplitter.fail()) throw IOException("i/o error while reading MEDSPLITTER master file", __FILE__, __LINE__);
847 // read number of parts
848 int nbParts = atoi(charbuffer);
849 cout << "nb parts=" << nbParts << endl;
851 char lMeshName[MED_TAILLE_NOM + 1];
853 char lPartName[MED_TAILLE_NOM + 1];
855 char lMEDFileName[256];
857 for (int i = 0 ; i < nbParts ; i++)
859 fileMasterMedsplitter.getline(charbuffer, MAX_SIZEOF_LINE);
860 if (fileMasterMedsplitter.fail()) throw IOException("", __FILE__, __LINE__);
862 // parses the current line
867 lMEDFileName[0] = '\0';
869 int ret = sscanf(charbuffer, "%s %d %s %s %s",
876 if (ret != 5) throw IOException("i/o error while reading MEDSPLITTER master file; bad format", __FILE__, __LINE__);
878 //cout << lMeshName << " " << (pId + i) << " " << pPart->getPartName() << "_" << (i + 1) << " " << lPath << " " << lMEDFileName << endl;
880 pFileMaster << lMeshName << " " << (pId + i) << " " << pPart->getPartName() << "_" << (i + 1) << " " << lPath << " " << lMEDFileName << endl;
883 fileMasterMedsplitter.close();
884 if (fileMasterMedsplitter.fail()) throw IOException("i/o error while closing MEDSPLITTER master file", __FILE__, __LINE__);
886 // remove master file generated by MEDSPLITTER
887 remove(pTmpFilename);
893 void MeshDis::writeDistributedMED(const char* pMEDfilenamePrefix)
895 if (pMEDfilenamePrefix == NULL) throw NullArgumentException("", __FILE__, __LINE__);
897 //---------------------------------------------------------------------
898 // Build master filename
899 //---------------------------------------------------------------------
900 string strPrefix = string(pMEDfilenamePrefix);
901 const char* strExtension = ".med";
902 string strMasterFilename;
904 // add suffix "_grains_maitre" iff it is not yet in the filename
905 if (strstr(pMEDfilenamePrefix, "_grains_maitre") == 0)
907 strMasterFilename= strPrefix + "_grains_maitre" + strExtension;
911 strMasterFilename = strPrefix + strExtension;
914 MULTIPR_LOG("Create master: " << strMasterFilename << endl);
915 strcpy(mMEDfilename, strMasterFilename.c_str());
917 //---------------------------------------------------------------------
918 // Create an ASCII master file for the resulting distributed mesh and write header
919 //---------------------------------------------------------------------
920 remove(strMasterFilename.c_str());
921 ofstream fileMaster(strMasterFilename.c_str());
923 if (fileMaster == 0) throw IOException("i/o error while creating MED master file", __FILE__, __LINE__);
925 fileMaster << "# MED file v2.3 - Master file created by MULTIPR v" << getVersion() << endl;
926 fileMaster << "#" << " " << endl;
928 fileMaster << computeNumParts() << endl;
929 if (fileMaster.fail()) throw IOException("i/o error while writing MED master file", __FILE__, __LINE__);
931 //---------------------------------------------------------------------
932 // Create a new MED file (v2.3)
933 //---------------------------------------------------------------------
936 if (gProgressCallback != NULL) gProgressCallback->start("Save mesh", mParts.size());
941 // for each sub-meshes
942 for (unsigned itPart = 0 ; itPart < mParts.size() ; itPart++)
944 switch (mParts[itPart]->mToDoOnNextWrite)
946 case MeshDisPart::MULTIPR_KEEP_AS_IT:
948 mParts[itPart]->mId = id;
950 fileMaster << (*mParts[itPart]) << endl;
951 cout << (*mParts[itPart]) << endl;
955 case MeshDisPart::MULTIPR_WRITE_MESH:
957 if (strlen(mParts[itPart]->getMEDFileName()) == 0) throw IOException("MED filename is empty", __FILE__, __LINE__);
958 if (mParts[itPart]->mMesh == NULL) throw IllegalStateException("invalid mesh (shoult not be NULL)", __FILE__, __LINE__);
959 mParts[itPart]->mMesh->writeMED(mParts[itPart]->getMEDFileName());
960 mParts[itPart]->mId = id;
962 fileMaster << (*mParts[itPart]) << endl;
963 cout << (*mParts[itPart]) << endl;
967 case MeshDisPart::MULTIPR_WRITE_PARTS:
969 // split this part using medsplitter
970 if (mParts[itPart]->mOldCollection == NULL) throw IllegalStateException("", __FILE__, __LINE__);
971 string strPrefix = removeExtension(mParts[itPart]->getMEDFileName(), ".med");
972 char tmpFilename[256];
973 sprintf(tmpFilename, "%s_part", strPrefix.c_str());
974 mParts[itPart]->mCollection->write(tmpFilename);
975 mParts[itPart]->mCollection->castAllFields(*(mParts[itPart]->mOldCollection));
976 int ret = convertMedsplitterToMultipr(fileMaster, tmpFilename, id, mParts[itPart]);
978 remove(mParts[itPart]->getMEDFileName());
982 default: throw IllegalStateException("should not be there", __FILE__, __LINE__);
985 if (gProgressCallback != NULL) gProgressCallback->moveOn();
989 catch (RuntimeException& e)
991 if (gProgressCallback != NULL) gProgressCallback->done();
995 if (gProgressCallback != NULL) gProgressCallback->done();
997 //---------------------------------------------------------------------
999 //---------------------------------------------------------------------
1001 if (fileMaster.fail()) throw IOException("i/o error while closing MED master file", __FILE__, __LINE__);
1005 ostream& operator<<(ostream& pOs, MeshDis& pM)
1007 pOs << "Mesh Dis.:" << endl;
1008 pOs << " Filename =|" << pM.mMEDfilename << "|" << endl;
1009 pOs << " #Sub-meshes=" << pM.mParts.size() << endl;
1011 for (unsigned itPart = 0 ; itPart < pM.mParts.size() ; itPart++)
1013 cout << " " << (itPart + 1) << ": " << (*(pM.mParts[itPart])) << endl;
1020 } // namespace multipr