Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ConjugateGradient Class Reference

Optimizes the objective function using the Polack-Ribiere scheme. More...

#include <ConjugateGradient.hpp>

Inheritance diagram for ConjugateGradient:
Collaboration diagram for ConjugateGradient:

Public Member Functions

 ConjugateGradient (ObjectiveFunction *objective, MsqError &err)
 
virtual ~ConjugateGradient ()
 
virtual void set_patch_type (PatchData::PatchType type, MsqError &err, int patch_param1=0, int patch_param2=0)
 Set the patch type. More...
 
void set_debugging_level (int new_lev)
 Just for debugging purposes or for obtaining more data during the optimization process. More...
 
 ConjugateGradient (ObjectiveFunction *objective, MsqError &err)
 
virtual ~ConjugateGradient ()
 
virtual void set_patch_type (PatchData::PatchType type, MsqError &err, int patch_param1=0, int patch_param2=0)
 Set the patch type. More...
 
void set_debugging_level (int new_lev)
 Just for debugging purposes or for obtaining more data during the optimization process. More...
 
- Public Member Functions inherited from VertexMover
virtual ~VertexMover ()
 
virtual double loop_over_mesh (MeshSet &ms, MsqError &err)
 Improves the quality of the MeshSet, calling some methods specified in a class derived from VertexMover. More...
 
virtual ~VertexMover ()
 
virtual double loop_over_mesh (MeshSet &ms, MsqError &err)
 This is the "run" function of PatchDataUser. It can do anything really. More...
 
- Public Member Functions inherited from QualityImprover
virtual ~QualityImprover ()
 
void set_name (msq_std::string name)
 provides a name to the QualityImprover (use it in constructor). More...
 
virtual msq_std::string get_name ()
 retrieves the QualityImprover name. A default name should be set in the constructor. More...
 
virtual AlgorithmType get_algorithm_type ()
 Return the algorithm type (to avoid RTTI use). More...
 
void set_inner_termination_criterion (TerminationCriterion *crit)
 Sets in the termination criterion for the concrete solver's optimization. More...
 
void set_outer_termination_criterion (TerminationCriterion *crit)
 Sets in the termination criterion for the outer loop over patches. More...
 
virtual ~QualityImprover ()
 
void set_name (msq_std::string name)
 provides a name to the QualityImprover (use it in constructor). More...
 
virtual msq_std::string get_name ()
 retrieves the QualityImprover name. A default name should be set in the constructor. More...
 
virtual AlgorithmType get_algorithm_type ()
 Return the algorithm type (to avoid RTTI use). More...
 
void set_inner_termination_criterion (TerminationCriterion *crit)
 Sets in the termination criterion for the concrete solver's optimization. More...
 
void set_outer_termination_criterion (TerminationCriterion *crit)
 Sets in the termination criterion for the outer loop over patches. More...
 
- Public Member Functions inherited from PatchDataUser
virtual ~PatchDataUser ()
 
PatchData::PatchType get_patch_type ()
 Returns the Patch Type. More...
 
int get_nb_layers (MsqError &err)
 Returns number of layers (if relevant for partition algorythm). More...
 
void add_culling_method (enum PatchData::culling_method cm)
 Sets on the culling method passed as argument. More...
 
void no_culling_method ()
 Sets off all culling methods. More...
 
void remove_culling_method (enum PatchData::culling_method cm)
 Sets off the culling method passed as argument. More...
 
long unsigned int get_culling_method_bits ()
 Returns the bitset containing culling methods flags. More...
 
void set_all_parameters (PatchDataParameters &params)
 
PatchDataParametersget_all_parameters ()
 Returns the PatchDataParameters object. More...
 
void set_global_patch (PatchData *pd, MsqError &err)
 Sets the Global Patch, so that it can be use by contiguoug PatchDataUser. More...
 
PatchDataget_global_patch ()
 Returns the Global Patch. More...
 
