Exemplo n.º 1
0
 void test_remove_preconditioner()
 {
    MsqPrintError err(cout);
    mQueue.clear();
    mQueue.add_preconditioner(mQI, err);   // 0
    mQueue.add_quality_assessor(mQA, err); // 1
    mQueue.add_preconditioner(mQI, err);   // 2
    mQueue.set_master_quality_improver(mQI, err);
    CPPUNIT_ASSERT(!err);
    err.clear();
    mQueue.remove_preconditioner(2, err);
    CPPUNIT_ASSERT_MESSAGE("should remove QualityImprover", !err);
    err.clear();
    mQueue.remove_preconditioner(3, err);
    CPPUNIT_ASSERT_MESSAGE("should not remove master QualityImprover", err);
    err.clear();
    mQueue.remove_preconditioner(1, err);
    CPPUNIT_ASSERT_MESSAGE("should not remove QualityAssessor", err);
    err.clear();
    mQueue.remove_preconditioner(0, err);
    CPPUNIT_ASSERT_MESSAGE("should  remove QualityImprover", !err);
    err.clear();
    mQueue.remove_preconditioner(0, err);
    CPPUNIT_ASSERT_MESSAGE("should not remove QualityAssessor", err);   
    err.clear();
 }
Exemplo n.º 2
0
 void test_add_preconditioner()
 {
    MsqPrintError err(cout);
    mQueue.clear();
    mQueue.add_preconditioner(mQI, err);
    CPPUNIT_ASSERT(!err);
    err.clear();
    mQueue.set_master_quality_improver(mQI,err);
    CPPUNIT_ASSERT(!err);
    err.clear();
    mQueue.add_preconditioner(mQI, err);
    CPPUNIT_ASSERT_MESSAGE("preconditioner cannot be added after master QI"
                           , err);
    err.clear(); 
 }
Exemplo n.º 3
0
 void test_insert_quality_assessor()
 {
    MsqPrintError err(cout);
    mQueue.clear();
    mQueue.add_preconditioner(mQI, err);   // 0
    mQueue.add_quality_assessor(mQA, err); // 1
    mQueue.add_preconditioner(mQI, err);   // 2
    mQueue.set_master_quality_improver(mQI, err);
    CPPUNIT_ASSERT(!err);
    err.clear();
    mQueue.insert_quality_assessor(mQA,2, err);
    CPPUNIT_ASSERT(!err);
    err.clear();
    mQueue.insert_quality_assessor(mQA, 5, err);
    CPPUNIT_ASSERT(!err);
    err.clear();
 }
Exemplo n.º 4
0
 void test_insert_preconditioner()
 {
    MsqPrintError err(cout);
    mQueue.clear();
    mQueue.add_preconditioner(mQI, err);   // 0
    mQueue.add_quality_assessor(mQA, err); // 1
    mQueue.add_preconditioner(mQI, err);   // 2
    mQueue.set_master_quality_improver(mQI, err);
    CPPUNIT_ASSERT(!err);
    err.clear();
    mQueue.insert_preconditioner(mQI,2, err);
    CPPUNIT_ASSERT(!err);
    err.clear();
    mQueue.insert_preconditioner(mQI, 5, err);
    CPPUNIT_ASSERT_MESSAGE("should not insert after master QualityImprover", err);
    err.clear();
 }
Exemplo n.º 5
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;
}
Exemplo n.º 6
0
int main( int argc, char* argv[] )
{
  const double default_fraction = 0.05;
  const double zero = 0.0;
  int one = 1;
  CLArgs::ToggleArg allow_invalid( false );
  CLArgs::DoubleRangeArg rand_percent( default_fraction, &zero, 0 );
  CLArgs::IntRangeArg unoptimize( 0, &one, 0 );
  
  CLArgs args( "vtkrandom",
               "Randomize mesh vertex locations.",
               "Read VTK file, randomize locations of containded vertices, and re-write file." );
  args.toggle_flag( INVALID_FLAG, "Allow inverted elements in output", &allow_invalid );
  args.double_flag( PERCENT_FLAG, "fract", "Randomize fraction", &rand_percent );
  args.int_flag( UNOPTIMIZE_FLAG, "N", "Use UnOptimizer with N passes rather than Randomize", &unoptimize );
  add_domain_args( args );
  args.add_required_arg( "input_file" );
  args.add_required_arg( "output_file" );

  std::vector<std::string> files;
  if (!args.parse_options( argc, argv, files, std::cerr )) {
    args.print_usage( std::cerr );
    exit(1);
  }
  std::string input_file = files[0];
  std::string output_file = files[1];
  
  MsqError err;
  MeshImpl mesh;
  mesh.read_vtk( input_file.c_str(), err );
  if (err) {
    std::cerr << "ERROR READING FILE: " << input_file << std::endl
                    << err << std::endl;
    return 2;
  }
  MeshDomain* domain = process_domain_args( &mesh );

  TerminationCriterion tc;
  QualityAssessor qa( false );
  InstructionQueue q;
  Randomize op( rand_percent.value() );
  IdealWeightInverseMeanRatio metric;
  PMeanPTemplate of( 1, &metric );
  UnOptimizer op2( &of );
  if (unoptimize.seen()) {
    tc.add_iteration_limit( unoptimize.value() );
    op2.set_outer_termination_criterion( &tc );
    q.add_preconditioner( &op, err );
    q.set_master_quality_improver( &op2, err );
  }
  else {
    q.set_master_quality_improver( &op, err );
  }
  q.add_quality_assessor( &qa, err );
  q.run_instructions( &mesh, domain, err );
  if (err) {
    std::cerr << err << std::endl;
    return 3;
  }

  int inverted, junk;
  if (qa.get_inverted_element_count( inverted, junk, err ) && inverted ) {
    if (allow_invalid.value())
      std::cerr << "Warning: output mesh contains " << inverted << " inverted elements" << std::endl;
    else {
      std::cerr << "Error: output mesh contains " << inverted << " inverted elements" << std::endl;
      return 4;
    }
  }
  
  mesh.write_vtk( output_file.c_str(), err );
  if (err) {
    std::cerr << "ERROR WRITING FILE: " << output_file << std::endl
                    << err << std::endl;
    return 2;
  }
  
  return 0;
}