ug4
subset_indicator_user_data.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015: G-CSC, Goethe University Frankfurt
3  * Author: Dmitry Logashenko
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 /*
34  * User data of a subset indicator (1 in the subset, 0 everywhere else)
35  */
36 #ifndef __H__UG__LIB_DISC__SPATIAL_DISC__USER_DATA__SSIND_USER_DATA__
37 #define __H__UG__LIB_DISC__SPATIAL_DISC__USER_DATA__SSIND_USER_DATA__
38 
39 #include <vector>
40 
41 // ug4 headers
42 #include "common/common.h"
43 #include "common/math/ugmath.h"
45 
46 namespace ug {
47 
49 
56 template <typename TDomain>
58  : public StdUserData<SubsetIndicatorUserData<TDomain>, number, TDomain::dim, void, UserData<number, TDomain::dim, void> >
59 {
60 public:
62  typedef TDomain domain_type;
63 
65  static const int dim = domain_type::dim;
66 
68  typedef typename domain_type::subset_handler_type subset_handler_type;
69 
70 private:
73 
74 public:
75 
78  (
80  const char * ss_names
81  )
82  : m_ssGrp (domain->subset_handler ())
83  {
84  // Parse the subset names:
85  std::vector<std::string> vssNames;
86  try
87  {
88  TokenizeString (ss_names, vssNames);
89  for (size_t k = 0; k < vssNames.size (); k++)
90  RemoveWhitespaceFromString (vssNames [k]);
91  m_ssGrp.clear ();
92  m_ssGrp.add (vssNames);
93  } UG_CATCH_THROW ("SubsetIndicatorUserData: Failed to parse subset names.");
94  }
95 
97  virtual bool continuous () const {return false;}
98 
100  virtual bool requires_grid_fct () const {return true;}
101 
103  template <int refDim>
104  inline void evaluate
105  (
106  number vValue [],
107  const MathVector<dim> vGlobIP [],
108  number time,
109  int si,
110  GridObject * elem,
111  const MathVector<dim> vCornerCoords [],
112  const MathVector<refDim> vLocIP [],
113  const size_t nip,
114  LocalVector * u,
115  const MathMatrix<refDim, dim> * vJT = NULL
116  ) const
117  {
118  // Get the subset index of the element
119  int elem_si = m_ssGrp.subset_handler()->get_subset_index (elem);
120  // Check if the element is in one of the specified subsets:
121  number indicator = (m_ssGrp.contains (elem_si))? 1 : 0;
122  // Return the indicator:
123  for (size_t i = 0; i < nip; i++)
124  vValue [i] = indicator;
125  };
126 
128  void operator()
129  (
130  number & vValue,
131  const MathVector<dim> & globIP,
132  number time,
133  int si
134  )
135  const
136  {
137  // Check if si is in one of the specified subsets:
138  vValue = (m_ssGrp.contains (si))? 1 : 0;
139  }
140 
142  void operator()
143  (
144  number vValue [],
145  const MathVector<dim> vGlobIP [],
146  number time,
147  int si,
148  const size_t nip
149  ) const
150  {
151  // Check if si is in one of the specified subsets:
152  number indicator = (m_ssGrp.contains (si))? 1 : 0;
153  // Return the indicator:
154  for (size_t i = 0; i < nip; i++)
155  vValue [i] = indicator;
156  }
157 };
158 
160 
164 template <typename TDomain>
166  : public StdUserData<ValueIndicatorUserData<TDomain>, number, TDomain::dim, void, UserData<number, TDomain::dim, void> >
167 {
169  static const int dim = TDomain::dim;
170 
172  typedef TDomain domain_type;
173 
175  typedef typename TDomain::grid_type grid_type;
176 
179 
182 
184  bool m_greater;
185 
186 public:
187 
190  (
192  number threshold,
193  bool greater
194  )
195  : m_spData (spData), m_threshold (threshold), m_greater (greater)
196  {
197  if (m_spData.invalid ())
198  UG_THROW ("ValueIndicatorUserData: No userdata specified!");
199  }
200 
202  virtual bool continuous () const {return m_spData->continuous ();}
203 
205  virtual bool requires_grid_fct () const {return m_spData->requires_grid_fct ();}
206 
208  template <int refDim>
209  inline void evaluate
210  (
211  number vValue [],
212  const MathVector<dim> vGlobIP [],
213  number time,
214  int si,
215  GridObject * elem,
216  const MathVector<dim> vCornerCoords [],
217  const MathVector<refDim> vLocIP [],
218  const size_t nip,
219  LocalVector * u,
220  const MathMatrix<refDim, dim> * vJT = NULL
221  ) const
222  {
223  // Call the original UserData, get the values
224  (* m_spData) (vValue, vGlobIP, time, si, elem, vCornerCoords, vLocIP, nip, u, vJT);
225 
226  // Reset the values
227  reset_values (vValue, nip);
228  };
229 
231  void operator()
232  (
233  number & vValue,
234  const MathVector<dim> & globIP,
235  number time,
236  int si
237  )
238  const
239  {
240  // Call the original UserData, get the values
241  (* m_spData) (vValue, globIP, time, si);
242 
243  // Reset the values
244  reset_values (&vValue, 1);
245  }
246 
248  void operator()
249  (
250  number vValue [],
251  const MathVector<dim> vGlobIP [],
252  number time,
253  int si,
254  const size_t nip
255  ) const
256  {
257  // Call the original UserData, get the values
258  (* m_spData) (vValue, vGlobIP, time, si, nip);
259 
260  // Reset the values
261  reset_values (vValue, nip);
262  }
263 
264 private:
265 
266  void reset_values (number vValue [], const size_t nip) const
267  {
268  if (m_greater)
269  for (size_t i = 0; i < nip; i++)
270  if (vValue[i] >= m_threshold) vValue[i] = 1; else vValue[i] = 0;
271  else
272  for (size_t i = 0; i < nip; i++)
273  if (vValue[i] <= m_threshold) vValue[i] = 1; else vValue[i] = 0;
274  }
275 };
276 
277 } // end namespace ug
278 
279 #endif // __H__UG__LIB_DISC__SPATIAL_DISC__USER_DATA__SSIND_USER_DATA__
280 
281 /* End of File */
Definition: smart_pointer.h:108
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition: grid_base_objects.h:157
Definition: local_algebra.h:198
A class for fixed size, dense matrices.
Definition: math_matrix.h:52
Definition: std_user_data.h:63
Group of subsets.
Definition: subset_group.h:51
void clear()
clear all subsets
Definition: subset_group.h:116
ConstSmartPtr< ISubsetHandler > subset_handler() const
get underlying subset handler
Definition: subset_group.h:72
void add(int si)
adds a subset by number to this group
Definition: subset_group.cpp:64
bool contains(int si) const
returns true if subset is contained in this group
Definition: subset_group.cpp:272
User data of a subset indicator (1 in the subset, 0 everywhere else)
Definition: subset_indicator_user_data.h:59
static const int dim
World dimension.
Definition: subset_indicator_user_data.h:65
TDomain domain_type
Type of domain.
Definition: subset_indicator_user_data.h:62
SubsetGroup m_ssGrp
subset group representing the specified subdomain
Definition: subset_indicator_user_data.h:72
virtual bool continuous() const
Indicator functions are discontinuous.
Definition: subset_indicator_user_data.h:97
domain_type::subset_handler_type subset_handler_type
subset handler type
Definition: subset_indicator_user_data.h:68
SubsetIndicatorUserData(ConstSmartPtr< domain_type > domain, const char *ss_names)
Constructor.
Definition: subset_indicator_user_data.h:78
virtual bool requires_grid_fct() const
Returns true to get the grid element in the evaluation routine.
Definition: subset_indicator_user_data.h:100
void evaluate(number vValue[], const MathVector< dim > vGlobIP[], number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< refDim > vLocIP[], const size_t nip, LocalVector *u, const MathMatrix< refDim, dim > *vJT=NULL) const
Evaluator.
Definition: subset_indicator_user_data.h:105
Type based UserData.
Definition: user_data.h:143
"Heaviside step function" based on the value of values of a further userdata
Definition: subset_indicator_user_data.h:167
SmartPtr< UserData< number, dim, void > > m_spData
the original data
Definition: subset_indicator_user_data.h:178
TDomain domain_type
the domain type
Definition: subset_indicator_user_data.h:172
void reset_values(number vValue[], const size_t nip) const
Definition: subset_indicator_user_data.h:266
TDomain::grid_type grid_type
the grid type
Definition: subset_indicator_user_data.h:175
virtual bool requires_grid_fct() const
Returns true to get the grid element in the evaluation routine.
Definition: subset_indicator_user_data.h:205
bool m_greater
if less or greater
Definition: subset_indicator_user_data.h:184
ValueIndicatorUserData(SmartPtr< UserData< number, dim, void > > spData, number threshold, bool greater)
constructor
Definition: subset_indicator_user_data.h:190
number m_threshold
the threshold value
Definition: subset_indicator_user_data.h:181
static const int dim
the world dimension
Definition: subset_indicator_user_data.h:169
virtual bool continuous() const
Indicator functions are discontinuous.
Definition: subset_indicator_user_data.h:202
void evaluate(number vValue[], const MathVector< dim > vGlobIP[], number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< refDim > vLocIP[], const size_t nip, LocalVector *u, const MathMatrix< refDim, dim > *vJT=NULL) const
Evaluator.
Definition: subset_indicator_user_data.h:210
static const int dim
void RemoveWhitespaceFromString(std::string &str)
removes all white space from a string, also within the string
Definition: string_util.cpp:50
#define UG_CATCH_THROW(msg)
Definition: error.h:64
#define UG_THROW(msg)
Definition: error.h:57
double number
Definition: types.h:124
the ug namespace
void TokenizeString(const string &str, vector< string > &vToken, const char delimiter)
Definition: string_util.cpp:56