1717#include < pcu_util.h>
1818#include < cstdlib>
1919
20+ #include < iostream> // cout
21+ #include < getopt.h> // option parser
22+
2023#ifdef SIM_PARASOLID
2124#include " SimParasolidKrnl.h"
2225#endif
@@ -37,8 +40,12 @@ pAManager SModel_attManager(pModel model);
3740
3841namespace {
3942
43+ int should_log = 0 ;
44+ int disable_volume = 0 ;
45+ int disable_surface = 0 ;
4046std::string modelFile;
4147std::string nativeModelFile;
48+ std::string surfaceMeshFile;
4249std::string caseName;
4350std::string outMeshFile;
4451
@@ -76,56 +83,118 @@ pParMesh generate(pGModel mdl, std::string meshCaseName) {
7683 MS_processSimModelerAdvMeshingAtts (mcaseFile, mcase);
7784 AttCase_setModel (mcase, mdl);
7885
79- pParMesh pmesh = PM_new (0 , mdl, PMU_size ());
86+ pParMesh pmesh;
87+ if ( ! surfaceMeshFile.empty () &&
88+ disable_surface && !disable_volume ) {
89+ // load the surface mesh instead of creating it
90+ pmesh = PM_load (surfaceMeshFile.c_str (), mdl, NULL );
91+ PM_setTotalNumParts (pmesh, PMU_size ()); // enable parallel volume meshing
92+ } else {
93+ // create an empty surface mesh
94+ pmesh = PM_new (0 , mdl, PMU_size ());
95+ }
8096
81- const double stime = MPI_Wtime ();
82- if (0 ==PCU_Comm_Self ()) {
83- printf (" Meshing surface..." ); fflush (stdout);
97+ if ( !disable_surface ) {
98+ const double stime = MPI_Wtime ();
99+ if (0 ==PCU_Comm_Self ()) {
100+ printf (" Meshing surface..." ); fflush (stdout);
101+ }
102+ pSurfaceMesher surfaceMesher = SurfaceMesher_new (mcase, pmesh);
103+ SurfaceMesher_execute (surfaceMesher, NULL );
104+ SurfaceMesher_delete (surfaceMesher);
105+ if (0 ==PCU_Comm_Self ())
106+ printf (" %f seconds\n " , MPI_Wtime ()-stime);
107+ if ( ! surfaceMeshFile.empty () ) {
108+ if (0 ==PCU_Comm_Self ())
109+ printf (" writing surface mesh %s\n " , surfaceMeshFile.c_str ());
110+ PM_write (pmesh, surfaceMeshFile.c_str (), NULL );
111+ }
84112 }
85- pSurfaceMesher surfaceMesher = SurfaceMesher_new (mcase, pmesh);
86- SurfaceMesher_execute (surfaceMesher, NULL );
87- SurfaceMesher_delete (surfaceMesher);
88- if (0 ==PCU_Comm_Self ())
89- printf (" %f seconds\n " , MPI_Wtime ()-stime);
90113
91- const double vtime = MPI_Wtime ();
92- if (0 ==PCU_Comm_Self ()) {
93- printf (" Meshing volume..." ); fflush (stdout);
114+ if ( !disable_volume ) {
115+ const double vtime = MPI_Wtime ();
116+ if (0 ==PCU_Comm_Self ()) {
117+ printf (" Meshing volume..." ); fflush (stdout);
118+ }
119+ pVolumeMesher volumeMesher = VolumeMesher_new (mcase, pmesh);
120+ VolumeMesher_execute (volumeMesher, NULL );
121+ VolumeMesher_delete (volumeMesher);
122+ if (0 ==PCU_Comm_Self ())
123+ printf (" %f seconds\n " , MPI_Wtime ()-vtime);
94124 }
95- pVolumeMesher volumeMesher = VolumeMesher_new (mcase, pmesh);
96- VolumeMesher_execute (volumeMesher, NULL );
97- VolumeMesher_delete (volumeMesher);
98- if (0 ==PCU_Comm_Self ())
99- printf (" %f seconds\n " , MPI_Wtime ()-vtime);
100125
101126 return pmesh;
102127}
103128
104- void getConfig (int argc, char ** argv)
105- {
106- if (argc < 3 ) {
107- if (0 ==PCU_Comm_Self ()) {
108- printf (" Usage: %s <GeomSim model (.smd)> <mesh case name> " , argv[0 ]);
109- printf (" to generate a mesh on a GeomSim model\n " );
110- printf (" or: %s <SimModeler model (.smd)> <parasolid or acis native model> <mesh case name>\n " , argv[0 ]);
111- printf (" to generate a mesh using the specified case name using the SimModeler"
112- " model which references the native parasolid or acis model\n " );
129+ void getConfig (int argc, char ** argv) {
130+ opterr = 0 ;
131+
132+ static struct option long_opts[] = {
133+ {" enable-log" , no_argument, &should_log, 1 },
134+ {" disable-volume" , no_argument, &disable_volume, 1 },
135+ {" disable-surface" , no_argument, &disable_surface, 1 },
136+ {" native-model" , required_argument, 0 , ' n' },
137+ {" surface-mesh" , required_argument, 0 , ' m' },
138+ {0 , 0 , 0 , 0 } // terminate the option array
139+ };
140+
141+ const char * usage=" "
142+ " [options] <GeomSim model (.smd)> <mesh case name>\n "
143+ " options:\n "
144+ " --enable-log Enable Simmetrix logging\n "
145+ " --disable-volume Disable volume mesh generation\n "
146+ " --disable-surface Disable suface mesh generation\n "
147+ " --native-model=/path/to/model Load the native Parasolid or ACIS model that the GeomSim model uses\n "
148+ " --surface-mesh=/path/to/surfaceMesh read or write the surface mesh - depends on generation mode\n " ;
149+
150+ nativeModelFile = " " ;
151+ surfaceMeshFile = " " ;
152+ int option_index = 0 ;
153+ while (1 ) {
154+ int c = getopt_long (argc, argv, " " , long_opts, &option_index);
155+ if (c == -1 ) break ; // end of options
156+ switch (c) {
157+ case 0 : // enable-log|disable-volume|disable-surf
158+ if (!PCU_Comm_Self ())
159+ printf (" read arg %d\n " , c);
160+ break ;
161+ case ' n' :
162+ nativeModelFile = std::string (optarg);
163+ break ;
164+ case ' m' :
165+ surfaceMeshFile = std::string (optarg);
166+ break ;
167+ case ' ?' :
168+ if (!PCU_Comm_Self ())
169+ printf (" warning: skipping unrecognized option\n " );
170+ break ;
171+ default :
172+ if (!PCU_Comm_Self ())
173+ printf (" Usage %s %s" , argv[0 ], usage);
174+ exit (EXIT_FAILURE);
113175 }
114- MPI_Finalize ();
115- exit (EXIT_SUCCESS);
116176 }
117- modelFile = argv[1 ];
118- if (argc == 3 ) {
119- nativeModelFile = " " ;
120- outMeshFile = caseName = argv[2 ];
121- } else if (argc == 4 ) {
122- nativeModelFile = argv[2 ];
123- outMeshFile = caseName = argv[3 ];
177+
178+
179+ if (argc-optind != 2 ) {
180+ if (!PCU_Comm_Self ())
181+ printf (" Usage %s %s" , argv[0 ], usage);
182+ exit (EXIT_FAILURE);
124183 }
184+ int i=optind;
185+ modelFile = std::string (argv[i++]);
186+ outMeshFile = caseName = std::string (argv[i++]);
125187 outMeshFile.append (" /" );
126- if (0 ==PCU_Comm_Self ()) {
127- printf (" Inputs: model \' %s\' native model \' %s\' case \' %s\'\n " ,
128- modelFile.c_str (), nativeModelFile.c_str (), caseName.c_str ());
188+
189+ if (!PCU_Comm_Self ()) {
190+ std::cout << " enable_log " << should_log <<
191+ " disable_surface " << disable_surface <<
192+ " disable_volume " << disable_volume <<
193+ " native-model " << nativeModelFile <<
194+ " model " << modelFile <<
195+ " surface mesh " << surfaceMeshFile <<
196+ " case name " << caseName <<
197+ " output mesh" << outMeshFile << " \n " ;
129198 }
130199}
131200
@@ -193,6 +262,8 @@ pNativeModel loadNativeModel() {
193262void simStart () {
194263 SimModel_start ();
195264 SimPartitionedMesh_start (NULL ,NULL );
265+ if (should_log)
266+ Sim_logOn (" generate_sim.log" );
196267 MS_init ();
197268 SimModel_start ();
198269#ifdef SIM_PARASOLID
@@ -232,7 +303,6 @@ int main(int argc, char** argv)
232303 getConfig (argc,argv);
233304
234305 simStart ();
235- Sim_logOn (" generate_sim.log" );
236306 pNativeModel nm = loadNativeModel ();
237307 pGModel simModel = GM_load (modelFile.c_str (), nm, NULL );
238308
0 commit comments