Plugins
Loading...
Searching...
No Matches
d3f_debug_linker.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Gesellschaft fuer Anlagen- und Reaktorsicherheit gGmbH
2 * SPDX-License-Identifier: EUPL-1.2
3 * SPDX-FileContributor: Andreas Vogel, Arne Naegel
4 * SPDX-FileContributor: Goethe Universität Frankfurt
5 * SPDX-FileType: SOURCE
6 *
7 * This file is part of d3f++.
8 * d3f++ is an extension for UG4. Licensing information and citation requirements of UG4 are provided in LICENSES/UG4-LGPL_2.1
9 */
10
11#ifndef __H__UG__LIB_DISC__SPATIAL_DISC__D3F_LINKER__
12#define __H__UG__LIB_DISC__SPATIAL_DISC__D3F_LINKER__
13
14
15
20
21
22
23
24namespace ug{
25
26
28// Peclet number linker
30
32template <int dim>
34 : public StdDataLinker< DFPecletNumber<dim>, number, dim>
35{
38
39 public:
41 m_spDispersion(NULL), /*m_spDDispersion(NULL),*/
42 m_spVelocity(NULL), /*m_spDVelocity(NULL),*/
44 {
45 // this linker has exactly two inputs
46 this->set_num_input(2);
47 }
48
49
50 inline void evaluate (number& value,
51 const MathVector<dim>& globIP,
52 number time, int si) const
53 {
54 MathVector<dim> q, Dq;
56
57 (*m_spVelocity)(q, globIP, time, si);
58 (*m_spDispersion)(D, globIP, time, si);
59
61 number qnorm = VecTwoNorm(q);
62
63 // Compute Diffusion Tensor times Gradient
64 MatVecMult(Dq, D, q);
65 const number qtDq = VecDot(Dq, q);
66
67 value = (qnorm*qnorm*qnorm*L)/qtDq;
68
69 // UG_ASSERT(value >= -1e-8, "Error");
70 // std::cout << VecTwoNorm(velocity) << " " << MinAbsEigenvalue(dispersion) << " "<< value <<std::endl;
71 UG_LOG("evaluate1:" << value << std::endl);
72 }
73
74 template <int refDim>
75 inline void evaluate(number vValue[],
76 const MathVector<dim> vGlobIP[],
77 number time, int si,
78 GridObject* elem,
79 const MathVector<dim> vCornerCoords[],
80 const MathVector<refDim> vLocIP[],
81 const size_t nip,
82 LocalVector* u,
83 const MathMatrix<refDim, dim>* vJT = NULL) const
84 {
86 number size = ElementSize<dim>(roid, vCornerCoords);
87 number hL = pow(size, 1.0/dim)*m_dLengthScale;
88
89 std::vector<MathVector<dim> > vVelocity(nip);
90 std::vector<MathMatrix<dim,dim> > vDispersion(nip);
91
92 (*m_spVelocity)(&vVelocity[0], vGlobIP, time, si,
93 elem, vCornerCoords, vLocIP, nip, u, vJT);
94 (*m_spDispersion)(&vDispersion[0], vGlobIP, time, si,
95 elem, vCornerCoords, vLocIP, nip, u, vJT);
96
97 for(size_t ip = 0; ip < nip; ++ip)
98 {
99
100 const number qnorm_ip = VecTwoNorm(vVelocity[ip]);
101
102 MathVector<dim> Dvel_ip;
103 MatVecMult(Dvel_ip, vDispersion[ip], vVelocity[ip]);
104 const number qtDq_ip = VecDot(Dvel_ip, vVelocity[ip]);
105
106 vValue[ip] = qnorm_ip*qnorm_ip*qnorm_ip*hL;
107 vValue[ip] /= qtDq_ip;
108
109 //UG_ASSERT(vValue[ip] >= -1e-8, "Error");
110 //std::cout << "ip=" << ip <<" : "<<VecTwoNorm(vVelocity[ip]) << " " << MinAbsEigenvalue(vDispersion[ip]) << "="<< vValue[ip] << std::endl;
111 // UG_LOG("evaluate2:" << vValue[ip] << std::endl);
112 }
113 }
114
115 template <int refDim>
116 void eval_and_deriv(number vValue[],
117 const MathVector<dim> vGlobIP[],
118 number time, int si,
119 GridObject* elem,
120 const MathVector<dim> vCornerCoords[],
121 const MathVector<refDim> vLocIP[],
122 const size_t nip,
123 LocalVector* u,
124 bool bDeriv,
125 int s,
126 std::vector<std::vector<number > > vvvDeriv[]//,
127 //const MathVector<refDim>* vJT = NULL
128 ) const
129 {
130
131 // Compute the derivatives at all ips //
133
134 // check if something to do
135 if(!bDeriv || this->zero_derivative()) return;
136
137 UG_ASSERT(0, "eval_and_deriv not implemented.");
138 // clear all derivative values
139 this->set_zero(vvvDeriv, nip);
140
141 }
142
143 public:
146 {
147 m_spDispersion = data;
148 //m_spDDispersion = data.template cast_dynamic<DependentUserData<MathMatrix<dim,dim>, dim> >();
150 }
151
154
157 {
158 m_spVelocity = data;
159 // m_spDVelocity = data.template cast_dynamic<DependentUserData<MathVector<dim>, dim> >();
160 base_type::set_input(_VELOCITY_, data, data);
161 }
162
165
166 protected:
167 enum {_DISPERSION_ = 0, _VELOCITY_ = 1};
170 // SmartPtr<DependentUserData<MathMatrix<dim,dim>, dim> > m_spDDispersion;
171
174 // SmartPtr<DependentUserData<MathVector<dim>, dim> > m_spDVelocity;
175
177
178};
179
181
184template <int dim>
186 : public StdDataLinker< DFAnisotropy<dim>, number, dim>
187{
190
191 public:
192 DFAnisotropy() : m_spDispersion(NULL)/*, m_spDDispersion(NULL)*/
193 {
194 this->set_num_input(1);
195 }
196
197
198 inline void evaluate (number& value,
199 const MathVector<dim>& globIP,
200 number time, int si) const
201 {
202 MathMatrix<dim,dim> dispersion;
203 (*m_spDispersion)(dispersion, globIP, time, si);
204
205 value = MinAbsEigenvalue(dispersion);
206 value /= MaxAbsEigenvalue(dispersion);
207 UG_LOG("aniso_evaluate1:" << value << std::endl);
208 }
209
210 template <int refDim>
211 inline void evaluate(number vValue[],
212 const MathVector<dim> vGlobIP[],
213 number time, int si,
214 GridObject* elem,
215 const MathVector<dim> vCornerCoords[],
216 const MathVector<refDim> vLocIP[],
217 const size_t nip,
218 LocalVector* u,
219 const MathMatrix<refDim, dim>* vJT = NULL) const
220 {
221 std::vector<MathMatrix<dim,dim> > vDispersion(nip);
222 (*m_spDispersion)(&vDispersion[0], vGlobIP, time, si,
223 elem, vCornerCoords, vLocIP, nip, u, vJT);
224
225 for(size_t ip = 0; ip < nip; ++ip)
226 {
227 vValue[ip] = MinAbsEigenvalue(vDispersion[ip]);
228 vValue[ip] /= MaxAbsEigenvalue(vDispersion[ip]);
229 UG_LOG("aniso_evaluate2:" << vValue[ip] << std::endl);
230 }
231
232 }
233
234 template <int refDim>
235 void eval_and_deriv(number vValue[],
236 const MathVector<dim> vGlobIP[],
237 number time, int si,
238 GridObject* elem,
239 const MathVector<dim> vCornerCoords[],
240 const MathVector<refDim> vLocIP[],
241 const size_t nip,
242 LocalVector* u,
243 bool bDeriv,
244 int s,
245 std::vector<std::vector<number > > vvvDeriv[]//,
246 //const MathVector<refDim>* vJT = NULL
247 ) const
248 {
249
250 // Compute the derivatives at all ips //
252
253 // check if something to do
254 if(!bDeriv || this->zero_derivative()) return;
255
256 UG_ASSERT(0, "eval_and_deriv not implemented.");
257 // clear all derivative values
258 this->set_zero(vvvDeriv, nip);
259
260 }
261
262 public:
265 {
266 m_spDispersion = data;
267 //m_spDDispersion = data.template cast_dynamic<DependentUserData<MathMatrix<dim,dim>, dim> >();
269 }
270
273
274 protected:
275 enum {_DISPERSION_ = 0};
278 //SmartPtr<DependentUserData<MathMatrix<dim,dim>, dim> > m_spDDispersion;
279
280 };
281
283template <int dim>
285 //: public StdDataLinker< ElementExtensions<dim>, MathVector<dim>, dim>
286 : public StdDependentUserData<ElementExtensions<dim>, MathVector<dim>, dim>
287{
288 public:
292
293 public:
296/*
298 virtual void operator() (MathVector<dim>& value,
299 const MathVector<dim>& globIP,
300 number time, int si) const
301 { UG_THROW("global operator() not implemented."); }
302
304
305 virtual void operator()(MathVector<dim> vValue[],
306 const MathVector<dim> vGlobIP[],
307 number time, int si, const size_t nip) const
308 { UG_THROW("global operator() not implemented."); }
309
310*/
311 /*inline void evaluate (number& value,
312 const MathVector<dim>& globIP,
313 number time, int si) const
314 {}*/
315/*
316 template <int refDim>
317 inline void evaluate(MathVector<dim> vValue[],
318 const MathVector<dim> vGlobIP[],
319 number time, int si,
320 GridObject* elem,
321 const MathVector<dim> vCornerCoords[],
322 const MathVector<refDim> vLocIP[],
323 const size_t nip,
324 LocalVector* u,
325 const MathMatrix<refDim, dim>* vJT = NULL) const
326 {
327 ReferenceObjectID roid=elem->reference_object_id();
328 MathVector<dim> ext;
329 ElementExtensionsSq<dim>(roid, ext, vCornerCoords);
330 for(size_t ip = 0; ip < nip; ++ip)
331 vValue[ip] = ext;
332
333 }
334 */
335 template <int refDim>
337 const MathVector<dim> vGlobIP[],
338 number time, int si,
339 GridObject* elem,
340 const MathVector<dim> vCornerCoords[],
341 const MathVector<refDim> vLocIP[],
342 const size_t nip,
343 LocalVector* u,
344 bool bDeriv,
345 int s,
346 std::vector<std::vector<data_type > > vvvDeriv[],
347 const MathMatrix<refDim, dim>* vJT = NULL
348 ) const
349 {
351 MathVector<dim> ext;
352 ElementExtensionsSq<dim>(roid, ext, vCornerCoords);
353 for(size_t ip = 0; ip < nip; ++ip)
354 {
355 vValue[ip] = ext;
356 }
357
358
360 // Compute the derivatives at all ips //
361
362
363 // check if something to do
364 if(!bDeriv || this->zero_derivative()) return;
365
366 UG_ASSERT(0, "eval_and_deriv not implemented.");
367 // clear all derivative values
368 //this->set_zero(vvvDeriv, nip);
369
370 }
371
372/*
374 virtual void compute(LocalVector* u, GridObject* elem,
375 const MathVector<dim> vCornerCoords[], bool bDeriv = false)
376 {
377 ReferenceObjectID roid=elem->reference_object_id();
378 MathVector<dim> ext;
379 ElementExtensionsSq<dim>(roid, ext, vCornerCoords);
380
381 for(size_t s = 0; s < this->num_series(); ++s)
382 for(size_t ip = 0; ip < this->num_ip(s); ++ip)
383 this->value(s,ip) = ext;
384 UG_ASSERT(0, "TODO: Implementation as 'UserData' is missing.");
385 }
386
387 virtual void compute(LocalVectorTimeSeries* u, GridObject* elem,
388 const MathVector<dim> vCornerCoords[], bool bDeriv = false)
389 {
390 ReferenceObjectID roid=elem->reference_object_id();
391 MathVector<dim> ext;
392 ElementExtensionsSq<dim>(roid, ext, vCornerCoords);
393
394 UG_ASSERT(0, "TODO: Implementation as 'UserData' is missing.");
395
396 }*/
397
399 virtual bool constant() const {return false;}
400
402 virtual bool requires_grid_fct() const {return true;}
403
405 virtual bool continuous() const {return false;}
406
407
408};
409
410} // end namespace ug
411
412#endif /* __H__UG__LIB_DISC__SPATIAL_DISC__DARCY_VELOCITY_LINKER__ */
parameterString s
Definition Biogas.lua:2
TData & value(size_t s, size_t ip)
Computes degree of anisotropy per element.
Definition d3f_debug_linker.h:187
DFAnisotropy()
Definition d3f_debug_linker.h:192
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 d3f_debug_linker.h:211
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
Definition d3f_debug_linker.h:235
SmartPtr< CplUserData< MathMatrix< dim, dim >, dim > > m_spDispersion
import for dispersion tensor
Definition d3f_debug_linker.h:277
void evaluate(number &value, const MathVector< dim > &globIP, number time, int si) const
Definition d3f_debug_linker.h:198
void set_dispersion(number val)
Definition d3f_debug_linker.h:271
void set_dispersion(SmartPtr< CplUserData< MathMatrix< dim, dim >, dim > > data)
set permeability import
Definition d3f_debug_linker.h:264
@ _DISPERSION_
Definition d3f_debug_linker.h:275
StdDataLinker< DFAnisotropy< dim >, number, dim > base_type
Base class type.
Definition d3f_debug_linker.h:189
Computes grid Peclet number (for d3f)
Definition d3f_debug_linker.h:35
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 d3f_debug_linker.h:75
StdDataLinker< DFPecletNumber< dim >, number, dim > base_type
Base class type.
Definition d3f_debug_linker.h:37
DFPecletNumber()
Definition d3f_debug_linker.h:40
void set_length_scale(number l)
Definition d3f_debug_linker.h:163
number m_dLengthScale
Definition d3f_debug_linker.h:176
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
Definition d3f_debug_linker.h:116
void set_dispersion(SmartPtr< CplUserData< MathMatrix< dim, dim >, dim > > data)
set permeability import
Definition d3f_debug_linker.h:145
SmartPtr< CplUserData< MathMatrix< dim, dim >, dim > > m_spDispersion
import for dispersion tensor
Definition d3f_debug_linker.h:169
@ _VELOCITY_
Definition d3f_debug_linker.h:167
@ _DISPERSION_
Definition d3f_debug_linker.h:167
void set_velocity(SmartPtr< CplUserData< MathVector< dim >, dim > > data)
set pressure gradient import
Definition d3f_debug_linker.h:156
SmartPtr< CplUserData< MathVector< dim >, dim > > m_spVelocity
import for Darcy velocity
Definition d3f_debug_linker.h:173
void set_dispersion(number val)
Definition d3f_debug_linker.h:152
void evaluate(number &value, const MathVector< dim > &globIP, number time, int si) const
Definition d3f_debug_linker.h:50
TODO: This is no linker!!!
Definition d3f_debug_linker.h:287
virtual bool constant() const
returns if data is constant
Definition d3f_debug_linker.h:399
virtual bool requires_grid_fct() const
returns if grid function is needed for evaluation
Definition d3f_debug_linker.h:402
void eval_and_deriv(data_type 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< data_type > > vvvDeriv[], const MathMatrix< refDim, dim > *vJT=NULL) const
Definition d3f_debug_linker.h:336
ElementExtensions()
Definition d3f_debug_linker.h:294
MathVector< dim > data_type
Definition d3f_debug_linker.h:291
virtual bool continuous() const
returns if provided data is continuous over geometric object boundaries
Definition d3f_debug_linker.h:405
StdDependentUserData< ElementExtensions< dim >, MathVector< dim >, dim > base_type
Base class type.
Definition d3f_debug_linker.h:290
virtual ReferenceObjectID reference_object_id() const=0
number time() const
const MathVector< dim > & ip(size_t s, size_t ip) const
virtual bool zero_derivative() const
virtual void set_input(size_t i, SmartPtr< ICplUserData< dim > > input, SmartPtr< UserDataInfo > info)
MathMatrix< N, M, T >::value_type MinAbsEigenvalue(const MathMatrix< M, N, T > &m)
#define UG_ASSERT(expr, msg)
#define UG_LOG(msg)
double number
void MatVecMult(vector_t_out &vOut, const matrix_t &m, const vector_t_in &v)
vector_t::value_type VecTwoNorm(const vector_t &v)
vector_t::value_type VecDot(const vector_t &v1, const vector_t &v2)
ReferenceObjectID
MathMatrix< 1, 1, T >::value_type MaxAbsEigenvalue(const MathMatrix< 1, 1, T > &m)
SmartPtr< T, FreePolicy > make_sp(T *inst)