Exemple #1
0
void PaverMinEdgeLengthWrapper::run_wrapper( Mesh* mesh,
                                             ParallelMesh* pmesh,
                                             MeshDomain* domain,
                                             Settings* settings,
                                             QualityAssessor* qa,
                                             MsqError& err )
{
  InstructionQueue q;
 
    // calculate average lambda for mesh
  ReferenceMesh ref_mesh( mesh );
  RefMeshTargetCalculator W_0( &ref_mesh );
  SimpleStats lambda_stats;
  MeshUtil tool(mesh, settings);
  tool.lambda_distribution( lambda_stats, err ); MSQ_ERRRTN(err);
  double lambda = lambda_stats.average();
  
    // create objective function
  IdealShapeTarget W_i;
  LambdaConstant W( lambda, &W_i );
  TShapeSizeB1 tm;
  TQualityMetric mu_0( &W, &tm );
  ElementPMeanP mu( 1.0, &mu_0 );
  PMeanPTemplate of( 1.0, &mu );
  
    // create quality assessor
  EdgeLengthMetric len(0.0);
  qa->add_quality_assessment( &mu );
  qa->add_quality_assessment( &len );
  q.add_quality_assessor( qa, err );
  
    // create solver
  TrustRegion solver( &of );
  TerminationCriterion tc, ptc;
  tc.add_absolute_vertex_movement( maxVtxMovement );
  tc.add_iteration_limit( iterationLimit );
  ptc.add_iteration_limit( pmesh ? parallelIterations : 1 );
  solver.set_inner_termination_criterion( &tc );
  solver.set_outer_termination_criterion( &ptc );
  q.set_master_quality_improver( &solver, err ); MSQ_ERRRTN(err);
  q.add_quality_assessor( qa, err );

  // Optimize mesh
  q.run_common( mesh, pmesh, domain, settings, err ); MSQ_CHKERR(err);  
}
void SizeAdaptShapeWrapper::run_wrapper( Mesh* mesh, 
                                         ParallelMesh* pmesh,
                                         MeshDomain* domain, 
                                         Settings* settings,
                                         QualityAssessor* qa,
                                         MsqError& err )
{
  InstructionQueue q;
 
    // calculate average lambda for mesh
  TagVertexMesh init_mesh( err, mesh );  MSQ_ERRRTN(err);
  ReferenceMesh ref_mesh( &init_mesh );
  RefMeshTargetCalculator W_0( &ref_mesh );
  q.add_tag_vertex_mesh( &init_mesh, err );  MSQ_ERRRTN(err);
  
    // create objective function
  IdealShapeTarget W_i;
  LambdaTarget W( &W_0, &W_i );
  Target2DShapeSizeBarrier tm2;
  Target3DShapeSizeBarrier tm3;
  TMPQualityMetric mu( &W, &tm2, &tm3 );
  PMeanPTemplate of( 1.0, &mu );
  
    // create quality assessor
  EdgeLengthMetric len(0.0);
  qa->add_quality_assessment( &mu );
  qa->add_quality_assessment( &len );
  q.add_quality_assessor( qa, err );
  
    // create solver
  TrustRegion solver( &of );
  TerminationCriterion tc, ptc;
  tc.add_absolute_vertex_movement( maxVtxMovement );
  tc.add_iteration_limit( iterationLimit );
  ptc.add_iteration_limit( pmesh ? parallelIterations : 1 );
  solver.set_inner_termination_criterion( &tc );
  solver.set_outer_termination_criterion( &ptc );
  q.set_master_quality_improver( &solver, err ); MSQ_ERRRTN(err);
  q.add_quality_assessor( qa, err );

  // Optimize mesh
  q.run_common( mesh, pmesh, domain, settings, err ); MSQ_CHKERR(err);  
}
Exemple #3
0
int ParShapeImprover::count_invalid_elements(Mesh &mesh, MeshDomain *domain)
{
  MsqError err;
  InstructionQueue q;
  
  IdealWeightInverseMeanRatio metric;
  metric.set_averaging_method( QualityMetric::LINEAR );

  // Check for inverted elements in the mesh
  QualityAssessor inv_check( &metric );
  //inv_check.disable_printing_results();
  q.add_quality_assessor( &inv_check, err );  MSQ_ERRZERO(err);
  Settings settings;
  // bug?  should we pass in pmesh?
  q.run_common( &mesh, 0, domain, &settings, err ); MSQ_ERRZERO(err);
  const QualityAssessor::Assessor* inv_b = inv_check.get_results( &metric );
  int num_invalid = inv_b->get_invalid_element_count();
  return num_invalid;
}
void UntangleWrapper::run_wrapper( MeshDomainAssoc* mesh_and_domain,
                                   ParallelMesh* pmesh,
                                   Settings* settings,
                                   QualityAssessor* qa,
                                   MsqError& err )
{
  Instruction::initialize_vertex_byte( mesh_and_domain, settings, err ); MSQ_ERRRTN(err);

  Mesh* mesh = mesh_and_domain->get_mesh();

    // get some global mesh properties
  SimpleStats edge_len, lambda;
  std::auto_ptr<MeshUtil> tool(new MeshUtil( mesh, settings ));
  tool->edge_length_distribution( edge_len, err ); MSQ_ERRRTN(err);
  tool->lambda_distribution( lambda, err ); MSQ_ERRRTN(err);
  tool.reset(0);
  
    // get target metrics from user perferences
  TSizeNB1 mu_size;
  TShapeSize2DNB1 mu_shape_2d;
  TShapeSize3DNB1 mu_shape_3d;
  TMixed mu_shape( &mu_shape_2d, &mu_shape_3d );
  std::auto_ptr<TMetric> mu;
  if (qualityMetric == BETA) {
    double beta = metricConstant;
    if (beta < 0) 
      beta = (lambda.average()*lambda.average())/20;
    //std::cout << "beta= " << beta << std::endl;
    mu.reset(new TUntangleBeta( beta ));
  }
  else {
    TMetric* sub = 0;
    if (qualityMetric == SIZE)
      sub = &mu_size;
    else 
      sub = &mu_shape;
    if (metricConstant >= 0) 
      mu.reset(new TUntangleMu( sub, metricConstant ));
    else 
      mu.reset(new TUntangleMu( sub ));
  }
    
    // define objective function
  IdealShapeTarget base_target;
  LambdaConstant target( lambda.average(), &base_target );
  TQualityMetric metric_0(&target, mu.get());
  ElementPMeanP metric( 1.0, &metric_0 );
  PMeanPTemplate objfunc( 1.0, &metric );
  
    // define termination criterion
  double eps = movementFactor * (edge_len.average() - edge_len.standard_deviation());
  TerminationCriterion inner("<type:untangle_inner>", TerminationCriterion::TYPE_INNER), 
    outer("<type:untangle_outer>", TerminationCriterion::TYPE_OUTER);
  outer.add_untangled_mesh();
  if (doCulling) 
    inner.cull_on_absolute_vertex_movement( eps );
  else
    outer.add_absolute_vertex_movement( eps );
  if (maxTime > 0.0) 
    outer.add_cpu_time( maxTime );
  inner.add_iteration_limit( NUM_INNER_ITERATIONS );
  if (maxIterations > 0)
    outer.add_iteration_limit(maxIterations);
  
    // construct solver
  SteepestDescent solver( &objfunc );
  solver.use_element_on_vertex_patch();
  solver.set_inner_termination_criterion( &inner );
  solver.set_outer_termination_criterion( &outer );
  if (doJacobi)
    solver.do_jacobi_optimization();
  else
    solver.do_gauss_optimization();
  
    // Run 
  qa->add_quality_assessment( &metric );
  InstructionQueue q;
  q.add_quality_assessor( qa, err ); MSQ_ERRRTN(err);
  q.set_master_quality_improver( &solver, err ); MSQ_ERRRTN(err);
  q.add_quality_assessor( qa, err ); MSQ_ERRRTN(err);
  q.run_common( mesh_and_domain, pmesh, settings, err ); MSQ_ERRRTN(err);
}
    void PMMShapeSizeOrientImprover::run_wrapper( Mesh* mesh,
                                                  ParallelMesh* pmesh,
                                                  MeshDomain* domain,
                                                  Settings* settings,
                                                  QualityAssessor* qa,
                                                  MsqError& err )
    {
      InstructionQueue q;
  
      // Set up barrier metric to see if mesh contains inverted elements
      TShapeB1 mu_b;
      IdealShapeTarget w_ideal;
      TQualityMetric barrier( &w_ideal, &mu_b );
  
      // Check for inverted elements in the mesh
      QualityAssessor inv_check( &barrier );
      //inv_check.disable_printing_results();
      q.add_quality_assessor( &inv_check, err );  MSQ_ERRRTN(err);
      q.run_common( mesh, pmesh, domain, settings, err ); MSQ_ERRRTN(err);
      q.remove_quality_assessor( 0, err ); MSQ_ERRRTN(err);
      const QualityAssessor::Assessor* inv_b = inv_check.get_results( &barrier );
      //const bool use_barrier = (0 == inv_b->get_invalid_element_count());
      std::cout << "tmp srk PMMShapeSizeOrientImprover::run_wrapper get_invalid_element_count= " 
                << inv_b->get_invalid_element_count() << std::endl;
  
      // Create remaining metric instances
      TShapeNB1 mu;
      TShapeSizeOrientNB1 mu_o;
      TShapeSizeOrientB1 mu_ob;
  
      // Select which target metrics to use
      //TMetric *mu_p, *mu_op;
      //if (use_barrier) {
      //  mu_p = &mu_b;
      //  mu_op = &mu_ob;
      //}
      //else {
      //  mu_p = &mu;
      //  mu_op = &mu_o;
      //}
  
      // Set up target and weight calculators
      std::string altCoordName = "msq_jacobi_temp_coords"; // FIXME
      bool should_clean_up_tag_data = true; // default
      TagVertexMesh init_mesh( err, pmesh ? (Mesh*)pmesh : mesh, should_clean_up_tag_data, altCoordName );  MSQ_ERRRTN(err);
      ReferenceMesh ref_mesh( &init_mesh );
      RefMeshTargetCalculator w_init( &ref_mesh );

      //TetDihedralWeight c_dihedral( &ref_mesh, dCutoff, aVal );
      //RemainingWeight c_remaining( &c_dihedral );
  
      // Create objective function
      //       TQualityMetric metric1( &w_ideal, &c_dihedral,  mu_p  );
      //       TQualityMetric metric2( &w_init,  &c_remaining, mu_op );
      //       AddQualityMetric of_metric( &metric1, &metric2, err );  MSQ_ERRRTN(err);
      TQualityMetric of_metric( &w_init, &mu_o );
      PMeanPTemplate obj_func( 1.0, &of_metric );
  
      // Create optimizer
      //TrustRegion solver( &obj_func );
      FeasibleNewton solver( &obj_func );
      TerminationCriterion term, ptc;
      term.add_iteration_limit( iterationLimit );
      term.add_absolute_vertex_movement( maxVtxMovement );
      ptc.add_iteration_limit( pmesh ? parallelIterations : 1 );
      solver.set_inner_termination_criterion( &term );
      solver.set_outer_termination_criterion( &ptc );
  
      // Create instruction queue
      //qa->add_quality_assessment( &metric1 );
      //qa->add_quality_assessment( &metric2 );
      qa->add_quality_assessment( &of_metric );
      q.add_quality_assessor( qa, err ); MSQ_ERRRTN(err);
      q.set_master_quality_improver( &solver, err ); MSQ_ERRRTN(err);
      q.add_quality_assessor( qa, err ); MSQ_ERRRTN(err);

      // Optimize mesh
      q.run_common( mesh, pmesh, domain, settings, err ); MSQ_CHKERR(err);  
    }