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 // UG4
38 
39 namespace ug{
40 
42 
43 template <typename TData, int dim, typename TRet = void>
44 class CompositeUserData : public UserData<TData, dim, TRet>
45 {
46 protected:
48 public:
51  typedef std::map<int, ref_type> map_type;
52 
54  {}
55 
56  virtual ~CompositeUserData(){}
57 
59  void add(int si, ref_type ref)
60 
61  {
62  // UG_ASSERT(ref->continuous() == m_continuous, "ERROR: Mixing continuous and discontinuous data!");
63  m_map[si] = ref;
64  m_continuous = m_continuous && ref->continuous();
65  m_bRequiresGridFunction = m_bRequiresGridFunction || ref->requires_grid_fct();
66  }
67 
68  ref_type get(int si)
69  { return (find(si)->second); }
70 
71  bool has(int si)
72  { return find(si) != m_map.end();}
73 
74 
75  bool is_coupled(int si)
76  { return (has(si) && find(si)->second.template is_of_type<TCplUserData>()); }
77 
79  { return find(si)->second.template cast_dynamic<TCplUserData>(); }
80 
81 
82 
83 
84  // Implementing virtual functions
85 
86  virtual bool continuous() const
87  {return m_continuous;}
88 
89 
91  virtual bool requires_grid_fct() const
92  {
94  }
95 
97  virtual TRet operator() (TData& value,
98  const MathVector<dim>& globIP,
99  number time, int si) const
100  { return (*find(si)->second)(value, globIP, time, si); }
101 
103  virtual void operator()(TData vValue[],
104  const MathVector<dim> vGlobIP[],
105  number time, int si, const size_t nip) const
106  { return (*find(si)->second)(vValue, vGlobIP, time, si, nip); }
107 
108 
109  virtual void operator()(TData vValue[],
110  const MathVector<dim> vGlobIP[],
111  number time, int si,
112  GridObject* elem,
113  const MathVector<dim> vCornerCoords[],
114  const MathVector<1> vLocIP[],
115  const size_t nip,
116  LocalVector* u,
117  const MathMatrix<1, dim>* vJT = NULL) const
118  {
119  return (*find(si)->second)(vValue, vGlobIP, time, si, elem, vCornerCoords, vLocIP, nip, u, vJT);
120  }
121 
122  virtual void operator()(TData vValue[],
123  const MathVector<dim> vGlobIP[],
124  number time, int si,
125  GridObject* elem,
126  const MathVector<dim> vCornerCoords[],
127  const MathVector<2> vLocIP[],
128  const size_t nip,
129  LocalVector* u,
130  const MathMatrix<2, dim>* vJT = NULL) const
131  {
132  return (*find(si)->second)(vValue, vGlobIP, time, si, elem, vCornerCoords, vLocIP, nip, u, vJT);
133  }
134 
135  virtual void operator()(TData vValue[],
136  const MathVector<dim> vGlobIP[],
137  number time, int si,
138  GridObject* elem,
139  const MathVector<dim> vCornerCoords[],
140  const MathVector<3> vLocIP[],
141  const size_t nip,
142  LocalVector* u,
143  const MathMatrix<3, dim>* vJT = NULL) const
144  {
145  return (*find(si)->second)(vValue, vGlobIP, time, si, elem, vCornerCoords, vLocIP, nip, u, vJT);
146  }
147 
148 
149 
150 protected:
151  typename map_type::const_iterator find(int si) const
152  {
153  typename map_type::const_iterator it = m_map.find(si);
154  UG_ASSERT(it != m_map.end(), "ERROR: Subset not found!");
155  return it;
156  }
157 
161 };
162 
163 
164 } // namespace ug
165 
166 #endif /* __LIB_DISC__COMPOSITE_USER_DATA_H_ */
Definition: smart_pointer.h:108
This is a compositum for user data from different subsets.
Definition: composite_user_data.h:45
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:97
bool has(int si)
Definition: composite_user_data.h:71
map_type m_map
Definition: composite_user_data.h:158
SmartPtr< TCplUserData > get_coupled(int si)
Definition: composite_user_data.h:78
UserData< TData, dim, TRet > base_type
Definition: composite_user_data.h:49
virtual ~CompositeUserData()
Definition: composite_user_data.h:56
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:103
void add(int si, ref_type ref)
! Add 'UserData' for given subset index.
Definition: composite_user_data.h:59
virtual bool continuous() const
returns if provided data is continuous over geometric object boundaries
Definition: composite_user_data.h:86
virtual bool requires_grid_fct() const
returns true, if at least one of the underlying UserData requires grid functions.
Definition: composite_user_data.h:91
bool is_coupled(int si)
Definition: composite_user_data.h:75
bool m_bRequiresGridFunction
Definition: composite_user_data.h:160
CompositeUserData(bool continuous)
Definition: composite_user_data.h:53
map_type::const_iterator find(int si) const
Definition: composite_user_data.h:151
std::map< int, ref_type > map_type
Definition: composite_user_data.h:51
bool m_continuous
Definition: composite_user_data.h:159
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:135
ref_type get(int si)
Definition: composite_user_data.h:68
CplUserData< TData, dim, TRet > TCplUserData
Definition: composite_user_data.h:47
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:109
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:122
SmartPtr< base_type > ref_type
Definition: composite_user_data.h:50
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
Type based UserData.
Definition: user_data.h:143
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
double number
Definition: types.h:124
the ug namespace