ug4
composite_user_data.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020: G-CSC, Goethe University Frankfurt
3  * Author: Arne Naegel
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 #ifndef __LIB_DISC__COMPOSITE_USER_DATA_H_
34 #define __LIB_DISC__COMPOSITE_USER_DATA_H_
35 
36 #include <vector>
37 #include <string>
38 
39 // UG4 headers
42 
43 namespace ug{
44 
46 
50 template <typename TData, int dim, typename TRet = void>
51 class CompositeUserData : public UserData<TData, dim, TRet>
52 {
53 protected:
55 public:
58 
60 
62 
63  virtual ~CompositeUserData(){}
64 
66  void add
67  (
68  int si,
70  )
71  {
72  UG_ASSERT (si >= 0, "CompositeUserData: Non-existing subset index!");
73 
74  if ((size_t) si >= m_vData.size ())
75  m_vData.resize (si + 1);
76  m_vData[si] = ref;
77 
78  // UG_ASSERT(ref->continuous() == m_continuous, "CompositeUserData: Mixing continuous and discontinuous data!");
79  m_bContinuous = m_bContinuous && ref->continuous();
80  m_bRequiresGridFunction = m_bRequiresGridFunction || ref->requires_grid_fct();
81  }
82 
84  void add
85  (
86  const SubsetGroup & ssg,
88  )
89  {
90  for (size_t i = 0; i < ssg.size (); i++) add (ssg[i], ref);
91  }
92 
94  void add
95  (
97  const char * ss_names,
99  )
100  {
101  std::vector<std::string> v_ss_names;
102  SubsetGroup ssg (ssh);
103 
104  TokenizeTrimString (std::string (ss_names), v_ss_names);
105  ssg.add (v_ss_names);
106  add (ssg, ref);
107  }
108 
110  bool has(int si) const { return si >= 0 && (size_t) si < m_vData.size () && m_vData[si].valid ();}
111 
112  SmartPtr<base_type> get(int si) const { check (si); return m_vData[si]; }
113 
114  bool is_coupled(int si) { return has(si) && m_vData[si].template is_of_type<TCplUserData>(); }
115 
116  SmartPtr<TCplUserData> get_coupled(int si) { return m_vData[si].template cast_dynamic<TCplUserData>(); }
117 
118  // Implementing virtual functions
119 
120  virtual bool continuous() const {return m_bContinuous;}
121 
123  virtual bool requires_grid_fct() const
124  {
126  }
127 
129  virtual TRet operator() (TData& value,
130  const MathVector<dim>& globIP,
131  number time, int si) const
132  { check (si); return (*m_vData[si]) (value, globIP, time, si); }
133 
135  virtual void operator()(TData vValue[],
136  const MathVector<dim> vGlobIP[],
137  number time, int si, const size_t nip) const
138  { check (si); return (*m_vData[si]) (vValue, vGlobIP, time, si, nip); }
139 
140 
141  virtual void operator()(TData vValue[],
142  const MathVector<dim> vGlobIP[],
143  number time, int si,
144  GridObject* elem,
145  const MathVector<dim> vCornerCoords[],
146  const MathVector<1> vLocIP[],
147  const size_t nip,
148  LocalVector* u,
149  const MathMatrix<1, dim>* vJT = NULL) const
150  {
151  check (si); return (*m_vData[si]) (vValue, vGlobIP, time, si, elem, vCornerCoords, vLocIP, nip, u, vJT);
152  }
153 
154  virtual void operator()(TData vValue[],
155  const MathVector<dim> vGlobIP[],
156  number time, int si,
157  GridObject* elem,
158  const MathVector<dim> vCornerCoords[],
159  const MathVector<2> vLocIP[],
160  const size_t nip,
161  LocalVector* u,
162  const MathMatrix<2, dim>* vJT = NULL) const
163  {
164  check (si); return (*m_vData[si]) (vValue, vGlobIP, time, si, elem, vCornerCoords, vLocIP, nip, u, vJT);
165  }
166 
167  virtual void operator()(TData vValue[],
168  const MathVector<dim> vGlobIP[],
169  number time, int si,
170  GridObject* elem,
171  const MathVector<dim> vCornerCoords[],
172  const MathVector<3> vLocIP[],
173  const size_t nip,
174  LocalVector* u,
175  const MathMatrix<3, dim>* vJT = NULL) const
176  {
177  check (si); return (*m_vData[si]) (vValue, vGlobIP, time, si, elem, vCornerCoords, vLocIP, nip, u, vJT);
178  }
179 
180 private:
181 
182  // checks if the subset si is present in the list
183  void check (int si) const
184  {
185  if (! has (si))
186  {
187  UG_THROW ("CompositeUserData: No data for subset " << si);
188  }
189  }
190 
191 private:
192 
193  std::vector<SmartPtr<base_type> > m_vData;
196 };
197 
198 
199 } // namespace ug
200 
201 #endif /* __LIB_DISC__COMPOSITE_USER_DATA_H_ */
Definition: smart_pointer.h:296
Definition: smart_pointer.h:108
This is a compositum for user data defined on different subsets.
Definition: composite_user_data.h:52
virtual TRet operator()(TData &value, const MathVector< dim > &globIP, number time, int si) const
returns value for a global position
Definition: composite_user_data.h:129
CompositeUserData()
Definition: composite_user_data.h:59
SmartPtr< TCplUserData > get_coupled(int si)
Definition: composite_user_data.h:116
UserData< TData, dim, TRet > base_type
Definition: composite_user_data.h:56
void add(const SubsetGroup &ssg, SmartPtr< base_type > ref)
Add 'UserData' object for all subsets in a given group.
Definition: composite_user_data.h:85
virtual ~CompositeUserData()
Definition: composite_user_data.h:63
void check(int si) const
Definition: composite_user_data.h:183
void add(ConstSmartPtr< ISubsetHandler > ssh, const char *ss_names, SmartPtr< base_type > ref)
Add 'UserData' object for all subsets by their names.
Definition: composite_user_data.h:95
virtual void operator()(TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, const size_t nip) const
returns values for global positions
Definition: composite_user_data.h:135
virtual bool continuous() const
returns if provided data is continuous over geometric object boundaries
Definition: composite_user_data.h:120
virtual bool requires_grid_fct() const
returns true, if at least one of the underlying UserData requires grid functions.
Definition: composite_user_data.h:123
bool is_coupled(int si)
Definition: composite_user_data.h:114
bool m_bRequiresGridFunction
Definition: composite_user_data.h:195
CompositeUserData(bool continuous)
Definition: composite_user_data.h:61
SmartPtr< base_type > get(int si) const
Definition: composite_user_data.h:112
bool m_bContinuous
Definition: composite_user_data.h:194
std::vector< SmartPtr< base_type > > m_vData
Definition: composite_user_data.h:193
virtual void operator()(TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< 3 > vLocIP[], const size_t nip, LocalVector *u, const MathMatrix< 3, dim > *vJT=NULL) const
Definition: composite_user_data.h:167
bool has(int si) const
Checks if anything is assigned to a given subset index.
Definition: composite_user_data.h:110
CplUserData< TData, dim, TRet > TCplUserData
Definition: composite_user_data.h:54
void add(int si, SmartPtr< base_type > ref)
Add 'UserData' object for given subset index.
Definition: composite_user_data.h:67
virtual void operator()(TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< 1 > vLocIP[], const size_t nip, LocalVector *u, const MathMatrix< 1, dim > *vJT=NULL) const
Definition: composite_user_data.h:141
virtual void operator()(TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< 2 > vLocIP[], const size_t nip, LocalVector *u, const MathMatrix< 2, dim > *vJT=NULL) const
Definition: composite_user_data.h:154
SmartPtr< base_type > ref_type
the attached UserData objects should have the same type as this class (i.e. they are "remapped")
Definition: composite_user_data.h:57
Type based UserData.
Definition: user_data.h:501
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
Group of subsets.
Definition: subset_group.h:51
size_t size() const
number of subsets in this group
Definition: subset_group.h:122
void add(int si)
adds a subset by number to this group
Definition: subset_group.cpp:64
Type based UserData.
Definition: user_data.h:143
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
#define UG_THROW(msg)
Definition: error.h:57
double number
Definition: types.h:124
the ug namespace
void TokenizeTrimString(const string &str, vector< string > &vToken, const char delimiter)
Definition: string_util.cpp:83