ug4
scale_add_linker.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__SCALE_ADD_LINKER__
34 #define __H__UG__LIB_DISC__SPATIAL_DISC__SCALE_ADD_LINKER__
35 
36 #include "linker.h"
37 
38 namespace ug{
39 
40 
42 // Scaled adding of Data
44 
58 template <typename TData, int dim, typename TDataScale, typename TRet = TData>
60  : public StdDataLinker<ScaleAddLinker<TData, dim, TDataScale, TRet>, TRet, dim>
61 {
62  public:
63  // type of base class
65 
66  public:
69 
71  ScaleAddLinker(const ScaleAddLinker& linker);
72 
77  void add(number scale,
80  number data);
81  void add(number scale,
82  number data);
84 
85  inline void evaluate (TRet& value,
86  const MathVector<dim>& globIP,
87  number time, int si) const;
88 
89  template <int refDim>
90  inline void evaluate(TRet vValue[],
91  const MathVector<dim> vGlobIP[],
92  number time, int si,
93  GridObject* elem,
94  const MathVector<dim> vCornerCoords[],
95  const MathVector<refDim> vLocIP[],
96  const size_t nip,
97  LocalVector* u,
98  const MathMatrix<refDim, dim>* vJT = NULL) const;
99 
100  template <int refDim>
101  void eval_and_deriv(TRet vValue[],
102  const MathVector<dim> vGlobIP[],
103  number time, int si,
104  GridObject* elem,
105  const MathVector<dim> vCornerCoords[],
106  const MathVector<refDim> vLocIP[],
107  const size_t nip,
108  LocalVector* u,
109  bool bDeriv,
110  int s,
111  std::vector<std::vector<TRet> > vvvDeriv[],
112  const MathMatrix<refDim, dim>* vJT = NULL) const;
113 
114  protected:
116  const TData& input_value(size_t i, size_t s, size_t ip) const
117  {
118  UG_ASSERT(i < m_vpUserData.size(), "Input not needed");
119  UG_ASSERT(m_vpUserData[i].valid(), "Input invalid");
120  return m_vpUserData[i]->value(this->series_id(2*i,s), ip);
121  }
122 
124  const TData& input_deriv(size_t i, size_t s, size_t ip, size_t fct, size_t dof) const
125  {
126  UG_ASSERT(i < m_vpDependData.size(), "Input not needed");
127  UG_ASSERT(m_vpDependData[i].valid(), "Input invalid");
128  return m_vpDependData[i]->deriv(this->series_id(2*i,s), ip, fct, dof);
129  }
130 
132  const TDataScale& scale_value(size_t i, size_t s, size_t ip) const
133  {
134  UG_ASSERT(i < m_vpScaleData.size(), "Input not needed");
135  UG_ASSERT(m_vpScaleData[i].valid(), "Input invalid");
136  return m_vpScaleData[i]->value(this->series_id(2*i+1,s), ip);
137  }
138 
140  const TDataScale& scale_deriv(size_t i, size_t s, size_t ip, size_t fct, size_t dof) const
141  {
142  UG_ASSERT(i < m_vpScaleDependData.size(), "Input not needed");
143  UG_ASSERT(m_vpScaleDependData[i].valid(), "Input invalid");
144  return m_vpScaleDependData[i]->deriv(this->series_id(2*i+1,s), ip, fct, dof);
145  }
146 
148  size_t input_num_fct(size_t i) const {return base_type::input_num_fct(2*i);}
149 
151  size_t input_common_fct(size_t i, size_t fct) const {return base_type::input_common_fct(2*i, fct);}
152 
154  size_t scale_num_fct(size_t i) const {return base_type::input_num_fct(2*i+1);}
155 
157  size_t scale_common_fct(size_t i, size_t fct) const {return base_type::input_common_fct(2*i+1, fct);}
158 
159  protected:
161  std::vector<SmartPtr<CplUserData<TDataScale, dim> > > m_vpScaleData;
162 
164  std::vector<SmartPtr<DependentUserData<TDataScale, dim> > > m_vpScaleDependData;
165 
167  std::vector<SmartPtr<CplUserData<TData, dim> > > m_vpUserData;
168 
170  std::vector<SmartPtr<DependentUserData<TData, dim> > > m_vpDependData;
171 };
172 
173 } // end namespace ug
174 
175 #include "scale_add_linker_impl.h"
176 
177 #endif /* __H__UG__LIB_DISC__SPATIAL_DISC__SCALE_ADD_LINKER__ */
parameterString s
Definition: smart_pointer.h:108
Type based UserData.
Definition: user_data.h:501
const TData & value(size_t s, size_t ip) const
returns the value at ip
Definition: user_data.h:512
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition: grid_base_objects.h:157
const MathVector< dim > & ip(size_t s, size_t ip) const
returns global ip
Definition: user_data.h:401
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:52
Definition: scale_add_linker.h:61
std::vector< SmartPtr< CplUserData< TData, dim > > > m_vpUserData
data input
Definition: scale_add_linker.h:167
size_t scale_num_fct(size_t i) const
returns number of functions the scaling depends on
Definition: scale_add_linker.h:154
size_t input_common_fct(size_t i, size_t fct) const
returns the number in the common FctGrp for a fct of an input
Definition: scale_add_linker.h:151
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
StdDataLinker< ScaleAddLinker< TData, dim, TDataScale, TRet >, TRet, dim > base_type
Definition: scale_add_linker.h:64
const TDataScale & scale_deriv(size_t i, size_t s, size_t ip, size_t fct, size_t dof) const
derivative of data at input at ip
Definition: scale_add_linker.h:140
const TData & input_deriv(size_t i, size_t s, size_t ip, size_t fct, size_t dof) const
derivative of data at input at ip
Definition: scale_add_linker.h:124
std::vector< SmartPtr< DependentUserData< TDataScale, dim > > > m_vpScaleDependData
data input casted to dependend data
Definition: scale_add_linker.h:164
void add(SmartPtr< CplUserData< TDataScale, dim > > scale, SmartPtr< CplUserData< TData, dim > > data)
Definition: scale_add_linker_impl.h:62
size_t input_num_fct(size_t i) const
returns number of functions the input depends on
Definition: scale_add_linker.h:148
const TData & input_value(size_t i, size_t s, size_t ip) const
data at ip of input
Definition: scale_add_linker.h:116
std::vector< SmartPtr< DependentUserData< TData, dim > > > m_vpDependData
data input casted to dependend data
Definition: scale_add_linker.h:170
void evaluate(TRet &value, const MathVector< dim > &globIP, number time, int si) const
Definition: scale_add_linker_impl.h:114
size_t scale_common_fct(size_t i, size_t fct) const
returns the number in the common FctGrp for a fct of a scaling
Definition: scale_add_linker.h:157
ScaleAddLinker()
constructor
Definition: scale_add_linker.h:68
const TDataScale & scale_value(size_t i, size_t s, size_t ip) const
scale at ip of input
Definition: scale_add_linker.h:132
combines several UserDatas to a new UserData of a specified type
Definition: linker.h:54
size_t series_id(size_t i, size_t s) const
returns the series id set for the i'th input
Definition: linker.h:161
size_t input_common_fct(size_t i, size_t fct) const
returns the number in the common FctGrp for a fct of an input
Definition: linker.h:153
size_t input_num_fct(size_t i) const
returns number of functions the input depends on
Definition: linker.h:145
static const int dim
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
double number
Definition: types.h:124
the ug namespace