本文整理汇总了C++中TerminationCriterion::accumulate_patch方法的典型用法代码示例。如果您正苦于以下问题:C++ TerminationCriterion::accumulate_patch方法的具体用法?C++ TerminationCriterion::accumulate_patch怎么用?C++ TerminationCriterion::accumulate_patch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TerminationCriterion
的用法示例。
在下文中一共展示了TerminationCriterion::accumulate_patch方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_gradient_common
void TerminationCriterionTest::test_gradient_common( bool absolute, bool L2 )
{
MsqPrintError err(std::cout);
PatchData pd;
create_twelve_hex_patch( pd, err );
ASSERT_NO_ERROR(err);
const double LIMIT = 1e-4;
TerminationCriterion tc;
if (absolute) {
if (L2)
tc.add_absolute_gradient_L2_norm( LIMIT );
else
tc.add_absolute_gradient_inf_norm( LIMIT );
}
else {
if (L2)
tc.add_relative_gradient_L2_norm( LIMIT );
else
tc.add_relative_gradient_inf_norm( LIMIT );
}
double (*func_ptr)(const Vector3D*, int) = L2 ? &lenfunc : &maxfunc;
double junk, value = 1;
objFunc.mGrad = Vector3D(value,value,value);
tc.reset_inner( pd, ofEval, err );
ASSERT_NO_ERROR(err);
tc.reset_patch( pd, err );
ASSERT_NO_ERROR(err);
std::vector<Vector3D> grad;
ofEval.evaluate( pd, junk, grad, err );
ASSERT_NO_ERROR(err);
double limit = LIMIT;
if (!absolute)
limit *= func_ptr(arrptr(grad),pd.num_free_vertices());
while (func_ptr(arrptr(grad),pd.num_free_vertices()) > limit) {
CPPUNIT_ASSERT(!tc.terminate());
value *= 0.1;
objFunc.mGrad = Vector3D(value,value,value);
ofEval.evaluate( pd, junk, grad, err );
ASSERT_NO_ERROR(err);
tc.accumulate_inner( pd, 0.0, arrptr(grad), err );
ASSERT_NO_ERROR(err);
tc.accumulate_patch( pd, err );
ASSERT_NO_ERROR(err);
}
CPPUNIT_ASSERT(tc.terminate());
}
示例2: test_cpu_time_common
//CPU TIME
void TerminationCriterionTest::test_cpu_time_common( bool inner )
{
MsqPrintError err(std::cout);
PatchData pd;
double LIMIT = 0.5;
TerminationCriterion tc;
tc.add_cpu_time(LIMIT);
if (inner)
tc.reset_inner( pd, ofEval, err );
else
tc.reset_outer( 0, 0, ofEval, 0, err );
ASSERT_NO_ERROR(err);
tc.reset_patch( pd, err );
ASSERT_NO_ERROR(err);
Timer timer;
while (timer.since_birth() < 0.5*LIMIT) {
CPPUNIT_ASSERT(!tc.terminate());
tc.accumulate_patch( pd, err );
ASSERT_NO_ERROR(err);
if (inner)
tc.accumulate_inner( pd, 0, 0, err );
else
tc.accumulate_outer( 0, 0, ofEval, 0, err );
ASSERT_NO_ERROR(err);
}
while (timer.since_birth() < 1.1*LIMIT);
tc.accumulate_patch( pd, err );
ASSERT_NO_ERROR(err);
if (inner)
tc.accumulate_inner( pd, 0, 0, err );
else
tc.accumulate_outer( 0, 0, ofEval, 0, err );
ASSERT_NO_ERROR(err);
CPPUNIT_ASSERT(tc.terminate());
}
示例3: test_quality_common
void TerminationCriterionTest::test_quality_common( bool absolute, bool successive )
{
MsqPrintError err(std::cout);
PatchData pd;
ASSERT_NO_ERROR(err);
const double LIMIT = 1e-4;
TerminationCriterion tc;
bool (*func_ptr)(double, double, double, double);
if (absolute) {
if (successive) {
tc.add_absolute_successive_improvement( LIMIT );
func_ptr = &limit_absolute_sucessive;
}
else {
tc.add_absolute_quality_improvement( LIMIT );
func_ptr = &limit_absolute_quality;
}
}
else {
if (successive) {
tc.add_relative_successive_improvement( LIMIT );
func_ptr = &limit_relative_sucessive;
}
else {
tc.add_relative_quality_improvement( LIMIT );
func_ptr = &limit_relative_quality;
}
}
const double INIT_VALUE = 10.0;
objFunc.mValue = INIT_VALUE;
tc.reset_inner( pd, ofEval, err );
ASSERT_NO_ERROR(err);
tc.reset_patch( pd, err );
ASSERT_NO_ERROR(err);
double prev = HUGE_VAL;
while (!func_ptr(INIT_VALUE,prev,objFunc.mValue,LIMIT)) {
CPPUNIT_ASSERT(!tc.terminate());
prev = objFunc.mValue;
objFunc.mValue *= 0.1;
tc.accumulate_inner( pd, objFunc.mValue, 0, err );
ASSERT_NO_ERROR(err);
tc.accumulate_patch( pd, err );
ASSERT_NO_ERROR(err);
}
CPPUNIT_ASSERT(tc.terminate());
}
示例4: test_untangled_mesh
//UNTANGLED
void TerminationCriterionTest::test_untangled_mesh()
{
MsqPrintError err(std::cout);
PatchData pd;
create_twelve_hex_patch( pd, err );
ASSERT_NO_ERROR(err);
// get two opposite vertices in first hexahedral element
int vtx1 = pd.element_by_index(0).get_vertex_index_array()[0];
int vtx2 = pd.element_by_index(0).get_vertex_index_array()[7];
Vector3D saved_coords = pd.vertex_by_index(vtx2);
Vector3D opposite_coords = pd.vertex_by_index(vtx1);
// invert the element
pd.move_vertex( 2*(opposite_coords-saved_coords), vtx2, err );
ASSERT_NO_ERROR(err);
int inverted, samples;
pd.element_by_index(0).check_element_orientation( pd, inverted, samples, err );
ASSERT_NO_ERROR(err);
CPPUNIT_ASSERT(inverted > 0);
// check initial termination criterion
TerminationCriterion tc;
tc.add_untangled_mesh();
tc.reset_inner( pd, ofEval, err );
ASSERT_NO_ERROR(err);
tc.reset_patch( pd, err );
ASSERT_NO_ERROR(err);
CPPUNIT_ASSERT(!tc.terminate());
// fix the element
pd.set_vertex_coordinates( saved_coords, vtx2, err );
ASSERT_NO_ERROR(err);
pd.element_by_index(0).check_element_orientation( pd, inverted, samples, err );
ASSERT_NO_ERROR(err);
CPPUNIT_ASSERT_EQUAL(0,inverted);
// check that TC recognized untangled mesh
tc.accumulate_inner( pd, 0.0, 0, err );
ASSERT_NO_ERROR(err);
tc.accumulate_patch( pd, err );
ASSERT_NO_ERROR(err);
CPPUNIT_ASSERT(tc.terminate());
}
示例5: 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());
}
示例6: test_absolute_vertex_movement_edge_length
void TerminationCriterionTest::test_absolute_vertex_movement_edge_length()
{
MsqPrintError err(std::cout);
// define two-tet mesh where tets share a face
double coords[] = { 0, -5, 0,
0, 5, 0,
1, 0, 0,
0, 0, 0,
0, 0, 1 };
const unsigned long conn[] = { 4, 3, 2, 0,
2, 3, 4, 1 };
int fixed[5] = {0};
ArrayMesh mesh( 3, 5, coords, fixed, 2, TETRAHEDRON, conn );
// calculate beta
const double LIMIT = 1e-4; // desired absolute limit
MeshUtil tool(&mesh);
SimpleStats len;
tool.edge_length_distribution( len, err );
ASSERT_NO_ERROR(err);
const double beta = LIMIT / (len.average() - len.standard_deviation());
// initialize termination criterion
TerminationCriterion tc;
tc.add_absolute_vertex_movement_edge_length( beta );
MeshDomainAssoc mesh_and_domain2 = MeshDomainAssoc(&mesh, 0);
tc.initialize_queue( &mesh_and_domain2, 0, err ); ASSERT_NO_ERROR(err);
// get a patch data
PatchData pd;
pd.set_mesh( &mesh );
pd.fill_global_patch( err ); ASSERT_NO_ERROR(err);
// test termination criteiorn
tc.reset_inner( pd, ofEval, err );
ASSERT_NO_ERROR(err);
tc.reset_patch( pd, err );
ASSERT_NO_ERROR(err);
CPPUNIT_ASSERT(!tc.terminate());
const double FIRST_STEP=10.0;
// move a vertex by 10 units and check that it did not meet criterion
pd.move_vertex( Vector3D(FIRST_STEP,0,0), 0, err );
ASSERT_NO_ERROR(err);
tc.accumulate_inner( pd, 0.0, 0, err );
ASSERT_NO_ERROR(err);
tc.accumulate_patch( pd, err );
ASSERT_NO_ERROR(err);
CPPUNIT_ASSERT(!tc.terminate());
double test_limit = LIMIT;
int idx = 0;
for (double step = FIRST_STEP; step > test_limit; step *= 0.09) {
idx = (idx + 1) % pd.num_free_vertices();
pd.move_vertex( Vector3D(step,0,0), idx, err );
ASSERT_NO_ERROR(err);
tc.accumulate_inner( pd, 0.0, 0, err );
ASSERT_NO_ERROR(err);
tc.accumulate_patch( pd, err );
ASSERT_NO_ERROR(err);
CPPUNIT_ASSERT(!tc.terminate());
}
idx = (idx + 1) % pd.num_free_vertices();
pd.move_vertex( Vector3D(0.5*test_limit,0,0), idx, err );
ASSERT_NO_ERROR(err);
tc.accumulate_inner( pd, 0.0, 0, err );
ASSERT_NO_ERROR(err);
tc.accumulate_patch( pd, err );
ASSERT_NO_ERROR(err);
CPPUNIT_ASSERT(tc.terminate());
}