void no_global_patch ()
 Sets the Global Patch pointer to NULL. More...
 
virtual ~PatchDataUser ()
 
PatchData::PatchType get_patch_type ()
 Returns the Patch Type. More...
 
int get_nb_layers (MsqError &err)
 Returns number of layers (if relevant for partition algorythm). More...
 
void add_culling_method (enum PatchData::culling_method cm)
 Sets on the culling method passed as argument. More...
 
void no_culling_method ()
 Sets off all culling methods. More...
 
void remove_culling_method (enum PatchData::culling_method cm)
 Sets off the culling method passed as argument. More...
 
long unsigned int get_culling_method_bits ()
 Returns the bitset containing culling methods flags. More...
 
void set_all_parameters (PatchDataParameters &params)
 
PatchDataParametersget_all_parameters ()
 Returns the PatchDataParameters object. More...
 
void set_global_patch (PatchData *pd, MsqError &err)
 Sets the Global Patch, so that it can be use by contiguoug PatchDataUser. More...
 
PatchDataget_global_patch ()
 Returns the Global Patch. More...
 
void no_global_patch ()
 Sets the Global Patch pointer to NULL. More...
 

Protected Member Functions

virtual void initialize (PatchData &pd, MsqError &err)
 Initialize data for smoothing process. More...
 
virtual void optimize_vertex_positions (PatchData &pd, MsqError &err)
 
virtual void initialize_mesh_iteration (PatchData &pd, MsqError &err)
 
virtual void terminate_mesh_iteration (PatchData &pd, MsqError &err)
 
virtual void cleanup ()
 Delete arrays initially created in initialize(). More...
 
double get_step (PatchData &pd, double f0, int &j, MsqError &err)
 Returns the step distance to take in the search direction. More...
 
virtual void initialize (PatchData &pd, MsqError &err)
 Initialize data for smoothing process. More...
 
virtual void optimize_vertex_positions (PatchData &pd, MsqError &err)
 
virtual void initialize_mesh_iteration (PatchData &pd, MsqError &err)
 
virtual void terminate_mesh_iteration (PatchData &pd, MsqError &err)
 
virtual void cleanup ()
 Delete arrays initially created in initialize(). More...
 
double get_step (PatchData &pd, double f0, int &j, MsqError &err)
 Returns the step distance to take in the search direction. More...
 
- Protected Member Functions inherited from VertexMover
 VertexMover ()
 
size_t check_feasible (PatchData &pd, MsqError &err)
 CHECK FEASIBLE IS NOT YET IMPLEMENTED. More...
 
 VertexMover ()
 
size_t check_feasible (PatchData &pd, MsqError &err)
 CHECK FEASIBLE IS NOT YET IMPLEMENTED. More...
 
- Protected Member Functions inherited from QualityImprover
 QualityImprover ()
 
const MeshSetget_mesh_set () const
 
MeshSetget_mesh_set ()
 
void set_mesh_set (MeshSet *ms)
 
TerminationCriterionget_outer_termination_criterion ()
 return the outer termination criterion pointer More...
 
TerminationCriterionget_inner_termination_criterion ()
 return the inner termination criterion pointer More...
 
 QualityImprover ()
 
const MeshSetget_mesh_set () const
 
MeshSetget_mesh_set ()
 
void set_mesh_set (MeshSet *ms)
 
TerminationCriterionget_outer_termination_criterion ()
 return the outer termination criterion pointer More...
 
TerminationCriterionget_inner_termination_criterion ()
 return the inner termination criterion pointer More...
 
- Protected Member Functions inherited from PatchDataUser
 PatchDataUser ()
 
 PatchDataUser ()
 

Private Attributes

Vector3DfGrad
 Culls the vertex list free_vertex_list. More...
 
Vector3DpGrad
 
PatchDataVerticesMementopMemento
 
Vector3DfNewGrad
 
int arraySize
 
int conjGradDebug
 

Additional Inherited Members

