Plugins
Loading...
Searching...
No Matches
normvel_util.h
Go to the documentation of this file.
1/*
2 * Author: Dmitry Logashenko
3 *
4 * This file is part of UG4.
5 *
6 * UG4 is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU Lesser General Public License version 3 (as published by the
8 * Free Software Foundation) with the following additional attribution
9 * requirements (according to LGPL/GPL v3 §7):
10 *
11 * (1) The following notice must be displayed in the Appropriate Legal Notices
12 * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
13 *
14 * (2) The following notice must be displayed at a prominent place in the
15 * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
16 *
17 * (3) The following bibliography is recommended for citation and must be
18 * preserved in all covered files:
19 * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
20 * parallel geometric multigrid solver on hierarchically distributed grids.
21 * Computing and visualization in science 16, 4 (2013), 151-164"
22 * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
23 * flexible software system for simulating pde based models on high performance
24 * computers. Computing and visualization in science 16, 4 (2013), 165-179"
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU Lesser General Public License for more details.
30 */
31
32/*
33 * Utilities for the computation of the vector velocity from the normal velocity.
34 */
35
36#ifndef __H__UG__PLUGINS__LEVEL_SET__NORMVEL_UTIL_H__
37#define __H__UG__PLUGINS__LEVEL_SET__NORMVEL_UTIL_H__
38
39// ug4 headers
43
44namespace ug{
45namespace LevelSet{
46
50template <typename TGridFunc>
53 <EikonalVel<TGridFunc>, MathVector<TGridFunc::dim>, TGridFunc::dim>
54{
55public:
57 typedef typename TGridFunc::domain_type domain_type;
58
60 static const int dim = domain_type::dim;
61
63 typedef typename domain_type::position_type position_type;
64
65private:
68
71
74
75public:
78 (
80 )
81 : m_spVelPot (spPot), m_scaling (1)
82 {
83 // local finite element ids
84 m_lfeID = m_spVelPot->local_finite_element_id(0);
85 };
86
89
91 virtual bool continuous () const {return false;}
92
94 virtual bool zero_derivative () const {return true;}
95
97 virtual bool requires_grid_fct () const {return true;}
98
100 template <int refDim>
102 (
103 MathVector<dim> vValue[],
104 const MathVector<dim> vGlobIP[],
105 number time,
106 int si,
107 GridObject * elem,
108 const MathVector<dim> vCornerCoords[],
109 const MathVector<refDim> vLocIP[],
110 const size_t nip,
111 LocalVector * u,
112 bool bDeriv,
113 int s,
114 std::vector<std::vector<MathVector<dim> > > vvvDeriv[],
115 const MathMatrix<refDim, dim> * vJT = NULL
116 ) const
117 {
118 // Derivatives are not implemented
119 if (bDeriv)
120 UG_THROW ("EikonalVel: Derivatives are not implemented.");
121
122 // reference object id
123 const ReferenceObjectID roid = elem->reference_object_id();
124
125 // compute the local -> global trannsformation if it is not given
126 std::vector<MathMatrix<refDim, dim> > vJTTmp(nip);
127 if(vJT == NULL)
128 {
130 = ReferenceMappingProvider::get<refDim, dim> (roid, vCornerCoords);
131 mapping.jacobian_transposed(&(vJTTmp[0]), vLocIP, nip);
132 vJT = &(vJTTmp[0]);
133 }
134
135 // the shape functions
136 const LocalShapeFunctionSet<refDim>& rTrialSpace =
137 LocalFiniteElementProvider::get<refDim>(roid, m_lfeID);
138
139 // memory for gradients and indices
140 std::vector<DoFIndex> ind;
141 std::vector<MathVector<refDim> > vLocGrad;
142 MathVector<refDim> locGrad;
143
144 // Reference Mapping
146
147 // loop the integration points
148 for(size_t ip = 0; ip < nip; ++ip)
149 {
150 // compute the direction of the velocity
151 MathVector<dim> grad;
152
153 // a) evaluate at shapes at ip
154 rTrialSpace.grads(vLocGrad, vLocIP[ip]);
155
156 // b) get multiindices of element
157 std::vector<DoFIndex > ind;
158 m_spVelPot->dof_indices(elem, 0, ind);
159
160 // compute grad at ip
161 VecSet(locGrad, 0.0);
162 for(size_t sh = 0; sh < vLocGrad.size(); ++sh)
163 VecScaleAppend(locGrad, DoFRef (*m_spVelPot, ind[sh]), vLocGrad[sh]);
164
165 RightInverse (JTInv, vJT[ip]);
166 MatVecMult(grad, JTInv, locGrad);
167
168 // compute the velocity vector
169 number len = VecLength (grad);
170 if (len > 1e-15)
171 VecScale (vValue[ip], grad, m_scaling / len);
172 else
173 VecSet (vValue[ip], 0.0);
174 }
175 };
176};
177
181template <typename TGridFunc>
183 : public StdDependentUserData
184 <VelByNormalVel<TGridFunc>, MathVector<TGridFunc::dim>, TGridFunc::dim>
185{
186public:
188 typedef typename TGridFunc::domain_type domain_type;
189
191 static const int dim = domain_type::dim;
192
194 typedef typename domain_type::position_type position_type;
195
196private:
199
202
205
206public:
209 (
212 )
213 : m_spNV (spNV), m_spVelPot (spPot)
214 {
215 // local finite element ids
216 LFEID lfeID_nv = m_spNV->local_finite_element_id(0);
217 LFEID lfeID_pot = m_spVelPot->local_finite_element_id(0);
218
219 if (lfeID_nv != lfeID_pot)
220 UG_THROW ("VelByNormalVel: Both grid functions should have the same approx. spaces");
221 m_lfeID = lfeID_nv;
222 };
223
225 virtual bool continuous () const {return false;}
226
228 virtual bool zero_derivative () const {return true;}
229
231 virtual bool requires_grid_fct () const {return true;}
232
234 template <int refDim>
236 (
237 MathVector<dim> vValue[],
238 const MathVector<dim> vGlobIP[],
239 number time,
240 int si,
241 GridObject * elem,
242 const MathVector<dim> vCornerCoords[],
243 const MathVector<refDim> vLocIP[],
244 const size_t nip,
245 LocalVector * u,
246 bool bDeriv,
247 int s,
248 std::vector<std::vector<MathVector<dim> > > vvvDeriv[],
249 const MathMatrix<refDim, dim> * vJT = NULL
250 ) const
251 {
252 // Derivatives are not implemented
253 if (bDeriv)
254 UG_THROW ("VelByNormalVel: Derivatives are not implemented.");
255
256 // reference object id
257 const ReferenceObjectID roid = elem->reference_object_id();
258
259 // compute the local -> global trannsformation if it is not given
260 std::vector<MathMatrix<refDim, dim> > vJTTmp(nip);
261 if(vJT == NULL)
262 {
264 = ReferenceMappingProvider::get<refDim, dim> (roid, vCornerCoords);
265 mapping.jacobian_transposed(&(vJTTmp[0]), vLocIP, nip);
266 vJT = &(vJTTmp[0]);
267 }
268
269 // the shape functions
270 const LocalShapeFunctionSet<refDim>& rTrialSpace =
271 LocalFiniteElementProvider::get<refDim>(roid, m_lfeID);
272
273 // memory for shapes, gradients and indices
274 std::vector<number> vShape;
275 std::vector<DoFIndex> ind;
276 std::vector<MathVector<refDim> > vLocGrad;
277 MathVector<refDim> locGrad;
278
279 // Reference Mapping
281
282 // loop the integration points
283 for(size_t ip = 0; ip < nip; ++ip)
284 {
285 // compute the normal velocity:
286 number nv = 0;
287
288 // a) evaluate at shapes at ip
289 rTrialSpace.shapes(vShape, vLocIP[ip]);
290
291 // b) get multiindices of element
292 m_spNV->dof_indices(elem, 0, ind);
293
294 // c) compute solution at integration point
295 for(size_t sh = 0; sh < vShape.size(); ++sh)
296 nv += DoFRef(*m_spNV, ind[sh]) * vShape[sh];
297
298 // compute the direction of the velocity
299 MathVector<dim> grad;
300
301 // a) evaluate at shapes at ip
302 rTrialSpace.grads(vLocGrad, vLocIP[ip]);
303
304 // b) get multiindices of element
305 m_spVelPot->dof_indices(elem, 0, ind);
306
307 // compute grad at ip
308 VecSet(locGrad, 0.0);
309 for(size_t sh = 0; sh < vLocGrad.size(); ++sh)
310 VecScaleAppend(locGrad, DoFRef (*m_spVelPot, ind[sh]), vLocGrad[sh]);
311
312 RightInverse (JTInv, vJT[ip]);
313 MatVecMult(grad, JTInv, locGrad);
314
315 // compute the velocity vector
316 number len = VecLength (grad);
317 if (len > 1e-15)
318 VecScale (vValue[ip], grad, nv / len);
319 else
320 VecSet (vValue[ip], 0.0);
321 }
322 };
323};
324
325} // end namespace LevelSet
326} // end namespace ug
327
328#endif // __H__UG__PLUGINS__LEVEL_SET__NORMVEL_UTIL_H__
329
330/* End of File */
parameterString s
Definition Biogas.lua:2
virtual void jacobian_transposed(MathMatrix< dim, worldDim > &JT, const MathVector< dim > &locPos) const=0
virtual ReferenceObjectID reference_object_id() const=0
number time() const
const MathVector< dim > & ip(size_t s, size_t ip) const
Definition normvel_util.h:54
virtual bool requires_grid_fct() const
Returns true to get the grid element in the evaluation routine.
Definition normvel_util.h:97
TGridFunc::domain_type domain_type
Type of domain.
Definition normvel_util.h:57
number m_scaling
scaling factor for the velocity
Definition normvel_util.h:70
virtual bool continuous() const
The vector field of the gradients is not continuous over the sides of the elements.
Definition normvel_util.h:91
domain_type::position_type position_type
Type of position coordinates (e.g. position_type)
Definition normvel_util.h:63
void set_scaling(number v)
Set the scaling.
Definition normvel_util.h:88
virtual bool zero_derivative() const
No derivatives implemented.
Definition normvel_util.h:94
void eval_and_deriv(MathVector< dim > 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< MathVector< dim > > > vvvDeriv[], const MathMatrix< refDim, dim > *vJT=NULL) const
Performs the main computations:
Definition normvel_util.h:102
static const int dim
World dimension.
Definition normvel_util.h:60
EikonalVel(SmartPtr< TGridFunc > spPot)
constructor
Definition normvel_util.h:78
LFEID m_lfeID
local finite element id (assumed to be the same for both the functions)
Definition normvel_util.h:73
SmartPtr< TGridFunc > m_spVelPot
'potential' of the velocity: direction is its normalized gradient; typically the LSF
Definition normvel_util.h:67
Definition normvel_util.h:185
VelByNormalVel(SmartPtr< TGridFunc > spNV, SmartPtr< TGridFunc > spPot)
constructor
Definition normvel_util.h:209
domain_type::position_type position_type
Type of position coordinates (e.g. position_type)
Definition normvel_util.h:194
TGridFunc::domain_type domain_type
Type of domain.
Definition normvel_util.h:188
LFEID m_lfeID
local finite element id (assumed to be the same for both the functions)
Definition normvel_util.h:204
SmartPtr< TGridFunc > m_spVelPot
'potential' of the velocity: direction is its normalized gradient; typically the LSF
Definition normvel_util.h:201
virtual bool zero_derivative() const
No derivatives implemented.
Definition normvel_util.h:228
SmartPtr< TGridFunc > m_spNV
normal velocity
Definition normvel_util.h:198
virtual bool requires_grid_fct() const
Returns true to get the grid element in the evaluation routine.
Definition normvel_util.h:231
void eval_and_deriv(MathVector< dim > 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< MathVector< dim > > > vvvDeriv[], const MathMatrix< refDim, dim > *vJT=NULL) const
Performs the main computations:
Definition normvel_util.h:236
virtual bool continuous() const
The vector field of the gradients is not continuous over the sides of the elements.
Definition normvel_util.h:225
static const int dim
World dimension.
Definition normvel_util.h:191
virtual void grads(std::vector< std::vector< grad_type > > &vvGrad, const std::vector< MathVector< dim > > &vLocPos) const=0
virtual void shapes(std::vector< std::vector< shape_type > > &vvShape, const std::vector< MathVector< dim > > &vLocPos) const=0
MathMatrix< N, M, T >::value_type RightInverse(MathMatrix< N, M, T > &mOut, const MathMatrix< M, N, T > &m)
#define UG_THROW(msg)
double number
void MatVecMult(vector_t_out &vOut, const matrix_t &m, const vector_t_in &v)
vector_t::value_type VecLength(const vector_t &v)
void VecScaleAppend(vector_t &vOut, typename vector_t::value_type s1, const vector_t &v1)
void VecScale(vector_t &vOut, const vector_t &v, typename vector_t::value_type s)
ReferenceObjectID
const number & DoFRef(const TMatrix &mat, const DoFIndex &iInd, const DoFIndex &jInd)
void VecSet(vector_t &dest, number alpha, const std::vector< size_t > vIndex)