29int 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; }
118 const real_t diff = std::abs(i_form - m_form) / std::abs(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 real_t 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 real_t rate_dF_sum = 0.0, err_old = 1.0;
170 for (
int k = 0; k < convergence_iter; k++)
173 for (
int i = 0; i < x_loc.
Size(); i++)
176 err_k = std::max(err_k, std::abs(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 real_t 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 real_t 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++)
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 = std::max(err_k, std::abs(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 real_t 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 = std::min(min_avg_rate, rate_sum / (convergence_iter - 1));
245 std::cout <<
"--- AssembleH: avg rate of convergence (should be 2): "
246 << min_avg_rate << endl;
Data type dense matrix using column-major storage.
real_t * GetData() const
Returns the matrix data array.
virtual void Print(std::ostream &out=mfem::out, int width_=4) const
Prints matrix to stream out.
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
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 ...
virtual const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th element in t...
Abstract class for all finite elements.
Class for grid function - Vector with associated FE space.
Arbitrary order H1-conforming (continuous) finite elements.
void GetElementTransformation(int i, IsoparametricTransformation *ElTr) const
Builds the transformation defining the i-th element in ElTr. ElTr must be allocated in advance and wi...
static Mesh MakeCartesian3D(int nx, int ny, int nz, Element::Type type, real_t sx=1.0, real_t sy=1.0, real_t sz=1.0, bool sfc_ordering=true)
Creates a mesh for the parallelepiped [0,sx]x[0,sy]x[0,sz], divided into nx*ny*nz hexahedra if type =...
void SetNodalGridFunction(GridFunction *nodes, bool make_owner=false)
virtual void SetNodalFESpace(FiniteElementSpace *nfes)
static Mesh MakeCartesian2D(int nx, int ny, Element::Type type, bool generate_edges=false, real_t sx=1.0, real_t sy=1.0, bool sfc_ordering=true)
Creates mesh for the rectangle [0,sx]x[0,sy], divided into nx*ny quadrilaterals if type = QUADRILATER...
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
void PrintUsage(std::ostream &out) const
Print the usage message.
void PrintOptions(std::ostream &out) const
Print the options.
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...
bool Good() const
Return true if the command line options were parsed successfully.
2D barrier Shape+Size+Orientation (VOS) metric (polyconvex).
2D barrier Shape+Orientation (OS) metric (polyconvex).
2D barrier Shape+Size (VS) metric (polyconvex).
A TMOP integrator class based on any given TMOP_QualityMetric and TargetConstructor.
2D non-barrier metric without a type.
2D barrier Shape+Size (VS) metric (not polyconvex).
2D barrier Shape+Size (VS) metric (not polyconvex).
2D non-barrier Shape+Size+Orientation (VOS) metric (polyconvex).
2D Shifted barrier form of shape metric (mu_2).
2D barrier shape (S) metric (not polyconvex).
2D barrier Shape+Orientation (OS) metric (polyconvex).
2D compound barrier Shape+Size (VS) metric (balanced).
2D compound barrier Shape+Size (VS) metric (balanced).
2D barrier Shape+Size+Orientation (VOS) metric (polyconvex).
3D barrier Shape (S) metric, well-posed (polyconvex & invex).
3D barrier Shape (S) metric, well-posed (polyconvex & invex).
3D barrier Shape (S) metric, well-posed (polyconvex & invex).
3D barrier Shape (S) metric, well-posed (polyconvex & invex).
3D Shape (S) metric, untangling version of 303.
3D barrier Shape+Size (VS) metric, well-posed (invex).
3D barrier Shape+Size (VS) metric, well-posed (invex).
3D barrier Shape+Size (VS) metric, well-posed (invex).
3D compound barrier Shape+Size (VS) metric (polyconvex, balanced).
3D compound barrier Shape+Size (VS) metric (polyconvex).
3D barrier Shape+Size (VS) metric, well-posed (polyconvex).
3D barrier Shape+Size (VS) metric, well-posed (polyconvex).
3D compound barrier Shape+Size (VS) metric (polyconvex, balanced).
3D barrier Shape+Size (VS) metric, well-posed (polyconvex).
3D non-barrier Shape (S) metric.
Abstract class for local mesh quality metrics in the target-matrix optimization paradigm (TMOP) by P....
virtual real_t EvalWMatrixForm(const DenseMatrix &Jpt) const
Evaluates the metric in matrix form (opposed to invariant form). Used for validating the invariant ev...
virtual real_t EvalW(const DenseMatrix &Jpt) const =0
Evaluate the strain energy density function, W = W(Jpt), by using the 2D or 3D matrix invariants,...
Base class representing target-matrix construction algorithms for mesh optimization via the target-ma...
void SetNodes(const GridFunction &n)
Set the nodes to be used in the target-matrix construction.
void Randomize(int seed=0)
Set random values in the vector.
void Print(std::ostream &out=mfem::out, int width=8) const
Prints vector to stream out.
real_t Max() const
Returns the maximal element of the vector.
int Size() const
Returns the size of the vector.
void GetSubVector(const Array< int > &dofs, Vector &elemvect) const
Extract entries listed in dofs to the output Vector elemvect.