- Public Types inherited from PatchDataUser
enum  AlgorithmType {
  QUALITY_IMPROVER, QUALITY_ASSESSOR, MESH_TRANSFORM, TARGET_CALCULATOR,
  QUALITY_IMPROVER, QUALITY_ASSESSOR, MESH_TRANSFORM, TARGET_CALCULATOR
}
 
enum  AlgorithmType {
  QUALITY_IMPROVER, QUALITY_ASSESSOR, MESH_TRANSFORM, TARGET_CALCULATOR,
  QUALITY_IMPROVER, QUALITY_ASSESSOR, MESH_TRANSFORM, TARGET_CALCULATOR
}
 
- Protected Attributes inherited from VertexMover
ObjectiveFunctionobjFunc
 

Detailed Description

Optimizes the objective function using the Polack-Ribiere scheme.

Definition at line 53 of file includeLinks/ConjugateGradient.hpp.

Constructor & Destructor Documentation

ConjugateGradient ( ObjectiveFunction objective,
MsqError err 
)

Definition at line 46 of file QualityImprover/VertexMover/ConjugateGradient/ConjugateGradient.cpp.

References TerminationCriterion::add_criterion_type_with_int(), PatchData::ELEMENTS_ON_VERTEX_PATCH, QualityImprover::get_inner_termination_criterion(), MsqError::INVALID_STATE, MSQ_ERRRTN, MSQ_SETERR, TerminationCriterion::NUMBER_OF_ITERATES, VertexMover::objFunc, ConjugateGradient::set_debugging_level(), QualityImprover::set_name(), and ConjugateGradient::set_patch_type().

47  :
48  VertexMover(),
49  fGrad(NULL),
50  pGrad(NULL),
51  pMemento(NULL),
52  fNewGrad(NULL)
53 {
54  this->set_name("ConjugateGradient");
56  objFunc=objective;
57  //Michael:: default to global?
59  //set the default inner termination criterion
60  TerminationCriterion* default_crit=get_inner_termination_criterion();
61  if(default_crit==NULL){
62  MSQ_SETERR(err)("QualityImprover did not create a default inner "
63  "termination criterion.", MsqError::INVALID_STATE);
64  return;
65  }
66  else{
67  default_crit->add_criterion_type_with_int(TerminationCriterion::NUMBER_OF_ITERATES,5,err);
68  MSQ_ERRRTN(err);
69  }
70 
71 }
void set_debugging_level(int new_lev)
Just for debugging purposes or for obtaining more data during the optimization process.
void set_name(msq_std::string name)
provides a name to the QualityImprover (use it in constructor).
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
virtual void set_patch_type(PatchData::PatchType type, MsqError &err, int patch_param1=0, int patch_param2=0)
Set the patch type.
Vector3D * fGrad
Culls the vertex list free_vertex_list.
TerminationCriterion * get_inner_termination_criterion()
return the inner termination criterion pointer
Terminates when the number of iterations exceeds a given integer.
object is in an invalid state
#define MSQ_ERRRTN(err)
If passed error is true, return from a void function.

Here is the call graph for this function:

~ConjugateGradient ( )
virtual

Definition at line 74 of file QualityImprover/VertexMover/ConjugateGradient/ConjugateGradient.cpp.

References ConjugateGradient::fGrad, ConjugateGradient::fNewGrad, ConjugateGradient::pGrad, and ConjugateGradient::pMemento.

75 {
76  // Checks that cleanup() has been called.
77  assert(fGrad==NULL);
78  assert(pGrad==NULL);
79  assert(pMemento==NULL);
80  assert(fNewGrad==NULL);
81 }
Vector3D * fGrad
Culls the vertex list free_vertex_list.
ConjugateGradient ( ObjectiveFunction objective,
MsqError err 
)
virtual ~ConjugateGradient ( )
virtual

Member Function Documentation

void cleanup ( )
protectedvirtual

Delete arrays initially created in initialize().

Implements VertexMover.

