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__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 :
41 : ////////////////////////////////////////////////////////////////////////////////
42 : // Scaled adding of Data
43 : ////////////////////////////////////////////////////////////////////////////////
44 :
45 : /**
46 : * This linker recombines the data like
47 : *
48 : * l = s_1 * i_1 + ... + s_k * i_k
49 : *
50 : * where, l, i_1, ..., i_k are of the same data type and the s_i are some
51 : * scaling factor of a (possibly) different type, that is applicable to the
52 : * data type
53 : *
54 : * \tparam TData exported and combined Data type
55 : * \tparam dim world dimension
56 : * \tparam TDataScale type of scaling data
57 : */
58 : template <typename TData, int dim, typename TDataScale, typename TRet = TData>
59 : class ScaleAddLinker
60 : : public StdDataLinker<ScaleAddLinker<TData, dim, TDataScale, TRet>, TRet, dim>
61 : {
62 : public:
63 : // type of base class
64 : typedef StdDataLinker<ScaleAddLinker<TData, dim, TDataScale, TRet>, TRet, dim> base_type;
65 :
66 : public:
67 : /// constructor
68 0 : ScaleAddLinker() {}
69 :
70 : /// constructor
71 : ScaleAddLinker(const ScaleAddLinker& linker);
72 :
73 : /// adds an input to the list of summands scaled by a user data factor
74 : /// \{
75 : void add(SmartPtr<CplUserData<TDataScale, dim> > scale,
76 : SmartPtr<CplUserData<TData, dim> > data);
77 : void add(number scale,
78 : SmartPtr<CplUserData<TData, dim> > data);
79 : void add(SmartPtr<CplUserData<TDataScale, dim> > scale,
80 : number data);
81 : void add(number scale,
82 : number data);
83 : /// \}
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:
115 : /// data at ip of input
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 :
123 : /// derivative of data at input at ip
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 :
131 : /// scale at ip of input
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 :
139 : /// derivative of data at input at ip
140 0 : 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 0 : return m_vpScaleDependData[i]->deriv(this->series_id(2*i+1,s), ip, fct, dof);
145 : }
146 :
147 : /// returns number of functions the input depends on
148 : size_t input_num_fct(size_t i) const {return base_type::input_num_fct(2*i);}
149 :
150 : /// returns the number in the common FctGrp for a fct of an input
151 : size_t input_common_fct(size_t i, size_t fct) const {return base_type::input_common_fct(2*i, fct);}
152 :
153 : /// returns number of functions the scaling depends on
154 : size_t scale_num_fct(size_t i) const {return base_type::input_num_fct(2*i+1);}
155 :
156 : /// returns the number in the common FctGrp for a fct of a scaling
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:
160 : /// data input
161 : std::vector<SmartPtr<CplUserData<TDataScale, dim> > > m_vpScaleData;
162 :
163 : /// data input casted to dependend data
164 : std::vector<SmartPtr<DependentUserData<TDataScale, dim> > > m_vpScaleDependData;
165 :
166 : /// data input
167 : std::vector<SmartPtr<CplUserData<TData, dim> > > m_vpUserData;
168 :
169 : /// data input casted to dependend data
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__ */
|