Line data Source code
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_LINKER__
34 : #define __H__UG__LIB_DISC__SPATIAL_DISC__DATA_LINKER__
35 :
36 : #include "../std_user_data.h"
37 : #include "lib_disc/common/groups_util.h"
38 :
39 : namespace ug{
40 :
41 : /// combines several UserDatas to a new UserData of a specified type
42 : /**
43 : * This class provides data at integration points and implements the
44 : * DependentUserData interface.
45 : *
46 : * \tparam TData output Data type
47 : * \tparam dim World dimension
48 : */
49 : template <typename TImpl, typename TData, int dim>
50 : class StdDataLinker
51 : : public StdUserData< StdDataLinker<TImpl, TData, dim>,
52 : TData, dim, void,
53 : DependentUserData<TData, dim> >
54 : {
55 : public:
56 : virtual void operator() (TData& value,
57 : const MathVector<dim>& globIP,
58 : number time, int si) const;
59 :
60 : virtual void operator()(TData vValue[],
61 : const MathVector<dim> vGlobIP[],
62 : number time, int si, const size_t nip) const;
63 :
64 : template <int refDim>
65 : inline void evaluate(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 : const MathMatrix<refDim, dim>* vJT = NULL) const;
74 :
75 : virtual void compute(LocalVector* u, GridObject* elem,
76 : const MathVector<dim> vCornerCoords[], bool bDeriv = false);
77 : virtual void compute(LocalVectorTimeSeries* u, GridObject* elem,
78 : const MathVector<dim> vCornerCoords[], bool bDeriv = false);
79 :
80 : protected:
81 : template <int refDim>
82 : void eval_deriv(LocalVector* u, GridObject* elem,
83 : const MathVector<dim> vCornerCoords[], bool bDeriv = false);
84 : template <int refDim>
85 : void eval_deriv(LocalVectorTimeSeries* u, GridObject* elem,
86 : const MathVector<dim> vCornerCoords[], bool bDeriv = false);
87 :
88 : public:
89 : /// returns that a grid function is needed for evaluation
90 : virtual bool requires_grid_fct() const;
91 :
92 : /// returns if provided data is continuous over geometric object boundaries
93 : virtual bool continuous() const;
94 :
95 : /// returns if derivative is zero
96 : virtual bool zero_derivative() const;
97 :
98 : public:
99 : /// returns if the derivative of the i'th input is zero
100 : bool zero_derivative(size_t i) const
101 : {
102 : if(!m_vspICplUserData[i].valid()) return true;
103 : return m_vspICplUserData[i]->zero_derivative();
104 : }
105 :
106 : /// sets the number of inputs
107 : void set_num_input(size_t num)
108 : {
109 0 : m_vspICplUserData.resize(num);
110 0 : m_vspUserDataInfo.resize(num);
111 0 : }
112 :
113 : /// sets an input
114 0 : virtual void set_input(size_t i,
115 : SmartPtr<ICplUserData<dim> > input,
116 : SmartPtr<UserDataInfo> info)
117 : {
118 : UG_ASSERT(i < m_vspICplUserData.size(), "invalid index");
119 0 : m_vspICplUserData[i] = input;
120 0 : m_vspUserDataInfo[i] = info;
121 0 : }
122 :
123 : /// number of inputs
124 0 : virtual size_t num_input() const {return num_needed_data();}
125 :
126 : /// number of other Data this data depends on
127 0 : virtual size_t num_needed_data() const {return m_vspICplUserData.size();}
128 :
129 : /// return needed data
130 0 : virtual SmartPtr<ICplUserData<dim> > needed_data(size_t i)
131 : {
132 : UG_ASSERT(i < m_vspICplUserData.size(), "Input not needed");
133 : UG_ASSERT(m_vspICplUserData[i].valid(), "Data input not valid");
134 0 : return m_vspICplUserData[i];
135 : }
136 :
137 : /// returns if data is ok
138 : virtual void check_setup() const;
139 :
140 : /// updates the function group
141 : virtual void set_function_pattern(ConstSmartPtr<FunctionPattern> fctPatt);
142 :
143 : protected:
144 : /// returns number of functions the input depends on
145 : size_t input_num_fct(size_t i) const
146 : {
147 : UG_ASSERT(i < m_vspUserDataInfo.size(), "Input invalid");
148 0 : if(!m_vspUserDataInfo[i].valid()) return 0;
149 0 : return m_vspUserDataInfo[i]->num_fct();
150 : }
151 :
152 : /// returns the number in the common FctGrp for a fct of an input
153 : size_t input_common_fct(size_t i, size_t fct) const
154 : {
155 : UG_ASSERT(i < m_vMap.size(), "Input Map invalid");
156 : UG_ASSERT(fct < m_vMap[i].num_fct(), "Input Map invalid for fct");
157 : return m_vMap[i][fct];
158 : }
159 :
160 : /// returns the series id set for the i'th input
161 : size_t series_id(size_t i, size_t s) const
162 : {
163 : UG_ASSERT(i < m_vvSeriesID.size(), "invalid index");
164 : UG_ASSERT(s < m_vvSeriesID[i].size(), "invalid index");
165 0 : return m_vvSeriesID[i][s];
166 : }
167 :
168 : /// requests series id's from input data
169 : virtual void local_ip_series_added(const size_t seriesID);
170 :
171 : /// forwards the local positions to the data inputs
172 : virtual void local_ips_changed(const size_t seriesID, const size_t newNumIP);
173 :
174 : /// requests cleaning of the ip series in the data inputs
175 : virtual void local_ip_series_to_be_cleared();
176 :
177 : /// forwards the global positions to the data inputs
178 : virtual void global_ips_changed(const size_t seriesID, const MathVector<dim>* vPos, const size_t numIP);
179 :
180 : protected:
181 : /// data input
182 : std::vector<SmartPtr<ICplUserData<dim> > > m_vspICplUserData;
183 :
184 : /// data input casted to IDependend data
185 : std::vector<SmartPtr<UserDataInfo> > m_vspUserDataInfo;
186 :
187 : /// Function mapping for each input relative to common FunctionGroup
188 : std::vector<FunctionIndexMapping> m_vMap;
189 :
190 : /// series id the linker uses to get data from input
191 : std::vector<std::vector<size_t> > m_vvSeriesID;
192 :
193 : protected:
194 : /// access to implementation
195 : TImpl& getImpl() {return static_cast<TImpl&>(*this);}
196 :
197 : /// const access to implementation
198 : const TImpl& getImpl() const {return static_cast<const TImpl&>(*this);}
199 : };
200 :
201 : } // end namespace ug
202 :
203 : // include implementation
204 : #include "linker_impl.h"
205 :
206 : #endif /* __H__UG__LIB_DISC__SPATIAL_DISC__DATA_LINKER__ */
|