Definition at line 295 of file QualityImprover/VertexMover/ConjugateGradient/ConjugateGradient.cpp.

References ConjugateGradient::fGrad, ConjugateGradient::fNewGrad, ConjugateGradient::pGrad, and ConjugateGradient::pMemento.

296 {
297  // cout << "- Executing ConjugateGradient::iteration_end()\n";
298  delete []fGrad; fGrad = NULL;
299  delete []pGrad; pGrad = NULL;
300  delete []fNewGrad; fNewGrad = NULL;
301  //pMemento->~PatchDataVerticesMemento();
302  delete pMemento;
303  pMemento = NULL;
304 }
Vector3D * fGrad
Culls the vertex list free_vertex_list.
virtual void cleanup ( )
protectedvirtual

Delete arrays initially created in initialize().

Implements VertexMover.

double get_step ( PatchData pd,
double  f0,
int &  j,
MsqError err 
)
protected

Returns the step distance to take in the search direction.

Computes a distance to move vertices given an initial position and search direction (stored in data member pGrad).

Returns alp, the double which scales the search direction vector which when added to the old nodal positions yields the new nodal positions.

Todo:
Michael NOTE: ConjugateGradient::get_step's int &j is only to remain consisitent with CUBIT for an initial test. It can be removed.

Returns alp, the double which scales the search direction vector which when added to the old nodal positions yields the new nodal positions.

Todo:
Michael NOTE: ConjugateGradient::get_step's int &j is only to remain consisitent with CUBIT for an initial test. It can be removed.

Definition at line 314 of file QualityImprover/VertexMover/ConjugateGradient/ConjugateGradient.cpp.

References ObjectiveFunction::evaluate(), MsqError::INVALID_MESH, j, MSQ_ERRZERO, Mesquite::MSQ_MIN, MSQ_PRINT, MSQ_SETERR, PatchData::num_vertices(), VertexMover::objFunc, ConjugateGradient::pGrad, ConjugateGradient::pMemento, PatchData::recreate_vertices_memento(), PatchData::set_free_vertices_constrained(), and PatchData::set_to_vertices_memento().

Referenced by ConjugateGradient::optimize_vertex_positions().

