29 int main(
int argc,
char *argv[])
32 int convergence_iter = 10;
37 args.
AddOption(&metric_id,
"-mid",
"--metric-id",
"Metric id");
38 args.
AddOption(&verbose,
"-v",
"-verbose",
"-no-v",
"--no-verbose",
39 "Enable extra screen output.");
40 args.
AddOption(&convergence_iter,
"-i",
"--iterations",
41 "Number of iterations to check convergence of derivatives.");
100 default: cout <<
"Unknown metric_id: " << metric_id << endl;
return 3;
103 const int dim = (metric_id < 300) ? 2 : 3;
108 int valid_cnt = 0, bad_cnt = 0;
109 for (
int i = 0; i < 1000; i++)
113 T(0, 0) += T_vec.Max();
114 if (T.Det() <= 0.0) {
continue; }
116 const double i_form = metric->
EvalW(T),
118 const double diff = fabs(i_form - m_form) / fabs(m_form);
124 cout <<
"Wrong metric computation: " 125 << i_form <<
" (invariant), " << m_form <<
" (matrix form) " 126 << diff <<
" (normalized difference) " << endl;
131 cout <<
"--- EvalW: " << bad_cnt <<
" errors out of " 132 << valid_cnt <<
" comparisons with det(T) > 0.\n";
154 a.AddDomainIntegrator(integ);
165 const double F_0 = integ->GetElementEnergy(fe, Tr, x_loc);
166 integ->AssembleElementVector(fe, Tr, x_loc, dF_0);
167 if (verbose) { cout <<
"***\ndF = \n"; dF_0.
Print(); cout <<
"***\n"; }
169 double rate_dF_sum = 0.0, err_old;
170 for (
int k = 0; k < convergence_iter; k++)
173 for (
int i = 0; i < x_loc.Size(); i++)
176 err_k = fmax(err_k, fabs(F_0 + dF_0(i) * dx -
177 integ->GetElementEnergy(fe, Tr, x_loc)));
182 if (verbose && k == 0)
184 std::cout <<
"dF error " << k <<
": " << err_k << endl;
188 double r = log2(err_old / err_k);
192 std::cout <<
"dF error " << k <<
": " << err_k <<
" " << r << endl;
197 std::cout <<
"--- EvalP: avg rate of convergence (should be 2): " 198 << rate_dF_sum / (convergence_iter - 1) << endl;
201 double min_avg_rate = 7.0;
203 integ->AssembleElementGrad(fe, Tr, x_loc, ddF_0);
204 if (verbose) { cout <<
"***\nddF = \n"; ddF_0.
Print(); cout <<
"***\n"; }
205 for (
int i = 0; i < x_loc.Size(); i++)
207 double rate_sum = 0.0;
209 for (
int k = 0; k < convergence_iter; k++)
213 for (
int j = 0; j < x_loc.Size(); j++)
217 integ->AssembleElementVector(fe, Tr, x_loc, dF_dx);
218 err_k = fmax(err_k, fabs(dF_0(i) + ddF_0(i, j) * dx - dF_dx(i)));
223 if (verbose && k == 0)
225 cout <<
"ddF error for dof " << i <<
", " << k <<
": " 230 double r = log2(err_old / err_k);
232 if (err_k < 1e-14) { r = 2.0; }
236 cout <<
"ddF error for dof " << i <<
", " << k <<
": " << err_k
243 min_avg_rate = fmin(min_avg_rate, rate_sum / (convergence_iter - 1));
245 std::cout <<
"--- AssembleH: avg rate of convergence (should be 2): " 246 << 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).
void PrintOptions(std::ostream &out) const
Print the options.
3D barrier Shape (S) metric, well-posed (polyconvex & invex).
void PrintUsage(std::ostream &out) const
Print the usage message.
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)
void Print(std::ostream &out=mfem::out, int width=8) const
Prints vector to stream out.
int Size() const
Returns the size of the vector.
Data type dense matrix using column-major storage.
3D barrier Shape (S) metric, well-posed (polyconvex & invex).
3D compound barrier Shape+Size (VS) metric (polyconvex, balanced).
2D barrier Shape+Size (VS) metric (polyconvex).
3D barrier Shape+Size (VS) metric, well-posed (invex).
bool Good() const
Return true if the command line options were parsed successfully.
void GetSubVector(const Array< int > &dofs, Vector &elemvect) const
Extract entries listed in dofs to the output Vector elemvect.
void Randomize(int seed=0)
Set random values in the vector.
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).
virtual const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th element in t...
2D barrier shape (S) metric (not polyconvex).
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...
2D compound barrier Shape+Size (VS) metric (balanced).
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
void SetNodes(const GridFunction &n)
Set the nodes to be used in the target-matrix construction.
virtual void Print(std::ostream &out=mfem::out, int width_=4) const
Prints matrix to stream out.
3D barrier Shape+Size (VS) metric, well-posed (polyconvex).
2D barrier Shape+Size+Orientation (VOS) metric (polyconvex).
virtual void SetNodalFESpace(FiniteElementSpace *nfes)
2D barrier Shape+Orientation (OS) metric (polyconvex).
DofTransformation * GetElementVDofs(int i, Array< int > &vdofs) const
Returns indices of degrees of freedom for the i'th element. The returned indices are offsets into an ...
3D compound barrier Shape+Size (VS) metric (polyconvex, balanced).
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
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).
virtual double EvalWMatrixForm(const DenseMatrix &Jpt) const
Evaluates the metric in matrix form (opposed to invariant form). Used for validating the invariant ev...
void GetElementTransformation(int i, IsoparametricTransformation *ElTr)
2D barrier Shape+Size+Orientation (VOS) metric (polyconvex).
3D Shape (S) metric, untangling version of 303.
2D compound barrier Shape+Size (VS) metric (balanced).
3D barrier Shape+Size (VS) metric, well-posed (polyconvex).
Arbitrary order H1-conforming (continuous) finite elements.
int main(int argc, char *argv[])
void SetNodalGridFunction(GridFunction *nodes, bool make_owner=false)
Base class representing target-matrix construction algorithms for mesh optimization via the target-ma...
3D compound 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.
A TMOP integrator class based on any given TMOP_QualityMetric and TargetConstructor.
2D non-barrier Shape+Size+Orientation (VOS) metric (polyconvex).