Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
data_export.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__DATA_EXPORT__
34#define __H__UG__LIB_DISC__SPATIAL_DISC__DATA_EXPORT__
35
40
43
44#include "std_user_data.h"
45
46namespace ug{
47
48
50// ValueDataExport
52
53template <int dim>
55 : public StdDependentUserData<ValueDataExport<dim>,number,dim>
56{
57 public:
58 ValueDataExport(const char* functions){this->set_functions(functions);}
59
60 template <int refDim>
61 void eval_and_deriv(number vValue[],
62 const MathVector<dim> vGlobIP[],
63 number time, int si,
64 GridObject* elem,
65 const MathVector<dim> vCornerCoords[],
66 const MathVector<refDim> vLocIP[],
67 const size_t nip,
68 LocalVector* u,
69 bool bDeriv,
70 int s,
71 std::vector<std::vector<number> > vvvDeriv[],
72 const MathMatrix<refDim, dim>* vJT = NULL) const;
73
74 virtual void check_setup() const;
75
76 virtual bool continuous() const;
77};
78
80// GradientDataExport
82
83template <int dim>
85 : public StdDependentUserData<GradientDataExport<dim>, MathVector<dim>,dim>
86{
87 public:
88 GradientDataExport(const char* functions){this->set_functions(functions);}
89
90 template <int refDim>
91 void eval_and_deriv(MathVector<dim> vValue[],
92 const MathVector<dim> vGlobIP[],
93 number time, int si,
94 GridObject* elem,
95 const MathVector<dim> vCornerCoords[],
96 const MathVector<refDim> vLocIP[],
97 const size_t nip,
98 LocalVector* u,
99 bool bDeriv,
100 int s,
101 std::vector<std::vector<MathVector<dim> > > vvvDeriv[],
102 const MathMatrix<refDim, dim>* vJT = NULL) const;
103
104 virtual void check_setup() const;
105
106 virtual bool continuous() const{return false;}
107};
108
110// VectorDataExport
112
113template <int dim>
115 : public StdDependentUserData<VectorDataExport<dim>, MathVector<dim>,dim>
116{
117 public:
118 VectorDataExport(const char* functions){this->set_functions(functions);}
119
120 template <int refDim>
121 void eval_and_deriv(MathVector<dim> vValue[],
122 const MathVector<dim> vGlobIP[],
123 number time, int si,
124 GridObject* elem,
125 const MathVector<dim> vCornerCoords[],
126 const MathVector<refDim> vLocIP[],
127 const size_t nip,
128 LocalVector* u,
129 bool bDeriv,
130 int s,
131 std::vector<std::vector<MathVector<dim> > > vvvDeriv[],
132 const MathMatrix<refDim, dim>* vJT = NULL) const;
133
134 virtual void check_setup() const;
135
136 virtual bool continuous() const;
137};
138
140// Data Export
142
144
147template <typename TData, int dim>
149 public StdDependentUserData<DataExport<TData,dim>, TData, dim>
150{
151 public:
153 DataExport(const char* functions);
154
155 template <int refDim>
156 void eval_and_deriv(TData vValue[],
157 const MathVector<dim> vGlobIP[],
158 number time, int si,
159 GridObject* elem,
160 const MathVector<dim> vCornerCoords[],
161 const MathVector<refDim> vLocIP[],
162 const size_t nip,
163 LocalVector* u,
164 bool bDeriv,
165 int s,
166 std::vector<std::vector<TData> > vvvDeriv[],
167 const MathMatrix<refDim, dim>* vJT = NULL) const;
168
170 template <typename TClass, int refDim>
171 void set_fct(ReferenceObjectID id, TClass* obj,
172 void (TClass::*func)( TData vValue[],
173 const MathVector<dim> vGlobIP[],
174 number time, int si,
175 const LocalVector& u,
176 GridObject* elem,
177 const MathVector<dim> vCornerCoords[],
178 const MathVector<refDim> vLocIP[],
179 const size_t nip,
180 bool bDeriv,
181 std::vector<std::vector<TData> > vvvDeriv[]));
182
184 template <int refDim>
186 void (*func)( TData vValue[],
187 const MathVector<dim> vGlobIP[],
188 number time, int si,
189 const LocalVector& u,
190 GridObject* elem,
191 const MathVector<dim> vCornerCoords[],
192 const MathVector<refDim> vLocIP[],
193 const size_t nip,
194 bool bDeriv,
195 std::vector<std::vector<TData> > vvvDeriv[]));
196
198 void clear_fct();
199
201 void clear() {m_vDependData.clear();}
202
205
208
210 virtual size_t num_needed_data() const {return m_vDependData.size();}
211
213 virtual SmartPtr<ICplUserData<dim> > needed_data(size_t i) {return m_vDependData.at(i);}
214
216 virtual bool continuous() const {return false;}
217
219 virtual bool requires_grid_fct() const {return true;}
220
221 protected:
222 /* The following classes are used to implement the functors to support
223 * free functions and member functions. We do not use boost::bind or
224 * loki here, since they usually do not support that many arguments. In
225 * addition arguments are known and can simply be hardcoded.
226 */
227
228 // base class
229 template <int refDim>
231 public:
232 virtual void operator()(TData vValue[],
233 const MathVector<dim> vGlobIP[],
234 number time, int si,
235 const LocalVector& u,
236 GridObject* elem,
237 const MathVector<dim> vCornerCoords[],
238 const MathVector<refDim> vLocIP[],
239 const size_t nip,
240 bool bDeriv,
241 std::vector<std::vector<TData> > vvvDeriv[]) const = 0;
242 virtual ~FunctorBase() {}
243 };
244
245 // free function functor
246 template <int refDim>
247 class FreeFunctionFunctor : public FunctorBase<refDim>{
248 typedef void (*FreeFunc)(TData vValue[],
249 const MathVector<dim> vGlobIP[],
250 number time, int si,
251 const LocalVector& u,
252 GridObject* elem,
253 const MathVector<dim> vCornerCoords[],
254 const MathVector<refDim> vLocIP[],
255 const size_t nip,
256 bool bDeriv,
257 std::vector<std::vector<TData> > vvvDeriv[]);
258
259 public:
261
262 void operator()(TData vValue[],
263 const MathVector<dim> vGlobIP[],
264 number time, int si,
265 const LocalVector& u,
266 GridObject* elem,
267 const MathVector<dim> vCornerCoords[],
268 const MathVector<refDim> vLocIP[],
269 const size_t nip,
270 bool bDeriv,
271 std::vector<std::vector<TData> > vvvDeriv[]) const
272 {
273 m_f(vValue, vGlobIP, time, si, u, elem, vCornerCoords, vLocIP, nip, bDeriv, vvvDeriv);
274 }
275
276 protected:
278 };
279
280 // member function functor
281 template <typename TClass, int refDim>
282 class MemberFunctionFunctor : public FunctorBase<refDim>{
283 typedef void (TClass::*MemFunc)(TData vValue[],
284 const MathVector<dim> vGlobIP[],
285 number time, int si,
286 const LocalVector& u,
287 GridObject* elem,
288 const MathVector<dim> vCornerCoords[],
289 const MathVector<refDim> vLocIP[],
290 const size_t nip,
291 bool bDeriv,
292 std::vector<std::vector<TData> > vvvDeriv[]);
293
294 public:
295 MemberFunctionFunctor(TClass* obj, MemFunc f) : m_pObj(obj), m_mf(f) {}
296
297 void operator()(TData vValue[],
298 const MathVector<dim> vGlobIP[],
299 number time, int si,
300 const LocalVector& u,
301 GridObject* elem,
302 const MathVector<dim> vCornerCoords[],
303 const MathVector<refDim> vLocIP[],
304 const size_t nip,
305 bool bDeriv,
306 std::vector<std::vector<TData> > vvvDeriv[]) const
307 {
308 ((m_pObj)->*m_mf)(vValue, vGlobIP, time, si, u, elem, vCornerCoords, vLocIP, nip, bDeriv, vvvDeriv);
309 }
310
311 protected:
312 TClass* m_pObj;
314 };
315
316 // generic functor for both types
317 template <int refDim>
318 class Functor{
319 public:
320 Functor() : m_spImpl(NULL) {}
321
322 template <typename FreeFunc>
323 Functor(FreeFunc f) : m_spImpl(new FreeFunctionFunctor<refDim>(f)) {}
324
325 template <typename TClass, typename MemFunc>
326 Functor(TClass* obj, MemFunc f) : m_spImpl(new MemberFunctionFunctor<TClass, refDim>(obj, f)) {}
327
328 void operator()(TData vValue[],
329 const MathVector<dim> vGlobIP[],
330 number time, int si,
331 const LocalVector& u,
332 GridObject* elem,
333 const MathVector<dim> vCornerCoords[],
334 const MathVector<refDim> vLocIP[],
335 const size_t nip,
336 bool bDeriv,
337 std::vector<std::vector<TData> > vvvDeriv[]) const
338 {
339 (*m_spImpl)(vValue, vGlobIP, time, si, u, elem, vCornerCoords, vLocIP, nip, bDeriv, vvvDeriv);
340 }
341
342 bool valid() const {return m_spImpl.valid();}
343 bool invalid() const {return m_spImpl.invalid();}
345
346 protected:
348 };
349
350 template <int refDim>
352 template <int refDim>
354
364
365 bool eval_fct_set(ReferenceObjectID id) const;
366
367 protected:
369 std::vector<SmartPtr<ICplUserData<dim> > > m_vDependData;
370};
371
372} // end namespace ug
373
374#include "data_export_impl.h"
375
376#endif /* __H__UG__LIB_DISC__SPATIAL_DISC__DATA_EXPORT__ */
parameterString s
Definition smart_pointer.h:296
Definition smart_pointer.h:108
Definition data_export.h:247
void operator()(TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, const LocalVector &u, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< refDim > vLocIP[], const size_t nip, bool bDeriv, std::vector< std::vector< TData > > vvvDeriv[]) const
Definition data_export.h:262
void(* FreeFunc)(TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, const LocalVector &u, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< refDim > vLocIP[], const size_t nip, bool bDeriv, std::vector< std::vector< TData > > vvvDeriv[])
Definition data_export.h:248
FreeFunc m_f
Definition data_export.h:277
FreeFunctionFunctor(FreeFunc f)
Definition data_export.h:260
Definition data_export.h:230
virtual void operator()(TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, const LocalVector &u, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< refDim > vLocIP[], const size_t nip, bool bDeriv, std::vector< std::vector< TData > > vvvDeriv[]) const =0
virtual ~FunctorBase()
Definition data_export.h:242
Definition data_export.h:318
Functor(TClass *obj, MemFunc f)
Definition data_export.h:326
bool invalid() const
Definition data_export.h:343
void invalidate()
Definition data_export.h:344
void operator()(TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, const LocalVector &u, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< refDim > vLocIP[], const size_t nip, bool bDeriv, std::vector< std::vector< TData > > vvvDeriv[]) const
Definition data_export.h:328
ConstSmartPtr< FunctorBase< refDim > > m_spImpl
Definition data_export.h:347
Functor()
Definition data_export.h:320
bool valid() const
Definition data_export.h:342
Functor(FreeFunc f)
Definition data_export.h:323
Definition data_export.h:282
void operator()(TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, const LocalVector &u, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< refDim > vLocIP[], const size_t nip, bool bDeriv, std::vector< std::vector< TData > > vvvDeriv[]) const
Definition data_export.h:297
MemFunc m_mf
Definition data_export.h:313
MemberFunctionFunctor(TClass *obj, MemFunc f)
Definition data_export.h:295
void(TClass::* MemFunc)(TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, const LocalVector &u, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< refDim > vLocIP[], const size_t nip, bool bDeriv, std::vector< std::vector< TData > > vvvDeriv[])
Definition data_export.h:283
TClass * m_pObj
Definition data_export.h:312
Data export.
Definition data_export.h:150
const Functor< 1 > & eval_fct(ReferenceObjectID id, Int2Type< 1 >) const
Definition data_export.h:358
Functor< 1 > & eval_fct(ReferenceObjectID id, Int2Type< 1 >)
Definition data_export.h:355
bool eval_fct_set(ReferenceObjectID id) const
Definition data_export_impl.h:132
Functor< 2 > m_vCompFct2d[NUM_REFERENCE_OBJECTS]
Definition data_export.h:362
virtual bool continuous() const
returns if provided data is continuous over geometric object boundaries
Definition data_export.h:216
void add_needed_data(SmartPtr< ICplUserData< dim > > data)
add data dependency
Definition data_export_impl.h:148
void eval_and_deriv(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, bool bDeriv, int s, std::vector< std::vector< TData > > vvvDeriv[], const MathMatrix< refDim, dim > *vJT=NULL) const
Definition data_export_impl.h:65
void remove_needed_data(SmartPtr< ICplUserData< dim > > data)
remove needed data
Definition data_export_impl.h:155
const Functor< 3 > & eval_fct(ReferenceObjectID id, Int2Type< 3 >) const
Definition data_export.h:360
const Functor< 2 > & eval_fct(ReferenceObjectID id, Int2Type< 2 >) const
Definition data_export.h:359
void clear_fct()
clears all export functions
Definition data_export_impl.h:54
void set_fct(ReferenceObjectID id, TClass *obj, void(TClass::*func)(TData vValue[], const MathVector< dim > vGlobIP[], number time, int si, const LocalVector &u, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< refDim > vLocIP[], const size_t nip, bool bDeriv, std::vector< std::vector< TData > > vvvDeriv[]))
register evaluation of export function
Definition data_export_impl.h:92
std::vector< SmartPtr< ICplUserData< dim > > > m_vDependData
data the export depends on
Definition data_export.h:369
Functor< refDim > & eval_fct(ReferenceObjectID id)
Definition data_export.h:351
virtual bool requires_grid_fct() const
returns if grid function is needed for evaluation
Definition data_export.h:219
Functor< 3 > & eval_fct(ReferenceObjectID id, Int2Type< 3 >)
Definition data_export.h:357
Functor< 2 > & eval_fct(ReferenceObjectID id, Int2Type< 2 >)
Definition data_export.h:356
virtual size_t num_needed_data() const
number of other Data this data depends on
Definition data_export.h:210
const Functor< refDim > & eval_fct(ReferenceObjectID id) const
Definition data_export.h:353
virtual SmartPtr< ICplUserData< dim > > needed_data(size_t i)
return needed data
Definition data_export.h:213
void clear()
clear dependent data
Definition data_export.h:201
Functor< 1 > m_vCompFct1d[NUM_REFERENCE_OBJECTS]
Definition data_export.h:361
Functor< 3 > m_vCompFct3d[NUM_REFERENCE_OBJECTS]
Definition data_export.h:363
Definition data_export.h:86
virtual bool continuous() const
returns if provided data is continuous over geometric object boundaries
Definition data_export.h:106
virtual void check_setup() const
returns if the dependent data is ready for evaluation
Definition data_export.cpp:194
void eval_and_deriv(MathVector< dim > 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, bool bDeriv, int s, std::vector< std::vector< MathVector< dim > > > vvvDeriv[], const MathMatrix< refDim, dim > *vJT=NULL) const
Definition data_export.cpp:122
GradientDataExport(const char *functions)
Definition data_export.h:88
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition grid_base_objects.h:157
Base class for UserData.
Definition user_data.h:260
number time() const
get the current evaluation time
Definition user_data.h:285
Definition local_algebra.h:198
A class for fixed size, dense matrices.
Definition math_matrix.h:63
a mathematical Vector with N entries.
Definition math_vector.h:97
Definition std_user_data.h:133
Definition data_export.h:56
void eval_and_deriv(number 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, bool bDeriv, int s, std::vector< std::vector< number > > vvvDeriv[], const MathMatrix< refDim, dim > *vJT=NULL) const
Definition data_export.cpp:44
virtual void check_setup() const
returns if the dependent data is ready for evaluation
Definition data_export.cpp:100
virtual bool continuous() const
returns if provided data is continuous over geometric object boundaries
Definition data_export.cpp:109
ValueDataExport(const char *functions)
Definition data_export.h:58
Definition data_export.h:116
VectorDataExport(const char *functions)
Definition data_export.h:118
void eval_and_deriv(MathVector< dim > 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, bool bDeriv, int s, std::vector< std::vector< MathVector< dim > > > vvvDeriv[], const MathMatrix< refDim, dim > *vJT=NULL) const
Definition data_export.cpp:208
virtual bool continuous() const
returns if provided data is continuous over geometric object boundaries
Definition data_export.cpp:276
virtual void check_setup() const
returns if the dependent data is ready for evaluation
Definition data_export.cpp:267
double number
Definition types.h:124
Definition smart_pointer.h:814
the ug namespace
ReferenceObjectID
these ids are used to identify the shape of a geometric object.
Definition grid_base_objects.h:74
@ NUM_REFERENCE_OBJECTS
Definition grid_base_objects.h:85
function func(x, y, z, t, si)
Definition metaprogramming_util.h:42
function ProblemDisc new(problemDesc, dom)