316 {
317  size_t num_vertices=pd.num_vertices();
318  //initial guess for alp
319  double alp=1.0;
320  int jmax=100;
321  double rho=0.5;
322  //feasible=false implies the mesh is not in the feasible region
323  bool feasible=false;
324  int found=0;
325  //f and fnew hold the objective function value
326  double f=0;
327  double fnew=0;
328  //Counter to avoid infinitly scaling alp
329  j=0;
330  //save memento
331  pd.recreate_vertices_memento(pMemento, err);
332  //if we must check feasiblility
333  //while step takes mesh into infeasible region and ...
334  while (j<jmax && !feasible && alp>MSQ_MIN) {
335  ++j;
336  pd.set_free_vertices_constrained(pMemento,pGrad,num_vertices,alp,err);
337  feasible=objFunc->evaluate(pd,f,err); MSQ_ERRZERO(err);
338  //if not feasible, try a smaller alp (take smaller step)
339  if(!feasible){
340  alp*=rho;
341  }
342  }//end while ...
343 
344  //if above while ended due to j>=jmax, no valid step was found.
345  if(j>=jmax){
346  MSQ_PRINT(2)("\nFeasible Point Not Found");
347  return 0.0;
348  }
349  //Message::print_info("\nOriginal f %f, first new f = %f, alp = %f",f0,f,alp);
350  //if new f is larger than original, our step was too large
351  if(f>=f0){
352  j=0;
353  while (j<jmax && found == 0){
354  ++j;
355  alp *= rho;
356  pd.set_free_vertices_constrained(pMemento,pGrad,num_vertices,alp,err);
357  //Get new obj value
358  //if patch is now invalid, then the feasible region is convex or
359  //we have an error. For now, we assume an error.
360  if(! objFunc->evaluate(pd,f,err) ){
361  MSQ_SETERR(err)("Non-convex feasiblility region found.",MsqError::INVALID_MESH);
362  }
363  pd.set_to_vertices_memento(pMemento,err);MSQ_ERRZERO(err);
364  //if our step has now improved the objective function value
365  if(f<f0){
366  found=1;
367  }
368  }// end while j less than jmax
369  //Message::print_info("\nj = %d found = %d f = %20.18f f0 = %20.18f\n",j,found,f,f0);
370  //if above ended because of j>=jmax, take no step
371  if(found==0){
372  //Message::print_info("alp = %10.8f, but returning zero\n",alp);
373  alp=0.0;
374  return alp;
375  }
376 
377  j=0;
378  //while shrinking the step improves the objFunc value further,
379  //scale alp down. Return alp, when scaling once more would
380  //no longer improve the objFunc value.
381  while(j<jmax){
382  ++j;
383  alp*=rho;
384  //step alp in search direction from original positions
385  pd.set_free_vertices_constrained(pMemento,pGrad,num_vertices,alp,err);MSQ_ERRZERO(err);
386 
387  //get new objective function value
388  if (! objFunc->evaluate(pd,fnew,err))
389  MSQ_SETERR(err)("Non-convex feasiblility region found while "
390  "computing new f.",MsqError::INVALID_MESH);
391  if(fnew<f){
392  f=fnew;
393  }
394  else{
395  //Reset the vertices to original position
396  pd.set_to_vertices_memento(pMemento,err);MSQ_ERRZERO(err);
397  alp/=rho;
398  return alp;
399  }
400  }
401  //Reset the vertices to original position and return alp
402  pd.set_to_vertices_memento(pMemento,err);MSQ_ERRZERO(err);
403  return alp;
404  }
405  //else our new f was already smaller than our original
406  else{
407  j=0;
408  //check to see how large of step we can take
409  while (j<jmax && found == 0) {
410  ++j;
411  //scale alp up (rho must be less than 1)
412  alp /= rho;
413  //step alp in search direction from original positions
414  pd.set_free_vertices_constrained(pMemento,pGrad,num_vertices,alp,err);MSQ_ERRZERO(err);
415 
416  feasible = objFunc->evaluate(pd,fnew, err);MSQ_ERRZERO(err);
417  if ( ! feasible ){
418  alp *= rho;
419 
420  //Reset the vertices to original position and return alp
421  pd.set_to_vertices_memento(pMemento,err);MSQ_ERRZERO(err);
422  return alp;
423  }
424  if (fnew<f) {
425  f = fnew;
426  }
427  else {
428  found=1;
429  alp *= rho;
430  }
431  }
432 
433  //Reset the vertices to original position and return alp
434  pd.set_to_vertices_memento(pMemento,err);MSQ_ERRZERO(err);
435  return alp;
436  }
437 }
#define MSQ_ERRZERO(err)
Return zero/NULL on error.
bool evaluate(PatchData &patch, double &fval, MsqError &err)
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
j indices j
Definition: Indexing.h:6
#define MSQ_PRINT(flag)
Check debug flag and print printf-style formatted output.
const double MSQ_MIN
Definition: Mesquite.hpp:160

Here is the call graph for this function:

Here is the caller graph for this function:

double get_step ( PatchData pd,
double  f0,
int &  j,
MsqError err 
)
protected

Returns the step distance to take in the search direction.

virtual void initialize ( PatchData pd,
MsqError err 
)
protectedvirtual

Initialize data for smoothing process.

Implements VertexMover.

void initialize ( PatchData pd,
MsqError err 
)
protectedvirtual

Initialize data for smoothing process.

Implements VertexMover.

Definition at line 83 of file QualityImprover/VertexMover/ConjugateGradient/ConjugateGradient.cpp.

