1111// Mesh interfaces
1212#include < apf.h>
1313#include < apfCAP.h>
14+ #include < apfMDS.h>
15+ #include < apfConvert.h>
1416
1517// Geometry interfaces
1618#include < gmi.h>
@@ -59,12 +61,13 @@ void writeCre(CapstoneModule& cs, const std::string& filename) {
5961}
6062
6163void printUsage (char *argv0) {
62- printf (" USAGE: %s [-agwv ] <size-field> <create_file.cre>\n " , argv0);
64+ printf (" USAGE: %s [-agwvm ] <size-field> <create_file.cre>\n " , argv0);
6365 printf (" Flags:\n "
6466 " -a\t Evaluate size-field analytically.\n "
6567 " -g\t Force mesh generation.\n "
6668 " -v\t Enable verbose output.\n "
6769 " -w\t Write before.vtk, after.vtk, and after.cre.\n "
70+ " -m\t Convert mesh to MDS during adaptation.\n "
6871 " SIZE-FIELDS:\n "
6972 " %d, for uniform anisotropic size-field\n "
7073 " %d, for wing-shock size-field\n "
@@ -80,6 +83,7 @@ int main(int argc, char** argv) {
8083 PCU_Comm_Init ();
8184
8285 // Initialize logging.
86+ lion_set_verbosity (1 );
8387 lion_set_stdout (stdout);
8488 lion_set_stderr (stderr);
8589
@@ -93,7 +97,7 @@ int main(int argc, char** argv) {
9397
9498 // Parse arguments.
9599 bool volume_flag = false , write_flag = false , analytic_flag = false ,
96- verbose_flag = false ;
100+ verbose_flag = false , mds_flag = false ;
97101 for (int i = 1 ; i < argc - 2 ; ++i) {
98102 if (*argv[i] == ' -' ) {
99103 for (int j = 1 ; argv[i][j] != ' \0 ' ; ++j) {
@@ -111,6 +115,9 @@ int main(int argc, char** argv) {
111115 case ' w' :
112116 write_flag = true ;
113117 break ;
118+ case ' m' :
119+ mds_flag = true ;
120+ break ;
114121 default :
115122 printf (" Error: invalid flag.\n " );
116123 printUsage (argv[0 ]);
@@ -147,8 +154,9 @@ int main(int argc, char** argv) {
147154 filenames.push_back (createFileName);
148155 M_GModel gmodel = cs.load_files (filenames);
149156
157+ M_MModel mmodel;
150158 if (volume_flag) {
151- M_MModel mmodel = cs.generate_mesh ();
159+ mmodel = cs.generate_mesh ();
152160 if (mmodel.is_invalid ()) {
153161 lion_eprint (1 , " FATAL: Failed to mesh the model.\n " );
154162 myExit (EXIT_FAILURE);
@@ -159,7 +167,8 @@ int main(int argc, char** argv) {
159167 std::vector<M_MModel> mmodels;
160168 MG_API_CALL (m, get_associated_mesh_models (gmodel, mmodels));
161169 PCU_ALWAYS_ASSERT (mmodels.size () == 1 );
162- MG_API_CALL (m, set_current_model (mmodels[0 ]));
170+ mmodel = mmodels[0 ];
171+ MG_API_CALL (m, set_current_model (mmodel));
163172 }
164173
165174 if (write_flag) {
@@ -174,21 +183,35 @@ int main(int argc, char** argv) {
174183
175184 // Make APF adapter over Capstone mesh.
176185 ma::Mesh* apfCapMesh = apf::createMesh (m, g);
186+ apf::writeVtkFiles (" core_capVol_cap.vtk" , apfCapMesh);
187+
188+ ma::Mesh* adaptMesh = apfCapMesh;
189+ if (mds_flag) {
190+ adaptMesh = apf::createMdsMesh (apfCapMesh->getModel (), apfCapMesh);
191+ adaptMesh->verify ();
192+ if (write_flag) {
193+ apf::writeVtkFiles (" core_capVol_mds.vtk" , adaptMesh);
194+ }
195+ apfCapMesh->setModel (nullptr ); // Disown the model.
196+ delete apfCapMesh;
197+ apfCapMesh = nullptr ;
198+ MG_API_CALL (m, delete_model (mmodel));
199+ }
177200
178201 // Choose appropriate size-field.
179202 ma::AnisotropicFunction* sf = nullptr ;
180203 switch (mode) {
181204 case 1 :
182- sf = new UniformAniso (apfCapMesh );
205+ sf = new UniformAniso (adaptMesh );
183206 break ;
184207 case 2 :
185- sf = new WingShock (apfCapMesh , 50 );
208+ sf = new WingShock (adaptMesh , 50 );
186209 break ;
187210 case 3 :
188- sf = new Shock (apfCapMesh );
211+ sf = new Shock (adaptMesh );
189212 break ;
190213 case 4 :
191- sf = new CylBoundaryLayer (apfCapMesh );
214+ sf = new CylBoundaryLayer (adaptMesh );
192215 break ;
193216 default :
194217 lion_eprint (1 , " FATAL: Invalid size-field.\n " );
@@ -200,38 +223,38 @@ int main(int argc, char** argv) {
200223 apf::Field* scaleField = nullptr ;
201224 ma::Input *in = nullptr ;
202225 if (!analytic_flag || write_flag) {
203- frameField = apf::createFieldOn (apfCapMesh , " adapt_frames" , apf::MATRIX);
204- scaleField = apf::createFieldOn (apfCapMesh , " adapt_scales" , apf::VECTOR);
226+ frameField = apf::createFieldOn (adaptMesh , " adapt_frames" , apf::MATRIX);
227+ scaleField = apf::createFieldOn (adaptMesh , " adapt_scales" , apf::VECTOR);
205228
206229 ma::Entity *v;
207- ma::Iterator* it = apfCapMesh ->begin (0 );
208- while ( (v = apfCapMesh ->iterate(it)) ) {
230+ ma::Iterator* it = adaptMesh ->begin (0 );
231+ while ( (v = adaptMesh ->iterate(it)) ) {
209232 ma::Vector s;
210233 ma::Matrix f;
211234 sf->getValue (v, f, s);
212235 apf::setVector (scaleField, v, 0 , s);
213236 apf::setMatrix (frameField, v, 0 , f);
214237 }
215- apfCapMesh ->end (it);
238+ adaptMesh ->end (it);
216239
217240 if (write_flag) {
218- apf::writeVtkFiles (" core_capVol_before" , apfCapMesh );
241+ apf::writeVtkFiles (" core_capVol_before.vtk " , adaptMesh );
219242 }
220243 }
221244
222245 if (!analytic_flag) {
223246 // Pass the field data.
224- in = ma::makeAdvanced (ma::configure (apfCapMesh , scaleField, frameField));
247+ in = ma::makeAdvanced (ma::configure (adaptMesh , scaleField, frameField));
225248 } else {
226249 // Pass the function.
227- in = ma::makeAdvanced (ma::configure (apfCapMesh , sf));
250+ in = ma::makeAdvanced (ma::configure (adaptMesh , sf));
228251 }
229252
230253 in->shouldSnap = true ;
231254 in->shouldTransferParametric = true ;
232255 in->shouldFixShape = true ;
233256 in->shouldForceAdaptation = true ;
234- if (apfCapMesh ->getDimension () == 2 )
257+ if (adaptMesh ->getDimension () == 2 )
235258 in->goodQuality = 0.04 ; // this is mean-ratio squared
236259 else // 3D meshes
237260 in->goodQuality = 0.027 ; // this is the mean-ratio cubed
@@ -246,11 +269,24 @@ int main(int argc, char** argv) {
246269
247270 if (volume_flag) {
248271 // We can't verify surface meshes.
249- apfCapMesh ->verify ();
272+ adaptMesh ->verify ();
250273 }
251274
252275 if (write_flag) {
253- apf::writeVtkFiles (" core_capVol_after" , apfCapMesh);
276+ if (mds_flag) {
277+ apf::writeVtkFiles (" core_capVol_after_mds.vtk" , adaptMesh);
278+ MG_API_CALL (m, create_associated_model (mmodel, gmodel, " MDS Adapt" ));
279+ MG_API_CALL (m, set_adjacency_state (REGION2FACE|REGION2EDGE|REGION2VERTEX|
280+ FACE2EDGE|FACE2VERTEX));
281+ MG_API_CALL (m, set_reverse_states ());
282+ // MG_API_CALL(m, compute_adjacency());
283+ ma::Mesh* newCapMesh = apf::createMesh (m, g);
284+ apf::convert (adaptMesh, newCapMesh);
285+ apf::writeVtkFiles (" core_capVol_after_cap.vtk" , newCapMesh);
286+ apf::destroyMesh (newCapMesh);
287+ } else {
288+ apf::writeVtkFiles (" core_capVol_after_cap.vtk" , adaptMesh);
289+ }
254290 writeCre (cs, " core_capVol_after.cre" );
255291 }
256292
@@ -264,9 +300,7 @@ int main(int argc, char** argv) {
264300 }
265301
266302 // Clean up.
267- if (frameField) apf::destroyField (frameField);
268- if (scaleField) apf::destroyField (scaleField);
269- apf::destroyMesh (apfCapMesh);
303+ apf::destroyMesh (adaptMesh);
270304 delete sf;
271305
272306 // Exit calls.
0 commit comments