MFEM  v3.2
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
mesh_operators.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 #ifndef MFEM_MESH_OPERATORS
13 #define MFEM_MESH_OPERATORS
14 
15 #include "../config/config.hpp"
16 #include "../general/array.hpp"
17 #include "mesh.hpp"
18 #include "../fem/estimators.hpp"
19 
20 #include <limits>
21 
22 namespace mfem
23 {
24 
47 {
48 private:
49  int mod;
50 
51 protected:
52  friend class MeshOperatorSequence;
53 
57  virtual int ApplyImpl(Mesh &mesh) = 0;
58 
60  MeshOperator() : mod(NONE) { }
61 
62 public:
69  enum Action
70  {
71  NONE = 0,
73  CONTINUE = 1,
75  STOP = 2,
76  REPEAT = 3,
80  };
81 
82  enum Info
83  {
84  REFINED = 4*1,
85  DEREFINED = 4*2,
86  REBALANCED = 4*3,
87  MASK_INFO = ~3
88  };
89 
93  bool Apply(Mesh &mesh) { return ((mod = ApplyImpl(mesh)) & MASK_UPDATE); }
94 
97  bool Stop() const { return ((mod & MASK_ACTION) == STOP); }
100  bool Repeat() const { return ((mod & MASK_ACTION) == REPEAT); }
103  bool Continue() const { return ((mod & MASK_ACTION) == CONTINUE); }
104 
106  bool Refined() const { return ((mod & MASK_INFO) == REFINED); }
108  bool Derefined() const { return ((mod & MASK_INFO) == DEREFINED); }
110  bool Rebalanced() const { return ((mod & MASK_INFO) == REBALANCED); }
111 
114  int GetActionInfo() const { return mod; }
115 
117  virtual void Reset() = 0;
118 
120  virtual ~MeshOperator() { }
121 };
122 
123 
127 {
128 protected:
129  int step;
131 
134 
138  virtual int ApplyImpl(Mesh &mesh);
139 
140 public:
143 
145  virtual ~MeshOperatorSequence();
146 
149  void Append(MeshOperator *mc) { sequence.Append(mc); }
150 
153 
155  virtual void Reset();
156 };
157 
158 
173 {
174 protected:
177 
178  double total_norm_p;
183 
184  double threshold;
186 
189 
191  int nc_limit;
192 
193  double GetNorm(const Vector &local_err, Mesh &mesh) const;
194 
198  virtual int ApplyImpl(Mesh &mesh);
199 
200 public:
203 
204  // default destructor (virtual)
205 
208  void SetTotalErrorNormP(double norm_p =
209  std::numeric_limits<double>::infinity())
210  { total_norm_p = norm_p; }
211 
214  void SetTotalErrorGoal(double err_goal) { total_err_goal = err_goal; }
215 
220  void SetTotalErrorFraction(double fraction) { total_fraction = fraction; }
221 
226  void SetLocalErrorGoal(double err_goal) { local_err_goal = err_goal; }
227 
231  void SetMaxElements(long max_elem) { max_elements = max_elem; }
232 
235 
239 
243  {
244  MFEM_ASSERT(nc_limit >= 0, "Invalid NC limit");
245  this->nc_limit = nc_limit;
246  }
247 
249  long GetNumMarkedElements() const { return num_marked_elements; }
250 
252  double GetThreshold() const { return threshold; }
253 
255  virtual void Reset();
256 };
257 
258 // TODO: BulkRefiner to refine a portion of the global error
259 
260 
270 {
271 protected:
273 
274  double threshold;
275  int nc_limit, op;
276 
280  virtual int ApplyImpl(Mesh &mesh);
281 
282 public:
285  : estimator(est)
286  {
287  threshold = 0.0;
288  nc_limit = 0;
289  op = 1;
290  }
291 
292  // default destructor (virtual)
293 
295  void SetThreshold(double thresh) { threshold = thresh; }
296 
297  void SetOp(int op) { this->op = op; }
298 
302  {
303  MFEM_ASSERT(nc_limit >= 0, "Invalid NC limit");
304  this->nc_limit = nc_limit;
305  }
306 
308  virtual void Reset() { estimator.Reset(); }
309 };
310 
311 
316 class Rebalancer : public MeshOperator
317 {
318 protected:
322  virtual int ApplyImpl(Mesh &mesh);
323 
324 public:
326  virtual void Reset() { }
327 };
328 
329 } // namespace mfem
330 
331 #endif // MFEM_MESH_OPERATORS
bool Continue() const
Check if CONTINUE action is requested, i.e. FiniteElementSpaces and GridFunctions need to be updated ...
MeshOperatorSequence(const MeshOperatorSequence &)
Do not allow copy construction, due to assumed ownership.
virtual void Reset()=0
Reset the MeshOperator.
bool Repeat() const
Check if REPEAT action is requested, i.e. FiniteElementSpaces and GridFunctions need to be updated...
virtual int ApplyImpl(Mesh &mesh)
Apply the operator to the mesh.
the mesh was refined
Action
Action and information constants and masks.
void SetNCLimit(int nc_limit)
Set the maximum ratio of refinement levels of adjacent elements (0 = unlimited).
bool Stop() const
Check if STOP action is requested, e.g. stopping criterion is satisfied.
void PreferNonconformingRefinement()
Use nonconforming refinement, if possible (triangles, quads, hexes).
double GetNorm(const Vector &local_err, Mesh &mesh) const
the mesh was de-refined
virtual int ApplyImpl(Mesh &mesh)
Apply the operator to the mesh.
int GetActionInfo() const
Get the full ActionInfo value generated by the last call to Apply().
virtual void Reset()
Reset all MeshOperators in the sequence.
virtual int ApplyImpl(Mesh &mesh)
Apply the MeshOperatorSequence.
bit mask for all &quot;action&quot; bits
long GetNumMarkedElements() const
Get the number of marked elements in the last Apply() call.
bool Apply(Mesh &mesh)
Perform the mesh operation.
virtual void Reset()
Reset the associated estimator.
void SetTotalErrorNormP(double norm_p=std::numeric_limits< double >::infinity())
Set the exponent, p, of the discrete p-norm used to compute the total error from the local element er...
bit mask for the &quot;update&quot; bit
virtual void Reset()
Reset the associated estimator.
Mesh refinement operator using an error threshold.
MeshOperator()
Constructor to be used by derived classes.
virtual int ApplyImpl(Mesh &mesh)
Rebalance a parallel mesh (only non-conforming parallel meshes are supported).
bit mask for all &quot;info&quot; bits
Base class for all element based error estimators.
Definition: estimators.hpp:39
Array< Refinement > marked_elements
ErrorEstimator & estimator
virtual void Reset()=0
Force recomputation of the estimates on the next call to GetLocalErrors.
void SetNCLimit(int nc_limit)
Set the maximum ratio of refinement levels of adjacent elements (0 = unlimited).
bool Derefined() const
Check if the mesh was de-refined.
void SetTotalErrorGoal(double err_goal)
Set the total error stopping criterion: stop when total_err &lt;= total_err_goal. The default value is z...
virtual ~MeshOperator()
The destructor is virtual.
The MeshOperator class serves as base for mesh manipulation classes.
void PreferConformingRefinement()
Use conforming refinement, if possible (triangles, tetrahedra) – this is the default.
virtual ~MeshOperatorSequence()
Delete all operators from the sequence.
a stopping criterion was satisfied
ThresholdDerefiner(ErrorEstimator &est)
Construct a ThresholdDerefiner using the given ErrorEstimator.
AnisotropicErrorEstimator * aniso_estimator
ErrorEstimator & estimator
the mesh was rebalanced
void Append(MeshOperator *mc)
Add an operator to the end of the sequence. The MeshOperatorSequence assumes ownership of the operato...
void SetMaxElements(long max_elem)
Set the maximum number of elements stopping criterion: stop when the input mesh has num_elements &gt;= m...
bool Refined() const
Check if the mesh was refined.
Array< MeshOperator * > & GetSequence()
Access the underlying sequence.
MeshOperatorSequence()
Constructor. Use the Append() method to create the sequence.
The AnisotropicErrorEstimator class is the base class for all error estimators that compute one non-n...
Definition: estimators.hpp:56
double GetThreshold() const
Get the threshold used in the last Apply() call.
void SetThreshold(double thresh)
Set the de-refinement threshold. The default value is zero.
bool Rebalanced() const
Check if the mesh was rebalanced.
void SetLocalErrorGoal(double err_goal)
Set the local stopping criterion: stop when local_err_i &lt;= local_err_goal. The default value is zero...
Vector data type.
Definition: vector.hpp:33
ThresholdRefiner(ErrorEstimator &est)
Construct a ThresholdRefiner using the given ErrorEstimator.
void SetTotalErrorFraction(double fraction)
Set the total fraction used in the computation of the threshold. The default value is 1/2...
virtual void Reset()
Empty.
Array< MeshOperator * > sequence
MeshOperators sequence, owned by us.
virtual int ApplyImpl(Mesh &mesh)=0
Implementation of the mesh operation. Invoked by the Apply() public method.
ParMesh rebalancing operator.
De-refinement operator using an error threshold.