NeoPZ
pzspacetimerichardseq.cpp
Go to the documentation of this file.
1 
7 #include "pzbndcond.h"
8 #include "pzreal.h"
9 #include "pzaxestools.h"
10 
11 #include <cmath>
12 using namespace std;
13 
15 STATE TPZSpaceTimeRichardsEq::TCoeff = 1./60.;
17 STATE TPZSpaceTimeRichardsEq::LCoeff = 1000.;
20 
24 {
25 }
26 
29 TPZMaterial(id)
30 {
31 }
32 
33 TPZSpaceTimeRichardsEq::TPZSpaceTimeRichardsEq(int matid, STATE Alpha, STATE N, STATE ThetaS, STATE ThetaR, STATE Ks)
35 TPZMaterial(matid){
36  this->Set(Alpha, N, ThetaS, ThetaR, Ks);
37 }
38 
40 {
41 }
42 
43 void TPZSpaceTimeRichardsEq::Set(STATE Alpha, STATE N, STATE ThetaS, STATE ThetaR, STATE Ks){
44  this->fAlpha = Alpha;
45  this->fN = N;
46  this->fThetaS = ThetaS;
47  this->fThetaR = ThetaR;
48  this->fKs = Ks;
49 }
50 
52  return 2;
53 }
54 
56  return 1;
57 }
58 
60  TPZFMatrix<REAL> &phi = data.phi;
61  TPZFMatrix<REAL> &dphi = data.dphix;
62  int numbersol = data.sol.size();
63  if (numbersol != 1) {
64  DebugStop();
65  }
66 
67  const STATE sol = data.sol[0][0];
68 
69  const STATE BetaBarT = 0*LCoeff*data.detjac/2.; //beta=(0,1)
70 
71  TPZFNMatrix<2,STATE> dsol(2,1,0.);
72  /*
73  TPZFNMatrix<9,STATE> axes(data.axes.Rows(),data.axes.Cols());
74  for (int r=0; r<axes.Rows(); r++) {
75  for (int c=0; c<axes.Cols(); c++) {
76  axes(r,c) = data.axes(r,c);
77  }
78  }
79  */
80  TPZAxesTools<STATE>::Axes2XYZ(data.dsol[0], dsol, data.axes);
81 
82  const int phr = phi.Rows();
83  int i, j;
84 
85  for(i = 0; i < phr; i++){
86  const STATE BetaBarGradV = BetaBarT*dphi(1,i);
87  ef(i,0) += -1.*weight *( -1.*sol*dphi(1,i) +1.*dsol(1,0)*BetaBarGradV + /*(K/C)*/(dsol(0,0))*dphi(0,i));
88  for(j = 0; j < phr; j++){
89  ek(i,j) += weight * ( -1.*phi(j,0)*dphi(1,i)+dphi(1,j)*BetaBarGradV + dphi(0,i)*dphi(0,j) );
90  }
91  }//for i
92 }//Contribute
93 
95 
96  const STATE v2 = bc.Val2()(0,0);
97  TPZFMatrix<REAL> &phi = data.phi;
98  const int phr = phi.Rows();
99  int in, jn;
100  int numbersol = data.sol.size();
101  if (numbersol != 1) {
102  DebugStop();
103  }
104 
105 
106  switch (bc.Type()){
107 
108  // Dirichlet condition
109  case 0 : {
110  for(in = 0 ; in < phr; in++) {
111  ef(in,0) += weight * ( gBigNumber * phi(in,0) * (v2 - data.sol[0][0]) );
112  for (jn = 0 ; jn < phr; jn++) {
113  ek(in,jn) += gBigNumber * phi(in,0) * phi(jn,0) * weight;
114  }
115  }
116  break;
117  }
118 
119  // Neumann condition
120  case 1:{
121  // please implement me
122  }
123  break;
124 
125  // outflow condition
126  case 3 : {
127 
128  const STATE sol = data.sol[0][0];
129  STATE ConvDir[2] = {0., 1.};
130  STATE normal[2];
131  normal[0] = data.axes(0,1);
132  normal[1] = -1.*data.axes(0,0);
133 
134  STATE ConvNormal = ConvDir[0]*normal[0] + ConvDir[1]*normal[1];
135  if(ConvNormal > 0.) {
136  for(int il = 0; il < phr; il++) {
137  for(int jl = 0; jl < phr; jl++) {
138  ek(il,jl) += weight * ConvNormal * phi(il)*phi(jl);
139  }
140  ef(il,0) += -1. * weight * ConvNormal * phi(il) * sol;
141  }
142  }
143  else{
144  if (ConvNormal < 0.) std::cout << "Boundary condition error: inflow detected in outflow boundary condition: ConvNormal = " << ConvNormal << "\n";
145  }
146  }
147  break;
148 
149  default:{
150  std::cout << __PRETTY_FUNCTION__ << " at line " << __LINE__ << " not implemented\n";
151  }
152  }//switch
153 
154 }//ContributeBC
155 
157 
158  sol = sol/LCoeff;
159  STATE n = this->fN;
160  STATE m = 1.-(1./n);
161  STATE TR = this->fThetaR;
162  STATE TS = this->fThetaS;
163  STATE a = this->fAlpha;
164  STATE result = (m*n*pow(pow(a,(STATE)2.)*pow(sol,(STATE)2.),n/2.)*pow(1./(1. + pow(pow(a,(STATE)2.)*pow(sol,(STATE)2.),n/2.)),1. + m)*(TR - TS))/sol;
165  return result/LCoeff;
166 }
167 
168 STATE TPZSpaceTimeRichardsEq::Se(STATE sol){
169  STATE n = this->fN;
170  STATE m = 1.-(1./n);
171  STATE result = pow((STATE)(1./(1.+pow(fabs(this->fAlpha*sol),n))),m);
172  return result;
173 }
174 
176  STATE result = Se*(fThetaS-fThetaR)+fThetaR;
177  return result;
178 }
179 
181 int Sign(double A, double tol){
182  if(fabs(A) < tol) return 0;
183  if(A > 0.) return +1;
184  return -1;
185 }
186 
188  STATE sol1 = sol*(1.-deltaDerivada);
189  STATE antes = this->C_Coef(sol1);
190  STATE sol2 = sol * (1.+deltaDerivada);
191  STATE depois = this->C_Coef(sol2);
192  STATE result = (depois-antes)/(sol2-sol1);
193  return result;
194 }
195 
196 void TPZSpaceTimeRichardsEq::AnalysisOfParameters(STATE sol0, STATE solL, char* filename){
197  int np = 100;
198  TPZFMatrix<STATE> C(np,2), K(np,2), dCdSol(np,2), dKdsol(np,2);
199  double delta = (solL - sol0)/(np-1);
200  double sol;
201  for(int i = 0; i < np; i++){
202  sol = sol0+i*delta;
203  C(i,0) = sol;
204  C(i,1) = this->C_Coef(sol);
205  K(i,0) = sol;
206  K(i,1) = this->K_Coef(sol);
207  dCdSol(i,0) = sol;
208  dCdSol(i,1) = this->DCDsol(sol);
209  dKdsol(i,0) = sol;
210  dKdsol(i,1) = this->DKDsol(sol);
211  }
212 
213  std::ofstream file(filename);
214  C.Print("C=",file,EMathematicaInput);
215  K.Print("K=",file,EMathematicaInput);
216  dCdSol.Print("dCdSol=",file,EMathematicaInput);
217  dKdsol.Print("dKdsol=",file,EMathematicaInput);
218 
219  K.Print("K=",file);
220 }
221 
223 
224  sol = sol / LCoeff;
225 
226  STATE n = this->fN;
227  STATE m = 1.-(1./n);
228  STATE Se = this->Se(sol);
229  STATE Ks = this->fKs;
230  STATE result = Ks*sqrt(Se)*pow(((STATE)1.)-pow(((STATE)1.)-pow(Se,((STATE)1.)/m),m),(STATE)2.);
231 
232  return result*LCoeff/TCoeff;
233 }
234 
235 
237 
238  STATE sol1 = sol*(1.-deltaDerivada);
239  STATE antes = this->K_Coef(sol1);
240  STATE sol2 = sol * (1.+deltaDerivada);
241  STATE depois = this->K_Coef(sol2);
242  STATE resposta = (depois-antes)/(sol2-sol1);
243  return resposta;
244 
245  sol = sol / LCoeff;
246  STATE n = this->fN;
247  STATE m = 1.-(1./n);
248  STATE Se = this->Se(sol);
249  STATE DkDSe = 0.5 * this->fKs * (1.-pow(((STATE)1.)-pow(Se,((STATE)1.)/m),m))*(4.*pow(Se,((STATE)-0.5)+(((STATE)1.)/m))*pow(((STATE)1.)-pow(Se,((STATE)1.)/m),m-((STATE)1.))-(-1.+pow(((STATE)1.)-pow(Se,((STATE)1.)/m),m))/sqrt(Se));
250  STATE DSeDsol = -(1./sol)*m*n*pow(fabs(this->fAlpha*sol),n)*pow(1./(1.+pow(fabs(this->fAlpha*sol),n)),m+1.);
251  STATE dkdsol = DkDSe * DSeDsol;
252  return dkdsol*LCoeff/(TCoeff*LCoeff);
253 }
254 
256  return Hash("TPZSpaceTimeRichardsEq") ^ TPZMaterial::ClassId() << 1;
257 }
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ fabs
Definition: tfadfunc.h:140
filename
Definition: stats.py:82
static STATE TCoeff
Inicializing local variable TCoeff.
virtual void ContributeBC(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef, TPZBndCond &bc) override
It computes a contribution to the stiffness matrix and load vector at one BC integration point...
void AnalysisOfParameters(STATE sol0, STATE solL, char *filename)
clarg::argBool bc("-bc", "binary checkpoints", false)
static void Axes2XYZ(const TPZFMatrix< TVar > &dudaxes, TPZFMatrix< TVar > &dudx, const TPZFMatrix< REAL > &axesv, bool colMajor=true)
Makes the basis transformation from axes basis to euclidian basis.
Definition: pzaxestools.h:61
int Type()
Definition: pzbndcond.h:249
static STATE deltaDerivada
Inicializing loval variable deltaDerivada.
TPZGradSolVec dsol
vector of the derivatives of the solution at the integration point
STATE K_Coef(STATE sol)
Computes coeficient K(sol) based on current solution sol.
TPZFMatrix< STATE > & Val2(int loadcase=0)
Definition: pzbndcond.h:255
TPZFNMatrix< 220, REAL > phi
vector of shapefunctions (format is dependent on the value of shapetype)
Contains the TPZSpaceTimeRichardsEq class which implements a 1D space-time Richards&#39; equation...
TPZFNMatrix< 660, REAL > dphix
values of the derivative of the shape functions
This abstract class defines the behaviour which each derived class needs to implement.
Definition: TPZMaterial.h:39
STATE Theta(STATE Se)
Computes Theta coefficient from Se coefficient.
Contains the TPZBndCond class which implements a boundary condition for TPZMaterial objects...
virtual int NStateVariables() const override
It returns the number of state variables associated with the material.
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
virtual int ClassId() const override
Define the class id associated with the class.
static const double tol
Definition: pzgeoprism.cpp:23
#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
static STATE LCoeff
Inicializing local variable LCoeff.
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
virtual void Contribute(TPZMaterialData &data, REAL weight, TPZFMatrix< STATE > &ek, TPZFMatrix< STATE > &ef) override
It computes a contribution to the stiffness matrix and load vector at one integration point...
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ sqrt
Definition: tfadfunc.h:120
TPZFNMatrix< 9, REAL > axes
axes indicating the directions of the derivatives of the shapefunctions
virtual int Dimension() const override
It returns the integrable dimension of the material.
static REAL gBigNumber
Big number to penalization method, used for Dirichlet conditions.
Definition: TPZMaterial.h:83
void Set(STATE Alpha, STATE N, STATE ThetaS, STATE ThetaR, STATE Ks)
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
int ClassId() const override
Unique identifier for serialization purposes.
int Sign(double A, double tol)
Return sign of the STATE A. If A is closed to zero up to tolerance tol returns zero (in absolute valu...
TPZFlopCounter pow(const TPZFlopCounter &orig, const TPZFlopCounter &xp)
Returns the power and increments the counter of the power.
Definition: pzreal.h:487
Implemenents a 1D space-time Richards&#39; equation.
STATE Se(STATE sol)
Computes Se coeficient which allows the computation of K and Theta coefficients.
Contains declaration of the TPZAxesTools class which implements verifications over axes...
virtual void Print(std::ostream &out) const
Definition: pzmatrix.h:253
Contains the declaration of TPZFlopCounter class and TPZCounter struct.
clarg::argString m("-m", "input matrix file name (text format)", "matrix.txt")
STATE C_Coef(STATE sol)
Computes coeficient C(sol) based on current solution sol.
STATE fAlpha
Soil parameters.
TPZSolVec sol
vector of the solutions at the integration point
REAL detjac
determinant of the jacobian
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
Definition: pzfmatrix.h:716