]> SALOME platform Git repositories - modules/multipr.git/blob - src/MULTIPR/MULTIPR_API.cxx
Salome HOME
5c5fda555d574efe2fa7b7fe24cb6a903a535e62
[modules/multipr.git] / src / MULTIPR / MULTIPR_API.cxx
1 // Project MULTIPR, IOLS WP1.2.1 - EDF/CS
2 // Partitioning/decimation module for the SALOME v3.2 platform
3
4 /**
5  * \file    MULTIPR_API.cxx
6  *
7  * \brief   see MULTIPR_API.hxx
8  *
9  * \author  Olivier LE ROUX - CS, Virtual Reality Dpt
10  * 
11  * \date    01/2007
12  */
13
14 //*****************************************************************************
15 // Includes section
16 //*****************************************************************************
17
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"
24
25 extern "C"
26 {
27         #include "med.h"
28 }
29
30 #include "MEDSPLITTER_API.hxx"
31
32 #include <iostream>
33 #include <fstream>
34 #include <string>
35
36 using namespace std;
37
38
39 //*****************************************************************************
40 // Implementation
41 //*****************************************************************************
42
43 const char* multipr::getVersion()
44 {
45         return "1.0";
46 }
47
48
49 void multipr::partitionneDomaine(const char* pMEDfilename, const char* pMeshName)
50 {       
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__);
53         
54         //---------------------------------------------------------------------
55         // Read the sequential mesh
56         //---------------------------------------------------------------------
57         cout << "Read sequential MED file: " << pMEDfilename << ": please wait... " << endl;
58         
59         multipr::Mesh mesh;
60         mesh.readSequentialMED(pMEDfilename, pMeshName);
61         cout << mesh << endl;
62         
63         //---------------------------------------------------------------------
64         // Build distributed mesh from groups
65         //---------------------------------------------------------------------
66         cout << "Build distributed mesh: please wait... " << endl;
67         multipr::MeshDis* meshDis = NULL;
68         try
69         {
70                 meshDis = mesh.splitGroupsOfElements();
71         
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());
78                 
79                 delete meshDis;
80         }
81         catch (RuntimeException& e)
82         {
83                 delete meshDis;
84                 throw e;
85         }
86 }
87
88
89 void multipr::partitionneGrain(
90         const char* pMEDfilename, 
91         const char* pGroupName, 
92         int         pNbParts, 
93         int         pPartitionner)
94 {
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__);
99         
100         //---------------------------------------------------------------------
101         // Read the distributed mesh
102         //---------------------------------------------------------------------
103         MULTIPR_LOG("Read distributed MED file: " << pMEDfilename << ": please wait... " << endl);
104         
105         int ret = MEDformatConforme(pMEDfilename);
106         if (ret == 0) throw IOException("waiting for a distributed MED file (not a sequential one)", __FILE__, __LINE__);
107
108         multipr::MeshDis meshDis;
109         meshDis.readDistributedMED(pMEDfilename);
110         cout << meshDis << endl;
111         
112         //---------------------------------------------------------------------
113         // Split the given part (pGroupName)
114         //---------------------------------------------------------------------
115         if (pPartitionner == MULTIPR_METIS)
116         {
117                 cout << "Use METIS" << endl;
118         }
119         else if (pPartitionner == MULTIPR_SCOTCH)
120         {
121                 cout << "Use SCOTCH" << endl;
122         }
123         
124         meshDis.splitPart(pGroupName, pNbParts, pPartitionner);
125         cout << meshDis << endl;
126         
127         //---------------------------------------------------------------------
128         // Write new distributed mesh
129         //---------------------------------------------------------------------
130         string strPrefix = multipr::removeExtension(pMEDfilename, ".med");
131         meshDis.writeDistributedMED(strPrefix.c_str());
132 }
133
134
135 void multipr::decimePartition(
136         const char* pMEDfilename,
137         const char* pPartName,
138         const char* pFieldName,
139         int         pFieldIt,
140         const char* pFilterName,
141         double      pTMed,
142         double      pTLow,
143         double      pRadius,
144         int         pBoxing)
145 {
146         //---------------------------------------------------------------------
147         // Check arguments
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__);
157         
158         cout << "--decim file=" << pMEDfilename << " part=" << pPartName << " filter=" << pFilterName << " tmed=" << pTMed << " tlow=" << pTLow << " radius=" << pRadius << endl;
159         
160         //---------------------------------------------------------------------
161         // Read the distributed mesh
162         //---------------------------------------------------------------------
163         MULTIPR_LOG("Read distributed MED file: " << pMEDfilename << ": please wait... " << endl);
164
165         int ret = MEDformatConforme(pMEDfilename);
166         if (ret == 0) throw IOException("waiting for a distributed MED file (not a sequential one)", __FILE__, __LINE__);
167         
168         multipr::MeshDis meshDis;
169         meshDis.readDistributedMED(pMEDfilename);
170         cout << meshDis << endl;
171         
172         //---------------------------------------------------------------------
173         // Create 3 resolutions of the given part
174         //---------------------------------------------------------------------
175         meshDis.decimatePart(
176                 pPartName, 
177                 pFieldName,
178                 pFieldIt,
179                 pFilterName,
180                 pTMed,
181                 pTLow,
182                 pRadius,
183                 pBoxing);
184         cout << meshDis << endl;
185         
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());
191 }
192
193 // EOF