Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
bingham_viscosity_linker.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2015: G-CSC, Goethe University Frankfurt
3 * Author: Jonas Simon
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__BINGHAM_VISCOSITY_LINKER__
34#define __H__UG__LIB_DISC__SPATIAL_DISC__BINGHAM_VISCOSITY_LINKER__
35
36#include "linker.h"
37
38namespace ug{
39
40
42// Bingham Viscosity linker
44
46
59template <int dim>
61 : public StdDataLinker< BinghamViscosityLinker<dim>, number, dim>
62{
63 // Base class type
65
66 // Constructor
67 public:
69 m_spDensity(NULL), m_spDDensity(NULL),
70 m_spViscosity(NULL), m_spDViscosity(NULL),
73 {
74 // this linker needs exactly four input
75 this->set_num_input(4);
76 }
77
78 // function for evaluation at single ip?
79 inline void evaluate (number& value,
80 const MathVector<dim>& globIP,
81 number time, int si) const
82 {
83 UG_LOG("BinghamViscosityLinker::evaluate single called");
84 number density;
85 number viscosity;
86 number yieldStress;
87 MathMatrix<dim,dim> velocityGrad;
88
89 (*m_spDensity)(density, globIP, time, si);
90 (*m_spViscosity)(viscosity, globIP, time, si);
91 (*m_spYieldStress)(yieldStress, globIP, time, si);
92 (*m_spVelocityGrad)(velocityGrad, globIP, time, si);
93
94 number innerSum = 0.0;
95
96 // compute inner sum
97 for(int d1 = 0; d1 < dim; ++d1)
98 {
99 for(int d2 = 0; d2 < dim; ++d2)
100 {
101 innerSum += pow(velocityGrad(d1,d2) + velocityGrad(d2,d1),2);
102 }
103 }
104
105 // compute mu = eta + sigma / \sqrt( delta + 1 / I)
106 value = viscosity + yieldStress/sqrt(0.5+(1.0/(pow(2, dim))*innerSum));
107 value *= 1./density;
108 }
109
110 // function for evaluation at multiple ips??
111 template <int refDim>
112 inline void evaluate(number vValue[],
113 const MathVector<dim> vGlobIP[],
114 number time, int si,
115 GridObject* elem,
116 const MathVector<dim> vCornerCoords[],
117 const MathVector<refDim> vLocIP[],
118 const size_t nip,
119 LocalVector* u,
120 const MathMatrix<refDim, dim>* vJT = NULL) const
121 {
122 UG_LOG("BinghamViscosityLinker::evaluate called");
123 std::vector<number> vDensity(nip);
124 std::vector<number> vViscosity(nip);
125 std::vector<number> vYieldStress(nip);
126 std::vector<MathMatrix<dim,dim> > vVelocityGrad(nip);
127
128 (*m_spDensity)(&vDensity[0], vGlobIP, time, si,
129 elem, vCornerCoords, vLocIP, nip, u, vJT);
130 (*m_spViscosity)(&vViscosity[0], vGlobIP, time, si,
131 elem, vCornerCoords, vLocIP, nip, u, vJT);
132 (*m_spYieldStress)(&vYieldStress[0], vGlobIP, time, si,
133 elem, vCornerCoords, vLocIP, nip, u, vJT);
134 (*m_spVelocityGrad)(&vVelocityGrad[0], vGlobIP, time, si,
135 elem, vCornerCoords, vLocIP, nip, u, vJT);
136
137 for(size_t ip = 0; ip < nip; ++ip)
138 {
139 number mu = 0.0;
140
141 // compute inner sum
142 for(int d1 = 0; d1 < dim; ++d1)
143 {
144 for(int d2 = 0; d2 < dim; ++d2)
145 {
146 mu += pow(vVelocityGrad[ip](d1,d2) + vVelocityGrad[ip](d2,d1),2);
147 }
148 }
149
150 // compute mu = eta + sigma
151 mu = vViscosity[ip] + vYieldStress[ip]/sqrt(0.5+(1.0/(pow(2, dim))*mu));
152 vValue[ip] = mu * 1./vDensity[ip];
153 }
154 }
155
156 template <int refDim>
157 void eval_and_deriv(number vValue[],
158 const MathVector<dim> vGlobIP[],
159 number time, int si,
160 GridObject* elem,
161 const MathVector<dim> vCornerCoords[],
162 const MathVector<refDim> vLocIP[],
163 const size_t nip,
164 LocalVector* u,
165 bool bDeriv,
166 int s,
167 std::vector<std::vector<number> > vvvDeriv[],
168 const MathMatrix<refDim, dim>* vJT = NULL) const
169 {
170
171 UG_LOG("BinghamViscosityLinker::eval_and_deriv called");
172 // get the data of the ip series
173 const number* vDensity = m_spDensity->values(s);
174 const number* vViscosity = m_spViscosity->values(s);
175 const number* vYieldStress = m_spYieldStress->values(s);
176 const MathMatrix<dim,dim>* vVelocityGrad = m_spVelocityGrad->values(s);
177
178 for(size_t ip = 0; ip < nip; ++ip)
179 {
180 number mu = 0.0;
181
182 // compute mu =
183 for(int d1 = 0; d1 < dim; ++d1)
184 {
185 for(int d2 = 0; d2 < dim; ++d2)
186 {
187 mu += pow(vVelocityGrad[ip](d1,d2) + vVelocityGrad[ip](d2,d1),2);
188 }
189 }
190
191 // compute mu = (eta + tau_F / \sqrt(delta + TrD^2)) / rho
192 mu = vViscosity[ip] + vYieldStress[ip]/sqrt(0.5+(1.0/(pow(2, dim))*mu));
193 vValue[ip] = mu * 1./vDensity[ip];
194 }
195
196 // Compute the derivatives at all ips //
198
199 // check if something is left to do
200 if(!bDeriv || this->zero_derivative()) return;
201
202 // clear all derivative values
203 this->set_zero(vvvDeriv, nip);
204
205 // Derivatives of Density
206 if(m_spDDensity.valid() && !m_spDDensity->zero_derivative())
207 {
208 for(size_t ip = 0; ip < nip; ++ip)
209 {
210 for(size_t fct = 0; fct < m_spDDensity->num_fct(); ++fct)
211 {
212 // get derivative of density w.r.t. to all functions
213 const number* vDDensity = m_spDDensity->deriv(s, ip, fct);
214
215 // get common fct id for this function
216 const size_t commonFct = this->input_common_fct(_RHO_, fct);
217
218 // loop all shapes and set the derivative
219 for(size_t sh = 0; sh < this->num_sh(commonFct); ++sh)
220 {
221 vvvDeriv[ip][commonFct][sh] -= vDDensity[sh] / vDensity[ip] * vValue[ip];
222 }
223 }
224 }
225 }
226
227 // Derivatives of Viscosity
228 if(m_spDViscosity.valid() && !m_spDViscosity->zero_derivative())
229 {
230 for(size_t ip = 0; ip < nip; ++ip)
231 {
232 for(size_t fct = 0; fct < m_spDViscosity->num_fct(); ++fct)
233 {
234 // get derivative of viscosity w.r.t. to all functions
235 const number* vDViscosity = m_spDViscosity->deriv(s, ip, fct);
236
237 // get common fct id for this function
238 const size_t commonFct = this->input_common_fct(_ETA_, fct);
239
240 // loop all shapes and set the derivative
241 for(size_t sh = 0; sh < this->num_sh(commonFct); ++sh)
242 {
243 vvvDeriv[ip][commonFct][sh] += vDViscosity[sh] / vDensity[ip];
244 }
245 }
246 }
247 }
248
249 // Derivatives of yield stress
250 if(m_spDYieldStress.valid() && !m_spDYieldStress->zero_derivative())
251 {
252 for(size_t ip = 0; ip < nip; ++ip)
253 {
254 // Precompute 1 / (rho * \sqrt(delta + TrD^2))
255 number rInvariant = vValue[ip] - (vViscosity[ip] / vDensity[ip]);
256
257 for(size_t fct = 0; fct < m_spDYieldStress->num_fct(); ++fct)
258 {
259 // get derivative of yield stress w.r.t. to all functions
260 const number* vDYieldStress = m_spDYieldStress->deriv(s, ip, fct);
261
262 // get common fct id for this function
263 const size_t commonFct = this->input_common_fct(_TAU_, fct);
264
265 // loop all shapes and set the derivative
266 for(size_t sh = 0; sh < this->num_sh(commonFct); ++sh)
267 {
268 vvvDeriv[ip][commonFct][sh] += vDYieldStress[sh] * rInvariant;
269 }
270 }
271 }
272 }
273
274 // Derivatives of velocity gradient
275 UG_LOG("Derivatives of velocity gradient missing");
276 /*if(m_spDVelocityGrad.valid() && !m_spDVelocityGrad->zero_derivative())
277 {
278 for(size_t ip = 0; ip < nip; ++ip)
279 {
280 for(size_t fct = 0; fct < m_spDYieldStress->num_fct(); ++fct)
281 {
282 // get derivative of velocity gradient w.r.t. to all functions
283 const number* vDYieldStress = m_spDYieldStress->deriv(s, ip, fct);
284
285 // get common fct id for this function
286 const size_t commonFct = this->input_common_fct(_DV_, fct);
287
288 // loop all shapes and set the derivative
289 for(size_t sh = 0; sh < this->num_sh(commonFct); ++sh)
290 {
291 VecScaleAppend(vvvDeriv[ip][commonFct][sh], vDYieldStress[sh], rInvariant);
292 }
293 }
294 }
295 }*/
296 }
297
298
299
300 // Setter functions for imports
303 {
304 m_spDensity = data;
305 m_spDDensity = data.template cast_dynamic<DependentUserData<number, dim> >();
306 base_type::set_input(_RHO_, data, data);
307 }
308
310 {
312 }
313
316 {
317 m_spViscosity = data;
318 m_spDViscosity = data.template cast_dynamic<DependentUserData<number, dim> >();
319 base_type::set_input(_ETA_, data, data);
320 }
321
323 {
325 }
326
329 {
330 m_spYieldStress = data;
331 m_spDYieldStress = data.template cast_dynamic<DependentUserData<number, dim> >();
332 base_type::set_input(_TAU_, data, data);
333 }
334
339
342 {
343 UG_LOG("Debug mark 1\n");
344 m_spVelocityGrad = data;
345 UG_LOG("Debug mark 2\n");
346 try{
347 UG_LOG(typeid(data).name() << "\n");
348 m_spDVelocityGrad = data.template cast_dynamic<DependentUserData<MathMatrix<dim,dim>, dim> >();
349 } catch (std::exception& e) {
350 UG_LOG("Error: " << e.what());
351 }
352 UG_LOG("Debug mark 3\n");
353 base_type::set_input(_DV_, data, data);
354 }
355
356 protected:
357 // variables for storing imports
359 static const size_t _RHO_ = 0;
363 static const size_t _ETA_ = 1;
367 static const size_t _TAU_ = 2;
371 static const size_t _DV_ = 3;
374};
375
376} // end of namespace ug
377
378#endif // __H__UG__LIB_DISC__SPATIAL_DISC__BINGHAM_VISCOSITY_LINKER__
parameterString s
location name
Definition checkpoint_util.lua:128
Definition smart_pointer.h:108
Linker for the Bingham viscosity.
Definition bingham_viscosity_linker.h:62
void set_density(SmartPtr< CplUserData< number, dim > > data)
set density import
Definition bingham_viscosity_linker.h:302
void set_viscosity(SmartPtr< CplUserData< number, dim > > data)
set viscosity import
Definition bingham_viscosity_linker.h:315
static const size_t _ETA_
import for viscosity
Definition bingham_viscosity_linker.h:363
SmartPtr< DependentUserData< MathMatrix< dim, dim >, dim > > m_spDVelocityGrad
Definition bingham_viscosity_linker.h:373
SmartPtr< DependentUserData< number, dim > > m_spDDensity
Definition bingham_viscosity_linker.h:361
BinghamViscosityLinker()
Definition bingham_viscosity_linker.h:68
StdDataLinker< BinghamViscosityLinker< dim >, number, dim > base_type
Definition bingham_viscosity_linker.h:64
void set_viscosity(number val)
Definition bingham_viscosity_linker.h:322
void set_velocity_gradient(SmartPtr< CplUserData< MathMatrix< dim, dim >, dim > > data)
set velocity gradient import
Definition bingham_viscosity_linker.h:341
static const size_t _DV_
import for velocity gradient
Definition bingham_viscosity_linker.h:371
void evaluate(number &value, const MathVector< dim > &globIP, number time, int si) const
Definition bingham_viscosity_linker.h:79
SmartPtr< CplUserData< number, dim > > m_spDensity
Definition bingham_viscosity_linker.h:360
SmartPtr< DependentUserData< number, dim > > m_spDViscosity
Definition bingham_viscosity_linker.h:365
SmartPtr< DependentUserData< number, dim > > m_spDYieldStress
Definition bingham_viscosity_linker.h:369
SmartPtr< CplUserData< MathMatrix< dim, dim >, dim > > m_spVelocityGrad
Definition bingham_viscosity_linker.h:372
void evaluate(number 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 bingham_viscosity_linker.h:112
void eval_and_deriv(number 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< number > > vvvDeriv[], const MathMatrix< refDim, dim > *vJT=NULL) const
Definition bingham_viscosity_linker.h:157
void set_yield_stress(number val)
Definition bingham_viscosity_linker.h:335
SmartPtr< CplUserData< number, dim > > m_spViscosity
Definition bingham_viscosity_linker.h:364
SmartPtr< CplUserData< number, dim > > m_spYieldStress
Definition bingham_viscosity_linker.h:368
static const size_t _TAU_
import for yield stress
Definition bingham_viscosity_linker.h:367
static const size_t _RHO_
import for density
Definition bingham_viscosity_linker.h:359
void set_yield_stress(SmartPtr< CplUserData< number, dim > > data)
set density import
Definition bingham_viscosity_linker.h:328
void set_density(number val)
Definition bingham_viscosity_linker.h:309
constant scalar user data
Definition const_user_data.h:153
Type based UserData.
Definition user_data.h:501
const TData * values(size_t s) const
returns all values for a series
Definition user_data.h:516
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
number time() const
get the current evaluation time
Definition user_data.h:285
const MathVector< dim > & ip(size_t s, size_t ip) const
returns global ip
Definition user_data.h:401
Definition local_algebra.h:198
A class for fixed size, dense matrices.
Definition math_matrix.h:63
a mathematical Vector with N entries.
Definition math_vector.h:97
combines several UserDatas to a new UserData of a specified type
Definition linker.h:54
void set_num_input(size_t num)
sets the number of inputs
Definition linker.h:107
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
virtual void set_input(size_t i, SmartPtr< ICplUserData< dim > > input, SmartPtr< UserDataInfo > info)
sets an input
Definition linker.h:114
virtual bool zero_derivative() const
returns if derivative is zero
Definition linker_impl.h:179
#define UG_LOG(msg)
Definition log.h:367
double number
Definition types.h:124
the ug namespace
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition smart_pointer.h:836