22 int main(
int argc,
char *argv[])
25 int convergence_iter = 10;
30 args.
AddOption(&metric_id,
"-mid",
"--metric-id",
"Metric id");
31 args.
AddOption(&verbose,
"-v",
"-verbose",
"-no-v",
"--no-verbose",
32 "Enable extra screen output.");
33 args.
AddOption(&convergence_iter,
"-i",
"--iterations",
34 "Number of iterations to check convergence of derivatives.");
89 default: cout <<
"Unknown metric_id: " << metric_id << endl;
return 3;
92 const int dim = (metric_id < 300) ? 2 : 3;
97 int valid_cnt = 0, bad_cnt = 0;
98 for (
int i = 0; i < 1000; i++)
102 T(0, 0) += T_vec.Max();
103 if (T.
Det() <= 0.0) {
continue; }
105 const double i_form = metric->
EvalW(T),
107 const double diff = fabs(i_form - m_form) / fabs(m_form);
113 cout <<
"Wrong metric computation: "
114 << i_form <<
" (invariant), " << m_form <<
" (matrix form) "
115 << diff <<
" (normalized difference) " << endl;
120 cout <<
"--- EvalW: " << bad_cnt <<
" errors out of "
121 << valid_cnt <<
" comparisons with det(T) > 0.\n";
156 const double F_0 = integ->GetElementEnergy(fe, Tr, x_loc);
157 integ->AssembleElementVector(fe, Tr, x_loc, dF_0);
158 if (verbose) { cout <<
"***\ndF = \n"; dF_0.
Print(); cout <<
"***\n"; }
160 double rate_dF_sum = 0.0, err_old;
161 for (
int k = 0; k < convergence_iter; k++)
164 for (
int i = 0; i < x_loc.Size(); i++)
167 err_k = fmax(err_k, fabs(F_0 + dF_0(i) * dx -
168 integ->GetElementEnergy(fe, Tr, x_loc)));
173 if (verbose && k == 0)
175 std::cout <<
"dF error " << k <<
": " << err_k << endl;
179 double r = log2(err_old / err_k);
183 std::cout <<
"dF error " << k <<
": " << err_k <<
" " << r << endl;
188 std::cout <<
"--- EvalP: avg rate of convergence (should be 2): "
189 << rate_dF_sum / (convergence_iter - 1) << endl;
194 double min_avg_rate = 7.0;
196 integ->AssembleElementGrad(fe, Tr, x_loc, ddF_0);
197 if (verbose) { cout <<
"***\nddF = \n"; ddF_0.
Print(); cout <<
"***\n"; }
198 for (
int i = 0; i < x_loc.Size(); i++)
200 double rate_sum = 0.0;
202 for (
int k = 0; k < convergence_iter; k++)
206 for (
int j = 0; j < x_loc.Size(); j++)
210 integ->AssembleElementVector(fe, Tr, x_loc, dF_dx);
211 err_k = fmax(err_k, fabs(dF_0(i) + ddF_0(i, j) * dx - dF_dx(i)));
216 if (verbose && k == 0)
218 cout <<
"ddF error for dof " << i <<
", " << k <<
": "
223 double r = log2(err_old / err_k);
227 cout <<
"ddF error for dof " << i <<
", " << k <<
": " << err_k
234 min_avg_rate = fmin(min_avg_rate, rate_sum / (convergence_iter - 1));
236 std::cout <<
"--- AssembleH: avg rate of convergence (should be 2): "
237 << min_avg_rate << endl;
Abstract class for all finite elements.
3D non-barrier Shape (S) metric.
Class for grid function - Vector with associated FE space.
3D barrier Shape+Size (VS) metric, well-posed (invex).
3D barrier Shape+Size (VS) metric, well-posed (polyconvex).
3D barrier Shape (S) metric, well-posed (polyconvex & invex).
virtual double EvalW(const DenseMatrix &Jpt) const =0
Evaluate the strain energy density function, W = W(Jpt), by using the 2D or 3D matrix invariants...
static Mesh MakeCartesian3D(int nx, int ny, int nz, Element::Type type, double sx=1.0, double sy=1.0, double sz=1.0, bool sfc_ordering=true)
2D barrier Shape+Size (VS) metric (polyconvex).
void GetSubVector(const Array< int > &dofs, Vector &elemvect) const
Extract entries listed in dofs to the output Vector elemvect.
Data type dense matrix using column-major storage.
3D barrier Shape (S) metric, well-posed (polyconvex & invex).
int Size() const
Returns the size of the vector.
2D barrier shape (S) metric (polyconvex).
3D non-barrier metric without a type.
2D barrier size (V) metric (polyconvex).
2D barrier Shape+Size (VS) metric (polyconvex).
3D barrier Shape+Size (VS) metric, well-posed (invex).
void Randomize(int seed=0)
Set random values in the vector.
double * GetData() const
Returns the matrix data array.
2D barrier Shape+Size (VS) metric (not polyconvex).
3D barrier Shape+Size (VS) metric, well-posed (invex).
2D Shifted barrier form of shape metric (mu_2).
2D barrier shape (S) metric (not polyconvex).
virtual void Print(std::ostream &out=mfem::out, int width_=4) const
Prints matrix to stream out.
3D barrier Shape (S) metric, well-posed (polyconvex & invex).
Abstract class for local mesh quality metrics in the target-matrix optimization paradigm (TMOP) by P...
DofTransformation * GetElementVDofs(int i, Array< int > &vdofs) const
Returns indexes of degrees of freedom in array dofs for i'th element.
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
2D non-barrier size (V) metric (not polyconvex).
3D barrier metric without a type.
void SetNodes(const GridFunction &n)
Set the nodes to be used in the target-matrix construction.
3D barrier Shape+Size (VS) metric, well-posed (polyconvex).
2D barrier Shape+Size+Orientation (VOS) metric (polyconvex).
virtual void SetNodalFESpace(FiniteElementSpace *nfes)
virtual double EvalWMatrixForm(const DenseMatrix &Jpt) const
Evaluates the metric in matrix form (opposed to invariant form). Used for validating the invariant ev...
void PrintUsage(std::ostream &out) const
Print the usage message.
2D barrier Shape+Orientation (OS) metric (polyconvex).
3D barrier Shape+Size (VS) metric (polyconvex).
2D barrier (not a shape) metric (polyconvex).
void Print(std::ostream &out=mfem::out, int width=8) const
Prints vector to stream out.
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
2D barrier size (V) metric (polyconvex).
void AddOption(bool *var, const char *enable_short_name, const char *enable_long_name, const char *disable_short_name, const char *disable_long_name, const char *description, bool required=false)
Add a boolean option and set 'var' to receive the value. Enable/disable tags are used to set the bool...
static Mesh MakeCartesian2D(int nx, int ny, Element::Type type, bool generate_edges=false, double sx=1.0, double sy=1.0, bool sfc_ordering=true)
2D barrier Shape+Size (VS) metric (not polyconvex).
void GetElementTransformation(int i, IsoparametricTransformation *ElTr)
2D barrier Shape+Size+Orientation (VOS) metric (polyconvex).
3D Shape (S) metric, untangling version of 303.
virtual const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th element in t...
void PrintOptions(std::ostream &out) const
Print the options.
3D barrier Shape+Size (VS) metric, well-posed (polyconvex).
Arbitrary order H1-conforming (continuous) finite elements.
void SetNodalGridFunction(GridFunction *nodes, bool make_owner=false)
Base class representing target-matrix construction algorithms for mesh optimization via the target-ma...
3D barrier Shape+Size (VS) metric (polyconvex).
2D barrier Shape+Orientation (OS) metric (polyconvex).
3D barrier Shape (S) metric, well-posed (polyconvex & invex).
2D non-barrier metric without a type.
bool Good() const
Return true if the command line options were parsed successfully.
A TMOP integrator class based on any given TMOP_QualityMetric and TargetConstructor.
2D non-barrier Shape+Size+Orientation (VOS) metric (polyconvex).