ug4
dim_dim_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  * Classes for user data that compute normals or project vectors to low-dimensional
35  * subsets. Note that these classes are mainly implemented for visualization purposes
36  * and cannot be used for coupling.
37  */
38 #ifndef __H__UG__LIB_DISC__SPATIAL_DISC__USER_DATA__ONC_USER_DATA__
39 #define __H__UG__LIB_DISC__SPATIAL_DISC__USER_DATA__ONC_USER_DATA__
40 
41 #include <vector>
42 
43 // ug4 headers
44 #include "common/common.h"
45 #include "common/math/ugmath.h"
47 #include "lib_disc/domain_traits.h"
48 #include "lib_disc/domain_util.h"
51 
52 namespace ug {
53 
55 
60 template <typename TDomain>
62  : public StdUserData<OutNormCmp<TDomain>, MathVector<TDomain::dim>, TDomain::dim, void, UserData<MathVector<TDomain::dim>, TDomain::dim, void> >
63 {
65  static const int dim = TDomain::dim;
66 
68  typedef TDomain domain_type;
69 
71  typedef typename TDomain::grid_type grid_type;
72 
75 
78 
81 
84 
85 public:
86 
89  (
90  SmartPtr<domain_type> spDomain,
92  const char * ss_names
93  )
94  : m_spData (spData), m_spDomain (spDomain), m_ssGrp (spDomain->subset_handler ())
95  {
96  // Parse the subset names:
97  std::vector<std::string> vssNames;
98  try
99  {
100  TokenizeString (ss_names, vssNames);
101  for (size_t k = 0; k < vssNames.size (); k++)
102  RemoveWhitespaceFromString (vssNames [k]);
103  m_ssGrp.clear ();
104  m_ssGrp.add (vssNames);
105  } UG_CATCH_THROW ("SubsetIndicatorUserData: Failed to parse subset names.");
106  }
107 
110  (
111  SmartPtr<domain_type> spDomain,
113  )
114  : m_spData (spData), m_spDomain (spDomain), m_ssGrp (spDomain->subset_handler ())
115  {}
116 
118  virtual bool continuous () const {return false;}
119 
121  virtual bool requires_grid_fct () const {return m_spData->requires_grid_fct ();}
122  // Remark: Note that actually we have not enought data for that. This dependence is neglected.
123 
125  template <int refDim>
126  inline void evaluate
127  (
128  vec_type vValue[],
129  const MathVector<dim> vGlobIP [],
130  number time,
131  int si,
132  GridObject * elem,
133  const MathVector<dim> vCornerCoords [],
134  const MathVector<refDim> vLocIP [],
135  const size_t nip,
136  LocalVector * u,
137  const MathMatrix<refDim, dim> * vJT = NULL
138  ) const
139  {
140  if (refDim == dim)
141  {
142  (* m_spData) (vValue, vGlobIP, time, si, elem, vCornerCoords, vLocIP, nip, u, vJT);
143  return;
144  }
145  if (refDim != dim - 1)
146  {
147  UG_THROW ("OutNormCmp: Wrong dimensionality of the subset.");
148  }
149 
150  // Get the full-dim. element associated with the given side
151  typedef typename grid_dim_traits<dim>::grid_base_object fd_elem_type;
152  fd_elem_type * fd_elem = NULL;
153  int fd_si = -1;
154 
155  typedef typename Grid::traits<fd_elem_type>::secure_container fd_elem_secure_container_type;
156  fd_elem_secure_container_type fd_elem_list;
157  grid_type& grid = * (grid_type*) (m_spDomain->grid().get ());
158  grid.associated_elements (fd_elem_list, elem);
159 
160  if (m_ssGrp.empty ()) // no subsets specified; we assume, elem should be the bnd of the whole domain
161  {
162  if (fd_elem_list.size () == 1)
163  {
164  fd_elem = fd_elem_list[0];
165  fd_si = m_spDomain->subset_handler()->get_subset_index (fd_elem);
166  }
167  // otherwise this is no boundary of the domain and we return 0
168  }
169  else
170  {
171  for (size_t k = 0; k < fd_elem_list.size (); k++)
172  {
173  fd_elem_type * e = fd_elem_list[k];
174  int e_si = m_ssGrp.subset_handler()->get_subset_index (e);
175  if (m_ssGrp.contains (e_si))
176  {
177  if (fd_elem != NULL) // i.e. e is already the second one
178  { // this is no boundary of the subset; return 0
179  fd_elem = NULL;
180  break;
181  }
182  fd_elem = e;
183  fd_si = e_si;
184  }
185  }
186  }
187  if (fd_elem == NULL)
188  { // this is no bondary, return 0
189  for (size_t ip = 0; ip < nip; ip++) vValue[ip] = 0;
190  return;
191  }
192 
193  // Get the coordinates of the corners of the full-dim. element
194  std::vector<MathVector<dim> > fd_elem_corner_coords (domain_traits<dim>::MaxNumVerticesOfElem);
195  CollectCornerCoordinates (fd_elem->base_object_id (), fd_elem_corner_coords,
196  *fd_elem, *m_spDomain, true);
197 
198  // Convert the local ip coordinates (use the global coordinates as they are the same)
199  const ReferenceObjectID fd_roid = fd_elem->reference_object_id ();
201  = ReferenceMappingProvider::get<dim, dim> (fd_roid, fd_elem_corner_coords);
202  std::vector<MathVector<dim> > fd_loc_ip (nip);
203  for (size_t ip = 0; ip < nip; ip++)
204  fd_map.global_to_local(fd_loc_ip[ip], vGlobIP[ip]);
205 
206  // Call the original UserData, get the vectors
207  (* m_spData) (&(vValue[0]), vGlobIP, time, fd_si, fd_elem, &(fd_elem_corner_coords[0]),
208  &(fd_loc_ip[0]), nip, u);
209  //TODO: Note that u is here a dummy parameter: We do not have enough data for it.
210 
211  // Project the vectors
212  const ReferenceObjectID roid = elem->reference_object_id ();
214  = ReferenceMappingProvider::get<refDim, dim> (roid, vCornerCoords);
215  for (size_t ip = 0; ip < nip; ip++)
216  {
218  MathVector<dim> p (vValue[ip]);
219 
220  map.jacobian (J, vLocIP[ip]);
221  OrthogProjectVec (p, J);
222  vValue[ip] -= p;
223  }
224  };
225 
227  void operator()
228  (
229  vec_type & vValue,
230  const MathVector<dim> & globIP,
231  number time,
232  int si
233  )
234  const
235  {
236  UG_THROW("OutNormCmp: Element required for evaluation, but not passed. Cannot evaluate.");
237  }
238 
240  void operator()
241  (
242  vec_type vValue [],
243  const MathVector<dim> vGlobIP [],
244  number time,
245  int si,
246  const size_t nip
247  ) const
248  {
249  UG_THROW("OutNormCmp: Element required for evaluation, but not passed. Cannot evaluate.");
250  }
251 
252 };
253 
254 } // end namespace ug
255 
256 #endif // __H__UG__LIB_DISC__SPATIAL_DISC__USER_DATA__ONC_USER_DATA__
257 
258 /* End of File */
parameterString p
Definition: smart_pointer.h:108
T * get()
returns encapsulated pointer
Definition: smart_pointer.h:197
virtual base class for reference mappings
Definition: reference_mapping_provider.h:53
virtual void global_to_local(MathVector< dim > &locPos, const MathVector< worldDim > &globPos, const size_t maxIter=1000, const number tol=1e-10) const =0
map global coordinate to local coordinate
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition: grid_base_objects.h:157
virtual ReferenceObjectID reference_object_id() const =0
Definition: local_algebra.h:198
A class for fixed size, dense matrices.
Definition: math_matrix.h:52
Projection to the outer normal for a given vector user data.
Definition: dim_dim_user_data.h:63
static const int dim
the world dimension
Definition: dim_dim_user_data.h:65
void evaluate(vec_type 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: dim_dim_user_data.h:127
SubsetGroup m_ssGrp
the subset group for the inner part
Definition: dim_dim_user_data.h:83
MathVector< dim > vec_type
the original data type
Definition: dim_dim_user_data.h:74
SmartPtr< domain_type > m_spDomain
the domain
Definition: dim_dim_user_data.h:80
virtual bool requires_grid_fct() const
Returns true to get the grid element in the evaluation routine.
Definition: dim_dim_user_data.h:121
SmartPtr< UserData< vec_type, dim, void > > m_spData
the original data
Definition: dim_dim_user_data.h:77
TDomain domain_type
the domain type
Definition: dim_dim_user_data.h:68
virtual bool continuous() const
Indicator functions are discontinuous.
Definition: dim_dim_user_data.h:118
TDomain::grid_type grid_type
the grid type
Definition: dim_dim_user_data.h:71
OutNormCmp(SmartPtr< domain_type > spDomain, SmartPtr< UserData< vec_type, dim, void > > spData, const char *ss_names)
constructor
Definition: dim_dim_user_data.h:89
OutNormCmp(SmartPtr< domain_type > spDomain, SmartPtr< UserData< vec_type, dim, void > > spData)
constructor
Definition: dim_dim_user_data.h:110
Container which holds an array of pointers.
Definition: pointer_const_array.h:84
Definition: std_user_data.h:63
Group of subsets.
Definition: subset_group.h:51
void clear()
clear all subsets
Definition: subset_group.h:116
bool empty() const
returns if function group is empty
Definition: subset_group.h:119
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
Type based UserData.
Definition: user_data.h:143
const FunctionIndexMapping & map() const
get function mapping
Definition: user_data.h:78
void CollectCornerCoordinates(std::vector< typename TAAPos::ValueType > &vCornerCoordsOut, const TElem &elem, const TAAPos &aaPos, bool clearContainer=true)
returns the corner coordinates of a geometric object
Definition: domain_util_impl.h:75
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
void OrthogProjectVec(vector_t &v, const matrix_t &A)
Orthogonal projection.
Definition: math_matrix_vector_functions_common_impl.hpp:251
the ug namespace
ReferenceObjectID
these ids are used to identify the shape of a geometric object.
Definition: grid_base_objects.h:74
void TokenizeString(const string &str, vector< string > &vToken, const char delimiter)
Definition: string_util.cpp:56
Definition: domain_traits.h:53
Definition: grid_dim_traits.h:53