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";
100 int patch_param1,
int patch_param2)
105 MSQ_SETERR(err)(
"Type not supported by ConjugateGradient algorythm.",
126 MSQ_DBGOUT(1) <<
"\nEmpty free vertex list in ConjugateGradient\n";
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);
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]);
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);
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",
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);
334 while (j<jmax && !feasible && alp>
MSQ_MIN) {
346 MSQ_PRINT(2)(
"\nFeasible Point Not Found");
353 while (j<jmax && found == 0){
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.
size_t value()
Returns an index corresponding to a free vertex.
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)
Used to hold the error state and return it to the application.
void accumulate_patch(PatchData &pd, MsqError &err)
Common code for both inner and outer termination criteria during inner iteration. ...
void recreate_vertices_memento(PatchDataVerticesMemento *memento, MsqError &err, bool include_higher_order=false)
reinstantiates a memento to holds the current state of the PatchData coordinates. ...
bool evaluate(PatchData &patch, double &fval, MsqError &err)
The TerminationCriterion class contains functionality to terminate the VertexMover's optimization...
void set_name(msq_std::string name)
provides a name to the QualityImprover (use it in constructor).
Vector3D is the object that effeciently stores information about about three-deminsional vectors...
void reset()
Resets the iterator.
bool terminate()
Check if termination criterion has been met.
void set_to_vertices_memento(PatchDataVerticesMemento *memento, MsqError &err)
Restore the PatchData coordinates to the state contained in the memento.
int num_free_vertices(MsqError &err) const
Returns the number of elements in the current patch who are free to move.
bool next()
Increments the iterator. returns false if there is no more free vertex.
PatchDataVerticesMemento * create_vertices_memento(MsqError &err, bool include_higher_order=false)
Creates a memento that holds the current state of the PatchData coordinates.
double since_birth() const
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
#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
void snap_vertex_to_domain(size_t vertex_index, MsqError &err)
Adjust the position of the specified vertex so that it lies on its constraining domain.
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)
size_t num_vertices() const
number of vertices in the patch.
void accumulate_inner(PatchData &pd, MsqError &err)
Accumulate data during inner iteration.
TerminationCriterion * get_inner_termination_criterion()
return the inner termination criterion pointer
virtual void initialize_mesh_iteration(PatchData &pd, MsqError &err)
const MsqVertex * get_vertex_array(MsqError &err) const
Returns a pointer to the start of the vertex array.
void set_free_vertices_constrained(PatchDataVerticesMemento *memento, Vector3D dk[], size_t nb_vtx, double step_size, 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)
void add_criterion_type_with_int(TCType tc_type, int bound, MsqError &err)
Sets the criterion by specifing the TCType and the integer value.
#define MSQ_DBGOUT(flag)
Check debug flag and return ostream associated with flag.
iterates over indexes of free vetices in a PatchData.
MsqVertex is the Mesquite object that stores information about the vertices in the mesh...
#define MSQ_ERRRTN(err)
If passed error is true, return from a void function.
ConjugateGradient(ObjectiveFunction *objective, MsqError &err)
Base class for concrete Objective Functions ObjectiveFunction contains a pointer to a QualityMetric...