ug4
const_user_data.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2015: G-CSC, Goethe University Frankfurt
3  * Author: Andreas Vogel
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 __H__UG__LIB_DISC__SPATIAL_DISC__USER_DATA__CONST_USER_DATA__
34 #define __H__UG__LIB_DISC__SPATIAL_DISC__USER_DATA__CONST_USER_DATA__
35 
36 #include "common/common.h"
37 #include "common/math/ugmath.h"
38 
39 #include "std_user_data.h"
40 
41 namespace ug {
42 
43 
45 // Base class for Constant Data
47 
56 template <typename TImpl, typename TData, int dim>
58  : public StdUserData<StdConstData<TImpl,TData,dim>, TData, dim>
59 {
60  public:
61  virtual void operator() (TData& value,
62  const MathVector<dim>& globIP,
63  number time, int si) const
64  {
65  getImpl().evaluate(value);
66  }
67 
68  virtual void operator()(TData vValue[],
69  const MathVector<dim> vGlobIP[],
70  number time, int si, const size_t nip) const
71  {
72  for(size_t ip = 0; ip < nip; ++ip)
73  getImpl().evaluate(vValue[ip]);
74  }
75 
76  template <int refDim>
77  inline void evaluate(TData vValue[],
78  const MathVector<dim> vGlobIP[],
79  number time, int si,
80  GridObject* elem,
81  const MathVector<dim> vCornerCoords[],
82  const MathVector<refDim> vLocIP[],
83  const size_t nip,
84  LocalVector* u,
85  const MathMatrix<refDim, dim>* vJT = NULL) const
86  {
87  for(size_t ip = 0; ip < nip; ++ip)
88  getImpl().evaluate(vValue[ip]);
89  }
90 
92  virtual void compute(LocalVector* u, GridObject* elem,
93  const MathVector<dim> vCornerCoords[], bool bDeriv = false)
94  {
95  for(size_t s = 0; s < this->num_series(); ++s)
96  for(size_t ip = 0; ip < this->num_ip(s); ++ip)
97  getImpl().evaluate(this->value(s,ip));
98  }
99 
101  virtual void compute(LocalVectorTimeSeries* u, GridObject* elem,
102  const MathVector<dim> vCornerCoords[], bool bDeriv = false)
103  {
104  for(size_t s = 0; s < this->num_series(); ++s)
105  for(size_t ip = 0; ip < this->num_ip(s); ++ip)
106  getImpl().evaluate(this->value(s,ip));
107  }
108 
110  virtual void value_storage_changed(const size_t seriesID)
111  {
112  for(size_t ip = 0; ip < this->num_ip(seriesID); ++ip)
113  getImpl().evaluate(this->value(seriesID,ip));
114  }
115 
117  virtual bool constant() const {return true;}
118 
120  virtual bool requires_grid_fct() const {return false;}
121 
123  virtual bool continuous() const {return true;}
124 
125  protected:
127  TImpl& getImpl() {return static_cast<TImpl&>(*this);}
128 
130  const TImpl& getImpl() const {return static_cast<const TImpl&>(*this);}
131 };
132 
134 // Constant UserData
136 
148 
150 template <int dim>
152  : public StdConstData<ConstUserNumber<dim>, number, dim>
153 {
154  public:
157 
160 
162  void set(number val) {m_Number = val;}
163 
165  void print() const {UG_LOG("ConstUserNumber:" << m_Number << "\n");}
166 
168  inline void evaluate (number& value) const {value = m_Number;}
169 
171  number get() const {return m_Number;}
172 
173  protected:
175 };
176 
178 
184 template <int dim, int worldDim = dim>
186  : public StdConstData<ConstUserVector<dim, worldDim>, MathVector<dim>, worldDim>
187 {
188  public:
191 
194 
196  ConstUserVector(const std::vector<number>& val) {set_vector(val);}
197 
199  void set_all_entries(number val) { m_Vector = val;}
200 
202  void set_entry(size_t i, number val){m_Vector[i] = val;}
203 
205  void set_vector(const std::vector<number>& val)
206  {
207  if(val.size() != dim) UG_THROW("Size mismatch in ConstUserVector");
208  for(size_t i = 0; i < dim; i++) m_Vector[i] = val[i];
209  }
210 
212  void print() const {UG_LOG("ConstUserVector:" << m_Vector << "\n");}
213 
215  inline void evaluate (MathVector<dim>& value) const{value = m_Vector;}
216 
217  protected:
219 };
220 
222 
229 template <int N, int M = N, int worldDim = N>
231  : public StdConstData<ConstUserMatrix<N, M, worldDim>, MathMatrix<N, M>, worldDim>
232 {
233  public:
236 
239 
242  {
243  for(size_t i = 0; i < N; ++i){
244  for(size_t j = 0; j < M; ++j){
245  m_Tensor[i][j] = 0;
246  }
247  m_Tensor[i][i] = val;
248  }
249  }
250 
253  {
254  for(size_t i = 0; i < N; ++i){
255  for(size_t j = 0; j < M; ++j){
256  m_Tensor[i][j] = val;
257  }
258  }
259  }
260 
262  void set_entry(size_t i, size_t j, number val){m_Tensor[i][j] = val;}
263 
265  void print() const{UG_LOG("ConstUserMatrix:\n" << m_Tensor << "\n");}
266 
268  inline void evaluate (MathMatrix<N, M>& value) const{value = m_Tensor;}
269 
270  protected:
272 };
273 
275 template <int TRank, int dim>
277  : public StdConstData<ConstUserTensor<TRank,dim>, MathTensor<TRank, dim>, dim>
278 {
279  public:
282 
285 
287  void set(number val) {m_Tensor.set(val);}
288 
290  void print() const{UG_LOG("ConstUserTensor:\n" << m_Tensor << "\n");}
291 
294 
295  protected:
297 };
298 
300 template <typename TData, int dim>
302 
303 template <int dim>
305 {
306  return make_sp(new ConstUserNumber<dim>(val));
307 };
308 
309 template <int dim, int worldDim=dim>
311 {
312  return make_sp(new ConstUserVector<dim,worldDim>(val));
313 }
314 
315 template <int dim>
317 {
318  return make_sp(new ConstUserMatrix<dim>(val));
319 }
320 
321 template <int dim>
323 {
324  return make_sp(new ConstUserTensor<4,dim>(val));
325 }
326 
328 
329 }
330 
331 #endif /* __H__UG__LIB_DISC__SPATIAL_DISC__USER_DATA__CONST_USER_DATA__ */
parameterString s
Definition: smart_pointer.h:108
constant matrix user data
Definition: const_user_data.h:232
ConstUserMatrix()
Constructor.
Definition: const_user_data.h:235
void set_all_entries(number val)
sets all entries of the matrix
Definition: const_user_data.h:252
void set_entry(size_t i, size_t j, number val)
sets a single entry
Definition: const_user_data.h:262
void evaluate(MathMatrix< N, M > &value) const
evaluate
Definition: const_user_data.h:268
ConstUserMatrix(number val)
Constructor setting the diagonal.
Definition: const_user_data.h:238
void set_diag_tensor(number val)
set diagonal of matrix to a vector
Definition: const_user_data.h:241
void print() const
print current setting
Definition: const_user_data.h:265
MathMatrix< N, M > m_Tensor
Definition: const_user_data.h:271
constant scalar user data
Definition: const_user_data.h:153
void evaluate(number &value) const
evaluate
Definition: const_user_data.h:168
ConstUserNumber()
creates empty user number
Definition: const_user_data.h:156
ConstUserNumber(number val)
creates user number with value
Definition: const_user_data.h:159
void set(number val)
set constant value
Definition: const_user_data.h:162
number get() const
get value
Definition: const_user_data.h:171
number m_Number
Definition: const_user_data.h:174
void print() const
print current setting
Definition: const_user_data.h:165
constant tensor user data
Definition: const_user_data.h:278
void print() const
print current setting
Definition: const_user_data.h:290
void evaluate(MathTensor< TRank, dim > &value) const
evaluate
Definition: const_user_data.h:293
ConstUserTensor(number val)
Constructor setting the diagonal.
Definition: const_user_data.h:284
ConstUserTensor()
Constructor.
Definition: const_user_data.h:281
MathTensor< TRank, dim > m_Tensor
Definition: const_user_data.h:296
void set(number val)
set diagonal of matrix to a vector
Definition: const_user_data.h:287
constant vector user data
Definition: const_user_data.h:187
void print() const
print current setting
Definition: const_user_data.h:212
void set_entry(size_t i, number val)
set i'th vector entry
Definition: const_user_data.h:202
void evaluate(MathVector< dim > &value) const
evaluate
Definition: const_user_data.h:215
void set_all_entries(number val)
set all vector entries
Definition: const_user_data.h:199
ConstUserVector()
Constructor: no arguments, zero entries.
Definition: const_user_data.h:190
MathVector< dim > m_Vector
Definition: const_user_data.h:218
void set_vector(const std::vector< number > &val)
set from a given vector:
Definition: const_user_data.h:205
ConstUserVector(const std::vector< number > &val)
Constructor: initialize with a given std::vector.
Definition: const_user_data.h:196
ConstUserVector(number val)
Constructor: set all the entries to the given value.
Definition: const_user_data.h:193
size_t num_ip(size_t s) const
returns the number of integration points
Definition: user_data.h:327
size_t num_series() const
explicitly forward some functions
Definition: user_data.h:324
const TData & value(size_t s, size_t ip) const
returns the value at ip
Definition: user_data.h:512
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition: grid_base_objects.h:157
const MathVector< dim > & ip(size_t s, size_t ip) const
returns global ip
Definition: user_data.h:401
number time() const
get the current evaluation time
Definition: user_data.h:285
Definition: local_algebra.h:198
time series of local vectors
Definition: solution_time_series.h:167
A class for fixed size, dense matrices.
Definition: math_matrix.h:52
void set(T val)
Definition: math_tensor.h:86
Definition: const_user_data.h:59
virtual void compute(LocalVector *u, GridObject *elem, const MathVector< dim > vCornerCoords[], bool bDeriv=false)
implement as a UserData
Definition: const_user_data.h:92
virtual bool requires_grid_fct() const
returns if grid function is needed for evaluation
Definition: const_user_data.h:120
virtual bool continuous() const
returns if provided data is continuous over geometric object boundaries
Definition: const_user_data.h:123
virtual void value_storage_changed(const size_t seriesID)
callback, invoked when data storage changed
Definition: const_user_data.h:110
const TImpl & getImpl() const
const access to implementation
Definition: const_user_data.h:130
virtual void operator()(TData &value, const MathVector< dim > &globIP, number time, int si) const
returns value for a global position
Definition: const_user_data.h:61
void evaluate(TData 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
Definition: const_user_data.h:77
virtual void compute(LocalVectorTimeSeries *u, GridObject *elem, const MathVector< dim > vCornerCoords[], bool bDeriv=false)
implement as a UserData
Definition: const_user_data.h:101
virtual bool constant() const
returns if data is constant
Definition: const_user_data.h:117
TImpl & getImpl()
access to implementation
Definition: const_user_data.h:127
virtual void operator()(TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, const size_t nip) const
returns value for global positions
Definition: const_user_data.h:68
Definition: std_user_data.h:63
SmartPtr< CplUserData< TData, dim > > CreateConstUserData(number val, TData dummy)
creates user data of desired type
static const int dim
#define UG_THROW(msg)
Definition: error.h:57
#define UG_LOG(msg)
Definition: log.h:367
double number
Definition: types.h:124
the ug namespace
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition: smart_pointer.h:836