Hermes2D  3.0
filter.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_FILTER_H
17 #define __H2D_FILTER_H
18 
19 #include "solution.h"
20 #include <complex>
21 
22 namespace Hermes
23 {
24  namespace Hermes2D
25  {
26  struct UniData;
27 
34  template<typename Scalar>
35  class HERMES_API Filter : public MeshFunction < Scalar >
36  {
37  public:
38  Filter();
39  Filter(std::vector<MeshFunctionSharedPtr<Scalar> > solutions);
40 
41  virtual ~Filter();
42 
43  virtual void reinit();
44 
45  inline SpaceType get_space_type() const { return space_type; };
46 
48  inline std::string getClassName() const { return "Filter"; }
49 
50  protected:
51  virtual void set_quad_2d(Quad2D* quad_2d);
52 
53  virtual void set_active_element(Element* e);
54 
55  virtual void free();
56 
57  virtual void push_transform(int son);
58 
59  virtual void pop_transform();
60 
61  virtual void init();
62 
63  std::vector<MeshFunctionSharedPtr<Scalar> > solutions;
64 
65  std::vector<uint64_t> solutions_sub_idx;
66 
67  bool unimesh;
68 
69  SpaceType space_type;
70 
71  UniData** unidata;
72 
73  void copy_base(Filter* flt);
74  };
75 
91  template<typename Scalar>
92  class HERMES_API SimpleFilter : public Filter < Scalar >
93  {
94  public:
95  SimpleFilter();
96  virtual ~SimpleFilter();
97 
98  SimpleFilter(std::vector<MeshFunctionSharedPtr<Scalar> > solutions, std::vector<int> items = std::vector<int>());
99 
100  virtual Func<Scalar>* get_pt_value(double x, double y, bool use_MeshHashGrid = false, Element* e = nullptr);
101 
102  protected:
103  std::vector<int> items;
104 
105  virtual void filter_fn(int n, const std::vector<const Scalar*>& values, Scalar* result) = 0;
106 
107  void init_components();
108  virtual void precalculate(unsigned short order, unsigned short mask);
109  };
110 
113  class HERMES_API ComplexFilter : public Filter < double >
114  {
115  public:
116  ComplexFilter();
117  ComplexFilter(MeshFunctionSharedPtr<std::complex<double> > solution, int item = H2D_FN_VAL_0);
118 
119  virtual ~ComplexFilter();
120  protected:
121  virtual Func<double>* get_pt_value(double x, double y, bool use_MeshHashGrid = false, Element* e = nullptr);
122 
123  virtual void set_quad_2d(Quad2D* quad_2d);
124 
125  virtual void set_active_element(Element* e);
126 
127  virtual void push_transform(int son);
128 
129  virtual void pop_transform();
130 
131  virtual void free();
132 
134 
135  int item;
136 
137  virtual void filter_fn(int n, const std::complex<double>* values, double* result) = 0;
138 
139  virtual void precalculate(unsigned short order, unsigned short mask);
140  };
141 
147  template<typename Scalar>
148  class HERMES_API DXDYFilter : public Filter < Scalar >
149  {
150  public:
151  // one result (rslt), all inputs and result including derivatives
152  DXDYFilter();
153 
154  DXDYFilter(std::vector<MeshFunctionSharedPtr<Scalar> > solutions);
155 
156  virtual ~DXDYFilter();
157  protected:
158  void init(std::vector<MeshFunctionSharedPtr<Scalar> > solutions);
159 
160  virtual Func<Scalar>* get_pt_value(double x, double y, bool use_MeshHashGrid = false, Element* e = nullptr);
161 
162  virtual void filter_fn(int n, double* x, double* y, const std::vector<const Scalar *>& values, const std::vector<const Scalar *>& dx, const std::vector<const Scalar *>& dy, Scalar* rslt, Scalar* rslt_dx, Scalar* rslt_dy) = 0;
163 
164  void init_components();
165 
166  virtual void precalculate(unsigned short order, unsigned short mask);
167  };
168 
172  template<typename Scalar>
173  class HERMES_API MagFilter : public SimpleFilter < Scalar >
174  {
175  public:
176  MagFilter(std::vector<MeshFunctionSharedPtr<Scalar> > solutions, std::vector<int> items = std::vector<int>());
177 
180  virtual MeshFunction<Scalar>* clone() const;
181 
182  virtual ~MagFilter();
183  protected:
184  virtual void filter_fn(int n, const std::vector<const Scalar*>& values, Scalar* result);
185  };
186 
188  class HERMES_API TopValFilter : public SimpleFilter < double >
189  {
190  public:
191  TopValFilter(std::vector<MeshFunctionSharedPtr<double> > solutions, std::vector<double> limits, std::vector<int> items = *(new std::vector<int>));
192 
194  TopValFilter(MeshFunctionSharedPtr<double> sln, double limit, int item = H2D_FN_VAL_0);
195  virtual MeshFunction<double>* clone() const;
196 
197  virtual ~TopValFilter();
198  protected:
199  virtual void filter_fn(int n, const std::vector<const double*>& values, double* result);
200  std::vector<double> limits;
201  };
202 
204  class HERMES_API BottomValFilter : public SimpleFilter < double >
205  {
206  public:
207  BottomValFilter(std::vector<MeshFunctionSharedPtr<double> > solutions, std::vector<double> limits, std::vector<int> items = *(new std::vector<int>));
208 
210  BottomValFilter(MeshFunctionSharedPtr<double> sln, double limit, int item = H2D_FN_VAL_0);
211  virtual MeshFunction<double>* clone() const;
212 
213  virtual ~BottomValFilter();
214  protected:
215  virtual void filter_fn(int n, const std::vector<const double*>& values, double* result);
216  std::vector<double> limits;
217  };
218 
220  class HERMES_API ValFilter : public SimpleFilter < double >
221  {
222  public:
223  ValFilter(std::vector<MeshFunctionSharedPtr<double> > solutions, std::vector<double> low_limits, std::vector<double> high_limits, std::vector<int> items = *(new std::vector<int>));
224 
226  ValFilter(MeshFunctionSharedPtr<double> sln, double low_limit, double high_limit, int item = H2D_FN_VAL_0);
227  virtual MeshFunction<double>* clone() const;
228 
229  virtual ~ValFilter();
230  protected:
231  virtual void filter_fn(int n, const std::vector<const double*>& values, double* result);
232  std::vector<double> low_limits;
233  std::vector<double> high_limits;
234  };
235 
237  template<typename Scalar>
238  class HERMES_API DiffFilter : public SimpleFilter < Scalar >
239  {
240  public:
241  DiffFilter(std::vector<MeshFunctionSharedPtr<Scalar> > solutions, std::vector<int> items = *(new std::vector<int>));
242  virtual MeshFunction<Scalar>* clone() const;
243  virtual ~DiffFilter();
244 
245  protected:
246  virtual void filter_fn(int n, const std::vector<const Scalar*>& values, Scalar* result);
247  };
248 
250  template<typename Scalar>
251  class HERMES_API SumFilter : public SimpleFilter < Scalar >
252  {
253  public:
254  SumFilter(std::vector<MeshFunctionSharedPtr<Scalar> > solutions, std::vector<int> items = *(new std::vector<int>));
255  virtual MeshFunction<Scalar>* clone() const;
256  virtual ~SumFilter();
257 
258  protected:
259  virtual void filter_fn(int n, const std::vector<const Scalar*>& values, Scalar* result);
260  };
261 
263  template<typename Scalar>
264  class HERMES_API SquareFilter : public SimpleFilter < Scalar >
265  {
266  public:
267  SquareFilter(std::vector<MeshFunctionSharedPtr<Scalar> > solutions, std::vector<int> items = *(new std::vector<int>));
268  virtual MeshFunction<Scalar>* clone() const;
269  virtual ~SquareFilter();
270 
271  protected:
272  virtual void filter_fn(int n, const std::vector<const Scalar*>& values, Scalar* result);
273  };
274 
276  class HERMES_API AbsFilter : public SimpleFilter < double >
277  {
278  public:
279  AbsFilter(std::vector<MeshFunctionSharedPtr<double> > solutions, std::vector<int> items = *(new std::vector<int>));
281  virtual MeshFunction<double>* clone() const;
282  virtual ~AbsFilter();
283 
284  protected:
285  virtual void filter_fn(int n, const std::vector<const double*>& values, double* result);
286  };
287 
289  class HERMES_API RealFilter : public ComplexFilter
290  {
291  public:
292  RealFilter();
293  RealFilter(MeshFunctionSharedPtr<std::complex<double> > solution, int item = H2D_FN_VAL_0);
294  virtual ~RealFilter();
295 
296  virtual MeshFunction<double>* clone() const;
297 
298  protected:
299  virtual void filter_fn(int n, const std::complex<double>* values, double* result);
300  };
301 
304  class HERMES_API ImagFilter : public ComplexFilter
305  {
306  public:
307  ImagFilter(MeshFunctionSharedPtr<std::complex<double> > solution, int item = H2D_FN_VAL_0);
308  virtual ~ImagFilter();
309 
310  virtual MeshFunction<double>* clone() const;
311  protected:
312  virtual void filter_fn(int n, const std::complex<double>* values, double* result);
313  };
314 
316  class HERMES_API ComplexAbsFilter : public ComplexFilter
317  {
318  public:
319  ComplexAbsFilter(MeshFunctionSharedPtr<std::complex<double> > solution, int item = H2D_FN_VAL_0);
320  virtual ~ComplexAbsFilter();
321 
322  virtual MeshFunction<double>* clone() const;
323 
324  protected:
325  virtual void filter_fn(int n, const std::complex<double>* values, double* result);
326  };
327 
329  class HERMES_API AngleFilter : public SimpleFilter < std::complex<double> >
330  {
331  public:
332  AngleFilter(std::vector<MeshFunctionSharedPtr<std::complex<double> > > solutions, std::vector<int> items = *(new std::vector<int>));
333  virtual ~AngleFilter();
334 
335  protected:
336  virtual void filter_fn(int n, const std::vector<const std::complex<double>*>& values, double* result);
337  };
338 
343  class HERMES_API VonMisesFilter : public Filter < double >
344  {
345  public:
346 
347  VonMisesFilter(std::vector<MeshFunctionSharedPtr<double> > solutions, double lambda, double mu,
348  int cyl = 0, int item1 = H2D_FN_VAL, int item2 = H2D_FN_VAL);
349 
350  virtual Func<double>* get_pt_value(double x, double y, bool use_MeshHashGrid = false, Element* e = nullptr);
351 
352  virtual MeshFunction<double>* clone() const;
353  virtual ~VonMisesFilter();
354 
355  protected:
356  double lambda, mu;
357 
358  int cyl, item1, item2;
359 
360  virtual void precalculate(unsigned short order, unsigned short mask);
361  };
362 
366  template<typename Scalar>
367  class HERMES_API LinearFilter : public Filter < Scalar >
368  {
369  public:
371 
373 
374  virtual Func<Scalar>* get_pt_value(double x, double y, bool use_MeshHashGrid = false, Element* e = nullptr);
375  virtual MeshFunction<Scalar>* clone() const;
376  virtual ~LinearFilter();
377 
378  protected:
379  double tau_frac;
380 
381  virtual void precalculate(unsigned short order, unsigned short mask);
382 
383  void init_components();
384 
385  virtual void set_active_element(Element* e);
386  };
387  }
388 }
389 #endif
Definition: adapt.h:24
Calculates the Von Mises stress.
Definition: filter.h:343
Stores one element of a mesh.
Definition: element.h:107
TopValFilter takes functions and puts a threshold on their highest values.
Definition: filter.h:188
Represents a function defined on a mesh.
Definition: mesh_function.h:56
std::string getClassName() const
State querying helpers.
Definition: filter.h:48
BottomValFilter takes functions and puts a threshold on their lowest values.
Definition: filter.h:204
Calculates the magnitude of a vector function.
Definition: filter.h:173
Calculates absolute value of a real solution.
Definition: filter.h:276
ValFilter takes functions and puts a threshold on their lowest AND highest values.
Definition: filter.h:220
Calculates the square of a function.
Definition: filter.h:264
Calculates the difference of two functions.
Definition: filter.h:238
Computes the absolute value of a complex solution.
Definition: filter.h:316
Calculates the sum of two functions.
Definition: filter.h:251
Computes the angle of a complex solution.
Definition: filter.h:329
Calculated function values (from the class Function) on an element for assembling.
Definition: forms.h:214
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.
const int H2D_FN_VAL
Both components are usually requested together...
Definition: function.h:53
Removes the imaginary part from a function.
Definition: filter.h:289