34 iso =
true; aniso =
true;
37 MFEM_VERIFY(iso || aniso,
"Metric type not supported in hr-adaptivity.");
40 const int num_ref_types = 3 + 4*(dim-2);
45 Vector amr_base_energy(NEorig), amr_temp_energy(NEorig);
50 for (
int i = 1; i < num_ref_types+1; i++)
52 if ( dim == 2 && i < 3 && aniso !=
true ) {
continue; }
53 if ( dim == 2 && i == 3 && iso !=
true ) {
continue; }
54 if ( dim == 3 && i < 7 && aniso !=
true ) {
continue; }
55 if ( dim == 3 && i == 7 && iso !=
true ) {
continue; }
59 for (
int e = 0; e < NEorig; e++)
76 for (
int i = 0; i < amr_base_energy.Size(); i++)
91 const int NE = fes->
GetNE();
97 el_energy_vec = std::numeric_limits<float>::max();
99 for (
int e = 0; e < NE; e++)
116 int ref_access = reftype == 0 ? 0 : 1;
123 int ref_access = reftype == 0 ? 0 : 1;
130 MFEM_VERIFY(
QuadIntRule[reftype],
" Integration rule does not exist.");
137 int ref_access = reftype == 0 ? 0 : 1;
143 MFEM_ABORT(
"Incompatible geometry type!");
147 el_energy_vec(e) = 0.;
156 for (
int i = 0; i < integs.Size(); i++)
170 for (
int j = 0; j < ati.
Size(); j++)
172 el_energy_vec(e) += ati[j]->GetRefinementElementEnergy(*fes->
GetFE(e),
187 Mesh base_mesh_copy(meshsplit);
192 for (
int i = 7; i < 8; i++)
195 Mesh mesh_ref(base_mesh_copy);
196 for (
int e = 0; e < mesh_ref.
GetNE(); e++)
212 Mesh base_mesh_copy(meshsplit);
217 for (
int i = 1; i < 4; i++)
220 Mesh mesh_ref(base_mesh_copy);
221 for (
int e = 0; e < mesh_ref.
GetNE(); e++)
236 const int Nvert = 3, NEsplit = 1;
237 Mesh meshsplit(2, Nvert, NEsplit, 0, 2);
238 const double tri_v[3][2] =
240 {0, 0}, {1, 0}, {0, 1}
242 const int tri_e[1][3] =
247 for (
int j = 0; j < Nvert; j++)
254 Mesh base_mesh_copy(meshsplit);
260 for (
int i = 1; i < 2; i++)
263 Mesh mesh_ref(base_mesh_copy);
264 for (
int e = 0; e < mesh_ref.
GetNE(); e++)
279 const int Nvert = 4, NEsplit = 1;
280 Mesh meshsplit(3, Nvert, NEsplit, 0, 3);
281 const double tet_v[4][3] =
283 {0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1}
285 const int tet_e[1][4] =
290 for (
int j = 0; j < Nvert; j++)
294 meshsplit.
AddTet(tet_e[0], 1);
297 Mesh base_mesh_copy(meshsplit);
303 for (
int i = 1; i < 2; i++)
306 Mesh mesh_ref(base_mesh_copy);
307 for (
int e = 0; e < mesh_ref.
GetNE(); e++)
324 const int NEsplit = meshsplit.
GetNE();
326 pts_cnt = NEsplit * dof_cnt;
337 for (
int i = 0; i < NEsplit; i++)
341 for (
int j = 0; j < dof_cnt; j++)
349 irule->
IntPoint(pt_id).
Set3(pos(j, 0), pos(j, 1), pos(j, 2));
375 double threshold = std::numeric_limits<float>::max();
398 Table coarse_to_fine;
402 for (
int pe = 0; pe < coarse_to_fine.
Size(); pe++)
404 coarse_to_fine.
GetRow(pe, tabrow);
405 int nchild = tabrow.
Size();
406 double parent_energy = coarse_energy(pe);
407 for (
int fe = 0; fe < nchild; fe++)
409 int child = tabrow[fe];
410 MFEM_VERIFY(child < mesh->GetNE(),
" invalid coarse to fine mapping");
411 fine_energy(child) -= parent_energy;
428 double threshold = std::numeric_limits<float>::max();
451 Table coarse_to_fine;
455 for (
int pe = 0; pe < meshcopy.
GetNE(); pe++)
457 coarse_to_fine.
GetRow(pe, tabrow);
458 int nchild = tabrow.
Size();
459 double parent_energy = coarse_energy(pe);
460 for (
int fe = 0; fe < nchild; fe++)
462 int child = tabrow[fe];
463 MFEM_VERIFY(child < pmesh->GetNE(),
" invalid coarse to fine mapping");
464 fine_energy(child) -= parent_energy;
486 for (
int i = 0; i < integs.
Size(); i++)
499 for (
int j = 0; j < ati.
Size(); j++)
513 const int cNE = cmesh.
GetNE();
524 for (
int j = 0; j < cNE; j++)
526 fe = fespace->
GetFE(j);
537 bool move_bnd_,
bool hradaptivity_,
538 int mesh_poly_deg_,
int amr_metric_id_,
539 int hr_iter_,
int h_per_r_iter_) :
540 mesh(&mesh_), nlf(&nlf_), tmopns(&tmopns_), x(&x_),
541 gridfuncarr(), fespacearr(),
542 move_bnd(move_bnd_), hradaptivity(hradaptivity_),
543 mesh_poly_deg(mesh_poly_deg_), amr_metric_id(amr_metric_id_),
544 serial(true), hr_iter(hr_iter_), h_per_r_iter(h_per_r_iter_)
560 bool move_bnd_,
bool hradaptivity_,
561 int mesh_poly_deg_,
int amr_metric_id_,
562 int hr_iter_,
int h_per_r_iter_) :
563 mesh(&pmesh_), nlf(&pnlf_), tmopns(&tmopns_), x(&px_),
564 gridfuncarr(), fespacearr(),
565 move_bnd(move_bnd_), hradaptivity(hradaptivity_),
566 mesh_poly_deg(mesh_poly_deg_), amr_metric_id(amr_metric_id_),
567 pmesh(&pmesh_), pnlf(&pnlf_), pgridfuncarr(), pfespacearr(),
568 serial(false), hr_iter(hr_iter_), h_per_r_iter(h_per_r_iter_)
602 if (myid == 0) {
mfem::out <<
"Nonlinear solver: rtol not achieved.\n"; }
608 bool radaptivity =
true;
615 for (
int i_hr = 0; i_hr <
hr_iter; i_hr++)
621 mfem::out << i_hr <<
" r-adaptivity iteration.\n";
627 mfem::out <<
"TMOP energy after r-adaptivity: " <<
629 ", Elements: " <<
mesh->
GetNE() << std::endl;
639 mfem::out <<
"TMOP energy after derefinement: " <<
641 ", Elements: " <<
mesh->
GetNE() << std::endl;
646 mfem::out <<
"TMOP energy after refinement: " <<
648 ", Elements: " <<
mesh->
GetNE() << std::endl;
653 mfem::out <<
"AMR stopping criterion satisfied. Stop.\n";
664 for (
int i_hr = 0; i_hr <
hr_iter; i_hr++)
670 if (myid == 0) {
mfem::out << i_hr <<
" r-adaptivity iteration.\n"; }
679 mfem::out <<
"TMOP energy after r-adaptivity: " << tmopenergy <<
680 ", Elements: " << NEGlob << std::endl;
698 mfem::out <<
"TMOP energy after derefinement: " << tmopenergy <<
699 ", Elements: " << NEGlob << std::endl;
709 mfem::out <<
"TMOP energy after refinement: " << tmopenergy <<
710 ", Elements: " << NEGlob << std::endl;
718 mfem::out <<
"AMR stopping criterion satisfied. Stop.\n";
736 for (
int i = 0; i < dreftable.
Size(); i++)
766 for (
int i = 0; i < integs.
Size(); i++)
779 for (
int j = 0; j < ati.
Size(); j++)
781 ati[j]->UpdateAfterMeshTopologyChange();
782 dtc = ati[j]->GetDiscreteAdaptTC();
813 for (
int i = 0; i < integs.
Size(); i++)
826 for (
int j = 0; j < ati.
Size(); j++)
828 ati[j]->ParUpdateAfterMeshTopologyChange();
829 dtc = ati[j]->GetDiscreteAdaptTC();
857 for (
int i = 0; i < mesh_->
GetNBE(); i++)
860 MFEM_VERIFY(!(dim == 2 && attr == 3),
861 "Boundary attribute 3 must be used only for 3D meshes. "
862 "Adjust the attributes (1/2/3/4 for fixed x/y/z/all "
863 "components, rest for free nodes), or use -fix-bnd.");
864 if (attr == 1 || attr == 2 || attr == 3) { n += nd; }
865 if (attr == 4) { n += nd *
dim; }
869 for (
int i = 0; i < mesh_->
GetNBE(); i++)
875 for (
int j = 0; j < nd; j++)
876 { ess_vdofs[n++] = vdofs[j]; }
880 for (
int j = 0; j < nd; j++)
881 { ess_vdofs[n++] = vdofs[j+nd]; }
885 for (
int j = 0; j < nd; j++)
886 { ess_vdofs[n++] = vdofs[j+2*nd]; }
890 for (
int j = 0; j < vdofs.
Size(); j++)
891 { ess_vdofs[n++] = vdofs[j]; }
Abstract class for all finite elements.
virtual double GetDerefinementElementEnergy(const FiniteElement &el, ElementTransformation &T, const Vector &elfun)
int Size() const
Return the logical size of the array.
ThresholdRefiner * tmop_r
int GetDim() const
Returns the reference space dimension for the finite element.
Class for an integration rule - an Array of IntegrationPoint.
void GetElementAverages(GridFunction &avgs) const
void GetVectorValues(int i, const IntegrationRule &ir, DenseMatrix &vals, DenseMatrix &tr) const
Class for grid function - Vector with associated FE space.
const CoarseFineTransformations & GetDerefinementTransforms()
virtual void Update(bool want_transform=true)
Reflect changes in the mesh: update number of DOFs, etc. Also, calculate GridFunction transformation ...
void GetTMOPRefinementEnergy(int reftype, Vector &el_energy_vec)
void SetFromTrueVector()
Shortcut for calling SetFromTrueDofs() with GetTrueVector() as argument.
virtual void SetOperator(const Operator &op)
Also calls SetOperator for the preconditioner if there is one.
void SetSize(int s)
Resize the vector to size s.
int GetNBE() const
Returns number of boundary elements.
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)
virtual void Update(bool want_transform=true)
void ParUpdateAfterMeshTopologyChange()
void GetSubVector(const Array< int > &dofs, Vector &elemvect) const
Extract entries listed in dofs to the output Vector elemvect.
int AddTriangle(int v1, int v2, int v3, int attr=1)
Data type dense matrix using column-major storage.
void GetRow(int i, Array< int > &row) const
Return row i in array row (the Table must be finalized)
int GetNE() const
Returns number of elements.
bool Stop() const
Check if STOP action is requested, e.g. stopping criterion is satisfied.
Abstract parallel finite element space.
TMOPHRSolver(Mesh &mesh_, NonlinearForm &nlf_, TMOPNewtonSolver &tmopns_, GridFunction &x_, bool move_bnd_, bool hradaptivity_, int mesh_poly_deg_, int amr_metric_id_, int hr_iter_=5, int h_per_r_iter_=1)
bool GetConverged() const
double * GetData() const
Returns the matrix data array.
A parallel extension of the NCMesh class.
DofTransformation * GetBdrElementVDofs(int i, Array< int > &vdofs) const
Returns indexes of degrees of freedom for i'th boundary element.
Array< FiniteElementSpace * > fespacearr
Geometry::Type GetGeomType() const
Returns the Geometry::Type of the reference element.
int GetNE() const
Returns number of elements in the mesh.
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
bool Apply(Mesh &mesh)
Perform the mesh operation.
int AddVertex(double x, double y=0.0, double z=0.0)
void SetTrueVector()
Shortcut for calling GetTrueDofs() with GetTrueVector() as argument.
DofTransformation * GetElementVDofs(int i, Array< int > &vdofs) const
Returns indexes of degrees of freedom in array dofs for i'th element.
void FinalizeTriMesh(int generate_edges=0, int refine=0, bool fix_orientation=true)
Finalize the construction of a triangular Mesh.
void SetEnergyScalingFactor(double scale)
const Table & GetDerefinementTable()
virtual void Reset()
Reset the associated estimator.
void FinalizeTetMesh(int generate_edges=0, int refine=0, bool fix_orientation=true)
Finalize the construction of a tetrahedral Mesh.
int Append(const T &el)
Append element 'el' to array, resize if necessary.
virtual void GetFineToCoarsePartitioning(const Array< int > &derefs, Array< int > &new_ranks) const
Mesh * GetMesh() const
Returns the mesh.
int AddTet(int v1, int v2, int v3, int v4, int attr=1)
virtual void Reset()
Reset the associated estimator.
ThresholdDerefiner * tmop_dr
Mesh refinement operator using an error threshold.
Array< ParGridFunction * > pgridfuncarr
Array< IntegrationRule * > QuadIntRule
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
int GetAttribute() const
Return element's attribute.
void Set2(const double x1, const double x2)
virtual void SetNodalFESpace(FiniteElementSpace *nfes)
int Size() const
Returns the number of TYPE I elements.
Array< IntegrationRule * > TetIntRule
void GetTMOPDerefinementEnergy(Mesh &cmesh, TMOP_Integrator &tmopi, Vector &el_energy_vec)
FiniteElementSpace * FESpace()
const Vector & GetTrueVector() const
Read only access to the (optional) internal true-dof Vector.
virtual double GetRefinementElementEnergy(const FiniteElement &el, ElementTransformation &T, const Vector &elfun, const IntegrationRule &irule)
Computes the mean of the energies of the given element's children.
void Set3(const double x1, const double x2, const double x3)
bool Derefined() const
Check if the mesh was de-refined.
double * Data() const
Returns the matrix data array.
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
void AddGridFunctionForUpdate(GridFunction *gf)
FiniteElementSpace * GetTSpecFESpace()
Get the FESpace associated with tspec.
Array< GridFunction * > gridfuncarr
void Transpose()
(*this) = (*this)^t
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
int GetDof() const
Returns the number of degrees of freedom in the finite element.
int NumRows() const
Get the number of rows (size of output) of the Operator. Synonym with Height().
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
int NumCols() const
Get the number of columns (size of input) of the Operator. Synonym with Width().
void RebalanceParNCMesh()
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)
TMOPRefinerEstimator * tmop_r_est
DiscreteAdaptTC * GetDiscreteAdaptTC() const
Array< IntegrationRule * > HexIntRule
void UpdateAfterMeshTopologyChange()
double energy_scaling_factor
void GetElementTransformation(int i, IsoparametricTransformation *ElTr)
const FiniteElementSpace * GetNodalFESpace() const
bool DerefineByError(Array< double > &elem_error, double threshold, int nc_limit=0, int op=1)
long long GetGlobalNE() const
Return the total (global) number of elements.
IntegrationRule * SetIntRulesFromMesh(Mesh &meshsplit)
void ParUpdateAfterMeshTopologyChange()
TMOPDeRefinerEstimator * tmop_dr_est
virtual const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th element in t...
ParFiniteElementSpace * GetTSpecParFESpace()
Array< IntegrationRule * > TriIntRule
NCMesh * ncmesh
Optional nonconforming mesh extension.
Array< ParFiniteElementSpace * > pfespacearr
void Clear()
Clear the contents of the Mesh.
void UpdateNonlinearFormAndBC(Mesh *mesh, NonlinearForm *nlf)
virtual void Mult(const Vector &b, Vector &x) const
Solve the nonlinear system with right-hand side b.
void GetNodes(Vector &node_coord) const
void SetTspecDataForDerefinement(FiniteElementSpace *fes)
Computes target specification data with respect to the coarse FE space.
Arbitrary order H1-conforming (continuous) finite elements.
Class for parallel grid function.
const FiniteElement * GetBE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th boundary fac...
void SetTotalErrorFraction(double fraction)
Set the total fraction used in the computation of the threshold. The default value is 1/2...
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
void GeneralRefinement(const Array< Refinement > &refinements, int nonconforming=-1, int nc_limit=0)
Class for parallel meshes.
const Array< TMOP_Integrator * > & GetTMOPIntegrators() const
TMOPNewtonSolver * tmopns
void UpdateAfterMeshTopologyChange()
Update all discrete fields based on tspec and update for AMR.
void ResetDerefinementTspecData()
const Element * GetBdrElement(int i) const
bool GetDerefineEnergyForIntegrator(TMOP_Integrator &tmopi, Vector &fine_energy)
Arbitrary order "L2-conforming" discontinuous finite elements.
De-refinement operator using an error threshold.
A TMOP integrator class based on any given TMOP_QualityMetric and TargetConstructor.