38 #include "MsqFreeVertexIndexIterator.hpp"
39 #include "MsqTimer.hpp"
40 #include "MsqDebug.hpp"
71 msq_std::vector<Vector3D> gradient(num_vertices), dk(num_vertices);
72 int nb_iterations = 0;
75 double smallest_edge = 0.4;
83 double original_value = 0.0;
91 MSQ_DBGOUT(3) <<
"\n o Free vertices ("<< num_free_vertices <<
")original coordinates:\n ";
102 for (
int n=0;
n<num_vertices; ++
n)
103 norm += gradient[
n] % gradient[
n];
105 MSQ_DBGOUT(3) <<
" o gradient norm: " << norm << msq_stdio::endl;
113 for (
int i=0;
i<num_vertices; ++
i)
114 for (
int j=0;
j<3; ++
j)
115 dk[
i][
j] = -gradient[
i][
j] / norm;
121 MSQ_SETERR(err)(
"SteepestDescent passed invalid initial patch.",
125 MSQ_DBGOUT(3) <<
" o original_value: " << original_value << msq_stdio::endl;
127 double new_value = original_value+1;
134 if (
MSQ_CHKERR(err)) {
delete pd_previous_coords;
return; }
136 double step_size = smallest_edge;
137 while (new_value > original_value
143 if (
MSQ_CHKERR(err)) {
delete pd_previous_coords;
return; }
146 if (
MSQ_CHKERR(err)) {
delete pd_previous_coords;
return; }
148 MSQ_SETERR(err)(
"SteepestDescent created invalid patch.",
150 delete pd_previous_coords;
153 MSQ_DBGOUT(3) <<
" o step_size: " << step_size << msq_stdio::endl;
154 MSQ_DBGOUT(3) <<
" o new_value: " << new_value << msq_stdio::endl;
157 if (new_value > original_value) {
160 if (
MSQ_CHKERR(err)) {
delete pd_previous_coords;
return; }
168 MSQ_DBGOUT(3) <<
" o Free vertices new coordinates: \n";
170 if (
MSQ_CHKERR(err)) {
delete pd_previous_coords;
return; }
172 if (
MSQ_CHKERR(err)) {
delete pd_previous_coords;
return; }
179 delete pd_previous_coords;
#define MSQ_DBG(flag)
Check if a debug flag is activated - evaluates to a bool.
size_t value()
Returns an index corresponding to a free vertex.
virtual void terminate_mesh_iteration(PatchData &pd, MsqError &err)
virtual void optimize_vertex_positions(PatchData &pd, MsqError &err)
virtual void set_patch_type(PatchData::PatchType patch_type, MsqError &err, int param1=0, int param2=0)
Sets the Patch Type.
Used to hold the error state and return it to the application.
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).
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.
virtual void initialize_mesh_iteration(PatchData &pd, MsqError &err)
T norm(const NVec< DIM, T > &v)
PatchDataVerticesMemento * create_vertices_memento(MsqError &err, bool include_higher_order=false)
Creates a memento that holds the current state of the PatchData coordinates.
invalid function argument passed
#define MSQ_CHKERR(err)
Mesquite'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.
ObjectiveFunction * objFunc
virtual void initialize(PatchData &pd, MsqError &err)
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
void move_free_vertices_constrained(Vector3D dk[], size_t nb_vtx, double step_size, MsqError &err)
Moves free vertices and then snaps the free vertices to the domain.
const MsqVertex * get_vertex_array(MsqError &err) const
Returns a pointer to the start of the vertex array.
#define MSQ_FUNCTION_TIMER(NAME)
Contains a copy of the coordinates of a PatchData.
#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...
SteepestDescent(ObjectiveFunction *of)
#define MSQ_ERRRTN(err)
If passed error is true, return from a void function.
Base class for concrete Objective Functions ObjectiveFunction contains a pointer to a QualityMetric...