38 #include "ConjugateGradient.hpp"
40 #include "MsqDebug.hpp"
41 #include "MsqTimer.hpp"
42 #include "MsqFreeVertexIndexIterator.hpp"
61 if(default_crit==NULL){
62 MSQ_SETERR(err)(
"QualityImprover did not create a default inner "
85 MSQ_DBGOUT(2) <<
"\no Performing Conjugate Gradient optimization.\n";
91 pMemento=pd.create_vertices_memento(err);
100 int patch_param1,
int patch_param2)
105 MSQ_SETERR(err)(
"Type not supported by ConjugateGradient algorythm.",
124 int num_vert=pd.num_vertices();
125 if(pd.num_free_vertices(err)<1){
126 MSQ_DBGOUT(1) <<
"\nEmpty free vertex list in ConjugateGradient\n";
150 MsqVertex* vertices=pd.get_vertex_array(err);
MSQ_ERRRTN(err);
154 MsqFreeVertexIndexIterator free_iter(&pd, err);
MSQ_ERRRTN(err);
165 MSQ_SETERR(err)(
"Conjugate Gradient not able to get valid gradient "
166 "and function values on intial patch.",
175 MSQ_PRINT(2)(
"\nCG's FIRST VALUE = %f,grad_norm = %f",f,grad_norm);
176 MSQ_PRINT(2)(
"\n TIME %f",c_timer.since_birth());
196 while(!term_crit->terminate()){
203 MSQ_PRINT(2)(
"\n Alp initial, alp = %20.18f",alp);
209 while (free_iter.next()) {
216 MSQ_PRINT(2)(
"\n CG's search direction reset.");
218 MSQ_PRINT(2)(
"\n Alp was zero, alp = %20.18f",alp);
224 while (free_iter.next()) {
226 vertices[m] += (alp *
pGrad[m]);
228 pd.snap_vertex_to_domain(m,err);
231 MSQ_SETERR(err)(
"Error inside Conjugate Gradient, vertices moved "
232 "making function value invalid.",
239 MSQ_PRINT(2)(
"\nCG's VALUE = %f, iter. = %i, grad_norm = %f, alp = %f",f,
i,grad_norm,alp);
240 MSQ_PRINT(2)(
"\n TIME %f",c_timer.since_birth());
246 while (free_iter.next()) {
260 double bet = (s22-s12)/s11;
262 while (free_iter.next()) {
268 MSQ_PRINT(2)(
" \nSEARCH DIRECTION INFINITY NORM = %e",
278 term_crit->accumulate_patch( pd, err );
MSQ_ERRRTN(err);
281 MSQ_PRINT(2)(
"\nConjugate Gradient complete i=%i ",
i);
282 MSQ_PRINT(2)(
"\n- FINAL value = %f, alp=%4.2e grad_norm=%4.2e",f,alp,grad_norm);
283 MSQ_PRINT(2)(
"\n FINAL TIME %f",c_timer.since_birth());
317 size_t num_vertices=pd.num_vertices();
331 pd.recreate_vertices_memento(
pMemento, err);
334 while (j<jmax && !feasible && alp>
MSQ_MIN) {
336 pd.set_free_vertices_constrained(
pMemento,
pGrad,num_vertices,alp,err);
346 MSQ_PRINT(2)(
"\nFeasible Point Not Found");
353 while (j<jmax && found == 0){
356 pd.set_free_vertices_constrained(
pMemento,
pGrad,num_vertices,alp,err);
389 MSQ_SETERR(err)(
"Non-convex feasiblility region found while "
409 while (j<jmax && found == 0) {
void set_debugging_level(int new_lev)
Just for debugging purposes or for obtaining more data during the optimization process.
#define MSQ_ERRZERO(err)
Return zero/NULL on error.
virtual void set_patch_type(PatchData::PatchType patch_type, MsqError &err, int param1=0, int param2=0)
Sets the Patch Type.
virtual void terminate_mesh_iteration(PatchData &pd, MsqError &err)
virtual void optimize_vertex_positions(PatchData &pd, MsqError &err)
bool evaluate(PatchData &patch, double &fval, MsqError &err)
void set_name(msq_std::string name)
provides a name to the QualityImprover (use it in constructor).
double get_step(PatchData &pd, double f0, int &j, MsqError &err)
Returns the step distance to take in the search direction.
invalid function argument passed
NVec< 3, double > Vector3D
#define MSQ_CHKERR(err)
Mesquite's Error Checking macro.
virtual ~ConjugateGradient()
PatchDataVerticesMemento * pMemento
bool compute_gradient(PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size=0)
Calls either compute_numerical_gradient or compute_analytical_gradient depending on the value of grad...
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
ObjectiveFunction * objFunc
virtual void set_patch_type(PatchData::PatchType type, MsqError &err, int patch_param1=0, int patch_param2=0)
Set the patch type.
virtual void cleanup()
Delete arrays initially created in initialize().
PatchType
Tells MeshSet how to retrieve the mesh entities that will be stored in PatchData. ...
Vector3D * fGrad
Culls the vertex list free_vertex_list.
double Linf(Vector3D *const v, int n)
TerminationCriterion * get_inner_termination_criterion()
return the inner termination criterion pointer
virtual void initialize_mesh_iteration(PatchData &pd, MsqError &err)
Terminates when the number of iterations exceeds a given integer.
virtual void initialize(PatchData &pd, MsqError &err)
Initialize data for smoothing process.
#define MSQ_PRINT(flag)
Check debug flag and print printf-style formatted output.
object is in an invalid state
#define MSQ_FUNCTION_TIMER(NAME)
void set(const double x, const double y, const double z)
#define MSQ_DBGOUT(flag)
Check debug flag and return ostream associated with flag.
#define MSQ_ERRRTN(err)
If passed error is true, return from a void function.
ConjugateGradient(ObjectiveFunction *objective, MsqError &err)