Hermes2D  3.0
adapt.h
1 // This file is part of Hermes2D.
2 //
3 // Hermes2D is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // Hermes2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Hermes2D. If not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef __H2D_ADAPT_H
17 #define __H2D_ADAPT_H
18 
19 #include "../space/space.h"
20 #include "error_calculator.h"
21 #include "../refinement_selectors/selector.h"
22 #include "exceptions.h"
23 
24 namespace Hermes
25 {
26  namespace Hermes2D
27  {
28  template<typename Scalar> class ErrorCalculator;
29 
44  template<typename Scalar>
50  {
51  public:
55  virtual bool add_refinement(ErrorCalculator<Scalar>* error_calculator, double processed_error_squared, double max_error_squared, int element_inspected_i) = 0;
56  };
57 
61  template<typename Scalar>
63  {
64  public:
66  AdaptStoppingCriterionCumulative(double threshold);
67 
71  bool add_refinement(ErrorCalculator<Scalar>* error_calculator, double processed_error_squared, double max_error_squared, int element_inspected_i);
72  private:
75  double threshold;
76  };
77 
81  template<typename Scalar>
83  {
84  public:
86  AdaptStoppingCriterionSingleElement(double threshold);
87 
89  bool add_refinement(ErrorCalculator<Scalar>* error_calculator, double processed_error_squared, double max_error_squared, int element_inspected_i);
90  private:
93  double threshold;
94  };
95 
99  template<typename Scalar>
100  class HERMES_API AdaptStoppingCriterionLevels : public AdaptivityStoppingCriterion < Scalar >
101  {
102  public:
104  AdaptStoppingCriterionLevels(double threshold);
105 
107  bool add_refinement(ErrorCalculator<Scalar>* error_calculator, double processed_error_squared, double max_error_squared, int element_inspected_i);
108  private:
111  double threshold;
112  };
113 
116 
121  template<typename Scalar>
122  class HERMES_API Adapt :
123  public Hermes::Mixins::TimeMeasurable,
124  public Hermes::Mixins::Loggable,
125  public Hermes::Mixins::StateQueryable,
127  {
128  public:
131  Adapt(std::vector<SpaceSharedPtr<Scalar> > spaces, ErrorCalculator<Scalar>* error_calculator, AdaptivityStoppingCriterion<Scalar>* strategy = nullptr);
132  Adapt(SpaceSharedPtr<Scalar> space, ErrorCalculator<Scalar>* error_calculator, AdaptivityStoppingCriterion<Scalar>* strategy = nullptr);
133  Adapt(ErrorCalculator<Scalar>* error_calculator, AdaptivityStoppingCriterion<Scalar>* strategy = nullptr);
135  virtual ~Adapt();
137  void free();
138 
140 
143  bool adapt(std::vector<RefinementSelectors::Selector<Scalar>*> refinement_selectors);
144 
146 
149  bool adapt(RefinementSelectors::Selector<Scalar>* refinement_selector);
150 
153  void set_strategy(AdaptivityStoppingCriterion<Scalar>* strategy);
154 
157  void set_regularization_level(int regularization);
158 
160  virtual bool isOkay() const;
161  inline std::string getClassName() const { return "Adapt"; }
162 
164  void set_spaces(std::vector<SpaceSharedPtr<Scalar> > spaces);
165  void set_space(SpaceSharedPtr<Scalar> space);
166 
169  MeshFunctionSharedPtr<double> get_refinementInfoMeshFunction(int component = -1);
170  protected:
172  void set_defaults();
173 
175  void init_adapt(std::vector<RefinementSelectors::Selector<Scalar>*>& refinement_selectors, ElementToRefine*** element_refinement_location, MeshSharedPtr* meshes);
177  int calculate_attempted_element_refinements_count();
179  void adapt_postprocess(MeshSharedPtr* meshes, int element_refinements_count);
181  void deinit_adapt(ElementToRefine*** element_refinement_location);
182 
184  void init();
185 
188 
190 
191  void apply_refinement(const ElementToRefine& elem_ref);
192 
194 
195  virtual void apply_refinements(ElementToRefine* elems_to_refine, int num_elem_to_process);
196 
198 
204  void fix_shared_mesh_refinements(MeshSharedPtr * meshes, ElementToRefine*& elems_to_refine, int& num_elem_to_process, ElementToRefine*** refinement_location, RefinementSelectors::Selector<Scalar>** refinement_selectors);
205 
207 
208  void homogenize_shared_mesh_orders(MeshSharedPtr * meshes);
209 
211  int num;
212 
215 
217  std::vector<MeshSharedPtr> meshes;
219  std::vector<SpaceSharedPtr<Scalar> > spaces;
220 
223 
226  int elements_to_refine_count;
227 
229  MeshFunctionSharedPtr<double> refinementInfoMeshFunction[H2D_MAX_COMPONENTS];
232  template<typename T, typename S> friend class AdaptSolver;
233  };
234  }
235 }
236 #endif
Definition: adapt.h:24
Class utilizes parallel calculation.
Definition: mixins2d.h:37
ElementToRefine * elements_to_refine
Information about performed refinements.
Definition: adapt.h:225
AdaptivityStoppingCriterion< Scalar > * strategy
Current strategy.
Definition: adapt.h:187
Used to pass the instances of Space around.
Definition: space.h:34
std::vector< MeshSharedPtr > meshes
Meshes.
Definition: adapt.h:217
std::vector< SpaceSharedPtr< Scalar > > spaces
Spaces.
Definition: adapt.h:219
ErrorCalculator< Scalar > * errorCalculator
Error calculator.
Definition: adapt.h:222
Evaluation of an error between a (coarse) solution and a reference solution.
Definition: adapt.h:28
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.
A parent of all refinement selectors. Abstract class.
Definition: function.h:29
int num
Number of solution components (as in wf->neq).
Definition: adapt.h:211
virtual bool add_refinement(ErrorCalculator< Scalar > *error_calculator, double processed_error_squared, double max_error_squared, int element_inspected_i)=0
MeshFunctionSharedPtr< double > refinementInfoMeshFunctionGlobal
Mesh function for postprocessing the information about which elements have been refined - for the who...
Definition: adapt.h:231
int regularization
Regularization (max. level of hanging nodes) level.
Definition: adapt.h:214