References ConjugateGradient::arraySize, PatchData::create_vertices_memento(), ConjugateGradient::fGrad, ConjugateGradient::fNewGrad, MSQ_DBGOUT, ConjugateGradient::pGrad, and ConjugateGradient::pMemento.

84 {
85  MSQ_DBGOUT(2) << "\no Performing Conjugate Gradient optimization.\n";
86  arraySize=5;
87  fGrad = new Vector3D[ arraySize ];
88  pGrad = new Vector3D[ arraySize ];
89  fNewGrad = new Vector3D[ arraySize ];
90  //mCoord = new Vector3D[ arraySize ];
91  pMemento=pd.create_vertices_memento(err);
92 }
NVec< 3, double > Vector3D
Vector3D * fGrad
Culls the vertex list free_vertex_list.
#define MSQ_DBGOUT(flag)
Check debug flag and return ostream associated with flag.

Here is the call graph for this function:

void initialize_mesh_iteration ( PatchData pd,
MsqError err 
)
protectedvirtual

Implements VertexMover.

Definition at line 110 of file QualityImprover/VertexMover/ConjugateGradient/ConjugateGradient.cpp.

112 {
113 
114 }
virtual void initialize_mesh_iteration ( PatchData pd,
MsqError err 
)
protectedvirtual

Implements VertexMover.

virtual void optimize_vertex_positions ( PatchData pd,
MsqError err 
)
protectedvirtual

Implements VertexMover.

void optimize_vertex_positions ( PatchData pd,
MsqError err 
)
protectedvirtual

Performs Conjugate gradient minimization on the PatchData, pd.

Implements VertexMover.

Definition at line 117 of file QualityImprover/VertexMover/ConjugateGradient/ConjugateGradient.cpp.

References TerminationCriterion::accumulate_inner(), TerminationCriterion::accumulate_patch(), ConjugateGradient::arraySize, ObjectiveFunction::compute_gradient(), ConjugateGradient::conjGradDebug, ConjugateGradient::fGrad, ConjugateGradient::fNewGrad, QualityImprover::get_inner_termination_criterion(), ConjugateGradient::get_step(), PatchData::get_vertex_array(), i, MsqError::INVALID_MESH, j, k, Mesquite::Linf(), MSQ_CHKERR, MSQ_DBGOUT, MSQ_ERRRTN, MSQ_FUNCTION_TIMER, Mesquite::MSQ_MAX_CAP, MSQ_PRINT, MSQ_SETERR, MsqFreeVertexIndexIterator::next(), PatchData::num_free_vertices(), PatchData::num_vertices(), VertexMover::objFunc, ConjugateGradient::pGrad, MsqFreeVertexIndexIterator::reset(), Vector3D::set(), Timer::since_birth(), PatchData::snap_vertex_to_domain(), TerminationCriterion::terminate(), and MsqFreeVertexIndexIterator::value().

