Plugins
Loading...
Searching...
No Matches
ls_darcy_velocity_linker.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013-2015: G-CSC, Goethe University Frankfurt
3 * Author: Dmitry Logashenko
4 * Based on the module by Andreas Vogel.
5 *
6 * This file is part of UG4.
7 *
8 * UG4 is free software: you can redistribute it and/or modify it under the
9 * terms of the GNU Lesser General Public License version 3 (as published by the
10 * Free Software Foundation) with the following additional attribution
11 * requirements (according to LGPL/GPL v3 §7):
12 *
13 * (1) The following notice must be displayed in the Appropriate Legal Notices
14 * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
15 *
16 * (2) The following notice must be displayed at a prominent place in the
17 * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
18 *
19 * (3) The following bibliography is recommended for citation and must be
20 * preserved in all covered files:
21 * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
22 * parallel geometric multigrid solver on hierarchically distributed grids.
23 * Computing and visualization in science 16, 4 (2013), 151-164"
24 * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
25 * flexible software system for simulating pde based models on high performance
26 * computers. Computing and visualization in science 16, 4 (2013), 165-179"
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU Lesser General Public License for more details.
32 */
33
34#ifndef __H__UG__PLUGINS__LEVEL_SET_DARCY_VELOCITY_LINKER__
35#define __H__UG__PLUGINS__LEVEL_SET_DARCY_VELOCITY_LINKER__
36
37// ug4 headers
40
41namespace ug{
42namespace LevelSet {
43
45// Darcy Velocity linker
47
49
65template <typename TDomain, typename TAlgebra>
67 : public StdDataLinker<LSDarcyVelocityLinker<TDomain, TAlgebra>, MathVector<TDomain::dim>, TDomain::dim>
68{
69 // domain type
70 typedef TDomain domain_type;
71
72 // algebra type
73 typedef TAlgebra algebra_type;
74
75 // world dimension
76 static const int dim = domain_type::dim;
77
78 // Base class type
80
81 // extrapolation type
83
84 public:
86 m_spExtrapolation(spExtrapol),
88 m_spViscosity(NULL), m_spDViscosity(NULL),
89 m_spDensity(NULL), m_spDDensity(NULL),
90 m_spGravity(NULL), m_spDGravity(NULL),
92 {
93 // this linker needs exactly five input
94 this->set_num_input(5);
95 }
96
97 private:
98 // checks whether the element is cut
100 (
101 GridObject * elem,
102 int si,
103 const MathVector<dim> vCornerCoords[],
104 number time
105 ) const
106 {
107 if(m_spExtrapolation.valid())
108 {
109 const ReferenceObjectID roid = elem->reference_object_id();
110 const DimReferenceElement<dim>& rRefElem = ReferenceElementProvider::get<dim>(roid);
111 return ((extrapol_type *) m_spExtrapolation.get())->check_elem_lsf
112 (rRefElem.num(0), elem, si, false, vCornerCoords, time);
113 }
114 return 1;
115 }
116
117 public:
118
120 const MathVector<dim>& globIP,
121 number time, int si) const
122 {
123 UG_THROW ("LSDarcyVelocityLinker: Element is necessary for the evaluation.");
124 }
125
126 template <int refDim>
127 inline void evaluate(MathVector<dim> vValue[],
128 const MathVector<dim> vGlobIP[],
129 number time, int si,
130 GridObject* elem,
131 const MathVector<dim> vCornerCoords[],
132 const MathVector<refDim> vLocIP[],
133 const size_t nip,
134 LocalVector* u,
135 const MathMatrix<refDim, dim>* vJT = NULL) const
136 {
137 if (elem_cut (elem, si, vCornerCoords, time) < 0) // if above the free surface
138 {
139 for(size_t ip = 0; ip < nip; ++ip) vValue[ip] = 0.0;
140 return;
141 }
142
143 std::vector<number> vDensity(nip);
144 std::vector<number> vViscosity(nip);
145 std::vector<MathVector<dim> > vGravity(nip);
146 std::vector<MathVector<dim> > vPressureGrad(nip);
147 std::vector<MathMatrix<dim,dim> > vPermeability(nip);
148
149 (*m_spDensity)(&vDensity[0], vGlobIP, time, si,
150 elem, vCornerCoords, vLocIP, nip, u, vJT);
151 (*m_spViscosity)(&vViscosity[0], vGlobIP, time, si,
152 elem, vCornerCoords, vLocIP, nip, u, vJT);
153 (*m_spGravity)(&vGravity[0], vGlobIP, time, si,
154 elem, vCornerCoords, vLocIP, nip, u, vJT);
155 (*m_spPressureGrad)(&vPressureGrad[0], vGlobIP, time, si,
156 elem, vCornerCoords, vLocIP, nip, u, vJT);
157 (*m_spPermeability)(&vPermeability[0], vGlobIP, time, si,
158 elem, vCornerCoords, vLocIP, nip, u, vJT);
159
160 for(size_t ip = 0; ip < nip; ++ip)
161 {
162 // Variables
163 MathVector<dim> Vel;
164
165 // compute rho*g
166 VecScale(Vel, vGravity[ip], vDensity[ip]);
167
168 // compute rho*g - \nabla p
169 VecSubtract(Vel, Vel, vPressureGrad[ip]);
170
171 // compute Darcy velocity q := K / mu * (rho*g - \nabla p)
172 MatVecMult(vValue[ip], vPermeability[ip], Vel);
173 VecScale(vValue[ip], vValue[ip], 1./vViscosity[ip]);
174 }
175 }
176
177 template <int refDim>
179 const MathVector<dim> vGlobIP[],
180 number time, int si,
181 GridObject* elem,
182 const MathVector<dim> vCornerCoords[],
183 const MathVector<refDim> vLocIP[],
184 const size_t nip,
185 LocalVector* u,
186 bool bDeriv,
187 int s,
188 std::vector<std::vector<MathVector<dim> > > vvvDeriv[],
189 const MathMatrix<refDim, dim>* vJT = NULL) const
190 {
191 if (elem_cut (elem, si, vCornerCoords, time) < 0) // if above the free surface
192 {
193 for(size_t ip = 0; ip < nip; ++ip) vDarcyVel[ip] = 0.0;
194 if(!bDeriv || this->zero_derivative()) return;
195 this->set_zero(vvvDeriv, nip);
196 return;
197 }
198
199 // get the data of the ip series
200 const number* vDensity = m_spDensity->values(s);
201 const number* vViscosity = m_spViscosity->values(s);
202 const MathVector<dim>* vGravity = m_spGravity->values(s);
203 const MathVector<dim>* vPressureGrad = m_spPressureGrad->values(s);
204 const MathMatrix<dim,dim>* vPermeability = m_spPermeability->values(s);
205
206 for(size_t ip = 0; ip < nip; ++ip)
207 {
208 // Variables
209 MathVector<dim> Vel;
210
211 // compute rho*g
212 VecScale(Vel, vGravity[ip], vDensity[ip]);
213
214 // compute rho*g - \nabla p
215 VecSubtract(Vel, Vel, vPressureGrad[ip]);
216
217 // compute Darcy velocity q := K / mu * (rho*g - \nabla p)
218 MatVecMult(vDarcyVel[ip], vPermeability[ip], Vel);
219 VecScale(vDarcyVel[ip], vDarcyVel[ip], 1./vViscosity[ip]);
220 }
221
222 // Compute the derivatives at all ips //
224
225 // check if something to do
226 if(!bDeriv || this->zero_derivative()) return;
227
228 // clear all derivative values
229 this->set_zero(vvvDeriv, nip);
230
231 // Derivatives of Viscosity
232 if(m_spDViscosity.valid() && !m_spDViscosity->zero_derivative())
233 for(size_t ip = 0; ip < nip; ++ip)
234 for(size_t fct = 0; fct < m_spDViscosity->num_fct(); ++fct)
235 {
236 // get derivative of viscosity w.r.t. to all functions
237 const number* vDViscosity = m_spDViscosity->deriv(s, ip, fct);
238
239 // get common fct id for this function
240 const size_t commonFct = this->input_common_fct(_MU_, fct);
241
242 // loop all shapes and set the derivative
243 for(size_t sh = 0; sh < this->num_sh(commonFct); ++sh)
244 {
245 // DarcyVel_fct[sh] -= mu_fct_sh / mu * q
246 VecScaleAppend(vvvDeriv[ip][commonFct][sh], -vDViscosity[sh] / vViscosity[ip], vDarcyVel[ip]);
247 }
248 }
249
250 // Derivatives of Density
251 if(m_spDDensity.valid() && !m_spDDensity->zero_derivative())
252 for(size_t ip = 0; ip < nip; ++ip)
253 for(size_t fct = 0; fct < m_spDDensity->num_fct(); ++fct)
254 {
255 // get derivative of viscosity w.r.t. to all functions
256 const number* vDDensity = m_spDDensity->deriv(s, ip, fct);
257
258 // get common fct id for this function
259 const size_t commonFct = this->input_common_fct(_RHO_, fct);
260
261 // Precompute K/mu * g
262 MathVector<dim> Kmug;
263
264 // a) compute K * g
265 MatVecMult(Kmug, vPermeability[ip], vGravity[ip]);
266
267 // b) compute K* g / mu
268 VecScale(Kmug, Kmug, 1./vViscosity[ip]);
269
270 // loop all shapes and set the derivative
271 for(size_t sh = 0; sh < this->num_sh(commonFct); ++sh)
272 {
273 UG_ASSERT(commonFct < vvvDeriv[ip].size(), commonFct<<", "<<vvvDeriv[ip].size());
274 UG_ASSERT(sh < vvvDeriv[ip][commonFct].size(), sh<<", "<<vvvDeriv[ip][commonFct].size());
275 // DarcyVel_fct[sh] += K/mu * (rho_fct_sh * g)
276 VecScaleAppend(vvvDeriv[ip][commonFct][sh],
277 vDDensity[sh], Kmug);
278 }
279 }
280
281 // Derivatives of Gravity
282 if(m_spDGravity.valid() && !m_spDGravity->zero_derivative())
283 for(size_t ip = 0; ip < nip; ++ip)
284 for(size_t fct = 0; fct < m_spDGravity->num_fct(); ++fct)
285 {
286 // get derivative of viscosity w.r.t. to all functions
287 const MathVector<dim>* vDGravity = m_spDGravity->deriv(s, ip, fct);
288
289 // get common fct id for this function
290 const size_t commonFct = this->input_common_fct(_G_, fct);
291
292 // Precompute K/mu * rho
293 MathMatrix<dim,dim> Kmurho;
294
295 // a) compute K/mu * rho
296 MatScale(Kmurho, vDensity[ip]/vViscosity[ip],vPermeability[ip]);
297
298 // loop all shapes and set the derivative
299 for(size_t sh = 0; sh < this->num_sh(commonFct); ++sh)
300 {
301 MathVector<dim> tmp;
302 MatVecMult(tmp, Kmurho, vDGravity[sh]);
303
304 vvvDeriv[ip][commonFct][sh] += tmp;
305 }
306 }
307
308 // Derivatives of Pressure
309 if(m_spDPressureGrad.valid() && !m_spDPressureGrad->zero_derivative())
310 for(size_t ip = 0; ip < nip; ++ip)
311 for(size_t fct = 0; fct < m_spDPressureGrad->num_fct(); ++fct)
312 {
313 // get derivative of viscosity w.r.t. to all functions
314 const MathVector<dim>* vDPressureGrad = m_spDPressureGrad->deriv(s, ip, fct);
315
316 // get common fct id for this function
317 const size_t commonFct = this->input_common_fct(_DP_, fct);
318
319 // Precompute -K/mu
321
322 // a) compute -K/mu
323 MatScale(Kmu, -1.0/vViscosity[ip],vPermeability[ip]);
324
325 // loop all shapes and set the derivative
326 for(size_t sh = 0; sh < this->num_sh(commonFct); ++sh)
327 {
328 MathVector<dim> tmp;
329 MatVecMult(tmp, Kmu, vDPressureGrad[sh]);
330
331 vvvDeriv[ip][commonFct][sh] += tmp;
332 }
333 }
334
335 // Derivatives of Permeability
336 if(m_spDPermeability.valid() && !m_spDPermeability->zero_derivative())
337 for(size_t ip = 0; ip < nip; ++ip)
338 for(size_t fct = 0; fct < m_spDPermeability->num_fct(); ++fct)
339 {
340 // get derivative of viscosity w.r.t. to all functions
341 const MathMatrix<dim,dim>* vDPermeability = m_spDPermeability->deriv(s, ip, fct);
342
343 // get common fct id for this function
344 const size_t commonFct = this->input_common_fct(_K_, fct);
345
346 // Variables
347 MathVector<dim> Vel;
348
349 // compute rho*g
350 VecScale(Vel, vGravity[ip], vDensity[ip]);
351
352 // compute rho*g - \nabla p
353 VecSubtract(Vel, Vel, vPressureGrad[ip]);
354
355 // compute Darcy velocity q := K / mu * (rho*g - \nabla p)
356 VecScale(Vel, Vel, 1./vViscosity[ip]);
357
358 // loop all shapes and set the derivative
359 for(size_t sh = 0; sh < this->num_sh(commonFct); ++sh)
360 {
361 MathVector<dim> tmp;
362 MatVecMult(tmp, vDPermeability[sh], Vel);
363
364 vvvDeriv[ip][commonFct][sh] += tmp;
365 }
366 }
367 }
368
369 public:
372 {
373 m_spPermeability = data;
374 m_spDPermeability = data.template cast_dynamic<DependentUserData<MathMatrix<dim,dim>, dim> >();
375 base_type::set_input(_K_, data, data);
376 }
377
382
385 {
386 m_spViscosity = data;
387 m_spDViscosity = data.template cast_dynamic<DependentUserData<number, dim> >();
388 base_type::set_input(_MU_, data, data);
389 }
390
392 {
394 }
395
398 {
399 m_spDensity = data;
400 m_spDDensity = data.template cast_dynamic<DependentUserData<number, dim> >();
401 base_type::set_input(_RHO_, data, data);
402 }
403
405 {
407 }
408
411 {
412 m_spGravity = data;
413 m_spDGravity = data.template cast_dynamic<DependentUserData<MathVector<dim>, dim> >();
414 base_type::set_input(_G_, data, data);
415 }
416
419 {
420 m_spPressureGrad = data;
421 m_spDPressureGrad = data.template cast_dynamic<DependentUserData<MathVector<dim>, dim> >();
422 base_type::set_input(_DP_, data, data);
423 }
424
425 protected:
428
430 static const size_t _K_ = 0;
433
435 static const size_t _MU_ = 1;
438
440 static const size_t _RHO_ = 2;
443
445 static const size_t _G_ = 3;
448
450 static const size_t _DP_ = 4;
453};
454
455} // end namespace LevelSet
456} // end namespace ug
457
458#endif /* __H__UG__PLUGINS__LEVEL_SET_DARCY_VELOCITY_LINKER__ */
parameterString s
Definition Biogas.lua:2
TData & value(size_t s, size_t ip)
virtual ReferenceObjectID reference_object_id() const=0
number time() const
const MathVector< dim > & ip(size_t s, size_t ip) const
Linker for the Darcy velocity in a domain with a free surface specified by the level-set.
Definition ls_darcy_velocity_linker.h:68
SmartPtr< extrapol_type > m_spExtrapolation
extrapolation by the level-set function
Definition ls_darcy_velocity_linker.h:427
void eval_and_deriv(MathVector< dim > vDarcyVel[], 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
Definition ls_darcy_velocity_linker.h:178
LSDarcyVelocityLinker(SmartPtr< extrapol_type > spExtrapol)
Definition ls_darcy_velocity_linker.h:85
static const size_t _K_
import for permeability
Definition ls_darcy_velocity_linker.h:430
void evaluate(MathVector< dim > &value, const MathVector< dim > &globIP, number time, int si) const
Definition ls_darcy_velocity_linker.h:119
int elem_cut(GridObject *elem, int si, const MathVector< dim > vCornerCoords[], number time) const
Definition ls_darcy_velocity_linker.h:100
SmartPtr< DependentUserData< MathVector< dim >, dim > > m_spDGravity
Definition ls_darcy_velocity_linker.h:447
IInterfaceExtrapolation< domain_type, algebra_type > extrapol_type
Definition ls_darcy_velocity_linker.h:82
static const size_t _DP_
import for pressure gradient
Definition ls_darcy_velocity_linker.h:450
void set_permeability(number val)
Definition ls_darcy_velocity_linker.h:378
void set_density(SmartPtr< CplUserData< number, dim > > data)
set density import
Definition ls_darcy_velocity_linker.h:397
void set_viscosity(SmartPtr< CplUserData< number, dim > > data)
set permeability import
Definition ls_darcy_velocity_linker.h:384
void set_pressure_gradient(SmartPtr< CplUserData< MathVector< dim >, dim > > data)
set pressure gradient import
Definition ls_darcy_velocity_linker.h:418
static const size_t _G_
import for gravity
Definition ls_darcy_velocity_linker.h:445
SmartPtr< DependentUserData< MathMatrix< dim, dim >, dim > > m_spDPermeability
Definition ls_darcy_velocity_linker.h:432
StdDataLinker< LSDarcyVelocityLinker< domain_type, algebra_type >, MathVector< dim >, dim > base_type
Definition ls_darcy_velocity_linker.h:79
void set_density(number val)
Definition ls_darcy_velocity_linker.h:404
static const int dim
Definition ls_darcy_velocity_linker.h:76
void set_viscosity(number val)
Definition ls_darcy_velocity_linker.h:391
SmartPtr< DependentUserData< MathVector< dim >, dim > > m_spDPressureGrad
Definition ls_darcy_velocity_linker.h:452
TAlgebra algebra_type
Definition ls_darcy_velocity_linker.h:73
SmartPtr< DependentUserData< number, dim > > m_spDDensity
Definition ls_darcy_velocity_linker.h:442
SmartPtr< CplUserData< number, dim > > m_spDensity
Definition ls_darcy_velocity_linker.h:441
static const size_t _MU_
import for viscosity
Definition ls_darcy_velocity_linker.h:435
void evaluate(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, const MathMatrix< refDim, dim > *vJT=NULL) const
Definition ls_darcy_velocity_linker.h:127
SmartPtr< CplUserData< MathVector< dim >, dim > > m_spPressureGrad
Definition ls_darcy_velocity_linker.h:451
SmartPtr< CplUserData< MathMatrix< dim, dim >, dim > > m_spPermeability
Definition ls_darcy_velocity_linker.h:431
void set_gravity(SmartPtr< CplUserData< MathVector< dim >, dim > > data)
set gravity import
Definition ls_darcy_velocity_linker.h:410
SmartPtr< DependentUserData< number, dim > > m_spDViscosity
Definition ls_darcy_velocity_linker.h:437
void set_permeability(SmartPtr< CplUserData< MathMatrix< dim, dim >, dim > > data)
set permeability import
Definition ls_darcy_velocity_linker.h:371
SmartPtr< CplUserData< MathVector< dim >, dim > > m_spGravity
Definition ls_darcy_velocity_linker.h:446
TDomain domain_type
Definition ls_darcy_velocity_linker.h:70
SmartPtr< CplUserData< number, dim > > m_spViscosity
Definition ls_darcy_velocity_linker.h:436
static const size_t _RHO_
import for density
Definition ls_darcy_velocity_linker.h:440
size_t num(int dim) const
virtual void set_input(size_t i, SmartPtr< ICplUserData< dim > > input, SmartPtr< UserDataInfo > info)
void MatScale(matrix_t &mOut, typename matrix_t::value_type s, const matrix_t &m)
#define UG_ASSERT(expr, msg)
#define UG_THROW(msg)
double number
void MatVecMult(vector_t_out &vOut, const matrix_t &m, const vector_t_in &v)
void VecScaleAppend(vector_t &vOut, typename vector_t::value_type s1, const vector_t &v1)
void VecSubtract(vector_t &vOut, const vector_t &v, typename vector_t::value_type s)
void VecScale(vector_t &vOut, const vector_t &v, typename vector_t::value_type s)
ReferenceObjectID
SmartPtr< T, FreePolicy > make_sp(T *inst)