ug4
data_export_impl.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__DATA_EXPORT_IMPL__
34 #define __H__UG__LIB_DISC__SPATIAL_DISC__DATA_EXPORT_IMPL__
35 
36 #include "data_export.h"
38 
39 namespace ug{
40 
42 // DataExport
44 
45 template <typename TData, int dim>
46 DataExport<TData, dim>::DataExport(const char* functions)
47 : StdDependentUserData<DataExport<TData,dim>, TData, dim>(functions)
48 {
49 // reset all evaluation functions
50  clear_fct();
51 }
52 
53 template <typename TData, int dim>
55 {
56  for(size_t roid = 0; roid < NUM_REFERENCE_OBJECTS; ++roid){
57  eval_fct<1>((ReferenceObjectID)roid).invalidate();
58  eval_fct<2>((ReferenceObjectID)roid).invalidate();
59  eval_fct<3>((ReferenceObjectID)roid).invalidate();
60  }
61 }
62 
63 template <typename TData, int dim>
64 template <int refDim>
66  const MathVector<dim> vGlobIP[],
67  number time, int si,
68  GridObject* elem,
69  const MathVector<dim> vCornerCoords[],
70  const MathVector<refDim> vLocIP[],
71  const size_t nip,
72  LocalVector* u,
73  bool bDeriv,
74  int s,
75  std::vector<std::vector<TData> > vvvDeriv[],
76  const MathMatrix<refDim, dim>* vJT) const
77 {
78  u->access_by_map(this->map());
79  const ReferenceObjectID roid = elem->reference_object_id();
80  const Functor<refDim>& func = eval_fct<refDim>(roid);
81  if(func.invalid())
82  UG_THROW("DataExport: no evaluation function set for "<<
83  roid<<" (world dim: "<<dim<<", ref dim: "<<refDim<<").");
84 
85  (func)(vValue,vGlobIP,time,si,*u,elem,
86  vCornerCoords,vLocIP,nip, bDeriv, vvvDeriv);
87 }
88 
89 template <typename TData, int dim>
90 template <typename TClass, int refDim>
92 set_fct(ReferenceObjectID id, TClass* obj,
93  void (TClass::*func)( TData vValue[],
94  const MathVector<dim> vGlobIP[],
95  number time, int si,
96  const LocalVector& u,
97  GridObject* elem,
98  const MathVector<dim> vCornerCoords[],
99  const MathVector<refDim> vLocIP[],
100  const size_t nip,
101  bool bDeriv,
102  std::vector<std::vector<TData> > vvvDeriv[]))
103 {
104  if(id >= NUM_REFERENCE_OBJECTS)
105  UG_THROW("Reference Object id invalid: "<<id);
106 
107  eval_fct<refDim>(id) = Functor<refDim>(obj, func);
108 }
109 
110 template <typename TData, int dim>
111 template <int refDim>
114  void (*func)( TData vValue[],
115  const MathVector<dim> vGlobIP[],
116  number time, int si,
117  const LocalVector& u,
118  GridObject* elem,
119  const MathVector<dim> vCornerCoords[],
120  const MathVector<refDim> vLocIP[],
121  const size_t nip,
122  bool bDeriv,
123  std::vector<std::vector<TData> > vvvDeriv[]))
124 {
125  if(id >= NUM_REFERENCE_OBJECTS)
126  UG_THROW("Reference Object id invalid: "<<id);
127 
128  eval_fct<refDim>(id) = Functor<refDim>(func);
129 }
130 
131 template <typename TData, int dim>
133 {
134  const int d = ReferenceElementDimension(id);
135  bool bRes = false;
136  switch(d){
137  case 1: if(eval_fct<1>(id).valid()) bRes = true; break;
138  case 2: if(eval_fct<2>(id).valid()) bRes = true; break;
139  case 3: if(eval_fct<3>(id).valid()) bRes = true; break;
140  default: UG_THROW("DataExport: Dimension "<<d<<" not supported.");
141  }
142  return bRes;
143 }
144 
145 
146 template <typename TData, int dim>
149 {
150  m_vDependData.push_back(data);
151 }
152 
153 template <typename TData, int dim>
156 {
157  m_vDependData.erase(remove(m_vDependData.begin(),
158  m_vDependData.end(),
159  data),
160  m_vDependData.end());
161 }
162 
163 } // end namespace ug
164 
165 #endif /* __H__UG__LIB_DISC__SPATIAL_DISC__DATA_EXPORT_IMPL__ */
Definition: smart_pointer.h:108
Definition: data_export.h:318
Data export.
Definition: data_export.h:150
bool eval_fct_set(ReferenceObjectID id) const
Definition: data_export_impl.h:132
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
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
DataExport(const char *functions)
default constructor
Definition: data_export_impl.h:46
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition: grid_base_objects.h:157
virtual ReferenceObjectID reference_object_id() const =0
Base class for UserData.
Definition: user_data.h:260
Definition: local_algebra.h:198
void access_by_map(const FunctionIndexMapping &funcMap)
access only part of the functions using mapping (restrict functions)
Definition: local_algebra.h:306
A class for fixed size, dense matrices.
Definition: math_matrix.h:52
Definition: std_user_data.h:133
static const int dim
#define UG_THROW(msg)
Definition: error.h:57
double number
Definition: types.h:124
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
int ReferenceElementDimension(ReferenceObjectID roid)
returns the reference element dimension at run-time
Definition: reference_element_util.h:40
function func(x, y, z, t, si)