void test_vertices() { size_t nbVert = mVertices.size(); CPPUNIT_ASSERT_EQUAL(9,(int)nbVert); Mesquite::MsqVertex correct_coords[9], coords[9]; correct_coords[0].set(1,0,0); correct_coords[1].set(0,1.732,0); correct_coords[2].set(-1,0,0); correct_coords[3].set(-1,-2,0); correct_coords[4].set(1,-2,0); correct_coords[5].set(2.732,1,0); correct_coords[6].set(1.732,2.732,0); correct_coords[7].set(-1.732,2.732,0); correct_coords[8].set(-2.732,1,0); mMesh->vertices_get_coordinates(&mVertices[0], coords, nbVert, mErr); CPPUNIT_ASSERT(!mErr); for (size_t i=0; i<nbVert; ++i) { for (int j=0; j<3; ++j) CPPUNIT_ASSERT_DOUBLES_EQUAL(coords[i][j], correct_coords[i][j], .01); } coords[3].set(2.,3.,4.); mMesh->vertex_set_coordinates(mVertices[3], coords[3], mErr); CPPUNIT_ASSERT(!mErr); Mesquite::MsqVertex coords_2; mMesh->vertices_get_coordinates(&mVertices[3], &coords_2, 1, mErr); CPPUNIT_ASSERT(!mErr); for (int j=0; j<3; ++j) CPPUNIT_ASSERT_DOUBLES_EQUAL(coords[3][j], coords_2[j], 1e-6); }
/* Automatically called by CppUnit before each test function. */ void setUp() { // Read a VTK file -- 1 triangle flanked by 1 quad on each side (1 tri + 3 quads) mMesh = new Mesquite::MeshImpl; mMesh->read_vtk(MESH_FILES_DIR "2D/VTK/hybrid_3quad_1tri.vtk", mErr); CPPUNIT_ASSERT(!mErr); // Get mesh data mMesh->get_all_elements( mElements, mErr ); CPPUNIT_ASSERT(!mErr); mMesh->elements_get_attached_vertices( &mElements[0], mElements.size(), mConnectivity, mOffsets, mErr ); CPPUNIT_ASSERT(!mErr); // Construct list of vertices w/out duplicates from // connectivity list. std::vector<Mesquite::Mesh::VertexHandle>::iterator new_end; mVertices = mConnectivity; std::sort( mVertices.begin(), mVertices.end() ); new_end = std::unique( mVertices.begin(), mVertices.end() ); mVertices.resize( new_end - mVertices.begin() ); }
void test_vertex_byte() { size_t nbVert = mVertices.size(); size_t i; unsigned char* bytes = new unsigned char[nbVert]; mMesh->vertices_get_byte(&mVertices[0], bytes, nbVert, mErr); CPPUNIT_ASSERT(!mErr); // Asserts all vertex bytes are initialised to 0. for (i=0; i<nbVert; ++i) CPPUNIT_ASSERT(bytes[i] == 0); // Test various vertex byte read / write routines. bytes[3] |= 4; mMesh->vertices_set_byte(&mVertices[0], bytes, nbVert, mErr); CPPUNIT_ASSERT(!mErr); mMesh->vertex_set_byte(mVertices[5], 8, mErr); CPPUNIT_ASSERT(!mErr); unsigned char byte; mMesh->vertex_get_byte(mVertices[3], &byte, mErr); CPPUNIT_ASSERT(!mErr); CPPUNIT_ASSERT(byte == 4); mMesh->vertices_get_byte(&mVertices[0], bytes, nbVert, mErr); CPPUNIT_ASSERT(!mErr); for (i=0; i<nbVert; ++i) { if (i==3) CPPUNIT_ASSERT(bytes[i] == 4); else if (i==5) CPPUNIT_ASSERT(bytes[i] == 8); else CPPUNIT_ASSERT(bytes[i] == 0); } delete [] bytes; }
void test_plane_tri_xz() { MsqPrintError err(cout); Mesquite::MeshImpl mesh; mesh.read_vtk(MESH_FILES_DIR "2D/VTK/tri_5_xz.vtk", err); CPPUNIT_ASSERT(!err); //create geometry: plane y=5, normal (0,1,0) Vector3D pnt(0,-5,0); Vector3D s_norm(0,-1,0); Mesquite::PlanarDomain msq_geom(s_norm, pnt); // creates an intruction queue InstructionQueue queue1; //creates a asm quality metric ... ConditionNumberQualityMetric smooth; // ... and builds an objective function with it (untangle) LPtoPTemplate smooth_func(&smooth,1,err); //Make sure no errors CPPUNIT_ASSERT(!err); // creates the cg optimization procedures ConjugateGradient pass1( &smooth_func, err ); //pass1->set_patch_type(PatchData::ELEMENTS_ON_VERTEX_PATCH, err,1 ,1); pass1.use_global_patch(); pass1.set_debugging_level(1); //Make sure no errors CPPUNIT_ASSERT(!err); QualityAssessor qa=QualityAssessor( &smooth ); //**********Set stopping criterion 5 iterates **************** TerminationCriterion sc5; sc5.add_iteration_limit( 5 ); pass1.set_inner_termination_criterion(&sc5); //StoppingCriterion sc5(StoppingCriterion::NUMBER_OF_PASSES,5); //pass1->set_stopping_criterion(&sc5); TerminationCriterion sc_inner; sc_inner.add_iteration_limit( 5 ); pass1.set_inner_termination_criterion(&sc_inner); //pass1->set_maximum_iteration(5); queue1.set_master_quality_improver(&pass1, err); CPPUNIT_ASSERT(!err); //********************UNTANGLE******************************* //Make sure no errors CPPUNIT_ASSERT(!err); // launches optimization on mesh_set1 double orig_qa_val=qa.loop_over_mesh(&mesh, &msq_geom, 0, err); //Make sure no errors CPPUNIT_ASSERT(!err); queue1.run_instructions(&mesh, &msq_geom, err); CPPUNIT_ASSERT(!err); //Make sure no errors CPPUNIT_ASSERT(!err); double fin_qa_val=qa.loop_over_mesh(&mesh, &msq_geom, 0, err); //Make sure no errors CPPUNIT_ASSERT(!err); //make sure 'quality' improved CPPUNIT_ASSERT( (fin_qa_val-orig_qa_val) <= 0.0 ); print_timing_diagnostics(cout); }
int main() { Mesquite::MeshImpl mesh; MsqPrintError err(cout); mesh.read_vtk(MESH_FILES_DIR "2D/vtk/quads/untangled/square_quad_2.vtk", err); if (err) return 1; //create geometry: plane z=0, normal (0,0,1) Vector3D pnt(0,0,5); Vector3D s_norm(0,0,1); Mesquite::PlanarDomain msq_geom(s_norm, pnt); // creates an intruction queue LaplaceWrapper laplacian_smoother; mesh.write_vtk("original_mesh.vtk", err); if (err) return 1; // launches optimization on mesh_set1 MeshDomainAssoc mesh_and_domain = MeshDomainAssoc(&mesh, &msq_geom); laplacian_smoother.run_instructions(&mesh_and_domain, err); if (err) return 1; mesh.write_vtk("smoothed_mesh.vtk", err); if (err) return 1; }
void test_cg_mesh_cond_sphere() { Mesquite::MeshImpl mesh; Mesquite::MsqPrintError err(cout); mesh.read_vtk(MESH_FILES_DIR "2D/vtk/quads/untangled/quads_on_sphere_529.vtk", err); CPPUNIT_ASSERT(!err); //create geometry: sphere, center (2,2,0), radius 3 Vector3D center(2,2,0); SphericalDomain msq_geom(center, 3.0); // creates an intruction queue InstructionQueue queue1; // creates a mean ratio quality metric ... ConditionNumberQualityMetric shape; UntangleBetaQualityMetric untan; // ... and builds an objective function with it LPtoPTemplate obj_func(&shape, 2, err); //Make sure no errors CPPUNIT_ASSERT(!err); // creates the steepest descent optimization procedures ConjugateGradient pass1( &obj_func, err ); //SteepestDescent* pass2 = new SteepestDescent( obj_func ); pass1.use_global_patch(); //Make sure no errors CPPUNIT_ASSERT(!err); QualityAssessor qa=QualityAssessor( &shape ); //**********Set stopping criterion 5 iterates **************** //StoppingCriterion sc5(StoppingCriterion::NUMBER_OF_PASSES,5); //pass1->set_stopping_criterion(&sc5); TerminationCriterion sc5; sc5.add_iteration_limit( 5 ); pass1.set_inner_termination_criterion(&sc5); //CG's debugging print, increase integer to get more print info pass1.set_debugging_level(0); // queue1.add_preconditioner(pass2, err); CPPUNIT_ASSERT(!err); queue1.set_master_quality_improver(&pass1, err); CPPUNIT_ASSERT(!err); //Make sure no errors CPPUNIT_ASSERT(!err); // launches optimization on mesh_set1 MeshDomainAssoc mesh_and_domain = MeshDomainAssoc(&mesh, &msq_geom); double orig_qa_val=qa.loop_over_mesh(&mesh_and_domain, 0, err); //Make sure no errors CPPUNIT_ASSERT(!err); queue1.run_instructions(&mesh_and_domain, err); CPPUNIT_ASSERT(!err); //Make sure no errors CPPUNIT_ASSERT(!err); double fin_qa_val=qa.loop_over_mesh(&mesh_and_domain, 0, err); //Make sure no errors CPPUNIT_ASSERT(!err); //make sure 'quality' improved CPPUNIT_ASSERT( fin_qa_val <= orig_qa_val ); }
void test_lapl_geo_sphere() { Mesquite::MeshImpl mesh; Mesquite::MsqPrintError err(cout); mesh.read_vtk(MESH_FILES_DIR "2D/vtk/tris/untangled/Mesquite_geo_10242.vtk", err); //create geometry sphere: ratius 1, centered at (0,0,0) Vector3D center(0,0,0); Mesquite::SphericalDomain msq_geom(center, 1.0); // creates an intruction queue InstructionQueue queue1; // creates an edge length metric ... EdgeLengthQualityMetric edg_len; //create the laplacian smoother LaplacianSmoother lapl; //Make sure no errors CPPUNIT_ASSERT(!err); //create a quality assessor QualityAssessor qa=QualityAssessor( &edg_len ); //*******Set stopping criterion 10 iterates *********** //StoppingCriterion sc10(StoppingCriterion::NUMBER_OF_PASSES,10); //lapl->set_stopping_criterion(&sc10); TerminationCriterion sc10; sc10.add_iteration_limit( 10 ); lapl.set_outer_termination_criterion(&sc10); //qa, qi, qa queue1.set_master_quality_improver(&lapl, err); //Make sure no errors CPPUNIT_ASSERT(!err); // launches optimization on mesh_set1 MeshDomainAssoc mesh_and_domain = MeshDomainAssoc(&mesh, &msq_geom); double orig_qa_val=qa.loop_over_mesh(&mesh_and_domain, 0, err); //Make sure no errors CPPUNIT_ASSERT(!err); queue1.run_instructions(&mesh_and_domain, err); CPPUNIT_ASSERT(!err); //Make sure no errors CPPUNIT_ASSERT(!err); double fin_qa_val=qa.loop_over_mesh(&mesh_and_domain, 0, err); //Make sure no errors CPPUNIT_ASSERT(!err); //make sure 'quality' improved CPPUNIT_ASSERT( fin_qa_val <= orig_qa_val ); }
void test_smart_lapl_sphere() { Mesquite::MeshImpl mesh; Mesquite::MsqPrintError err(cout); mesh.read_vtk(MESH_FILES_DIR "2D/vtk/quads/untangled/quads_on_sphere_529.vtk", err); //create geometry sphere: ratius 1, centered at (0,0,0) Vector3D center(2,2,0); SphericalDomain msq_geom(center, 3.0); // creates an intruction queue InstructionQueue queue1; // creates an edge length metric ... IdealWeightInverseMeanRatio shape_metric(err); LInfTemplate shape_func(&shape_metric); //create the smart laplacian smoother SmartLaplacianSmoother s_lapl(&shape_func); //Make sure no errors CPPUNIT_ASSERT(!err); //*******Set stopping criterion 5 iterates *********** TerminationCriterion sc5; sc5.add_iteration_limit( 5 ); s_lapl.set_outer_termination_criterion(&sc5); //qa, qi, qa queue1.set_master_quality_improver(&s_lapl, err); CPPUNIT_ASSERT(!err); //Make sure no errors CPPUNIT_ASSERT(!err); // launches optimization on mesh_set1 QualityAssessor qa=QualityAssessor( &shape_metric ); MeshDomainAssoc mesh_and_domain = MeshDomainAssoc(&mesh, &msq_geom); double orig_val=qa.loop_over_mesh(&mesh_and_domain, 0, err); //Make sure no errors CPPUNIT_ASSERT(!err); queue1.run_instructions(&mesh_and_domain, err); CPPUNIT_ASSERT(!err); //Make sure no errors CPPUNIT_ASSERT(!err); double final_val= qa.loop_over_mesh(&mesh_and_domain, 0, err); //Make sure no errors CPPUNIT_ASSERT(!err); //make sure 'quality' improved CPPUNIT_ASSERT( final_val < orig_val ); }
void test_element_get_attached_vertex_indices() { // Find the index of the triangle Mesquite::EntityTopology topo=Mesquite::MIXED; int tri_index = -1; while (topo != Mesquite::TRIANGLE) { ++tri_index; CPPUNIT_ASSERT((unsigned)tri_index < mElements.size()); Mesquite::Mesh::ElementHandle handle = mElements[tri_index]; mMesh->elements_get_topologies(&handle, &topo, 1, mErr); CPPUNIT_ASSERT(!mErr); } // creates list with correct vertices coordinates for the triangle std::vector<Mesquite::Vector3D> correct_coords; correct_coords.push_back(Mesquite::Vector3D(1.,0.,0.)); correct_coords.push_back(Mesquite::Vector3D(0.,1.732050807,0.)); correct_coords.push_back(Mesquite::Vector3D(-1.,0.,0.)); // Creates same list from the mesh implementation std::vector<Mesquite::MsqVertex> tri_coords(3); mMesh->vertices_get_coordinates(&mConnectivity[mOffsets[tri_index]], &tri_coords[0], 3, mErr ); CPPUNIT_ASSERT(!mErr); // Makes sure both list contain the same elements (not necessarily in the same order). std::vector<Mesquite::Vector3D>::iterator correct_iter; std::vector<Mesquite::MsqVertex>::iterator tri_iter; for (tri_iter = tri_coords.begin(); tri_iter != tri_coords.end(); ++tri_iter) { for (correct_iter = correct_coords.begin(); correct_iter != correct_coords.end(); ++correct_iter) { if (Mesquite::Vector3D::distance_between(*tri_iter, *correct_iter) < 10e-4) break; } // check if a match was found CPPUNIT_ASSERT( correct_iter != correct_coords.end() ); // remove match from list correct_coords.erase( correct_iter ); } CPPUNIT_ASSERT(correct_coords.empty()); }
void test_vertex_is_fixed() { size_t nbVert = mVertices.size(); bool correct_fixed[9] = {false, false, false, true, true, true, true, true, true}; bool fixed[9]; mMesh->vertices_get_fixed_flag( &mVertices[0], fixed, 9, mErr ); CPPUNIT_ASSERT(!mErr); for (size_t i=0; i<nbVert; ++i) { CPPUNIT_ASSERT(fixed[i] == correct_fixed[i]); } }
void test_vertex_get_attached_elements() { size_t i; const size_t nbVert = mVertices.size(); std::vector<Mesquite::Mesh::ElementHandle> elements; std::vector<size_t> offsets; mMesh->vertices_get_attached_elements( &mVertices[0], mVertices.size(), elements, offsets, mErr ); CPPUNIT_ASSERT(!mErr); CPPUNIT_ASSERT_EQUAL(offsets.size(), mVertices.size() + 1); // checks we have 6 vertices contained in 1 element only // and 3 vertices contained in 3 elements. int n1=0; int n3=0; for (i = 1; i <= mVertices.size(); ++i) { const size_t nev = offsets[i] - offsets[i-1]; if (nev==1) ++n1; else if (nev==3) ++n3; else // failure. CPPUNIT_ASSERT(false); } CPPUNIT_ASSERT(n1==6); CPPUNIT_ASSERT(n3==3); // gets the index of a vertex in a corner int one_corner_vertex_index=0; for (i = 0; i < nbVert; ++i) { const size_t nev = offsets[i+1] - offsets[i]; if (1 == nev) break; } CPPUNIT_ASSERT( i < nbVert ); one_corner_vertex_index = i; // retrieve the attached element. // This is a poor test. We allow an element handle of zero, // and just testing that the function returned something isn't // that useful. - J.K. //Mesquite::Mesh::ElementHandle elem=0; //mMesh->vertex_get_attached_elements(mVertices[one_corner_vertex_index], &elem, 1, mErr); //CPPUNIT_ASSERT(!mErr); //CPPUNIT_ASSERT(elem!=0); }
void test_vertex_is_fixed() { size_t nbVert = mVertices.size(); bool correct_fixed[9] = {false, false, false, true, true, true, true, true, true}; std::vector<bool> fixed; mMesh->vertices_get_fixed_flag( arrptr(mVertices), fixed, 9, mErr ); CPPUNIT_ASSERT(!mErr); CPPUNIT_ASSERT_EQUAL( (size_t)8, fixed.size() ); for (size_t i=0; i<nbVert; ++i) { CPPUNIT_ASSERT_EQUAL(correct_fixed[i], (bool)fixed[i]); } }
void test_elements_get_topology() { const size_t nbElem = mElements.size(); int nb_quads=0; int nb_tri=0; Mesquite::EntityTopology* topos = new Mesquite::EntityTopology[nbElem]; mMesh->elements_get_topologies(&mElements[0], topos, nbElem, mErr); CPPUNIT_ASSERT(!mErr); for (size_t i=0; i<nbElem; ++i) { switch (topos[i]) { case Mesquite::TRIANGLE: ++nb_tri; break; case Mesquite::QUADRILATERAL: ++nb_quads; break; default: CPPUNIT_FAIL("Topology should be quad or Hex only."); } } CPPUNIT_ASSERT_EQUAL(1,nb_tri); CPPUNIT_ASSERT_EQUAL(3,nb_quads); delete []topos; }
int main() { MsqPrintError err(std::cout); Mesquite::MeshImpl mesh; mesh.read_vtk(MESH_FILES_DIR "3D/vtk/hexes/untangled/hexes_4by2by2.vtk", err); // creates an intruction queue InstructionQueue queue1; // creates a mean ratio quality metric ... IdealWeightInverseMeanRatio mean_ratio(err); if (err) return 1; ConditionNumberQualityMetric cond_num; mean_ratio.set_averaging_method(QualityMetric::LINEAR); // ... and builds an objective function with it //LInfTemplate* obj_func = new LInfTemplate(mean_ratio); LPtoPTemplate obj_func(&mean_ratio, 2, err); if (err) return 1; // creates the steepest descent optimization procedures SteepestDescent pass1( &obj_func ); pass1.use_global_patch(); //if (err) return 1; //pass1.set_maximum_iteration(6); QualityAssessor stop_qa=QualityAssessor(&mean_ratio); if (err) return 1; stop_qa.add_quality_assessment(&cond_num); if (err) return 1; //**************Set stopping criterion**************** // StoppingCriterion sc1(&stop_qa,1.0,1.8); //StoppingCriterion sc2(StoppingCriterion::NUMBER_OF_PASSES,1); TerminationCriterion tc2; tc2.add_iteration_limit( 1 ); // CompositeAndStoppingCriterion sc(&sc1,&sc2); pass1.set_inner_termination_criterion(&tc2); // adds 1 pass of pass1 to mesh_set1 // queue1.add_preconditioner(pass1, err); // if (err) return 1; queue1.add_quality_assessor(&stop_qa,err); queue1.set_master_quality_improver(&pass1, err); if (err) return 1; queue1.add_quality_assessor(&stop_qa,err); if (err) return 1; // adds 1 passes of pass2 to mesh_set1 // mesh_set1.add_quality_pass(pass2); mesh.write_vtk("original_mesh.vtk", err); if (err) return 1; // launches optimization on mesh_set1 queue1.run_instructions(&mesh, err); if (err) return 1; mesh.write_vtk("smoothed_mesh.vtk", err); if (err) return 1; return 0; }
int main() { /* Reads a Mesh file */ const char *file_name = // MESH_FILES_DIR "2D/vtk/tris/untangled/equil_tri2.vtk"; // MESH_FILES_DIR "2D/vtk/tris/untangled/tri_20258.vtk"; // MESH_FILES_DIR "3D/vtk/tets/untangled/tet_1.vtk"; // MESH_FILES_DIR "3D/vtk/hexes/untangled/cube_tet_2.vtk"; MESH_FILES_DIR "3D/vtk/tets/untangled//tire.vtk"; printf("Loading mesh set 1\n"); MsqPrintError err( cout ); Mesquite::MeshImpl mesh; mesh.read_vtk(file_name, err); if (err) return 1; // Creates an intruction queue // printf("Creating instruction queue\n"); InstructionQueue queue1; // Creates a condition number quality metric // printf("Creating quality metric\n"); ConditionNumberQualityMetric cond_no; // Create the NonSmooth Steepest Descent procedures // printf("creating optimizer\n"); NonSmoothDescent minmax_method( &cond_no ); // Set a termination criterion TerminationCriterion tc2; tc2.add_iteration_limit( 1 ); minmax_method.set_outer_termination_criterion(&tc2); // Set up the quality assessor // printf("Setting up the quality assessor\n"); QualityAssessor quality_assessor=QualityAssessor(&cond_no); // assess the quality of the initial mesh queue1.add_quality_assessor(&quality_assessor, err); if (err) return 1; // Set the max min method to be the master quality improver queue1.set_master_quality_improver(&minmax_method, err); if (err) return 1; // assess the quality of the final mesh queue1.add_quality_assessor(&quality_assessor, err); if (err) return 1; // write out the original mesh // printf("Writing out the original mesh\n"); mesh.write_vtk("original_mesh.vtk", err); if (err) return 1; // launches optimization on mesh_set1 // printf("Running the instruction queue\n"); queue1.run_instructions(&mesh, err); if (err) return 1; // write out the smoothed mesh // printf("Writing out the final mesh\n"); mesh.write_vtk("smoothed_mesh.vtk", err); if (err) return 1; return 0; }
bool smooth_mixed_mesh( const char* filename ) { Mesquite::MsqPrintError err(cout); // print a little output so we know when we died std::cout << "**************************************************************************" << std::endl << "* Smoothing: " << filename << std::endl << "**************************************************************************" << std::endl; // The instruction queue to set up InstructionQueue Q; // Use numeric approx of derivitives until analytic solutions // are working for pyramids IdealWeightInverseMeanRatio mr_metric(err); //sRI_DFT dft_metric; UntangleBetaQualityMetric un_metric(0); CPPUNIT_ASSERT(!err); // Create Mesh object Mesquite::MeshImpl mesh; mesh.read_vtk(filename, err); CPPUNIT_ASSERT(!err); // Set up a preconditioner LInfTemplate pre_obj_func( &un_metric ); ConjugateGradient precond( &pre_obj_func, err ); CPPUNIT_ASSERT(!err); precond.use_element_on_vertex_patch(); TerminationCriterion pre_term, pre_outer; //pre_term.add_relative_quality_improvement( 0.1 ); pre_term .add_iteration_limit( 3 ); pre_outer.add_iteration_limit( 1 ); CPPUNIT_ASSERT(!err); precond.set_inner_termination_criterion( &pre_term ); precond.set_outer_termination_criterion( &pre_outer ); //precond.use_element_on_vertex_patch(); // Set up objective function LPtoPTemplate obj_func(&mr_metric, 1, err); CPPUNIT_ASSERT(!err); // Create solver FeasibleNewton solver( &obj_func, true ); CPPUNIT_ASSERT(!err); solver.use_global_patch(); CPPUNIT_ASSERT(!err); // Set stoping criteria for solver TerminationCriterion tc_inner; tc_inner.add_relative_quality_improvement( 0.25 ); solver.set_inner_termination_criterion(&tc_inner); TerminationCriterion tc_outer; tc_outer.add_iteration_limit( 1 ); CPPUNIT_ASSERT(!err); solver.set_outer_termination_criterion(&tc_outer); // Create a QualityAssessor Mesquite::QualityAssessor qa; qa.add_quality_assessment( &mr_metric ); qa.add_quality_assessment( &un_metric ); Q.add_quality_assessor( &qa, err ); CPPUNIT_ASSERT(!err); // Add untangler to queue Q.add_preconditioner( &precond, err ); CPPUNIT_ASSERT(!err); Q.add_quality_assessor( &qa, err ); CPPUNIT_ASSERT(!err); // Add solver to queue Q.set_master_quality_improver(&solver, err); CPPUNIT_ASSERT(!err); Q.add_quality_assessor( &qa, err ); CPPUNIT_ASSERT(!err); // And smooth... Q.run_instructions(&mesh, err); CPPUNIT_ASSERT(!err); return false; }
int main( int argc, char* argv[] ) { unsigned i; const char* input_file = MESH_FILES_DIR "3D/VTK/mixed-hex-pyr-tet.vtk"; if (argc == 2) input_file = argv[1]; else if (argc != 1) { std::cerr << "Invalid arguments.\n"; return 2; } Mesquite::MsqPrintError err(cout); IdealWeightMeanRatio m1; IdealWeightInverseMeanRatio m2(err); ConditionNumberQualityMetric m3; QualityMetric* metrics[] = { &m1, &m2, &m3, 0 }; // Read Mesh Mesquite::MeshImpl mesh; mesh.read_vtk(MESH_FILES_DIR "3D/VTK/12-pyramid-unit-sphere.vtk", err); CPPUNIT_ASSERT(!err); Mesquite::MeshImpl ideal_mesh; ideal_mesh.read_vtk(MESH_FILES_DIR "3D/VTK/12-pyramid-unit-sphere.vtk", err); CPPUNIT_ASSERT(!err); // Check that the mesh read correctly, and contains what is // expected later. // Get mesh data // Expecting file to contain 12 pyramid elements constructed // from 15 vertices. std::vector<Mesh::VertexHandle> vert_array; std::vector<Mesh::ElementHandle> elem_array; std::vector<size_t> conn_offsets; mesh.get_all_elements( elem_array, err ); CPPUNIT_ASSERT(!err); CPPUNIT_ASSERT( elem_array.size() == 12 ); mesh.elements_get_attached_vertices( &elem_array[0], elem_array.size(), vert_array, conn_offsets, err ); CPPUNIT_ASSERT(!err); CPPUNIT_ASSERT(vert_array.size() == 60); CPPUNIT_ASSERT(conn_offsets.size() == 13); EntityTopology type_array[12]; mesh.elements_get_topologies( &elem_array[0], type_array, 12, err ); CPPUNIT_ASSERT(!err); // Verify element types and number of vertices for (i = 0; i < 12; ++i) { CPPUNIT_ASSERT( type_array[i] == PYRAMID ); CPPUNIT_ASSERT( conn_offsets[i] == 5*i ); } // All pyramids should share a common apex, at the // center of the sphere Mesh::VertexHandle apex_handle = vert_array[4]; for (i = 1; i < 12; ++i) { CPPUNIT_ASSERT( vert_array[5*i+4] == apex_handle ); } // Verify that apex is at origin and all other vertices are // on unit sphere MsqVertex vertices[60]; mesh.vertices_get_coordinates( &vert_array[0], vertices, 60, err ); CPPUNIT_ASSERT(!err); for (i = 0; i < 60; ++i) { if (vert_array[i] == apex_handle) CPPUNIT_ASSERT( vertices[i].within_tolerance_box( Vector3D(0,0,0), 1e-6 ) ); else CPPUNIT_ASSERT( fabs(1.0 - vertices[i].length()) < 1e-6 ); } // Try smoothing w/out moving the free vertex and verify that // the smoother didn't move the vertex Vector3D position(0,0,0); for (i = 0; metrics[i] != NULL; ++i) CPPUNIT_ASSERT( !smooth_mesh( &mesh, &ideal_mesh, apex_handle, position, metrics[i] ) ); // Now try moving the vertex and see if the smoother moves it back // to the origin position.set( 0.1, 0.1, 0.1 ); for (i = 0; metrics[i] != NULL; ++i) CPPUNIT_ASSERT( !smooth_mesh( &mesh, &ideal_mesh, apex_handle, position, metrics[i] ) ); // Now try moving the vertex further and see if the smoother moves it back // to the origin position.set( 0.3, 0.3, 0.3 ); for (i = 0; metrics[i] != NULL; ++i) CPPUNIT_ASSERT( !smooth_mesh( &mesh, &ideal_mesh, apex_handle, position, metrics[i] ) ); // Now try smoothing a real mixed mesh CPPUNIT_ASSERT( !smooth_mixed_mesh( input_file ) ); return 0; }
int main() { Mesquite::MeshImpl mesh; MsqPrintError err(cout); //create geometry: plane z=0, normal (0,0,1) Vector3D pnt(0,0,0); Vector3D s_norm(0,0,1); Mesquite::PlanarDomain msq_geom(s_norm, pnt); //mesh->read_vtk(MESH_FILES_DIR "2D/VTK/cube-clip-corner.vtk", err); mesh.read_vtk(MESH_FILES_DIR "2D/VTK/hybrid_3quad_1tri.vtk", err); if (err) return 1; // creates an intruction queue InstructionQueue queue1; // creates a mean ratio quality metric ... IdealWeightInverseMeanRatio mean_ratio(err); if (err) return 1; // mean_ratio->set_gradient_type(QualityMetric::NUMERICAL_GRADIENT); // mean_ratio->set_hessian_type(QualityMetric::NUMERICAL_HESSIAN); //mean_ratio->set_averaging_method(QualityMetric::SUM, err); //MSQ_CHKERR(err); // ... and builds an objective function with it LPtoPTemplate obj_func(&mean_ratio, 2, err); if (err) return 1;; // creates the steepest descent, feas newt optimization procedures //ConjugateGradient* pass1 = new ConjugateGradient( &obj_func, err ); FeasibleNewton pass1( &obj_func, true ); pass1.use_global_patch(); if (err) return 1;; QualityAssessor qa=QualityAssessor(&mean_ratio); if (err) return 1;; // **************Set termination criterion**************** TerminationCriterion tc_inner; tc_inner.add_iteration_limit( 1 ); //_inner.add_absolute_quality_improvement( OF_value ); //tc_inner.add_absolute_gradient_L2_norm( OF_value ); TerminationCriterion tc_outer; //tc_outer.add_iteration_limit( 1 ); tc_outer.add_iteration_limit( 1 ); pass1.set_inner_termination_criterion(&tc_inner); pass1.set_outer_termination_criterion(&tc_outer); queue1.add_quality_assessor(&qa,err); if (err) return 1; // adds 1 pass of pass1 to mesh_set1 queue1.set_master_quality_improver(&pass1, err); if (err) return 1; queue1.add_quality_assessor(&qa,err); if (err) return 1; mesh.write_vtk("original_mesh.vtk",err); if (err) return 1; queue1.run_instructions(&mesh, &msq_geom, err); if (err) return 1; mesh.write_vtk("smoothed_mesh.vtk",err); if (err) return 1; //std::cout<<"\n\nNow running the shape wrapper.\n=n"; //ShapeImprovementWrapper wrap(100); //wrap.run_instructions(mesh_set1, err); MSQ_CHKERR(err); print_timing_diagnostics(cout); return 0; }
int main(int argc, char* argv[]) { std::cout << std::endl << "********* Wrappers Timing Tests **********" << std::endl << "Version " << version_string(true) << std::endl << std::endl; Mesquite::MsqPrintError err(cout); Mesquite::MeshImpl mesh; // #################### Begin ShapeImprover tests ################### ShapeImprover si_wrapper; mesh.read_vtk(shape_improv_file_name_1, err); Timer t; si_wrapper.run_instructions(&mesh, err); if (err) return 1; double si_s_secs = t.since_birth(); std::cout << std::endl << "ShapeImprover small file optimization completed in " << si_s_secs << " seconds" << std::endl; mesh.clear(); mesh.read_vtk(shape_improv_file_name_2, err); t.reset(); si_wrapper.run_instructions(&mesh, err); if (err) return 1; double si_l_secs = t.since_birth(); std::cout << std::endl << "ShapeImprover large file optimization completed in " << si_l_secs << " seconds" << std::endl; // #################### Begin LaplacianWrapper tests ################### Vector3D pnt1(0,0,5); Vector3D s_norm(0,0,1); Mesquite::PlanarDomain msq_geom(s_norm, pnt1); LaplaceWrapper lp_wrapper; mesh.clear(); mesh.read_vtk(laplacian_file_name_1, err); if (err) return 1; MeshDomainAssoc mesh_and_domain4 = MeshDomainAssoc(&mesh, &msq_geom); t.reset(); lp_wrapper.run_instructions(&mesh_and_domain4, err); if (err) return 1; double lp_s_secs = t.since_birth(); std::cout << std::endl << "LaplacianWrapper small file optimization completed in " << lp_s_secs << " seconds" << std::endl; Vector3D pnt2(0,0,0); Mesquite::PlanarDomain msq_geom2(s_norm, pnt2); mesh.clear(); mesh.read_vtk(laplacian_file_name_2, err); if (err) return 1; MeshDomainAssoc mesh_and_domain5 = MeshDomainAssoc(&mesh, &msq_geom2); t.reset(); lp_wrapper.run_instructions(&mesh_and_domain5, err); if (err) return 1; double lp_l1_secs = t.since_birth(); std::cout << std::endl << "LaplacianWrapper large file (term crit=0.001) completed in " << lp_l1_secs << " seconds" << std::endl; mesh.clear(); mesh.read_vtk(laplacian_file_name_2, err); if (err) return 1; lp_wrapper.set_vertex_movement_limit_factor(0.1); t.reset(); lp_wrapper.run_instructions(&mesh_and_domain5, err); if (err) return 1; double lp_l2_secs = t.since_birth(); std::cout << std::endl << "LaplacianWrapper large file (term crit=0.1) completed in " << lp_l2_secs << " seconds" << std::endl; // #################### Begin UntangleWrapper::BETA tests ################### mesh.clear(); mesh.read_vtk(untangle_file_name_1, err); if (err) return 1; std::vector<Mesh::VertexHandle> verts; mesh.get_all_vertices( verts, err ); if (err || verts.empty()) return 1; MsqVertex coords; mesh.vertices_get_coordinates( arrptr(verts), &coords, 1, err ); if (err) return 1; Vector3D norm(0,0,1); PlanarDomain u_domain( norm, coords ); UntangleWrapper::UntangleMetric metric = UntangleWrapper::BETA; UntangleWrapper un_wrapper (metric); un_wrapper.set_vertex_movement_limit_factor( 0.005 ); MeshDomainAssoc mesh_and_domain3 = MeshDomainAssoc(&mesh, &u_domain); t.reset(); un_wrapper.run_instructions( &mesh_and_domain3, err ); if (err) return 1; double unb_s_secs = t.since_birth(); std::cout << std::endl << "UntangleWrapper::BETA small file optimization completed in " << unb_s_secs << " seconds" << std::endl; mesh.clear(); mesh.read_vtk(untangle_file_name_2, err); if (err) return 1; // get domain verts.clear(); mesh.get_all_vertices( verts, err ); if (err || verts.empty()) return 1; MsqVertex coords2; mesh.vertices_get_coordinates( arrptr(verts), &coords2, 1, err ); if (err) return 1; PlanarDomain un_domain2( norm, coords2 ); MeshDomainAssoc mesh_and_domain6 = MeshDomainAssoc(&mesh, &un_domain2); t.reset(); un_wrapper.run_instructions( &mesh_and_domain6, err ); if (err) return 1; double unb_l1_secs = t.since_birth(); std::cout << std::endl << "UntangleWrapper::BETA large file (term crit=0.005) completed in " << unb_l1_secs << " seconds" << std::endl; mesh.clear(); mesh.read_vtk(untangle_file_name_2, err); if (err) return 1; // get domain verts.clear(); mesh.get_all_vertices( verts, err ); if (err || verts.empty()) return 1; MsqVertex coords3; mesh.vertices_get_coordinates( arrptr(verts), &coords3, 1, err ); if (err) return 1; PlanarDomain un_domain3( norm, coords3 ); un_wrapper.set_vertex_movement_limit_factor( 0.1 ); MeshDomainAssoc mesh_and_domain7 = MeshDomainAssoc(&mesh, &un_domain3); t.reset(); un_wrapper.run_instructions( &mesh_and_domain7, err ); if (err) return 1; double unb_l2_secs = t.since_birth(); std::cout << std::endl << "UntangleWrapper::BETA large file (term crit=0.1) completed in " << unb_l2_secs << " seconds" << std::endl; // #################### Begin UntangleWrapper::SIZE tests ################### mesh.clear(); mesh.read_vtk(untangle_file_name_1, err); if (err) return 1; verts.clear(); mesh.get_all_vertices( verts, err ); if (err || verts.empty()) return 1; MsqVertex coords2a; mesh.vertices_get_coordinates( arrptr(verts), &coords2a, 1, err ); if (err) return 1; PlanarDomain u_domain3( norm, coords2a ); UntangleWrapper::UntangleMetric metric2 = UntangleWrapper::SIZE; UntangleWrapper un_wrapper2s(metric2); UntangleWrapper un_wrapper2l(metric2); MeshDomainAssoc mesh_and_domain8 = MeshDomainAssoc(&mesh, &u_domain3); t.reset(); un_wrapper2s.run_instructions( &mesh_and_domain8, err ); if (err) return 1; double uns_s_secs = t.since_birth(); std::cout << std::endl << "UntangleWrapper::SIZE small file optimization completed in " << uns_s_secs << " seconds" << std::endl; mesh.clear(); mesh.read_vtk(untangle_file_name_2, err); if (err) return 1; // get domain verts.clear(); mesh.get_all_vertices( verts, err ); if (err || verts.empty()) return 1; MsqVertex coords4; mesh.vertices_get_coordinates( arrptr(verts), &coords4, 1, err ); if (err) return 1; PlanarDomain un_domain4( norm, coords4 ); un_wrapper2s.set_vertex_movement_limit_factor( 0.005 ); MeshDomainAssoc mesh_and_domain9 = MeshDomainAssoc(&mesh, &un_domain4); t.reset(); un_wrapper2s.run_instructions( &mesh_and_domain9, err ); if (err) return 1; double uns_l1_secs = t.since_birth(); std::cout << std::endl << "UntangleWrappe::SIZE large file (term crit=0.005) completed in " << uns_l1_secs << " seconds" << std::endl; mesh.clear(); mesh.read_vtk(untangle_file_name_2, err); if (err) return 1; mesh.get_all_vertices( verts, err ); if (err || verts.empty()) return 1; mesh.vertices_get_coordinates( arrptr(verts), &coords4, 1, err ); if (err) return 1; un_wrapper2l.set_vertex_movement_limit_factor( 0.1 ); t.reset(); un_wrapper2l.run_instructions( &mesh_and_domain9, err ); if (err) return 1; double uns_l2_secs = t.since_birth(); std::cout << std::endl << "UntangleWrappe::SIZE large file (term crit=0.1) completed in " << uns_l2_secs << " seconds" << std::endl; // #################### Begin UntangleWrapper::SHAPESIZE tests ################### mesh.clear(); mesh.read_vtk(untangle_file_name_1, err); if (err) return 1; verts.clear(); mesh.get_all_vertices( verts, err ); if (err || verts.empty()) return 1; MsqVertex coords5; mesh.vertices_get_coordinates( arrptr(verts), &coords5, 1, err ); if (err) return 1; PlanarDomain u_domain5( norm, coords3 ); UntangleWrapper::UntangleMetric metric3 = UntangleWrapper::SHAPESIZE; UntangleWrapper un_wrapper3(metric3); MeshDomainAssoc mesh_and_domain10 = MeshDomainAssoc(&mesh, &u_domain5); t.reset(); un_wrapper3.run_instructions( &mesh_and_domain10, err ); if (err) return 1; double unss_s_secs = t.since_birth(); std::cout << std::endl << "UntangleWrapper::SHAPESIZE small file optimization completed in " << unss_s_secs << " seconds" << std::endl; mesh.clear(); mesh.read_vtk(untangle_file_name_2, err); if (err) return 1; // get domain verts.clear(); mesh.get_all_vertices( verts, err ); if (err || verts.empty()) return 1; MsqVertex coords6; mesh.vertices_get_coordinates( arrptr(verts), &coords6, 1, err ); if (err) return 1; PlanarDomain un_domain6( norm, coords6 ); MeshDomainAssoc mesh_and_domain11 = MeshDomainAssoc(&mesh, &un_domain6); t.reset(); un_wrapper3.run_instructions( &mesh_and_domain11, err ); if (err) return 1; double unss_l_secs = t.since_birth(); std::cout << std::endl << "UntangleWrapper::SHAPESIZE large file optimization completed in " << unss_l_secs << " seconds" << std::endl; // #################### Begin SizeAdaptShapeWrapper tests ################### mesh.clear(); mesh.read_vtk(size_adapt_shape_file_name_1, err); if (err) return 1; elem_vec_t polar, equatorial; find_z10_extreme_elements( mesh, polar, equatorial, err ); if (err) return 1; double eq_min, eq_max, eq_mean, pol_min, pol_max, pol_mean; elem_areas( mesh, polar, pol_min, pol_mean, pol_max, err ); if (err) return 1; elem_areas( mesh, equatorial, eq_min, eq_mean, eq_max, err ); if (err) return 1; SphericalDomain geom( Vector3D(0,0,0), 10.0 ); SizeAdaptShapeWrapper sas_wrapper1(1e-2, 50); SizeAdaptShapeWrapper sas_wrapper2(1e-1, 50); MeshDomainAssoc mesh_and_domain12 = MeshDomainAssoc(&mesh, &geom); t.reset(); sas_wrapper1.run_instructions( &mesh_and_domain12, err); if (err) return 1; double sas1_secs = t.since_birth(); std::cout << std::endl << "SizeAdaptShapeWrapper (term crit=0.01) completed in " << sas1_secs << " seconds" << std::endl; mesh.clear(); mesh.read_vtk(size_adapt_shape_file_name_1, err); if (err) return 1; t.reset(); sas_wrapper2.run_instructions( &mesh_and_domain12, err); if (err) return 1; double sas2_secs = t.since_birth(); std::cout << std::endl << "SizeAdaptShapeWrapper (term crit=0.1) completed in " << sas2_secs << " seconds" << std::endl; // #################### Begin PaverMinEdgeLengthWrapper tests ################### PaverMinEdgeLengthWrapper mel_wrapper1(.005, 50); PaverMinEdgeLengthWrapper mel_wrapper2(.1, 50); mesh.clear(); mesh.read_vtk(min_edge_length_file_name_1, err); t.reset(); mel_wrapper1.run_instructions(&mesh, err); if (err) return 1; double mel_s_secs = t.since_birth(); std::cout << std::endl << "PaverMinEdgeLengthWrapper small file optimization completed in " << mel_s_secs << " seconds" << std::endl; mesh.clear(); mesh.read_vtk(min_edge_length_file_name_2, err); t.reset(); mel_wrapper1.run_instructions(&mesh, err); if (err) return 1; double mel1_l_secs = t.since_birth(); std::cout << std::endl << "PaverMinEdgeLengthWrapper large file (term crit=0.005) completed in " << mel1_l_secs << " seconds" << std::endl; mesh.clear(); mesh.read_vtk(min_edge_length_file_name_2, err); t.reset(); mel_wrapper2.run_instructions(&mesh, err); if (err) return 1; double mel2_l_secs = t.since_birth(); std::cout << std::endl << "PaverMinEdgeLengthWrapper large file (term crit=0.1) completed in " << mel2_l_secs << " seconds" << std::endl; // #################### Begin DeformingDomainWrapper tests ################### // load mesh mesh.clear(); mesh.read_vtk( deforming_domain_file_name_1, err ); if (MSQ_CHKERR(err)) return 1; std::vector<Mesh::VertexHandle> curves[4]; Mesh::VertexHandle corners[4]; classify_boundary( &mesh, corners, curves, err ); if (MSQ_CHKERR(err)) return 1; // new, "deformed" domain will be an 2HDx2HD planar square const double corner_coords[][3] = { {-HD,-HD, Z}, { HD,-HD, Z}, { HD, HD, Z}, {-HD, HD, Z} }; LineDomain lines[4] = { LineDomain( Vector3D(corner_coords[0]), Vector3D( 1, 0, 0) ), LineDomain( Vector3D(corner_coords[1]), Vector3D( 0, 1, 0) ), LineDomain( Vector3D(corner_coords[2]), Vector3D(-1, 0, 0) ), LineDomain( Vector3D(corner_coords[3]), Vector3D( 0,-1, 0) ) }; PlanarDomain surface( PlanarDomain::XY, Z ); // save initial mesh state DeformingCurveSmoother curve_tool; for (int i = 0; i < 4; ++i) { curve_tool.store_initial_mesh( &mesh, &curves[i][0], curves[i].size(), &lines[i], err ); if (MSQ_CHKERR(err)) return 1; } DeformingDomainWrapper dd_wrapper; dd_wrapper.store_initial_mesh( &mesh, err ); if (MSQ_CHKERR(err)) return 1; // move corner vertices to new location for (int i = 0; i < 4; ++i) { Vector3D vect(corner_coords[i]); mesh.vertex_set_coordinates( corners[i], vect, err ); if (MSQ_CHKERR(err)) return 1; } std::vector<bool> fixed(4,true); mesh.vertices_set_fixed_flag( corners, fixed, 4, err ); if (MSQ_CHKERR(err)) return 1; // smooth curves for (int i = 0; i < 4; ++i) { curve_tool.smooth_curve( &mesh, &curves[i][0], curves[i].size(), &lines[i], DeformingCurveSmoother::PROPORTIONAL, err ); if (MSQ_CHKERR(err)) return 1; fixed.resize(curves[i].size(),true); mesh.vertices_set_fixed_flag( &curves[i][0], fixed, curves[i].size(), err ); if (MSQ_CHKERR(err)) return 1; } MeshDomainAssoc mesh_and_domain1 = MeshDomainAssoc(&mesh, &surface); t.reset(); dd_wrapper.run_instructions( &mesh_and_domain1, err ); if (MSQ_CHKERR(err)) return 1; double dd_secs = t.since_birth(); std::cout << std::endl << "DeformingDomainWrapper file (term crit=0.01) completed in " << dd_secs << " seconds" << std::endl; // Do it all again for the next test mesh.clear(); mesh.read_vtk( deforming_domain_file_name_1, err ); if (MSQ_CHKERR(err)) return 1; std::vector<Mesh::VertexHandle> curves2[4]; Mesh::VertexHandle corners2[4]; classify_boundary( &mesh, corners2, curves2, err ); if (MSQ_CHKERR(err)) return 1; // new, "deformed" domain will be an 2HDx2HD planar square const double corner_coords2[][3] = { {-HD,-HD, Z}, { HD,-HD, Z}, { HD, HD, Z}, {-HD, HD, Z} }; LineDomain lines2[4] = { LineDomain( Vector3D(corner_coords2[0]), Vector3D( 1, 0, 0) ), LineDomain( Vector3D(corner_coords2[1]), Vector3D( 0, 1, 0) ), LineDomain( Vector3D(corner_coords2[2]), Vector3D(-1, 0, 0) ), LineDomain( Vector3D(corner_coords2[3]), Vector3D( 0,-1, 0) ) }; PlanarDomain surface2( PlanarDomain::XY, Z ); // save initial mesh state DeformingCurveSmoother curve_tool2; for (int i = 0; i < 4; ++i) { curve_tool2.store_initial_mesh( &mesh, &curves2[i][0], curves2[i].size(), &lines2[i], err ); if (MSQ_CHKERR(err)) return 1; } DeformingDomainWrapper dd_wrapper2; dd_wrapper2.store_initial_mesh( &mesh, err ); if (MSQ_CHKERR(err)) return 1; // move corner vertices to new location for (int i = 0; i < 4; ++i) { Vector3D vect(corner_coords2[i]); mesh.vertex_set_coordinates( corners2[i], vect, err ); if (MSQ_CHKERR(err)) return 1; } std::vector<bool> fixed2(4,true); mesh.vertices_set_fixed_flag( corners2, fixed2, 4, err ); if (MSQ_CHKERR(err)) return 1; // smooth curves for (int i = 0; i < 4; ++i) { curve_tool2.smooth_curve( &mesh, &curves2[i][0], curves2[i].size(), &lines2[i], DeformingCurveSmoother::PROPORTIONAL, err ); if (MSQ_CHKERR(err)) return 1; fixed2.resize(curves2[i].size(),true); mesh.vertices_set_fixed_flag( &curves2[i][0], fixed2, curves2[i].size(), err ); if (MSQ_CHKERR(err)) return 1; } dd_wrapper2.set_vertex_movement_limit_factor(0.1); MeshDomainAssoc mesh_and_domain2 = MeshDomainAssoc(&mesh, &surface2); t.reset(); dd_wrapper2.run_instructions( &mesh_and_domain2, err ); if (MSQ_CHKERR(err)) return 1; double dd_secs2 = t.since_birth(); std::cout << std::endl << "DeformingDomainWrapper file (term crit=0.1) completed in " << dd_secs2 << " seconds" << std::endl; // Timing Summary std::cout << std::endl << "********* Wrappers Timing Summary **********" << std::endl << "Version " << version_string(true) << std::endl << std::endl; std::cout << "ShapeImprover small file optimization completed in " << si_s_secs << " seconds" << std::endl; std::cout << "ShapeImprover large file optimization completed in " << si_l_secs << " seconds" << std::endl; std::cout << "LaplacianWrapper small file optimization completed in " << lp_s_secs << " seconds" << std::endl; std::cout << "LaplacianWrapper large file optimization (term crit=0.001) in " << lp_l1_secs << " seconds" << std::endl; std::cout << "LaplacianWrapper large file optimization (term crit=0.1) in " << lp_l2_secs << " seconds" << std::endl; std::cout << "UntangleWrapper::BETA small file optimization completed in " << unb_s_secs << " seconds" << std::endl; std::cout << "UntangleWrapper::BETA large file (term crit=0.005) completed in " << unb_l1_secs << " seconds" << std::endl; std::cout << "UntangleWrapper::BETA large file (term crit=0.1) completed in " << unb_l2_secs << " seconds" << std::endl; std::cout << "UntangleWrapper::SIZE small file optimization completed in " << uns_s_secs << " seconds" << std::endl; std::cout << "UntangleWrapper::SIZE large file (term crit=0.005) completed in " << uns_l1_secs << " seconds" << std::endl; std::cout << "UntangleWrapper::SIZE large file (term crit=0.1) completed in " << uns_l2_secs << " seconds" << std::endl; std::cout << "UntangleWrapper::SHAPESIZE small file optimization completed in " << unss_s_secs << " seconds" << std::endl; std::cout << "UntangleWrapper::SHAPESIZE large file optimization completed in " << unss_l_secs << " seconds" << std::endl; std::cout << "SizeAdaptShapeWrapper (term crit=0.01) completed in " << sas1_secs << " seconds" << std::endl; std::cout << "SizeAdaptShapeWrapper (term crit=0.1) completed in " << sas2_secs << " seconds" << std::endl; std::cout << "PaverMinEdgeLengthWrapper small file optimization completed in " << mel_s_secs << " seconds" << std::endl; std::cout << "PaverMinEdgeLengthWrapper large file (term crit=0.005) completed in " << mel1_l_secs << " seconds" << std::endl; std::cout << "PaverMinEdgeLengthWrapper large file (term crit=0.1) completed in " << mel2_l_secs << " seconds" << std::endl; std::cout << "DeformingDomainWrapper file (term crit=0.01) completed in " << dd_secs << " seconds" << std::endl; std::cout << "DeformingDomainWrapper file (term crit=0.1) completed in " << dd_secs2 << " seconds" << std::endl; return 0; }
int main( ) { Mesquite::MeshImpl mesh; MsqPrintError err(cout); mesh.read_vtk(VTK_2D_DIR "quads/tangled/tangled_quad.vtk", err); if (err) return 1; // Set Domain Constraint Vector3D pnt(0,0,5); Vector3D s_norm(0,0,1); PlanarDomain msq_geom(s_norm, pnt); // creates an intruction queue InstructionQueue queue1; // creates a mean ratio quality metric ... ConditionNumberQualityMetric shape_metric; UntangleBetaQualityMetric untangle(2); Randomize pass0(.05); // ... and builds an objective function with it //LInfTemplate* obj_func = new LInfTemplate(shape_metric); LInfTemplate obj_func(&untangle); LPtoPTemplate obj_func2(&shape_metric, 2, err); if (err) return 1; // creates the steepest descent optimization procedures ConjugateGradient pass1( &obj_func, err ); if (err) return 1; //SteepestDescent* pass2 = new SteepestDescent( obj_func2 ); ConjugateGradient pass2( &obj_func2, err ); if (err) return 1; pass2.use_element_on_vertex_patch(); if (err) return 1; pass2.use_global_patch(); if (err) return 1; QualityAssessor stop_qa=QualityAssessor(&shape_metric); QualityAssessor stop_qa2=QualityAssessor(&shape_metric); if (brief_output) { stop_qa.disable_printing_results(); stop_qa2.disable_printing_results(); } stop_qa.add_quality_assessment(&untangle); // **************Set stopping criterion************** //untangle beta should be 0 when untangled TerminationCriterion sc1; sc1.add_relative_quality_improvement( 0.000001 ); TerminationCriterion sc3; sc3.add_iteration_limit( 10 ); TerminationCriterion sc_rand; sc_rand.add_iteration_limit( 1 ); //StoppingCriterion sc1(&stop_qa,-1.0,.0000001); //StoppingCriterion sc3(&stop_qa2,.9,1.00000001); //StoppingCriterion sc2(StoppingCriterion::NUMBER_OF_PASSES,10); //StoppingCriterion sc_rand(StoppingCriterion::NUMBER_OF_PASSES,1); //either until untangled or 10 iterations pass0.set_outer_termination_criterion(&sc_rand); pass1.set_outer_termination_criterion(&sc1); pass2.set_inner_termination_criterion(&sc3); // adds 1 pass of pass1 to mesh_set1 queue1.add_quality_assessor(&stop_qa,err); if (err) return 1; //queue1.add_preconditioner(pass0,err);MSQ_CHKERR(err); //queue1.add_preconditioner(pass1,err);MSQ_CHKERR(err); //queue1.set_master_quality_improver(pass2, err); MSQ_CHKERR(err); queue1.set_master_quality_improver(&pass1, err); if (err) return 1; queue1.add_quality_assessor(&stop_qa2,err); if (err) return 1; if (write_output) mesh.write_vtk("original_mesh.vtk", err); if (err) return 1; // launches optimization on mesh_set1 MeshDomainAssoc mesh_and_domain = MeshDomainAssoc(&mesh, &msq_geom); queue1.run_instructions(&mesh_and_domain, err); if (err) return 1; if (write_output) mesh.write_vtk("smoothed_mesh.vtk", err); if (err) return 1; if (!brief_output) print_timing_diagnostics(cout); return 0; }
int main(int argc, char* argv[]) { const char* input_file = DEFAULT_INPUT; const char* output_file = NULL; switch (argc) { default: help(argv[0]); case 3: if (!strcmp(argv[2],"-h")) help(argv[0]); output_file = argv[2]; case 2: if (!strcmp(argv[1],"-h")) help(argv[0]); input_file = argv[1]; case 1: ; } /* Read a VTK Mesh file */ MsqPrintError err(cout); Mesquite::MeshImpl mesh; mesh.read_vtk( input_file, err); if (err) { std::cerr << input_file << ": file read failed" << endl; return 1; } double min_ini, avg_ini, max_ini; tet_dihedral_angle_ratios( mesh, min_ini, avg_ini, max_ini, err ); /* Run optimizer */ ViscousCFDTetShapeWrapper smoother(1e-2); smoother.run_instructions( &mesh, err); if (err) return 1; double min_fin, avg_fin, max_fin; tet_dihedral_angle_ratios( mesh, min_fin, avg_fin, max_fin, err ); cout << "\tMinimum \tAverage \tMaximum "<<endl << "Init\t"<<min_ini<<'\t'<<avg_ini<<'\t'<<max_ini<<endl << "Fini\t"<<min_fin<<'\t'<<avg_fin<<'\t'<<max_fin<<endl; if (output_file) { mesh.write_vtk( output_file, err ); if (err) { std::cerr << output_file << ": file write failed" << endl; return 1; } else { std::cout << "Wrote file: " << output_file << endl; } } if (min_ini > min_fin || avg_ini > avg_fin || max_ini > max_fin) { std::cerr << "Dihedral handle ratio decreased" << endl; return 1; } return 0; }
int main(int argc, char* argv[]) { const char* input_file = DEFAULT_INPUT; const char* output_file = NULL; switch (argc) { default: help(argv[0]); case 3: if (!strcmp(argv[2],"-h")) help(argv[0]); output_file = argv[2]; case 2: if (!strcmp(argv[1],"-h")) help(argv[0]); input_file = argv[1]; case 1: ; } /* Read a VTK Mesh file */ MsqPrintError err(cout); Mesquite::MeshImpl mesh; mesh.read_vtk( input_file, err); if (err) return 1; // creates an intruction queue InstructionQueue queue1; // creates a mean ratio quality metric ... ConditionNumberQualityMetric shape_metric; EdgeLengthQualityMetric lapl_met; lapl_met.set_averaging_method(QualityMetric::RMS); // creates the laplacian smoother procedures LaplacianSmoother lapl1; QualityAssessor stop_qa=QualityAssessor(&shape_metric); stop_qa.add_quality_assessment(&lapl_met); //**************Set stopping criterion**************** TerminationCriterion sc2; sc2.add_iteration_limit( 10 ); if (err) return 1; lapl1.set_outer_termination_criterion(&sc2); // adds 1 pass of pass1 to mesh_set1 // queue1.add_quality_assessor(&stop_qa,err); if (err) return 1; queue1.set_master_quality_improver(&lapl1, err); if (err) return 1; // queue1.add_quality_assessor(&stop_qa,err); if (err) return 1; PlanarDomain plane(Vector3D(0,0,1), Vector3D(0,0,0)); // launches optimization on mesh_set1 Timer t; queue1.run_instructions(&mesh, &plane, err); if (err) return 1; double secs = t.since_birth(); std::cout << "Optimization completed in " << secs << " seconds" << std::endl; if (output_file) { mesh.write_vtk(output_file, err); if (err) return 1; std::cout << "Wrote file: " << output_file << std::endl; } return 0; }
int main(int argc, char* argv[]) { const char* input_file = DEFAULT_INPUT; const char* output_file = NULL; switch (argc) { default: help(argv[0]); case 3: if (!strcmp(argv[2],"-h")) help(argv[0]); output_file = argv[2]; case 2: if (!strcmp(argv[1],"-h")) help(argv[0]); input_file = argv[1]; case 1: ; } /* Read a VTK Mesh file */ MsqPrintError err(cout); Mesquite::MeshImpl mesh; mesh.read_vtk( input_file, err); if (err) return 1; // creates an intruction queue InstructionQueue queue1; // creates a mean ratio quality metric ... ConditionNumberQualityMetric shape_metric; EdgeLengthQualityMetric lapl_met; lapl_met.set_averaging_method(QualityMetric::RMS); // creates the laplacian smoother procedures LaplacianSmoother lapl1; QualityAssessor stop_qa=QualityAssessor(&shape_metric); stop_qa.add_quality_assessment(&lapl_met); //**************Set stopping criterion**************** TerminationCriterion sc2; sc2.add_iteration_limit( 10 ); if (err) return 1; lapl1.set_outer_termination_criterion(&sc2); // adds 1 pass of pass1 to mesh_set1 queue1.add_quality_assessor(&stop_qa,err); if (err) return 1; queue1.set_master_quality_improver(&lapl1, err); if (err) return 1; queue1.add_quality_assessor(&stop_qa,err); if (err) return 1; // adds 1 passes of pass2 to mesh_set1 // mesh_set1.add_quality_pass(pass2); //writeVtkMesh("original_mesh", mesh, err); MSQ_CHKERR(err); PlanarDomain plane(Vector3D(0,0,1), Vector3D(0,0,5)); // launches optimization on mesh_set1 MeshDomainAssoc mesh_and_domain = MeshDomainAssoc(&mesh, &plane); Timer t; queue1.run_instructions(&mesh_and_domain, err); if (err) return 1; double secs = t.since_birth(); std::cout << "Optimization completed in " << secs << " seconds" << std::endl; if (output_file) { mesh.write_vtk(output_file, err); if (err) return 1; std::cout << "Wrote file: " << output_file << std::endl; } // check that smoother is working: // the one free vertex must be at the origin if (input_file == DEFAULT_INPUT) { std::vector<Mesh::VertexHandle> vertices; mesh.get_all_vertices( vertices, err ); if (err) return 1; std::vector<bool> fixed_flags; mesh.vertices_get_fixed_flag( arrptr(vertices), fixed_flags, vertices.size(), err ); if (err) return 1; // find one free vertex int idx = -1; for (unsigned i = 0; i < vertices.size(); ++i) { if (fixed_flags[i] == true) continue; if (idx != -1) { std::cerr << "Multiple free vertices in mesh." << std::endl; return 1; } idx = i; } if (idx == -1) { std::cerr << "No free vertex in mesh!!!!!" << std::endl; return 1; } Mesh::VertexHandle vertex = vertices[idx]; MsqVertex coords; mesh.vertices_get_coordinates( &vertex, &coords, 1, err ); if (err) return 1; // calculate distance from origin double dist = sqrt( coords[0]*coords[0] + coords[1]*coords[1] ); if (dist > 1e-8) { std::cerr << "Free vertex not at origin after Laplace smooth." << std::endl << "Expected location: (0,0)" << std::endl << "Actual location: (" << coords[0] << "," << coords[1] << ")" << std::endl; return 2; } } return 0; }
int main(int argc, char* argv[]) { Mesquite::MsqPrintError err(cout); Mesquite::MeshImpl mesh; //mesh->read_exodus("transformed_mesh.exo", err); mesh.read_vtk(MESH_FILES_DIR "2D/vtk/quads/untangled/tfi_horse10x4-12.vtk", err); if (err) return 1; // Get all vertex coordinates from mesh std::vector<Mesquite::Mesh::VertexHandle> handles; mesh.get_all_vertices( handles, err ); if (err) return 1; if (handles.empty()) { std::cerr << "No verticies in mesh" << endl; return 1; } std::vector<Mesquite::MsqVertex> coords( handles.size() ); mesh.vertices_get_coordinates( arrptr(handles), arrptr(coords), handles.size(), err ); if (err) return 1; //create the matrix for affine transformation double array_entries[9]; array_entries[0]=0; array_entries[1]=1; array_entries[2]=0; array_entries[3]=1; array_entries[4]=0; array_entries[5]=0; array_entries[6]=0; array_entries[7]=0; array_entries[8]=1; //create the translation vector Matrix3D my_mat(array_entries); Vector3D my_vec(0, 0 , 10); MeshTransform my_transform(my_mat, my_vec); //mesh->write_exodus("original_mesh.exo", err); MeshDomainAssoc mesh_and_domain = MeshDomainAssoc(&mesh, 0); my_transform.loop_over_mesh(&mesh_and_domain, 0, err); if (err) return 1; //mesh->write_exodus("transformed_mesh.exo", err); mesh.write_vtk("transformed_mesh.vtk", err); if (err) return 1; // Get transformed coordinates std::vector<Mesquite::MsqVertex> coords2( handles.size() ); mesh.vertices_get_coordinates( arrptr(handles), arrptr(coords2), handles.size(), err ); if (err) return 1; // Compare vertex coordinates size_t invalid = 0; std::vector<Mesquite::MsqVertex>::iterator iter, iter2; iter = coords.begin(); iter2 = coords2.begin(); for ( ; iter != coords.end(); ++iter, ++iter2 ) { Mesquite::Vector3D xform = my_mat * *iter + my_vec; double d = (xform - *iter2).length(); if (d > EPSILON) ++invalid; } std::cerr << invalid << " vertices not within " << EPSILON << " of expected location" << std::endl; return (invalid != 0); }
void test_plane_quad_tangled() { Mesquite::MeshImpl mesh; MsqPrintError err(cout); mesh.read_vtk(MESH_FILES_DIR "2D/VTK/tangled_quad.vtk", err); CPPUNIT_ASSERT(!err); //create geometry: plane z=5, normal (0,0,1) Vector3D pnt(0,0,5); Vector3D s_norm(0,0,1); Mesquite::PlanarDomain msq_geom(s_norm, pnt); // creates an intruction queue InstructionQueue queue1, queue2; //creates a mean ratio quality metric ... ConditionNumberQualityMetric shape; UntangleBetaQualityMetric untan(.1); // ... and builds an objective function with it (untangle) LInfTemplate untan_func(&untan); LPtoPTemplate shape_func(&shape,2,err); //Make sure no errors CPPUNIT_ASSERT(!err); // creates the cg optimization procedures ConjugateGradient pass1( &untan_func, err ); ConjugateGradient pass2( &shape_func, err ); pass1.use_element_on_vertex_patch(); pass2.use_global_patch(); //Make sure no errors CPPUNIT_ASSERT(!err); QualityAssessor stop_qa=QualityAssessor( &untan ); QualityAssessor qa=QualityAssessor( &shape ); //turn off printing if print flag not set. if(pF==0){ stop_qa.disable_printing_results(); qa.disable_printing_results(); } //**********Set stopping criterion untangle ver small ******** //StoppingCriterion sc_qa(&stop_qa,-100,MSQ_MIN); //pass1->set_stopping_criterion(&sc_qa); TerminationCriterion sc_of; sc_of.add_iteration_limit( 10 ); pass1.set_outer_termination_criterion(&sc_of); //**********Set stopping criterion 5 iterates **************** //StoppingCriterion sc5(StoppingCriterion::NUMBER_OF_PASSES,5); //pass2->set_stopping_criterion(&sc5); TerminationCriterion sc5; sc5.add_iteration_limit( 5 ); pass2.set_inner_termination_criterion(&sc5); //pass2->set_maximum_iteration(5); //TerminationCriterion sc_inner; //sc_inner.add_iteration_limit( 5 ); //pass2->set_inner_termination_criterion(&sc_inner); queue1.set_master_quality_improver(&pass1, err); CPPUNIT_ASSERT(!err); queue2.set_master_quality_improver(&pass2, err); CPPUNIT_ASSERT(!err); //********************UNTANGLE******************************* //Make sure no errors CPPUNIT_ASSERT(!err); // launches optimization on mesh_set1 double orig_qa_val=stop_qa.loop_over_mesh(&mesh, &msq_geom, 0, err); //Make sure no errors CPPUNIT_ASSERT(!err); queue1.run_instructions(&mesh, &msq_geom, err); CPPUNIT_ASSERT(!err); //Make sure no errors CPPUNIT_ASSERT(!err); double fin_qa_val=stop_qa.loop_over_mesh(&mesh, &msq_geom, 0, err); //Make sure no errors CPPUNIT_ASSERT(!err); //make sure 'quality' improved CPPUNIT_ASSERT( (fin_qa_val-orig_qa_val) <= 0.0 ); //make sure sc_qa really was satisfied CPPUNIT_ASSERT( fin_qa_val <= MSQ_MIN ); //********************SMOOTH******************************* //Make sure no errors CPPUNIT_ASSERT(!err); // launches optimization on mesh_set1 orig_qa_val=qa.loop_over_mesh(&mesh, &msq_geom, 0, err); //Make sure no errors CPPUNIT_ASSERT(!err); queue2.run_instructions(&mesh, &msq_geom, err); CPPUNIT_ASSERT(!err); //Make sure no errors CPPUNIT_ASSERT(!err); fin_qa_val=qa.loop_over_mesh(&mesh, &msq_geom, 0, err); //Make sure no errors CPPUNIT_ASSERT(!err); //make sure 'quality' improved CPPUNIT_ASSERT( (fin_qa_val-orig_qa_val) <= 0.0 ); print_timing_diagnostics(cout); }
void test_laplacian_smoothing_with_cull() { /* Read a VTK Mesh file */ MsqPrintError err(cout); Mesquite::MeshImpl mesh; mesh.read_vtk(MESH_FILES_DIR "2D/vtk/quads/untangled/square_quad_10_rand.vtk", err); CPPUNIT_ASSERT(!err); Vector3D pnt(0,0,5); Vector3D s_norm(0,0,1); Mesquite::PlanarDomain msq_geom(s_norm, pnt); // create an objective function for use in termination criteria IdealWeightInverseMeanRatio metric; LPtoPTemplate of(2, &metric); // creates an intruction queue InstructionQueue queue1; // creates a mean ratio quality metric ... ConditionNumberQualityMetric shape_metric; EdgeLengthQualityMetric lapl_met; lapl_met.set_averaging_method(QualityMetric::RMS); // creates the laplacian smoother procedures LaplacianSmoother lapl1(&of); LaplacianSmoother lapl2(&of); QualityAssessor stop_qa=QualityAssessor( &shape_metric ); stop_qa.add_quality_assessment( &lapl_met ); //**************Set termination criterion**************** TerminationCriterion sc2; sc2.add_iteration_limit( 1000 ); sc2.add_absolute_successive_improvement( 0.0 ); //set a criterion with a culling method for the inner criterion TerminationCriterion sc_cull; sc_cull.cull_on_absolute_vertex_movement( 0.1 ); CPPUNIT_ASSERT(!err); TerminationCriterion sc_cull_2; sc_cull_2.cull_on_absolute_vertex_movement( 0.000001 ); CPPUNIT_ASSERT(!err); //Make sure no errors CPPUNIT_ASSERT(!err); lapl1.set_outer_termination_criterion(&sc2); lapl2.set_outer_termination_criterion(&sc2); lapl1.set_inner_termination_criterion(&sc_cull); lapl2.set_inner_termination_criterion(&sc_cull_2); // adds 1 pass of pass1 to mesh_set1 queue1.add_quality_assessor(&stop_qa,err); //Make sure no errors CPPUNIT_ASSERT(!err); queue1.add_preconditioner(&lapl1,err); //Make sure no errors CPPUNIT_ASSERT(!err); queue1.set_master_quality_improver(&lapl2, err); //Make sure no errors CPPUNIT_ASSERT(!err); queue1.add_quality_assessor(&stop_qa,err); //Make sure no errors CPPUNIT_ASSERT(!err); MeshDomainAssoc mesh_and_domain = MeshDomainAssoc(&mesh, &msq_geom); queue1.run_instructions(&mesh_and_domain, err); CPPUNIT_ASSERT(!err); }
int main() { MsqPrintError err(cout); Mesquite::MeshImpl mesh; mesh.read_vtk(MESH_FILES_DIR "3D/VTK/tire.vtk", err); if (err) return 1; // creates an intruction queue InstructionQueue queue1; // creates a mean ratio quality metric ... IdealWeightInverseMeanRatio mean(err); if (err) return 1; LPtoPTemplate obj_func(&mean, 1, err); if (err) return 1; // creates the optimization procedures // ConjugateGradient* pass1 = new ConjugateGradient( obj_func, err ); FeasibleNewton pass1( &obj_func, true ); //perform optimization globally pass1.use_global_patch(); if (err) return 1; QualityAssessor mean_qa=QualityAssessor(&mean); //**************Set termination criterion**************** //perform 1 pass of the outer loop (this line isn't essential as it is //the default behavior). TerminationCriterion tc_outer; tc_outer.add_iteration_limit( 1 ); pass1.set_outer_termination_criterion(&tc_outer); //perform the inner loop until a certain objective function value is //reached. The exact value needs to be determined (about 18095). //As a safety, also stop if the time exceeds 10 minutes (600 seconds). TerminationCriterion tc_inner; tc_inner.add_absolute_quality_improvement( 13975 ); // tc_inner.add_absolute_quality_improvement( 13964.93818 ); tc_inner.add_cpu_time( 1800 ); pass1.set_inner_termination_criterion(&tc_inner); //used for cg to get some info // pass1->set_debugging_level(2); // adds 1 pass of pass1 to mesh_set1 queue1.add_quality_assessor(&mean_qa,err); if (err) return 1; queue1.set_master_quality_improver(&pass1, err); if (err) return 1; queue1.add_quality_assessor(&mean_qa,err); if (err) return 1; mesh.write_vtk("original_mesh.vtk", err); if (err) return 1; // launches optimization on mesh_set1 queue1.run_instructions(&mesh, err); if (err) return 1; mesh.write_vtk("smoothed_mesh.vtk", err); if (err) return 1; print_timing_diagnostics( cout ); return 0; }
int main( int argc, char* argv[] ) { /* init MPI */ int rank, nprocs; if (MPI_SUCCESS != MPI_Init(&argc, &argv)) { cerr << "MPI_Init failed." << endl; return 2; } MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); if (nprocs > 2) { cerr << "parallel_laplace_smooth test can only be run with 1 or 2 processors" << std::endl; return 0; } const int debug=0; // 1,2,3 for more debug info if (debug) { MsqDebug::enable(1); if (debug > 1) MsqDebug::enable(2); if (debug > 2) MsqDebug::enable(3); } /* create processor-specific file names */ ostringstream in_name, out_name, gold_name; in_name << VTK_3D_DIR << "par_original_hex_mesh." << nprocs << "." << rank << ".vtk"; gold_name << VTK_3D_DIR << "par_smoothed_hex_mesh." << nprocs << "." << rank << ".vtk"; out_name << "par_smoothed_hex_mesh." << nprocs << "." << rank << ".vtk"; /* load different mesh files on each processor */ Mesquite::MsqError err; Mesquite::MeshImpl mesh; mesh.read_vtk(in_name.str().c_str(), err); if (err) {cerr << err << endl; return 1;} /* create parallel mesh instance, specifying tags * containing parallel data */ Mesquite::ParallelMeshImpl parallel_mesh(&mesh, "GLOBAL_ID", "PROCESSOR_ID"); Mesquite::ParallelHelperImpl helper; helper.set_communicator(MPI_COMM_WORLD); helper.set_parallel_mesh(¶llel_mesh); parallel_mesh.set_parallel_helper(&helper); /* do Laplacian smooth */ LaplaceWrapper optimizer; optimizer.set_vertex_movement_limit_factor(1.e-10); optimizer.set_iteration_limit(2000); optimizer.enable_culling(false); optimizer.run_instructions(¶llel_mesh, err); if (err) {cerr << err << endl; return 1; } /* write mesh */ mesh.write_vtk(out_name.str().c_str(),err); if (err) {cerr << err << endl; return 1;} /* compare mesh with gold copy */ MeshImpl gold; gold.read_vtk(gold_name.str().c_str(),err); if (err) {cerr << err << endl; return 1;} bool do_print=true; double tol = 1.e-4; bool diff = MeshUtil::meshes_are_different(mesh, gold, err, tol, do_print); if (err) {cerr << err << endl; return 1;} if (diff) {cerr << "Error, computed mesh different from gold copy" << std::endl; return 1;} print_timing_diagnostics(cout); MPI_Finalize(); return 0; }
int main(int argc, char* argv[]) { Mesquite::MsqPrintError err(cout); const char* file_name = MESH_FILES_DIR "3D/vtk/hexes/untangled/large_box_hex_1000.vtk"; double OF_value = 0.; if (argc == 1) { cerr << "Warning: No file specified, using default: " << file_name << endl; } if (argc > 1) { file_name = argv[1]; } if (argc > 2) { char* end_ptr; OF_value = strtod( argv[2], &end_ptr ); if (!*argv[2] || *end_ptr) usage(); } if (argc > 3) { usage(); } Mesquite::MeshImpl mesh; mesh.read_vtk(file_name, err); if (err) return 1; // creates an intruction queue InstructionQueue queue1; // creates a mean ratio quality metric ... // SmoothnessQualityMetric* mean_ratio = new EdgeLengthQualityMetric; IdealWeightInverseMeanRatio mean_ratio(err); if (err) return 1; // mean_ratio->set_gradient_type(QualityMetric::NUMERICAL_GRADIENT); // mean_ratio->set_hessian_type(QualityMetric::NUMERICAL_HESSIAN); mean_ratio.set_averaging_method(QualityMetric::SUM); // ... and builds an objective function with it LPtoPTemplate obj_func(&mean_ratio, 1, err); if (err) return 1; // creates the steepest descentfeas newt optimization procedures // ConjugateGradient* pass1 = new ConjugateGradient( obj_func, err ); FeasibleNewton pass1( &obj_func ); pass1.use_global_patch(); if (err) return 1; QualityAssessor stop_qa=QualityAssessor(&mean_ratio); // **************Set stopping criterion**************** TerminationCriterion tc_inner; if (OF_value!=0) { tc_inner.add_absolute_quality_improvement( OF_value ); pass1.set_inner_termination_criterion(&tc_inner); } TerminationCriterion tc_outer; tc_outer.add_iteration_limit( 1 ); pass1.set_outer_termination_criterion(&tc_outer); queue1.add_quality_assessor(&stop_qa, err); if (err) return 1; // adds 1 pass of pass1 to mesh_set1 queue1.set_master_quality_improver(&pass1, err); if (err) return 1; queue1.add_quality_assessor(&stop_qa, err); if (err) return 1; //mesh.write_vtk("original_mesh",err); MSQ_CHKERR(err); // launches optimization on mesh_set1 queue1.run_instructions(&mesh, err); if (err) return 1; //mesh.write_vtk("smoothed_mesh", err); MSQ_CHKERR(err); print_timing_diagnostics( cout ); return 0; }
void test_get_geometric_dimension() { int d = mMesh->get_geometric_dimension(mErr); CPPUNIT_ASSERT_EQUAL(d,3); }