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_)
606 bool radaptivity =
true;
613 for (
int i_hr = 0; i_hr <
hr_iter; i_hr++)
619 mfem::out << i_hr <<
" r-adaptivity iteration.\n";
625 mfem::out <<
"TMOP energy after r-adaptivity: " <<
627 ", Elements: " <<
mesh->
GetNE() << std::endl;
637 mfem::out <<
"TMOP energy after derefinement: " <<
639 ", Elements: " <<
mesh->
GetNE() << std::endl;
644 mfem::out <<
"TMOP energy after refinement: " <<
646 ", Elements: " <<
mesh->
GetNE() << std::endl;
651 mfem::out <<
"AMR stopping criterion satisfied. Stop.\n";
662 for (
int i_hr = 0; i_hr <
hr_iter; i_hr++)
668 if (myid == 0) {
mfem::out << i_hr <<
" r-adaptivity iteration.\n"; }
677 mfem::out <<
"TMOP energy after r-adaptivity: " << tmopenergy <<
678 ", Elements: " << NEGlob << std::endl;
696 mfem::out <<
"TMOP energy after derefinement: " << tmopenergy <<
697 ", Elements: " << NEGlob << std::endl;
707 mfem::out <<
"TMOP energy after refinement: " << tmopenergy <<
708 ", Elements: " << NEGlob << std::endl;
716 mfem::out <<
"AMR stopping criterion satisfied. Stop.\n";
734 for (
int i = 0; i < dreftable.
Size(); i++)
764 for (
int i = 0; i < integs.
Size(); i++)
777 for (
int j = 0; j < ati.
Size(); j++)
779 ati[j]->UpdateAfterMeshTopologyChange();
780 dtc = ati[j]->GetDiscreteAdaptTC();
811 for (
int i = 0; i < integs.
Size(); i++)
824 for (
int j = 0; j < ati.
Size(); j++)
826 ati[j]->ParUpdateAfterMeshTopologyChange();
827 dtc = ati[j]->GetDiscreteAdaptTC();
855 for (
int i = 0; i < mesh_->
GetNBE(); i++)
858 MFEM_VERIFY(!(
dim == 2 && attr == 3),
859 "Boundary attribute 3 must be used only for 3D meshes. " 860 "Adjust the attributes (1/2/3/4 for fixed x/y/z/all " 861 "components, rest for free nodes), or use -fix-bnd.");
862 if (attr == 1 || attr == 2 || attr == 3) { n += nd; }
863 if (attr == 4) { n += nd *
dim; }
867 for (
int i = 0; i < mesh_->
GetNBE(); i++)
873 for (
int j = 0; j < nd; j++)
874 { ess_vdofs[n++] = vdofs[j]; }
878 for (
int j = 0; j < nd; j++)
879 { ess_vdofs[n++] = vdofs[j+nd]; }
883 for (
int j = 0; j < nd; j++)
884 { ess_vdofs[n++] = vdofs[j+2*nd]; }
888 for (
int j = 0; j < vdofs.
Size(); j++)
889 { ess_vdofs[n++] = vdofs[j]; }
Abstract class for all finite elements.
void GetFineToCoarsePartitioning(const Array< int > &derefs, Array< int > &new_ranks) const
virtual double GetDerefinementElementEnergy(const FiniteElement &el, ElementTransformation &T, const Vector &elfun)
ThresholdRefiner * tmop_r
bool Derefined() const
Check if the mesh was de-refined.
Class for an integration rule - an Array of IntegrationPoint.
const FiniteElementSpace * GetNodalFESpace() 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.
int Dimension() const
Dimension of the reference space used within the elements.
void SetSize(int s)
Resize the vector to size s.
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)
const Array< TMOP_Integrator * > & GetTMOPIntegrators() const
virtual void Update(bool want_transform=true)
void ParUpdateAfterMeshTopologyChange()
DiscreteAdaptTC * GetDiscreteAdaptTC() const
int GetAttribute() const
Return element's attribute.
int AddTriangle(int v1, int v2, int v3, int attr=1)
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
void GetElementAverages(GridFunction &avgs) const
Data type dense matrix using column-major storage.
double * Data() const
Returns the matrix data array.
int NumRows() const
Get the number of rows (size of output) of the Operator. Synonym with Height().
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)
void GetSubVector(const Array< int > &dofs, Vector &elemvect) const
Extract entries listed in dofs to the output Vector elemvect.
int GetNBE() const
Returns number of boundary elements.
virtual const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th element in t...
A parallel extension of the NCMesh class.
Array< FiniteElementSpace * > fespacearr
Geometry::Type GetGeomType() const
Returns the Geometry::Type of the reference element.
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.
long long GetGlobalNE() const
Return the total (global) number of elements.
void FinalizeTriMesh(int generate_edges=0, int refine=0, bool fix_orientation=true)
Finalize the construction of a triangular Mesh.
double * GetData() const
Returns the matrix data array.
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.
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
void Set2(const double x1, const double x2)
virtual void SetNodalFESpace(FiniteElementSpace *nfes)
Array< IntegrationRule * > TetIntRule
void GetTMOPDerefinementEnergy(Mesh &cmesh, TMOP_Integrator &tmopi, Vector &el_energy_vec)
FiniteElementSpace * FESpace()
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 in the mesh.
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.
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 ...
void Set3(const double x1, const double x2, const double x3)
Mesh * GetMesh() const
Returns the mesh.
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
int GetDim() const
Returns the reference space dimension for the finite element.
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
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
int GetDof() const
Returns the number of degrees of freedom in the finite element.
int NumCols() const
Get the number of columns (size of input) of the Operator. Synonym with Width().
const Vector & GetTrueVector() const
Read only access to the (optional) internal true-dof Vector.
Array< IntegrationRule * > HexIntRule
void UpdateAfterMeshTopologyChange()
int GetNE() const
Returns number of elements.
double energy_scaling_factor
void GetElementTransformation(int i, IsoparametricTransformation *ElTr)
int Size() const
Returns the number of TYPE I elements.
DofTransformation * GetBdrElementVDofs(int i, Array< int > &vdofs) const
Returns indices of degrees of freedom for i'th boundary element. The returned indices are offsets int...
bool DerefineByError(Array< double > &elem_error, double threshold, int nc_limit=0, int op=1)
IntegrationRule * SetIntRulesFromMesh(Mesh &meshsplit)
void ParUpdateAfterMeshTopologyChange()
TMOPDeRefinerEstimator * tmop_dr_est
ParFiniteElementSpace * GetTSpecParFESpace()
Array< IntegrationRule * > TriIntRule
NCMesh * ncmesh
Optional nonconforming mesh extension.
Array< ParFiniteElementSpace * > pfespacearr
void GetVectorValues(int i, const IntegrationRule &ir, DenseMatrix &vals, DenseMatrix &tr) const
int Size() const
Return the logical size of the array.
void Clear()
Clear the contents of the Mesh.
void UpdateNonlinearFormAndBC(Mesh *mesh, NonlinearForm *nlf)
void SetTspecDataForDerefinement(FiniteElementSpace *fes)
Computes target specification data with respect to the coarse FE space.
Arbitrary order H1-conforming (continuous) finite elements.
void GetNodes(Vector &node_coord) const
const Element * GetBdrElement(int i) const
Return pointer to the i'th boundary element object.
Class for parallel grid function.
void SetTotalErrorFraction(double fraction)
Set the total fraction used in the computation of the threshold. The default value is 1/2...
bool Stop() const
Check if STOP action is requested, e.g. stopping criterion is satisfied.
void GeneralRefinement(const Array< Refinement > &refinements, int nonconforming=-1, int nc_limit=0)
Class for parallel meshes.
virtual void Mult(const Vector &b, Vector &x) const
Solve the nonlinear system with right-hand side b.
const FiniteElement * GetBE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th boundary fac...
TMOPNewtonSolver * tmopns
void UpdateAfterMeshTopologyChange()
Update all discrete fields based on tspec and update for AMR.
void ResetDerefinementTspecData()
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.