45 TPZSwelling::TPZSwelling(
int matindex, STATE lambda, STATE shear, STATE alfa, STATE M, STATE Gamma, STATE Kperm, STATE DPlus, STATE DMinus,
46 STATE rHinder, STATE Cfc, STATE Nf0, STATE NPlus0, STATE NMinus0) :
65 for(ic=0; ic<3; ic++) {
78 out <<
"name of material : " <<
Name() <<
"\n";
79 out <<
"properties : \n";
81 out <<
"Compression modulus " <<
fLambda << endl;
82 out <<
"Shear modulus " <<
fShear << endl;
83 out <<
"Biot coupling coeficient " <<
fAlfa << endl;
84 out <<
"Storage modulus " <<
fM << endl;
85 out <<
"Osmotic coeficient " <<
fGamma << endl;
86 out <<
"Hydraulic permeability " <<
fKperm << endl;
87 out <<
"Diffusion coeficient for cations " <<
fDPlus << endl;
88 out <<
"Diffusion coeficient for anions " <<
fDMinus << endl;
89 out <<
"Hindrance factor " <<
frHinder << endl;
90 out <<
"Initial deformation " <<
fInitDeform << endl;
91 out <<
"Fixed charge density " <<
fCfc << endl;
92 out <<
"Initial fluid volume fraction " <<
fNf0 << endl;
93 out <<
"Initial cation volume fraction " <<
fNPlus0 << endl;
94 out <<
"Initial anion volume fraction " <<
fNMinus0 << endl;
95 out <<
"Weight factor for time integration of ionic conservation law " <<
fTheta << endl;
96 out <<
"Timestep " <<
fDelt << endl;
97 out <<
"Faraday constant " <<
gFaraday << endl;
98 out <<
"Molar volume cation " <<
gVPlus << endl;
99 out <<
"Molar volume anions " <<
gVMinus << endl;
100 out <<
"Gas constant " <<
gRGas << endl;
101 out <<
"Absolute temperature " <<
gTemp << endl;
103 for(ieq=0; ieq<3; ieq++) {
104 out <<
"Reference chemical potentials [" << ieq <<
"] " <<
gMuRef[ieq] << endl;
135 int numbersol = data.
sol.
size();
136 if (numbersol != 1) {
143 PZError <<
"TPZMatHyperElastic.ContributeBC : this material don't exists \n";
147 PZError <<
"ContributeBC.aplybc, unknown boundary condition type : "<<bc.
Type() << endl;
151 int nnod = ek.
Rows()/ndof;
157 for(in=0 ; in<nnod ; ++in){
158 for(idf = 0;idf<r;idf++) {
161 for(jn=0 ; jn<nnod ; ++jn) {
162 for(idf = 0;idf<r;idf++) {
163 ek(in*r+idf,jn*r+idf) +=
gBigNumber*phi(in,0)*phi(jn,0)*weight;
170 for(in=0 ; in<nnod ; ++in){
171 for(idf = 0;idf<r;idf++) {
173 (ef)(in*r+idf,0) += weight*phi(in,0)*(bc.
Val2()(
idf,0));
179 for(in=0 ; in<nnod ; ++in){
180 for(idf = 0;idf<r;idf++) {
181 for (jdf=0; jdf<r; jdf++){
182 (ef)(in*r+idf,0) += phi(in,0)*bc.
Val1()(
idf,jdf)*(bc.
Val2()(jdf,0)-sol[jdf])*weight;
184 for(jn=0 ; jn<nnod ; ++jn) {
185 for(idf = 0;idf<r;idf++) {
186 for(jdf = 0;jdf<r;jdf++) {
187 ek(in*r+idf,jn*r+jdf) += bc.
Val1()(
idf,jdf)*phi(in,0)*phi(jn,0)*weight;
203 inline int ith(
const int i,
const int j)
210 FADFADREAL &U, REAL weight)
213 int numeq = dsol[0].
size();
214 FADREAL defaultFAD(numeq, REAL(0.), REAL(0.));
215 FADFADREAL defaultFADFAD(numeq, defaultFAD, defaultFAD);
218 for(iel=0; iel<9; iel++) {
222 for(iel=0; iel<3; iel++) GradMap[ith(iel,iel)].val().val() +=
fInitDeform;
224 TrC = GradMap[0]*GradMap[0]+GradMap[1]*GradMap[1]+GradMap[2]*GradMap[2]+
225 GradMap[3]*GradMap[3]+GradMap[4]*GradMap[4]+GradMap[5]*GradMap[5]+
226 GradMap[6]*GradMap[6]+GradMap[7]*GradMap[7]+GradMap[8]*GradMap[8];
254 const int nstate = 8;
257 ContributePrevResidual(x,sol,dsol,phi,dphi,RES,weight);
260 int numeq = sol[0].
size();
261 FADREAL defaultFAD(numeq, REAL(0.), REAL(0.));
262 FADFADREAL defaultFADFAD(numeq, defaultFAD, defaultFAD);
263 FADFADREAL deform(defaultFADFAD);
268 for(der=0; der<9; der++) {
269 dsolFADFAD[der].val().val() = dsol[der].val();
270 for(ieq=0; ieq<numeq; ieq++) {
271 dsolFADFAD[der].val().fastAccessDx(ieq) = dsol[der].fastAccessDx(ieq);
272 dsolFADFAD[der].fastAccessDx(ieq).val() = dsol[der].fastAccessDx(ieq);
277 ContributeElastEnergy(dsolFADFAD, deform, weight);
280 for(ieq=0; ieq<numeq; ieq++) {
281 RES[ieq].val() += deform.fastAccessDx(ieq).val();
282 for(jeq=0; jeq<numeq; jeq++) {
283 RES[ieq].fastAccessDx(jeq) += deform.fastAccessDx(ieq).fastAccessDx(jeq);
292 FADREAL GradMap[3][3];
293 GradMap[0][0] = dsol[0]+REAL(1.);
294 GradMap[0][1] = dsol[1];
295 GradMap[0][2] = dsol[2];
296 GradMap[1][0] = dsol[3];
297 GradMap[1][1] = dsol[4]+REAL(1.);
298 GradMap[1][2] = dsol[5];
299 GradMap[2][0] = dsol[6];
300 GradMap[2][1] = dsol[7];
301 GradMap[2][2] = dsol[8]+REAL(1.);
361 void TPZSwelling::ContributePrevResidual(
TPZVec<REAL> & x,
368 const int nstate = 8;
371 cout <<
"TPZSwelling::ContributePrevResidual should not be called\n";
374 int numeq = sol[0].
size();
375 FADREAL defaultFAD(numeq, REAL(0.), REAL(0.));
376 FADFADREAL defaultFADFAD(numeq, defaultFAD, defaultFAD);
377 FADFADREAL deform(defaultFADFAD);
382 for(der=0; der<9; der++) {
383 dsolFADFAD[der].val().val() = dsol[der].val();
384 for(ieq=0; ieq<numeq; ieq++) {
385 dsolFADFAD[der].val().fastAccessDx(ieq) = dsol[der].fastAccessDx(ieq);
386 dsolFADFAD[der].fastAccessDx(ieq).val() = dsol[der].fastAccessDx(ieq);
397 GradMap[0][0] = dsol[0].val()+1.;
398 GradMap[0][1] = dsol[1].val();
399 GradMap[0][2] = dsol[2].val();
400 GradMap[1][0] = dsol[3].val();
401 GradMap[1][1] = dsol[4].val()+1.;
402 GradMap[1][2] = dsol[5].val();
403 GradMap[2][0] = dsol[6].val();
404 GradMap[2][1] = dsol[7].val();
405 GradMap[2][2] = dsol[8].val()+1.;
444 void TPZSwelling::ComputeW(FADFADREAL &W,
TPZVec<STATE> &N) {
471 NResidual(mu,ksi,pressure,N,res,tangent);
473 REAL resnorm =
Norm(res);
475 while(resnorm > 1.e-6) {
479 for(ieq=0; ieq<3; ieq++) {
480 N[ieq] -=
res(ieq,0);
482 NResidual(mu,ksi,pressure,N,res,tangent);
489 FADREAL defaultFAD(3,REAL(0.),STATE(0.));
490 FADFADREAL defaultFADFAD(3,defaultFAD,defaultFAD),W;
500 STATE z[3] = {0.,1.,-1.};
503 for(ieq=0; ieq<3; ieq++) {
504 res(ieq,0) = -mu[ieq]+W.val().fastAccessDx(ieq)+
gFaraday*z[ieq]*ksi/v[ieq]+pressure;
505 for(jeq=0; jeq<3; jeq++) {
506 tangent(ieq,jeq) = W.fastAccessDx(ieq).fastAccessDx(jeq);
522 REAL z[3] = {0.,1.,-1.};
524 FADREAL &ksi = sol[7];
525 FADREAL &pressure = sol[3];
526 for(ieq=0; ieq<3; ieq++) {
527 muloc[ieq]= sol[ieq+4].val();
528 Nloc[ieq] = N[ieq].val();
535 for(ieq=0; ieq<3; ieq++) {
536 N[ieq] = FADREAL(sol[0].size(),((REAL)Nloc[ieq]),0.);
541 for(ieq=0; ieq<3; ieq++) {
542 res[ieq] = -sol[ieq+4]+W.val().fastAccessDx(ieq)+
gFaraday*z[ieq]*ksi/v[ieq]+pressure;
543 for(jeq=0; jeq<3; jeq++) {
544 tangent[ieq][jeq] = FADREAL(sol[0].size(),W.fastAccessDx(ieq).fastAccessDx(jeq),0);
549 for(ieq=0; ieq<3; ieq++) {
558 for(k=0; k<neq; k++) {
559 FADREAL pivot = tangent[k][k];
560 for ( i = k+1; i < neq; i++ ) {
561 tangent[i][k] /= pivot;
562 for (j = k+1; j < neq; j++ ) tangent[i][j] -= tangent[i][k]*tangent[k][j];
563 res[i] -= tangent[i][k]*res[k];
566 for ( i = neq-1; i >= 0; i-- ) {
567 for (j = i+1; j < neq ; j++ ) {
568 res[i] -= tangent[i][j]*res[j];
570 res[i] /= tangent[i][i];
585 STATE DMinus = 5.e-4;
591 STATE cplus0 = (-Cfc+
sqrt(Cfc*Cfc+4.*C0*C0))/2.;
592 STATE cminus0 = (Cfc+
sqrt(Cfc*Cfc+4.*C0*C0))/2.;
593 STATE NPlus0 =
gVPlus*cplus0*Nf0;
594 STATE NMinus0 =
gVMinus*cminus0*Nf0;
596 TPZSwelling test(matindex, lambda, shear, alfa, M, Gamma, Kperm, DPlus, DMinus,
597 rHinder, Cfc, Nf0, NPlus0, NMinus0);
605 for(ieq=0; ieq<3; ieq++) {
608 FADREAL defaultFAD(8,REAL(0.),REAL(0.));
613 REAL
values[8] = {1.,1.,1.,0.001,-0.7243,-9258.,-1401.,-15};
616 for(ieq=0; ieq<3; ieq++) mu[ieq] = values[ieq+4];
617 STATE ksi,J = 1.0062,pres;
621 cout <<
"Based on J " << J <<
" and mu \n" << mu <<
"\nThe initial guesses pres " << pres <<
" ksi " << ksi <<
"\n N\n" << N << endl;
624 for(ieq=0; ieq<8; ieq++) {
625 sol[ieq].val() = values[ieq];
626 sol[ieq].fastAccessDx(ieq) = phi(0);
628 dsol[ieq*3 + d].val() = dphi(d,0)*values[ieq];
629 dsol[ieq*3 + d].fastAccessDx(ieq) = dphi(d,0);
635 STATE rangeval[11] = {0.1,0.1,0.1,0.0001,0.01,1.,1.,0.1,0.,0.,0.};
637 for(ieq=0; ieq<8; ieq++) {
638 state(ieq,0) = values[ieq];
639 range(ieq,0) = rangeval[ieq];
641 for(ieq=8; ieq<11; ieq++) {
642 state(ieq,0) = N[ieq-8];
643 range(ieq,0) = rangeval[ieq];
651 test.ContributeResidual(x,sol,dsol,phi,dphi,RES,weight);
654 ek.
Print(
"stiffness matrix");
665 for(ieq=0; ieq<nel; ieq++) {
666 for(jeq=0; jeq<nel; jeq++) {
667 ek(ieq,jeq) = vec[ieq].fastAccessDx(jeq);
678 if(state.
Rows() != 11) {
679 cout <<
"TPZSwelling LoadState wrong number of variables expect bad things\n";
684 tangent.
Redim(11,11);
686 FADREAL defaultFAD(8,REAL(0.),REAL(0.));
691 for(ieq=0; ieq<8; ieq++) {
693 sol[ieq].fastAccessDx(ieq) =
gphi(0);
696 dsol[ieq*3 + d].fastAccessDx(ieq) =
gdphi(d,0);
699 ContributeResidual(x,sol,dsol,
gphi,
gdphi,RES,weight);
700 for(ieq=0; ieq<8; ieq++) {
701 for(jeq=0; jeq<8; jeq++) {
702 tangent(ieq,jeq) = RES[ieq].fastAccessDx(jeq);
706 for(ieq=0; ieq<3; ieq++) N[ieq] =
gState(8+ieq,0);
707 FADREAL defwFAD(3,REAL(0.),REAL(0.));
708 FADFADREAL defwFADFAD(3,defwFAD,defwFAD);
709 FADFADREAL W(defwFADFAD);
711 for(ieq=0; ieq<3; ieq++) {
712 for(jeq=0; jeq<3; jeq++) {
713 tangent(8+ieq,8+jeq) = W.fastAccessDx(ieq).fastAccessDx(jeq);
720 FADREAL defaultFAD(8,REAL(0.),REAL(0.));
725 for(ieq=0; ieq<8; ieq++) {
727 sol[ieq].fastAccessDx(ieq) =
gphi(0);
730 dsol[ieq*3 + d].fastAccessDx(ieq) =
gdphi(d,0);
733 ContributeResidual(x,sol,dsol,
gphi,
gdphi,RES,weight);
734 for(ieq=0; ieq<8; ieq++) {
735 res(ieq,0) = RES[ieq].val();
738 for(ieq=0; ieq<3; ieq++) N[ieq] =
gState(8+ieq,0);
739 FADREAL defwFAD(3,REAL(0.),REAL(0.));
740 FADFADREAL defwFADFAD(3,defwFAD,defwFAD);
741 FADFADREAL W(defwFADFAD);
743 for(ieq=0; ieq<3; ieq++) {
744 res(8+ieq,0) = W.fastAccessDx(ieq).val();
754 STATE expcontr2 = expcontr*STATE(4.);
756 STATE cplus = (-
fCfc + sqrtval)/2.;
757 STATE cmin = (
fCfc+sqrtval)/2.;
760 for(iter=0; iter<5; iter++) {
763 cout <<
"pres " << pres <<
" cplus " << cplus <<
" cmin " << cmin <<
" expcontr " << expcontr << endl;
765 STATE expcontr2 = expcontr*STATE(4.);
767 cplus = (-
fCfc + sqrtval)/2.;
768 cmin = (
fCfc+sqrtval)/2.;
771 cout <<
"cplus " << cplus <<
" cmin " << cmin << endl;
784 STATE fac =
exp(c1)+
exp(c2);
786 N[0] =
pow(fac2/fac,1./(fGamma-1));
798 FADREAL &pres = sol[3];
799 FADREAL &mu0 = sol[4];
800 FADREAL &mu1 = sol[5];
801 FADREAL &mu2 = sol[6];
802 FADREAL &ksi = sol[7];
810 N[0] =
pow(fac2/(expc1+expc2),1./(fGamma-1));
811 FADREAL N0Gamma =
pow(N[0].
val(),(REAL)fGamma);
813 N[1] = N0Gamma*expc1*
gVPlus;
821 REAL &pres = sol[3].val();
822 REAL &mu0 = sol[4].val();
823 REAL &mu1 = sol[5].val();
824 REAL &mu2 = sol[6].val();
825 REAL &ksi = sol[7].val();
833 N[0] =
pow(fac2/(expc1+expc2),((REAL)(1./(fGamma-1))));
834 REAL N0Gamma =
pow(N[0],((REAL)fGamma));
836 N[1] = N0Gamma*expc1*
gVPlus;
STATE fDPlus
Diffusion coeficient for cations [mm^2/s].
virtual void Solution(TPZMaterialData &data, int var, TPZVec< STATE > &Solout)
Returns the solution associated with the var index based on the finite element approximation.
TPZFMatrix< STATE > fKperm
Hydraulic permeability .
void CheckConvergence(TConv &obj, TPZFMatrix< STATE > &state, TPZFMatrix< STATE > &range, TPZVec< REAL > &coefs)
Implements a general procedure to check whether the class TConv implements a consistente tangent matr...
STATE fNMinus0
Initial anion volume fraction (no dimension)
virtual void Solution(TPZVec< STATE > &Sol, TPZFMatrix< STATE > &DSol, TPZFMatrix< REAL > &axes, int var, TPZVec< STATE > &Solout) override
Computes a post-processed solution variable corresponding to the variable index.
Implements a vector class which allows to use external storage provided by the user. Utility.
STATE fM
Storage modulus [N/mm^2].
STATE fDMinus
Diffusion coeficient for anions [mm^2/s].
clarg::argBool bc("-bc", "binary checkpoints", false)
int NumCases()
Methods needed to perform convergence checks.
virtual void Print(std::ostream &out) override
Prints out the data associated with the material.
STATE fShear
Shear modulus [N/mm^2].
virtual int VariableIndex(const std::string &name)
Returns the variable index associated with the name.
The TPZSwelling class implements a numerical model of swelling material coupling flow through porous ...
virtual int NStateVariables() const override
Number of state variables, in this case: 3 displacements, 1 pressure, 3 eletrochemical potencials...
This class implements a simple vector storage scheme for a templated class T. Utility.
REAL val(STATE &number)
Returns value of the variable.
static TPZFMatrix< REAL > gdphi
TPZFMatrix< STATE > & Val2(int loadcase=0)
TPZFNMatrix< 220, REAL > phi
vector of shapefunctions (format is dependent on the value of shapetype)
void ExactSolution(TPZVec< STATE > &mu, STATE ksi, STATE pres, TPZVec< STATE > &N)
void ComputeTangent(TPZFMatrix< STATE > &tangent, TPZVec< REAL > &coefs, int cases)
Computes the tangent matrix for a given loadcase.
STATE fAlfa
Biot coupling coeficient (no dimension)
virtual void Print(std::ostream &out=std::cout)
Prints out the data associated with the material.
This abstract class defines the behaviour which each derived class needs to implement.
Contains declaration of TPZElementMatrix struct which associates an element matrix with the coeficien...
static STATE gTemp
Absolute temperature [K].
Contains the TPZBndCond class which implements a boundary condition for TPZMaterial objects...
static STATE gRGas
gas constant [Nmm/(mmol K)]
STATE fCfc
Fixed charge density [mmoleq/mm^3].
int64_t size() const
Returns the number of elements of the vector.
STATE fInitDeform
Initial deformation (assuming everything occurs isotropically, a constant is suficient (no dimension)...
STATE fNf0
Initial fluid volume fraction (do dimension)
TVar Norm(const TPZFMatrix< TVar > &A)
Returns the norm of the matrix A.
Contains TPZMatrixclass which implements full matrix (using column major representation).
#define DebugStop()
Returns a message to user put a breakpoint in.
This class defines the boundary condition for TPZMaterial objects.
virtual std::string Name() override
Returns the name of the material.
int64_t Rows() const
Returns number of rows.
STATE fTheta
Timestepping parameter theta (no dimension)
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ sqrt
static STATE gFaraday
Faraday constant [C/mmol].
void ComputeN(TPZVec< STATE > &N, TPZVec< STATE > &mu, STATE ksi)
Computes the value of the N coeficients in function of ksi and mus, iterative method, inverting the Hessian of W.
int fComputationMode
Computation mode: 0->residual wrt to time 1->residual and tangent wrt to time .
static TPZFMatrix< REAL > gphi
Variables which holds the state variables used in the check convergence procedure.
TPZFMatrix< STATE > & Val1()
STATE fGamma
Osmotic coeficient (no dimension)
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
TPZSwelling(int matindex, STATE lambda, STATE shear, STATE alfa, STATE M, STATE Gamma, STATE Kperm, STATE DPlus, STATE DMinus, STATE rHinder, STATE Cfc, STATE Nf0, STATE NPlus0, STATE NMinus0)
Constructor of the class, where the user needs to specify the most important parameters.
static REAL gBigNumber
Big number to penalization method, used for Dirichlet conditions.
void LoadState(TPZFMatrix< STATE > &state)
Loads the state within the current object, to be used when computing the tangent matrix.
int32_t Hash(std::string str)
Contains TPZMatrix<TVar>class, root matrix class.
int ClassId() const override
Unique identifier for serialization purposes.
STATE fNPlus0
Initial cation volume fraction (no dimension)
void ComputeInitialGuess(TPZVec< STATE > &mu, STATE J, STATE &pres, STATE &ksi, TPZVec< STATE > &N)
Computes the aproximate values of the pressure, ksi and N based on mu and J by direct inversion of th...
TPZFlopCounter pow(const TPZFlopCounter &orig, const TPZFlopCounter &xp)
Returns the power and increments the counter of the power.
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_ log
virtual int NSolutionVariables(int var)
Returns the number of variables associated with the variable indexed by var.
virtual int VariableIndex(const std::string &name) override
static STATE gMuRef[3]
Reference chemical potentials (order f,plus,minus) [mV].
static STATE gVPlus
Molar volume cation [mm^3/mmol].
virtual int ClassId() const override
Define the class id associated with the class.
STATE frHinder
Hindrance factor (no dimension)
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ exp
virtual void Print(std::ostream &out) const
STATE fLambda
Compression modulus [N/mm^2].
int64_t NElements() const
Returns the number of elements of the vector.
static TPZFMatrix< STATE > gState
Variables which holds the state variables used in the check convergence procedure.
Contains the implementation of the CheckConvergence function.
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...
Contains the TPZSwelling class which implements a numerical model of swelling material coupling flow...
TPZSolVec sol
vector of the solutions at the integration point
static STATE gVMinus
Molar volume anions [mm^3/mmol].
virtual int NSolutionVariables(int var) override
Returns the number of solution variables associated with a variable index.
virtual int SolveDirect(TPZFMatrix< TVar > &F, const DecomposeType dt, std::list< int64_t > &singular)
Solves the linear system using Direct methods.
#define PZError
Defines the output device to error messages and the DebugStop() function.
TPZMaterial * Material() const
void Residual(TPZFMatrix< STATE > &res, int cases)
Computes the residual for the given state variable.
void NResidual(TPZVec< STATE > &mu, STATE ksi, STATE pressure, TPZVec< STATE > &N, TPZFMatrix< STATE > &res, TPZFMatrix< STATE > &tangent)
Computes the residual and tangent vector of the system of equations which determines N...