ug4
std_user_data.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-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__STD_USER_DATA__
34 #define __H__UG__LIB_DISC__SPATIAL_DISC__STD_USER_DATA__
35 
36 #include "user_data.h"
37 
38 namespace ug{
39 
41 // Wrapper Class for UserData
43 
61 template <typename TImpl, typename TData, int dim, typename TRet = void, typename TBase = CplUserData<TData, dim, TRet> >
62 class StdUserData : public TBase
63 {
64  public:
66  virtual TRet operator() (TData& value,
67  const MathVector<dim>& globIP,
68  number time, int si) const = 0;
69 
71  virtual void operator()(TData vValue[],
72  const MathVector<dim> vGlobIP[],
73  number time, int si, const size_t nip) const = 0;
74 
77  virtual void operator()(TData vValue[],
78  const MathVector<dim> vGlobIP[],
79  number time, int si,
80  GridObject* elem,
81  const MathVector<dim> vCornerCoords[],
82  const MathVector<1> vLocIP[],
83  const size_t nip,
84  LocalVector* u,
85  const MathMatrix<1, dim>* vJT = NULL) const
86  {
87  getImpl().template evaluate<1>(vValue,vGlobIP,time,si,elem,
88  vCornerCoords,vLocIP,nip,u,vJT);
89  }
90 
91  virtual void operator()(TData vValue[],
92  const MathVector<dim> vGlobIP[],
93  number time, int si,
94  GridObject* elem,
95  const MathVector<dim> vCornerCoords[],
96  const MathVector<2> vLocIP[],
97  const size_t nip,
98  LocalVector* u,
99  const MathMatrix<2, dim>* vJT = NULL) const
100  {
101  getImpl().template evaluate<2>(vValue,vGlobIP,time,si,elem,
102  vCornerCoords,vLocIP,nip,u,vJT);
103  }
104 
105  virtual void operator()(TData vValue[],
106  const MathVector<dim> vGlobIP[],
107  number time, int si,
108  GridObject* elem,
109  const MathVector<dim> vCornerCoords[],
110  const MathVector<3> vLocIP[],
111  const size_t nip,
112  LocalVector* u,
113  const MathMatrix<3, dim>* vJT = NULL) const
114  {
115  getImpl().template evaluate<3>(vValue,vGlobIP,time,si,elem,
116  vCornerCoords,vLocIP,nip,u,vJT);
117  }
118 
120  protected:
122  TImpl& getImpl() {return static_cast<TImpl&>(*this);}
123 
125  const TImpl& getImpl() const {return static_cast<const TImpl&>(*this);}
126 };
127 
128 template <typename TImpl, typename TData, int dim>
130  : public StdUserData< StdDependentUserData<TImpl, TData, dim>,
131  TData, dim, void,
132  DependentUserData<TData, dim> >
133 {
134  public:
136 
137  StdDependentUserData(const char* symbFct) {this->set_functions(symbFct);}
138  StdDependentUserData(const std::string& symbFct) {this->set_functions(symbFct);}
139  StdDependentUserData(const std::vector<std::string>& symbFct) {this->set_functions(symbFct);}
140 
141  public:
142  virtual void operator() (TData& value,
143  const MathVector<dim>& globIP,
144  number time, int si) const
145  {
146  UG_THROW("StdDependentUserData: Solution, element and local ips required "
147  "for evaluation, but not passed. Cannot evaluate.");
148  }
149 
150  virtual void operator()(TData vValue[],
151  const MathVector<dim> vGlobIP[],
152  number time, int si, const size_t nip) const
153  {
154  UG_THROW("StdDependentUserData: Solution, element and local ips required "
155  "for evaluation, but not passed. Cannot evaluate.");
156  }
157 
158  template <int refDim>
159  inline void evaluate(TData vValue[],
160  const MathVector<dim> vGlobIP[],
161  number time, int si,
162  GridObject* elem,
163  const MathVector<dim> vCornerCoords[],
164  const MathVector<refDim> vLocIP[],
165  const size_t nip,
166  LocalVector* u,
167  const MathMatrix<refDim, dim>* vJT = NULL) const
168  {
169  const_cast<TImpl*>(static_cast<const TImpl*>(this))->
170  template eval_and_deriv<refDim>(vValue,vGlobIP,time,si,elem,
171  vCornerCoords,vLocIP,nip,u,
172  false,0,NULL,vJT);
173  }
174 
175  template <int refDim>
177  const MathVector<dim> vCornerCoords[], bool bDeriv = false) {
178 
179  const int si = this->subset();
180 
181  std::vector<std::vector<TData> >* vvvDeriv = NULL;
182 
183  for(size_t s = 0; s < this->num_series(); ++s){
184 
185  if(bDeriv && this->m_vvvvDeriv[s].size() > 0)
186  vvvDeriv = &this->m_vvvvDeriv[s][0];
187  else
188  vvvDeriv = NULL;
189 
190  getImpl().template eval_and_deriv<refDim>(this->values(s), this->ips(s), this->time(s), si,
191  elem, vCornerCoords,
192  this->template local_ips<refDim>(s), this->num_ip(s),
193  u, bDeriv, s, vvvDeriv);
194  }
195  }
196 
197  template <int refDim>
199  const MathVector<dim> vCornerCoords[], bool bDeriv = false) {
200 
201  const int si = this->subset();
202 
203  std::vector<std::vector<TData> >* vvvDeriv = NULL;
204 
205  for(size_t s = 0; s < this->num_series(); ++s){
206 
207  bool bDoDeriv = bDeriv && this->at_current_time (s); // derivatives only for the 'current' time point!
208 
209  if(bDoDeriv && this->m_vvvvDeriv[s].size() > 0)
210  vvvDeriv = &this->m_vvvvDeriv[s][0];
211  else
212  vvvDeriv = NULL;
213 
214  getImpl().template eval_and_deriv<refDim>(this->values(s), this->ips(s), this->time(s), si,
215  elem, vCornerCoords,
216  this->template local_ips<refDim>(s), this->num_ip(s),
217  &(u->solution(this->time_point(s))), bDoDeriv, s, vvvDeriv);
218  }
219  }
220 
221  virtual void compute(LocalVector* u, GridObject* elem,
222  const MathVector<dim> vCornerCoords[], bool bDeriv = false){
223 
224  UG_ASSERT(elem->base_object_id() == this->dim_local_ips(),
225  "local ip dimension (" << this->dim_local_ips()
226  << ") and reference element dimension ("
227  << elem->base_object_id() << ") mismatch.");
228 
229  switch(this->dim_local_ips()){
230  case 1: eval_deriv<1>(u,elem,vCornerCoords,bDeriv); break;
231  case 2: eval_deriv<2>(u,elem,vCornerCoords,bDeriv); break;
232  case 3: eval_deriv<3>(u,elem,vCornerCoords,bDeriv); break;
233  default: UG_THROW("StdDependentUserData: Dimension not supported.");
234  }
235  }
236 
237  virtual void compute(LocalVectorTimeSeries* u, GridObject* elem,
238  const MathVector<dim> vCornerCoords[], bool bDeriv = false){
239 
240  UG_ASSERT(elem->base_object_id() == this->dim_local_ips(),
241  "local ip dimension and reference element dimension mismatch.");
242 
243  switch(this->dim_local_ips()){
244  case 1: eval_deriv<1>(u,elem,vCornerCoords,bDeriv); break;
245  case 2: eval_deriv<2>(u,elem,vCornerCoords,bDeriv); break;
246  case 3: eval_deriv<3>(u,elem,vCornerCoords,bDeriv); break;
247  default: UG_THROW("StdDependentUserData: Dimension not supported.");
248  }
249  }
250 
251  protected:
253  TImpl& getImpl() {return static_cast<TImpl&>(*this);}
254 
256  const TImpl& getImpl() const {return static_cast<const TImpl&>(*this);}
257 
258 };
259 
260 } // namespace ug
261 
262 #endif /* __H__UG__LIB_DISC__SPATIAL_DISC__STD_USER_DATA__ */
parameterString s
const TData * values(size_t s) const
returns all values for a series
Definition: user_data.h:516
const TData & value(size_t s, size_t ip) const
returns the value at ip
Definition: user_data.h:512
std::vector< std::vector< std::vector< std::vector< TData > > > > m_vvvvDeriv
Derivatives.
Definition: user_data.h:704
size_t num_ip(size_t s) const
returns the number of integration points
Definition: user_data.h:327
size_t num_series() const
returns the number of ip series
Definition: user_data.h:324
void set_functions(const char *symbFct)
Definition: user_data_impl.h:391
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition: grid_base_objects.h:157
virtual int base_object_id() const =0
int dim_local_ips() const
returns current local ip dimension
Definition: user_data.h:372
bool at_current_time(size_t s) const
returns true iff the time point specification is equal to the current one, or not specified
Definition: user_data_impl.h:221
int subset() const
returns the subset of evaluation
Definition: user_data.h:273
number time() const
get the current evaluation time
Definition: user_data.h:285
const MathVector< dim > * ips(size_t s) const
returns global ips
Definition: user_data.h:398
Definition: local_algebra.h:198
time series of local vectors
Definition: solution_time_series.h:167
const LocalVector & solution(size_t i) const
returns the local vector for the i'th time point
Definition: solution_time_series.h:182
A class for fixed size, dense matrices.
Definition: math_matrix.h:52
Definition: std_user_data.h:133
void eval_deriv(LocalVector *u, GridObject *elem, const MathVector< dim > vCornerCoords[], bool bDeriv=false)
Definition: std_user_data.h:176
void eval_deriv(LocalVectorTimeSeries *u, GridObject *elem, const MathVector< dim > vCornerCoords[], bool bDeriv=false)
Definition: std_user_data.h:198
virtual void operator()(TData &value, const MathVector< dim > &globIP, number time, int si) const
returns value for a global position
Definition: std_user_data.h:142
virtual void compute(LocalVectorTimeSeries *u, GridObject *elem, const MathVector< dim > vCornerCoords[], bool bDeriv=false)
compute values (and derivatives iff compDeriv == true, but only for the 'current' time point)
Definition: std_user_data.h:237
virtual void operator()(TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, const size_t nip) const
returns value for global positions
Definition: std_user_data.h:150
StdDependentUserData(const char *symbFct)
Definition: std_user_data.h:137
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: std_user_data.h:159
StdDependentUserData(const std::vector< std::string > &symbFct)
Definition: std_user_data.h:139
StdDependentUserData(const std::string &symbFct)
Definition: std_user_data.h:138
StdDependentUserData()
Definition: std_user_data.h:135
TImpl & getImpl()
access to implementation
Definition: std_user_data.h:253
virtual void compute(LocalVector *u, GridObject *elem, const MathVector< dim > vCornerCoords[], bool bDeriv=false)
compute values (and derivatives iff compDeriv == true)
Definition: std_user_data.h:221
const TImpl & getImpl() const
const access to implementation
Definition: std_user_data.h:256
Definition: std_user_data.h:63
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: std_user_data.h:77
virtual TRet operator()(TData &value, const MathVector< dim > &globIP, number time, int si) const =0
returns value for a global position
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: std_user_data.h:91
const TImpl & getImpl() const
const access to implementation
Definition: std_user_data.h:125
virtual void operator()(TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, const size_t nip) const =0
returns value for global positions
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: std_user_data.h:105
TImpl & getImpl()
access to implementation
Definition: std_user_data.h:122
#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