33 #ifndef __H__UG__LIB_DISC__SPATIAL_DISC__SCALE_ADD_LINKER_IMPL__
34 #define __H__UG__LIB_DISC__SPATIAL_DISC__SCALE_ADD_LINKER_IMPL__
46 template <
typename TData,
int dim,
typename TDataScale,
typename TRet>
51 UG_THROW(
"ScaleAddLinker: number of scaling factors and data mismatch.");
60 template <
typename TData,
int dim,
typename TDataScale,
typename TRet>
65 const size_t numInput = base_type::num_input() / 2;
68 m_vpUserData.resize(numInput+1);
69 m_vpDependData.resize(numInput+1);
70 m_vpScaleData.resize(numInput+1);
71 m_vpScaleDependData.resize(numInput+1);
74 UG_ASSERT(data.valid(),
"Null Pointer as Input set.");
75 m_vpUserData[numInput] = data;
76 m_vpDependData[numInput] = data.template cast_dynamic<DependentUserData<TData, dim> >();
79 UG_ASSERT(scale.valid(),
"Null Pointer as Scale set.");
80 m_vpScaleData[numInput] = scale;
81 m_vpScaleDependData[numInput] = scale.template cast_dynamic<DependentUserData<TDataScale, dim> >();
84 base_type::set_num_input(2*numInput+2);
85 base_type::set_input(2*numInput, data, data);
86 base_type::set_input(2*numInput+1, scale, scale);
89 template <
typename TData,
int dim,
typename TDataScale,
typename TRet>
93 add(CreateConstUserData<dim>(scale, TDataScale()), data);
96 template <
typename TData,
int dim,
typename TDataScale,
typename TRet>
100 add(scale, CreateConstUserData<dim>(data, TData()));
103 template <
typename TData,
int dim,
typename TDataScale,
typename TRet>
107 add(CreateConstUserData<dim>(scale, TDataScale()),
108 CreateConstUserData<dim>(data, TData()));
112 template <
typename TData,
int dim,
typename TDataScale,
typename TRet>
116 number time,
int si)
const
125 for(
size_t c = 0; c < m_vpUserData.size(); ++c)
127 (*m_vpUserData[c])(valData, globIP, time, si);
128 (*m_vpScaleData[c])(valScale, globIP, time, si);
135 template <
typename TData,
int dim,
typename TDataScale,
typename TRet>
136 template <
int refDim>
149 for(
size_t ip = 0; ip < nip; ++ip)
152 std::vector<TData> vValData(nip);
153 std::vector<TDataScale> vValScale(nip);
156 for(
size_t c = 0; c < m_vpUserData.size(); ++c)
158 (*m_vpUserData[c])(&vValData[0], vGlobIP, time, si,
159 elem, vCornerCoords, vLocIP, nip, u, vJT);
160 (*m_vpScaleData[c])(&vValScale[0], vGlobIP, time, si,
161 elem, vCornerCoords, vLocIP, nip, u, vJT);
163 for(
size_t ip = 0; ip < nip; ++ip)
165 mult_add(vValue[ip], vValData[ip], vValScale[ip]);
169 template <
typename TData,
int dim,
typename TDataScale,
typename TRet>
170 template <
int refDim>
182 std::vector<std::vector<TRet> > vvvDeriv[],
186 UG_ASSERT(m_vpUserData.size() == m_vpScaleData.size(),
"Wrong num Scales.");
189 for(
size_t ip = 0; ip < nip; ++ip)
195 for(
size_t c = 0; c < m_vpUserData.size(); ++c)
199 input_value(c,
s, ip),
200 scale_value(c,
s, ip));
205 if(!bDeriv || this->zero_derivative())
return;
208 UG_ASSERT(m_vpDependData.size() == m_vpScaleDependData.size(),
209 "Wrong num Scales.");
212 this->set_zero(vvvDeriv, nip);
215 for(
size_t c = 0; c < m_vpUserData.size(); ++c)
218 if(!m_vpUserData[c]->zero_derivative())
220 for(
size_t ip = 0; ip < nip; ++ip)
223 for(
size_t fct = 0; fct < input_num_fct(c); ++fct)
226 const size_t commonFct = input_common_fct(c, fct);
229 for(
size_t sh = 0; sh < this->num_sh(fct); ++sh)
232 mult_add(vvvDeriv[ip][commonFct][sh],
233 input_deriv(c,
s, ip, fct, sh),
234 scale_value(c,
s, ip));
241 if(!m_vpScaleData[c]->zero_derivative())
243 for(
size_t ip = 0; ip < nip; ++ip)
246 for(
size_t fct = 0; fct < scale_num_fct(c); ++fct)
249 const size_t commonFct = scale_common_fct(c, fct);
252 for(
size_t sh = 0; sh < this->num_sh(fct); ++sh)
255 mult_add(vvvDeriv[ip][commonFct][sh],
256 input_value(c,
s, ip),
257 scale_deriv(c,
s, ip, fct, sh));
Definition: smart_pointer.h:108
Type based UserData.
Definition: user_data.h:501
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition: grid_base_objects.h:157
Definition: local_algebra.h:198
A class for fixed size, dense matrices.
Definition: math_matrix.h:52
Definition: scale_add_linker.h:61
std::vector< SmartPtr< CplUserData< TData, dim > > > m_vpUserData
data input
Definition: scale_add_linker.h:167
void eval_and_deriv(TRet 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< TRet > > vvvDeriv[], const MathMatrix< refDim, dim > *vJT=NULL) const
Definition: scale_add_linker_impl.h:172
std::vector< SmartPtr< CplUserData< TDataScale, dim > > > m_vpScaleData
data input
Definition: scale_add_linker.h:161
void add(SmartPtr< CplUserData< TDataScale, dim > > scale, SmartPtr< CplUserData< TData, dim > > data)
Definition: scale_add_linker_impl.h:62
void evaluate(TRet &value, const MathVector< dim > &globIP, number time, int si) const
Definition: scale_add_linker_impl.h:114
ScaleAddLinker()
constructor
Definition: scale_add_linker.h:68
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
#define UG_THROW(msg)
Definition: error.h:57
double number
Definition: types.h:124
Linker Traits.
Definition: linker_traits.h:47
static void mult_add(TData &out, const TData &in1, const TDataIn &s)
computes out += s * in1 (with appropriate '*')