NeoPZ
eulerdif.cpp
Go to the documentation of this file.
1 
5 #include "eulerdif.h"
6 #include "pzfmatrix.h"
7 #include "pzvec.h"
8 #include "pzreal.h"
9 using namespace std;
10 
11 STATE TEulerDiffusivity::fGamma = 1.4;
12 
13 
15  if(U[0] > -1.e-6 && U[0] < 1.e-6) return (fGamma-1.)*U[3];
16  STATE velocity = (U[1]*U[1]+U[2]*U[2])/U[0];
17  return (fGamma-1.)*(U[3]-(.5*velocity));
18 }
19 
21  //Variavel : u = (densidade, densidade*velocidade, energia)
22  //Funcao : f(u)=(densid*veloc, densid*(velocid)^2+pressao, veloc*(energia+pressao))
23  //Funcao : f(u)=( u2, ((u2*u2)/u1)+pressao, (u2/u1)*(u3+pressao))
24 
25  STATE pressao = Pressure(U);
26  if(U[0] > -1.e-6 && U[0] < 1.e-6) {
27  flux[0] = flux[2] = flux[3] = flux[4] = flux[5] = flux[7] = 0.;
28  cout << "EulerLaw2D::Flux find nule density.\n";
29  flux[1] = flux[6] = pressao; // Jorge 17/08
30  return;
31  }
32 
33  flux[0] = U[1];
34  flux[1] = ((U[1]/U[0])*U[1]) + pressao;
35  flux[2] = U[1]*(U[2]/U[0]);
36  flux[3] = (U[1]/U[0])*(U[3]+pressao);
37  flux[4] = U[2];
38  flux[5] = U[2]*(U[1]/U[0]);
39  flux[6] = ((U[2]/U[0])*U[2]) + pressao;
40  flux[7] = (U[2]/U[0])*(U[3] + pressao);
41 }
42 
44  if(U[0] > -1.e-6 && U[0] < 1.e-6) {
45  cout << "\nERRO : Densidade NULA. Falla jacobiano.\n";
46  exit(1);
47  }
48 
49  STATE velx, vely, ener, aux, gammam1 = fGamma-1.;
50  velx = U[1]/U[0];
51  vely = U[2]/U[0];
52  ener = U[3]/U[0];
53 
54  Ajacob(0,0)=Ajacob(0,2)=Ajacob(0,3)=Ajacob(2,3)=0.;
55  Bjacob(0,0)=Bjacob(0,1)=Bjacob(0,3)=Bjacob(1,3)=0.;
56  Ajacob(0,1)=Bjacob(0,2)=1.;
57  Ajacob(1,3)=Bjacob(2,3)=gammam1;
58  Ajacob(1,1)=(3.-fGamma)*velx;
59  Bjacob(2,2)=(3.-fGamma)*vely;
60  Ajacob(1,2)=-1.*gammam1*vely;
61  Bjacob(2,1)=-1.*gammam1*velx;
62  Ajacob(3,2)=Bjacob(3,1)=Ajacob(1,2)*velx;
63  Ajacob(2,0)=Bjacob(1,0)=-1.*velx*vely;
64  Ajacob(2,1)=Bjacob(1,1)=vely;
65  Ajacob(2,2)=Bjacob(1,2)=velx;
66  Ajacob(3,3)=fGamma*velx;
67  Bjacob(3,3)=fGamma*vely;
68  aux = gammam1*(velx*velx+vely*vely);
69  Ajacob(1,0) = 0.5*aux - (velx*velx);
70  Ajacob(3,1) = (fGamma*ener) - (.5*gammam1*(3*velx*velx+vely*vely));
71  Bjacob(3,2) = (fGamma*ener) - (.5*gammam1*(velx*velx+3*vely*vely));
72  Bjacob(2,0) = 0.5*aux - (vely*vely);
73  Ajacob(3,0) = (aux-(fGamma*ener))*velx;
74  Bjacob(3,0) = (aux-(fGamma*ener))*vely;
75 }
76 
78  valjacob.Zero();
79  STATE rho = U[0];
80  STATE vx, vy, /*lambda,*/ cval, cval2, u, kt, st, aa, bb;
81  STATE gM1 = fGamma-1.;
82  vx = U[1]/rho;
83  vy = U[2]/rho;
84  cval2 = (fGamma*Pressure(U))/rho;
85  if(cval2<0) {
86  cout << "TEulerLaw2D::ValJacobFlux. velocidade do som negativa.\n";
87  return;
88  }
89  cval = sqrt(cval2);
90  // d = sqrt(normal[0]*normal[0] + normal[1]*normal[1]);
91  // if(IsZero(d)) return 2;
92 
93  u = sqrt(vx*vx + vy*vy);
94  STATE Mach = u/cval;
95  STATE Mach2 = u*u/cval2;
96  if(u>-1.e-6 && u< 1.e-6) {
97  kt=1.;
98  st=0.;
99  } else {
100  kt = vx/u;
101  st = vy/u;
102  }
103  aa = normal[0]*kt + normal[1]*st;
104  bb = normal[1]*kt - normal[0]*st;
105  /*
106  cout << "normal = ("<<normal[0]<<","<<normal[1]<<")" << endl;
107  cout << "aa = " << aa << " bb = " << bb << endl;
108  cout << "kt = " << kt << " st = " << st << endl;
109  cout << "cval2 = " << cval2 << " Mach = " << Mach << endl;
110  */
111  STATE aabbnorm2 = aa*aa+bb*bb;
112  STATE aabbnorm = sqrt(aabbnorm2);
113  //Para o computo da matrix direita
114  TPZFMatrix<STATE> right(4,4);
115  TPZVec<STATE> diag(4);
116  STATE aascal = aa/aabbnorm;
117  STATE bbscal = bb/aabbnorm;
118  right(0,0) = -(bbscal*cval*Mach);
119  right(0,1) = bbscal*kt + aascal*st;
120  right(0,2) = -(aascal*kt) + bbscal*st;
121  right(0,3) = 0.;
122 
123  right(1,0) = 1 - gM1*Mach2/2.;
124  right(1,1) = (gM1*kt*Mach)/cval;
125  right(1,2) = (gM1*Mach*st)/cval;
126  right(1,3) = -gM1/cval2;
127 
128  right(2,0) = (cval2*Mach*(2*aascal + gM1*Mach))/4.;
129  right(2,1) = -(cval*(aascal*kt + gM1*kt*Mach - bbscal*st))/2.;
130  right(2,2) = -(cval*(bbscal*kt + (aascal + gM1*Mach)*st))/2.;
131  right(2,3) = gM1/2.;
132 
133  right(3,0) = (cval2*Mach*(-2*aascal + gM1*Mach))/4.;
134  right(3,1) = (cval*(aascal*kt - gM1*kt*Mach - bbscal*st))/2.;
135  right(3,2) = (cval*(bbscal*kt + (aascal - gM1*Mach)*st))/2.;
136  right(3,3) = gM1/2.;
137 
138  //matriz esquerda RtQX*val(autovalores)
139  TPZFMatrix<STATE> left(4,4);
140  left(0,0) = 0.;
141  left(0,1) = 1.;
142  left(0,2) = 1/cval2;
143  left(0,3) = 1/cval2;
144 
145  left(1,0) = bbscal*kt + aascal*st;
146  left(1,1) = cval*kt*Mach;
147  left(1,2) = (-(aascal*kt) + kt*Mach + bbscal*st)/cval;
148  left(1,3) = (aascal*kt + kt*Mach - bbscal*st)/cval;
149 
150  left(2,0) = -(aascal*kt) + bbscal*st;
151  left(2,1) = cval*Mach*st;
152  left(2,2) = -((bbscal*kt + aascal*st - Mach*st)/cval);
153  left(2,3) = (bbscal*kt + (aascal + Mach)*st)/cval;
154 
155 
156  left(3,0) = bbscal*cval*Mach;
157  left(3,1) = (cval2*Mach2)/2.;
158  left(3,2) = 1/gM1 + (Mach*(-2*aascal + Mach))/2.;
159  left(3,3) = 1/gM1 + (Mach*(2*aascal + Mach))/2.;
160 
161  //right.Print("right eigenvalues");
162  //left.Print("left eigenvalues");
163  diag[0] = fabs(aa*cval*Mach);
164  diag[1] = fabs(aa*cval*Mach);
165  diag[2] = fabs(-(aabbnorm*cval) + aa*cval*Mach);
166  diag[3] = fabs(cval*(aabbnorm + aa*Mach));
167 
168  int i,j,k;
169  for(i=0;i<4;i++) {
170  for(j=0;j<4;j++) {
171  valjacob(i,j)=0.;
172  for(k=0;k<4;k++) {
173  valjacob(i,j) += left(i,k)*diag[k]*right(k,j);
174  }
175  }
176  }
177  //valjacob.Print("valjacob");
178  return;
179 }
180 
181 //Dada uma matrix da forma {{0,a,b,x},{c,d,e,f},{g,h,i,j},{k,l,m,n}} retorna a inversa dela
183  STATE a=jac.GetVal(0,0), b=jac.GetVal(0,1), c=jac.GetVal(0,2), d=jac.GetVal(0,3);
184  STATE e=jac.GetVal(1,0), f=jac.GetVal(1,1), g=jac.GetVal(1,2), h=jac.GetVal(1,3);
185  STATE i=jac.GetVal(2,0), j=jac.GetVal(2,1), k=jac.GetVal(2,2), l=jac.GetVal(2,3);
186  STATE m=jac.GetVal(3,0), n=jac.GetVal(3,1), r=jac.GetVal(3,2), s=jac.GetVal(3,3);
187  STATE BHDF = b*h-d*f, BKCJ = b*k-c*j, BSDN = b*s-d*n, CFBG = c*f-b*g;
188  STATE CLDK = c*l-d*k, CNBR = c*n-b*r, DGCH = d*g-c*h, DJBL = d*j-b*l;
189  STATE DRCS = d*r-c*s, FRGN = f*r-g*n, GJFK = g*j-f*k, GSHR = g*s-h*r;
190  STATE FSHN = f*s-h*n, LNJS = l*n-j*s, HJFL = h*j-f*l, HKGL = h*k-g*l;
191  STATE KNJR = k*n-j*r, LRKS = l*r-k*s;
192  STATE det = DJBL*(g*m-e*r)+BHDF*(k*m-i*r)+BSDN*(g*i-e*k);
193  det += (FSHN*(a*k-c*i)+LNJS*(a*g-c*e)+HJFL*(a*r-c*m));
194  if(det > -1.e-6 && det < 1.e-6) {
195  cout << "TEulerLaw2D::InverseJacob. Determinante zero, matriz singular.\n";
196  exit(1);
197  }
198 
199  det = 1./det;
200  jac(0,0) = det*(k*FSHN+g*LNJS+r*HJFL);
201  jac(1,0) = det*(m*HKGL+i*GSHR+e*LRKS);
202  jac(2,0) = (-det)*(m*HJFL+i*FSHN+e*LNJS);
203  jac(3,0) = det*(m*GJFK+i*FRGN+e*KNJR);
204  jac(0,1) = det*(d*KNJR+b*LRKS-c*LNJS);
205  jac(1,1) = det*(m*CLDK+i*DRCS-a*LRKS);
206  jac(2,1) = det*(m*DJBL+i*BSDN+a*LNJS);
207  jac(3,1) = det*(m*BKCJ+i*CNBR-a*KNJR);
208  jac(0,2) = det*(d*FRGN-c*FSHN+b*GSHR);
209  jac(1,2) = det*(m*DGCH-e*DRCS-a*GSHR);
210  jac(2,2) = det*(m*BHDF-e*BSDN+a*FSHN);
211  jac(3,2) = det*(m*CFBG-e*CNBR-a*FRGN);
212  jac(0,3) = det*(d*GJFK-c*HJFL+b*HKGL);
213  jac(1,3) = (-det)*(i*DGCH+e*CLDK+a*HKGL);
214  jac(2,3) = det*(a*HJFL-i*BHDF-e*DJBL);
215  jac(3,3) = (-det)*(i*CFBG+e*BKCJ+a*GJFK);
216 }
217 
219 
220  REAL tmp[2][2];
221  // d(ksi) / dx
222  tmp[0][0] = jacinv(0,0)*axes(0,0)+jacinv(0,1)*axes(1,0);
223  // d(ksi) / dy
224  tmp[0][1] = jacinv(0,0)*axes(0,1)+jacinv(0,1)*axes(1,1);
225  // d(eta) / dx
226  tmp[1][0] = jacinv(1,0)*axes(0,0)+jacinv(1,1)*axes(1,0);
227  // d(eta) / dy
228  tmp[1][1] = jacinv(1,0)*axes(0,1)+jacinv(1,1)*axes(1,1);
229 
230  jacinv(0,0) = tmp[0][0];
231  jacinv(0,1) = tmp[0][1];
232  jacinv(1,0) = tmp[1][0];
233  jacinv(1,1) = tmp[1][1];
234 }
235 
238  TPZFMatrix<STATE> &BTauB) {
239 
240  //Computando o jacobiano da transformacao do elemento mestre ao elemento triangular
241  InvJacob2d(axes,jacinv);
242 
243  //int dsolr = dsol.Rows(), dsolc = dsol.Cols();
244  // Vetor de coeficientes dos jacobianos (alfa,beta) onde alfa*B+beta*B
245  TPZVec<REAL> Beta(2);
246 
247  TPZFMatrix<STATE> Ajacob(4,4);
248  TPZFMatrix<STATE> Bjacob(4,4);
249  TPZFMatrix<STATE> valjacob(4,4);
250  TPZFMatrix<STATE> invvaljacob(4,4,0.);
251 
252  JacobFlux(sol,Ajacob,Bjacob);
253 
254  // Calculando Tau
255  // Matrix | jacinv(0,0)*A + jacinv(0,1)*B|
256  Beta[0] = jacinv(0,0); Beta[1] = jacinv(0,1);
257  ValJacobFlux(sol,valjacob,Beta);
258  //valjacob.Print("Jacob ValAbs dksi");
259 
260  invvaljacob = valjacob;
261  Beta[0] = jacinv(1,0); Beta[1] = jacinv(1,1);
262  ValJacobFlux(sol,valjacob,Beta);
263  //valjacob.Print("Jacob ValAbs deta");
264 
265  invvaljacob += valjacob;
266  InverseJacob(invvaljacob);
267  //invvaljacob.Print("InvValJacob");
268 
269  ATauA.Zero();
270  ATauB.Zero();
271  BTauA.Zero();
272  BTauB.Zero();
273  int i,j,k,l;
274  for(i=0;i<4;i++) {
275  for(j=0;j<4;j++) {
276  for(k=0;k<4;k++) {
277  for(l=0;l<4;l++) {
278  ATauA(i,j) += Ajacob(i,k)*invvaljacob(k,l)*Ajacob(l,j);
279  ATauB(i,j) += Ajacob(i,k)*invvaljacob(k,l)*Bjacob(l,j);
280  BTauA(i,j) += Bjacob(i,k)*invvaljacob(k,l)*Ajacob(l,j);
281  BTauB(i,j) += Bjacob(i,k)*invvaljacob(k,l)*Bjacob(l,j);
282  }
283  }
284  }
285  }
286 }
287 
289  &normal) {
290 
291  STATE velx, vely, ener, aux, gammam1 = fGamma-1.;
292  velx = U[1]/U[0];
293  vely = U[2]/U[0];
294  ener = U[3]/U[0];
295  STATE alfa = normal[0], beta= normal[1];
296  aux = gammam1*(velx*velx+vely*vely);
297 
298  jacob(0,0)=jacob(0,3)=0.;
299  jacob(0,1)=alfa; jacob(0,2)=beta;
300  jacob(1,3)= alfa*gammam1;
301  jacob(2,3)= beta*gammam1;
302  jacob(1,1)= alfa*((3.-fGamma)*velx)+beta*vely;
303  jacob(1,2)=-alfa*gammam1*vely+beta*velx;
304  jacob(3,2)=-alfa*gammam1*velx*vely+beta*((fGamma*ener) - .5*gammam1*(3*vely*vely+velx*velx));
305  jacob(2,0)=-alfa*velx*vely+beta*(0.5*aux - (vely*vely));
306  jacob(2,1)=alfa*vely-beta*gammam1*velx;
307  jacob(2,2)=alfa*velx+beta*(3.-fGamma)*vely;
308  jacob(3,3)=fGamma*(alfa*velx+beta*vely);
309  jacob(1,0) = alfa*(0.5*aux - (velx*velx))-beta*(velx*vely);
310  jacob(3,1) = alfa*((fGamma*ener) - .5*gammam1*(3*velx*velx+vely*vely))-beta*gammam1*vely*velx;
311  jacob(3,0) = (alfa*velx+beta*vely)*(aux - fGamma*ener);
312 }
313 
315 
316  TEulerDiffusivity eul;
317  TPZVec<STATE> U(4);
318  U[0] = 5.4;
319  U[1] = -.5;
320  U[2] = -.25;
321  U[3] = 50.8;
322  TPZVec<STATE> flux(8);
323  eul.Flux(U,flux);
324 
325  TPZVec<REAL> normal(2);
326  normal[0] = 0.5;
327  normal[1] = sqrt(.75);
328  TPZFMatrix<STATE> A(4,4);
329  TPZFMatrix<STATE> B(4,4);
330  TPZFMatrix<STATE> jacob(4,4);
331  eul.JacobFlux(U,A,B);
332  eul.JacobFlux(U,jacob,normal);
333  A *= normal[0];
334  B *= normal[1];
335  int i,j;
336  for(j=0;j<4;j++)
337  for(i=0;i<4;i++)
338  A(i,j) += B(i,j);
339 
340  eul.ValJacobFlux(U,jacob,normal);
341  jacob.Print("ValJacob");
342  TPZFMatrix<REAL> axes(3,3,0.),jacinv(2,2,0.);
343  TPZFNMatrix<16,STATE> ATA(4,4), ATB(4,4), BTA(4,4),BTB(4,4);
344  axes(0,0)=1.5; axes(0,1)=2.3; axes(1,0)=.1; axes(1,1)=-1.9;
345  jacinv(0,0) = 1.3;jacinv(0,1) = -2.4;jacinv(1,0)=3.5;jacinv(1,1)=5.2;
346  eul.MatrixDiff(U,axes,jacinv,ATA,ATB,BTA,BTB);
347  ATA.Print("ATA ");
348  ATB.Print("ATB ");
349  BTA.Print("BTA ");
350  BTB.Print("BTB ");
351  return 0;
352 }
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
static void Flux(TPZVec< STATE > &u, TPZVec< STATE > &flux)
Calculates the fluxes and .
Definition: eulerdif.cpp:20
static STATE fGamma
Polytropic gas constant.
Definition: eulerdif.h:43
Templated vector implementation.
static void JacobFlux(TPZVec< STATE > &u, TPZFMatrix< STATE > &Ajacob, TPZFMatrix< STATE > &Bjacob)
Definition: eulerdif.cpp:43
clarg::argBool h("-h", "help message", false)
AutoPointerMutexArrayInit tmp
int Zero() override
Makes Zero all the elements.
Definition: pzfmatrix.h:651
f
Definition: test.py:287
static void ValJacobFlux(TPZVec< STATE > &u, TPZFMatrix< STATE > &valjacob, TPZVec< REAL > &normal)
Definition: eulerdif.cpp:77
static STATE Pressure(TPZVec< STATE > &U)
Calculates the pressure from equation of state. It is expected: .
Definition: eulerdif.cpp:14
Contains TPZMatrixclass which implements full matrix (using column major representation).
Implements a numerical diffusivity coeficient for the SUPG method. Analysis: Solving process Analysis...
Definition: eulerdif.h:40
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
static void MatrixDiff(TPZVec< STATE > &sol, TPZFMatrix< REAL > &axes, TPZFMatrix< REAL > &jacinv, TPZFMatrix< STATE > &ATauA, TPZFMatrix< STATE > &ATauB, TPZFMatrix< STATE > &BTauA, TPZFMatrix< STATE > &BTauB)
Definition: eulerdif.cpp:236
static int main()
Static main for test.
Definition: eulerdif.cpp:314
Contains the TEulerDiffusivity class which implements a numerical diffusivity coefficient for SUPG...
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")
static void InvJacob2d(TPZFMatrix< REAL > &axes, TPZFMatrix< REAL > &jacinv)
Definition: eulerdif.cpp:218
static void InverseJacob(TPZFMatrix< STATE > &jac)
Definition: eulerdif.cpp:182
const TVar & GetVal(const int64_t row, const int64_t col) const override
Get values without bounds checking This method is faster than "Get" if DEBUG is defined.
Definition: pzfmatrix.h:566
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
Definition: pzfmatrix.h:716