118  {
119  // pd.reorder();
120 
121  MSQ_FUNCTION_TIMER( "ConjugateGradient::optimize_vertex_positions" );
122 
123  Timer c_timer;
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";
127  return;
128  }
129 
130  if(num_vert>arraySize){
131  delete []fGrad;
132  delete []pGrad;
133  delete []fNewGrad;
134  //Increase number to try to avoid reallocating
135  arraySize=num_vert + 5;
136  fGrad = new Vector3D[ arraySize ];
137  pGrad = new Vector3D[ arraySize ];
138  fNewGrad = new Vector3D[ arraySize ];
139  }
140  //zero out arrays
141  int zero_loop=0;
142  while(zero_loop<arraySize){
143  fGrad[zero_loop].set(0,0,0);
144  pGrad[zero_loop].set(0,0,0);
145  fNewGrad[zero_loop].set(0,0,0);
146  ++zero_loop;
147  }
148 
149  // gets the array of vertices for the patch
150  MsqVertex* vertices=pd.get_vertex_array(err); MSQ_ERRRTN(err);
151  int ind;
152  //Michael cull list: possibly set soft_fixed flags here
153 
154  MsqFreeVertexIndexIterator free_iter(&pd, err); MSQ_ERRRTN(err);
155 
156 
157  double f=0;
158  //Michael, this isn't equivalent to CUBIT because we only want to check
159  //the objective function value of the 'bad' elements
160  //if invalid initial patch set an error.
161  bool temp_bool = objFunc->compute_gradient(pd, fGrad, f, err, num_vert);
162  if(MSQ_CHKERR(err))
163  return;
164  if( ! temp_bool){
165  MSQ_SETERR(err)("Conjugate Gradient not able to get valid gradient "
166  "and function values on intial patch.",
168  return;
169  }
170  double grad_norm=MSQ_MAX_CAP;
171 
172  if(conjGradDebug>0){
173  MSQ_PRINT(2)("\nCG's DEGUB LEVEL = %i \n",conjGradDebug);
174  grad_norm=Linf(fGrad,num_vert);
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());
177  grad_norm=MSQ_MAX_CAP;
178  }
179 
180  ind=0;
181  //Initializing pGrad (search direction).
182  while(ind<num_vert){
183  pGrad[ind]=(-fGrad[ind]);
184  ++ind;
185  }
186  int j=0; // total nb of step size changes ... not used much
187  int i=0; // iteration counter
188  int m=0; //
189  double alp=MSQ_MAX_CAP; // alp: scale factor of search direction
190  //we know inner_criterion is false because it was checked in
191  //loop_over_mesh before being sent here.
192  TerminationCriterion* term_crit=get_inner_termination_criterion();
193 
194  //while ((i<maxIteration && alp>stepBound && grad_norm>normGradientBound)
195  // && !inner_criterion){
196  while(!term_crit->terminate()){
197  ++i;
198  //std::cout<<"\Michael delete i = "<<i;
199  int k=0;
200  alp=get_step(pd,f,k,err);
201  j+=k;
202  if(conjGradDebug>2){
203  MSQ_PRINT(2)("\n Alp initial, alp = %20.18f",alp);
204  }
205 
206  // if alp == 0, revert to steepest descent search direction
207  if(alp==0){
208  free_iter.reset();
209  while (free_iter.next()) {
210  m=free_iter.value();
211  pGrad[m]=(-fGrad[m]);
212  }
213  alp=get_step(pd,f,k,err);
214  j+=k;
215  if(conjGradDebug>1){
216  MSQ_PRINT(2)("\n CG's search direction reset.");
217  if(conjGradDebug>2)
218  MSQ_PRINT(2)("\n Alp was zero, alp = %20.18f",alp);
219  }
220 
221  }
222  if(alp!=0){
223  free_iter.reset();
224  while (free_iter.next()) {
225  m=free_iter.value();
226  vertices[m] += (alp * pGrad[m]);
227  //Added move_to_ownever
228  pd.snap_vertex_to_domain(m,err);
229  }
230  if (! objFunc->compute_gradient(pd, fNewGrad, f, err, num_vert)){
231  MSQ_SETERR(err)("Error inside Conjugate Gradient, vertices moved "
232  "making function value invalid.",
234  return;
235  }
236 
237  if(conjGradDebug>0){
238  grad_norm=Linf(fNewGrad,num_vert);
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());
241  }
242  double s11=0;
243  double s12=0;
244  double s22=0;
245  free_iter.reset();
246  while (free_iter.next()) {
247  m=free_iter.value();
248  s11+=fGrad[m]%fGrad[m];
249  s12+=fGrad[m]%fNewGrad[m];
250  s22+=fNewGrad[m]%fNewGrad[m];
251  }
252 
253  // Steepest Descent (takes 2-3 times as long as P-R)
254  //double bet=0;
255 
256  // Fletcher-Reeves (takes twice as long as P-R)
257  //double bet = s22/s11;
258 
259  // Polack-Ribiere
260  double bet = (s22-s12)/s11;
261  free_iter.reset();
262  while (free_iter.next()) {
263  m=free_iter.value();
264  pGrad[m]=(-fNewGrad[m]+(bet*pGrad[m]));
265  fGrad[m]=fNewGrad[m];
266  }
267  if(conjGradDebug>2){
268  MSQ_PRINT(2)(" \nSEARCH DIRECTION INFINITY NORM = %e",
269  Linf(fNewGrad,num_vert));
270  }
271 
272  }//end if on alp == 0
273  //Removing the following line of code (4/2/03) as it should not
274  //be needed with the new version of Termination Criterion.
275  //Update mesh before checking criterion
276  //pd.update_mesh(err);
277  term_crit->accumulate_inner( pd, f, fNewGrad, err ); MSQ_ERRRTN(err);
278  term_crit->accumulate_patch( pd, err ); MSQ_ERRRTN(err);
279  }//end while
280  if(conjGradDebug>0){
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());
284  }
285 }
const double MSQ_MAX_CAP
Definition: Mesquite.hpp:173
j indices k indices k
Definition: Indexing.h:6
double get_step(PatchData &pd, double f0, int &j, MsqError &err)
Returns the step distance to take in the search direction.
NVec< 3, double > Vector3D
#define MSQ_CHKERR(err)
Mesquite&#39;s Error Checking macro.
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.
blockLoc i
Definition: read.cpp:79
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
j indices j
Definition: Indexing.h:6
#define MSQ_PRINT(flag)
Check debug flag and print printf-style formatted output.
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.

