Line data Source code
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"
37 : #include "lib_disc/reference_element/reference_element_util.h"
38 :
39 : namespace ug{
40 :
41 : ////////////////////////////////////////////////////////////////////////////////
42 : // DataExport
43 : ////////////////////////////////////////////////////////////////////////////////
44 :
45 : template <typename TData, int dim>
46 0 : DataExport<TData, dim>::DataExport(const char* functions)
47 0 : : StdDependentUserData<DataExport<TData,dim>, TData, dim>(functions)
48 : {
49 : // reset all evaluation functions
50 0 : clear_fct();
51 0 : }
52 :
53 : template <typename TData, int dim>
54 0 : void DataExport<TData, dim>::clear_fct()
55 : {
56 0 : for(size_t roid = 0; roid < NUM_REFERENCE_OBJECTS; ++roid){
57 0 : eval_fct<1>((ReferenceObjectID)roid).invalidate();
58 0 : eval_fct<2>((ReferenceObjectID)roid).invalidate();
59 0 : eval_fct<3>((ReferenceObjectID)roid).invalidate();
60 : }
61 0 : }
62 :
63 : template <typename TData, int dim>
64 : template <int refDim>
65 0 : void DataExport<TData, dim>::eval_and_deriv(TData vValue[],
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 0 : u->access_by_map(this->map());
79 0 : const ReferenceObjectID roid = elem->reference_object_id();
80 : const Functor<refDim>& func = eval_fct<refDim>(roid);
81 0 : if(func.invalid())
82 0 : 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 0 : }
88 :
89 : template <typename TData, int dim>
90 : template <typename TClass, int refDim>
91 0 : void DataExport<TData, dim>::
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 0 : if(id >= NUM_REFERENCE_OBJECTS)
105 0 : UG_THROW("Reference Object id invalid: "<<id);
106 :
107 0 : eval_fct<refDim>(id) = Functor<refDim>(obj, func);
108 0 : }
109 :
110 : template <typename TData, int dim>
111 : template <int refDim>
112 : void DataExport<TData, dim>::
113 : set_fct(ReferenceObjectID id,
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>
132 : bool DataExport<TData, dim>::eval_fct_set(ReferenceObjectID id) const
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>
147 : void DataExport<TData, dim>::
148 : add_needed_data(SmartPtr<ICplUserData<dim> > data)
149 : {
150 : m_vDependData.push_back(data);
151 : }
152 :
153 : template <typename TData, int dim>
154 : void DataExport<TData, dim>::
155 : remove_needed_data(SmartPtr<ICplUserData<dim> > data)
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__ */
|