1 |
//------------------------------------------------------------
|
2 |
//------------------------------------------------------------
|
3 |
// MAGiC
|
4 |
// Jean Christophe Cuilli�e et Vincent FRANCOIS
|
5 |
// D�artement de G�ie M�anique - UQTR
|
6 |
//------------------------------------------------------------
|
7 |
// Le projet MAGIC est un projet de recherche du d�artement
|
8 |
// de g�ie m�anique de l'Universit�du Qu�ec �
|
9 |
// Trois Rivi�es
|
10 |
// Les librairies ne peuvent �re utilis�s sans l'accord
|
11 |
// des auteurs (contact : francois@uqtr.ca)
|
12 |
//------------------------------------------------------------
|
13 |
//------------------------------------------------------------
|
14 |
//
|
15 |
// main.cpp
|
16 |
//
|
17 |
//------------------------------------------------------------
|
18 |
//------------------------------------------------------------
|
19 |
// COPYRIGHT 2000
|
20 |
// Version du 02/03/2006 �11H25
|
21 |
//------------------------------------------------------------
|
22 |
//------------------------------------------------------------
|
23 |
#include "gestionversion.h"
|
24 |
#ifdef WINDOWS_VERSION
|
25 |
#include "fenetre.h"
|
26 |
#endif
|
27 |
#include <sstream>
|
28 |
#include <fstream>
|
29 |
#include <string>
|
30 |
#include <time.h>
|
31 |
#include <float.h>
|
32 |
|
33 |
#pragma hdrstop
|
34 |
|
35 |
#include "main.h"
|
36 |
|
37 |
#include "mg_file.h"
|
38 |
#include "fct_taille.h"
|
39 |
#include "occ_import.h"
|
40 |
#include "CAD4FE_mailleur0d.h"
|
41 |
#include "CAD4FE_mailleur1d.h"
|
42 |
#include "CAD4FE_mailleur2d.h"
|
43 |
//#include "mailleur3d_dia.h"
|
44 |
#include "CAD4FE_MeshQualityReport.h"
|
45 |
#include "fct_generateur_3d.h"
|
46 |
#include "fct_generateur_constante.h"
|
47 |
|
48 |
#include "CAD4FE_MCAA.h"
|
49 |
#include "CAD4FE_FileUtils.h"
|
50 |
#include "CAD4FE_MCAAHtmlReport.h"
|
51 |
#include "mg_gestionnaire.h"
|
52 |
#include "CAD4FE_MCBody.h"
|
53 |
#include "CAD4FE_MCVertex.h"
|
54 |
#include "CAD4FE_MCEdge.h"
|
55 |
#include "CAD4FE_MCFace.h"
|
56 |
#include "CAD4FE_PolyCurve.h"
|
57 |
#include "CAD4FE_PolySurface.h"
|
58 |
#include "CAD4FE_InventorText_MCAA.h"
|
59 |
#include "CAD4FE_InventorText_MG_MAILLAGE.h"
|
60 |
#include "CAD4FE_InventorText_MCMesh.h"
|
61 |
#ifndef GCC
|
62 |
#include "CAD4FE_SW_FeatureSimplification.h"
|
63 |
#endif
|
64 |
#include "CAD4FE_construire_fem_maillage_quadratique.h"
|
65 |
#include "CAD4FE_MCMesh_SetSaveFormat.h"
|
66 |
#include "fct_generateur_3d.h"
|
67 |
#include "fct_generateur_constante.h"
|
68 |
#include <fct_generateur_fichier.h>
|
69 |
#include "ot_fonctions.h"
|
70 |
#include "mailleur_fem.h"
|
71 |
|
72 |
//---------------------------------------------------------------------------
|
73 |
|
74 |
void affiche(const char* message)
|
75 |
{
|
76 |
#if !defined(CONSOLE) && defined(WINDOWS_VERSION)
|
77 |
Form1->Memo1->Lines->Add(message);
|
78 |
#else
|
79 |
std::cout << message << std::endl;
|
80 |
#endif
|
81 |
}
|
82 |
|
83 |
#define MSG_HELP "Feature Simplifications parameters (Windows Only):\n\
|
84 |
-fillet -hole -extrusion -fastener -implicitholes -ribs\n\
|
85 |
Mesher parameters:\n\
|
86 |
-niveau <n>: =3 for volumic mesh generation =2 for surfacic mesh generation =1 for edge mesh generation\n\
|
87 |
-prioritemetrique <f>: float number in [0 ; 1] interval (0=mesh respecting shape quality only, 1=size map quality only)\n\ -console \n\
|
88 |
-femmaillagedegre <n>: n=2 for quadratic mesh elements generation, n=1 for linear mesh elements generation\n\
|
89 |
-femmaillageexportcosmos : export to COSMOS/M file\n\
|
90 |
-typecarte <n>: type of size map definition 1=constant value (requires option \"-eng <f>\"),\n 2 = ctt file (requires option \"-carte <f>\"),\n 3 = pog file (requires option \"-carte <f>\"),\n\
|
91 |
-carte <file>: size map file with .ctt extension\n\
|
92 |
-sld <file>: (Windows only) name of the SW file\n\
|
93 |
-step <file>: (Linux only) name of the STEP file\n\
|
94 |
MCAA parameters:\n\
|
95 |
-epsilonmax <f>: ratio between the sag tolerance and the local mesh size \n\ -betamax minimal dihedral angle defining a real edge between 2 triangles<f>\n\ -jmax <f> maximal mesh overdensity tolerated \n\
|
96 |
\n\
|
97 |
"
|
98 |
|
99 |
#define FLOAT_UNDEF -504333333341.5
|
100 |
|
101 |
|
102 |
//---------------------------------------------------------------------------
|
103 |
|
104 |
double RefinementFile_GetEng(const char * __filename)
|
105 |
|
106 |
{
|
107 |
FILE* in=fopen(__filename,"rt");
|
108 |
char chaine[500];
|
109 |
double eng;
|
110 |
fgets(chaine,500,in);
|
111 |
fgets(chaine,500,in);
|
112 |
int nb=sscanf(chaine,"%lf",&eng);
|
113 |
char cmdline[10000];
|
114 |
fclose(in);
|
115 |
return eng;
|
116 |
}
|
117 |
//---------------------------------------------------------------------------
|
118 |
|
119 |
int ReadSizeMapRefinementFile(const char * __filename)
|
120 |
{
|
121 |
double eng = RefinementFile_GetEng(__filename);
|
122 |
FCT_GENERATEUR_FICHIER * sizeMap = new FCT_GENERATEUR_FICHIER((char*)__filename, eng);
|
123 |
//_sizeMap = sizeMap;
|
124 |
sizeMap->construit(20,20);
|
125 |
char outfilename[10000]="";
|
126 |
sprintf(outfilename,"%s.ctt",__filename);
|
127 |
sizeMap->enregistrer(outfilename);
|
128 |
return 1;
|
129 |
}
|
130 |
|
131 |
#if !defined(CONSOLE) && defined(WINDOWS_VERSION)
|
132 |
int amain(int argc,char **argv)
|
133 |
#else
|
134 |
int main(int argc,char **argv)
|
135 |
#endif
|
136 |
{
|
137 |
#ifdef __BORLANDC__
|
138 |
// Very important in Borland C++ : disable floating point overflow exceptions !
|
139 |
// (because we don't want unexpected program terminations during production phase)
|
140 |
// For more information, see float.h file, and Borland C++ help files
|
141 |
_control87(MCW_EM,MCW_EM);
|
142 |
#endif
|
143 |
|
144 |
int debug = 0;
|
145 |
int res=0;
|
146 |
|
147 |
/// internal parameters
|
148 |
MG_VOLUME * refBody=NULL, *mcBody=NULL;
|
149 |
MG_MAILLAGE * refTessellation;
|
150 |
MG_MAILLAGE * mgmai;
|
151 |
MG_GESTIONNAIRE * gest=NULL;
|
152 |
MG_GEOMETRIE * mggeo=NULL;
|
153 |
FCT_TAILLE *metrique;
|
154 |
|
155 |
/// general parameters
|
156 |
char CTT_filename[5000];
|
157 |
char MAGIC_filename[5000];
|
158 |
char TEMP_SLD_filename[5000];
|
159 |
char SLD_filename[5000];
|
160 |
char STEP_filename[5000]; // for GCC
|
161 |
int typecarte;
|
162 |
double eng;
|
163 |
|
164 |
double qual_couleurs[100],qual_intervalles[100];
|
165 |
int qual_nb;
|
166 |
double qual_forme_couleurs[100],qual_forme_intervalles[100];
|
167 |
int qual_forme_nb;
|
168 |
|
169 |
//// Feature Simplification parameters
|
170 |
bool bNothing;
|
171 |
bool bFillet=false, bHole=false, bExtrusion=false;
|
172 |
bool bFastener=false, bImplicitHoles=false, bRibs=false;
|
173 |
int stopetape1 = 0;
|
174 |
|
175 |
/// MCT parameters
|
176 |
double epsilon_max=FLOAT_UNDEF, beta_max=FLOAT_UNDEF, J_max=FLOAT_UNDEF;
|
177 |
|
178 |
/// CAD4FE Mesher parameters
|
179 |
int niveau=2;
|
180 |
double prioritemetrique=0.65;
|
181 |
int formatmaillage = 0;
|
182 |
|
183 |
/// FEM Maillage and Export COSMOS/M parameters
|
184 |
FEM_MAILLAGE * femMesh = NULL;
|
185 |
int fem_maillage_degre=-1;
|
186 |
char * fem_maillage_export_cosmos=0;
|
187 |
|
188 |
/* default quality colors */
|
189 |
/* -formatmaillage 0 -couleurqualite 4 1 0 0 1 1 0 0 0.0 0.92 0.02 0.9 0.05 .25 .5 .75 */
|
190 |
int qual_nb_default = 4;
|
191 |
double qual_couleurs_default[] = { 1, 0, 0 , 1, 1, 0, 0, 0.0, 0.92, 0.02, 0.9, 0.05};
|
192 |
double qual_intervalles_default[]={0, .25, .5, .75, 1};
|
193 |
qual_nb = qual_nb_default;
|
194 |
qual_couleurs[0]=qual_couleurs[1]=qual_couleurs[2]=0;
|
195 |
// for (int k=1;k<qual_nb+1; k++)
|
196 |
// {
|
197 |
// qual_couleurs[3*k+0]=qual_couleurs_default[3*(k-1)];
|
198 |
// qual_couleurs[3*k+1]=atof(argv[j++]);
|
199 |
// qual_couleurs[3*k+2]=atof(argv[j++]);
|
200 |
// }
|
201 |
for (int i=3; i<(qual_nb_default+1)*3; i++) qual_couleurs[i] = qual_couleurs_default[i-3];
|
202 |
for (int i=0; i<qual_nb_default+1; i++) qual_intervalles[i] = qual_intervalles_default[i];
|
203 |
|
204 |
/// Reading the command line parameters :
|
205 |
for (int i=0;i<argc;i++)
|
206 |
{
|
207 |
|
208 |
if (strcmp(argv[i],"-help")==0 || strcmp(argv[i],"--help")==0)
|
209 |
{
|
210 |
printf(MSG_HELP);
|
211 |
exit(0);
|
212 |
}
|
213 |
if (strcmp(argv[i],"-debug")==0)
|
214 |
debug=1;
|
215 |
//// Example : -fillet -hole -extrusion -fastener -niveau 2 -prioritemetrique 0.65 -console -carte c:/gilles/doctorat/CAD_FEA_models/Plots_fixation/plots_fixationMAGiC.txt.ctt -sld c:/gilles/doctorat/CAD_FEA_models/Plots_fixation/plots_fixation2MAGIC.Sldprt
|
216 |
/// general parameters
|
217 |
if (strcmp(argv[i],"-carte")==0)
|
218 |
sprintf(CTT_filename,"%s",argv[i+1]);
|
219 |
if (strcmp(argv[i],"-magic")==0)
|
220 |
strcpy(MAGIC_filename,argv[i+1]);
|
221 |
if (strcmp(argv[i],"-step")==0) // Input geometry file For GCC
|
222 |
{
|
223 |
strcpy(STEP_filename,argv[i+1]);
|
224 |
strcpy(MAGIC_filename,argv[i+1]);
|
225 |
strcat(MAGIC_filename,".magic");
|
226 |
}
|
227 |
if (strcmp(argv[i],"-sld")==0) // Input geometry file For Win32 + SW only
|
228 |
{
|
229 |
strcpy(SLD_filename,argv[i+1]);
|
230 |
strcpy(MAGIC_filename,argv[i+1]);
|
231 |
strcat(SLD_filename,".magic");
|
232 |
}
|
233 |
if (strcmp(argv[i],"-typecarte")==0)
|
234 |
typecarte=atoi(argv[i+1]);
|
235 |
if (strcmp(argv[i],"-eng")==0)
|
236 |
eng=atof(argv[i+1]);
|
237 |
if (strcmp(argv[i],"-stopetape1")==0)
|
238 |
stopetape1=1;
|
239 |
if (strcmp(argv[i],"-formatmaillage")==0)
|
240 |
// 0=save as MCNode, MCSegment, MCTriangle
|
241 |
// 1=save as MG_NOEUD, MG_SEGMENT, MG_TRIANGLE
|
242 |
// 2=no MCT adaptation, generate mesh on the CAD topology
|
243 |
formatmaillage=atoi(argv[i+1]);
|
244 |
if (strcmp(argv[i],"-couleurqualite")==0)
|
245 |
{
|
246 |
int j=i+1;
|
247 |
qual_nb = atoi(argv[j++]);
|
248 |
qual_couleurs[0]=qual_couleurs[1]=qual_couleurs[2]=0;
|
249 |
for (int k=1;k<qual_nb+1; k++)
|
250 |
{
|
251 |
qual_couleurs[3*k+0]=atof(argv[j++]);
|
252 |
qual_couleurs[3*k+1]=atof(argv[j++]);
|
253 |
qual_couleurs[3*k+2]=atof(argv[j++]);
|
254 |
}
|
255 |
qual_intervalles[0]=0;
|
256 |
qual_intervalles[qual_nb]=1;
|
257 |
for (int k=1;k<qual_nb; k++)
|
258 |
{
|
259 |
qual_intervalles[k]=atof(argv[j++]);
|
260 |
}
|
261 |
}
|
262 |
//// Feature Simplification parameters
|
263 |
if (strcmp(argv[i],"-fillet")==0)bFillet=true;
|
264 |
if (strcmp(argv[i],"-hole")==0)bHole=true;
|
265 |
if (strcmp(argv[i],"-extrusion")==0)bExtrusion=true;
|
266 |
if (strcmp(argv[i],"-fastener")==0)bFastener=true;
|
267 |
if (strcmp(argv[i],"-implicitholes")==0)bImplicitHoles=true;
|
268 |
if (strcmp(argv[i],"-ribs")==0)bRibs=true;
|
269 |
bNothing = (!bFillet&&!bHole&&!bExtrusion&&!bFastener&&!bImplicitHoles&&!bRibs);
|
270 |
|
271 |
/// MCAA parameters
|
272 |
if (strcmp(argv[i],"-epsilonmax")==0) epsilon_max=atof(argv[i+1]);
|
273 |
if (strcmp(argv[i],"-betamax")==0) beta_max=atof(argv[i+1]);
|
274 |
if (strcmp(argv[i],"-jmax")==0) J_max=atof(argv[i+1]);
|
275 |
|
276 |
|
277 |
/// CAD4FE Mesher parameters
|
278 |
if (strcmp(argv[i],"-niveau")==0)
|
279 |
niveau=atoi(argv[i+1]);
|
280 |
if (strcmp(argv[i],"-prioritemetrique")==0)
|
281 |
prioritemetrique=atof(argv[i+1]);
|
282 |
|
283 |
/// FEM Maillage and Export COSMOS/M parameters
|
284 |
if (strcmp(argv[i],"-femmaillagedegre")==0)
|
285 |
fem_maillage_degre = atoi(argv[i+1]);
|
286 |
if (strcmp(argv[i],"-femmaillageexportcosmos")==0)
|
287 |
fem_maillage_export_cosmos = argv[i+1];
|
288 |
}
|
289 |
|
290 |
//// Basename of reports
|
291 |
#ifdef WINDOWS_VERSION
|
292 |
std::string basename (getenv("TEMP"));
|
293 |
#endif
|
294 |
#ifdef GCC
|
295 |
if (getenv("TEMP") == NULL)
|
296 |
setenv("TEMP","/tmp",0);
|
297 |
std::string basename (getenv("TEMP"));
|
298 |
std::cout << "Temporary folder is set to " << basename << std::endl;
|
299 |
#endif
|
300 |
basename += std::string("/CAD4FE");
|
301 |
|
302 |
if (strlen(SLD_filename) > 0) { // For Windows Solidworks
|
303 |
// Copy file to temporary file
|
304 |
strncpy(TEMP_SLD_filename,SLD_filename,strlen(SLD_filename)-strlen(".SLDPRT"));
|
305 |
TEMP_SLD_filename[strlen(SLD_filename)-strlen(".SLDPRT")]='\0';
|
306 |
strcat(TEMP_SLD_filename,"TEMP.SLDPRT");
|
307 |
res=CAD4FE::FileUtils::Copy(SLD_filename,TEMP_SLD_filename);
|
308 |
if (res == 0)
|
309 |
{
|
310 |
affiche( "Error occured while reading SolidWorks file" );
|
311 |
return 0;
|
312 |
}
|
313 |
}
|
314 |
|
315 |
/// Generate HTML Report file
|
316 |
CAD4FE::HtmlText_Page out;
|
317 |
out.Add("<h2>MCAA Mesher Report</h2>");
|
318 |
|
319 |
// Generate size map object
|
320 |
if (typecarte == 1)
|
321 |
{
|
322 |
affiche("Type of size map : constant value");
|
323 |
double bbox[6];
|
324 |
// featureSimplification.GetPartBoundaryBox(bbox);
|
325 |
MG_GESTIONNAIRE gesttmp;
|
326 |
metrique = new FCT_GENERATEUR_CONSTANTE ( gesttmp, eng );
|
327 |
((FCT_GENERATEUR_CONSTANTE*)metrique)->construit(-1E6, -1E6, -1E6, +1E6, +1E6, +1E6, 2,2);
|
328 |
((FCT_GENERATEUR_CONSTANTE*)metrique)->enregistrer((char*)(basename+std::string("_MCBody.magic.ctt")).c_str());
|
329 |
}
|
330 |
if (typecarte == 2)
|
331 |
{
|
332 |
affiche("Type of size map : ctt file");
|
333 |
FCT_GENERATEUR_3D<4> * sizeMap = new FCT_GENERATEUR_3D<4>();
|
334 |
sizeMap->lire(CTT_filename);
|
335 |
metrique=sizeMap;
|
336 |
}
|
337 |
if (typecarte == 3)
|
338 |
{
|
339 |
affiche("Type of size map : pog file");
|
340 |
ReadSizeMapRefinementFile(CTT_filename);
|
341 |
FCT_GENERATEUR_3D<4> * sizeMap = new FCT_GENERATEUR_3D<4>();
|
342 |
strcat(CTT_filename,".ctt");
|
343 |
sizeMap->lire(CTT_filename);
|
344 |
metrique=sizeMap;
|
345 |
// affiche("Type of size map : pog file");
|
346 |
// affiche("not implemented in GCC...");
|
347 |
//
|
348 |
// exit(0);
|
349 |
}
|
350 |
|
351 |
|
352 |
#ifndef GCC
|
353 |
// Open SolidWorks part
|
354 |
affiche ("Starting SolidWorks ATL/COM server");
|
355 |
CAD4FE::SW_FeatureSimplification featureSimplification;
|
356 |
featureSimplification.OpenPart(TEMP_SLD_filename);
|
357 |
if (typecarte == 1) // constant size (requires -eng <Double> option)
|
358 |
{
|
359 |
featureSimplification.SetSizeMap(metrique);
|
360 |
}
|
361 |
if (typecarte == 2) // ctt file
|
362 |
{
|
363 |
featureSimplification.SetSizeMap(metrique);
|
364 |
}
|
365 |
if (typecarte == 3) // pog file
|
366 |
{
|
367 |
affiche("Type of size map : pog file");
|
368 |
featureSimplification.ReadSizeMapRefinementFile(CTT_filename);
|
369 |
metrique = featureSimplification.GetSizeMap();
|
370 |
}
|
371 |
|
372 |
affiche("*** Adapting the SolidWorks Feature-Tree for Meshing***");
|
373 |
if (bNothing == false)
|
374 |
{
|
375 |
featureSimplification.DeleteAllConstraintsInSketches();
|
376 |
int nbThickenFeature = featureSimplification.ThickenFeature_GetCount();
|
377 |
//int nbThickenFeature = 0;
|
378 |
for (int i=0;i<=nbThickenFeature;i++)
|
379 |
{
|
380 |
if (i==nbThickenFeature)
|
381 |
featureSimplification.EndEditRollback();
|
382 |
else
|
383 |
featureSimplification.ThickenFeature_EditRollback(i);
|
384 |
|
385 |
char tempMessage[5000];
|
386 |
sprintf(tempMessage,"Pass %d of %d",i+1,nbThickenFeature+1);
|
387 |
affiche (tempMessage);
|
388 |
|
389 |
if (bFastener) {
|
390 |
affiche("Simplifying fastener features");
|
391 |
featureSimplification.SimplifyFeature_PlotFixation();
|
392 |
}
|
393 |
if (bHole) {
|
394 |
affiche("Simplifying 'hole wizard' and 'revolution cut' features");
|
395 |
featureSimplification.SimplifyFeature_HoleWzd();
|
396 |
}
|
397 |
if (bExtrusion) {
|
398 |
affiche("Simplifying 'Cut' 'Boss' 'BossThin' 'CutThin' features");
|
399 |
featureSimplification.SimplifyFeature_GlobalCutBoss();
|
400 |
}
|
401 |
if (bFillet) {
|
402 |
affiche("Simplifying constant-radius fillets");
|
403 |
featureSimplification.SimplifyFeature_Fillet();
|
404 |
affiche("Simplifying chamfers");
|
405 |
featureSimplification.SimplifyFeature_Chamfers();
|
406 |
}
|
407 |
if (bExtrusion)
|
408 |
featureSimplification.SimplifyFeature_GlobalCutBoss();
|
409 |
|
410 |
if (bRibs)
|
411 |
{
|
412 |
affiche("Simplifying ribs");
|
413 |
featureSimplification.SimplifyFeature_Rib();
|
414 |
}
|
415 |
}
|
416 |
// Features that are recognized on the final B-Rep
|
417 |
|
418 |
if (bImplicitHoles)
|
419 |
{
|
420 |
affiche("Deleting small revolved holes/bosses that are implicit (skecth holes)");
|
421 |
featureSimplification.SimplifyFeature_Body();
|
422 |
}
|
423 |
}
|
424 |
|
425 |
affiche("*** End of the SolidWorks Feature-Tree adaptation ***");
|
426 |
affiche("MAGiC: Generating MAGiC file with SolidWorks part...");
|
427 |
featureSimplification.SaveAsMagicFile(MAGIC_filename, &gest);
|
428 |
if( remove( TEMP_SLD_filename ) != 0)
|
429 |
affiche ("Error deleting SolidWorks temp file : (SolidWorks still open?)");
|
430 |
out.Add(featureSimplification.HtmlReport());
|
431 |
out.WriteFile(basename+".html");
|
432 |
if (stopetape1)
|
433 |
{
|
434 |
affiche("Exit with success!");
|
435 |
return 0;
|
436 |
}
|
437 |
#else // For linux : open the STEP file directly
|
438 |
// Example : -niveau 2 -prioritemetrique 0.65 -console -typecarte 1 -eng .01 -step /home/gilles/doctorat/CAD_FEA_models/Plots_fixation/plots_fixation2.STEP
|
439 |
|
440 |
gest = new MG_GESTIONNAIRE();
|
441 |
OCC_IMPORT occimport;
|
442 |
occimport.importer(*gest, STEP_filename, FICHIERSTEP);
|
443 |
gest->enregistrer(MAGIC_filename);
|
444 |
#endif
|
445 |
|
446 |
|
447 |
/// initialize MAGIC data-structure
|
448 |
mggeo=gest->get_mg_geometrie(0);
|
449 |
refBody = mggeo->get_mg_volume(0);
|
450 |
#ifdef WINDOWS_VERSION
|
451 |
refTessellation=gest->get_mg_maillage(0);
|
452 |
#else
|
453 |
#ifdef GCC
|
454 |
affiche ("Generation of the tessellation");
|
455 |
//class MG_MAILLAGE* importer(class MG_GESTIONNAIRE& gest,MG_GEOMETRIE* mggeo,double epsilon=1.,int mode=1);
|
456 |
refTessellation=occimport.importer(*gest, mggeo, 0.01, 2);
|
457 |
#endif //GCC
|
458 |
#endif // WINDOWS
|
459 |
|
460 |
/// MCAA : generation of the MCT (Meshing Constraints Topology)
|
461 |
affiche ("Generation of the MCT (Meshing Constraints Topology)");
|
462 |
affiche ("Initializing the Meshing Constraints Automatic Adaptation with the B-Rep");
|
463 |
CAD4FE::MCAA * mcaa = new CAD4FE::MCAA(refBody,refTessellation,gest,mggeo);
|
464 |
gest->enregistrer((char*)(basename+std::string("_MCBody.magic")).c_str());
|
465 |
double default_J_max = 2;
|
466 |
if (J_max != FLOAT_UNDEF) {
|
467 |
mcaa->SetMaxOverdensity(default_J_max);
|
468 |
}
|
469 |
else
|
470 |
{
|
471 |
printf("Jmax is not specified : setting maximum overdensity to defaults %f \n", default_J_max);
|
472 |
mcaa->SetMaxOverdensity(2);
|
473 |
}
|
474 |
if (beta_max != FLOAT_UNDEF) mcaa->SetLimitAngle(beta_max*PI/180);
|
475 |
if (epsilon_max != FLOAT_UNDEF) mcaa->SetRelativeSag(epsilon_max);
|
476 |
if (beta_max == FLOAT_UNDEF && epsilon_max == FLOAT_UNDEF) {
|
477 |
double default_beta_max = 30*PI/180;
|
478 |
printf("Neither Beta max nor Relative Sag are specified : setting Beta max to defaults %f \n", default_beta_max);
|
479 |
mcaa->SetLimitAngle(default_beta_max);
|
480 |
}
|
481 |
|
482 |
CAD4FE::MCAAHtmlReport mcaaReport (mcaa, basename);
|
483 |
mcaa->SetSizeMap(metrique);
|
484 |
mcaaReport.WriteInitialCriteriaFile();
|
485 |
if (formatmaillage != 2)
|
486 |
{
|
487 |
affiche ("Adapting the MCT for Meshing");
|
488 |
mcaa->Simplify();
|
489 |
char tmpMessage[5000];
|
490 |
sprintf(tmpMessage,"Deleted %d MC Edges",mcaa->GetEdgeDeletionCount()); affiche(tmpMessage);
|
491 |
sprintf(tmpMessage,"Deleted %d MC Vertices",mcaa->GetVertexDeletionCount()); affiche(tmpMessage);
|
492 |
sprintf(tmpMessage,"Contracted %d MC Edges on MC Vertices",mcaa->GetEdgeCollapseCount()); affiche(tmpMessage);
|
493 |
sprintf(tmpMessage,"Collapsed %d constricted sections",mcaa->GetConstrictedSectionCollapseCount()); affiche(tmpMessage);
|
494 |
sprintf(tmpMessage,"Deleted %d small loops",mcaa->GetLoopDeletionCount()); affiche(tmpMessage);
|
495 |
}
|
496 |
mcaaReport.WriteFinalFEMeshFile();
|
497 |
mcaaReport.WriteFinalMCTFile();
|
498 |
affiche ("Converting MCT hypergraphs to B-Rep model");
|
499 |
mcBody = mcaa->GetMCBody()->ExportBRep();
|
500 |
mcaaReport.Build();
|
501 |
out.Add(mcaaReport);
|
502 |
if (formatmaillage != 2)
|
503 |
{
|
504 |
delete mcaa;
|
505 |
}
|
506 |
out.WriteFile(basename+".html");
|
507 |
|
508 |
gest->enregistrer((char*)(basename+std::string("_MCBody.magic")).c_str());
|
509 |
/// Meshing the MCT
|
510 |
std::set < CAD4FE::MCFace * > lst_mc_faces;
|
511 |
std::set < CAD4FE::MCEdge * > lst_mc_edges;
|
512 |
std::set < CAD4FE::MCVertex * > lst_mc_vertices;
|
513 |
std::set < MG_COQUILLE * > lst_mc_shell;
|
514 |
std::set < MG_BOUCLE * > lst_mc_loop;
|
515 |
|
516 |
// initialize MC face, MC edge, MC loop, MC shell, and MC vertices lists
|
517 |
unsigned nb_shells = mcBody->get_nb_mg_coquille ();
|
518 |
for (unsigned it_shells = 0; it_shells < nb_shells; it_shells++)
|
519 |
{
|
520 |
MG_COQUILLE * shell = mcBody->get_mg_coquille(it_shells);
|
521 |
lst_mc_shell.insert(shell);
|
522 |
unsigned nb_coface = shell->get_nb_mg_coface();
|
523 |
for (unsigned it_coface = 0; it_coface < nb_coface; it_coface++)
|
524 |
{
|
525 |
CAD4FE::MCFace * face = (CAD4FE::MCFace *)shell->get_mg_coface(it_coface)->get_face();
|
526 |
lst_mc_faces.insert(face);
|
527 |
|
528 |
unsigned nb_loop = face->get_nb_mg_boucle();
|
529 |
for (unsigned it_loop = 0; it_loop < nb_loop; it_loop++)
|
530 |
{
|
531 |
MG_BOUCLE * loop = face->get_mg_boucle(it_loop);
|
532 |
lst_mc_loop.insert(loop);
|
533 |
unsigned nb_edge = loop->get_nb_mg_coarete();
|
534 |
|
535 |
for (unsigned it_edge = 0; it_edge < nb_edge; it_edge++)
|
536 |
{
|
537 |
CAD4FE::MCEdge * edge = (CAD4FE::MCEdge*)loop->get_mg_coarete(it_edge)->get_arete();
|
538 |
lst_mc_edges.insert(edge);
|
539 |
|
540 |
lst_mc_vertices.insert ((CAD4FE::MCVertex*)edge->get_cosommet1()->get_sommet());
|
541 |
lst_mc_vertices.insert ((CAD4FE::MCVertex*)edge->get_cosommet2()->get_sommet());
|
542 |
}
|
543 |
}
|
544 |
}
|
545 |
}
|
546 |
|
547 |
mgmai=new MG_MAILLAGE(mggeo);
|
548 |
gest->ajouter_mg_maillage(mgmai);
|
549 |
|
550 |
if (niveau>-1)
|
551 |
{
|
552 |
affiche("MAILLAGE 0D");
|
553 |
for (std::set<CAD4FE::MCVertex *>::iterator itVertex = lst_mc_vertices.begin(); itVertex != lst_mc_vertices.end(); itVertex++)
|
554 |
{
|
555 |
double coo[3];
|
556 |
CAD4FE::MCVertex * mcVertex = *itVertex;
|
557 |
mcVertex->get_point()->evaluer(coo);
|
558 |
CAD4FE::MCNode * n = new CAD4FE::MCNode(mcVertex,mcVertex->GetRefVertex(),coo[0],coo[1],coo[2]);
|
559 |
n->incrementer();
|
560 |
mcVertex->get_lien_maillage()->ajouter(n);
|
561 |
mgmai->ajouter_mg_noeud(n);
|
562 |
}
|
563 |
}
|
564 |
if (niveau>0)
|
565 |
{
|
566 |
affiche("MAILLAGE 1D");
|
567 |
for (std::set<CAD4FE::MCEdge *>::iterator itEdge = lst_mc_edges.begin(); itEdge != lst_mc_edges.end(); itEdge++)
|
568 |
{
|
569 |
CAD4FE::MCEdge* mcEdge=*itEdge;
|
570 |
printf("Arete %lx\n", mcEdge->get_id());
|
571 |
CAD4FE::MAILLEUR1D m1d(mgmai,mggeo,mcEdge,metrique);
|
572 |
m1d.maille();
|
573 |
}
|
574 |
}
|
575 |
if (niveau>1)
|
576 |
{
|
577 |
affiche("MAILLAGE 2D");
|
578 |
CAD4FE::MAILLEUR2D::priorite_metrique=prioritemetrique;
|
579 |
int iFace=0;
|
580 |
for (std::set<CAD4FE::MCFace *>::iterator itFace = lst_mc_faces.begin(); itFace != lst_mc_faces.end(); itFace++)
|
581 |
{
|
582 |
char mess[100];
|
583 |
CAD4FE::MCFace* face=*itFace;
|
584 |
sprintf(mess," face %d / %d ",++iFace,lst_mc_faces.size());
|
585 |
affiche(mess);
|
586 |
affiche("");
|
587 |
CAD4FE::MAILLEUR2D m2d(mgmai,mggeo,face,metrique);
|
588 |
m2d.debug=debug;
|
589 |
#if !defined(CONSOLE) && defined(WINDOWS_VERSION)
|
590 |
clock_t time = clock();
|
591 |
sprintf(Form1->filenameNbTriangles,"%s\\CAD4FE_%d.txt",getenv("TEMP"),time);
|
592 |
strcpy(m2d.filenameNbTriangles,Form1->filenameNbTriangles);
|
593 |
#endif
|
594 |
m2d.maille();
|
595 |
m2d.optimise_bascule_segment(face);
|
596 |
m2d.optimise(face);
|
597 |
#if !defined(CONSOLE) && defined(WINDOWS_VERSION)
|
598 |
remove(Form1->filenameNbTriangles);
|
599 |
#endif
|
600 |
}
|
601 |
}
|
602 |
|
603 |
CAD4FE::MeshQualityReport meshQualReport(mgmai, metrique, basename);
|
604 |
meshQualReport.SetQualityColorMap(qual_nb, qual_intervalles, qual_couleurs);
|
605 |
meshQualReport.Build();
|
606 |
out.Add(meshQualReport);
|
607 |
out.Add("<h3>FEM_MAILLAGE and COSMOS/M output</h3>");
|
608 |
if ((fem_maillage_degre==1||fem_maillage_degre==2) && (niveau == 3))
|
609 |
{
|
610 |
std::ostringstream tmp;tmp<<"Degree of elements = "<<(fem_maillage_degre)<<"<br>";
|
611 |
tmp<<"The session file is located <a href=\"file:///"<<fem_maillage_export_cosmos<<".ses\">here</a>, Use the following command in COSMOS/M";
|
612 |
tmp<<"<pre>FILE,"<<fem_maillage_export_cosmos<<".ses,0,0,0</pre><br>";
|
613 |
out.Add(tmp.str());
|
614 |
}
|
615 |
if (niveau == 1)
|
616 |
{
|
617 |
std::ostringstream tmp;tmp<<"The \"FEM_MAILLAGE\" and COSMOS meshes were not generated because only the mesh of curves was generated<br>";
|
618 |
out.Add(tmp.str());
|
619 |
}
|
620 |
|
621 |
if (niveau == 2)
|
622 |
{
|
623 |
std::ostringstream tmp;tmp<<"The \"FEM_MAILLAGE\" and COSMOS meshes were not generated because only the surfacic mesh was generated<br>";
|
624 |
out.Add(tmp.str());
|
625 |
}
|
626 |
out.WriteFile(basename+".html");
|
627 |
|
628 |
|
629 |
CAD4FE::MCMesh_SetSaveFormat(mgmai,formatmaillage);
|
630 |
if (formatmaillage==2)
|
631 |
{
|
632 |
mcaa->GetMCBody()->DeleteBRep(gest,mggeo);
|
633 |
}
|
634 |
/*
|
635 |
if (niveau==3)
|
636 |
{
|
637 |
affiche("MAILLAGE 3D");
|
638 |
if (formatmaillage == 2)
|
639 |
{
|
640 |
::MAILLEUR3D_DIA m3d(mgmai,mggeo,refBody);
|
641 |
m3d.maille(refBody);
|
642 |
}
|
643 |
else
|
644 |
{
|
645 |
::MAILLEUR3D_DIA m3d(mgmai,mggeo,mcBody);
|
646 |
m3d.maille(mcBody);
|
647 |
}
|
648 |
}*/
|
649 |
|
650 |
/// FEM Maillage
|
651 |
if (fem_maillage_degre==1 && niveau == 3)
|
652 |
{
|
653 |
affiche("Generating \"FEM maillage\" with linear mesh elements");
|
654 |
femMesh = new FEM_MAILLAGE (mggeo, mgmai, 1);
|
655 |
gest->ajouter_fem_maillage(femMesh);
|
656 |
MAILLEUR_FEM m;
|
657 |
m.maille(femMesh,0);
|
658 |
}
|
659 |
if (fem_maillage_degre==2 && niveau == 3)
|
660 |
{
|
661 |
affiche("Generating \"FEM maillage\" with quadratic mesh elements");
|
662 |
femMesh = new FEM_MAILLAGE (mggeo, mgmai, 2);
|
663 |
gest->ajouter_fem_maillage(femMesh);
|
664 |
CAD4FE::construire_fem_maillage_quadratique(femMesh);
|
665 |
}
|
666 |
if (fem_maillage_export_cosmos && femMesh)
|
667 |
{
|
668 |
affiche ("Exporting to COSMOS/M session file");
|
669 |
std::string tmpFilename(fem_maillage_export_cosmos);
|
670 |
femMesh->exporter_cosmos(tmpFilename);
|
671 |
}
|
672 |
|
673 |
affiche("Enregistrement");
|
674 |
gest->enregistrer(MAGIC_filename);
|
675 |
|
676 |
affiche("Finished successfully");
|
677 |
|
678 |
delete metrique;
|
679 |
delete gest;
|
680 |
|
681 |
return 0;
|
682 |
}
|
683 |
|
684 |
|
685 |
|
686 |
#pragma package(smart_init)
|