1 // Project MULTIPR, IOLS WP1.2.1 - EDF/CS
2 // Partitioning/decimation module for the SALOME v3.2 platform
5 * \file MULTIPR_API.cxx
7 * \brief see MULTIPR_API.hxx
9 * \author Olivier LE ROUX - CS, Virtual Reality Dpt
14 //*****************************************************************************
16 //*****************************************************************************
18 #include "MULTIPR_API.hxx"
19 #include "MULTIPR_Globals.hxx"
20 #include "MULTIPR_Mesh.hxx"
21 #include "MULTIPR_MeshDis.hxx"
22 #include "MULTIPR_Utils.hxx"
23 #include "MULTIPR_Exceptions.hxx"
30 #include "MEDSPLITTER_API.hxx"
39 //*****************************************************************************
41 //*****************************************************************************
43 const char* multipr::getVersion()
49 void multipr::partitionneDomaine(const char* pMEDfilename, const char* pMeshName)
51 if (pMEDfilename == NULL) throw NullArgumentException("pMEDfilename should not be NULL", __FILE__, __LINE__);
52 if (pMeshName == NULL) throw NullArgumentException("pMeshName should not be NULL", __FILE__, __LINE__);
54 //---------------------------------------------------------------------
55 // Read the sequential mesh
56 //---------------------------------------------------------------------
57 cout << "Read sequential MED file: " << pMEDfilename << ": please wait... " << endl;
60 mesh.readSequentialMED(pMEDfilename, pMeshName);
63 //---------------------------------------------------------------------
64 // Build distributed mesh from groups
65 //---------------------------------------------------------------------
66 cout << "Build distributed mesh: please wait... " << endl;
67 multipr::MeshDis* meshDis = NULL;
70 meshDis = mesh.splitGroupsOfElements();
72 //-------------------------------------------------------------
73 // Write distributed mesh
74 //-------------------------------------------------------------
75 cout << "Write distributed mesh: please wait... " << endl;
76 string strPrefix = removeExtension(pMEDfilename, ".med");
77 meshDis->writeDistributedMED(strPrefix.c_str());
81 catch (RuntimeException& e)
89 void multipr::partitionneGrain(
90 const char* pMEDfilename,
91 const char* pGroupName,
95 if (pMEDfilename == NULL) throw NullArgumentException("pMEDfilename should not be NULL", __FILE__, __LINE__);
96 if (pGroupName == NULL) throw NullArgumentException("pGroupName should not be NULL", __FILE__, __LINE__);
97 if (pNbParts < 2) throw IllegalArgumentException("pNbParts should be >= 2", __FILE__, __LINE__);
98 if ((pPartitionner != MULTIPR_METIS) && (pPartitionner != MULTIPR_SCOTCH)) throw NullArgumentException("pPartitionner should be METIS (0) or SCOTCH (1)", __FILE__, __LINE__);
100 //---------------------------------------------------------------------
101 // Read the distributed mesh
102 //---------------------------------------------------------------------
103 MULTIPR_LOG("Read distributed MED file: " << pMEDfilename << ": please wait... " << endl);
105 int ret = MEDformatConforme(pMEDfilename);
106 if (ret == 0) throw IOException("waiting for a distributed MED file (not a sequential one)", __FILE__, __LINE__);
108 multipr::MeshDis meshDis;
109 meshDis.readDistributedMED(pMEDfilename);
110 cout << meshDis << endl;
112 //---------------------------------------------------------------------
113 // Split the given part (pGroupName)
114 //---------------------------------------------------------------------
115 if (pPartitionner == MULTIPR_METIS)
117 cout << "Use METIS" << endl;
119 else if (pPartitionner == MULTIPR_SCOTCH)
121 cout << "Use SCOTCH" << endl;
124 meshDis.splitPart(pGroupName, pNbParts, pPartitionner);
125 cout << meshDis << endl;
127 //---------------------------------------------------------------------
128 // Write new distributed mesh
129 //---------------------------------------------------------------------
130 string strPrefix = multipr::removeExtension(pMEDfilename, ".med");
131 meshDis.writeDistributedMED(strPrefix.c_str());
135 void multipr::decimePartition(
136 const char* pMEDfilename,
137 const char* pPartName,
138 const char* pFieldName,
140 const char* pFilterName,
146 //---------------------------------------------------------------------
148 //---------------------------------------------------------------------
149 if (pMEDfilename == NULL) throw NullArgumentException("pMEDfilename should not be NULL", __FILE__, __LINE__);
150 if (pPartName == NULL) throw NullArgumentException("pPartName should not be NULL", __FILE__, __LINE__);
151 if (pFieldName == NULL) throw NullArgumentException("pFieldName should not be NULL", __FILE__, __LINE__);
152 if (pFieldIt < 1) throw IllegalArgumentException("pFieldIt: invalid field iteration; should be >= 1", __FILE__, __LINE__);
153 if (pTMed < 0.0) throw IllegalArgumentException("med res.: threshold must be > 0", __FILE__, __LINE__);
154 if (pTMed >= pTLow) throw IllegalArgumentException("threshold for med res. must be < threshold for low res.", __FILE__, __LINE__);
155 if (pRadius <= 0.0) throw IllegalArgumentException("radius should be > 0", __FILE__, __LINE__);
156 if ((pBoxing < 1) || (pBoxing > 200)) throw IllegalArgumentException("boxing should be in [1..200]", __FILE__, __LINE__);
158 cout << "--decim file=" << pMEDfilename << " part=" << pPartName << " filter=" << pFilterName << " tmed=" << pTMed << " tlow=" << pTLow << " radius=" << pRadius << endl;
160 //---------------------------------------------------------------------
161 // Read the distributed mesh
162 //---------------------------------------------------------------------
163 MULTIPR_LOG("Read distributed MED file: " << pMEDfilename << ": please wait... " << endl);
165 int ret = MEDformatConforme(pMEDfilename);
166 if (ret == 0) throw IOException("waiting for a distributed MED file (not a sequential one)", __FILE__, __LINE__);
168 multipr::MeshDis meshDis;
169 meshDis.readDistributedMED(pMEDfilename);
170 cout << meshDis << endl;
172 //---------------------------------------------------------------------
173 // Create 3 resolutions of the given part
174 //---------------------------------------------------------------------
175 meshDis.decimatePart(
184 cout << meshDis << endl;
186 //---------------------------------------------------------------------
187 // Write new distributed mesh
188 //---------------------------------------------------------------------
189 string strPrefix = removeExtension(pMEDfilename, ".med"); // get prefix from the original MED filename
190 meshDis.writeDistributedMED(strPrefix.c_str());