本文整理汇总了C++中TerminationCriterion::add_iteration_limit方法的典型用法代码示例。如果您正苦于以下问题:C++ TerminationCriterion::add_iteration_limit方法的具体用法?C++ TerminationCriterion::add_iteration_limit怎么用?C++ TerminationCriterion::add_iteration_limit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TerminationCriterion
的用法示例。
在下文中一共展示了TerminationCriterion::add_iteration_limit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_number_of_iterates_outer
void TerminationCriterionTest::test_number_of_iterates_outer()
{
MsqPrintError err(std::cout);
PatchData pd;
const int LIMIT = 2;
TerminationCriterion tc;
tc.add_iteration_limit(LIMIT);
tc.reset_outer( 0, 0, ofEval, 0, err );
ASSERT_NO_ERROR(err);
tc.reset_patch( pd, err );
ASSERT_NO_ERROR(err);
for (int i = 0; i < LIMIT; ++i) {
CPPUNIT_ASSERT(!tc.terminate());
CPPUNIT_ASSERT_EQUAL( i, tc.get_iteration_count() );
tc.accumulate_patch( pd, err );
ASSERT_NO_ERROR(err);
tc.accumulate_outer( 0, 0, ofEval, 0, err );
ASSERT_NO_ERROR(err);
}
CPPUNIT_ASSERT_EQUAL( 2, tc.get_iteration_count() );
CPPUNIT_ASSERT(tc.terminate());
}
示例2: run_test
void run_test( Grouping grouping, int of_power, Weight w, const string filename )
{
MsqError err;
IdentityTarget target;
TSquared target_metric;
AffineMapMetric qual_metric( &target, &target_metric );
ElementPMeanP elem_metric( of_power, &qual_metric );
QualityMetric* qm_ptr = (grouping == ELEMENT) ? (QualityMetric*)&elem_metric : (QualityMetric*)&qual_metric;
PMeanPTemplate OF( of_power, qm_ptr );
ConjugateGradient solver( &OF );
TerminationCriterion tc;
TerminationCriterion itc;
tc.add_absolute_vertex_movement( 1e-4 );
itc.add_iteration_limit( 2 );
#ifdef USE_GLOBAL_PATCH
solver.use_global_patch();
solver.set_inner_termination_criterion( &tc );
#else
solver.use_element_on_vertex_patch();
solver.set_inner_termination_criterion( &itc );
solver.set_outer_termination_criterion( &tc );
#endif
MeshImpl mesh, expected_mesh;
mesh.read_vtk( SRCDIR "/initial.vtk", err );
CHKERR(err)
// expected_mesh.read_vtk( (filename + ".vtk").c_str(), err ); CHKERR(err)
PlanarDomain plane( PlanarDomain::XY );
MeshDomainAssoc mesh_and_domain = MeshDomainAssoc(&mesh, &plane);
MetricWeight mw( &qual_metric );
InverseMetricWeight imw( &qual_metric );
WeightReader reader;
if (w == METRIC) {
TargetWriter writer( 0, &mw );
InstructionQueue tq;
tq.add_target_calculator( &writer, err );
tq.run_instructions( &mesh_and_domain, err );
CHKERR(err);
qual_metric.set_weight_calculator( &reader );
}
else if (w == INV_METRIC) {
TargetWriter writer( 0, &imw );
InstructionQueue tq;
tq.add_target_calculator( &writer, err );
tq.run_instructions( &mesh_and_domain, err );
CHKERR(err);
qual_metric.set_weight_calculator( &reader );
}
InstructionQueue q;
q.set_master_quality_improver( &solver, err );
q.run_instructions( &mesh_and_domain, err );
CHKERR(err)
/*
vector<Mesh::VertexHandle> vemain.cpprts;
vector<MsqVertex> mesh_coords, expected_coords;
mesh.get_all_vertices( verts, err ); CHKERR(err)
mesh_coords.resize(verts.size());
mesh.vertices_get_coordinates( arrptr(verts), arrptr(mesh_coords), verts.size(), err ); CHKERR(err)
expected_mesh.get_all_vertices( verts, err ); CHKERR(err)
expected_coords.resize(verts.size());
expected_mesh.vertices_get_coordinates( arrptr(verts), arrptr(expected_coords), verts.size(), err ); CHKERR(err)
if (expected_coords.size() != mesh_coords.size()) {
cerr << "Invlid expected mesh. Vertex count doesn't match" << endl;
exit(1);
}
unsigned error_count = 0;
for (size_t i = 0; i < mesh_coords.size(); ++i)
if ((expected_coords[i] - mesh_coords[i]).length_squared() > epsilon*epsilon)
++error_count;
if (!error_count)
cout << filename << " : SUCCESS" << endl;
else
cout << filename << " : FAILURE (" << error_count
<< " vertices differ by more than " << epsilon << ")" << endl;
*/
if (write_results)
mesh.write_vtk( (filename + ".results.vtk").c_str(), err );
CHKERR(err)
}
示例3: main
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;
}