Here is the call graph for this function:

void set_debugging_level ( int  new_lev)
inline

Just for debugging purposes or for obtaining more data during the optimization process.

Definition at line 65 of file includeLinks/ConjugateGradient.hpp.

References ConjugateGradient::conjGradDebug.

Referenced by ConjugateGradient::ConjugateGradient().

Here is the caller graph for this function:

void set_debugging_level ( int  new_lev)
inline

Just for debugging purposes or for obtaining more data during the optimization process.

Definition at line 65 of file src/QualityImprover/VertexMover/ConjugateGradient/ConjugateGradient.hpp.

References ConjugateGradient::conjGradDebug.

virtual void set_patch_type ( PatchData::PatchType  type,
MsqError err,
int  patch_param1 = 0,
int  patch_param2 = 0 
)
virtual

Set the patch type.

Reimplemented from PatchDataUser.

void set_patch_type ( PatchData::PatchType  type,
MsqError err,
int  patch_param1 = 0,
int  patch_param2 = 0 
)
virtual

Set the patch type.

Reimplemented from PatchDataUser.

Definition at line 99 of file QualityImprover/VertexMover/ConjugateGradient/ConjugateGradient.cpp.

References PatchData::ELEMENTS_ON_VERTEX_PATCH, PatchData::GLOBAL_PATCH, MsqError::INVALID_ARG, MSQ_SETERR, and PatchDataUser::set_patch_type().

Referenced by ConjugateGradient::ConjugateGradient().

101 {
103  PatchDataUser::set_patch_type(type, err, patch_param1, patch_param2);
104  } else {
105  MSQ_SETERR(err)("Type not supported by ConjugateGradient algorythm.",
107  }
108 }
virtual void set_patch_type(PatchData::PatchType patch_type, MsqError &err, int param1=0, int param2=0)
Sets the Patch Type.
invalid function argument passed
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.

Here is the call graph for this function:

Here is the caller graph for this function:

void terminate_mesh_iteration ( PatchData pd,
MsqError err 
)
protectedvirtual

Implements VertexMover.

Definition at line 288 of file QualityImprover/VertexMover/ConjugateGradient/ConjugateGradient.cpp.

290 {
291  // cout << "- Executing ConjugateGradient::iteration_complete()\n";
292 }
virtual void terminate_mesh_iteration ( PatchData pd,
MsqError err 
)
protectedvirtual

Implements VertexMover.

Member Data Documentation


The documentation for this class was generated from the following files: