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);
  }
Beispiel #2
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;
}