本文整理汇总了C++中PatchData::create_vertices_memento方法的典型用法代码示例。如果您正苦于以下问题:C++ PatchData::create_vertices_memento方法的具体用法?C++ PatchData::create_vertices_memento怎么用?C++ PatchData::create_vertices_memento使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PatchData
的用法示例。
在下文中一共展示了PatchData::create_vertices_memento方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initialize
void FeasibleNewton::initialize(PatchData &pd, MsqError &err)
{
// Cannot do anything. Variable sizes with maximum size dependent
// upon the entire MeshSet.
coordsMem = pd.create_vertices_memento(err); MSQ_CHKERR(err);
havePrintedDirectionMessage = false;
}
示例2: initialize
void QuasiNewton::initialize( PatchData& pd, MsqError& err )
{
if (!mMemento) {
mMemento = pd.create_vertices_memento( err );
MSQ_CHKERR(err);
}
}
示例3: optimize_vertex_positions
void UnOptimizer::optimize_vertex_positions( PatchData &pd, MsqError &err) {
assert( pd.num_free_vertices() == 1 && pd.vertex_by_index(0).is_free_vertex() );
std::vector<Vector3D> grad(1);
double val, junk, coeff;
bool state;
state = objectiveFunction->evaluate_with_gradient( ObjectiveFunction::CALCULATE,
pd, val, grad, err );
MSQ_ERRRTN(err);
if (!state) {
MSQ_SETERR(err)(MsqError::INVALID_MESH);
return;
}
grad[0] /= grad[0].length();
PatchDataVerticesMemento* memento = pd.create_vertices_memento( err ); MSQ_ERRRTN(err);
std::auto_ptr<PatchDataVerticesMemento> deleter( memento );
pd.get_minmax_edge_length( junk, coeff );
for (int i = 0; i < 100; ++i) {
pd.set_free_vertices_constrained( memento, &grad[0], 1, coeff, err ); MSQ_ERRRTN(err);
state = objectiveFunction->evaluate( ObjectiveFunction::CALCULATE, pd, val, true, err );
MSQ_ERRRTN(err);
if (state)
break;
coeff *= 0.5;
}
if (!state) {
pd.set_to_vertices_memento( memento, err );
}
}
示例4: reset_patch
void TerminationCriterion::reset_patch(PatchData &pd, MsqError &err)
{
const unsigned long totalFlag = terminationCriterionFlag | cullingMethodFlag;
if (totalFlag & MOVEMENT_FLAGS)
{
if (previousVerticesMemento)
pd.recreate_vertices_memento(previousVerticesMemento,err);
else
previousVerticesMemento = pd.create_vertices_memento(err);
MSQ_ERRRTN(err);
}
if (totalFlag & UNTANGLED_MESH) {
patchInvertedCount = count_inverted( pd, err );
//MSQ_DBGOUT_P0_ONLY(debugLevel) << par_string() << " o Num Patch Inverted: " << " " << patchInvertedCount << std::endl;
MSQ_ERRRTN(err);
}
}
示例5: reset_inner
//.........这里部分代码省略.........
//get the gradient norms
if (totalFlag & (GRADIENT_INF_NORM_ABSOLUTE|GRADIENT_INF_NORM_RELATIVE))
{
currentGradInfNorm = initialGradInfNorm = Linf(mGrad);
MSQ_DBGOUT_P0_ONLY(debugLevel) << par_string() << " o Initial gradient Inf norm: " << " "
<< RPM(initialGradInfNorm) << std::endl;
}
if (totalFlag & (GRADIENT_L2_NORM_ABSOLUTE|GRADIENT_L2_NORM_RELATIVE))
{
currentGradL2NormSquared = initialGradL2NormSquared = length_squared(mGrad);
MSQ_DBGOUT_P0_ONLY(debugLevel) << par_string() << " o Initial gradient L2 norm: " << " "
<< RPM(std::sqrt(initialGradL2NormSquared)) << std::endl;
}
//the OFvalue comes for free, so save it
previousOFValue=currentOFValue;
initialOFValue=currentOFValue;
}
//find the initial objective function value if needed and not already
//computed. If we needed the gradient, we have the OF value for free.
// Also, if possible, get initial OF value if writing plot file. Solvers
// often supply the OF value for subsequent iterations so by calculating
// the initial value we can generate OF value plots.
else if ((totalFlag & OF_FLAGS) ||
(plotFile.is_open() && pd.num_free_vertices() && obj_eval.have_objective_function()))
{
//ensure the obj_ptr is not null
if(!obj_eval.have_objective_function()){
MSQ_SETERR(err)("Error termination criteria set which uses objective "
"functions, but no objective function is available.",
MsqError::INVALID_STATE);
return;
}
bool b = obj_eval.evaluate(pd, currentOFValue, err); MSQ_ERRRTN(err);
if (!b){
MSQ_SETERR(err)("Initial patch is invalid for evaluation.",MsqError::INVALID_STATE);
return;
}
//std::cout<<"\nReseting initial of value = "<<initialOFValue;
previousOFValue=currentOFValue;
initialOFValue=currentOFValue;
}
if (totalFlag & (GRAD_FLAGS|OF_FLAGS))
MSQ_DBGOUT_P0_ONLY(debugLevel) << par_string() << " o Initial OF value: " << " " << RPM(initialOFValue) << std::endl;
// Store current vertex locations now, because we'll
// need them later to compare the current movement with.
if (totalFlag & VERTEX_MOVEMENT_RELATIVE)
{
if (initialVerticesMemento)
{
pd.recreate_vertices_memento( initialVerticesMemento, err );
}
else
{
initialVerticesMemento = pd.create_vertices_memento( err );
}
MSQ_ERRRTN(err);
maxSquaredInitialMovement = DBL_MAX;
}
else {
maxSquaredInitialMovement = 0;
}
if (terminationCriterionFlag & UNTANGLED_MESH) {
globalInvertedCount = count_inverted( pd, err );
//if (innerOuterType==TYPE_OUTER) MSQ_DBGOUT_P0_ONLY(debugLevel) << par_string() << " o Num Inverted: " << " " << globalInvertedCount << std::endl;
patchInvertedCount = 0;
MSQ_ERRRTN(err);
}
if (timeStepFileType) {
// If didn't already calculate gradient abive, calculate it now.
if (!(totalFlag & GRAD_FLAGS)) {
mGrad.resize( pd.num_free_vertices() );
obj_eval.evaluate(pd, currentOFValue, mGrad, err);
err.clear();
}
write_timestep( pd, mGrad.empty() ? 0 : arrptr(mGrad), err);
}
if (plotFile.is_open()) {
// two newlines so GNU plot knows that we are starting a new data set
plotFile << std::endl << std::endl;
// write column headings as comment in data file
plotFile << "#Iter\tCPU\tObjFunc\tGradL2\tGradInf\tMovement\tInverted" << std::endl;
// write initial values
plotFile << 0
<< '\t' << mTimer.since_birth()
<< '\t' << initialOFValue
<< '\t' << std::sqrt( currentGradL2NormSquared )
<< '\t' << currentGradInfNorm
<< '\t' << 0.0
<< '\t' << globalInvertedCount
<< std::endl;
}
}
示例6: optimize_vertex_positions
void SteepestDescent::optimize_vertex_positions(PatchData &pd,
MsqError &err)
{
MSQ_FUNCTION_TIMER( "SteepestDescent::optimize_vertex_positions" );
const int SEARCH_MAX = 100;
const double c1 = 1e-4;
//std::vector<Vector3D> unprojected(pd.num_free_vertices());
std::vector<Vector3D> gradient(pd.num_free_vertices());
bool feasible=true;//bool for OF values
double min_edge_len, max_edge_len;
double step_size=0, original_value=0, new_value=0;
double norm_squared=0;
PatchDataVerticesMemento* pd_previous_coords;
TerminationCriterion* term_crit=get_inner_termination_criterion();
OFEvaluator& obj_func = get_objective_function_evaluator();
// get vertex memento so we can restore vertex coordinates for bad steps.
pd_previous_coords = pd.create_vertices_memento( err ); MSQ_ERRRTN(err);
// use auto_ptr to automatically delete memento when we exit this function
std::auto_ptr<PatchDataVerticesMemento> memento_deleter( pd_previous_coords );
// Evaluate objective function.
//
// Always use 'update' version when beginning optimization so that
// if doing block coordinate descent the OF code knows the set of
// vertices we are modifying during the optimziation (the subset
// of the mesh contained in the current patch.) This has to be
// done up-front because typically an OF will just store the portion
// of the OF value (e.g. the numeric contribution to the sum for an
// averaging OF) for the initial patch.
feasible = obj_func.update( pd, original_value, gradient, err ); MSQ_ERRRTN(err);
// calculate gradient dotted with itself
norm_squared = length_squared( gradient );
//set an error if initial patch is invalid.
if(!feasible){
MSQ_SETERR(err)("SteepestDescent passed invalid initial patch.",
MsqError::INVALID_ARG);
return;
}
// use edge length as an initial guess for for step size
pd.get_minmax_edge_length( min_edge_len, max_edge_len );
//step_size = max_edge_len / std::sqrt(norm_squared);
//if (!finite(step_size)) // zero-length gradient
// return;
// if (norm_squared < DBL_EPSILON)
// return;
if (norm_squared >= DBL_EPSILON)
step_size = max_edge_len / std::sqrt(norm_squared) * pd.num_free_vertices();
// The steepest descent loop...
// We loop until the user-specified termination criteria are met.
while (!term_crit->terminate()) {
MSQ_DBGOUT(3) << "Iteration " << term_crit->get_iteration_count() << std::endl;
MSQ_DBGOUT(3) << " o original_value: " << original_value << std::endl;
MSQ_DBGOUT(3) << " o grad norm suqared: " << norm_squared << std::endl;
// Save current vertex coords so that they can be restored if
// the step was bad.
pd.recreate_vertices_memento( pd_previous_coords, err ); MSQ_ERRRTN(err);
// Reduce step size until it satisfies Armijo condition
int counter = 0;
for (;;) {
if (++counter > SEARCH_MAX || step_size < DBL_EPSILON) {
MSQ_DBGOUT(3) << " o No valid step found. Giving Up." << std::endl;
return;
}
// Move vertices to new positions.
// Note: step direction is -gradient so we pass +gradient and
// -step_size to achieve the same thing.
pd.move_free_vertices_constrained( arrptr(gradient), gradient.size(), -step_size, err ); MSQ_ERRRTN(err);
// Evaluate objective function for new vertices. We call the
// 'evaluate' form here because we aren't sure yet if we want to
// keep these vertices. Until we call 'update', we have the option
// of reverting a block coordinate decent objective function's state
// to that of the initial vertex coordinates. However, for block
// coordinate decent to work correctly, we will need to call an
// 'update' form if we decide to keep the new vertex coordinates.
feasible = obj_func.evaluate( pd, new_value, err );
if (err.error_code() == err.BARRIER_VIOLATED)
err.clear(); // barrier violated does not represent an actual error here
MSQ_ERRRTN(err);
MSQ_DBGOUT(3) << " o step_size: " << step_size << std::endl;
MSQ_DBGOUT(3) << " o new_value: " << new_value << std::endl;
if (!feasible) {
// OF value is invalid, decrease step_size a lot
step_size *= 0.2;
}
else if (new_value > original_value - c1 * step_size * norm_squared) {
// Armijo condition not met.
step_size *= 0.5;
}
else {
// Armijo condition met, stop
break;
//.........这里部分代码省略.........