Plugins
Loading...
Searching...
No Matches
bear_scheidegger.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
4// SPDX-FileContributor: Goethe Universität Frankfurt
5// SPDX-FileType: SOURCE
6
7#ifndef __H__UG__LIB_DISC__DENSITY_DRIVEN_FLOW__BEAR_SCHEIDEGGER__
8#define __H__UG__LIB_DISC__DENSITY_DRIVEN_FLOW__BEAR_SCHEIDEGGER__
9
11#include "d3f_limex.h"
12
13#define LIMEX_PATCH
14
15namespace ug{
16
25template <int dim>
27 : public StdDataLinker< BearScheidegger<dim>, MathMatrix<dim,dim>, dim>
28{
30
31 public:
33 number alphaTrans, number alphaLong) :
34 m_alphaT(alphaTrans), m_alphaL(alphaLong),
35 m_spVelocity(NULL), m_spDVelocity(NULL),
36 m_damp_limex(1.0)
37 {
38 this->set_num_input(1);
39 m_spVelocity = vel;
40 m_spDVelocity = vel.template cast_dynamic<DependentUserData<MathVector<dim>, dim> >();
41 base_type::set_input(_Q_, vel, vel);
42 }
43
45 number alphaTrans, number alphaLong, number damp) :
46 m_alphaT(alphaTrans), m_alphaL(alphaLong),
47 m_spVelocity(NULL), m_spDVelocity(NULL),
48 m_damp_limex(damp)
49 {
50 this->set_num_input(1);
51 m_spVelocity = vel;
52 m_spDVelocity = vel.template cast_dynamic<DependentUserData<MathVector<dim>, dim> >();
53 base_type::set_input(_Q_, vel, vel);
54 }
55
56 double alphaT () const {return m_alphaT;}
57 double alphaL () const {return m_alphaL;}
59
61 const MathVector<dim>& globIP,
62 number time, int si) const
63 {
65 (*m_spVelocity)(q, globIP, time, si);
66
67 const number qabs = VecTwoNorm(q);
68 if(qabs == 0.0){
69 D = 0.0;
70 }
71 else{
72 const number alpha = (m_alphaL - m_alphaT)/qabs;
73
74 for(size_t d1 = 0; d1 < dim; ++d1)
75 for(size_t d2 = 0; d2 < dim; ++d2)
76 D(d1,d2) = alpha*q[d1]*q[d2];
77
78 for(size_t d = 0; d < dim; ++d)
79 D(d,d) += qabs*m_alphaT;
80 }
81 }
82
83 template <int refDim>
84 inline void evaluate(MathMatrix<dim,dim> vD[],
85 const MathVector<dim> vGlobIP[],
86 number time, int si,
87 GridObject* elem,
88 const MathVector<dim> vCornerCoords[],
89 const MathVector<refDim> vLocIP[],
90 const size_t nip,
91 LocalVector* u,
92 const MathMatrix<refDim, dim>* vJT = NULL) const
93 {
94 std::vector<MathVector<dim> > vQ(nip);
95 (*m_spVelocity)(&vQ[0], vGlobIP, time, si,
96 elem, vCornerCoords, vLocIP, nip, u, vJT);
97
98 for(size_t ip = 0; ip < nip; ++ip)
99 {
100 MathMatrix<dim,dim>& D = vD[ip];
101 MathVector<dim>& q = vQ[ip];
102
103 const number qabs = VecTwoNorm(q);
104
105 if(qabs == 0.0){
106 D = 0.0;
107 }
108 else{
109 const number alpha = (m_alphaL - m_alphaT)/qabs;
110
111 for(size_t d1 = 0; d1 < dim; ++d1)
112 for(size_t d2 = 0; d2 < dim; ++d2)
113 D(d1,d2) = alpha*q[d1]*q[d2];
114
115 for(size_t d = 0; d < dim; ++d)
116 D(d,d) += qabs*m_alphaT;
117 }
118 }
119 }
120
121 template <int refDim>
123 const MathVector<dim> vGlobIP[],
124 number time, int si,
125 GridObject* elem,
126 const MathVector<dim> vCornerCoords[],
127 const MathVector<refDim> vLocIP[],
128 const size_t nip,
129 LocalVector* u,
130 bool bDeriv,
131 int subset,
132 std::vector<std::vector<MathMatrix<dim,dim> > > vvvDeriv[],
133 const MathMatrix<refDim, dim>* vJT = NULL) const
134 {
135 const bool noDeriv = !bDeriv ||
136 !m_spDVelocity.valid() ||
137 m_spDVelocity->zero_derivative();
138
139 // a check
140 if(!noDeriv) {
141 for(size_t fct = 0; fct < m_spDVelocity->num_fct(); ++fct)
142 if(this->input_common_fct(_Q_, fct) != fct)
143 UG_THROW("BearScheidegger: commonFct <-> fct should be equal");
144 }
145
146 const MathVector<dim>* vQ = m_spVelocity->values(subset);
147 for(size_t ip = 0; ip < nip; ++ip)
148 {
149 MathMatrix<dim,dim>& D = vD[ip];
150 const MathVector<dim>& q = vQ[ip];
151
152 const number qabs = VecTwoNorm(q);
153 if(qabs == 0.0){
154 D = 0.0;
155 if(noDeriv) continue;
156 for(size_t fct = 0; fct < m_spDVelocity->num_fct(); ++fct)
157 for(size_t sh = 0; sh < this->num_sh(fct); ++sh)
158 vvvDeriv[ip][fct][sh] = 0.0;
159 continue;
160 }
161
162 const number alpha = (m_alphaL - m_alphaT)/qabs;
163
164 for(size_t d1 = 0; d1 < dim; ++d1)
165 for(size_t d2 = 0; d2 < dim; ++d2)
166 D(d1,d2) = alpha*q[d1]*q[d2];
167
168 for(size_t d = 0; d < dim; ++d)
169 D(d,d) += qabs*m_alphaT;
170
171 // Derivative
172#ifndef DF_LIMEX_PATCH
173 if(noDeriv) continue;
174#else
175 if(noDeriv || m_damp_limex==0.0) continue;
176#endif
177
178 for(size_t fct = 0; fct < m_spDVelocity->num_fct(); ++fct)
179 {
180 const MathVector<dim>* vDVelocity = m_spDVelocity->deriv(subset, ip, fct);
181
182 for(size_t sh = 0; sh < this->num_sh(fct); ++sh)
183 {
184 const MathVector<dim>& qLin = vDVelocity[sh];
185 const number qabslin = VecDot(q, qLin) / qabs;
186 const number qabslinOverQabs = qabslin / qabs;
187
188 for(size_t d1 = 0; d1 < dim; ++d1)
189 for(size_t d2 = 0; d2 < dim; ++d2)
190 vvvDeriv[ip][fct][sh](d1,d2) =
191 alpha*(qLin[d1]*q[d2] + q[d1]*qLin[d2]
192#ifdef DF_LIMEX_PATCH
193 - q[d1]*q[d2] * qabslinOverQabs)*m_damp_limex;
194#else
195 - q[d1]*q[d2] * qabslinOverQabs);
196#endif
197
198 for(size_t d = 0; d < dim; ++d)
199#ifdef DF_LIMEX_PATCH
200 vvvDeriv[ip][fct][sh](d,d) += qabslin*m_alphaT*m_damp_limex;
201#else
202 vvvDeriv[ip][fct][sh](d,d) += qabslin*m_alphaT;
203#endif
204 }
205 }
206 }
207 }
208#ifdef DF_LIMEX_PATCH
210#endif
211
212 protected:
215
216 static const size_t _Q_ = 0;
217
220#ifdef DF_LIMEX_PATCH
222#endif
223};
224
225} // end namespace ug
226
227#endif /* __H__UG__LIB_DISC__DENSITY_DRIVEN_FLOW__BEAR_SCHEIDEGGER__ */
Definition bear_scheidegger.h:28
number m_damp_limex
Definition bear_scheidegger.h:221
const number m_alphaT
Definition bear_scheidegger.h:213
SmartPtr< DependentUserData< MathVector< dim >, dim > > m_spDVelocity
Definition bear_scheidegger.h:219
BearScheidegger(SmartPtr< CplUserData< MathVector< dim >, dim > > vel, number alphaTrans, number alphaLong)
Definition bear_scheidegger.h:32
void eval_and_deriv(MathMatrix< dim, dim > vD[], 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 subset, std::vector< std::vector< MathMatrix< dim, dim > > > vvvDeriv[], const MathMatrix< refDim, dim > *vJT=NULL) const
Definition bear_scheidegger.h:122
double alphaL() const
Definition bear_scheidegger.h:57
SmartPtr< CplUserData< MathVector< dim >, dim > > velocity() const
Definition bear_scheidegger.h:58
SmartPtr< CplUserData< MathVector< dim >, dim > > m_spVelocity
Definition bear_scheidegger.h:218
double alphaT() const
Definition bear_scheidegger.h:56
BearScheidegger(SmartPtr< CplUserData< MathVector< dim >, dim > > vel, number alphaTrans, number alphaLong, number damp)
Definition bear_scheidegger.h:44
void set_damp(number x)
Definition bear_scheidegger.h:209
static const size_t _Q_
Definition bear_scheidegger.h:216
void evaluate(MathMatrix< dim, dim > vD[], 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 bear_scheidegger.h:84
const number m_alphaL
Definition bear_scheidegger.h:214
StdDataLinker< BearScheidegger< dim >, MathMatrix< dim, dim >, dim > base_type
Definition bear_scheidegger.h:29
void evaluate(MathMatrix< dim, dim > &D, const MathVector< dim > &globIP, number time, int si) const
Definition bear_scheidegger.h:60
int subset() const
number time() const
const MathVector< dim > & ip(size_t s, size_t ip) const
virtual void set_input(size_t i, SmartPtr< ICplUserData< dim > > input, SmartPtr< UserDataInfo > info)
#define DF_LIMEX_PATCH
Definition d3f_limex.h:17
#define UG_THROW(msg)
double number
vector_t::value_type VecTwoNorm(const vector_t &v)
vector_t::value_type VecDot(const vector_t &v1, const vector_t &v2)