NeoPZ
TPZMixedDarcyFlow.cpp
Go to the documentation of this file.
1 //
2 // TPZMixedDarcyFlow.cpp
3 // HDiv
4 //
5 // Created by Omar DurĂ¡n on 3/29/19.
6 //
7 
8 #include "TPZMixedDarcyFlow.h"
9 
11 
12  m_kappa.Resize(0, 0);
13  m_kappa_inv.Resize(0, 0);
14  m_d = 0.0;
15  m_dim = 0;
16 
17 }
18 
20 
21 }
22 
23 TPZMixedDarcyFlow::TPZMixedDarcyFlow(int mat_id, int dim) : TPZMaterial(mat_id){
24  m_kappa.Resize(3, 3);
25  m_kappa_inv.Resize(3, 3);
26  m_d = 0.0;
27  m_dim = dim;
28 }
29 
30 
32 
33  m_kappa = other.m_kappa;
34  m_kappa_inv = other.m_kappa_inv;
35  m_d = other.m_d;
36  m_dim = other.m_dim;
37 }
38 
40  return new TPZMixedDarcyFlow(*this);
41 }
42 
44  if (this != & other) // prevent self-assignment
45  {
47  m_kappa = other.m_kappa;
48  m_kappa_inv = other.m_kappa_inv;
49  m_d = other.m_d;
50  m_dim = other.m_dim;
51  }
52  return *this;
53 }
54 
56  return m_dim;
57 }
58 
60  return 1;
61 }
62 
63 void TPZMixedDarcyFlow::Print(std::ostream & out){
64  m_kappa.Print(out);
65  m_kappa_inv.Print(out);
66  out << m_d << std::endl;
67  out << m_dim << std::endl;
68 }
69 
71  return "TPZMixedDarcyFlow";
72 }
73 
75  int ndata = datavec.size();
76  for (int idata=0; idata < ndata ; idata++) {
77  datavec[idata].SetAllRequirements(false);
78  datavec[idata].fNeedsSol = true;
79  }
80 }
81 
83  int ndata = datavec.size();
84  for (int idata=0; idata < ndata ; idata++) {
85  datavec[idata].SetAllRequirements(false);
86  datavec[idata].fNeedsSol = true;
87  }
88 }
89 
91  return Hash("TPZMixedDarcyFlow") ^ TPZMaterial::ClassId() << 1;
92 }
93 
94 void TPZMixedDarcyFlow::Write(TPZStream &buf, int withclassid) const{
95  DebugStop();
96 }
97 
98 void TPZMixedDarcyFlow::Read(TPZStream &buf, void *context){
99  DebugStop();
100 }
101 
103 
104  int qb = 0;
105  int pb = 1;
106 
107  TPZFNMatrix<100,REAL> phi_qs = datavec[qb].phi;
108  TPZFNMatrix<100,REAL> phi_ps = datavec[pb].phi;
109  TPZFNMatrix<300,REAL> dphi_qs = datavec[qb].dphix;
110  TPZFNMatrix<100,REAL> dphi_ps = datavec[pb].dphix;
111 
112  // Computing the radius
113  TPZFMatrix<REAL> x_spatial(3,1,0.0);
114  x_spatial(0,0) = datavec[0].x[0];
115  STATE val = x_spatial(0,0);
116  REAL r = Norm(x_spatial);
117 
118 
119  auto &div_phi = datavec[qb].divphi;
120  REAL div_q = datavec[qb].divsol[0][0];
121 
122  int nphi_q = datavec[qb].fVecShapeIndex.NElements();
123  int nphi_p = phi_ps.Rows();
124  int first_q = 0;
125  int first_p = nphi_q + first_q;
126 
127  TPZManVector<STATE,3> q = datavec[qb].sol[0];
128  STATE p = datavec[pb].sol[0][0];
129 
130  //axisimetria
131  REAL s = 1.0;
132  if (1) {
133  s *= 2.0*M_PI*r;
134  q[0] *= (1.0/s);
135  q[1] *= (1.0/s);
136  // q[2] *= (1.0/s);
137  dphi_qs *= (1.0/s);
138  }
139  //axisimetria
140 
141  TPZFNMatrix<3,STATE> phi_q_i(3,1,0.0), kappa_inv_phi_q_j(3,1,0.0), kappa_inv_q(3,1,0.0);
142 
143  int s_i, s_j;
144  int v_i, v_j;
145 
146  for (int i = 0; i < 3; i++) {
147  for (int j = 0; j < 3; j++) {
148  kappa_inv_q(i,0) += m_kappa_inv(i,j)*q[j];
149  }
150  }
151 
152  for (int iq = 0; iq < nphi_q; iq++)
153  {
154 
155  v_i = datavec[qb].fVecShapeIndex[iq].first;
156  s_i = datavec[qb].fVecShapeIndex[iq].second;
157 
158  STATE kappa_inv_q_dot_phi_q_i = 0.0;
159  for (int i = 0; i < 3; i++) {
160  phi_q_i(i,0) = phi_qs(s_i,0) * datavec[qb].fNormalVec(i,v_i);
161  kappa_inv_q_dot_phi_q_i += kappa_inv_q(i,0)*phi_q_i(i,0);
162  }
163 
164  ef(iq + first_q) += -1.0 * weight * ( kappa_inv_q_dot_phi_q_i - p * div_phi(iq,0));
165 
166  for (int jq = 0; jq < nphi_q; jq++)
167  {
168 
169  v_j = datavec[qb].fVecShapeIndex[jq].first;
170  s_j = datavec[qb].fVecShapeIndex[jq].second;
171 
172  kappa_inv_phi_q_j.Zero();
173  for (int i = 0; i < 3; i++) {
174  for (int j = 0; j < 3; j++) {
175  kappa_inv_phi_q_j(i,0) += m_kappa_inv(i,j) * phi_qs(s_j,0) * datavec[qb].fNormalVec(j,v_j);
176  }
177  }
178 
179  STATE kappa_inv_phi_q_j_dot_phi_q_i = 0.0;
180  for (int j = 0; j < 3; j++) {
181  kappa_inv_phi_q_j_dot_phi_q_i += kappa_inv_phi_q_j(j,0)*phi_q_i(j,0);
182  }
183 
184  ek(iq + first_q,jq + first_q) += weight * kappa_inv_phi_q_j_dot_phi_q_i;
185  }
186 
187  for (int jp = 0; jp < nphi_p; jp++)
188  {
189  ek(iq + first_q, jp + first_p) += weight * ( - div_phi(iq,0) ) * phi_ps(jp,0);
190  }
191 
192  }
193 
194  for (int ip = 0; ip < nphi_p; ip++)
195  {
196  STATE force = 0.0;
197  if(fForcingFunction) {
199  fForcingFunction->Execute(datavec[0].x,res);
200  force = res[0];
201  }
202 
203 
204  ef(ip + first_p) += -1.0 * weight * (force) * phi_ps(ip,0);
205 
206  for (int jq = 0; jq < nphi_q; jq++)
207  {
208  ek(ip + first_p, jq + first_q) += -1.0 * weight * div_phi(jq,0) * phi_ps(ip,0);
209  }
210 
211  }
212 
213 }
214 
216  TPZFMatrix<STATE> ekfake(ef.Rows(),ef.Rows(),0.0);
217  this->Contribute(datavec, weight, ekfake, ef);
218 }
219 
221  TPZFMatrix<STATE> ekfake(ef.Rows(),ef.Rows(),0.0);
222  this->ContributeBC(datavec, weight, ekfake, ef, bc);
223 }
224 
226 
227  int qb = 0;
228  TPZFNMatrix<100,REAL> phi_qs = datavec[qb].phi;
229 
230  int nphi_q = phi_qs.Rows();
231  int first_q = 0;
232 
233  TPZManVector<STATE,3> q = datavec[qb].sol[0];
234 
235 
236  //
237 
238  // Computing the radius
239  TPZFMatrix<REAL> x_spatial(3,1,0.0);
240  x_spatial(0,0) = datavec[0].x[0];
241  REAL r = Norm(x_spatial);
242 
243  int npos = q.size();
244 
245  //axisimetria
246  REAL s = 1.0;
247  if (1) {
248  s *= 2.0*M_PI*r;
249  q[0] *= (1.0/s);
250  // q[1] *= (1.0/s);
251  // q[2] *= (1.0/s);
252 
253  }
254  //axisimetria
255 
256  //
257 
258 
259  TPZManVector<STATE,1> bc_data(1,0.0);
260  bc_data[0] = bc.Val2()(0,0);
261 
262  switch (bc.Type()) {
263  case 0 : // Dirichlet BC PD
264  {
265  STATE p_D = bc_data[0];
266  for (int iq = 0; iq < nphi_q; iq++)
267  {
268  ef(iq + first_q) += -1.0 * weight * p_D * phi_qs(iq,0);
269  }
270  }
271  break;
272 
273  case 1 : // Neumann BC QN
274  {
275 
276  for (int iq = 0; iq < nphi_q; iq++)
277  {
278  REAL qn_N = bc_data[0], qn = q[0];
279  ef(iq + first_q) += -1.0 * weight * gBigNumber * (qn - qn_N) * phi_qs(iq,0);
280 
281  for (int jq = 0; jq < nphi_q; jq++)
282  {
283 
284  ek(iq + first_q,jq + first_q) += -1.0 * weight * gBigNumber * phi_qs(jq,0) * phi_qs(iq,0);
285  }
286 
287  }
288 
289  }
290  break;
291 
292  default: std::cout << "This BC doesn't exist." << std::endl;
293  {
294 
295  DebugStop();
296  }
297  break;
298  }
299 
300  return;
301 
302 }
303 
304 int TPZMixedDarcyFlow::VariableIndex(const std::string &name){
305  if(!strcmp("q",name.c_str())) return 1;
306  if(!strcmp("p",name.c_str())) return 2;
307  if(!strcmp("div_q",name.c_str())) return 3;
308  if(!strcmp("kappa",name.c_str())) return 4;
309  return TPZMaterial::VariableIndex(name);
310 }
311 
313  if(var == 1) return 3;
314  if(var == 2) return 1;
315  if(var == 3) return 1;
316  if(var == 4) return this->Dimension();
317 
319 }
320 
322 
323  int qb = 0;
324  int pb = 1;
325  Solout.Resize( this->NSolutionVariables(var));
327 
328  q = datavec[qb].sol[0];
329  p = datavec[pb].sol[0];
330  REAL div_q = datavec[qb].divsol[0][0];
331 
332  // Computing the radius
333  TPZFMatrix<REAL> x_spatial(3,1,0.0);
334  x_spatial(0,0) = datavec[0].x[0];
335  REAL r = Norm(x_spatial);
336 
337 
338  //axisimetria
339  REAL s = 1.0;
340  if (1) {
341  s *= 2.0*M_PI*r;
342  q[0] *= (1.0/s);
343  q[1] *= (1.0/s);
344  // q[2] *= (1.0/s);
345 
346  }
347  //axisimetria
348 
349  if(var == 1){
350  for (int i=0; i < 3; i++)
351  {
352  Solout[i] = q[i];
353  }
354  return;
355  }
356 
357  if(var == 2){
358  Solout[0] = p[0];
359  return;
360  }
361 
362  if(var == 3){
363  Solout[0] = div_q;
364  return;
365  }
366 
367  if(var == 4){
368  for (int i = 0; i < this->Dimension(); i++) {
369  Solout[i] = m_kappa(i,i);
370  }
371  return;
372  }
373 
374  DebugStop();
375 }
virtual void Execute(const TPZVec< REAL > &x, TPZVec< TVar > &f, TPZFMatrix< TVar > &df)
Performs function computation.
Definition: pzfunction.h:38
void ContributeBC(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ef, TPZBndCond &bc) override
Boundary contribute without jacobian matrix.
TPZFNMatrix< 9, REAL > m_kappa
Absolute permeability.
clarg::argBool bc("-bc", "binary checkpoints", false)
REAL m_d
Dimensional factor.
int Type()
Definition: pzbndcond.h:249
TPZMaterial & operator=(const TPZMaterial &copy)
operator =
Definition: TPZMaterial.cpp:62
virtual int VariableIndex(const std::string &name)
Returns the variable index associated with the name.
This class implements a simple vector storage scheme for a templated class T. Utility.
Definition: pzgeopoint.h:19
REAL val(STATE &number)
Returns value of the variable.
Definition: pzartdiff.h:23
void FillDataRequirements(TPZVec< TPZMaterialData > &datavec) override
fill requirements for volumetric contribute methods multiphsycis mesh
void Print(std::ostream &out) override
print all material information
int NSolutionVariables(int var) override
size of the current variable (1 -> scalar, 3-> vector, 9 -> Tensor )
TPZFMatrix< STATE > & Val2(int loadcase=0)
Definition: pzbndcond.h:255
std::string Name() override
print material name
int VariableIndex(const std::string &name) override
Variable index based on variable naming.
This abstract class defines the behaviour which each derived class needs to implement.
Definition: TPZMaterial.h:39
virtual int NStateVariables() const override
return the number of state variables associated with each trial function
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object reallocating the necessary storage, copying the existing objects to the new...
Definition: pzvec.h:373
TVar Norm(const TPZFMatrix< TVar > &A)
Returns the norm of the matrix A.
void Read(TPZStream &buf, void *context) override
write class from disk
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
This class defines the boundary condition for TPZMaterial objects.
Definition: pzbndcond.h:29
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
TPZMixedDarcyFlow()
default constructor
string res
Definition: test.py:151
void Contribute(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef) override
Volumetric contribute with jacobian matrix.
TPZMixedDarcyFlow & operator=(const TPZMixedDarcyFlow &other)
assignment operator
virtual int ClassId() const override
unique class identifier
void FillBoundaryConditionDataRequirement(int type, TPZVec< TPZMaterialData > &datavec) override
fill requirements for boundary contribute methods multiphsycis mesh
static REAL gBigNumber
Big number to penalization method, used for Dirichlet conditions.
Definition: TPZMaterial.h:83
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
int ClassId() const override
Unique identifier for serialization purposes.
~TPZMixedDarcyFlow()
default desconstructor
virtual void Write(TPZStream &buf, int withclassid) const override
write class in disk
int m_dim
Material dimension.
virtual int NSolutionVariables(int var)
Returns the number of variables associated with the variable indexed by var.
TPZFNMatrix< 9, REAL > m_kappa_inv
Inver of absolute permeability.
TPZAutoPointer< TPZFunction< STATE > > fForcingFunction
Pointer to forcing function, it is the right member at differential equation.
Definition: TPZMaterial.h:47
virtual void Print(std::ostream &out) const
Definition: pzmatrix.h:253
int Resize(const int64_t newRows, const int64_t wCols) override
Redimension a matrix, but maintain your elements.
Definition: pzfmatrix.cpp:1016
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
TPZMaterial * NewMaterial() override
return a material object from a this object
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
Definition: pzfmatrix.h:716
int Dimension() const override
return the euclidean dimension of the weak statement
void Solution(TPZVec< TPZMaterialData > &datavec, int var, TPZVec< STATE > &Solout) override
Postprocess required variables multiphysics.