file(GLOB FullEulerEquations_EXAMPLES_TO_INSTALL
-EulerSystem1D/EulerSystem1DUpwind EulerSystem1D/EulerSystem1DUpwindEntrCorr EulerSystem1D/EulerSystem1DConservativeStaggered EulerSystem_Shock/EulerSystemStaggered EulerSystem_Shock/EulerSystemUpwind
+EulerSystem1D_HeatedChannel_Roe EulerSystem1D_HeatedChannel_MAC EulerSystem1D_RiemannProblem_Roe EulerSystem1D_RiemannProblem_MAC
)
install(DIRECTORY ${FullEulerEquations_EXAMPLES_TO_INSTALL} DESTINATION share/examples/EulerEquations/FullEulerEquations)
IF (CDMATH_WITH_PYTHON AND CDMATH_WITH_PETSC AND CDMATH_WITH_POSTPRO)
- ADD_SUBDIRECTORY(EulerSystem1D_RiemannProblem)
- ADD_SUBDIRECTORY(EulerSystem1D_HeatedChannel)
+ ADD_SUBDIRECTORY(EulerSystem1D_RiemannProblem_Roe)
+ ADD_SUBDIRECTORY(EulerSystem1D_RiemannProblem_MAC)
+ ADD_SUBDIRECTORY(EulerSystem1D_HeatedChannel_Roe)
+ ADD_SUBDIRECTORY(EulerSystem1D_HeatedChannel_MAC)
ENDIF (CDMATH_WITH_PYTHON AND CDMATH_WITH_PETSC AND CDMATH_WITH_POSTPRO)
+++ /dev/null
-
-if (CDMATH_WITH_PYTHON AND CDMATH_WITH_PETSC AND CDMATH_WITH_POSTPRO)
-
- ADD_TEST(ExampleFullEulerSystem_1DHeatedChannel_Roe ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Euler_complet_HeatedChanel.py )
-
-endif (CDMATH_WITH_PYTHON AND CDMATH_WITH_PETSC AND CDMATH_WITH_POSTPRO)
-
-
+++ /dev/null
-#!/usr/bin/env python3\r
-# -*-coding:utf-8 -*\r
-\r
-"""\r
-Created on Mon Aug 30 2021\r
-@author: Michael NDJINGA, Katia Ait Ameur, Coraline Mounier\r
-\r
-Euler system with heating source term (phi) in one dimension on regular domain [a,b]\r
-Riemann problemn with ghost cell boundary condition\r
-Left : Inlet boundary condition (velocity and temperature imposed)\r
-Right : Outlet boundary condition (pressure imposed)\r
-Roe scheme\r
-Regular square mesh\r
-\r
-State law Stiffened gaz : p = (gamma - 1) * rho * (e - q) - gamma * p0\r
-4 choices of parameters gamma and p0 are available : \r
- - Lagrange interpolation (with q=0)\r
- - Hermite interpolation with reference point at 575K (with q=0)\r
- - Hermite interpolation with reference point at 590K (with q=0)\r
- - Hermite interpolation with reference point at 617.94K (saturation at 155 bar) with q=0\r
- \r
-Linearized enthalpy : h = h_sat + cp * (T - T_sat)\r
-Values for cp and T_sat parameters are taken at the reference point chosen for the state law\r
-\r
-To do correct the computation of the time step : lambda_max (maximum eigenvalue) should be computed first)\r
-"""\r
-\r
-import cdmath\r
-import numpy as np\r
-import matplotlib\r
-\r
-matplotlib.use("Agg")\r
-import matplotlib.pyplot as plt\r
-import matplotlib.animation as manimation\r
-import sys\r
-from math import sqrt, atan, pi\r
-from numpy import sign\r
-\r
-\r
-#### Initial and boundary condition (T in K, v in m/s, p in Pa)\r
-T_inlet = 565.\r
-v_inlet = 5.\r
-p_outlet = 155.0 * 10**5\r
-\r
-#initial parameters are determined from boundary conditions\r
-p_0 = p_outlet #initial pressure\r
-v_0 = v_inlet #initial velocity\r
-T_0 = T_inlet #initial temperature\r
-### Heating source term\r
-phi=1.e8\r
-\r
-## Numerical parameter\r
-precision = 1e-6\r
-\r
-#state law parameter : can be 'Lagrange', 'Hermite590K', 'Hermite617K', or 'FLICA'\r
-state_law = "Hermite575K"\r
-\r
-def state_law_parameters(state_law):\r
- #state law Stiffened Gaz : p = (gamma - 1) * rho * e - gamma * p0\r
- global gamma\r
- global p0\r
- global q\r
- global c0\r
- global cp\r
- global h_sat\r
- global T_sat\r
- \r
- if state_law == "Lagrange":\r
- # reference values for Lagrange interpolation\r
- p_ref = 155. * 10**5 #Reference pressure in a REP 900 nuclear power plant \r
- p1 = 153. * 10**5 # value of pressure at inlet of a 900 MWe PWR vessel\r
- rho_ref = 594.38 #density of water at saturation temperature of 617.94K and 155 bars\r
- rho1 = 742.36 # value of density at inlet of a 900 MWe PWR vessel (T1 = 565K)\r
- e_ref = 1603.8 * 10**3 #internal energy of water at saturation temperature of 617.94K and 155 bars\r
- e1 = 1273.6 * 10**3 # value of internal energy at inlet of a 900 MWe PWR vessel\r
- \r
- gamma = (p1 - p_ref) / (rho1 * e1 - rho_ref *e_ref) + 1.\r
- p0 = - 1. / gamma * ( - (gamma - 1) * rho_ref * e_ref + p_ref)\r
- q=0.\r
- c0 = sqrt((gamma - 1) * (e_ref + p_ref / rho_ref))\r
- \r
- cp = 8950.\r
- h_sat = 1.63 * 10 ** 6 # saturation enthalpy of water at 155 bars\r
- T_sat = 617.94 \r
-\r
- elif state_law == "Hermite617K":\r
- # reference values for Hermite interpolation\r
- p_ref = 155. * 10**5 #Reference pressure in a REP 900 nuclear power plant\r
- T_ref = 617.94 #Reference temperature for interpolation at 617.94K\r
- rho_ref = 594.38 #density of water at saturation temperature of 617.94K and 155 bars\r
- e_ref = 1603.8 * 10**3 #internal energy of water at saturation temperature of 617.94K and 155 bars\r
- h_ref = e_ref + p_ref / rho_ref\r
- c_ref = 621.43 #sound speed for water at 155 bars and 617.94K\r
-\r
- gamma = 1. + c_ref * c_ref / (e_ref + p_ref / rho_ref) # From the sound speed formula\r
- p0 = 1. / gamma * ( (gamma - 1) * rho_ref * e_ref - p_ref) \r
- q=0.\r
- c0 = sqrt((gamma - 1) * (e_ref + p_ref / rho_ref))\r
- \r
- cp = 8950. # value at 155 bar and 617.94K\r
- h_sat = 1.63 * 10 ** 6 # saturation enthalpy of water at 155 bars\r
- T_sat = 617.94 \r
- \r
- elif state_law == 'Hermite590K':\r
- # reference values for Hermite interpolation\r
- p_ref = 155. * 10**5 #Reference pressure in a REP 900 nuclear power plant\r
- T_ref = 590. #Reference temperature for interpolation at 590K\r
- rho_ref = 688.3 #density of water at 590K and 155 bars\r
- e_ref = 1411.4 * 10**3 #internal energy of water at 590K and 155 bars\r
- h_ref = e_ref + p_ref / rho_ref\r
- c_ref = 866.29 #sound speed for water at 155 bars and 590K\r
- \r
- gamma = 1. + c_ref * c_ref / (e_ref + p_ref / rho_ref) # From the sound speed formula\r
- p0 = 1. / gamma * ( (gamma - 1) * rho_ref * e_ref - p_ref) \r
- q=0.\r
- c0 = sqrt((gamma - 1) * (e_ref + p_ref / rho_ref))\r
- \r
- cp = 5996.8 # value at 155 bar and 590K\r
- h_sat = 1433.9 * 10 ** 3 # saturation enthalpy of water at 155 bars\r
- T_sat = 590. \r
-\r
- elif state_law == 'Hermite575K':\r
- # reference values for Hermite interpolation\r
- p_ref = 155 * 10**5 #Reference pressure in a REP 900 nuclear power plant\r
- T_ref = 575 #Reference temperature at inlet in a REP 900 nuclear power plant\r
- #Remaining values determined using iapws python package\r
- rho_ref = 722.66 #density of water at 575K and 155 bars\r
- e_ref = 1326552.66 #internal energy of water at 575K and 155 bars\r
- h_ref = e_ref + p_ref / rho_ref\r
- c_ref = 959.28 #sound speed for water at 155 bars and 575K\r
- \r
- gamma = 1 + c_ref * c_ref / (e_ref + p_ref / rho_ref) # From the sound speed formula\r
- p0 = 1 / gamma * ( (gamma - 1) * rho_ref * e_ref - p_ref) \r
- q=0.\r
- c0 = sqrt((gamma - 1) * (e_ref + p_ref / rho_ref))#This is actually c_ref\r
- \r
- cp = 5504.05 # value at 155 bar and 590K\r
- h_sat = h_ref # saturation enthalpy of water at 155 bars\r
- T_sat = T_ref\r
- else:\r
- raise ValueError("Incorrect value for parameter state_law")\r
- \r
-def initial_conditions_Riemann_problem(a, b, nx):\r
- print("Initial data Riemann problem")\r
- dx = (b - a) / nx # space step\r
- x = [a + 0.5 * dx + i * dx for i in range(nx)] # array of cell center (1D mesh)\r
-\r
- p_initial = np.array([ p_0 for xi in x])\r
- v_initial = np.array([ v_0 for xi in x])\r
- T_initial = np.array([ T_0 for xi in x])\r
-\r
- rho_initial = p_to_rho_StiffenedGaz(p_initial, T_initial)\r
- q_initial = rho_initial * v_initial\r
- rho_E_initial = T_to_rhoE_StiffenedGaz(T_initial, rho_initial, q_initial)\r
-\r
- return rho_initial, q_initial, rho_E_initial, p_initial, v_initial, T_initial\r
-\r
-def p_to_rho_StiffenedGaz(p_field, T_field):\r
- rho_field = (p_field + p0) * gamma / (gamma - 1) * 1. / (h_sat + cp * (T_field - T_sat))\r
- return rho_field\r
- \r
-def T_to_rhoE_StiffenedGaz(T_field, rho_field, q_field):\r
- rho_E_field = 1. / 2. * (q_field) ** 2 / rho_field + p0 + rho_field / gamma * (h_sat + cp * (T_field- T_sat))\r
- return rho_E_field\r
-\r
-def rhoE_to_T_StiffenedGaz(rho_field, q_field, rho_E_field):\r
- T_field = T_sat + 1 / cp * (gamma * (rho_E_field / rho_field - 1 / 2 * (q_field / rho_field) ** 2) - gamma * p0 / rho_field - h_sat)\r
- return T_field\r
-\r
-def rho_to_p_StiffenedGaz(rho_field, q_field, rho_E_field):\r
- p_field = (gamma - 1) * (rho_E_field - 1. / 2 * q_field ** 2 / rho_field) - gamma * p0\r
- return p_field\r
-\r
-def T_to_E_StiffenedGaz(p_field, T_field, v_field):\r
- rho_field = p_to_rho_StiffenedGaz(p_field, T_field)\r
- E_field = (p_field + gamma * p0) / ((gamma-1) * rho_field) + 0.5 * v_field **2\r
- return E_field\r
- \r
-def dp_drho_e_const_StiffenedGaz( e ):\r
- return (gamma-1)*(e-q)\r
-\r
-def dp_de_rho_const_StiffenedGaz( rho ):\r
- return (gamma-1)*rho\r
-\r
-def sound_speed_StiffenedGaz( h ):\r
- return np.sqrt((gamma-1)*(h-q))\r
-\r
-def rho_h_to_p_StiffenedGaz( rho, h ):\r
- return (gamma - 1) * rho * ( h - q ) / gamma - p0\r
-\r
-def MatRoe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
- RoeMat = cdmath.Matrix(3, 3)\r
-\r
- u_l = q_l / rho_l\r
- u_r = q_r / rho_r\r
- p_l = rho_to_p_StiffenedGaz(rho_l, q_l, rho_E_l)\r
- p_r = rho_to_p_StiffenedGaz(rho_r, q_r, rho_E_r)\r
- H_l = rho_E_l / rho_l + p_l / rho_l\r
- H_r = rho_E_r / rho_r + p_r / rho_r\r
-\r
- # Roe averages\r
- rho = np.sqrt(rho_l * rho_r)\r
- u = (u_l * sqrt(rho_l) + u_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
- H = (H_l * sqrt(rho_l) + H_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
-\r
- p = rho_h_to_p_StiffenedGaz( rho, H - u**2/2. )\r
- e = H - p / rho - 1./2 * u**2\r
- dp_drho = dp_drho_e_const_StiffenedGaz( e )\r
- dp_de = dp_de_rho_const_StiffenedGaz( rho )\r
-\r
- RoeMat[0, 0] = 0\r
- RoeMat[0, 1] = 1\r
- RoeMat[0, 2] = 0\r
- RoeMat[1, 0] = dp_drho - u ** 2 + dp_de / rho * (u**2/2 - e)\r
- RoeMat[1, 1] = 2 * u - u * dp_de / rho\r
- RoeMat[1, 2] = dp_de / rho\r
- RoeMat[2, 0] = -u * ( -dp_drho + H - dp_de / rho * (u**2/2 - e) )\r
- RoeMat[2, 1] = H - dp_de / rho * u ** 2\r
- RoeMat[2, 2] = (dp_de / rho +1) * u\r
- \r
- return(RoeMat)\r
-\r
- \r
-def Droe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
- Droe = cdmath.Matrix(3, 3)\r
-\r
- u_l = q_l / rho_l\r
- u_r = q_r / rho_r\r
- p_l = rho_to_p_StiffenedGaz(rho_l, q_l, rho_E_l)\r
- p_r = rho_to_p_StiffenedGaz(rho_r, q_r, rho_E_r)\r
- H_l = rho_E_l / rho_l + p_l / rho_l\r
- H_r = rho_E_r / rho_r + p_r / rho_r\r
-\r
- # Roe averages\r
- rho = np.sqrt(rho_l * rho_r)\r
- u = (u_l * sqrt(rho_l) + u_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
- H = (H_l * sqrt(rho_l) + H_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
-\r
- c = sound_speed_StiffenedGaz( H - u**2/2. )\r
- \r
- lamb = cdmath.Vector(3)\r
- lamb[0] = u-c\r
- lamb[1] = u\r
- lamb[2] = u+c \r
-\r
- r = cdmath.Matrix(3, 3)\r
- r[0,0] = 1.\r
- r[1,0] = u-c\r
- r[2,0] = H-u*c \r
- r[0,1] = 1.\r
- r[1,1] = u \r
- r[2,1] = H-c**2/(gamma-1) \r
- r[0,2] = 1.\r
- r[1,2] = u+c\r
- r[2,2] = H+u*c \r
-\r
- l = cdmath.Matrix(3, 3)\r
- l[0,0] = (1./(2*c**2))*(0.5*(gamma-1)*u**2+u*c)\r
- l[1,0] = (1./(2*c**2))*(-u*(gamma-1)-c)\r
- l[2,0] = (1./(2*c**2))*(gamma-1)\r
- l[0,1] = ((gamma-1)/c**2)*(H-u**2)\r
- l[1,1] = ((gamma-1)/c**2)*u \r
- l[2,1] = -((gamma-1)/c**2) \r
- l[0,2] = (1./(2*c**2))*(0.5*(gamma-1)*u**2-u*c)\r
- l[1,2] = (1./(2*c**2))*(c-u*(gamma-1))\r
- l[2,2] = (1./(2*c**2))*(gamma-1)\r
-\r
- M1 = cdmath.Matrix(3, 3) #abs(lamb[0])*r[:,0].tensProduct(l[:,0])\r
- M2 = cdmath.Matrix(3, 3) #abs(lamb[1])*r[:,1].tensProduct(l[:,1]) \r
- M3 = cdmath.Matrix(3, 3) #abs(lamb[2])*r[:,2].tensProduct(l[:,2])\r
- for i in range(3):\r
- for j in range(3):\r
- M1[i,j] = abs(lamb[0])*r[i,0]*l[j,0]\r
- M2[i,j] = abs(lamb[1])*r[i,1]*l[j,1] \r
- M3[i,j] = abs(lamb[2])*r[i,2]*l[j,2]\r
- \r
- Droe = M1+M2+M3 \r
- \r
- return(Droe) \r
-\r
-\r
-def jacobianMatricesm(coeff, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
-\r
- if rho_l < 0 or rho_r < 0:\r
- print("rho_l=", rho_l, " rho_r= ", rho_r)\r
- raise ValueError("Negative density")\r
- if rho_E_l < 0 or rho_E_r < 0:\r
- print("rho_E_l=", rho_E_l, " rho_E_r= ", rho_E_r)\r
- raise ValueError("Negative total energy")\r
-\r
- RoeMat = MatRoe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
- \r
- Droe = Droe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
- return (RoeMat - Droe) * coeff * 0.5\r
-\r
-\r
-def jacobianMatricesp(coeff, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
- if rho_l < 0 or rho_r < 0:\r
- print("rho_l=", rho_l, " rho_r= ", rho_r)\r
- raise ValueError("Negative density")\r
- if rho_E_l < 0 or rho_E_r < 0:\r
- print("rho_E_l=", rho_E_l, " rho_E_r= ", rho_E_r)\r
- raise ValueError("Negative total energy")\r
-\r
- RoeMat = MatRoe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
- Droe = Droe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
-\r
- return (RoeMat + Droe) * coeff * 0.5\r
-\r
-\r
-def FillEdges(j, Uk, nbComp, divMat, Rhs, Un, dt, dx, isImplicit):\r
- dUi1 = cdmath.Vector(3)\r
- dUi2 = cdmath.Vector(3)\r
- temp1 = cdmath.Vector(3)\r
- temp2 = cdmath.Vector(3)\r
-\r
- if (j == 0):\r
- rho_l = Uk[j * nbComp + 0]\r
- q_l = Uk[j * nbComp + 1]\r
- rho_E_l = Uk[j * nbComp + 2]\r
- rho_r = Uk[(j + 1) * nbComp + 0]\r
- q_r = Uk[(j + 1) * nbComp + 1]\r
- rho_E_r = Uk[(j + 1) * nbComp + 2] \r
-\r
- Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
- divMat.addValue(j * nbComp, (j + 1) * nbComp, Am)\r
- divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
-\r
- p_inlet = rho_to_p_StiffenedGaz(Uk[j * nbComp + 0], Uk[j * nbComp + 1], Uk[j * nbComp + 2])# We take p from inside the domain\r
- rho_l=p_to_rho_StiffenedGaz(p_inlet, T_inlet) # rho is computed from the temperature BC and the inner pressure\r
- #rho_l = Uk[j * nbComp + 0] # We take rho from inside the domain\r
- q_l = rho_l * v_inlet # q is imposed by the boundary condition v_inlet\r
- rho_E_l = T_to_rhoE_StiffenedGaz(T_inlet, rho_l, q_l) #rhoE is obtained using the two boundary conditions v_inlet and e_inlet\r
- rho_r = Uk[j * nbComp + 0]\r
- q_r = Uk[j * nbComp + 1]\r
- rho_E_r = Uk[j * nbComp + 2]\r
-\r
- Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
- divMat.addValue(j * nbComp, j * nbComp, Ap)\r
- \r
- if(isImplicit):\r
- dUi1[0] = Uk[(j + 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
- dUi1[1] = Uk[(j + 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
- dUi1[2] = Uk[(j + 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
- temp1 = Am * dUi1\r
- \r
- dUi2[0] = rho_l - Uk[(j ) * nbComp + 0]\r
- dUi2[1] = q_l - Uk[(j ) * nbComp + 1]\r
- dUi2[2] = rho_E_l - Uk[(j ) * nbComp + 2]\r
- temp2 = Ap * dUi2\r
- else:\r
- dUi2[0] = rho_l \r
- dUi2[1] = q_l \r
- dUi2[2] = rho_E_l \r
- temp2 = Ap * dUi2\r
-\r
- elif (j == nx - 1):\r
- rho_l = Uk[(j - 1) * nbComp + 0]\r
- q_l = Uk[(j - 1) * nbComp + 1]\r
- rho_E_l = Uk[(j - 1) * nbComp + 2]\r
- rho_r = Uk[j * nbComp + 0]\r
- q_r = Uk[j * nbComp + 1]\r
- rho_E_r = Uk[j * nbComp + 2]\r
-\r
- Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
- divMat.addValue(j * nbComp, j * nbComp, Ap)\r
- divMat.addValue(j * nbComp, (j - 1) * nbComp, Ap * (-1.))\r
-\r
- rho_l = Uk[j * nbComp + 0]\r
- q_l = Uk[j * nbComp + 1]\r
- rho_E_l = Uk[j * nbComp + 2]\r
- rho_r = Uk[(j ) * nbComp + 0] # We take rho inside the domain\r
- q_r = Uk[(j ) * nbComp + 1] # We take q from inside the domain\r
- rho_E_r = (p_outlet+gamma*p0)/(gamma-1) + 0.5*q_r**2/rho_r # rhoE is obtained using the boundary condition p_outlet\r
-\r
- Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
- divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
-\r
- if(isImplicit):\r
- dUi1[0] = rho_r - Uk[j * nbComp + 0]\r
- dUi1[1] = q_r - Uk[j * nbComp + 1]\r
- dUi1[2] = rho_E_r - Uk[j * nbComp + 2]\r
- temp1 = Am * dUi1\r
-\r
- dUi2[0] = Uk[(j - 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
- dUi2[1] = Uk[(j - 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
- dUi2[2] = Uk[(j - 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
- temp2 = Ap * dUi2\r
- else:\r
- dUi1[0] = rho_r \r
- dUi1[1] = q_r \r
- dUi1[2] = rho_E_r \r
- temp1 = Am * dUi1\r
- \r
- if(isImplicit):#implicit scheme, contribution from the Newton scheme residual\r
- Rhs[j * nbComp + 0] = -temp1[0] + temp2[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
- Rhs[j * nbComp + 1] = -temp1[1] + temp2[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
- Rhs[j * nbComp + 2] = -temp1[2] + temp2[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
- else:#explicit scheme, contribution from the boundary data the right hand side\r
- Rhs[j * nbComp + 0] = -temp1[0] + temp2[0] \r
- Rhs[j * nbComp + 1] = -temp1[1] + temp2[1] \r
- Rhs[j * nbComp + 2] = -temp1[2] + temp2[2] \r
-\r
-def FillInnerCell(j, Uk, nbComp, divMat, Rhs, Un, dt, dx, isImplicit):\r
-\r
- rho_l = Uk[(j - 1) * nbComp + 0]\r
- q_l = Uk[(j - 1) * nbComp + 1]\r
- rho_E_l = Uk[(j - 1) * nbComp + 2]\r
- rho_r = Uk[j * nbComp + 0]\r
- q_r = Uk[j * nbComp + 1]\r
- rho_E_r = Uk[j * nbComp + 2]\r
- Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
- \r
- rho_l = Uk[j * nbComp + 0]\r
- q_l = Uk[j * nbComp + 1]\r
- rho_E_l = Uk[j * nbComp + 2]\r
- rho_r = Uk[(j + 1) * nbComp + 0]\r
- q_r = Uk[(j + 1) * nbComp + 1]\r
- rho_E_r = Uk[(j + 1) * nbComp + 2]\r
- Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
-\r
- divMat.addValue(j * nbComp, (j + 1) * nbComp, Am)\r
- divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
- divMat.addValue(j * nbComp, j * nbComp, Ap)\r
- divMat.addValue(j * nbComp, (j - 1) * nbComp, Ap * (-1.))\r
-\r
- if(isImplicit):\r
- dUi1 = cdmath.Vector(3)\r
- dUi2 = cdmath.Vector(3)\r
- \r
- dUi1[0] = Uk[(j + 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
- dUi1[1] = Uk[(j + 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
- dUi1[2] = Uk[(j + 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
- \r
- dUi2[0] = Uk[(j - 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
- dUi2[1] = Uk[(j - 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
- dUi2[2] = Uk[(j - 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
- \r
- temp1 = Am * dUi1\r
- temp2 = Ap * dUi2\r
-\r
- Rhs[j * nbComp + 0] = -temp1[0] + temp2[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
- Rhs[j * nbComp + 1] = -temp1[1] + temp2[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
- Rhs[j * nbComp + 2] = -temp1[2] + temp2[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
- else:\r
- Rhs[j * nbComp + 0] = 0\r
- Rhs[j * nbComp + 1] = 0\r
- Rhs[j * nbComp + 2] = 0\r
-\r
-def SetPicture(rho_field_Roe, q_field_Roe, h_field_Roe, p_field_Roe, v_field_Roe, T_field_Roe, dx):\r
- max_initial_rho = max(rho_field_Roe)\r
- min_initial_rho = min(rho_field_Roe)\r
- max_initial_q = max(q_field_Roe)\r
- min_initial_q = min(q_field_Roe)\r
- min_initial_h = min(h_field_Roe)\r
- max_initial_h = max(h_field_Roe)\r
- max_initial_p = max(p_field_Roe)\r
- min_initial_p = min(p_field_Roe)\r
- max_initial_v = max(v_field_Roe)\r
- min_initial_v = min(v_field_Roe)\r
- max_initial_T = max(T_field_Roe)\r
- min_initial_T = min(T_field_Roe)\r
-\r
- fig, ([axDensity, axMomentum, axh],[axPressure, axVitesse, axTemperature]) = plt.subplots(2, 3,sharex=True, figsize=(14,10))\r
- plt.gcf().subplots_adjust(wspace = 0.5)\r
-\r
- lineDensity_Roe, = axDensity.plot([a+0.5*dx + i*dx for i in range(nx)], rho_field_Roe, label='Roe')\r
- axDensity.set(xlabel='x (m)', ylabel='Densité (kg/m3)')\r
- axDensity.set_xlim(a,b)\r
- axDensity.set_ylim(680, 800)\r
- axDensity.legend()\r
-\r
- lineMomentum_Roe, = axMomentum.plot([a+0.5*dx + i*dx for i in range(nx)], q_field_Roe, label='Roe')\r
- axMomentum.set(xlabel='x (m)', ylabel='Momentum (kg/(m2.s))')\r
- axMomentum.set_xlim(a,b)\r
- axMomentum.set_ylim(3500, 4000)\r
- axMomentum.legend()\r
-\r
- lineh_Roe, = axh.plot([a+0.5*dx + i*dx for i in range(nx)], h_field_Roe, label='Roe')\r
- axh.set(xlabel='x (m)', ylabel='h (J/m3)')\r
- axh.set_xlim(a,b)\r
- axh.set_ylim(1.2 * 10**6, 1.5*10**6)\r
- axh.legend()\r
- \r
- linePressure_Roe, = axPressure.plot([a+0.5*dx + i*dx for i in range(nx)], p_field_Roe, label='Roe')\r
- axPressure.set(xlabel='x (m)', ylabel='Pression (bar)')\r
- axPressure.set_xlim(a,b)\r
- axPressure.set_ylim(155, 155.5)\r
- axPressure.ticklabel_format(axis='y', style='sci', scilimits=(0,0))\r
- axPressure.legend()\r
-\r
- lineVitesse_Roe, = axVitesse.plot([a+0.5*dx + i*dx for i in range(nx)], v_field_Roe, label='Roe')\r
- axVitesse.set(xlabel='x (m)', ylabel='Vitesse (m/s)')\r
- axVitesse.set_xlim(a,b)\r
- axVitesse.set_ylim(v_0-1, v_0+1)\r
- axVitesse.ticklabel_format(axis='y', style='sci', scilimits=(0,0))\r
- axVitesse.legend()\r
-\r
- lineTemperature_Roe, = axTemperature.plot([a+0.5*dx + i*dx for i in range(nx)], T_field_Roe, label='Roe')\r
- axTemperature.set(xlabel='x (m)', ylabel='Température (K)')\r
- axTemperature.set_xlim(a,b)\r
- axTemperature.set_ylim(T_0-10, T_0+30)\r
- axTemperature.ticklabel_format(axis='y', style='sci', scilimits=(0,0))\r
- axTemperature.legend()\r
- \r
- return(fig, lineDensity_Roe, lineMomentum_Roe, lineh_Roe, linePressure_Roe, lineVitesse_Roe, lineTemperature_Roe)\r
-\r
-\r
-def EulerSystemRoe(ntmax, tmax, cfl, a, b, nbCells, output_freq, meshName, state_law, isImplicit):\r
- state_law_parameters(state_law)\r
- dim = 1\r
- nbComp = 3\r
- dt = 0.\r
- time = 0.\r
- it = 0\r
- isStationary = False\r
- dx = (b - a) / nx\r
- dt = cfl * dx / c0\r
- #dt = 5*10**(-6)\r
- nbVoisinsMax = 2\r
-\r
- # iteration vectors\r
- Un_Roe = cdmath.Vector(nbCells * (nbComp))\r
- dUn_Roe = cdmath.Vector(nbCells * (nbComp))\r
- dUk_Roe = cdmath.Vector(nbCells * (nbComp))\r
- Rhs_Roe = cdmath.Vector(nbCells * (nbComp))\r
-\r
- # Initial conditions\r
- print("Construction of the initial condition …")\r
-\r
- rho_field_Roe, q_field_Roe, rho_E_field_Roe, p_field_Roe, v_field_Roe, T_field_Roe = initial_conditions_Riemann_problem(a, b, nx)\r
- h_field_Roe = (rho_E_field_Roe + p_field_Roe) / rho_field_Roe - 0.5 * (q_field_Roe / rho_field_Roe) **2\r
- p_field_Roe = p_field_Roe * 10 ** (-5)\r
- \r
-\r
- for k in range(nbCells):\r
- Un_Roe[k * nbComp + 0] = rho_field_Roe[k]\r
- Un_Roe[k * nbComp + 1] = q_field_Roe[k]\r
- Un_Roe[k * nbComp + 2] = rho_E_field_Roe[k]\r
-\r
- divMat_Roe = cdmath.SparseMatrixPetsc(nbCells * nbComp, nbCells * nbComp, (nbVoisinsMax + 1) * nbComp)\r
- \r
- # Picture settings\r
- fig, lineDensity_Roe, lineMomentum_Roe, lineRhoE_Roe, linePressure_Roe, lineVitesse_Roe, lineTemperature_Roe = SetPicture( rho_field_Roe, q_field_Roe, h_field_Roe, p_field_Roe, v_field_Roe, T_field_Roe, dx)\r
-\r
- plt.savefig("EulerComplet_HeatedChannel_" + str(dim) + "D_Roe" + meshName + "0" + ".png")\r
- iterGMRESMax = 50\r
- newton_max = 100\r
-\r
- print("Starting computation of the non linear Euler non isentropic system with Roe scheme …")\r
- # STARTING TIME LOOP\r
- while (it < ntmax and time <= tmax and not isStationary):\r
- dUn_Roe = Un_Roe.deepCopy()\r
- Uk_Roe = Un_Roe.deepCopy()\r
- residu_Roe = 1.\r
- \r
- k_Roe = 0\r
- while (k_Roe < newton_max and residu_Roe > precision):\r
- # STARTING NEWTON LOOP\r
- divMat_Roe.zeroEntries() #sets the matrix coefficients to zero\r
- for j in range(nbCells):\r
- \r
- # traitements des bords\r
- if (j == 0):\r
- FillEdges(j, Uk_Roe, nbComp, divMat_Roe, Rhs_Roe, Un_Roe, dt, dx, isImplicit)\r
- elif (j == nbCells - 1):\r
- FillEdges(j, Uk_Roe, nbComp, divMat_Roe, Rhs_Roe, Un_Roe, dt, dx, isImplicit)\r
-\r
- # traitement des cellules internes\r
- else:\r
- FillInnerCell(j, Uk_Roe, nbComp, divMat_Roe, Rhs_Roe, Un_Roe, dt, dx, isImplicit)\r
- \r
- Rhs_Roe[j * nbComp + 2] += phi*dt\r
- \r
- if(isImplicit):\r
- #solving the linear system divMat * dUk = Rhs\r
- divMat_Roe.diagonalShift(1.)\r
- LS_Roe = cdmath.LinearSolver(divMat_Roe, Rhs_Roe, iterGMRESMax, precision, "GMRES", "LU")\r
- dUk_Roe = LS_Roe.solve()\r
- vector_residu_Roe = dUk_Roe.maxVector(nbComp)\r
- residu_Roe = max(abs(vector_residu_Roe[0])/rho0, abs(vector_residu_Roe[1])/(rho0*v_0), abs(vector_residu_Roe[2])/rhoE0 )\r
- else:\r
- dUk_Roe=Rhs_Roe - divMat_Roe*Un_Roe\r
- residu_Roe = 0.#Convergence schéma Newton\r
- \r
- if (isImplicit and (it == 1 or it % output_freq == 0 or it >= ntmax or isStationary or time >= tmax)):\r
- print("Residu Newton at iteration ",k_Roe, " : ", residu_Roe)\r
- print("Linear system converged in ", LS_Roe.getNumberOfIter(), " GMRES iterations")\r
-\r
- #updates for Newton loop\r
- Uk_Roe += dUk_Roe\r
- k_Roe = k_Roe + 1\r
- if (isImplicit and not LS_Roe.getStatus()):\r
- print("Linear system did not converge ", LS_Roe.getNumberOfIter(), " GMRES iterations")\r
- raise ValueError("No convergence of the linear system")\r
- \r
- if k_Roe == newton_max:\r
- raise ValueError("No convergence of Newton Roe Scheme")\r
-\r
- #updating fields\r
- Un_Roe = Uk_Roe.deepCopy()\r
- dUn_Roe -= Un_Roe\r
-\r
- #Testing stationarity\r
- residu_stat = dUn_Roe.maxVector(nbComp)#On prend le max de chaque composante\r
- if (it % output_freq == 0 ):\r
- print("Test de stationarité : Un+1-Un= ", max(abs(residu_stat[0])/rho0, abs(residu_stat[1])/(rho0*v_0), abs(residu_stat[2])/rhoE0 ))\r
-\r
- if ( it>1 and abs(residu_stat[0])/rho0<precision and abs(residu_stat[1])/(rho0*v_0)<precision and abs(residu_stat[2])/rhoE0<precision):\r
- isStationary = True\r
- \r
- for k in range(nbCells):\r
- rho_field_Roe[k] = Un_Roe[k * nbComp + 0]\r
- q_field_Roe[k] = Un_Roe[k * nbComp + 1]\r
- rho_E_field_Roe[k] = Un_Roe[k * nbComp + 2]\r
-\r
- v_field_Roe = q_field_Roe / rho_field_Roe\r
- p_field_Roe = rho_to_p_StiffenedGaz(rho_field_Roe, q_field_Roe, rho_E_field_Roe)\r
- T_field_Roe = rhoE_to_T_StiffenedGaz(rho_field_Roe, q_field_Roe, rho_E_field_Roe)\r
- h_field_Roe = (rho_E_field_Roe + p_field_Roe) / rho_field_Roe - 0.5 * (q_field_Roe / rho_field_Roe) **2\r
- p_field_Roe = p_field_Roe * 10 ** (-5)\r
- \r
- if( min(p_field_Roe)<0) :\r
- raise ValueError("Negative pressure, stopping calculation")\r
-\r
- #picture and video updates\r
- lineDensity_Roe.set_ydata(rho_field_Roe)\r
- lineMomentum_Roe.set_ydata(q_field_Roe)\r
- lineRhoE_Roe.set_ydata(h_field_Roe)\r
- linePressure_Roe.set_ydata(p_field_Roe)\r
- lineVitesse_Roe.set_ydata(v_field_Roe)\r
- lineTemperature_Roe.set_ydata(T_field_Roe)\r
- \r
- time = time + dt\r
- it = it + 1\r
-\r
- # Savings\r
- if (it == 1 or it % output_freq == 0 or it >= ntmax or isStationary or time >= tmax):\r
- \r
- print("-- Time step : " + str(it) + ", Time: " + str(time) + ", dt: " + str(dt))\r
-\r
- print("Temperature gain between inlet and outlet is ", T_field_Roe[nbCells-1]-T_field_Roe[0],"\n")\r
-\r
- plt.savefig("EulerComplet_HeatedChannel_" + str(dim) + "D_Roe" + meshName + "Implicit"+str(isImplicit)+ str(it) + '_time' + str(time) + ".png")\r
-\r
- print("-- Iter: " + str(it) + ", Time: " + str(time) + ", dt: " + str(dt)+"\n")\r
- \r
- if (it >= ntmax):\r
- print("Maximum number of time steps ntmax= ", ntmax, " reached")\r
- return\r
-\r
- elif (isStationary):\r
- print("Stationary regime reached at time step ", it, ", t= ", time)\r
- print("------------------------------------------------------------------------------------")\r
- np.savetxt("EulerComplet_HeatedChannel_" + str(dim) + "D_Roe" + meshName + "_rho_Stat.txt", rho_field_Roe, delimiter="\n")\r
- np.savetxt("EulerComplet_HeatedChannel_" + str(dim) + "D_Roe" + meshName + "_q_Stat.txt", q_field_Roe, delimiter="\n")\r
- np.savetxt("EulerComplet_HeatedChannel_" + str(dim) + "D_Roe" + meshName + "_rhoE_Stat.txt", rho_E_field_Roe, delimiter="\n")\r
- np.savetxt("EulerComplet_HeatedChannel_" + str(dim) + "D_Roe" + meshName + "_p_Stat.txt", p_field_Roe, delimiter="\n")\r
- plt.savefig("EulerComplet_HeatedChannel_" + str(dim) + "D_Roe" + meshName + "Implicit"+str(isImplicit)+"_Stat.png")\r
- return\r
- else:\r
- print("Maximum time Tmax= ", tmax, " reached")\r
- return\r
-\r
-\r
-def solve(a, b, nx, meshName, meshType, cfl, state_law, isImplicit):\r
- print("Simulation of a heated channel in dimension 1 on " + str(nx) + " cells")\r
- print("State Law Stiffened Gaz, " + state_law)\r
- print("Initial data : ", "constant fields")\r
- print("Boundary conditions : ", "Inlet (Left), Outlet (Right)")\r
- print("Mesh name : ", meshName, ", ", nx, " cells")\r
- # Problem data\r
- tmax = 10.\r
- ntmax = 100000\r
- output_freq = 1000\r
- EulerSystemRoe(ntmax, tmax, cfl, a, b, nx, output_freq, meshName, state_law, isImplicit)\r
- return\r
-\r
-def FillMatrixFromEdges(j, Uk, nbComp, divMat, dt, dx):\r
-\r
- if (j == 0):\r
- rho_l = Uk[j * nbComp + 0]\r
- q_l = Uk[j * nbComp + 1]\r
- rho_E_l = Uk[j * nbComp + 2]\r
- rho_r = Uk[(j + 1) * nbComp + 0]\r
- q_r = Uk[(j + 1) * nbComp + 1]\r
- rho_E_r = Uk[(j + 1) * nbComp + 2] \r
-\r
- Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
- divMat.addValue(j * nbComp, (j + 1) * nbComp, Am)\r
- divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
- \r
- p_inlet = rho_to_p_StiffenedGaz(Uk[j * nbComp + 0], Uk[j * nbComp + 1], Uk[j * nbComp + 2])# We take p from inside the domain\r
- rho_l=p_to_rho_StiffenedGaz(p_inlet, T_inlet) # rho is computed from the temperature BC and the inner pressure\r
- #rho_l = Uk[j * nbComp + 0] # We take rho from inside the domain\r
- q_l = rho_l * v_inlet # q is imposed by the boundary condition v_inlet\r
- rho_E_l = T_to_rhoE_StiffenedGaz(T_inlet, rho_l, q_l) #rhoE is obtained using the two boundary conditions v_inlet and e_inlet\r
- rho_r = Uk[j * nbComp + 0]\r
- q_r = Uk[j * nbComp + 1]\r
- rho_E_r = Uk[j * nbComp + 2]\r
-\r
- Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
- divMat.addValue(j * nbComp, j * nbComp, Ap)\r
-\r
- elif (j == nx - 1):\r
- rho_l = Uk[j * nbComp + 0]\r
- q_l = Uk[j * nbComp + 1]\r
- rho_E_l = Uk[j * nbComp + 2]\r
- rho_r = Uk[(j ) * nbComp + 0] # We take rho inside the domain\r
- q_r = Uk[(j ) * nbComp + 1] # We take q from inside the domain\r
- rho_E_r = (p_outlet+gamma*p0)/(gamma-1) + 0.5*q_r**2/rho_r # rhoE is obtained using the boundary condition p_outlet\r
-\r
- Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
- divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
- \r
- rho_l = Uk[(j - 1) * nbComp + 0]\r
- q_l = Uk[(j - 1) * nbComp + 1]\r
- rho_E_l = Uk[(j - 1) * nbComp + 2]\r
- rho_r = Uk[j * nbComp + 0]\r
- q_r = Uk[j * nbComp + 1]\r
- rho_E_r = Uk[j * nbComp + 2]\r
-\r
- Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
- divMat.addValue(j * nbComp, j * nbComp, Ap)\r
- divMat.addValue(j * nbComp, (j - 1) * nbComp, Ap * (-1.))\r
-\r
-\r
-def FillMatrixFromInnerCell(j, Uk, nbComp, divMat, dt, dx):\r
-\r
- rho_l = Uk[(j - 1) * nbComp + 0]\r
- q_l = Uk[(j - 1) * nbComp + 1]\r
- rho_E_l = Uk[(j - 1) * nbComp + 2]\r
- rho_r = Uk[j * nbComp + 0]\r
- q_r = Uk[j * nbComp + 1]\r
- rho_E_r = Uk[j * nbComp + 2]\r
- Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
- \r
- rho_l = Uk[j * nbComp + 0]\r
- q_l = Uk[j * nbComp + 1]\r
- rho_E_l = Uk[j * nbComp + 2]\r
- rho_r = Uk[(j + 1) * nbComp + 0]\r
- q_r = Uk[(j + 1) * nbComp + 1]\r
- rho_E_r = Uk[(j + 1) * nbComp + 2]\r
- Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
-\r
- divMat.addValue(j * nbComp, (j + 1) * nbComp, Am)\r
- divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
- divMat.addValue(j * nbComp, j * nbComp, Ap)\r
- divMat.addValue(j * nbComp, (j - 1) * nbComp, Ap * (-1.))\r
- \r
-def FillRHSFromEdges(j, Uk, nbComp, Rhs, Un, dt, dx, isImplicit):\r
- dUi1 = cdmath.Vector(3)\r
- dUi2 = cdmath.Vector(3)\r
- temp1 = cdmath.Vector(3)\r
- temp2 = cdmath.Vector(3)\r
-\r
- if (j == 0):\r
- rho_l = Uk[j * nbComp + 0]\r
- q_l = Uk[j * nbComp + 1]\r
- rho_E_l = Uk[j * nbComp + 2]\r
- rho_r = Uk[(j + 1) * nbComp + 0]\r
- q_r = Uk[(j + 1) * nbComp + 1]\r
- rho_E_r = Uk[(j + 1) * nbComp + 2] \r
-\r
- Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
-\r
- p_inlet = rho_to_p_StiffenedGaz(Uk[j * nbComp + 0], Uk[j * nbComp + 1], Uk[j * nbComp + 2])# We take p from inside the domain\r
- rho_l=p_to_rho_StiffenedGaz(p_inlet, T_inlet) # rho is computed from the temperature BC and the inner pressure\r
- #rho_l = Uk[j * nbComp + 0] # We take rho from inside the domain\r
- q_l = rho_l * v_inlet # q is imposed by the boundary condition v_inlet\r
- rho_E_l = T_to_rhoE_StiffenedGaz(T_inlet, rho_l, q_l) #rhoE is obtained using the two boundary conditions v_inlet and e_inlet\r
- rho_r = Uk[j * nbComp + 0]\r
- q_r = Uk[j * nbComp + 1]\r
- rho_E_r = Uk[j * nbComp + 2]\r
-\r
- Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
- \r
- if(isImplicit):\r
- dUi1[0] = Uk[(j + 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
- dUi1[1] = Uk[(j + 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
- dUi1[2] = Uk[(j + 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
- temp1 = Am * dUi1\r
- \r
- dUi2[0] = rho_l - Uk[(j ) * nbComp + 0]\r
- dUi2[1] = q_l - Uk[(j ) * nbComp + 1]\r
- dUi2[2] = rho_E_l - Uk[(j ) * nbComp + 2]\r
- temp2 = Ap * dUi2\r
- else:\r
- dUi2[0] = rho_l \r
- dUi2[1] = q_l \r
- dUi2[2] = rho_E_l \r
- temp2 = Ap * dUi2\r
-\r
- elif (j == nx - 1):\r
- rho_l = Uk[(j - 1) * nbComp + 0]\r
- q_l = Uk[(j - 1) * nbComp + 1]\r
- rho_E_l = Uk[(j - 1) * nbComp + 2]\r
- rho_r = Uk[j * nbComp + 0]\r
- q_r = Uk[j * nbComp + 1]\r
- rho_E_r = Uk[j * nbComp + 2]\r
-\r
- Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
-\r
- rho_l = Uk[j * nbComp + 0]\r
- q_l = Uk[j * nbComp + 1]\r
- rho_E_l = Uk[j * nbComp + 2]\r
- rho_r = Uk[(j ) * nbComp + 0] # We take rho inside the domain\r
- q_r = Uk[(j ) * nbComp + 1] # We take q from inside the domain\r
- rho_E_r = (p_outlet+gamma*p0)/(gamma-1) + 0.5*q_r**2/rho_r # rhoE is obtained using the boundary condition p_outlet\r
-\r
- Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
-\r
- if(isImplicit):\r
- dUi1[0] = rho_r - Uk[j * nbComp + 0]\r
- dUi1[1] = q_r - Uk[j * nbComp + 1]\r
- dUi1[2] = rho_E_r - Uk[j * nbComp + 2]\r
- temp1 = Am * dUi1\r
- \r
- dUi2[0] = Uk[(j - 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
- dUi2[1] = Uk[(j - 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
- dUi2[2] = Uk[(j - 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
- temp2 = Ap * dUi2\r
- else:\r
- dUi1[0] = rho_r \r
- dUi1[1] = q_r \r
- dUi1[2] = rho_E_r \r
- temp1 = Am * dUi1\r
- \r
- if(isImplicit):\r
- Rhs[j * nbComp + 0] = -temp1[0] + temp2[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
- Rhs[j * nbComp + 1] = -temp1[1] + temp2[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
- Rhs[j * nbComp + 2] = -temp1[2] + temp2[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
- else:#explicit scheme, contribution from the boundary data the right hand side\r
- Rhs[j * nbComp + 0] = -temp1[0] + temp2[0] \r
- Rhs[j * nbComp + 1] = -temp1[1] + temp2[1] \r
- Rhs[j * nbComp + 2] = -temp1[2] + temp2[2] \r
-\r
-def FillRHSFromInnerCell(j, Uk, nbComp, Rhs, Un, dt, dx, isImplicit):\r
-\r
- rho_l = Uk[(j - 1) * nbComp + 0]\r
- q_l = Uk[(j - 1) * nbComp + 1]\r
- rho_E_l = Uk[(j - 1) * nbComp + 2]\r
- rho_r = Uk[j * nbComp + 0]\r
- q_r = Uk[j * nbComp + 1]\r
- rho_E_r = Uk[j * nbComp + 2]\r
- Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
- \r
- rho_l = Uk[j * nbComp + 0]\r
- q_l = Uk[j * nbComp + 1]\r
- rho_E_l = Uk[j * nbComp + 2]\r
- rho_r = Uk[(j + 1) * nbComp + 0]\r
- q_r = Uk[(j + 1) * nbComp + 1]\r
- rho_E_r = Uk[(j + 1) * nbComp + 2]\r
- Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
-\r
- if(isImplicit):#Contribution to the right hand side if te scheme is implicit\r
- dUi1 = cdmath.Vector(3)\r
- dUi2 = cdmath.Vector(3)\r
- \r
- dUi1[0] = Uk[(j + 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
- dUi1[1] = Uk[(j + 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
- dUi1[2] = Uk[(j + 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
- \r
- dUi2[0] = Uk[(j - 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
- dUi2[1] = Uk[(j - 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
- dUi2[2] = Uk[(j - 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
-\r
- temp1 = Am * dUi1\r
- temp2 = Ap * dUi2\r
-\r
- Rhs[j * nbComp + 0] = -temp1[0] + temp2[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
- Rhs[j * nbComp + 1] = -temp1[1] + temp2[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
- Rhs[j * nbComp + 2] = -temp1[2] + temp2[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
- else:\r
- Rhs[j * nbComp + 0] = 0\r
- Rhs[j * nbComp + 1] = 0\r
- Rhs[j * nbComp + 2] = 0\r
-\r
-\r
-def computeSystemMatrix(a,b,nx, cfl, Uk, isImplicit):\r
- dim = 1\r
- nbComp = 3\r
- dx = (b - a) / nx\r
- dt = cfl * dx / c0\r
- nbVoisinsMax = 2\r
-\r
- nbCells = nx\r
- divMat = cdmath.SparseMatrixPetsc(nbCells * nbComp, nbCells * nbComp, (nbVoisinsMax + 1) * nbComp)\r
-\r
- divMat.zeroEntries() #sets the matrix coefficients to zero\r
- for j in range(nbCells):\r
- \r
- # traitements des bords\r
- if (j == 0):\r
- FillMatrixFromEdges(j, Uk, nbComp, divMat, dt, dx)\r
- elif (j == nbCells - 1):\r
- FillMatrixFromEdges(j, Uk, nbComp, divMat, dt, dx)\r
- # traitement des cellules internes\r
- else:\r
- FillMatrixFromInnerCell(j, Uk, nbComp, divMat, dt, dx)\r
- \r
- if(isImplicit): \r
- divMat.diagonalShift(1.) # add one on the diagonal\r
- else:\r
- divMat*=-1.\r
- divMat.diagonalShift(1.) # add one on the diagonal\r
-\r
- return divMat\r
-\r
-def computeRHSVector(a,b,nx, cfl, Uk, Un, isImplicit):\r
- dim = 1\r
- nbComp = 3\r
- dx = (b - a) / nx\r
- dt = cfl * dx / c0\r
- nbVoisinsMax = 2\r
-\r
- nbCells = nx\r
- Rhs = cdmath.Vector(nbCells * (nbComp))\r
-\r
- for j in range(nbCells):\r
- \r
- # traitements des bords\r
- if (j == 0):\r
- FillRHSFromEdges(j, Uk, nbComp, Rhs, Un, dt, dx, isImplicit)\r
- elif (j == nbCells - 1):\r
- FillRHSFromEdges(j, Uk, nbComp, Rhs, Un, dt, dx, isImplicit)\r
- # traitement des cellules internes\r
- else:\r
- FillRHSFromInnerCell(j, Uk, nbComp, Rhs, Un, dt, dx, isImplicit)\r
- \r
- return Rhs\r
-\r
-\r
-if __name__ == """__main__""":\r
- nbComp=3 # number of equations \r
- a = 0.# domain is interval [a,b]\r
- b = 4.2# domain is interval [a,b]\r
- nx = 10# number of cells\r
- dx = (b - a) / nx # space step\r
- x = [a + 0.5 * dx + i * dx for i in range(nx)] # array of cell center (1D mesh)\r
- state_law = "Hermite575K"\r
- state_law_parameters(state_law)\r
- rho0=p_to_rho_StiffenedGaz(p_0, T_0)\r
- rhoE0=T_to_rhoE_StiffenedGaz(T_0, rho0, rho0*v_0)\r
-\r
-\r
-#### initial condition (T in K, v in m/s, p in Pa)\r
- p_initial = np.array([ p_outlet for xi in x])\r
- v_initial = np.array([ v_inlet for xi in x])\r
- T_initial = np.array([ T_inlet for xi in x])\r
- \r
- rho_field = p_to_rho_StiffenedGaz(p_initial, T_initial)\r
- q_field = rho_field * v_initial\r
- rho_E_field = rho_field * T_to_E_StiffenedGaz(p_initial, T_initial, v_initial)\r
-\r
- U = cdmath.Vector(nx * (nbComp))#Inutile à terme mais nécessaire pour le moment\r
-\r
- for k in range(nx):\r
- U[k * nbComp + 0] = rho_field[k]\r
- U[k * nbComp + 1] = q_field[k]\r
- U[k * nbComp + 2] = rho_E_field[k]\r
- print("\n Testing function computeSystemMatrix \n")\r
- cfl = 0.5\r
- computeSystemMatrix(a, b, nx, cfl, U,True) #Implicit matrix\r
- computeSystemMatrix(a, b, nx, cfl, U,False) #Explicit matrix\r
-\r
- print("\n Testing function computeRHSVector \n")\r
- cfl = 0.5\r
- computeRHSVector(a, b, nx, cfl, U, U,True) #Implicit RHS\r
- computeRHSVector(a, b, nx, cfl, U, U,False) #Explicit RHS\r
-\r
- print("\n Testing function solve (Implicit scheme) \n")\r
- isImplicit=True\r
- cfl = 1000.\r
- solve(a, b, nx, "RegularSquares", "", cfl, state_law, isImplicit)\r
- \r
- print("\n Testing function solve (Explicit scheme) \n")\r
- isImplicit=False\r
- cfl = 0.5\r
- solve(a, b, nx, "RegularSquares", "", cfl, state_law, isImplicit)\r
-\r
--- /dev/null
+
+if (CDMATH_WITH_PYTHON AND CDMATH_WITH_PETSC AND CDMATH_WITH_POSTPRO)
+
+ ADD_TEST(ExampleFullEulerSystem_1DHeatedChannel_MAC ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Euler_complet_HeatedChanel_MAC.py )
+
+endif (CDMATH_WITH_PYTHON AND CDMATH_WITH_PETSC AND CDMATH_WITH_POSTPRO)
+
+
--- /dev/null
+#!/usr/bin/env python3\r
+# -*-coding:utf-8 -*\r
+\r
+"""\r
+Created on Mon Sep 27 2021\r
+@author: Michael NDJINGA, Katia Ait Ameur, Coraline Mounier\r
+\r
+Euler system with heating source term (phi) in one dimension on regular domain [a,b]\r
+Riemann problemn with ghost cell boundary condition\r
+Left : Inlet boundary condition (velocity and temperature imposed)\r
+Right : Outlet boundary condition (pressure imposed)\r
+Staggered scheme\r
+Regular square mesh\r
+\r
+State law Stiffened gaz : p = (gamma - 1) * rho * (e - q) - gamma * p0\r
+4 choices of parameters gamma and p0 are available : \r
+ - Lagrange interpolation (with q=0)\r
+ - Hermite interpolation with reference point at 575K (with q=0)\r
+ - Hermite interpolation with reference point at 590K (with q=0)\r
+ - Hermite interpolation with reference point at 617.94K (saturation at 155 bar) with q=0\r
+ \r
+Linearized enthalpy : h = h_sat + cp * (T - T_sat)\r
+Values for cp and T_sat parameters are taken at the reference point chosen for the state law\r
+\r
+To do correct the computation of the time step : lambda_max (maximum eigenvalue) should be computed first)\r
+"""\r
+\r
+import cdmath\r
+import numpy as np\r
+import matplotlib\r
+\r
+matplotlib.use("Agg")\r
+import matplotlib.pyplot as plt\r
+from math import sqrt\r
+from numpy import sign\r
+\r
+\r
+#### Initial and boundary condition (T in K, v in m/s, p in Pa)\r
+T_inlet = 565.\r
+v_inlet = 5.\r
+p_outlet = 155.0 * 10**5\r
+\r
+#initial parameters are determined from boundary conditions\r
+p_0 = p_outlet #initial pressure\r
+v_0 = v_inlet #initial velocity\r
+T_0 = T_inlet #initial temperature\r
+### Heating source term\r
+phi=1.e8\r
+\r
+## Numerical parameter\r
+precision = 1e-6\r
+\r
+#state law parameter : can be 'Lagrange', 'Hermite590K', 'Hermite617K', or 'FLICA'\r
+state_law = "Hermite575K"\r
+\r
+def state_law_parameters(state_law):\r
+ #state law Stiffened Gaz : p = (gamma - 1) * rho * e - gamma * p0\r
+ global gamma\r
+ global p0\r
+ global q\r
+ global c0\r
+ global cp\r
+ global h_sat\r
+ global T_sat\r
+ \r
+ if state_law == "Lagrange":\r
+ # reference values for Lagrange interpolation\r
+ p_ref = 155. * 10**5 #Reference pressure in a REP 900 nuclear power plant \r
+ p1 = 153. * 10**5 # value of pressure at inlet of a 900 MWe PWR vessel\r
+ rho_ref = 594.38 #density of water at saturation temperature of 617.94K and 155 bars\r
+ rho1 = 742.36 # value of density at inlet of a 900 MWe PWR vessel (T1 = 565K)\r
+ e_ref = 1603.8 * 10**3 #internal energy of water at saturation temperature of 617.94K and 155 bars\r
+ e1 = 1273.6 * 10**3 # value of internal energy at inlet of a 900 MWe PWR vessel\r
+ \r
+ gamma = (p1 - p_ref) / (rho1 * e1 - rho_ref *e_ref) + 1.\r
+ p0 = - 1. / gamma * ( - (gamma - 1) * rho_ref * e_ref + p_ref)\r
+ q=0.\r
+ c0 = sqrt((gamma - 1) * (e_ref + p_ref / rho_ref))\r
+ \r
+ cp = 8950.\r
+ h_sat = 1.63 * 10 ** 6 # saturation enthalpy of water at 155 bars\r
+ T_sat = 617.94 \r
+\r
+ elif state_law == "Hermite617K":\r
+ # reference values for Hermite interpolation\r
+ p_ref = 155. * 10**5 #Reference pressure in a REP 900 nuclear power plant\r
+ T_ref = 617.94 #Reference temperature for interpolation at 617.94K\r
+ rho_ref = 594.38 #density of water at saturation temperature of 617.94K and 155 bars\r
+ e_ref = 1603.8 * 10**3 #internal energy of water at saturation temperature of 617.94K and 155 bars\r
+ h_ref = e_ref + p_ref / rho_ref\r
+ c_ref = 621.43 #sound speed for water at 155 bars and 617.94K\r
+\r
+ gamma = 1. + c_ref * c_ref / (e_ref + p_ref / rho_ref) # From the sound speed formula\r
+ p0 = 1. / gamma * ( (gamma - 1) * rho_ref * e_ref - p_ref) \r
+ q=0.\r
+ c0 = sqrt((gamma - 1) * (e_ref + p_ref / rho_ref))\r
+ \r
+ cp = 8950. # value at 155 bar and 617.94K\r
+ h_sat = 1.63 * 10 ** 6 # saturation enthalpy of water at 155 bars\r
+ T_sat = 617.94 \r
+ \r
+ elif state_law == 'Hermite590K':\r
+ # reference values for Hermite interpolation\r
+ p_ref = 155. * 10**5 #Reference pressure in a REP 900 nuclear power plant\r
+ T_ref = 590. #Reference temperature for interpolation at 590K\r
+ rho_ref = 688.3 #density of water at 590K and 155 bars\r
+ e_ref = 1411.4 * 10**3 #internal energy of water at 590K and 155 bars\r
+ h_ref = e_ref + p_ref / rho_ref\r
+ c_ref = 866.29 #sound speed for water at 155 bars and 590K\r
+ \r
+ gamma = 1. + c_ref * c_ref / (e_ref + p_ref / rho_ref) # From the sound speed formula\r
+ p0 = 1. / gamma * ( (gamma - 1) * rho_ref * e_ref - p_ref) \r
+ q=0.\r
+ c0 = sqrt((gamma - 1) * (e_ref + p_ref / rho_ref))\r
+ \r
+ cp = 5996.8 # value at 155 bar and 590K\r
+ h_sat = 1433.9 * 10 ** 3 # saturation enthalpy of water at 155 bars\r
+ T_sat = 590. \r
+\r
+ elif state_law == 'Hermite575K':\r
+ # reference values for Hermite interpolation\r
+ p_ref = 155 * 10**5 #Reference pressure in a REP 900 nuclear power plant\r
+ T_ref = 575 #Reference temperature at inlet in a REP 900 nuclear power plant\r
+ #Remaining values determined using iapws python package\r
+ rho_ref = 722.66 #density of water at 575K and 155 bars\r
+ e_ref = 1326552.66 #internal energy of water at 575K and 155 bars\r
+ h_ref = e_ref + p_ref / rho_ref\r
+ c_ref = 959.28 #sound speed for water at 155 bars and 575K\r
+ \r
+ gamma = 1 + c_ref * c_ref / (e_ref + p_ref / rho_ref) # From the sound speed formula\r
+ p0 = 1 / gamma * ( (gamma - 1) * rho_ref * e_ref - p_ref) \r
+ q=0.\r
+ c0 = sqrt((gamma - 1) * (e_ref + p_ref / rho_ref))#This is actually c_ref\r
+ \r
+ cp = 5504.05 # value at 155 bar and 590K\r
+ h_sat = h_ref # saturation enthalpy of water at 155 bars\r
+ T_sat = T_ref\r
+ else:\r
+ raise ValueError("Incorrect value for parameter state_law")\r
+ \r
+def initial_conditions_Riemann_problem(a, b, nx):\r
+ print("Initial data Riemann problem")\r
+ dx = (b - a) / nx # space step\r
+ x = [a + 0.5 * dx + i * dx for i in range(nx)] # array of cell center (1D mesh)\r
+\r
+ p_initial = np.array([ p_0 for xi in x])\r
+ v_initial = np.array([ v_0 for xi in x])\r
+ T_initial = np.array([ T_0 for xi in x])\r
+\r
+ rho_initial = p_to_rho_StiffenedGaz(p_initial, T_initial)\r
+ q_initial = rho_initial * v_initial\r
+ rho_E_initial = T_to_rhoE_StiffenedGaz(T_initial, rho_initial, q_initial)\r
+\r
+ return rho_initial, q_initial, rho_E_initial, p_initial, v_initial, T_initial\r
+\r
+def p_to_rho_StiffenedGaz(p_field, T_field):\r
+ rho_field = (p_field + p0) * gamma / (gamma - 1) * 1. / (h_sat + cp * (T_field - T_sat))\r
+ return rho_field\r
+ \r
+def T_to_rhoE_StiffenedGaz(T_field, rho_field, q_field):\r
+ rho_E_field = 1. / 2. * (q_field) ** 2 / rho_field + p0 + rho_field / gamma * (h_sat + cp * (T_field- T_sat))\r
+ return rho_E_field\r
+\r
+def rhoE_to_T_StiffenedGaz(rho_field, q_field, rho_E_field):\r
+ T_field = T_sat + 1 / cp * (gamma * (rho_E_field / rho_field - 1 / 2 * (q_field / rho_field) ** 2) - gamma * p0 / rho_field - h_sat)\r
+ return T_field\r
+\r
+def rho_to_p_StiffenedGaz(rho_field, q_field, rho_E_field):\r
+ p_field = (gamma - 1) * (rho_E_field - 1. / 2 * q_field ** 2 / rho_field) - gamma * p0\r
+ return p_field\r
+\r
+def T_to_E_StiffenedGaz(p_field, T_field, v_field):\r
+ rho_field = p_to_rho_StiffenedGaz(p_field, T_field)\r
+ E_field = (p_field + gamma * p0) / ((gamma-1) * rho_field) + 0.5 * v_field **2\r
+ return E_field\r
+ \r
+def dp_drho_e_const_StiffenedGaz( e ):\r
+ return (gamma-1)*(e-q)\r
+\r
+def dp_de_rho_const_StiffenedGaz( rho ):\r
+ return (gamma-1)*rho\r
+\r
+def sound_speed_StiffenedGaz( h ):\r
+ return np.sqrt((gamma-1)*(h-q))\r
+\r
+def rho_h_to_p_StiffenedGaz( rho, h ):\r
+ return (gamma - 1) * rho * ( h - q ) / gamma - p0\r
+\r
+def MatRoe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
+ RoeMat = cdmath.Matrix(3, 3)\r
+\r
+ u_l = q_l / rho_l\r
+ u_r = q_r / rho_r\r
+ p_l = rho_to_p_StiffenedGaz(rho_l, q_l, rho_E_l)\r
+ p_r = rho_to_p_StiffenedGaz(rho_r, q_r, rho_E_r)\r
+ H_l = rho_E_l / rho_l + p_l / rho_l\r
+ H_r = rho_E_r / rho_r + p_r / rho_r\r
+\r
+ # Roe averages\r
+ rho = np.sqrt(rho_l * rho_r)\r
+ u = (u_l * sqrt(rho_l) + u_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
+ H = (H_l * sqrt(rho_l) + H_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
+\r
+ p = rho_h_to_p_StiffenedGaz( rho, H - u**2/2. )\r
+ e = H - p / rho - 1./2 * u**2\r
+ dp_drho = dp_drho_e_const_StiffenedGaz( e )\r
+ dp_de = dp_de_rho_const_StiffenedGaz( rho )\r
+\r
+ RoeMat[0, 0] = 0\r
+ RoeMat[0, 1] = 1\r
+ RoeMat[0, 2] = 0\r
+ RoeMat[1, 0] = dp_drho - u ** 2 + dp_de / rho * (u**2/2 - e)\r
+ RoeMat[1, 1] = 2 * u - u * dp_de / rho\r
+ RoeMat[1, 2] = dp_de / rho\r
+ RoeMat[2, 0] = -u * ( -dp_drho + H - dp_de / rho * (u**2/2 - e) )\r
+ RoeMat[2, 1] = H - dp_de / rho * u ** 2\r
+ RoeMat[2, 2] = (dp_de / rho +1) * u\r
+ \r
+ return(RoeMat)\r
+\r
+ \r
+def Dmac_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
+ Dmac = cdmath.Matrix(3, 3)\r
+\r
+ u_l = q_l / rho_l\r
+ u_r = q_r / rho_r\r
+ p_l = rho_to_p_StiffenedGaz(rho_l, q_l, rho_E_l)\r
+ p_r = rho_to_p_StiffenedGaz(rho_r, q_r, rho_E_r)\r
+ H_l = rho_E_l / rho_l + p_l / rho_l\r
+ H_r = rho_E_r / rho_r + p_r / rho_r\r
+\r
+ # Roe averages\r
+ rho = np.sqrt(rho_l * rho_r)\r
+ u = (u_l * sqrt(rho_l) + u_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
+ H = (H_l * sqrt(rho_l) + H_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
+\r
+ p = rho_h_to_p_StiffenedGaz( rho, H - u**2/2. )\r
+ e = H - p / rho - 1./2 * u**2\r
+ dp_drho = dp_drho_e_const_StiffenedGaz( e )\r
+ dp_de = dp_de_rho_const_StiffenedGaz( rho )\r
+ \r
+ #Third choice for Dstag\r
+ Dmac[0, 0] = 0\r
+ Dmac[0, 1] = 1\r
+ Dmac[0, 2] = 0\r
+ Dmac[1, 0] = -dp_drho - u ** 2 - dp_de / rho * (u**2/2 - e)\r
+ Dmac[1, 1] = 2 * u + u * dp_de / rho\r
+ Dmac[1, 2] = -dp_de / rho\r
+ Dmac[2, 0] = -u * ( dp_drho + H + dp_de / rho * (u**2/2 - e) )\r
+ Dmac[2, 1] = H + dp_de / rho * u ** 2\r
+ Dmac[2, 2] = (-dp_de / rho +1) * u\r
+ \r
+ return Dmac * sign(u)\r
+ \r
+def jacobianMatricesm(coeff, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
+\r
+ if rho_l < 0 or rho_r < 0:\r
+ print("rho_l=", rho_l, " rho_r= ", rho_r)\r
+ raise ValueError("Negative density")\r
+ if rho_E_l < 0 or rho_E_r < 0:\r
+ print("rho_E_l=", rho_E_l, " rho_E_r= ", rho_E_r)\r
+ raise ValueError("Negative total energy")\r
+\r
+ RoeMat = MatRoe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ \r
+ Dmac = Dmac_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
+ return (RoeMat - Dmac) * coeff * 0.5\r
+\r
+\r
+def jacobianMatricesp(coeff, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
+ if rho_l < 0 or rho_r < 0:\r
+ print("rho_l=", rho_l, " rho_r= ", rho_r)\r
+ raise ValueError("Negative density")\r
+ if rho_E_l < 0 or rho_E_r < 0:\r
+ print("rho_E_l=", rho_E_l, " rho_E_r= ", rho_E_r)\r
+ raise ValueError("Negative total energy")\r
+\r
+ RoeMat = MatRoe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ Dmac = Dmac_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
+\r
+ return (RoeMat + Dmac) * coeff * 0.5\r
+\r
+\r
+def FillEdges(j, Uk, nbComp, divMat, Rhs, Un, dt, dx):\r
+ dUi1 = cdmath.Vector(3)\r
+ dUi2 = cdmath.Vector(3)\r
+ temp1 = cdmath.Vector(3)\r
+ temp2 = cdmath.Vector(3)\r
+\r
+ if (j == 0):\r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j + 1) * nbComp + 0]\r
+ q_r = Uk[(j + 1) * nbComp + 1]\r
+ rho_E_r = Uk[(j + 1) * nbComp + 2] \r
+\r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ divMat.addValue(j * nbComp, (j + 1) * nbComp, Am)\r
+ divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
+\r
+ p_inlet = rho_to_p_StiffenedGaz(Uk[j * nbComp + 0], Uk[j * nbComp + 1], Uk[j * nbComp + 2])# We take p from inside the domain\r
+ rho_l=p_to_rho_StiffenedGaz(p_inlet, T_inlet) # rho is computed from the temperature BC and the inner pressure\r
+ q_l = rho_l * v_inlet # q is imposed by the boundary condition v_inlet\r
+ rho_E_l = T_to_rhoE_StiffenedGaz(T_inlet, rho_l, q_l) #rhoE is obtained using the two boundary conditions v_inlet and e_inlet\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ divMat.addValue(j * nbComp, j * nbComp, Ap)\r
+ \r
+ dUi1[0] = Uk[(j + 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi1[1] = Uk[(j + 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi1[2] = Uk[(j + 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+ temp1 = Am * dUi1\r
+ \r
+ dUi2[0] = rho_l - Uk[(j ) * nbComp + 0]\r
+ dUi2[1] = q_l - Uk[(j ) * nbComp + 1]\r
+ dUi2[2] = rho_E_l - Uk[(j ) * nbComp + 2]\r
+ temp2 = Ap * dUi2\r
+\r
+ elif (j == nx - 1):\r
+ rho_l = Uk[(j - 1) * nbComp + 0]\r
+ q_l = Uk[(j - 1) * nbComp + 1]\r
+ rho_E_l = Uk[(j - 1) * nbComp + 2]\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ divMat.addValue(j * nbComp, j * nbComp, Ap)\r
+ divMat.addValue(j * nbComp, (j - 1) * nbComp, Ap * (-1.))\r
+\r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j ) * nbComp + 0] # We take rho inside the domain\r
+ q_r = Uk[(j ) * nbComp + 1] # We take q from inside the domain\r
+ rho_E_r = (p_outlet+gamma*p0)/(gamma-1) + 0.5*q_r**2/rho_r # rhoE is obtained using the boundary condition p_outlet\r
+\r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
+ divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
+\r
+ dUi1[0] = rho_r - Uk[j * nbComp + 0]\r
+ dUi1[1] = q_r - Uk[j * nbComp + 1]\r
+ dUi1[2] = rho_E_r - Uk[j * nbComp + 2]\r
+ temp1 = Am * dUi1\r
+\r
+ dUi2[0] = Uk[(j - 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi2[1] = Uk[(j - 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi2[2] = Uk[(j - 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+ temp2 = Ap * dUi2\r
+ \r
+ Rhs[j * nbComp + 0] = -temp1[0] + temp2[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
+ Rhs[j * nbComp + 1] = -temp1[1] + temp2[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
+ Rhs[j * nbComp + 2] = -temp1[2] + temp2[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
+\r
+def FillInnerCell(j, Uk, nbComp, divMat, Rhs, Un, dt, dx):\r
+\r
+ rho_l = Uk[(j - 1) * nbComp + 0]\r
+ q_l = Uk[(j - 1) * nbComp + 1]\r
+ rho_E_l = Uk[(j - 1) * nbComp + 2]\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ \r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j + 1) * nbComp + 0]\r
+ q_r = Uk[(j + 1) * nbComp + 1]\r
+ rho_E_r = Uk[(j + 1) * nbComp + 2]\r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+\r
+ divMat.addValue(j * nbComp, (j + 1) * nbComp, Am)\r
+ divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
+ divMat.addValue(j * nbComp, j * nbComp, Ap)\r
+ divMat.addValue(j * nbComp, (j - 1) * nbComp, Ap * (-1.))\r
+\r
+ dUi1 = cdmath.Vector(3)\r
+ dUi2 = cdmath.Vector(3)\r
+ \r
+ dUi1[0] = Uk[(j + 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi1[1] = Uk[(j + 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi1[2] = Uk[(j + 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+\r
+ dUi2[0] = Uk[(j - 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi2[1] = Uk[(j - 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi2[2] = Uk[(j - 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+ \r
+ temp1 = Am * dUi1\r
+ temp2 = Ap * dUi2\r
+\r
+ Rhs[j * nbComp + 0] = -temp1[0] + temp2[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
+ Rhs[j * nbComp + 1] = -temp1[1] + temp2[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
+ Rhs[j * nbComp + 2] = -temp1[2] + temp2[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
+\r
+def SetPicture(rho_field, q_field, h_field, p_field, v_field, T_field, dx):\r
+ max_initial_rho = max(rho_field)\r
+ min_initial_rho = min(rho_field)\r
+ max_initial_q = max(q_field)\r
+ min_initial_q = min(q_field)\r
+ min_initial_h = min(h_field)\r
+ max_initial_h = max(h_field)\r
+ max_initial_p = max(p_field)\r
+ min_initial_p = min(p_field)\r
+ max_initial_v = max(v_field)\r
+ min_initial_v = min(v_field)\r
+ max_initial_T = max(T_field)\r
+ min_initial_T = min(T_field)\r
+\r
+ fig, ([axDensity, axMomentum, axh],[axPressure, axVitesse, axTemperature]) = plt.subplots(2, 3,sharex=True, figsize=(14,10))\r
+ plt.gcf().subplots_adjust(wspace = 0.5)\r
+\r
+ lineDensity, = axDensity.plot([a+0.5*dx + i*dx for i in range(nx)], rho_field, label='MAC scheme')\r
+ axDensity.set(xlabel='x (m)', ylabel='Densité (kg/m3)')\r
+ axDensity.set_xlim(a,b)\r
+ axDensity.set_ylim(680, 800)\r
+ axDensity.legend()\r
+\r
+ lineMomentum, = axMomentum.plot([a+0.5*dx + i*dx for i in range(nx)], q_field, label='MAC scheme')\r
+ axMomentum.set(xlabel='x (m)', ylabel='Momentum (kg/(m2.s))')\r
+ axMomentum.set_xlim(a,b)\r
+ axMomentum.set_ylim(3760, 3780)\r
+ axMomentum.legend()\r
+\r
+ lineh, = axh.plot([a+0.5*dx + i*dx for i in range(nx)], h_field, label='MAC scheme')\r
+ axh.set(xlabel='x (m)', ylabel='h (J/m3)')\r
+ axh.set_xlim(a,b)\r
+ axh.set_ylim(1.25 * 10**6, 1.45*10**6)\r
+ axh.legend()\r
+ \r
+ linePressure, = axPressure.plot([a+0.5*dx + i*dx for i in range(nx)], p_field, label='MAC scheme')\r
+ axPressure.set(xlabel='x (m)', ylabel='Pression (bar)')\r
+ axPressure.set_xlim(a,b)\r
+ axPressure.set_ylim(154.99, 155.02)\r
+ axPressure.ticklabel_format(axis='y', style='sci', scilimits=(0,0))\r
+ axPressure.legend()\r
+\r
+ lineVitesse, = axVitesse.plot([a+0.5*dx + i*dx for i in range(nx)], v_field, label='MAC scheme')\r
+ axVitesse.set(xlabel='x (m)', ylabel='Vitesse (m/s)')\r
+ axVitesse.set_xlim(a,b)\r
+ axVitesse.set_ylim(v_0-1, v_0+1)\r
+ axVitesse.ticklabel_format(axis='y', style='sci', scilimits=(0,0))\r
+ axVitesse.legend()\r
+\r
+ lineTemperature, = axTemperature.plot([a+0.5*dx + i*dx for i in range(nx)], T_field, label='MAC scheme')\r
+ axTemperature.set(xlabel='x (m)', ylabel='Température (K)')\r
+ axTemperature.set_xlim(a,b)\r
+ axTemperature.set_ylim(T_0-10, T_0+30)\r
+ axTemperature.ticklabel_format(axis='y', style='sci', scilimits=(0,0))\r
+ axTemperature.legend()\r
+ \r
+ return(fig, lineDensity, lineMomentum, lineh, linePressure, lineVitesse, lineTemperature)\r
+\r
+\r
+def EulerSystemMAC(ntmax, tmax, cfl, a, b, nbCells, output_freq, meshName, state_law):\r
+ state_law_parameters(state_law)\r
+ dim = 1\r
+ nbComp = 3\r
+ dt = 0.\r
+ time = 0.\r
+ it = 0\r
+ isStationary = False\r
+ dx = (b - a) / nx\r
+ dt = cfl * dx / c0\r
+ #dt = 5*10**(-6)\r
+ nbVoisinsMax = 2\r
+\r
+ # iteration vectors\r
+ Un = cdmath.Vector(nbCells * (nbComp))\r
+ dUn = cdmath.Vector(nbCells * (nbComp))\r
+ dUk = cdmath.Vector(nbCells * (nbComp))\r
+ Rhs = cdmath.Vector(nbCells * (nbComp))\r
+\r
+ # Initial conditions\r
+ print("Construction of the initial condition …")\r
+\r
+ rho_field, q_field, rho_E_field, p_field, v_field, T_field = initial_conditions_Riemann_problem(a, b, nx)\r
+ h_field = (rho_E_field + p_field) / rho_field - 0.5 * (q_field / rho_field) **2\r
+ p_field = p_field * 10 ** (-5)\r
+ \r
+\r
+ for k in range(nbCells):\r
+ Un[k * nbComp + 0] = rho_field[k]\r
+ Un[k * nbComp + 1] = q_field[k]\r
+ Un[k * nbComp + 2] = rho_E_field[k]\r
+\r
+ divMat = cdmath.SparseMatrixPetsc(nbCells * nbComp, nbCells * nbComp, (nbVoisinsMax + 1) * nbComp)\r
+ \r
+ # Picture settings\r
+ fig, lineDensity, lineMomentum, lineRhoE, linePressure, lineVitesse, lineTemperature = SetPicture( rho_field, q_field, h_field, p_field, v_field, T_field, dx)\r
+\r
+ plt.savefig("EulerComplet_HeatedChannel_" + str(dim) + "D_MAC" + meshName + "0" + ".png")\r
+ iterGMRESMax = 50\r
+ newton_max = 100\r
+\r
+ print("Starting computation of the non linear Euler non isentropic system with MAC scheme …")\r
+ # STARTING TIME LOOP\r
+ while (it < ntmax and time <= tmax and not isStationary):\r
+ dUn = Un.deepCopy()\r
+ Uk = Un.deepCopy()\r
+ residu = 1.\r
+ \r
+ k = 0\r
+ while (k < newton_max and residu > precision):\r
+ # STARTING NEWTON LOOP\r
+ divMat.zeroEntries() #sets the matrix coefficients to zero\r
+ for j in range(nbCells):\r
+ \r
+ # traitements des bords\r
+ if (j == 0):\r
+ FillEdges(j, Uk, nbComp, divMat, Rhs, Un, dt, dx)\r
+ elif (j == nbCells - 1):\r
+ FillEdges(j, Uk, nbComp, divMat, Rhs, Un, dt, dx)\r
+\r
+ # traitement des cellules internes\r
+ else:\r
+ FillInnerCell(j, Uk, nbComp, divMat, Rhs, Un, dt, dx)\r
+ \r
+ Rhs[j * nbComp + 2] += phi*dt\r
+ \r
+ #solving the linear system divMat * dUk = Rhs\r
+ divMat.diagonalShift(1.)\r
+ LS = cdmath.LinearSolver(divMat, Rhs, iterGMRESMax, precision, "GMRES", "LU")\r
+ dUk = LS.solve()\r
+ vector_residu = dUk.maxVector(nbComp)\r
+ residu = max(abs(vector_residu[0])/rho0, abs(vector_residu[1])/(rho0*v_0), abs(vector_residu[2])/rhoE0 )\r
+ \r
+ if (it == 1 or it % output_freq == 0 or it >= ntmax or isStationary or time >= tmax):\r
+ print("Residu Newton at iteration ",k, " : ", residu)\r
+ print("Linear system converged in ", LS.getNumberOfIter(), " GMRES iterations")\r
+\r
+ #updates for Newton loop\r
+ Uk += dUk\r
+ k = k + 1\r
+ if (not LS.getStatus()):\r
+ print("Linear system did not converge ", LS.getNumberOfIter(), " GMRES iterations")\r
+ raise ValueError("No convergence of the linear system")\r
+ \r
+ if k == newton_max:\r
+ raise ValueError("No convergence of Newton MAC Scheme")\r
+\r
+ #updating fields\r
+ Un = Uk.deepCopy()\r
+ dUn -= Un\r
+\r
+ #Testing stationarity\r
+ residu_stat = dUn.maxVector(nbComp)#On prend le max de chaque composante\r
+ if (it % output_freq == 0 ):\r
+ print("Test de stationarité : Un+1-Un= ", max(abs(residu_stat[0])/rho0, abs(residu_stat[1])/(rho0*v_0), abs(residu_stat[2])/rhoE0 ))\r
+\r
+ if ( it>1 and abs(residu_stat[0])/rho0<precision and abs(residu_stat[1])/(rho0*v_0)<precision and abs(residu_stat[2])/rhoE0<precision):\r
+ isStationary = True\r
+ \r
+ for k in range(nbCells):\r
+ rho_field[k] = Un[k * nbComp + 0]\r
+ q_field[k] = Un[k * nbComp + 1]\r
+ rho_E_field[k] = Un[k * nbComp + 2]\r
+\r
+ v_field = q_field / rho_field\r
+ p_field = rho_to_p_StiffenedGaz(rho_field, q_field, rho_E_field)\r
+ T_field = rhoE_to_T_StiffenedGaz(rho_field, q_field, rho_E_field)\r
+ h_field = (rho_E_field + p_field) / rho_field - 0.5 * (q_field / rho_field) **2\r
+ p_field = p_field * 10 ** (-5)\r
+ \r
+ if( min(p_field)<0) :\r
+ raise ValueError("Negative pressure, stopping calculation")\r
+\r
+ #picture and video updates\r
+ lineDensity.set_ydata(rho_field)\r
+ lineMomentum.set_ydata(q_field)\r
+ lineRhoE.set_ydata(h_field)\r
+ linePressure.set_ydata(p_field)\r
+ lineVitesse.set_ydata(v_field)\r
+ lineTemperature.set_ydata(T_field)\r
+ \r
+ time = time + dt\r
+ it = it + 1\r
+\r
+ # Savings\r
+ if (it == 1 or it % output_freq == 0 or it >= ntmax or isStationary or time >= tmax):\r
+ \r
+ print("-- Time step : " + str(it) + ", Time: " + str(time) + ", dt: " + str(dt))\r
+\r
+ print("Temperature gain between inlet and outlet is ", T_field[nbCells-1]-T_field[0],"\n")\r
+\r
+ plt.savefig("EulerComplet_HeatedChannel_" + str(dim) + "D_MAC" + meshName + str(it) + '_time' + str(time) + ".png")\r
+\r
+ print("-- Iter: " + str(it) + ", Time: " + str(time) + ", dt: " + str(dt)+"\n")\r
+ \r
+ if (it >= ntmax):\r
+ print("Maximum number of time steps ntmax= ", ntmax, " reached")\r
+ return\r
+\r
+ elif (isStationary):\r
+ print("Stationary regime reached at time step ", it, ", t= ", time)\r
+ print("------------------------------------------------------------------------------------")\r
+ np.savetxt("EulerComplet_HeatedChannel_" + str(dim) + "D_MAC" + meshName + "_rho_Stat.txt", rho_field, delimiter="\n")\r
+ np.savetxt("EulerComplet_HeatedChannel_" + str(dim) + "D_MAC" + meshName + "_q_Stat.txt", q_field, delimiter="\n")\r
+ np.savetxt("EulerComplet_HeatedChannel_" + str(dim) + "D_MAC" + meshName + "_rhoE_Stat.txt", rho_E_field, delimiter="\n")\r
+ np.savetxt("EulerComplet_HeatedChannel_" + str(dim) + "D_MAC" + meshName + "_p_Stat.txt", p_field, delimiter="\n")\r
+ plt.savefig("EulerComplet_HeatedChannel_" + str(dim) + "D_MAC" + meshName +"_Stat.png")\r
+ return\r
+ else:\r
+ print("Maximum time Tmax= ", tmax, " reached")\r
+ return\r
+\r
+\r
+def solve(a, b, nx, meshName, meshType, cfl, state_law):\r
+ print("Simulation of a heated channel in dimension 1 on " + str(nx) + " cells")\r
+ print("State Law Stiffened Gaz, " + state_law)\r
+ print("Initial data : ", "constant fields")\r
+ print("Boundary conditions : ", "Inlet (Left), Outlet (Right)")\r
+ print("Mesh name : ", meshName, ", ", nx, " cells")\r
+ # Problem data\r
+ tmax = 10.\r
+ ntmax = 100000\r
+ output_freq = 1000\r
+ EulerSystemMAC(ntmax, tmax, cfl, a, b, nx, output_freq, meshName, state_law)\r
+ return\r
+\r
+def FillMatrixFromEdges(j, Uk, nbComp, divMat, dt, dx):\r
+\r
+ if (j == 0):\r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j + 1) * nbComp + 0]\r
+ q_r = Uk[(j + 1) * nbComp + 1]\r
+ rho_E_r = Uk[(j + 1) * nbComp + 2] \r
+\r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ divMat.addValue(j * nbComp, (j + 1) * nbComp, Am)\r
+ divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
+ \r
+ p_inlet = rho_to_p_StiffenedGaz(Uk[j * nbComp + 0], Uk[j * nbComp + 1], Uk[j * nbComp + 2])# We take p from inside the domain\r
+ rho_l=p_to_rho_StiffenedGaz(p_inlet, T_inlet) # rho is computed from the temperature BC and the inner pressure\r
+ #rho_l = Uk[j * nbComp + 0] # We take rho from inside the domain\r
+ q_l = rho_l * v_inlet # q is imposed by the boundary condition v_inlet\r
+ rho_E_l = T_to_rhoE_StiffenedGaz(T_inlet, rho_l, q_l) #rhoE is obtained using the two boundary conditions v_inlet and e_inlet\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ divMat.addValue(j * nbComp, j * nbComp, Ap)\r
+\r
+ elif (j == nx - 1):\r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j ) * nbComp + 0] # We take rho inside the domain\r
+ q_r = Uk[(j ) * nbComp + 1] # We take q from inside the domain\r
+ rho_E_r = (p_outlet+gamma*p0)/(gamma-1) + 0.5*q_r**2/rho_r # rhoE is obtained using the boundary condition p_outlet\r
+\r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
+ divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
+ \r
+ rho_l = Uk[(j - 1) * nbComp + 0]\r
+ q_l = Uk[(j - 1) * nbComp + 1]\r
+ rho_E_l = Uk[(j - 1) * nbComp + 2]\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ divMat.addValue(j * nbComp, j * nbComp, Ap)\r
+ divMat.addValue(j * nbComp, (j - 1) * nbComp, Ap * (-1.))\r
+\r
+\r
+def FillMatrixFromInnerCell(j, Uk, nbComp, divMat, dt, dx):\r
+\r
+ rho_l = Uk[(j - 1) * nbComp + 0]\r
+ q_l = Uk[(j - 1) * nbComp + 1]\r
+ rho_E_l = Uk[(j - 1) * nbComp + 2]\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ \r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j + 1) * nbComp + 0]\r
+ q_r = Uk[(j + 1) * nbComp + 1]\r
+ rho_E_r = Uk[(j + 1) * nbComp + 2]\r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+\r
+ divMat.addValue(j * nbComp, (j + 1) * nbComp, Am)\r
+ divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
+ divMat.addValue(j * nbComp, j * nbComp, Ap)\r
+ divMat.addValue(j * nbComp, (j - 1) * nbComp, Ap * (-1.))\r
+ \r
+def FillRHSFromEdges(j, Uk, nbComp, Rhs, Un, dt, dx):\r
+ dUi1 = cdmath.Vector(3)\r
+ dUi2 = cdmath.Vector(3)\r
+ temp1 = cdmath.Vector(3)\r
+ temp2 = cdmath.Vector(3)\r
+\r
+ if (j == 0):\r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j + 1) * nbComp + 0]\r
+ q_r = Uk[(j + 1) * nbComp + 1]\r
+ rho_E_r = Uk[(j + 1) * nbComp + 2] \r
+\r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+\r
+ p_inlet = rho_to_p_StiffenedGaz(Uk[j * nbComp + 0], Uk[j * nbComp + 1], Uk[j * nbComp + 2])# We take p from inside the domain\r
+ rho_l=p_to_rho_StiffenedGaz(p_inlet, T_inlet) # rho is computed from the temperature BC and the inner pressure\r
+ #rho_l = Uk[j * nbComp + 0] # We take rho from inside the domain\r
+ q_l = rho_l * v_inlet # q is imposed by the boundary condition v_inlet\r
+ rho_E_l = T_to_rhoE_StiffenedGaz(T_inlet, rho_l, q_l) #rhoE is obtained using the two boundary conditions v_inlet and e_inlet\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ \r
+ dUi1[0] = Uk[(j + 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi1[1] = Uk[(j + 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi1[2] = Uk[(j + 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+ temp1 = Am * dUi1\r
+ \r
+ dUi2[0] = rho_l - Uk[(j ) * nbComp + 0]\r
+ dUi2[1] = q_l - Uk[(j ) * nbComp + 1]\r
+ dUi2[2] = rho_E_l - Uk[(j ) * nbComp + 2]\r
+ temp2 = Ap * dUi2\r
+\r
+ elif (j == nx - 1):\r
+ rho_l = Uk[(j - 1) * nbComp + 0]\r
+ q_l = Uk[(j - 1) * nbComp + 1]\r
+ rho_E_l = Uk[(j - 1) * nbComp + 2]\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+\r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j ) * nbComp + 0] # We take rho inside the domain\r
+ q_r = Uk[(j ) * nbComp + 1] # We take q from inside the domain\r
+ rho_E_r = (p_outlet+gamma*p0)/(gamma-1) + 0.5*q_r**2/rho_r # rhoE is obtained using the boundary condition p_outlet\r
+\r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
+\r
+ dUi1[0] = rho_r - Uk[j * nbComp + 0]\r
+ dUi1[1] = q_r - Uk[j * nbComp + 1]\r
+ dUi1[2] = rho_E_r - Uk[j * nbComp + 2]\r
+ temp1 = Am * dUi1\r
+\r
+ dUi2[0] = Uk[(j - 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi2[1] = Uk[(j - 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi2[2] = Uk[(j - 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+ temp2 = Ap * dUi2\r
+ \r
+ Rhs[j * nbComp + 0] = -temp1[0] + temp2[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
+ Rhs[j * nbComp + 1] = -temp1[1] + temp2[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
+ Rhs[j * nbComp + 2] = -temp1[2] + temp2[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
+\r
+def FillRHSFromInnerCell(j, Uk, nbComp, Rhs, Un, dt, dx):\r
+\r
+ rho_l = Uk[(j - 1) * nbComp + 0]\r
+ q_l = Uk[(j - 1) * nbComp + 1]\r
+ rho_E_l = Uk[(j - 1) * nbComp + 2]\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ \r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j + 1) * nbComp + 0]\r
+ q_r = Uk[(j + 1) * nbComp + 1]\r
+ rho_E_r = Uk[(j + 1) * nbComp + 2]\r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+\r
+ dUi1 = cdmath.Vector(3)\r
+ dUi2 = cdmath.Vector(3)\r
+ \r
+ dUi1[0] = Uk[(j + 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi1[1] = Uk[(j + 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi1[2] = Uk[(j + 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+\r
+ dUi2[0] = Uk[(j - 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi2[1] = Uk[(j - 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi2[2] = Uk[(j - 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+\r
+ temp1 = Am * dUi1\r
+ temp2 = Ap * dUi2\r
+\r
+ Rhs[j * nbComp + 0] = -temp1[0] + temp2[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
+ Rhs[j * nbComp + 1] = -temp1[1] + temp2[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
+ Rhs[j * nbComp + 2] = -temp1[2] + temp2[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
+\r
+\r
+def computeSystemMatrix(a,b,nx, cfl, Uk):\r
+ dim = 1\r
+ nbComp = 3\r
+ dx = (b - a) / nx\r
+ dt = cfl * dx / c0\r
+ nbVoisinsMax = 2\r
+\r
+ nbCells = nx\r
+ divMat = cdmath.SparseMatrixPetsc(nbCells * nbComp, nbCells * nbComp, (nbVoisinsMax + 1) * nbComp)\r
+\r
+ divMat.zeroEntries() #sets the matrix coefficients to zero\r
+ for j in range(nbCells):\r
+ \r
+ # traitements des bords\r
+ if (j == 0):\r
+ FillMatrixFromEdges(j, Uk, nbComp, divMat, dt, dx)\r
+ elif (j == nbCells - 1):\r
+ FillMatrixFromEdges(j, Uk, nbComp, divMat, dt, dx)\r
+ # traitement des cellules internes\r
+ else:\r
+ FillMatrixFromInnerCell(j, Uk, nbComp, divMat, dt, dx)\r
+ \r
+ divMat.diagonalShift(1.) # add one on the diagonal\r
+\r
+ return divMat\r
+\r
+def computeRHSVector(a,b,nx, cfl, Uk, Un):\r
+ dim = 1\r
+ nbComp = 3\r
+ dx = (b - a) / nx\r
+ dt = cfl * dx / c0\r
+ nbVoisinsMax = 2\r
+\r
+ nbCells = nx\r
+ Rhs = cdmath.Vector(nbCells * (nbComp))\r
+\r
+ for j in range(nbCells):\r
+ \r
+ # traitements des bords\r
+ if (j == 0):\r
+ FillRHSFromEdges(j, Uk, nbComp, Rhs, Un, dt, dx)\r
+ elif (j == nbCells - 1):\r
+ FillRHSFromEdges(j, Uk, nbComp, Rhs, Un, dt, dx)\r
+ # traitement des cellules internes\r
+ else:\r
+ FillRHSFromInnerCell(j, Uk, nbComp, Rhs, Un, dt, dx)\r
+ \r
+ return Rhs\r
+\r
+\r
+if __name__ == """__main__""":\r
+ nbComp=3 # number of equations \r
+ a = 0.# domain is interval [a,b]\r
+ b = 4.2# domain is interval [a,b]\r
+ nx = 50# number of cells\r
+ dx = (b - a) / nx # space step\r
+ x = [a + 0.5 * dx + i * dx for i in range(nx)] # array of cell center (1D mesh)\r
+ state_law = "Hermite575K"\r
+ state_law_parameters(state_law)\r
+ rho0=p_to_rho_StiffenedGaz(p_0, T_0)\r
+ rhoE0=T_to_rhoE_StiffenedGaz(T_0, rho0, rho0*v_0)\r
+\r
+\r
+#### initial condition (T in K, v in m/s, p in Pa)\r
+ p_initial = np.array([ p_outlet for xi in x])\r
+ v_initial = np.array([ v_inlet for xi in x])\r
+ T_initial = np.array([ T_inlet for xi in x])\r
+ \r
+ rho_field = p_to_rho_StiffenedGaz(p_initial, T_initial)\r
+ q_field = rho_field * v_initial\r
+ rho_E_field = rho_field * T_to_E_StiffenedGaz(p_initial, T_initial, v_initial)\r
+\r
+ U = cdmath.Vector(nx * (nbComp))#Inutile à terme mais nécessaire pour le moment\r
+\r
+ for k in range(nx):\r
+ U[k * nbComp + 0] = rho_field[k]\r
+ U[k * nbComp + 1] = q_field[k]\r
+ U[k * nbComp + 2] = rho_E_field[k]\r
+ print("\n Testing function computeSystemMatrix \n")\r
+ cfl = 0.5\r
+ computeSystemMatrix(a, b, nx, cfl, U)\r
+\r
+ print("\n Testing function computeRHSVector \n")\r
+ cfl = 0.5\r
+ computeRHSVector(a, b, nx, cfl, U, U) \r
+\r
+ print("\n Testing function solve \n")\r
+ cfl = 1000.\r
+ solve(a, b, nx, "RegularSquares", "", cfl, state_law)\r
+ \r
--- /dev/null
+
+if (CDMATH_WITH_PYTHON AND CDMATH_WITH_PETSC AND CDMATH_WITH_POSTPRO)
+
+ ADD_TEST(ExampleFullEulerSystem_1DHeatedChannel_Roe ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Euler_complet_HeatedChanel_Roe.py )
+
+endif (CDMATH_WITH_PYTHON AND CDMATH_WITH_PETSC AND CDMATH_WITH_POSTPRO)
+
+
--- /dev/null
+#!/usr/bin/env python3\r
+# -*-coding:utf-8 -*\r
+\r
+"""\r
+Created on Mon Aug 30 2021\r
+@author: Michael NDJINGA, Katia Ait Ameur, Coraline Mounier\r
+\r
+Euler system with heating source term (phi) in one dimension on regular domain [a,b]\r
+Riemann problemn with ghost cell boundary condition\r
+Left : Inlet boundary condition (velocity and temperature imposed)\r
+Right : Outlet boundary condition (pressure imposed)\r
+Roe scheme\r
+Regular square mesh\r
+\r
+State law Stiffened gaz : p = (gamma - 1) * rho * (e - q) - gamma * p0\r
+4 choices of parameters gamma and p0 are available : \r
+ - Lagrange interpolation (with q=0)\r
+ - Hermite interpolation with reference point at 575K (with q=0)\r
+ - Hermite interpolation with reference point at 590K (with q=0)\r
+ - Hermite interpolation with reference point at 617.94K (saturation at 155 bar) with q=0\r
+ \r
+Linearized enthalpy : h = h_sat + cp * (T - T_sat)\r
+Values for cp and T_sat parameters are taken at the reference point chosen for the state law\r
+\r
+To do correct the computation of the time step : lambda_max (maximum eigenvalue) should be computed first)\r
+"""\r
+\r
+import cdmath\r
+import numpy as np\r
+import matplotlib\r
+\r
+matplotlib.use("Agg")\r
+import matplotlib.pyplot as plt\r
+from math import sqrt\r
+from numpy import sign\r
+\r
+\r
+#### Initial and boundary condition (T in K, v in m/s, p in Pa)\r
+T_inlet = 565.\r
+v_inlet = 5.\r
+p_outlet = 155.0 * 10**5\r
+\r
+#initial parameters are determined from boundary conditions\r
+p_0 = p_outlet #initial pressure\r
+v_0 = v_inlet #initial velocity\r
+T_0 = T_inlet #initial temperature\r
+### Heating source term\r
+phi=1.e8\r
+\r
+## Numerical parameter\r
+precision = 1e-6\r
+\r
+#state law parameter : can be 'Lagrange', 'Hermite590K', 'Hermite617K', or 'FLICA'\r
+state_law = "Hermite575K"\r
+\r
+def state_law_parameters(state_law):\r
+ #state law Stiffened Gaz : p = (gamma - 1) * rho * e - gamma * p0\r
+ global gamma\r
+ global p0\r
+ global q\r
+ global c0\r
+ global cp\r
+ global h_sat\r
+ global T_sat\r
+ \r
+ if state_law == "Lagrange":\r
+ # reference values for Lagrange interpolation\r
+ p_ref = 155. * 10**5 #Reference pressure in a REP 900 nuclear power plant \r
+ p1 = 153. * 10**5 # value of pressure at inlet of a 900 MWe PWR vessel\r
+ rho_ref = 594.38 #density of water at saturation temperature of 617.94K and 155 bars\r
+ rho1 = 742.36 # value of density at inlet of a 900 MWe PWR vessel (T1 = 565K)\r
+ e_ref = 1603.8 * 10**3 #internal energy of water at saturation temperature of 617.94K and 155 bars\r
+ e1 = 1273.6 * 10**3 # value of internal energy at inlet of a 900 MWe PWR vessel\r
+ \r
+ gamma = (p1 - p_ref) / (rho1 * e1 - rho_ref *e_ref) + 1.\r
+ p0 = - 1. / gamma * ( - (gamma - 1) * rho_ref * e_ref + p_ref)\r
+ q=0.\r
+ c0 = sqrt((gamma - 1) * (e_ref + p_ref / rho_ref))\r
+ \r
+ cp = 8950.\r
+ h_sat = 1.63 * 10 ** 6 # saturation enthalpy of water at 155 bars\r
+ T_sat = 617.94 \r
+\r
+ elif state_law == "Hermite617K":\r
+ # reference values for Hermite interpolation\r
+ p_ref = 155. * 10**5 #Reference pressure in a REP 900 nuclear power plant\r
+ T_ref = 617.94 #Reference temperature for interpolation at 617.94K\r
+ rho_ref = 594.38 #density of water at saturation temperature of 617.94K and 155 bars\r
+ e_ref = 1603.8 * 10**3 #internal energy of water at saturation temperature of 617.94K and 155 bars\r
+ h_ref = e_ref + p_ref / rho_ref\r
+ c_ref = 621.43 #sound speed for water at 155 bars and 617.94K\r
+\r
+ gamma = 1. + c_ref * c_ref / (e_ref + p_ref / rho_ref) # From the sound speed formula\r
+ p0 = 1. / gamma * ( (gamma - 1) * rho_ref * e_ref - p_ref) \r
+ q=0.\r
+ c0 = sqrt((gamma - 1) * (e_ref + p_ref / rho_ref))\r
+ \r
+ cp = 8950. # value at 155 bar and 617.94K\r
+ h_sat = 1.63 * 10 ** 6 # saturation enthalpy of water at 155 bars\r
+ T_sat = 617.94 \r
+ \r
+ elif state_law == 'Hermite590K':\r
+ # reference values for Hermite interpolation\r
+ p_ref = 155. * 10**5 #Reference pressure in a REP 900 nuclear power plant\r
+ T_ref = 590. #Reference temperature for interpolation at 590K\r
+ rho_ref = 688.3 #density of water at 590K and 155 bars\r
+ e_ref = 1411.4 * 10**3 #internal energy of water at 590K and 155 bars\r
+ h_ref = e_ref + p_ref / rho_ref\r
+ c_ref = 866.29 #sound speed for water at 155 bars and 590K\r
+ \r
+ gamma = 1. + c_ref * c_ref / (e_ref + p_ref / rho_ref) # From the sound speed formula\r
+ p0 = 1. / gamma * ( (gamma - 1) * rho_ref * e_ref - p_ref) \r
+ q=0.\r
+ c0 = sqrt((gamma - 1) * (e_ref + p_ref / rho_ref))\r
+ \r
+ cp = 5996.8 # value at 155 bar and 590K\r
+ h_sat = 1433.9 * 10 ** 3 # saturation enthalpy of water at 155 bars\r
+ T_sat = 590. \r
+\r
+ elif state_law == 'Hermite575K':\r
+ # reference values for Hermite interpolation\r
+ p_ref = 155 * 10**5 #Reference pressure in a REP 900 nuclear power plant\r
+ T_ref = 575 #Reference temperature at inlet in a REP 900 nuclear power plant\r
+ #Remaining values determined using iapws python package\r
+ rho_ref = 722.66 #density of water at 575K and 155 bars\r
+ e_ref = 1326552.66 #internal energy of water at 575K and 155 bars\r
+ h_ref = e_ref + p_ref / rho_ref\r
+ c_ref = 959.28 #sound speed for water at 155 bars and 575K\r
+ \r
+ gamma = 1 + c_ref * c_ref / (e_ref + p_ref / rho_ref) # From the sound speed formula\r
+ p0 = 1 / gamma * ( (gamma - 1) * rho_ref * e_ref - p_ref) \r
+ q=0.\r
+ c0 = sqrt((gamma - 1) * (e_ref + p_ref / rho_ref))#This is actually c_ref\r
+ \r
+ cp = 5504.05 # value at 155 bar and 590K\r
+ h_sat = h_ref # saturation enthalpy of water at 155 bars\r
+ T_sat = T_ref\r
+ else:\r
+ raise ValueError("Incorrect value for parameter state_law")\r
+ \r
+def initial_conditions_Riemann_problem(a, b, nx):\r
+ print("Initial data Riemann problem")\r
+ dx = (b - a) / nx # space step\r
+ x = [a + 0.5 * dx + i * dx for i in range(nx)] # array of cell center (1D mesh)\r
+\r
+ p_initial = np.array([ p_0 for xi in x])\r
+ v_initial = np.array([ v_0 for xi in x])\r
+ T_initial = np.array([ T_0 for xi in x])\r
+\r
+ rho_initial = p_to_rho_StiffenedGaz(p_initial, T_initial)\r
+ q_initial = rho_initial * v_initial\r
+ rho_E_initial = T_to_rhoE_StiffenedGaz(T_initial, rho_initial, q_initial)\r
+\r
+ return rho_initial, q_initial, rho_E_initial, p_initial, v_initial, T_initial\r
+\r
+def p_to_rho_StiffenedGaz(p_field, T_field):\r
+ rho_field = (p_field + p0) * gamma / (gamma - 1) * 1. / (h_sat + cp * (T_field - T_sat))\r
+ return rho_field\r
+ \r
+def T_to_rhoE_StiffenedGaz(T_field, rho_field, q_field):\r
+ rho_E_field = 1. / 2. * (q_field) ** 2 / rho_field + p0 + rho_field / gamma * (h_sat + cp * (T_field- T_sat))\r
+ return rho_E_field\r
+\r
+def rhoE_to_T_StiffenedGaz(rho_field, q_field, rho_E_field):\r
+ T_field = T_sat + 1 / cp * (gamma * (rho_E_field / rho_field - 1 / 2 * (q_field / rho_field) ** 2) - gamma * p0 / rho_field - h_sat)\r
+ return T_field\r
+\r
+def rho_to_p_StiffenedGaz(rho_field, q_field, rho_E_field):\r
+ p_field = (gamma - 1) * (rho_E_field - 1. / 2 * q_field ** 2 / rho_field) - gamma * p0\r
+ return p_field\r
+\r
+def T_to_E_StiffenedGaz(p_field, T_field, v_field):\r
+ rho_field = p_to_rho_StiffenedGaz(p_field, T_field)\r
+ E_field = (p_field + gamma * p0) / ((gamma-1) * rho_field) + 0.5 * v_field **2\r
+ return E_field\r
+ \r
+def dp_drho_e_const_StiffenedGaz( e ):\r
+ return (gamma-1)*(e-q)\r
+\r
+def dp_de_rho_const_StiffenedGaz( rho ):\r
+ return (gamma-1)*rho\r
+\r
+def sound_speed_StiffenedGaz( h ):\r
+ return np.sqrt((gamma-1)*(h-q))\r
+\r
+def rho_h_to_p_StiffenedGaz( rho, h ):\r
+ return (gamma - 1) * rho * ( h - q ) / gamma - p0\r
+\r
+def MatRoe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
+ RoeMat = cdmath.Matrix(3, 3)\r
+\r
+ u_l = q_l / rho_l\r
+ u_r = q_r / rho_r\r
+ p_l = rho_to_p_StiffenedGaz(rho_l, q_l, rho_E_l)\r
+ p_r = rho_to_p_StiffenedGaz(rho_r, q_r, rho_E_r)\r
+ H_l = rho_E_l / rho_l + p_l / rho_l\r
+ H_r = rho_E_r / rho_r + p_r / rho_r\r
+\r
+ # Roe averages\r
+ rho = np.sqrt(rho_l * rho_r)\r
+ u = (u_l * sqrt(rho_l) + u_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
+ H = (H_l * sqrt(rho_l) + H_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
+\r
+ p = rho_h_to_p_StiffenedGaz( rho, H - u**2/2. )\r
+ e = H - p / rho - 1./2 * u**2\r
+ dp_drho = dp_drho_e_const_StiffenedGaz( e )\r
+ dp_de = dp_de_rho_const_StiffenedGaz( rho )\r
+\r
+ RoeMat[0, 0] = 0\r
+ RoeMat[0, 1] = 1\r
+ RoeMat[0, 2] = 0\r
+ RoeMat[1, 0] = dp_drho - u ** 2 + dp_de / rho * (u**2/2 - e)\r
+ RoeMat[1, 1] = 2 * u - u * dp_de / rho\r
+ RoeMat[1, 2] = dp_de / rho\r
+ RoeMat[2, 0] = -u * ( -dp_drho + H - dp_de / rho * (u**2/2 - e) )\r
+ RoeMat[2, 1] = H - dp_de / rho * u ** 2\r
+ RoeMat[2, 2] = (dp_de / rho +1) * u\r
+ \r
+ return(RoeMat)\r
+\r
+ \r
+def Droe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
+ Droe = cdmath.Matrix(3, 3)\r
+\r
+ u_l = q_l / rho_l\r
+ u_r = q_r / rho_r\r
+ p_l = rho_to_p_StiffenedGaz(rho_l, q_l, rho_E_l)\r
+ p_r = rho_to_p_StiffenedGaz(rho_r, q_r, rho_E_r)\r
+ H_l = rho_E_l / rho_l + p_l / rho_l\r
+ H_r = rho_E_r / rho_r + p_r / rho_r\r
+\r
+ # Roe averages\r
+ rho = np.sqrt(rho_l * rho_r)\r
+ u = (u_l * sqrt(rho_l) + u_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
+ H = (H_l * sqrt(rho_l) + H_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
+\r
+ c = sound_speed_StiffenedGaz( H - u**2/2. )\r
+ \r
+ lamb = cdmath.Vector(3)\r
+ lamb[0] = u-c\r
+ lamb[1] = u\r
+ lamb[2] = u+c \r
+\r
+ r = cdmath.Matrix(3, 3)\r
+ r[0,0] = 1.\r
+ r[1,0] = u-c\r
+ r[2,0] = H-u*c \r
+ r[0,1] = 1.\r
+ r[1,1] = u \r
+ r[2,1] = H-c**2/(gamma-1) \r
+ r[0,2] = 1.\r
+ r[1,2] = u+c\r
+ r[2,2] = H+u*c \r
+\r
+ l = cdmath.Matrix(3, 3)\r
+ l[0,0] = (1./(2*c**2))*(0.5*(gamma-1)*u**2+u*c)\r
+ l[1,0] = (1./(2*c**2))*(-u*(gamma-1)-c)\r
+ l[2,0] = (1./(2*c**2))*(gamma-1)\r
+ l[0,1] = ((gamma-1)/c**2)*(H-u**2)\r
+ l[1,1] = ((gamma-1)/c**2)*u \r
+ l[2,1] = -((gamma-1)/c**2) \r
+ l[0,2] = (1./(2*c**2))*(0.5*(gamma-1)*u**2-u*c)\r
+ l[1,2] = (1./(2*c**2))*(c-u*(gamma-1))\r
+ l[2,2] = (1./(2*c**2))*(gamma-1)\r
+\r
+ M1 = cdmath.Matrix(3, 3) #abs(lamb[0])*r[:,0].tensProduct(l[:,0])\r
+ M2 = cdmath.Matrix(3, 3) #abs(lamb[1])*r[:,1].tensProduct(l[:,1]) \r
+ M3 = cdmath.Matrix(3, 3) #abs(lamb[2])*r[:,2].tensProduct(l[:,2])\r
+ for i in range(3):\r
+ for j in range(3):\r
+ M1[i,j] = abs(lamb[0])*r[i,0]*l[j,0]\r
+ M2[i,j] = abs(lamb[1])*r[i,1]*l[j,1] \r
+ M3[i,j] = abs(lamb[2])*r[i,2]*l[j,2]\r
+ \r
+ Droe = M1+M2+M3 \r
+ \r
+ return(Droe) \r
+\r
+\r
+def jacobianMatricesm(coeff, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
+\r
+ if rho_l < 0 or rho_r < 0:\r
+ print("rho_l=", rho_l, " rho_r= ", rho_r)\r
+ raise ValueError("Negative density")\r
+ if rho_E_l < 0 or rho_E_r < 0:\r
+ print("rho_E_l=", rho_E_l, " rho_E_r= ", rho_E_r)\r
+ raise ValueError("Negative total energy")\r
+\r
+ RoeMat = MatRoe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ \r
+ Droe = Droe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
+ return (RoeMat - Droe) * coeff * 0.5\r
+\r
+\r
+def jacobianMatricesp(coeff, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
+ if rho_l < 0 or rho_r < 0:\r
+ print("rho_l=", rho_l, " rho_r= ", rho_r)\r
+ raise ValueError("Negative density")\r
+ if rho_E_l < 0 or rho_E_r < 0:\r
+ print("rho_E_l=", rho_E_l, " rho_E_r= ", rho_E_r)\r
+ raise ValueError("Negative total energy")\r
+\r
+ RoeMat = MatRoe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ Droe = Droe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
+\r
+ return (RoeMat + Droe) * coeff * 0.5\r
+\r
+\r
+def FillEdges(j, Uk, nbComp, divMat, Rhs, Un, dt, dx, isImplicit):\r
+ dUi1 = cdmath.Vector(3)\r
+ dUi2 = cdmath.Vector(3)\r
+ temp1 = cdmath.Vector(3)\r
+ temp2 = cdmath.Vector(3)\r
+\r
+ if (j == 0):\r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j + 1) * nbComp + 0]\r
+ q_r = Uk[(j + 1) * nbComp + 1]\r
+ rho_E_r = Uk[(j + 1) * nbComp + 2] \r
+\r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ divMat.addValue(j * nbComp, (j + 1) * nbComp, Am)\r
+ divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
+\r
+ p_inlet = rho_to_p_StiffenedGaz(Uk[j * nbComp + 0], Uk[j * nbComp + 1], Uk[j * nbComp + 2])# We take p from inside the domain\r
+ rho_l=p_to_rho_StiffenedGaz(p_inlet, T_inlet) # rho is computed from the temperature BC and the inner pressure\r
+ #rho_l = Uk[j * nbComp + 0] # We take rho from inside the domain\r
+ q_l = rho_l * v_inlet # q is imposed by the boundary condition v_inlet\r
+ rho_E_l = T_to_rhoE_StiffenedGaz(T_inlet, rho_l, q_l) #rhoE is obtained using the two boundary conditions v_inlet and e_inlet\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ divMat.addValue(j * nbComp, j * nbComp, Ap)\r
+ \r
+ if(isImplicit):\r
+ dUi1[0] = Uk[(j + 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi1[1] = Uk[(j + 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi1[2] = Uk[(j + 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+ temp1 = Am * dUi1\r
+ \r
+ dUi2[0] = rho_l - Uk[(j ) * nbComp + 0]\r
+ dUi2[1] = q_l - Uk[(j ) * nbComp + 1]\r
+ dUi2[2] = rho_E_l - Uk[(j ) * nbComp + 2]\r
+ temp2 = Ap * dUi2\r
+ else:\r
+ dUi2[0] = rho_l \r
+ dUi2[1] = q_l \r
+ dUi2[2] = rho_E_l \r
+ temp2 = Ap * dUi2\r
+\r
+ elif (j == nx - 1):\r
+ rho_l = Uk[(j - 1) * nbComp + 0]\r
+ q_l = Uk[(j - 1) * nbComp + 1]\r
+ rho_E_l = Uk[(j - 1) * nbComp + 2]\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ divMat.addValue(j * nbComp, j * nbComp, Ap)\r
+ divMat.addValue(j * nbComp, (j - 1) * nbComp, Ap * (-1.))\r
+\r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j ) * nbComp + 0] # We take rho inside the domain\r
+ q_r = Uk[(j ) * nbComp + 1] # We take q from inside the domain\r
+ rho_E_r = (p_outlet+gamma*p0)/(gamma-1) + 0.5*q_r**2/rho_r # rhoE is obtained using the boundary condition p_outlet\r
+\r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
+ divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
+\r
+ if(isImplicit):\r
+ dUi1[0] = rho_r - Uk[j * nbComp + 0]\r
+ dUi1[1] = q_r - Uk[j * nbComp + 1]\r
+ dUi1[2] = rho_E_r - Uk[j * nbComp + 2]\r
+ temp1 = Am * dUi1\r
+\r
+ dUi2[0] = Uk[(j - 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi2[1] = Uk[(j - 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi2[2] = Uk[(j - 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+ temp2 = Ap * dUi2\r
+ else:\r
+ dUi1[0] = rho_r \r
+ dUi1[1] = q_r \r
+ dUi1[2] = rho_E_r \r
+ temp1 = Am * dUi1\r
+ \r
+ if(isImplicit):#implicit scheme, contribution from the Newton scheme residual\r
+ Rhs[j * nbComp + 0] = -temp1[0] + temp2[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
+ Rhs[j * nbComp + 1] = -temp1[1] + temp2[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
+ Rhs[j * nbComp + 2] = -temp1[2] + temp2[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
+ else:#explicit scheme, contribution from the boundary data the right hand side\r
+ Rhs[j * nbComp + 0] = -temp1[0] + temp2[0] \r
+ Rhs[j * nbComp + 1] = -temp1[1] + temp2[1] \r
+ Rhs[j * nbComp + 2] = -temp1[2] + temp2[2] \r
+\r
+def FillInnerCell(j, Uk, nbComp, divMat, Rhs, Un, dt, dx, isImplicit):\r
+\r
+ rho_l = Uk[(j - 1) * nbComp + 0]\r
+ q_l = Uk[(j - 1) * nbComp + 1]\r
+ rho_E_l = Uk[(j - 1) * nbComp + 2]\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ \r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j + 1) * nbComp + 0]\r
+ q_r = Uk[(j + 1) * nbComp + 1]\r
+ rho_E_r = Uk[(j + 1) * nbComp + 2]\r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+\r
+ divMat.addValue(j * nbComp, (j + 1) * nbComp, Am)\r
+ divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
+ divMat.addValue(j * nbComp, j * nbComp, Ap)\r
+ divMat.addValue(j * nbComp, (j - 1) * nbComp, Ap * (-1.))\r
+\r
+ if(isImplicit):\r
+ dUi1 = cdmath.Vector(3)\r
+ dUi2 = cdmath.Vector(3)\r
+ \r
+ dUi1[0] = Uk[(j + 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi1[1] = Uk[(j + 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi1[2] = Uk[(j + 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+ \r
+ dUi2[0] = Uk[(j - 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi2[1] = Uk[(j - 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi2[2] = Uk[(j - 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+ \r
+ temp1 = Am * dUi1\r
+ temp2 = Ap * dUi2\r
+\r
+ Rhs[j * nbComp + 0] = -temp1[0] + temp2[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
+ Rhs[j * nbComp + 1] = -temp1[1] + temp2[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
+ Rhs[j * nbComp + 2] = -temp1[2] + temp2[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
+ else:\r
+ Rhs[j * nbComp + 0] = 0\r
+ Rhs[j * nbComp + 1] = 0\r
+ Rhs[j * nbComp + 2] = 0\r
+\r
+def SetPicture(rho_field_Roe, q_field_Roe, h_field_Roe, p_field_Roe, v_field_Roe, T_field_Roe, dx):\r
+ max_initial_rho = max(rho_field_Roe)\r
+ min_initial_rho = min(rho_field_Roe)\r
+ max_initial_q = max(q_field_Roe)\r
+ min_initial_q = min(q_field_Roe)\r
+ min_initial_h = min(h_field_Roe)\r
+ max_initial_h = max(h_field_Roe)\r
+ max_initial_p = max(p_field_Roe)\r
+ min_initial_p = min(p_field_Roe)\r
+ max_initial_v = max(v_field_Roe)\r
+ min_initial_v = min(v_field_Roe)\r
+ max_initial_T = max(T_field_Roe)\r
+ min_initial_T = min(T_field_Roe)\r
+\r
+ fig, ([axDensity, axMomentum, axh],[axPressure, axVitesse, axTemperature]) = plt.subplots(2, 3,sharex=True, figsize=(14,10))\r
+ plt.gcf().subplots_adjust(wspace = 0.5)\r
+\r
+ lineDensity_Roe, = axDensity.plot([a+0.5*dx + i*dx for i in range(nx)], rho_field_Roe, label='Roe')\r
+ axDensity.set(xlabel='x (m)', ylabel='Densité (kg/m3)')\r
+ axDensity.set_xlim(a,b)\r
+ axDensity.set_ylim(680, 800)\r
+ axDensity.legend()\r
+\r
+ lineMomentum_Roe, = axMomentum.plot([a+0.5*dx + i*dx for i in range(nx)], q_field_Roe, label='Roe')\r
+ axMomentum.set(xlabel='x (m)', ylabel='Momentum (kg/(m2.s))')\r
+ axMomentum.set_xlim(a,b)\r
+ axMomentum.set_ylim(3500, 4000)\r
+ axMomentum.legend()\r
+\r
+ lineh_Roe, = axh.plot([a+0.5*dx + i*dx for i in range(nx)], h_field_Roe, label='Roe')\r
+ axh.set(xlabel='x (m)', ylabel='h (J/m3)')\r
+ axh.set_xlim(a,b)\r
+ axh.set_ylim(1.2 * 10**6, 1.5*10**6)\r
+ axh.legend()\r
+ \r
+ linePressure_Roe, = axPressure.plot([a+0.5*dx + i*dx for i in range(nx)], p_field_Roe, label='Roe')\r
+ axPressure.set(xlabel='x (m)', ylabel='Pression (bar)')\r
+ axPressure.set_xlim(a,b)\r
+ axPressure.set_ylim(155, 155.5)\r
+ axPressure.ticklabel_format(axis='y', style='sci', scilimits=(0,0))\r
+ axPressure.legend()\r
+\r
+ lineVitesse_Roe, = axVitesse.plot([a+0.5*dx + i*dx for i in range(nx)], v_field_Roe, label='Roe')\r
+ axVitesse.set(xlabel='x (m)', ylabel='Vitesse (m/s)')\r
+ axVitesse.set_xlim(a,b)\r
+ axVitesse.set_ylim(v_0-1, v_0+1)\r
+ axVitesse.ticklabel_format(axis='y', style='sci', scilimits=(0,0))\r
+ axVitesse.legend()\r
+\r
+ lineTemperature_Roe, = axTemperature.plot([a+0.5*dx + i*dx for i in range(nx)], T_field_Roe, label='Roe')\r
+ axTemperature.set(xlabel='x (m)', ylabel='Température (K)')\r
+ axTemperature.set_xlim(a,b)\r
+ axTemperature.set_ylim(T_0-10, T_0+30)\r
+ axTemperature.ticklabel_format(axis='y', style='sci', scilimits=(0,0))\r
+ axTemperature.legend()\r
+ \r
+ return(fig, lineDensity_Roe, lineMomentum_Roe, lineh_Roe, linePressure_Roe, lineVitesse_Roe, lineTemperature_Roe)\r
+\r
+\r
+def EulerSystemRoe(ntmax, tmax, cfl, a, b, nbCells, output_freq, meshName, state_law, isImplicit):\r
+ state_law_parameters(state_law)\r
+ dim = 1\r
+ nbComp = 3\r
+ dt = 0.\r
+ time = 0.\r
+ it = 0\r
+ isStationary = False\r
+ dx = (b - a) / nx\r
+ dt = cfl * dx / c0\r
+ #dt = 5*10**(-6)\r
+ nbVoisinsMax = 2\r
+\r
+ # iteration vectors\r
+ Un_Roe = cdmath.Vector(nbCells * (nbComp))\r
+ dUn_Roe = cdmath.Vector(nbCells * (nbComp))\r
+ dUk_Roe = cdmath.Vector(nbCells * (nbComp))\r
+ Rhs_Roe = cdmath.Vector(nbCells * (nbComp))\r
+\r
+ # Initial conditions\r
+ print("Construction of the initial condition …")\r
+\r
+ rho_field_Roe, q_field_Roe, rho_E_field_Roe, p_field_Roe, v_field_Roe, T_field_Roe = initial_conditions_Riemann_problem(a, b, nx)\r
+ h_field_Roe = (rho_E_field_Roe + p_field_Roe) / rho_field_Roe - 0.5 * (q_field_Roe / rho_field_Roe) **2\r
+ p_field_Roe = p_field_Roe * 10 ** (-5)\r
+ \r
+\r
+ for k in range(nbCells):\r
+ Un_Roe[k * nbComp + 0] = rho_field_Roe[k]\r
+ Un_Roe[k * nbComp + 1] = q_field_Roe[k]\r
+ Un_Roe[k * nbComp + 2] = rho_E_field_Roe[k]\r
+\r
+ divMat_Roe = cdmath.SparseMatrixPetsc(nbCells * nbComp, nbCells * nbComp, (nbVoisinsMax + 1) * nbComp)\r
+ \r
+ # Picture settings\r
+ fig, lineDensity_Roe, lineMomentum_Roe, lineRhoE_Roe, linePressure_Roe, lineVitesse_Roe, lineTemperature_Roe = SetPicture( rho_field_Roe, q_field_Roe, h_field_Roe, p_field_Roe, v_field_Roe, T_field_Roe, dx)\r
+\r
+ plt.savefig("EulerComplet_HeatedChannel_" + str(dim) + "D_Roe" + meshName + "0" + ".png")\r
+ iterGMRESMax = 50\r
+ newton_max = 100\r
+\r
+ print("Starting computation of the non linear Euler non isentropic system with Roe scheme …")\r
+ # STARTING TIME LOOP\r
+ while (it < ntmax and time <= tmax and not isStationary):\r
+ dUn_Roe = Un_Roe.deepCopy()\r
+ Uk_Roe = Un_Roe.deepCopy()\r
+ residu_Roe = 1.\r
+ \r
+ k_Roe = 0\r
+ while (k_Roe < newton_max and residu_Roe > precision):\r
+ # STARTING NEWTON LOOP\r
+ divMat_Roe.zeroEntries() #sets the matrix coefficients to zero\r
+ for j in range(nbCells):\r
+ \r
+ # traitements des bords\r
+ if (j == 0):\r
+ FillEdges(j, Uk_Roe, nbComp, divMat_Roe, Rhs_Roe, Un_Roe, dt, dx, isImplicit)\r
+ elif (j == nbCells - 1):\r
+ FillEdges(j, Uk_Roe, nbComp, divMat_Roe, Rhs_Roe, Un_Roe, dt, dx, isImplicit)\r
+\r
+ # traitement des cellules internes\r
+ else:\r
+ FillInnerCell(j, Uk_Roe, nbComp, divMat_Roe, Rhs_Roe, Un_Roe, dt, dx, isImplicit)\r
+ \r
+ Rhs_Roe[j * nbComp + 2] += phi*dt\r
+ \r
+ if(isImplicit):\r
+ #solving the linear system divMat * dUk = Rhs\r
+ divMat_Roe.diagonalShift(1.)\r
+ LS_Roe = cdmath.LinearSolver(divMat_Roe, Rhs_Roe, iterGMRESMax, precision, "GMRES", "LU")\r
+ dUk_Roe = LS_Roe.solve()\r
+ vector_residu_Roe = dUk_Roe.maxVector(nbComp)\r
+ residu_Roe = max(abs(vector_residu_Roe[0])/rho0, abs(vector_residu_Roe[1])/(rho0*v_0), abs(vector_residu_Roe[2])/rhoE0 )\r
+ else:\r
+ dUk_Roe=Rhs_Roe - divMat_Roe*Un_Roe\r
+ residu_Roe = 0.#Convergence schéma Newton\r
+ \r
+ if (isImplicit and (it == 1 or it % output_freq == 0 or it >= ntmax or isStationary or time >= tmax)):\r
+ print("Residu Newton at iteration ",k_Roe, " : ", residu_Roe)\r
+ print("Linear system converged in ", LS_Roe.getNumberOfIter(), " GMRES iterations")\r
+\r
+ #updates for Newton loop\r
+ Uk_Roe += dUk_Roe\r
+ k_Roe = k_Roe + 1\r
+ if (isImplicit and not LS_Roe.getStatus()):\r
+ print("Linear system did not converge ", LS_Roe.getNumberOfIter(), " GMRES iterations")\r
+ raise ValueError("No convergence of the linear system")\r
+ \r
+ if k_Roe == newton_max:\r
+ raise ValueError("No convergence of Newton Roe Scheme")\r
+\r
+ #updating fields\r
+ Un_Roe = Uk_Roe.deepCopy()\r
+ dUn_Roe -= Un_Roe\r
+\r
+ #Testing stationarity\r
+ residu_stat = dUn_Roe.maxVector(nbComp)#On prend le max de chaque composante\r
+ if (it % output_freq == 0 ):\r
+ print("Test de stationarité : Un+1-Un= ", max(abs(residu_stat[0])/rho0, abs(residu_stat[1])/(rho0*v_0), abs(residu_stat[2])/rhoE0 ))\r
+\r
+ if ( it>1 and abs(residu_stat[0])/rho0<precision and abs(residu_stat[1])/(rho0*v_0)<precision and abs(residu_stat[2])/rhoE0<precision):\r
+ isStationary = True\r
+ \r
+ for k in range(nbCells):\r
+ rho_field_Roe[k] = Un_Roe[k * nbComp + 0]\r
+ q_field_Roe[k] = Un_Roe[k * nbComp + 1]\r
+ rho_E_field_Roe[k] = Un_Roe[k * nbComp + 2]\r
+\r
+ v_field_Roe = q_field_Roe / rho_field_Roe\r
+ p_field_Roe = rho_to_p_StiffenedGaz(rho_field_Roe, q_field_Roe, rho_E_field_Roe)\r
+ T_field_Roe = rhoE_to_T_StiffenedGaz(rho_field_Roe, q_field_Roe, rho_E_field_Roe)\r
+ h_field_Roe = (rho_E_field_Roe + p_field_Roe) / rho_field_Roe - 0.5 * (q_field_Roe / rho_field_Roe) **2\r
+ p_field_Roe = p_field_Roe * 10 ** (-5)\r
+ \r
+ if( min(p_field_Roe)<0) :\r
+ raise ValueError("Negative pressure, stopping calculation")\r
+\r
+ #picture and video updates\r
+ lineDensity_Roe.set_ydata(rho_field_Roe)\r
+ lineMomentum_Roe.set_ydata(q_field_Roe)\r
+ lineRhoE_Roe.set_ydata(h_field_Roe)\r
+ linePressure_Roe.set_ydata(p_field_Roe)\r
+ lineVitesse_Roe.set_ydata(v_field_Roe)\r
+ lineTemperature_Roe.set_ydata(T_field_Roe)\r
+ \r
+ time = time + dt\r
+ it = it + 1\r
+\r
+ # Savings\r
+ if (it == 1 or it % output_freq == 0 or it >= ntmax or isStationary or time >= tmax):\r
+ \r
+ print("-- Time step : " + str(it) + ", Time: " + str(time) + ", dt: " + str(dt))\r
+\r
+ print("Temperature gain between inlet and outlet is ", T_field_Roe[nbCells-1]-T_field_Roe[0],"\n")\r
+\r
+ plt.savefig("EulerComplet_HeatedChannel_" + str(dim) + "D_Roe" + meshName + "Implicit"+str(isImplicit)+ str(it) + '_time' + str(time) + ".png")\r
+\r
+ print("-- Iter: " + str(it) + ", Time: " + str(time) + ", dt: " + str(dt)+"\n")\r
+ \r
+ if (it >= ntmax):\r
+ print("Maximum number of time steps ntmax= ", ntmax, " reached")\r
+ return\r
+\r
+ elif (isStationary):\r
+ print("Stationary regime reached at time step ", it, ", t= ", time)\r
+ print("------------------------------------------------------------------------------------")\r
+ np.savetxt("EulerComplet_HeatedChannel_" + str(dim) + "D_Roe" + meshName + "_rho_Stat.txt", rho_field_Roe, delimiter="\n")\r
+ np.savetxt("EulerComplet_HeatedChannel_" + str(dim) + "D_Roe" + meshName + "_q_Stat.txt", q_field_Roe, delimiter="\n")\r
+ np.savetxt("EulerComplet_HeatedChannel_" + str(dim) + "D_Roe" + meshName + "_rhoE_Stat.txt", rho_E_field_Roe, delimiter="\n")\r
+ np.savetxt("EulerComplet_HeatedChannel_" + str(dim) + "D_Roe" + meshName + "_p_Stat.txt", p_field_Roe, delimiter="\n")\r
+ plt.savefig("EulerComplet_HeatedChannel_" + str(dim) + "D_Roe" + meshName + "Implicit"+str(isImplicit)+"_Stat.png")\r
+ return\r
+ else:\r
+ print("Maximum time Tmax= ", tmax, " reached")\r
+ return\r
+\r
+\r
+def solve(a, b, nx, meshName, meshType, cfl, state_law, isImplicit):\r
+ print("Simulation of a heated channel in dimension 1 on " + str(nx) + " cells")\r
+ print("State Law Stiffened Gaz, " + state_law)\r
+ print("Initial data : ", "constant fields")\r
+ print("Boundary conditions : ", "Inlet (Left), Outlet (Right)")\r
+ print("Mesh name : ", meshName, ", ", nx, " cells")\r
+ # Problem data\r
+ tmax = 10.\r
+ ntmax = 100000\r
+ output_freq = 1000\r
+ EulerSystemRoe(ntmax, tmax, cfl, a, b, nx, output_freq, meshName, state_law, isImplicit)\r
+ return\r
+\r
+def FillMatrixFromEdges(j, Uk, nbComp, divMat, dt, dx):\r
+\r
+ if (j == 0):\r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j + 1) * nbComp + 0]\r
+ q_r = Uk[(j + 1) * nbComp + 1]\r
+ rho_E_r = Uk[(j + 1) * nbComp + 2] \r
+\r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ divMat.addValue(j * nbComp, (j + 1) * nbComp, Am)\r
+ divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
+ \r
+ p_inlet = rho_to_p_StiffenedGaz(Uk[j * nbComp + 0], Uk[j * nbComp + 1], Uk[j * nbComp + 2])# We take p from inside the domain\r
+ rho_l=p_to_rho_StiffenedGaz(p_inlet, T_inlet) # rho is computed from the temperature BC and the inner pressure\r
+ #rho_l = Uk[j * nbComp + 0] # We take rho from inside the domain\r
+ q_l = rho_l * v_inlet # q is imposed by the boundary condition v_inlet\r
+ rho_E_l = T_to_rhoE_StiffenedGaz(T_inlet, rho_l, q_l) #rhoE is obtained using the two boundary conditions v_inlet and e_inlet\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ divMat.addValue(j * nbComp, j * nbComp, Ap)\r
+\r
+ elif (j == nx - 1):\r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j ) * nbComp + 0] # We take rho inside the domain\r
+ q_r = Uk[(j ) * nbComp + 1] # We take q from inside the domain\r
+ rho_E_r = (p_outlet+gamma*p0)/(gamma-1) + 0.5*q_r**2/rho_r # rhoE is obtained using the boundary condition p_outlet\r
+\r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
+ divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
+ \r
+ rho_l = Uk[(j - 1) * nbComp + 0]\r
+ q_l = Uk[(j - 1) * nbComp + 1]\r
+ rho_E_l = Uk[(j - 1) * nbComp + 2]\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ divMat.addValue(j * nbComp, j * nbComp, Ap)\r
+ divMat.addValue(j * nbComp, (j - 1) * nbComp, Ap * (-1.))\r
+\r
+\r
+def FillMatrixFromInnerCell(j, Uk, nbComp, divMat, dt, dx):\r
+\r
+ rho_l = Uk[(j - 1) * nbComp + 0]\r
+ q_l = Uk[(j - 1) * nbComp + 1]\r
+ rho_E_l = Uk[(j - 1) * nbComp + 2]\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ \r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j + 1) * nbComp + 0]\r
+ q_r = Uk[(j + 1) * nbComp + 1]\r
+ rho_E_r = Uk[(j + 1) * nbComp + 2]\r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+\r
+ divMat.addValue(j * nbComp, (j + 1) * nbComp, Am)\r
+ divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
+ divMat.addValue(j * nbComp, j * nbComp, Ap)\r
+ divMat.addValue(j * nbComp, (j - 1) * nbComp, Ap * (-1.))\r
+ \r
+def FillRHSFromEdges(j, Uk, nbComp, Rhs, Un, dt, dx, isImplicit):\r
+ dUi1 = cdmath.Vector(3)\r
+ dUi2 = cdmath.Vector(3)\r
+ temp1 = cdmath.Vector(3)\r
+ temp2 = cdmath.Vector(3)\r
+\r
+ if (j == 0):\r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j + 1) * nbComp + 0]\r
+ q_r = Uk[(j + 1) * nbComp + 1]\r
+ rho_E_r = Uk[(j + 1) * nbComp + 2] \r
+\r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+\r
+ p_inlet = rho_to_p_StiffenedGaz(Uk[j * nbComp + 0], Uk[j * nbComp + 1], Uk[j * nbComp + 2])# We take p from inside the domain\r
+ rho_l=p_to_rho_StiffenedGaz(p_inlet, T_inlet) # rho is computed from the temperature BC and the inner pressure\r
+ #rho_l = Uk[j * nbComp + 0] # We take rho from inside the domain\r
+ q_l = rho_l * v_inlet # q is imposed by the boundary condition v_inlet\r
+ rho_E_l = T_to_rhoE_StiffenedGaz(T_inlet, rho_l, q_l) #rhoE is obtained using the two boundary conditions v_inlet and e_inlet\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ \r
+ if(isImplicit):\r
+ dUi1[0] = Uk[(j + 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi1[1] = Uk[(j + 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi1[2] = Uk[(j + 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+ temp1 = Am * dUi1\r
+ \r
+ dUi2[0] = rho_l - Uk[(j ) * nbComp + 0]\r
+ dUi2[1] = q_l - Uk[(j ) * nbComp + 1]\r
+ dUi2[2] = rho_E_l - Uk[(j ) * nbComp + 2]\r
+ temp2 = Ap * dUi2\r
+ else:\r
+ dUi2[0] = rho_l \r
+ dUi2[1] = q_l \r
+ dUi2[2] = rho_E_l \r
+ temp2 = Ap * dUi2\r
+\r
+ elif (j == nx - 1):\r
+ rho_l = Uk[(j - 1) * nbComp + 0]\r
+ q_l = Uk[(j - 1) * nbComp + 1]\r
+ rho_E_l = Uk[(j - 1) * nbComp + 2]\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+\r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j ) * nbComp + 0] # We take rho inside the domain\r
+ q_r = Uk[(j ) * nbComp + 1] # We take q from inside the domain\r
+ rho_E_r = (p_outlet+gamma*p0)/(gamma-1) + 0.5*q_r**2/rho_r # rhoE is obtained using the boundary condition p_outlet\r
+\r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
+\r
+ if(isImplicit):\r
+ dUi1[0] = rho_r - Uk[j * nbComp + 0]\r
+ dUi1[1] = q_r - Uk[j * nbComp + 1]\r
+ dUi1[2] = rho_E_r - Uk[j * nbComp + 2]\r
+ temp1 = Am * dUi1\r
+ \r
+ dUi2[0] = Uk[(j - 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi2[1] = Uk[(j - 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi2[2] = Uk[(j - 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+ temp2 = Ap * dUi2\r
+ else:\r
+ dUi1[0] = rho_r \r
+ dUi1[1] = q_r \r
+ dUi1[2] = rho_E_r \r
+ temp1 = Am * dUi1\r
+ \r
+ if(isImplicit):\r
+ Rhs[j * nbComp + 0] = -temp1[0] + temp2[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
+ Rhs[j * nbComp + 1] = -temp1[1] + temp2[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
+ Rhs[j * nbComp + 2] = -temp1[2] + temp2[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
+ else:#explicit scheme, contribution from the boundary data the right hand side\r
+ Rhs[j * nbComp + 0] = -temp1[0] + temp2[0] \r
+ Rhs[j * nbComp + 1] = -temp1[1] + temp2[1] \r
+ Rhs[j * nbComp + 2] = -temp1[2] + temp2[2] \r
+\r
+def FillRHSFromInnerCell(j, Uk, nbComp, Rhs, Un, dt, dx, isImplicit):\r
+\r
+ rho_l = Uk[(j - 1) * nbComp + 0]\r
+ q_l = Uk[(j - 1) * nbComp + 1]\r
+ rho_E_l = Uk[(j - 1) * nbComp + 2]\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ \r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j + 1) * nbComp + 0]\r
+ q_r = Uk[(j + 1) * nbComp + 1]\r
+ rho_E_r = Uk[(j + 1) * nbComp + 2]\r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+\r
+ if(isImplicit):#Contribution to the right hand side if te scheme is implicit\r
+ dUi1 = cdmath.Vector(3)\r
+ dUi2 = cdmath.Vector(3)\r
+ \r
+ dUi1[0] = Uk[(j + 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi1[1] = Uk[(j + 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi1[2] = Uk[(j + 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+ \r
+ dUi2[0] = Uk[(j - 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi2[1] = Uk[(j - 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi2[2] = Uk[(j - 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+\r
+ temp1 = Am * dUi1\r
+ temp2 = Ap * dUi2\r
+\r
+ Rhs[j * nbComp + 0] = -temp1[0] + temp2[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
+ Rhs[j * nbComp + 1] = -temp1[1] + temp2[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
+ Rhs[j * nbComp + 2] = -temp1[2] + temp2[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
+ else:\r
+ Rhs[j * nbComp + 0] = 0\r
+ Rhs[j * nbComp + 1] = 0\r
+ Rhs[j * nbComp + 2] = 0\r
+\r
+\r
+def computeSystemMatrix(a,b,nx, cfl, Uk, isImplicit):\r
+ dim = 1\r
+ nbComp = 3\r
+ dx = (b - a) / nx\r
+ dt = cfl * dx / c0\r
+ nbVoisinsMax = 2\r
+\r
+ nbCells = nx\r
+ divMat = cdmath.SparseMatrixPetsc(nbCells * nbComp, nbCells * nbComp, (nbVoisinsMax + 1) * nbComp)\r
+\r
+ divMat.zeroEntries() #sets the matrix coefficients to zero\r
+ for j in range(nbCells):\r
+ \r
+ # traitements des bords\r
+ if (j == 0):\r
+ FillMatrixFromEdges(j, Uk, nbComp, divMat, dt, dx)\r
+ elif (j == nbCells - 1):\r
+ FillMatrixFromEdges(j, Uk, nbComp, divMat, dt, dx)\r
+ # traitement des cellules internes\r
+ else:\r
+ FillMatrixFromInnerCell(j, Uk, nbComp, divMat, dt, dx)\r
+ \r
+ if(isImplicit): \r
+ divMat.diagonalShift(1.) # add one on the diagonal\r
+ else:\r
+ divMat*=-1.\r
+ divMat.diagonalShift(1.) # add one on the diagonal\r
+\r
+ return divMat\r
+\r
+def computeRHSVector(a,b,nx, cfl, Uk, Un, isImplicit):\r
+ dim = 1\r
+ nbComp = 3\r
+ dx = (b - a) / nx\r
+ dt = cfl * dx / c0\r
+ nbVoisinsMax = 2\r
+\r
+ nbCells = nx\r
+ Rhs = cdmath.Vector(nbCells * (nbComp))\r
+\r
+ for j in range(nbCells):\r
+ \r
+ # traitements des bords\r
+ if (j == 0):\r
+ FillRHSFromEdges(j, Uk, nbComp, Rhs, Un, dt, dx, isImplicit)\r
+ elif (j == nbCells - 1):\r
+ FillRHSFromEdges(j, Uk, nbComp, Rhs, Un, dt, dx, isImplicit)\r
+ # traitement des cellules internes\r
+ else:\r
+ FillRHSFromInnerCell(j, Uk, nbComp, Rhs, Un, dt, dx, isImplicit)\r
+ \r
+ return Rhs\r
+\r
+\r
+if __name__ == """__main__""":\r
+ nbComp=3 # number of equations \r
+ a = 0.# domain is interval [a,b]\r
+ b = 4.2# domain is interval [a,b]\r
+ nx = 10# number of cells\r
+ dx = (b - a) / nx # space step\r
+ x = [a + 0.5 * dx + i * dx for i in range(nx)] # array of cell center (1D mesh)\r
+ state_law = "Hermite575K"\r
+ state_law_parameters(state_law)\r
+ rho0=p_to_rho_StiffenedGaz(p_0, T_0)\r
+ rhoE0=T_to_rhoE_StiffenedGaz(T_0, rho0, rho0*v_0)\r
+\r
+\r
+#### initial condition (T in K, v in m/s, p in Pa)\r
+ p_initial = np.array([ p_outlet for xi in x])\r
+ v_initial = np.array([ v_inlet for xi in x])\r
+ T_initial = np.array([ T_inlet for xi in x])\r
+ \r
+ rho_field = p_to_rho_StiffenedGaz(p_initial, T_initial)\r
+ q_field = rho_field * v_initial\r
+ rho_E_field = rho_field * T_to_E_StiffenedGaz(p_initial, T_initial, v_initial)\r
+\r
+ U = cdmath.Vector(nx * (nbComp))#Inutile à terme mais nécessaire pour le moment\r
+\r
+ for k in range(nx):\r
+ U[k * nbComp + 0] = rho_field[k]\r
+ U[k * nbComp + 1] = q_field[k]\r
+ U[k * nbComp + 2] = rho_E_field[k]\r
+ print("\n Testing function computeSystemMatrix \n")\r
+ cfl = 0.5\r
+ computeSystemMatrix(a, b, nx, cfl, U,True) #Implicit matrix\r
+ computeSystemMatrix(a, b, nx, cfl, U,False) #Explicit matrix\r
+\r
+ print("\n Testing function computeRHSVector \n")\r
+ cfl = 0.5\r
+ computeRHSVector(a, b, nx, cfl, U, U,True) #Implicit RHS\r
+ computeRHSVector(a, b, nx, cfl, U, U,False) #Explicit RHS\r
+\r
+ print("\n Testing function solve (Implicit scheme) \n")\r
+ isImplicit=True\r
+ cfl = 1000.\r
+ solve(a, b, nx, "RegularSquares", "", cfl, state_law, isImplicit)\r
+ \r
+ print("\n Testing function solve (Explicit scheme) \n")\r
+ isImplicit=False\r
+ cfl = 0.5\r
+ solve(a, b, nx, "RegularSquares", "", cfl, state_law, isImplicit)\r
+\r
+++ /dev/null
-
-if (CDMATH_WITH_PYTHON AND CDMATH_WITH_PETSC AND CDMATH_WITH_POSTPRO)
-
- ADD_TEST(ExampleFullEulerSystem_1DRiemammProblem_Roe ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Euler_complet_RP.py )
-
-endif (CDMATH_WITH_PYTHON AND CDMATH_WITH_PETSC AND CDMATH_WITH_POSTPRO)
-
-
+++ /dev/null
-#!/usr/bin/env python3\r
-# -*-coding:utf-8 -*\r
-\r
-"""\r
-Created on Mon Aug 30 2021\r
-@author: Michael NDJINGA, Katia Ait Ameur, Coraline Mounier\r
-\r
-Euler system without source term in one dimension on regular domain [a,b]\r
-Riemann problemn with ghost cell boundary condition\r
-Left and right: Neumann boundary condition \r
-Roe scheme\r
-Regular square mesh\r
-\r
-State law Stiffened gaz : p = (gamma - 1) * rho * (e - q) - gamma * p0\r
-4 choices of parameters gamma and p0 are available : \r
- - Lagrange interpolation (with q=0)\r
- - Hermite interpolation with reference point at 575K (with q=0)\r
- - Hermite interpolation with reference point at 590K (with q=0)\r
- - Hermite interpolation with reference point at 617.94K (saturation at 155 bar) with q=0\r
- \r
-Linearized enthalpy : h = h_sat + cp * (T - T_sat)\r
-Values for cp and T_sat parameters are taken at the reference point chosen for the state law\r
-\r
-To do correct the computation of the time step : lambda_max (maximum eigenvalue) should be computed first)\r
-"""\r
-\r
-import cdmath\r
-import numpy as np\r
-import matplotlib\r
-\r
-matplotlib.use("Agg")\r
-import matplotlib.pyplot as plt\r
-import matplotlib.animation as manimation\r
-import sys\r
-from math import sqrt, atan, pi\r
-from numpy import sign\r
-\r
-\r
-## Numerical parameter\r
-precision = 1e-5\r
-\r
-#state law parameter : can be 'Lagrange', 'Hermite590K', 'Hermite617K', or 'FLICA'\r
-state_law = "Hermite590K"\r
-\r
-#indicates with test case is simulated to compare with FLICA5 results\r
-#num_test = 0 means there are no FLICA5 results given here\r
-num_test = 0\r
-\r
-#def state_law_parameters(state_law):\r
-#state law Stiffened Gaz : p = (gamma - 1) * rho * e - gamma * p0\r
-global gamma\r
-global p0\r
-global q\r
-global c0\r
-global cp\r
-global h_sat\r
-global T_sat\r
-\r
-if state_law == "Lagrange":\r
- # reference values for Lagrange interpolation\r
- p_ref = 155. * 10**5 #Reference pressure in a REP 900 nuclear power plant \r
- p1 = 153. * 10**5 # value of pressure at inlet of a 900 MWe PWR vessel\r
- rho_ref = 594.38 #density of water at saturation temperature of 617.94K and 155 bars\r
- rho1 = 742.36 # value of density at inlet of a 900 MWe PWR vessel (T1 = 565K)\r
- e_ref = 1603.8 * 10**3 #internal energy of water at saturation temperature of 617.94K and 155 bars\r
- e1 = 1273.6 * 10**3 # value of internal energy at inlet of a 900 MWe PWR vessel\r
- \r
- gamma = (p1 - p_ref) / (rho1 * e1 - rho_ref *e_ref) + 1.\r
- p0 = - 1. / gamma * ( - (gamma - 1) * rho_ref * e_ref + p_ref)\r
- q=0.\r
- c0 = sqrt((gamma - 1) * (e_ref + p_ref / rho_ref))\r
- \r
- cp = 8950.\r
- h_sat = 1.63 * 10 ** 6 # saturation enthalpy of water at 155 bars\r
- T_sat = 617.94 \r
-\r
-elif state_law == "Hermite617K":\r
- # reference values for Hermite interpolation\r
- p_ref = 155. * 10**5 #Reference pressure in a REP 900 nuclear power plant\r
- T_ref = 617.94 #Reference temperature for interpolation at 617.94K\r
- rho_ref = 594.38 #density of water at saturation temperature of 617.94K and 155 bars\r
- e_ref = 1603.8 * 10**3 #internal energy of water at saturation temperature of 617.94K and 155 bars\r
- h_ref = e_ref + p_ref / rho_ref\r
- c_ref = 621.43 #sound speed for water at 155 bars and 617.94K\r
-\r
- gamma = 1. + c_ref * c_ref / (e_ref + p_ref / rho_ref) # From the sound speed formula\r
- p0 = 1. / gamma * ( (gamma - 1) * rho_ref * e_ref - p_ref) \r
- q=0.\r
- c0 = sqrt((gamma - 1) * (e_ref + p_ref / rho_ref))\r
- \r
- cp = 8950. # value at 155 bar and 617.94K\r
- h_sat = 1.63 * 10 ** 6 # saturation enthalpy of water at 155 bars\r
- T_sat = 617.94 \r
-\r
-elif state_law == 'Hermite590K':\r
- # reference values for Hermite interpolation\r
- p_ref = 155. * 10**5 #Reference pressure in a REP 900 nuclear power plant\r
- T_ref = 590. #Reference temperature for interpolation at 590K\r
- rho_ref = 688.3 #density of water at 590K and 155 bars\r
- e_ref = 1411.4 * 10**3 #internal energy of water at 590K and 155 bars\r
- h_ref = e_ref + p_ref / rho_ref\r
- c_ref = 866.29 #sound speed for water at 155 bars and 590K\r
- \r
- gamma = 1. + c_ref * c_ref / (e_ref + p_ref / rho_ref) # From the sound speed formula\r
- p0 = 1. / gamma * ( (gamma - 1) * rho_ref * e_ref - p_ref) \r
- q=0.\r
- c0 = sqrt((gamma - 1) * (e_ref + p_ref / rho_ref))\r
- \r
- cp = 5996.8 # value at 155 bar and 590K\r
- h_sat = 1433.9 * 10 ** 3 # saturation enthalpy of water at 155 bars\r
- T_sat = 590. \r
-\r
-elif state_law == 'Hermite575K':\r
- # reference values for Hermite interpolation\r
- p_ref = 155 * 10**5 #Reference pressure in a REP 900 nuclear power plant\r
- T_ref = 575 #Reference temperature at inlet in a REP 900 nuclear power plant\r
- #Remaining values determined using iapws python package\r
- rho_ref = 722.66 #density of water at 575K and 155 bars\r
- e_ref = 1326552.66 #internal energy of water at 575K and 155 bars\r
- h_ref = e_ref + p_ref / rho_ref\r
- c_ref = 959.28 #sound speed for water at 155 bars and 575K\r
- \r
- gamma = 1 + c_ref * c_ref / (e_ref + p_ref / rho_ref) # From the sound speed formula\r
- p0 = 1 / gamma * ( (gamma - 1) * rho_ref * e_ref - p_ref) \r
- q=0.\r
- c0 = sqrt((gamma - 1) * (e_ref + p_ref / rho_ref))#This is actually c_ref\r
- \r
- cp = 5504.05 # value at 155 bar and 590K\r
- h_sat = h_ref # saturation enthalpy of water at 155 bars\r
- T_sat = T_ref\r
-else:\r
- raise ValueError("Incorrect value for parameter state_law")\r
-\r
-\r
-#initial parameters for Riemann problem (p in Pa, v in m/s, T in K)\r
-p_L = 155. * 10**5 \r
-p_R = 150. * 10**5\r
-v_L = 0.\r
-v_R = 0.\r
-h_L = 1.4963*10**6\r
-h_R = 1.4963*10**6\r
-\r
-T_L = (h_L - h_sat ) / cp + T_sat\r
-T_R = (h_R - h_sat ) / cp + T_sat\r
-\r
-def initial_conditions_Riemann_problem(a, b, nx):\r
- print("Initial data Riemann problem")\r
- dx = (b - a) / nx # space step\r
- x = [a + 0.5 * dx + i * dx for i in range(nx)] # array of cell center (1D mesh) \r
-\r
- p_initial = np.array([ (xi < (a + b) / 2) * p_L + (xi >= (a + b) / 2) * p_R for xi in x])\r
- v_initial = np.array([ (xi < (a + b) / 2) * v_L + (xi >= (a + b) / 2) * v_R for xi in x])\r
- T_initial = np.array([ (xi < (a + b) / 2) * T_L + (xi >= (a + b) / 2) * T_R for xi in x])\r
-\r
- rho_initial = p_to_rho_StiffenedGaz(p_initial, T_initial)\r
- q_initial = rho_initial * v_initial\r
- rho_E_initial = T_to_rhoE_StiffenedGaz(T_initial, rho_initial, q_initial)\r
-\r
- return rho_initial, q_initial, rho_E_initial, p_initial, v_initial, T_initial\r
-\r
-def rho_to_p_StiffenedGaz(rho_field, q_field, rho_E_field):\r
- p_field = (gamma - 1) * ( rho_E_field - 1. / 2 * q_field ** 2 / rho_field - rho_field * q) - gamma * p0\r
- return p_field\r
- \r
-\r
-def p_to_rho_StiffenedGaz(p_field, T_field):\r
- rho_field = (p_field + p0) * gamma / (gamma - 1) * 1 / (h_sat + cp * (T_field - T_sat) - q)\r
- return rho_field\r
- \r
-\r
-def T_to_rhoE_StiffenedGaz(T_field, rho_field, q_field):\r
- rho_E_field = 1 / 2 * (q_field) ** 2 / rho_field + p0 + rho_field / gamma * (h_sat + cp * (T_field- T_sat) + (gamma - 1) * q)\r
- return rho_E_field\r
-\r
- \r
-def rhoE_to_T_StiffenedGaz(rho_field, q_field, rho_E_field):\r
- T_field = T_sat + 1 / cp * (gamma * (rho_E_field / rho_field - 1 / 2 * (q_field / rho_field) ** 2) - gamma * p0 / rho_field - (gamma - 1) * q - h_sat)\r
- return T_field\r
-\r
-def dp_drho_e_const_StiffenedGaz( e ):\r
- return (gamma-1)*(e-q)\r
-\r
-def dp_de_rho_const_StiffenedGaz( rho ):\r
- return (gamma-1)*rho\r
-\r
-def sound_speed_StiffenedGaz( h ):\r
- return np.sqrt((gamma-1)*(h-q))\r
-\r
-def rho_h_to_p_StiffenedGaz( rho, h ):\r
- return (gamma - 1) * rho * ( h - q ) / gamma - p0\r
-\r
-def MatRoe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
- RoeMat = cdmath.Matrix(3, 3)\r
-\r
- u_l = q_l / rho_l\r
- u_r = q_r / rho_r\r
- p_l = rho_to_p_StiffenedGaz(rho_l, q_l, rho_E_l)\r
- p_r = rho_to_p_StiffenedGaz(rho_r, q_r, rho_E_r)\r
- H_l = rho_E_l / rho_l + p_l / rho_l\r
- H_r = rho_E_r / rho_r + p_r / rho_r\r
-\r
- # Roe averages\r
- rho = np.sqrt(rho_l * rho_r)\r
- u = (u_l * sqrt(rho_l) + u_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
- H = (H_l * sqrt(rho_l) + H_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
-\r
- p = rho_h_to_p_StiffenedGaz( rho, H - u**2/2. )\r
- e = H - p / rho - 1./2 * u**2\r
- dp_drho = dp_drho_e_const_StiffenedGaz( e )\r
- dp_de = dp_de_rho_const_StiffenedGaz( rho )\r
-\r
- RoeMat[0, 0] = 0\r
- RoeMat[0, 1] = 1\r
- RoeMat[0, 2] = 0\r
- RoeMat[1, 0] = dp_drho - u ** 2 + dp_de / rho * (u**2/2 - e)\r
- RoeMat[1, 1] = 2 * u - u * dp_de / rho\r
- RoeMat[1, 2] = dp_de / rho\r
- RoeMat[2, 0] = -u * ( -dp_drho + H - dp_de / rho * (u**2/2 - e) )\r
- RoeMat[2, 1] = H - dp_de / rho * u ** 2\r
- RoeMat[2, 2] = (dp_de / rho +1) * u\r
- \r
- return(RoeMat)\r
-\r
- \r
-def Droe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
- Droe = cdmath.Matrix(3, 3)\r
-\r
- u_l = q_l / rho_l\r
- u_r = q_r / rho_r\r
- p_l = rho_to_p_StiffenedGaz(rho_l, q_l, rho_E_l)\r
- p_r = rho_to_p_StiffenedGaz(rho_r, q_r, rho_E_r)\r
- H_l = rho_E_l / rho_l + p_l / rho_l\r
- H_r = rho_E_r / rho_r + p_r / rho_r\r
-\r
- # Roe averages\r
- rho = np.sqrt(rho_l * rho_r)\r
- u = (u_l * sqrt(rho_l) + u_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
- H = (H_l * sqrt(rho_l) + H_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
-\r
- c = sound_speed_StiffenedGaz( H - u**2/2. )\r
- \r
- lamb = cdmath.Vector(3)\r
- lamb[0] = u-c\r
- lamb[1] = u\r
- lamb[2] = u+c \r
-\r
- r = cdmath.Matrix(3, 3)\r
- r[0,0] = 1.\r
- r[1,0] = u-c\r
- r[2,0] = H-u*c \r
- r[0,1] = 1.\r
- r[1,1] = u \r
- r[2,1] = H-c**2/(gamma-1) \r
- r[0,2] = 1.\r
- r[1,2] = u+c\r
- r[2,2] = H+u*c \r
-\r
- l = cdmath.Matrix(3, 3)\r
- l[0,0] = (1./(2*c**2))*(0.5*(gamma-1)*u**2+u*c)\r
- l[1,0] = (1./(2*c**2))*(-u*(gamma-1)-c)\r
- l[2,0] = (1./(2*c**2))*(gamma-1)\r
- l[0,1] = ((gamma-1)/c**2)*(H-u**2)\r
- l[1,1] = ((gamma-1)/c**2)*u \r
- l[2,1] = -((gamma-1)/c**2) \r
- l[0,2] = (1./(2*c**2))*(0.5*(gamma-1)*u**2-u*c)\r
- l[1,2] = (1./(2*c**2))*(c-u*(gamma-1))\r
- l[2,2] = (1./(2*c**2))*(gamma-1)\r
-\r
- M1 = cdmath.Matrix(3, 3) #abs(lamb[0])*r[:,0].tensProduct(l[:,0])\r
- M2 = cdmath.Matrix(3, 3) #abs(lamb[1])*r[:,1].tensProduct(l[:,1]) \r
- M3 = cdmath.Matrix(3, 3) #abs(lamb[2])*r[:,2].tensProduct(l[:,2])\r
- for i in range(3):\r
- for j in range(3):\r
- M1[i,j] = abs(lamb[0])*r[i,0]*l[j,0]\r
- M2[i,j] = abs(lamb[1])*r[i,1]*l[j,1] \r
- M3[i,j] = abs(lamb[2])*r[i,2]*l[j,2]\r
- \r
- Droe = M1+M2+M3 \r
- \r
- return(Droe) \r
-\r
-\r
-def jacobianMatricesm(coeff, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
-\r
- if rho_l < 0 or rho_r < 0:\r
- print("rho_l=", rho_l, " rho_r= ", rho_r)\r
- raise ValueError("Negative density")\r
- if rho_E_l < 0 or rho_E_r < 0:\r
- print("rho_E_l=", rho_E_l, " rho_E_r= ", rho_E_r)\r
- raise ValueError("Negative total energy")\r
-\r
- RoeMat = MatRoe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
- \r
- Droe = Droe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
- return (RoeMat - Droe) * coeff * 0.5\r
-\r
-\r
-def jacobianMatricesp(coeff, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
- if rho_l < 0 or rho_r < 0:\r
- print("rho_l=", rho_l, " rho_r= ", rho_r)\r
- raise ValueError("Negative density")\r
- if rho_E_l < 0 or rho_E_r < 0:\r
- print("rho_E_l=", rho_E_l, " rho_E_r= ", rho_E_r)\r
- raise ValueError("Negative total energy")\r
-\r
- RoeMat = MatRoe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
- Droe = Droe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
-\r
- return (RoeMat + Droe) * coeff * 0.5\r
-\r
-\r
-def FillEdges(j, Uk, nbComp, divMat, Rhs, Un, dt, dx, isImplicit):\r
- dUi = cdmath.Vector(3)\r
-\r
- if (j == 0):\r
- rho_l = Uk[j * nbComp + 0]\r
- q_l = Uk[j * nbComp + 1]\r
- rho_E_l = Uk[j * nbComp + 2]\r
- rho_r = Uk[(j + 1) * nbComp + 0]\r
- q_r = Uk[(j + 1) * nbComp + 1]\r
- rho_E_r = Uk[(j + 1) * nbComp + 2]\r
- \r
- Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
- divMat.addValue(j * nbComp, (j + 1) * nbComp, Am)\r
- divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
-\r
- dUi[0] = Uk[(j + 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
- dUi[1] = Uk[(j + 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
- dUi[2] = Uk[(j + 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
- temp = Am * dUi\r
-\r
- if(isImplicit):\r
- Rhs[j * nbComp + 0] = -temp[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
- Rhs[j * nbComp + 1] = -temp[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
- Rhs[j * nbComp + 2] = -temp[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
-\r
- elif (j == nx - 1):\r
- rho_l = Uk[(j - 1) * nbComp + 0]\r
- q_l = Uk[(j - 1) * nbComp + 1]\r
- rho_E_l = Uk[(j - 1) * nbComp + 2]\r
- rho_r = Uk[j * nbComp + 0]\r
- q_r = Uk[j * nbComp + 1]\r
- rho_E_r = Uk[j * nbComp + 2]\r
-\r
- Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
- divMat.addValue(j * nbComp, j * nbComp, Ap)\r
- divMat.addValue(j * nbComp, (j - 1) * nbComp, Ap * (-1.))\r
-\r
- dUi[0] = Uk[(j - 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
- dUi[1] = Uk[(j - 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
- dUi[2] = Uk[(j - 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
-\r
- temp = Ap * dUi\r
-\r
- if(isImplicit):\r
- Rhs[j * nbComp + 0] = temp[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
- Rhs[j * nbComp + 1] = temp[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
- Rhs[j * nbComp + 2] = temp[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
-\r
-def FillInnerCell(j, Uk, nbComp, divMat, Rhs, Un, dt, dx, isImplicit):\r
-\r
- rho_l = Uk[(j - 1) * nbComp + 0]\r
- q_l = Uk[(j - 1) * nbComp + 1]\r
- rho_E_l = Uk[(j - 1) * nbComp + 2]\r
- rho_r = Uk[j * nbComp + 0]\r
- q_r = Uk[j * nbComp + 1]\r
- rho_E_r = Uk[j * nbComp + 2]\r
- Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
- \r
- rho_l = Uk[j * nbComp + 0]\r
- q_l = Uk[j * nbComp + 1]\r
- rho_E_l = Uk[j * nbComp + 2]\r
- rho_r = Uk[(j + 1) * nbComp + 0]\r
- q_r = Uk[(j + 1) * nbComp + 1]\r
- rho_E_r = Uk[(j + 1) * nbComp + 2]\r
- Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
-\r
- divMat.addValue(j * nbComp, (j + 1) * nbComp, Am)\r
- divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
- divMat.addValue(j * nbComp, j * nbComp, Ap)\r
- divMat.addValue(j * nbComp, (j - 1) * nbComp, Ap * (-1.))\r
- dUi1 = cdmath.Vector(3)\r
- dUi2 = cdmath.Vector(3)\r
- dUi1[0] = Uk[(j + 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
- dUi1[1] = Uk[(j + 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
- dUi1[2] = Uk[(j + 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
-\r
- dUi2[0] = Uk[(j - 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
- dUi2[1] = Uk[(j - 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
- dUi2[2] = Uk[(j - 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
- temp1 = Am * dUi1\r
- temp2 = Ap * dUi2\r
-\r
- if(isImplicit):\r
- Rhs[j * nbComp + 0] = -temp1[0] + temp2[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
- Rhs[j * nbComp + 1] = -temp1[1] + temp2[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
- Rhs[j * nbComp + 2] = -temp1[2] + temp2[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
-\r
-def SetPicture(rho_field_Roe, q_field_Roe, h_field_Roe, p_field_Roe, v_field_Roe, T_field_Roe, dx):\r
- max_initial_rho = max(rho_field_Roe)\r
- min_initial_rho = min(rho_field_Roe)\r
- max_initial_q = max(q_field_Roe)\r
- min_initial_q = min(q_field_Roe)\r
- min_initial_h = min(h_field_Roe)\r
- max_initial_h = max(h_field_Roe)\r
- max_initial_p = max(p_field_Roe)\r
- min_initial_p = min(p_field_Roe)\r
- max_initial_v = max(v_field_Roe)\r
- min_initial_v = min(v_field_Roe)\r
- max_initial_T = max(T_field_Roe)\r
- min_initial_T = min(T_field_Roe)\r
-\r
- fig, ([axDensity, axMomentum, axRhoE],[axPressure, axVitesse, axTemperature]) = plt.subplots(2, 3,sharex=True, figsize=(14,10))\r
- plt.gcf().subplots_adjust(wspace = 0.5)\r
-\r
- lineDensity_Roe, = axDensity.plot([a+0.5*dx + i*dx for i in range(nx)], rho_field_Roe, label='Roe')\r
- axDensity.set(xlabel='x (m)', ylabel='Densité (kg/m3)')\r
- axDensity.set_xlim(a,b)\r
- #axDensity.set_ylim(min_initial_rho - 0.1 * (max_initial_rho - min_initial_rho), 700.)\r
- axDensity.set_ylim(657, 660.5)\r
- axDensity.legend()\r
-\r
- lineMomentum_Roe, = axMomentum.plot([a+0.5*dx + i*dx for i in range(nx)], q_field_Roe, label='Roe')\r
- axMomentum.set(xlabel='x (m)', ylabel='Momentum (kg/(m2.s))')\r
- axMomentum.set_xlim(a,b)\r
- #axMomentum.set_ylim(min_initial_q - 0.1*(max_initial_q-min_initial_q), max_initial_q * 2.5)\r
- axMomentum.set_ylim(-50, 500)\r
- axMomentum.legend()\r
- \r
- lineRhoE_Roe, = axRhoE.plot([a+0.5*dx + i*dx for i in range(nx)], h_field_Roe, label='Roe')\r
- axRhoE.set(xlabel='x (m)', ylabel='h (J/m3)')\r
- axRhoE.set_xlim(a,b)\r
- #axRhoE.set_ylim(min_initial_h - 0.05*abs(min_initial_h), max_initial_h + 0.5*(max_initial_h-min_initial_h))\r
- axRhoE.set_ylim(1.495 * 10**6, 1.5*10**6)\r
- axRhoE.legend()\r
- \r
- linePressure_Roe, = axPressure.plot([a+0.5*dx + i*dx for i in range(nx)], p_field_Roe, label='Roe')\r
- axPressure.set(xlabel='x (m)', ylabel='Pression (bar)')\r
- axPressure.set_xlim(a,b)\r
- #axPressure.set_ylim(min_initial_p - 0.05*abs(min_initial_p), max_initial_p + 0.5*(max_initial_p-min_initial_p))\r
- axPressure.set_ylim(149, 156)\r
- axPressure.ticklabel_format(axis='y', style='sci', scilimits=(0,0))\r
- axPressure.legend()\r
-\r
- lineVitesse_Roe, = axVitesse.plot([a+0.5*dx + i*dx for i in range(nx)], v_field_Roe, label='Roe')\r
- axVitesse.set(xlabel='x (m)', ylabel='Vitesse (m/s)')\r
- axVitesse.set_xlim(a,b)\r
- #axVitesse.set_ylim(min_initial_v - 0.05*abs(min_initial_v), 15)\r
- axVitesse.set_ylim(-0.5, 1)\r
- axVitesse.ticklabel_format(axis='y', style='sci', scilimits=(0,0))\r
- axVitesse.legend()\r
-\r
- lineTemperature_Roe, = axTemperature.plot([a+0.5*dx + i*dx for i in range(nx)], T_field_Roe, label='Roe')\r
- axTemperature.set(xlabel='x (m)', ylabel='Température (K)')\r
- axTemperature.set_xlim(a,b)\r
- #axTemperature.set_ylim(min_initial_T - 0.005*abs(min_initial_T), 604)\r
- axTemperature.set_ylim(600, 601)\r
- axTemperature.ticklabel_format(axis='y', style='sci', scilimits=(0,0))\r
- axTemperature.legend()\r
- \r
- return(fig, lineDensity_Roe, lineMomentum_Roe, lineRhoE_Roe, linePressure_Roe, lineVitesse_Roe, lineTemperature_Roe, lineDensity_Roe, lineMomentum_Roe, lineRhoE_Roe, linePressure_Roe, lineVitesse_Roe, lineTemperature_Roe)\r
-\r
-\r
-def EulerSystemRoe(ntmax, tmax, cfl, a, b, nbCells, output_freq, meshName, state_law):\r
- #state_law_parameters(state_law)\r
- dim = 1\r
- nbComp = 3\r
- dt = 0.\r
- time = 0.\r
- it = 0\r
- isStationary = False\r
- isImplicit = False\r
- dx = (b - a) / nx\r
- dt = cfl * dx / c0\r
- #dt = 5*10**(-6)\r
- nbVoisinsMax = 2\r
-\r
- # iteration vectors\r
- Un_Roe = cdmath.Vector(nbCells * (nbComp))\r
- dUn_Roe = cdmath.Vector(nbCells * (nbComp))\r
- dUk_Roe = cdmath.Vector(nbCells * (nbComp))\r
- Rhs_Roe = cdmath.Vector(nbCells * (nbComp))\r
-\r
- # Initial conditions\r
- print("Construction of the initial condition …")\r
-\r
- rho_field_Roe, q_field_Roe, rho_E_field_Roe, p_field_Roe, v_field_Roe, T_field_Roe = initial_conditions_Riemann_problem(a, b, nx)\r
- h_field_Roe = (rho_E_field_Roe + p_field_Roe) / rho_field_Roe - 0.5 * (q_field_Roe / rho_field_Roe) **2\r
- p_field_Roe = p_field_Roe * 10 ** (-5)\r
- \r
-\r
- for k in range(nbCells):\r
- Un_Roe[k * nbComp + 0] = rho_field_Roe[k]\r
- Un_Roe[k * nbComp + 1] = q_field_Roe[k]\r
- Un_Roe[k * nbComp + 2] = rho_E_field_Roe[k]\r
-\r
- divMat_Roe = cdmath.SparseMatrixPetsc(nbCells * nbComp, nbCells * nbComp, (nbVoisinsMax + 1) * nbComp)\r
- \r
- # Picture settings\r
- fig, lineDensity, lineMomentum, lineRhoE, linePressure, lineVitesse, lineTemperature, lineDensity_Roe, lineMomentum_Roe, lineRhoE_Roe, linePressure_Roe, lineVitesse_Roe, lineTemperature_Roe = SetPicture( rho_field_Roe, q_field_Roe, h_field_Roe, p_field_Roe, v_field_Roe, T_field_Roe, dx)\r
-\r
- # Video settings\r
- FFMpegWriter = manimation.writers['ffmpeg']\r
- metadata = dict(title="Roe scheme for the 1D Euler system", artist="CEA Saclay", comment="Shock tube")\r
- writer = FFMpegWriter(fps=10, metadata=metadata, codec='h264')\r
- with writer.saving(fig, "1DEuler_complet_RP_Roe" + ".mp4", ntmax):\r
- writer.grab_frame()\r
- plt.savefig("EulerComplet_RP_" + str(dim) + "D_Roe" + meshName + "0" + ".png")\r
- np.savetxt( "EulerComplet_RP_" + str(dim) + "D_Roe" + meshName + "_rho" + "0" + ".txt", rho_field_Roe, delimiter="\n")\r
- np.savetxt( "EulerComplet_RP_" + str(dim) + "D_Roe" + meshName + "_q" + "0" + ".txt", q_field_Roe, delimiter="\n")\r
- iterGMRESMax = 50\r
- newton_max = 100\r
- \r
- print("Starting computation of the non linear Euler non isentropic system with Roe scheme …")\r
- # STARTING TIME LOOP\r
- while (it < ntmax and time <= tmax and not isStationary):\r
- dUn_Roe = Un_Roe.deepCopy()\r
- Uk_Roe = Un_Roe.deepCopy()\r
- residu_Roe = 1.\r
- \r
- k_Roe = 0\r
- while (k_Roe < newton_max and residu_Roe > precision):\r
- # STARTING NEWTON LOOP\r
- divMat_Roe.zeroEntries() #sets the matrix coefficients to zero\r
- for j in range(nbCells):\r
- \r
- # traitements des bords\r
- if (j == 0):\r
- FillEdges(j, Uk_Roe, nbComp, divMat_Roe, Rhs_Roe, Un_Roe, dt, dx, isImplicit)\r
- elif (j == nbCells - 1):\r
- FillEdges(j, Uk_Roe, nbComp, divMat_Roe, Rhs_Roe, Un_Roe, dt, dx, isImplicit)\r
- \r
- # traitement des cellules internes\r
- else:\r
- FillInnerCell(j, Uk_Roe, nbComp, divMat_Roe, Rhs_Roe, Un_Roe, dt, dx, isImplicit)\r
- \r
- #solving the linear system divMat * dUk = Rhs\r
- \r
- if(isImplicit):\r
- divMat_Roe.diagonalShift(1.)\r
- LS_Roe = cdmath.LinearSolver(divMat_Roe, Rhs_Roe, iterGMRESMax, precision, "GMRES", "LU")\r
- dUk_Roe = LS_Roe.solve()\r
- residu_Roe = dUk_Roe.norm()\r
- else:\r
- dUk_Roe=Rhs_Roe - divMat_Roe*Un_Roe\r
- residu_Roe = 0.#Convergence schéma Newton\r
- \r
- if (isImplicit and (it == 1 or it % output_freq == 0 or it >= ntmax or isStationary or time >= tmax)):\r
- print("Residu Newton : ", residu_Roe)\r
- print("Linear system converged in ", LS_Roe.getNumberOfIter(), " GMRES iterations")\r
- \r
- #updates for Newton loop\r
- Uk_Roe += dUk_Roe\r
- k_Roe = k_Roe + 1\r
- if (isImplicit and not LS_Roe.getStatus()):\r
- print("Linear system did not converge ", LS_Roe.getNumberOfIter(), " GMRES iterations")\r
- raise ValueError("No convergence of the linear system")\r
- \r
- if k_Roe == newton_max:\r
- raise ValueError("No convergence of Newton Roe Scheme")\r
- \r
- #updating fields\r
- Un_Roe = Uk_Roe.deepCopy()\r
- dUn_Roe -= Un_Roe\r
- if (dUn_Roe.norm()<precision):\r
- isStationary = True\r
- \r
- for k in range(nbCells):\r
- rho_field_Roe[k] = Un_Roe[k * nbComp + 0]\r
- q_field_Roe[k] = Un_Roe[k * nbComp + 1]\r
- rho_E_field_Roe[k] = Un_Roe[k * nbComp + 2]\r
- \r
- v_field_Roe = q_field_Roe / rho_field_Roe\r
- p_field_Roe = rho_to_p_StiffenedGaz(rho_field_Roe, q_field_Roe, rho_E_field_Roe)\r
- T_field_Roe = rhoE_to_T_StiffenedGaz(rho_field_Roe, q_field_Roe, rho_E_field_Roe)\r
- h_field_Roe = (rho_E_field_Roe + p_field_Roe) / rho_field_Roe - 0.5 * (q_field_Roe / rho_field_Roe) **2\r
- p_field_Roe = p_field_Roe * 10 ** (-5)\r
- \r
- if( min(p_field_Roe)<0) :\r
- raise ValueError("Negative pressure, stopping calculation")\r
- \r
- #picture and video updates\r
- lineDensity_Roe.set_ydata(rho_field_Roe)\r
- lineMomentum_Roe.set_ydata(q_field_Roe)\r
- lineRhoE_Roe.set_ydata(h_field_Roe)\r
- linePressure_Roe.set_ydata(p_field_Roe)\r
- lineVitesse_Roe.set_ydata(v_field_Roe)\r
- lineTemperature_Roe.set_ydata(T_field_Roe)\r
- \r
- writer.grab_frame()\r
- \r
- time = time + dt\r
- it = it + 1\r
- \r
- # Savings\r
- if (it == 1 or it % output_freq == 0 or it >= ntmax or isStationary or time >= tmax):\r
- \r
- print("-- Time step : " + str(it) + ", Time: " + str(time) + ", dt: " + str(dt))\r
- \r
- plt.savefig("EulerComplet_RP_" + str(dim) + "D_Roe" + meshName + str(it) + '_time' + str(time) + ".png")\r
-\r
- print("-- Iter: " + str(it) + ", Time: " + str(time) + ", dt: " + str(dt))\r
- if (it >= ntmax):\r
- print("Maximum number of time steps ntmax= ", ntmax, " reached")\r
- return\r
-\r
- elif (isStationary):\r
- print("Stationary regime reached at time step ", it, ", t= ", time)\r
- print("------------------------------------------------------------------------------------")\r
- np.savetxt("EulerComplet_RP_" + str(dim) + "D_Roe" + meshName + "_rho_Stat.txt", rho_field_Roe, delimiter="\n")\r
- np.savetxt("EulerComplet_RP_" + str(dim) + "D_Roe" + meshName + "_q_Stat.txt", q_field_Roe, delimiter="\n")\r
- np.savetxt("EulerComplet_RP_" + str(dim) + "D_Roe" + meshName + "_rhoE_Stat.txt", rho_E_field_Roe, delimiter="\n")\r
- np.savetxt("EulerComplet_RP_" + str(dim) + "D_Roe" + meshName + "_p_Stat.txt", p_field_Roe, delimiter="\n")\r
- plt.savefig("EulerComplet_RP_" + str(dim) + "D_Roe" + meshName + "_Stat.png")\r
- return\r
- else:\r
- print("Maximum time Tmax= ", tmax, " reached")\r
- return\r
-\r
-\r
-def solve(a, b, nx, meshName, meshType, cfl, state_law):\r
- print("Resolution of the Euler System in dimension 1 on " + str(nx) + " cells")\r
- print("State Law Stiffened Gaz, " + state_law)\r
- print("Initial data : ", "Riemann problem")\r
- print("Boundary conditions : ", "Neumann")\r
- print("Mesh name : ", meshName, ", ", nx, " cells")\r
- # Problem data\r
- tmax = 10.\r
- ntmax = 25\r
- output_freq = 1\r
- EulerSystemRoe(ntmax, tmax, cfl, a, b, nx, output_freq, meshName, state_law)\r
- return\r
-\r
-\r
-if __name__ == """__main__""":\r
- a = 0.\r
- b = 1.\r
- nx = 50\r
- cfl = 0.5\r
- #state_law = "Hermite590K"\r
- #state_law_parameters(state_law)\r
- solve(a, b, nx, "RegularSquares", "", cfl, state_law)\r
--- /dev/null
+
+if (CDMATH_WITH_PYTHON AND CDMATH_WITH_PETSC AND CDMATH_WITH_POSTPRO)
+ file(COPY TTC4.dat DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
+
+ ADD_TEST(ExampleFullEulerSystem_1DRiemammProblem_MAC ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Euler_complet_Toro4_convergence.py )
+
+endif (CDMATH_WITH_PYTHON AND CDMATH_WITH_PETSC AND CDMATH_WITH_POSTPRO)
+
+
--- /dev/null
+#!/usr/bin/env python3\r
+# -*-coding:utf-8 -*\r
+\r
+\r
+\r
+"""\r
+Created on Mon Apr 26 2021\r
+@author: Michael NDJINGA\r
+\r
+Toro 4 shock tube benchmarck from book 'Riemann Solvers and Numerical Methods for Fluid Dynamics, Third edition, Springer, 2009' (chapter 10)\r
+\r
+Euler system in one dimension on domain [a,b]\r
+Riemann problemn with ghost cell boundary condition\r
+Stag scheme compared with exact solution\r
+Regular mesh\r
+\r
+\r
+"""\r
+\r
+import cdmath\r
+import numpy as np\r
+import matplotlib\r
+\r
+matplotlib.use("Agg")\r
+import matplotlib.pyplot as plt\r
+import os\r
+from math import sqrt\r
+from numpy import sign\r
+\r
+#initial parameters for Riemann problem (p in Pa, v in m/s, rho in Kg/m**3)\r
+\r
+p_L = 460.894\r
+p_R = 46.095\r
+v_L = 19.5975\r
+v_R = -6.19633\r
+rho_L = 5.99924\r
+rho_R = 5.99242 \r
+\r
+pos_disc = 0.4\r
+\r
+precision = 1.e-5\r
+\r
+gamma = 1.4\r
+p0 = 0.\r
+q = 0\r
+\r
+tmax=0.035\r
+lam_max= max(abs(v_L)+sqrt(gamma*p_L/rho_L), abs(v_R)+sqrt(gamma*p_R/rho_R) )\r
+\r
+def initial_conditions_Riemann_problem(a, b, nx):\r
+ print("Initial data Riemann problem")\r
+ dx = (b - a) / nx # space step\r
+ x = [a + 0.5 * dx + i * dx for i in range(nx)] # array of cell center (1D mesh)\r
+ \r
+\r
+ p_initial = np.array([ (xi < pos_disc) * p_L + (xi >= pos_disc) * p_R for xi in x])\r
+ v_initial = np.array([ (xi < pos_disc) * v_L + (xi >= pos_disc) * v_R for xi in x])\r
+ rho_initial = np.array([ (xi < pos_disc) * rho_L + (xi >= pos_disc) * rho_R for xi in x])\r
+\r
+ e_initial = p_to_e_StiffenedGaz(p_initial, rho_initial)\r
+ q_initial = rho_initial * v_initial\r
+ rho_E_initial = rho_initial*e_initial + 0.5 * q_initial**2/rho_initial\r
+\r
+ return rho_initial, q_initial, rho_E_initial, p_initial, v_initial, e_initial\r
+\r
+def rho_to_p_StiffenedGaz(rho_field, q_field, rho_E_field):\r
+ p_field = (gamma - 1.) * ( rho_E_field - 1. / 2 * q_field ** 2 / rho_field - rho_field * q) - gamma * p0\r
+ return p_field \r
+\r
+def p_to_e_StiffenedGaz(p_field, rho_field):\r
+ e_field = (p_field + gamma*p0) / (gamma - 1.) / rho_field + q\r
+ return e_field\r
+ \r
+#Does not involve stiffened gas\r
+def e_to_rhoE_StiffenedGaz(e_field, rho_field, q_field):\r
+ rho_E_field = 1 / 2 * (q_field) ** 2 / rho_field + rho_field * e_field\r
+ return rho_E_field\r
+\r
+#Does not involve stiffened gas \r
+def rhoE_to_e_StiffenedGaz(rho_field, q_field, rho_E_field):\r
+ e_field = rho_E_field / rho_field - 1. / 2. * (q_field / rho_field)**2\r
+ return e_field\r
+\r
+def dp_drho_e_const_StiffenedGaz( e ):\r
+ return (gamma-1)*(e-q)\r
+\r
+def dp_de_rho_const_StiffenedGaz( rho ):\r
+ return (gamma-1)*rho\r
+\r
+def sound_speed_StiffenedGaz( h ):\r
+ return np.sqrt((gamma-1)*(h-q))\r
+\r
+def rho_h_to_p_StiffenedGaz( rho, h ):\r
+ return (gamma - 1) * rho * ( h - q ) / gamma - p0\r
+\r
+def MatRoe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
+ RoeMat = cdmath.Matrix(3, 3)\r
+\r
+ u_l = q_l / rho_l\r
+ u_r = q_r / rho_r\r
+ p_l = rho_to_p_StiffenedGaz(rho_l, q_l, rho_E_l)\r
+ p_r = rho_to_p_StiffenedGaz(rho_r, q_r, rho_E_r)\r
+ H_l = rho_E_l / rho_l + p_l / rho_l\r
+ H_r = rho_E_r / rho_r + p_r / rho_r\r
+\r
+ # Roe averages\r
+ rho = np.sqrt(rho_l * rho_r)\r
+ u = (u_l * sqrt(rho_l) + u_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
+ H = (H_l * sqrt(rho_l) + H_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
+\r
+ p = rho_h_to_p_StiffenedGaz( rho, H - u**2/2. )\r
+ e = H - p / rho - 1./2 * u**2\r
+ dp_drho = dp_drho_e_const_StiffenedGaz( e )\r
+ dp_de = dp_de_rho_const_StiffenedGaz( rho )\r
+\r
+ RoeMat[0, 0] = 0\r
+ RoeMat[0, 1] = 1\r
+ RoeMat[0, 2] = 0\r
+ RoeMat[1, 0] = dp_drho - u ** 2 + dp_de / rho * (u**2/2 - e)\r
+ RoeMat[1, 1] = 2 * u - u * dp_de / rho\r
+ RoeMat[1, 2] = dp_de / rho\r
+ RoeMat[2, 0] = -u * ( -dp_drho + H - dp_de / rho * (u**2/2 - e) )\r
+ RoeMat[2, 1] = H - dp_de / rho * u ** 2\r
+ RoeMat[2, 2] = (dp_de / rho +1) * u\r
+ \r
+ return(RoeMat)\r
+\r
+def Dmac_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
+ Dmac = cdmath.Matrix(3, 3)\r
+\r
+ u_l = q_l / rho_l\r
+ u_r = q_r / rho_r\r
+ p_l = rho_to_p_StiffenedGaz(rho_l, q_l, rho_E_l)\r
+ p_r = rho_to_p_StiffenedGaz(rho_r, q_r, rho_E_r)\r
+ H_l = rho_E_l / rho_l + p_l / rho_l\r
+ H_r = rho_E_r / rho_r + p_r / rho_r\r
+\r
+ # Roe averages\r
+ rho = np.sqrt(rho_l * rho_r)\r
+ u = (u_l * sqrt(rho_l) + u_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
+ H = (H_l * sqrt(rho_l) + H_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
+\r
+ p = rho_h_to_p_StiffenedGaz( rho, H - u**2/2. )\r
+ e = H - p / rho - 1./2 * u**2\r
+ dp_drho = dp_drho_e_const_StiffenedGaz( e )\r
+ dp_de = dp_de_rho_const_StiffenedGaz( rho )\r
+ \r
+ #Third choice for Dstag\r
+ # Dmac[0, 0] = 0\r
+ # Dmac[0, 1] = 1\r
+ # Dmac[0, 2] = 0\r
+ # Dmac[1, 0] = -dp_drho - u ** 2 - dp_de / rho * (u**2/2 - e)\r
+ # Dmac[1, 1] = 2 * u + u * dp_de / rho\r
+ # Dmac[1, 2] = -dp_de / rho\r
+ # Dmac[2, 0] = -u * ( dp_drho + H + dp_de / rho * (u**2/2 - e) )\r
+ # Dmac[2, 1] = H + dp_de / rho * u ** 2\r
+ # Dmac[2, 2] = (-dp_de / rho +1) * u\r
+ \r
+ #return Dmac * sign(u)\r
+\r
+ #Fifth choice for Dstag\r
+ Dmac[0, 0] = abs(u)-u\r
+ Dmac[0, 1] = 1\r
+ Dmac[0, 2] = 0\r
+ Dmac[1, 0] = -dp_drho - u ** 2 - dp_de / rho * (u**2/2 - e)\r
+ Dmac[1, 1] = abs(u) + u + u * dp_de / rho\r
+ Dmac[1, 2] = -dp_de / rho\r
+ Dmac[2, 0] = -u * ( dp_drho + H + u*(u-abs(u)) + dp_de / rho * (u**2/2 - e) )\r
+ Dmac[2, 1] = H + dp_de / rho * u ** 2\r
+ Dmac[2, 2] = -u*dp_de / rho + abs(u)\r
+ \r
+ return Dmac \r
+ \r
+\r
+def jacobianMatricesm(coeff, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r, scheme):\r
+\r
+ if rho_l < 0 or rho_r < 0:\r
+ print("rho_l=", rho_l, " rho_r= ", rho_r)\r
+ raise ValueError("Negative density")\r
+ if rho_E_l < 0 or rho_E_r < 0:\r
+ print("rho_E_l=", rho_E_l, " rho_E_r= ", rho_E_r)\r
+ raise ValueError("Negative total energy")\r
+\r
+ RoeMat = MatRoe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ \r
+ if scheme == 'Stag':\r
+ Dmac = Dmac_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ return (RoeMat - Dmac) * coeff * 0.5\r
+ \r
+ elif scheme == 'Roe':\r
+ Droe = Droe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
+ return (RoeMat - Droe) * coeff * 0.5\r
+\r
+\r
+def jacobianMatricesp(coeff, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r, scheme):\r
+ if rho_l < 0 or rho_r < 0:\r
+ print("rho_l=", rho_l, " rho_r= ", rho_r)\r
+ raise ValueError("Negative density")\r
+ if rho_E_l < 0 or rho_E_r < 0:\r
+ print("rho_E_l=", rho_E_l, " rho_E_r= ", rho_E_r)\r
+ raise ValueError("Negative total energy")\r
+\r
+ RoeMat = MatRoe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ if scheme == 'Stag':\r
+ Dmac = Dmac_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ return (RoeMat + Dmac) * coeff * 0.5\r
+ \r
+ elif scheme == 'Roe':\r
+ Droe = Droe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
+ return (RoeMat + Droe) * coeff * 0.5\r
+\r
+\r
+def FillEdges(j, Uk, nbComp, divMat, Rhs, Un, dt, dx, scheme):\r
+ if (j == 0):\r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j + 1) * nbComp + 0]\r
+ q_r = Uk[(j + 1) * nbComp + 1]\r
+ rho_E_r = Uk[(j + 1) * nbComp + 2]\r
+ \r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r, scheme)\r
+ divMat.addValue(j * nbComp, (j + 1) * nbComp, Am)\r
+ divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
+\r
+ dUi = cdmath.Vector(3)\r
+ dUi[0] = Uk[(j + 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi[1] = Uk[(j + 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi[2] = Uk[(j + 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+ temp = Am * dUi\r
+\r
+ Rhs[j * nbComp + 0] = -temp[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
+ Rhs[j * nbComp + 1] = -temp[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
+ Rhs[j * nbComp + 2] = -temp[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
+\r
+ elif (j == Un.size()/nbComp - 1):\r
+ rho_l = Uk[(j - 1) * nbComp + 0]\r
+ q_l = Uk[(j - 1) * nbComp + 1]\r
+ rho_E_l = Uk[(j - 1) * nbComp + 2]\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r, scheme)\r
+ divMat.addValue(j * nbComp, j * nbComp, Ap)\r
+ divMat.addValue(j * nbComp, (j - 1) * nbComp, Ap * (-1.))\r
+\r
+ dUi = cdmath.Vector(3)\r
+ dUi[0] = Uk[(j - 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi[1] = Uk[(j - 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi[2] = Uk[(j - 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+\r
+ temp = Ap * dUi\r
+ Rhs[j * nbComp + 0] = temp[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
+ Rhs[j * nbComp + 1] = temp[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
+ Rhs[j * nbComp + 2] = temp[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
+\r
+def FillInnerCell(j, Uk, nbComp, divMat, Rhs, Un, dt, dx, scheme):\r
+\r
+ rho_l = Uk[(j - 1) * nbComp + 0]\r
+ q_l = Uk[(j - 1) * nbComp + 1]\r
+ rho_E_l = Uk[(j - 1) * nbComp + 2]\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r, scheme)\r
+ \r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j + 1) * nbComp + 0]\r
+ q_r = Uk[(j + 1) * nbComp + 1]\r
+ rho_E_r = Uk[(j + 1) * nbComp + 2]\r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r, scheme)\r
+\r
+ divMat.addValue(j * nbComp, (j + 1) * nbComp, Am)\r
+ divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
+ divMat.addValue(j * nbComp, j * nbComp, Ap)\r
+ divMat.addValue(j * nbComp, (j - 1) * nbComp, Ap * (-1.))\r
+ dUi1 = cdmath.Vector(3)\r
+ dUi2 = cdmath.Vector(3)\r
+ dUi1[0] = Uk[(j + 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi1[1] = Uk[(j + 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi1[2] = Uk[(j + 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+\r
+ dUi2[0] = Uk[(j - 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi2[1] = Uk[(j - 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi2[2] = Uk[(j - 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+ temp1 = Am * dUi1\r
+ temp2 = Ap * dUi2\r
+\r
+ Rhs[j * nbComp + 0] = -temp1[0] + temp2[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
+ Rhs[j * nbComp + 1] = -temp1[1] + temp2[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
+ Rhs[j * nbComp + 2] = -temp1[2] + temp2[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
+\r
+def SetPicture():\r
+ max_initial_rho = max(rho_L,rho_R)\r
+ min_initial_rho = min(rho_L,rho_R)\r
+ max_initial_p = max(p_L,p_R)\r
+ min_initial_p = min(p_L,p_R)\r
+ max_initial_v = max(v_L,v_R)\r
+ min_initial_v = min(v_L,v_R)\r
+ max_initial_q = max_initial_rho*max_initial_v\r
+ min_initial_q = min_initial_rho*min_initial_v\r
+\r
+ e_L=p_to_e_StiffenedGaz(p_L, rho_L)\r
+ e_R=p_to_e_StiffenedGaz(p_R, rho_R)\r
+ h_L=e_L+p_L/rho_L\r
+ h_R=e_R+p_R/rho_R\r
+ max_initial_e = max(e_L, e_R)\r
+ min_initial_e = min(e_L, e_R)\r
+ min_initial_h = min(h_L,h_R)\r
+ max_initial_h = max(h_L,h_R)\r
+\r
+ fig, ([axDensity, axMomentum, axEnthalpie],[axPressure, axVitesse, axEinterne]) = plt.subplots(2, 3,sharex=True, figsize=(14,10))\r
+ #fig.suptitle('Staggered scheme')\r
+ plt.gcf().subplots_adjust(wspace = 0.5)\r
+\r
+ axDensity.set(xlabel='x (m)', ylabel='Densité (Kg/m3)')\r
+ axDensity.set_xlim(a,b)\r
+ axDensity.set_ylim(0.9*min_initial_rho , 6*max_initial_rho )\r
+ #axDensity.set_ylim(0.125, 1.01)\r
+ axDensity.legend()\r
+\r
+ axMomentum.set(xlabel='x (m)', ylabel='Momentum (Kg/m2/s)')\r
+ axMomentum.set_xlim(a,b)\r
+ axMomentum.set_ylim(0.9*min_initial_q , 2.5*max_initial_q )\r
+ #axMomentum.set_ylim(0., 1.)\r
+ axMomentum.legend()\r
+ \r
+ axEnthalpie.set(xlabel='x (m)', ylabel='h (J/Kg)')\r
+ axEnthalpie.set_xlim(a,b)\r
+ axEnthalpie.set_ylim(0.9*min_initial_h , 1.75*max_initial_h )\r
+ #axEnthalpie.set_ylim(2.5, 5.)\r
+ axEnthalpie.legend()\r
+ \r
+ axPressure.set(xlabel='x (m)', ylabel='Pression (Pa)')\r
+ axPressure.set_xlim(a,b)\r
+ axPressure.set_ylim(0.9*min_initial_p , 4*max_initial_p)\r
+ #axPressure.set_ylim(0.1, 1)\r
+ axPressure.ticklabel_format(axis='y', style='sci', scilimits=(0,0))\r
+ axPressure.legend()\r
+\r
+ axVitesse.set(xlabel='x (m)', ylabel='Vitesse (m/s)')\r
+ axVitesse.set_xlim(a,b)\r
+ axVitesse.set_ylim(0.9*min_initial_v , 1.1*max_initial_v)\r
+ #axVitesse.set_ylim(0., 1.5)\r
+ axVitesse.ticklabel_format(axis='y', style='sci', scilimits=(0,0))\r
+ axVitesse.legend()\r
+\r
+ axEinterne.set(xlabel='x (m)', ylabel='Energie interne (J/Kg)')\r
+ axEinterne.set_xlim(a,b)\r
+ axEinterne.set_ylim(0.9*min_initial_e , 1.75*max_initial_e)\r
+ #axEinterne.set_ylim(2., 3.5)\r
+ axEinterne.ticklabel_format(axis='y', style='sci', scilimits=(0,0))\r
+ axEinterne.legend()\r
+ \r
+ return(fig)\r
+\r
+def addCurves(rho_field_Stag, q_field_Stag, h_field_Stag, p_field_Stag, v_field_Stag, e_field_Stag, dx, nbCells, fig):\r
+\r
+ [axDensity, axMomentum, axEnthalpie,axPressure, axVitesse, axEinterne] = fig.get_axes()\r
+\r
+ lineDensity_Stag, = axDensity.plot([a+0.5*dx + i*dx for i in range(nbCells)], rho_field_Stag, label='Stag on '+str(nbCells)+' cells') #new picture for video # Returns a tuple of line objects, thus the comma\r
+\r
+ lineMomentum_Stag, = axMomentum.plot([a+0.5*dx + i*dx for i in range(nbCells)], q_field_Stag, label='Stag on '+str(nbCells)+' cells')\r
+ \r
+ lineEnthalpie_Stag, = axEnthalpie.plot([a+0.5*dx + i*dx for i in range(nbCells)], h_field_Stag, label='Stag on '+str(nbCells)+' cells')\r
+ \r
+ linePressure_Stag, = axPressure.plot([a+0.5*dx + i*dx for i in range(nbCells)], p_field_Stag, label='Stag on '+str(nbCells)+' cells')\r
+\r
+ lineVitesse_Stag, = axVitesse.plot([a+0.5*dx + i*dx for i in range(nbCells)], v_field_Stag, label='Stag on '+str(nbCells)+' cells')\r
+\r
+ lineEinterne_Stag, = axEinterne.plot([a+0.5*dx + i*dx for i in range(nbCells)], e_field_Stag, label='Stag on '+str(nbCells)+' cells')\r
+ \r
+ return\r
+\r
+def addSolutionToro(fig) :\r
+\r
+ x_exact, rho_exact, v_exact, p_exact, e_exact, h_exact, Mach_exact, left_or_right = np.loadtxt(os.path.dirname(__file__)+'/TTC'+str(4) + '.dat', unpack = True )\r
+\r
+ [axDensity, axMomentum, axEnthalpie,axPressure, axVitesse, axEinterne] = fig.get_axes()\r
+ lineRhoToro, = axDensity.plot(x_exact, rho_exact , label='Solution exacte')\r
+ axDensity.legend()\r
+ lineVToro, = axVitesse.plot(x_exact, v_exact, label='Solution exacte')\r
+ axVitesse.legend()\r
+ lineQToro, = axMomentum.plot(x_exact, v_exact*rho_exact, label='Solution exacte')\r
+ axMomentum.legend()\r
+ lineEToro, = axEinterne.plot(x_exact, e_exact, label='Solution exacte')\r
+ axEinterne.legend()\r
+ linePToro, = axPressure.plot(x_exact, p_exact, label='Solution exacte')\r
+ axPressure.legend()\r
+ lineEnthalpieToro, = axEnthalpie.plot(x_exact, h_exact, label='Solution exacte')\r
+ axEnthalpie.legend()\r
+\r
+\r
+def EulerSystemStaggered(ntmax, tmax, cfl, a, b, nbCells, output_freq, meshName,fig):\r
+ nbComp = 3\r
+ time = 0.\r
+ it = 0\r
+ isStationary = False\r
+ dx = (b - a) / nbCells\r
+ dt = cfl * dx / lam_max\r
+ nbVoisinsMax = 2\r
+\r
+ # iteration vectors\r
+ Un_Stag = cdmath.Vector(nbCells * (nbComp))\r
+ dUn_Stag = cdmath.Vector(nbCells * (nbComp))\r
+ dUk_Stag = cdmath.Vector(nbCells * (nbComp))\r
+ Rhs_Stag = cdmath.Vector(nbCells * (nbComp))\r
+ \r
+ # Initial conditions\r
+ print("Construction of the initial condition …")\r
+ rho_field_Stag, q_field_Stag, rho_E_field_Stag, p_field_Stag, v_field_Stag, e_field_Stag = initial_conditions_Riemann_problem(a, b, nbCells)\r
+ h_field_Stag = (rho_E_field_Stag + p_field_Stag) / rho_field_Stag - 0.5 * (q_field_Stag / rho_field_Stag) **2\r
+ \r
+\r
+ for k in range(nbCells):\r
+ Un_Stag[k * nbComp + 0] = rho_field_Stag[k]\r
+ Un_Stag[k * nbComp + 1] = q_field_Stag[k]\r
+ Un_Stag[k * nbComp + 2] = rho_E_field_Stag[k]\r
+ \r
+ divMat_Stag = cdmath.SparseMatrixPetsc(nbCells * nbComp, nbCells * nbComp, (nbVoisinsMax + 1) * nbComp)\r
+ \r
+ iterGMRESMax = 50\r
+ newton_max = 100\r
+\r
+ print("Starting computation of the non linear Euler non isentropic system with staggered scheme …")\r
+ # STARTING TIME LOOP\r
+ while (it < ntmax and time <= tmax and not isStationary):\r
+ dUn_Stag = Un_Stag.deepCopy()\r
+ Uk_Stag = Un_Stag.deepCopy()\r
+ residu_Stag = 1.\r
+ \r
+ k_Stag = 0\r
+ while (k_Stag < newton_max and residu_Stag > precision):\r
+ # STARTING NEWTON LOOP\r
+ #print("Iteration k=", k_Stag, " residu = ",residu_Stag)\r
+ divMat_Stag.zeroEntries() #sets the matrix coefficients to zero\r
+ for j in range(nbCells):\r
+ # traitements des bords\r
+ if (j == 0):\r
+ FillEdges(j, Uk_Stag, nbComp, divMat_Stag, Rhs_Stag, Un_Stag, dt, dx, 'Stag')\r
+ \r
+ elif (j == nbCells - 1):\r
+ FillEdges(j, Uk_Stag, nbComp, divMat_Stag, Rhs_Stag, Un_Stag, dt, dx, 'Stag')\r
+\r
+ # traitement des cellules internes\r
+ else:\r
+ FillInnerCell(j, Uk_Stag, nbComp, divMat_Stag, Rhs_Stag, Un_Stag, dt, dx, 'Stag')\r
+ \r
+ #print(divMat_Stag)\r
+ divMat_Stag.diagonalShift(1) # only after filling all coefficients\r
+\r
+ #solving the linear system divMat * dUk = Rhs\r
+ LS_Stag = cdmath.LinearSolver(divMat_Stag, Rhs_Stag, iterGMRESMax, precision, "GMRES", "LU")\r
+ dUk_Stag = LS_Stag.solve()\r
+ residu_Stag = dUk_Stag.norm()\r
+ \r
+ #updates for Newton loop\r
+ Uk_Stag += dUk_Stag\r
+ k_Stag = k_Stag + 1\r
+ if (not LS_Stag.getStatus()):\r
+ print("Linear system did not converge ", LS_Stag.getNumberOfIter(), " GMRES iterations")\r
+ raise ValueError("No convergence of the linear system")\r
+ \r
+ if k_Stag == newton_max:\r
+ raise ValueError("No convergence of Newton Staggered Scheme")\r
+ \r
+\r
+ #updating fields\r
+ Un_Stag = Uk_Stag.deepCopy()\r
+ dUn_Stag -= Un_Stag\r
+ \r
+ if (dUn_Stag.norm()<precision):\r
+ isStationary = True\r
+ \r
+ time = time + dt\r
+ it = it + 1\r
+\r
+ # Savings\r
+ if (it == 1 or it % output_freq == 0 or it >= ntmax or isStationary or time >= tmax):\r
+ \r
+ print("-- Time step : " + str(it) + ", Time: " + str(time) + ", dt: " + str(dt))\r
+ print("Linear system converged in ", LS_Stag.getNumberOfIter(), " GMRES iterations")\r
+\r
+ plt.savefig("EulerCompletStaggeredToro4" + meshName + str(it) + '_time' + str(time) + ".png")\r
+\r
+ print("##################### Last time step: " + str(it) + ", Time: " + str(time) + ", dt: " + str(dt))\r
+\r
+ # Postprocessing\r
+ for k in range(nbCells):\r
+ rho_field_Stag[k] = Un_Stag[k * nbComp + 0]\r
+ q_field_Stag[k] = Un_Stag[k * nbComp + 1]\r
+ rho_E_field_Stag[k] = Un_Stag[k * nbComp + 2]\r
+ \r
+ v_field_Stag = q_field_Stag / rho_field_Stag\r
+ p_field_Stag = rho_to_p_StiffenedGaz(rho_field_Stag, q_field_Stag, rho_E_field_Stag)\r
+ e_field_Stag = rhoE_to_e_StiffenedGaz(rho_field_Stag, q_field_Stag, rho_E_field_Stag)\r
+ h_field_Stag = (rho_E_field_Stag + p_field_Stag) / rho_field_Stag - 0.5 * (q_field_Stag / rho_field_Stag) **2\r
+ \r
+ # Picture settings\r
+ addCurves(rho_field_Stag, q_field_Stag, h_field_Stag, p_field_Stag, v_field_Stag, e_field_Stag, dx, nbCells,fig)\r
+\r
+ np.savetxt("EulerCompletStaggeredToro4" + meshName + "_rho_" + str(nbCells) + "_cells.txt", rho_field_Stag, delimiter="\n")\r
+ np.savetxt("EulerCompletStaggeredToro4" + meshName + "_q_" + str(nbCells) + "_cells.txt", q_field_Stag, delimiter="\n")\r
+ np.savetxt("EulerCompletStaggeredToro4" + meshName + "_h_" + str(nbCells) + "._cellstxt", h_field_Stag, delimiter="\n")\r
+ np.savetxt("EulerCompletStaggeredToro4" + meshName + "_p_" + str(nbCells) + "_cells.txt", p_field_Stag, delimiter="\n")\r
+ np.savetxt("EulerCompletStaggeredToro4" + meshName + "_v_" + str(nbCells) + "_cells.txt", v_field_Stag, delimiter="\n")\r
+ np.savetxt("EulerCompletStaggeredToro4" + meshName + "_e_" + str(nbCells) + "_cells.txt", e_field_Stag, delimiter="\n")\r
+ \r
+ if (it >= ntmax):\r
+ print("Maximum number of time steps ntmax= ", ntmax, " reached on "+ str(nbCells) + " cells")\r
+\r
+ elif (time >= tmax):\r
+ print("Maximum time tmax= ", tmax, " reached on "+ str(nbCells) + " cells")\r
+ elif (isStationary):\r
+ print("Stationary regime reached at time step ", it, ", t= ", time, ", on "+ str(nbCells) + " cells")\r
+ else:\r
+ raise ValueError("Unexpected end of simulation")\r
+\r
+ return\r
+\r
+def solve(a, b, meshName, meshType, cfl):\r
+ print("Convergence study for the Euler System in dimension 1")\r
+ print("State Law Stiffened Gaz, gamma = ", gamma, " p0= ", p0 )\r
+ print("Initial data : ", "Riemann problem")\r
+ print("Boundary conditions : ", "Neumann")\r
+ print("Mesh name : ", meshName)\r
+ # Problem data\r
+ ntmax = 1000000\r
+ output_freq = 100\r
+ fig=SetPicture()\r
+ for nx in [20, 50, 100]:\r
+ print("Resolution of the Euler System in dimension 1 on " + str(nx) + " cells")\r
+ EulerSystemStaggered(ntmax, tmax, cfl, a, b, nx, output_freq, meshName,fig)\r
+\r
+ addSolutionToro(fig)\r
+ plt.savefig("EulerCompletStaggeredToro4" + meshName + "_convergence.png")\r
+\r
+ return\r
+\r
+\r
+if __name__ == """__main__""":\r
+ a = 0.\r
+ b = 1.\r
+ cfl = 0.99\r
+ solve(a, b, "RegularGrid", "", cfl)\r
--- /dev/null
+0.0 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.01 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.02 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.03 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.04 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.05 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.06 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.07 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.08 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.09 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.1 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.11 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.12 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.13 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.14 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.15 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.16 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.17 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.18 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.19 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.2 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.21 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.22 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.23 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.24 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.25 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.26 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.27 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.28 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.29 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.3 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.31 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.32 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.33 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.34 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.35 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.36 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.37 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.38 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.39 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.4 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.41 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.42 5.99924 19.5975 460.894 192.063494709 268.888892593 1.88966250666 1.0
+0.43 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.44 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.45 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.46 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.47 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.48 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.49 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.5 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.51 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.52 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.53 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.54 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.55 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.56 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.57 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.58 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.59 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.6 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.61 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.62 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.63 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.64 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.65 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.66 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.67 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.68 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.69 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.7 14.282349952 8.68977441163 1691.6469554 296.107951613 414.551132258 0.674822343487 1.0
+0.71 31.0426016416 8.68977441163 1691.6469554 136.235919828 190.730287759 0.994875359291 0.0
+0.72 31.0426016416 8.68977441163 1691.6469554 136.235919828 190.730287759 0.994875359291 0.0
+0.73 31.0426016416 8.68977441163 1691.6469554 136.235919828 190.730287759 0.994875359291 0.0
+0.74 31.0426016416 8.68977441163 1691.6469554 136.235919828 190.730287759 0.994875359291 0.0
+0.75 31.0426016416 8.68977441163 1691.6469554 136.235919828 190.730287759 0.994875359291 0.0
+0.76 31.0426016416 8.68977441163 1691.6469554 136.235919828 190.730287759 0.994875359291 0.0
+0.77 31.0426016416 8.68977441163 1691.6469554 136.235919828 190.730287759 0.994875359291 0.0
+0.78 31.0426016416 8.68977441163 1691.6469554 136.235919828 190.730287759 0.994875359291 0.0
+0.79 31.0426016416 8.68977441163 1691.6469554 136.235919828 190.730287759 0.994875359291 0.0
+0.8 31.0426016416 8.68977441163 1691.6469554 136.235919828 190.730287759 0.994875359291 0.0
+0.81 31.0426016416 8.68977441163 1691.6469554 136.235919828 190.730287759 0.994875359291 0.0
+0.82 31.0426016416 8.68977441163 1691.6469554 136.235919828 190.730287759 0.994875359291 0.0
+0.83 5.99242 -6.19633 46.095 19.230544588 26.9227624232 1.88818582941 0.0
+0.84 5.99242 -6.19633 46.095 19.230544588 26.9227624232 1.88818582941 0.0
+0.85 5.99242 -6.19633 46.095 19.230544588 26.9227624232 1.88818582941 0.0
+0.86 5.99242 -6.19633 46.095 19.230544588 26.9227624232 1.88818582941 0.0
+0.87 5.99242 -6.19633 46.095 19.230544588 26.9227624232 1.88818582941 0.0
+0.88 5.99242 -6.19633 46.095 19.230544588 26.9227624232 1.88818582941 0.0
+0.89 5.99242 -6.19633 46.095 19.230544588 26.9227624232 1.88818582941 0.0
+0.9 5.99242 -6.19633 46.095 19.230544588 26.9227624232 1.88818582941 0.0
+0.91 5.99242 -6.19633 46.095 19.230544588 26.9227624232 1.88818582941 0.0
+0.92 5.99242 -6.19633 46.095 19.230544588 26.9227624232 1.88818582941 0.0
+0.93 5.99242 -6.19633 46.095 19.230544588 26.9227624232 1.88818582941 0.0
+0.94 5.99242 -6.19633 46.095 19.230544588 26.9227624232 1.88818582941 0.0
+0.95 5.99242 -6.19633 46.095 19.230544588 26.9227624232 1.88818582941 0.0
+0.96 5.99242 -6.19633 46.095 19.230544588 26.9227624232 1.88818582941 0.0
+0.97 5.99242 -6.19633 46.095 19.230544588 26.9227624232 1.88818582941 0.0
+0.98 5.99242 -6.19633 46.095 19.230544588 26.9227624232 1.88818582941 0.0
+0.99 5.99242 -6.19633 46.095 19.230544588 26.9227624232 1.88818582941 0.0
--- /dev/null
+
+if (CDMATH_WITH_PYTHON AND CDMATH_WITH_PETSC AND CDMATH_WITH_POSTPRO)
+
+ SET(ISIMPLICIT 0 )#Explicit scheme
+ ADD_TEST(ExampleEulerSystem_1DRiemammProblem_ExplicitRoe ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/EulerEquations_RiemannProblem_Roe.py ${ISIMPLICIT} )
+
+ SET(ISIMPLICIT 1 )#Implicit scheme
+ ADD_TEST(ExampleEulerSystem_1DRiemammProblem_ImplicitRoe ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/EulerEquations_RiemannProblem_Roe.py ${ISIMPLICIT} )
+
+endif (CDMATH_WITH_PYTHON AND CDMATH_WITH_PETSC AND CDMATH_WITH_POSTPRO)
+
+
--- /dev/null
+#!/usr/bin/env python3\r
+# -*-coding:utf-8 -*\r
+\r
+"""\r
+Created on Mon Aug 30 2021\r
+@author: Michael NDJINGA, Katia Ait Ameur, Coraline Mounier\r
+\r
+Euler system without source term in one dimension on regular domain [a,b]\r
+Riemann problemn with ghost cell boundary condition\r
+Left and right: Neumann boundary condition \r
+Roe scheme\r
+Regular square mesh\r
+\r
+State law Stiffened gaz : p = (gamma - 1) * rho * (e - q) - gamma * p0\r
+4 choices of parameters gamma and p0 are available : \r
+ - Lagrange interpolation (with q=0)\r
+ - Hermite interpolation with reference point at 575K (with q=0)\r
+ - Hermite interpolation with reference point at 590K (with q=0)\r
+ - Hermite interpolation with reference point at 617.94K (saturation at 155 bar) with q=0\r
+ \r
+Linearized enthalpy : h = h_sat + cp * (T - T_sat)\r
+Values for cp and T_sat parameters are taken at the reference point chosen for the state law\r
+\r
+To do correct the computation of the time step : lambda_max (maximum eigenvalue) should be computed first)\r
+"""\r
+\r
+import cdmath\r
+import numpy as np\r
+import matplotlib\r
+import matplotlib.animation as manimation\r
+matplotlib.use("Agg")\r
+import matplotlib.pyplot as plt\r
+from math import sqrt\r
+from numpy import sign\r
+import sys\r
+\r
+## Numerical parameter\r
+precision = 1e-5\r
+\r
+#state law parameter : can be 'Lagrange', 'Hermite590K', 'Hermite617K', or 'FLICA'\r
+state_law = "Hermite590K"\r
+\r
+#indicates with test case is simulated to compare with FLICA5 results\r
+#num_test = 0 means there are no FLICA5 results given here\r
+num_test = 0\r
+\r
+#def state_law_parameters(state_law):\r
+#state law Stiffened Gaz : p = (gamma - 1) * rho * e - gamma * p0\r
+global gamma\r
+global p0\r
+global q\r
+global c0\r
+global cp\r
+global h_sat\r
+global T_sat\r
+\r
+if state_law == "Lagrange":\r
+ # reference values for Lagrange interpolation\r
+ p_ref = 155. * 10**5 #Reference pressure in a REP 900 nuclear power plant \r
+ p1 = 153. * 10**5 # value of pressure at inlet of a 900 MWe PWR vessel\r
+ rho_ref = 594.38 #density of water at saturation temperature of 617.94K and 155 bars\r
+ rho1 = 742.36 # value of density at inlet of a 900 MWe PWR vessel (T1 = 565K)\r
+ e_ref = 1603.8 * 10**3 #internal energy of water at saturation temperature of 617.94K and 155 bars\r
+ e1 = 1273.6 * 10**3 # value of internal energy at inlet of a 900 MWe PWR vessel\r
+ \r
+ gamma = (p1 - p_ref) / (rho1 * e1 - rho_ref *e_ref) + 1.\r
+ p0 = - 1. / gamma * ( - (gamma - 1) * rho_ref * e_ref + p_ref)\r
+ q=0.\r
+ c0 = sqrt((gamma - 1) * (e_ref + p_ref / rho_ref))\r
+ \r
+ cp = 8950.\r
+ h_sat = 1.63 * 10 ** 6 # saturation enthalpy of water at 155 bars\r
+ T_sat = 617.94 \r
+\r
+elif state_law == "Hermite617K":\r
+ # reference values for Hermite interpolation\r
+ p_ref = 155. * 10**5 #Reference pressure in a REP 900 nuclear power plant\r
+ T_ref = 617.94 #Reference temperature for interpolation at 617.94K\r
+ rho_ref = 594.38 #density of water at saturation temperature of 617.94K and 155 bars\r
+ e_ref = 1603.8 * 10**3 #internal energy of water at saturation temperature of 617.94K and 155 bars\r
+ h_ref = e_ref + p_ref / rho_ref\r
+ c_ref = 621.43 #sound speed for water at 155 bars and 617.94K\r
+\r
+ gamma = 1. + c_ref * c_ref / (e_ref + p_ref / rho_ref) # From the sound speed formula\r
+ p0 = 1. / gamma * ( (gamma - 1) * rho_ref * e_ref - p_ref) \r
+ q=0.\r
+ c0 = sqrt((gamma - 1) * (e_ref + p_ref / rho_ref))\r
+ \r
+ cp = 8950. # value at 155 bar and 617.94K\r
+ h_sat = 1.63 * 10 ** 6 # saturation enthalpy of water at 155 bars\r
+ T_sat = 617.94 \r
+\r
+elif state_law == 'Hermite590K':\r
+ # reference values for Hermite interpolation\r
+ p_ref = 155. * 10**5 #Reference pressure in a REP 900 nuclear power plant\r
+ T_ref = 590. #Reference temperature for interpolation at 590K\r
+ rho_ref = 688.3 #density of water at 590K and 155 bars\r
+ e_ref = 1411.4 * 10**3 #internal energy of water at 590K and 155 bars\r
+ h_ref = e_ref + p_ref / rho_ref\r
+ c_ref = 866.29 #sound speed for water at 155 bars and 590K\r
+ \r
+ gamma = 1. + c_ref * c_ref / (e_ref + p_ref / rho_ref) # From the sound speed formula\r
+ p0 = 1. / gamma * ( (gamma - 1) * rho_ref * e_ref - p_ref) \r
+ q=0.\r
+ c0 = sqrt((gamma - 1) * (e_ref + p_ref / rho_ref))\r
+ \r
+ cp = 5996.8 # value at 155 bar and 590K\r
+ h_sat = 1433.9 * 10 ** 3 # saturation enthalpy of water at 155 bars\r
+ T_sat = 590. \r
+\r
+elif state_law == 'Hermite575K':\r
+ # reference values for Hermite interpolation\r
+ p_ref = 155 * 10**5 #Reference pressure in a REP 900 nuclear power plant\r
+ T_ref = 575 #Reference temperature at inlet in a REP 900 nuclear power plant\r
+ #Remaining values determined using iapws python package\r
+ rho_ref = 722.66 #density of water at 575K and 155 bars\r
+ e_ref = 1326552.66 #internal energy of water at 575K and 155 bars\r
+ h_ref = e_ref + p_ref / rho_ref\r
+ c_ref = 959.28 #sound speed for water at 155 bars and 575K\r
+ \r
+ gamma = 1 + c_ref * c_ref / (e_ref + p_ref / rho_ref) # From the sound speed formula\r
+ p0 = 1 / gamma * ( (gamma - 1) * rho_ref * e_ref - p_ref) \r
+ q=0.\r
+ c0 = sqrt((gamma - 1) * (e_ref + p_ref / rho_ref))#This is actually c_ref\r
+ \r
+ cp = 5504.05 # value at 155 bar and 590K\r
+ h_sat = h_ref # saturation enthalpy of water at 155 bars\r
+ T_sat = T_ref\r
+else:\r
+ raise ValueError("Incorrect value for parameter state_law")\r
+\r
+\r
+#initial parameters for Riemann problem (p in Pa, v in m/s, T in K)\r
+p_L = 155. * 10**5 \r
+p_R = 150. * 10**5\r
+v_L = 0.\r
+v_R = 0.\r
+h_L = 1.4963*10**6\r
+h_R = 1.4963*10**6\r
+\r
+T_L = (h_L - h_sat ) / cp + T_sat\r
+T_R = (h_R - h_sat ) / cp + T_sat\r
+\r
+def initial_conditions_Riemann_problem(a, b, nx):\r
+ print("Initial data Riemann problem")\r
+ dx = (b - a) / nx # space step\r
+ x = [a + 0.5 * dx + i * dx for i in range(nx)] # array of cell center (1D mesh) \r
+\r
+ p_initial = np.array([ (xi < (a + b) / 2) * p_L + (xi >= (a + b) / 2) * p_R for xi in x])\r
+ v_initial = np.array([ (xi < (a + b) / 2) * v_L + (xi >= (a + b) / 2) * v_R for xi in x])\r
+ T_initial = np.array([ (xi < (a + b) / 2) * T_L + (xi >= (a + b) / 2) * T_R for xi in x])\r
+\r
+ rho_initial = p_to_rho_StiffenedGaz(p_initial, T_initial)\r
+ q_initial = rho_initial * v_initial\r
+ rho_E_initial = T_to_rhoE_StiffenedGaz(T_initial, rho_initial, q_initial)\r
+\r
+ return rho_initial, q_initial, rho_E_initial, p_initial, v_initial, T_initial\r
+\r
+def rho_to_p_StiffenedGaz(rho_field, q_field, rho_E_field):\r
+ p_field = (gamma - 1) * ( rho_E_field - 1. / 2 * q_field ** 2 / rho_field - rho_field * q) - gamma * p0\r
+ return p_field\r
+ \r
+\r
+def p_to_rho_StiffenedGaz(p_field, T_field):\r
+ rho_field = (p_field + p0) * gamma / (gamma - 1) * 1 / (h_sat + cp * (T_field - T_sat) - q)\r
+ return rho_field\r
+ \r
+\r
+def T_to_rhoE_StiffenedGaz(T_field, rho_field, q_field):\r
+ rho_E_field = 1 / 2 * (q_field) ** 2 / rho_field + p0 + rho_field / gamma * (h_sat + cp * (T_field- T_sat) + (gamma - 1) * q)\r
+ return rho_E_field\r
+\r
+ \r
+def rhoE_to_T_StiffenedGaz(rho_field, q_field, rho_E_field):\r
+ T_field = T_sat + 1 / cp * (gamma * (rho_E_field / rho_field - 1 / 2 * (q_field / rho_field) ** 2) - gamma * p0 / rho_field - (gamma - 1) * q - h_sat)\r
+ return T_field\r
+\r
+def dp_drho_e_const_StiffenedGaz( e ):\r
+ return (gamma-1)*(e-q)\r
+\r
+def dp_de_rho_const_StiffenedGaz( rho ):\r
+ return (gamma-1)*rho\r
+\r
+def sound_speed_StiffenedGaz( h ):\r
+ return np.sqrt((gamma-1)*(h-q))\r
+\r
+def rho_h_to_p_StiffenedGaz( rho, h ):\r
+ return (gamma - 1) * rho * ( h - q ) / gamma - p0\r
+\r
+def MatRoe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
+ RoeMat = cdmath.Matrix(3, 3)\r
+\r
+ u_l = q_l / rho_l\r
+ u_r = q_r / rho_r\r
+ p_l = rho_to_p_StiffenedGaz(rho_l, q_l, rho_E_l)\r
+ p_r = rho_to_p_StiffenedGaz(rho_r, q_r, rho_E_r)\r
+ H_l = rho_E_l / rho_l + p_l / rho_l\r
+ H_r = rho_E_r / rho_r + p_r / rho_r\r
+\r
+ # Roe averages\r
+ rho = np.sqrt(rho_l * rho_r)\r
+ u = (u_l * sqrt(rho_l) + u_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
+ H = (H_l * sqrt(rho_l) + H_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
+\r
+ p = rho_h_to_p_StiffenedGaz( rho, H - u**2/2. )\r
+ e = H - p / rho - 1./2 * u**2\r
+ dp_drho = dp_drho_e_const_StiffenedGaz( e )\r
+ dp_de = dp_de_rho_const_StiffenedGaz( rho )\r
+\r
+ RoeMat[0, 0] = 0\r
+ RoeMat[0, 1] = 1\r
+ RoeMat[0, 2] = 0\r
+ RoeMat[1, 0] = dp_drho - u ** 2 + dp_de / rho * (u**2/2 - e)\r
+ RoeMat[1, 1] = 2 * u - u * dp_de / rho\r
+ RoeMat[1, 2] = dp_de / rho\r
+ RoeMat[2, 0] = -u * ( -dp_drho + H - dp_de / rho * (u**2/2 - e) )\r
+ RoeMat[2, 1] = H - dp_de / rho * u ** 2\r
+ RoeMat[2, 2] = (dp_de / rho +1) * u\r
+ \r
+ return(RoeMat)\r
+\r
+ \r
+def Droe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
+ Droe = cdmath.Matrix(3, 3)\r
+\r
+ u_l = q_l / rho_l\r
+ u_r = q_r / rho_r\r
+ p_l = rho_to_p_StiffenedGaz(rho_l, q_l, rho_E_l)\r
+ p_r = rho_to_p_StiffenedGaz(rho_r, q_r, rho_E_r)\r
+ H_l = rho_E_l / rho_l + p_l / rho_l\r
+ H_r = rho_E_r / rho_r + p_r / rho_r\r
+\r
+ # Roe averages\r
+ rho = np.sqrt(rho_l * rho_r)\r
+ u = (u_l * sqrt(rho_l) + u_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
+ H = (H_l * sqrt(rho_l) + H_r * sqrt(rho_r)) / (sqrt(rho_l) + sqrt(rho_r))\r
+\r
+ c = sound_speed_StiffenedGaz( H - u**2/2. )\r
+ \r
+ lamb = cdmath.Vector(3)\r
+ lamb[0] = u-c\r
+ lamb[1] = u\r
+ lamb[2] = u+c \r
+\r
+ r = cdmath.Matrix(3, 3)\r
+ r[0,0] = 1.\r
+ r[1,0] = u-c\r
+ r[2,0] = H-u*c \r
+ r[0,1] = 1.\r
+ r[1,1] = u \r
+ r[2,1] = H-c**2/(gamma-1) \r
+ r[0,2] = 1.\r
+ r[1,2] = u+c\r
+ r[2,2] = H+u*c \r
+\r
+ l = cdmath.Matrix(3, 3)\r
+ l[0,0] = (1./(2*c**2))*(0.5*(gamma-1)*u**2+u*c)\r
+ l[1,0] = (1./(2*c**2))*(-u*(gamma-1)-c)\r
+ l[2,0] = (1./(2*c**2))*(gamma-1)\r
+ l[0,1] = ((gamma-1)/c**2)*(H-u**2)\r
+ l[1,1] = ((gamma-1)/c**2)*u \r
+ l[2,1] = -((gamma-1)/c**2) \r
+ l[0,2] = (1./(2*c**2))*(0.5*(gamma-1)*u**2-u*c)\r
+ l[1,2] = (1./(2*c**2))*(c-u*(gamma-1))\r
+ l[2,2] = (1./(2*c**2))*(gamma-1)\r
+\r
+ M1 = cdmath.Matrix(3, 3) #abs(lamb[0])*r[:,0].tensProduct(l[:,0])\r
+ M2 = cdmath.Matrix(3, 3) #abs(lamb[1])*r[:,1].tensProduct(l[:,1]) \r
+ M3 = cdmath.Matrix(3, 3) #abs(lamb[2])*r[:,2].tensProduct(l[:,2])\r
+ for i in range(3):\r
+ for j in range(3):\r
+ M1[i,j] = abs(lamb[0])*r[i,0]*l[j,0]\r
+ M2[i,j] = abs(lamb[1])*r[i,1]*l[j,1] \r
+ M3[i,j] = abs(lamb[2])*r[i,2]*l[j,2]\r
+ \r
+ Droe = M1+M2+M3 \r
+ \r
+ return(Droe) \r
+\r
+\r
+def jacobianMatricesm(coeff, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
+\r
+ if rho_l < 0 or rho_r < 0:\r
+ print("rho_l=", rho_l, " rho_r= ", rho_r)\r
+ raise ValueError("Negative density")\r
+ if rho_E_l < 0 or rho_E_r < 0:\r
+ print("rho_E_l=", rho_E_l, " rho_E_r= ", rho_E_r)\r
+ raise ValueError("Negative total energy")\r
+\r
+ RoeMat = MatRoe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ \r
+ Droe = Droe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
+ return (RoeMat - Droe) * coeff * 0.5\r
+\r
+\r
+def jacobianMatricesp(coeff, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r):\r
+ if rho_l < 0 or rho_r < 0:\r
+ print("rho_l=", rho_l, " rho_r= ", rho_r)\r
+ raise ValueError("Negative density")\r
+ if rho_E_l < 0 or rho_E_r < 0:\r
+ print("rho_E_l=", rho_E_l, " rho_E_r= ", rho_E_r)\r
+ raise ValueError("Negative total energy")\r
+\r
+ RoeMat = MatRoe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ Droe = Droe_StiffenedGaz( rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r) \r
+\r
+ return (RoeMat + Droe) * coeff * 0.5\r
+\r
+\r
+def FillEdges(j, Uk, nbComp, divMat, Rhs, Un, dt, dx, isImplicit):\r
+ dUi = cdmath.Vector(3)\r
+\r
+ if (j == 0):\r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j + 1) * nbComp + 0]\r
+ q_r = Uk[(j + 1) * nbComp + 1]\r
+ rho_E_r = Uk[(j + 1) * nbComp + 2]\r
+ \r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ divMat.addValue(j * nbComp, (j + 1) * nbComp, Am)\r
+ divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
+\r
+ dUi[0] = Uk[(j + 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi[1] = Uk[(j + 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi[2] = Uk[(j + 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+ temp = Am * dUi\r
+\r
+ if(isImplicit):\r
+ Rhs[j * nbComp + 0] = -temp[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
+ Rhs[j * nbComp + 1] = -temp[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
+ Rhs[j * nbComp + 2] = -temp[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
+\r
+ elif (j == nx - 1):\r
+ rho_l = Uk[(j - 1) * nbComp + 0]\r
+ q_l = Uk[(j - 1) * nbComp + 1]\r
+ rho_E_l = Uk[(j - 1) * nbComp + 2]\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ divMat.addValue(j * nbComp, j * nbComp, Ap)\r
+ divMat.addValue(j * nbComp, (j - 1) * nbComp, Ap * (-1.))\r
+\r
+ dUi[0] = Uk[(j - 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi[1] = Uk[(j - 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi[2] = Uk[(j - 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+\r
+ temp = Ap * dUi\r
+\r
+ if(isImplicit):\r
+ Rhs[j * nbComp + 0] = temp[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
+ Rhs[j * nbComp + 1] = temp[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
+ Rhs[j * nbComp + 2] = temp[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
+\r
+def FillInnerCell(j, Uk, nbComp, divMat, Rhs, Un, dt, dx, isImplicit):\r
+\r
+ rho_l = Uk[(j - 1) * nbComp + 0]\r
+ q_l = Uk[(j - 1) * nbComp + 1]\r
+ rho_E_l = Uk[(j - 1) * nbComp + 2]\r
+ rho_r = Uk[j * nbComp + 0]\r
+ q_r = Uk[j * nbComp + 1]\r
+ rho_E_r = Uk[j * nbComp + 2]\r
+ Ap = jacobianMatricesp(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+ \r
+ rho_l = Uk[j * nbComp + 0]\r
+ q_l = Uk[j * nbComp + 1]\r
+ rho_E_l = Uk[j * nbComp + 2]\r
+ rho_r = Uk[(j + 1) * nbComp + 0]\r
+ q_r = Uk[(j + 1) * nbComp + 1]\r
+ rho_E_r = Uk[(j + 1) * nbComp + 2]\r
+ Am = jacobianMatricesm(dt / dx, rho_l, q_l, rho_E_l, rho_r, q_r, rho_E_r)\r
+\r
+ divMat.addValue(j * nbComp, (j + 1) * nbComp, Am)\r
+ divMat.addValue(j * nbComp, j * nbComp, Am * (-1.))\r
+ divMat.addValue(j * nbComp, j * nbComp, Ap)\r
+ divMat.addValue(j * nbComp, (j - 1) * nbComp, Ap * (-1.))\r
+ dUi1 = cdmath.Vector(3)\r
+ dUi2 = cdmath.Vector(3)\r
+ dUi1[0] = Uk[(j + 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi1[1] = Uk[(j + 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi1[2] = Uk[(j + 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+\r
+ dUi2[0] = Uk[(j - 1) * nbComp + 0] - Uk[j * nbComp + 0]\r
+ dUi2[1] = Uk[(j - 1) * nbComp + 1] - Uk[j * nbComp + 1]\r
+ dUi2[2] = Uk[(j - 1) * nbComp + 2] - Uk[j * nbComp + 2]\r
+ temp1 = Am * dUi1\r
+ temp2 = Ap * dUi2\r
+\r
+ if(isImplicit):\r
+ Rhs[j * nbComp + 0] = -temp1[0] + temp2[0] - (Uk[j * nbComp + 0] - Un[j * nbComp + 0])\r
+ Rhs[j * nbComp + 1] = -temp1[1] + temp2[1] - (Uk[j * nbComp + 1] - Un[j * nbComp + 1])\r
+ Rhs[j * nbComp + 2] = -temp1[2] + temp2[2] - (Uk[j * nbComp + 2] - Un[j * nbComp + 2])\r
+\r
+def SetPicture(rho_field_Roe, q_field_Roe, h_field_Roe, p_field_Roe, v_field_Roe, T_field_Roe, dx):\r
+ max_initial_rho = max(rho_field_Roe)\r
+ min_initial_rho = min(rho_field_Roe)\r
+ max_initial_q = max(q_field_Roe)\r
+ min_initial_q = min(q_field_Roe)\r
+ min_initial_h = min(h_field_Roe)\r
+ max_initial_h = max(h_field_Roe)\r
+ max_initial_p = max(p_field_Roe)\r
+ min_initial_p = min(p_field_Roe)\r
+ max_initial_v = max(v_field_Roe)\r
+ min_initial_v = min(v_field_Roe)\r
+ max_initial_T = max(T_field_Roe)\r
+ min_initial_T = min(T_field_Roe)\r
+\r
+ fig, ([axDensity, axMomentum, axRhoE],[axPressure, axVitesse, axTemperature]) = plt.subplots(2, 3,sharex=True, figsize=(14,10))\r
+ plt.gcf().subplots_adjust(wspace = 0.5)\r
+\r
+ lineDensity_Roe, = axDensity.plot([a+0.5*dx + i*dx for i in range(nx)], rho_field_Roe, label='Roe')\r
+ axDensity.set(xlabel='x (m)', ylabel='Densité (kg/m3)')\r
+ axDensity.set_xlim(a,b)\r
+ #axDensity.set_ylim(min_initial_rho - 0.1 * (max_initial_rho - min_initial_rho), 700.)\r
+ axDensity.set_ylim(657, 660.5)\r
+ axDensity.legend()\r
+\r
+ lineMomentum_Roe, = axMomentum.plot([a+0.5*dx + i*dx for i in range(nx)], q_field_Roe, label='Roe')\r
+ axMomentum.set(xlabel='x (m)', ylabel='Momentum (kg/(m2.s))')\r
+ axMomentum.set_xlim(a,b)\r
+ #axMomentum.set_ylim(min_initial_q - 0.1*(max_initial_q-min_initial_q), max_initial_q * 2.5)\r
+ axMomentum.set_ylim(-50, 500)\r
+ axMomentum.legend()\r
+ \r
+ lineRhoE_Roe, = axRhoE.plot([a+0.5*dx + i*dx for i in range(nx)], h_field_Roe, label='Roe')\r
+ axRhoE.set(xlabel='x (m)', ylabel='h (J/m3)')\r
+ axRhoE.set_xlim(a,b)\r
+ #axRhoE.set_ylim(min_initial_h - 0.05*abs(min_initial_h), max_initial_h + 0.5*(max_initial_h-min_initial_h))\r
+ axRhoE.set_ylim(1.495 * 10**6, 1.5*10**6)\r
+ axRhoE.legend()\r
+ \r
+ linePressure_Roe, = axPressure.plot([a+0.5*dx + i*dx for i in range(nx)], p_field_Roe, label='Roe')\r
+ axPressure.set(xlabel='x (m)', ylabel='Pression (bar)')\r
+ axPressure.set_xlim(a,b)\r
+ #axPressure.set_ylim(min_initial_p - 0.05*abs(min_initial_p), max_initial_p + 0.5*(max_initial_p-min_initial_p))\r
+ axPressure.set_ylim(149, 156)\r
+ axPressure.ticklabel_format(axis='y', style='sci', scilimits=(0,0))\r
+ axPressure.legend()\r
+\r
+ lineVitesse_Roe, = axVitesse.plot([a+0.5*dx + i*dx for i in range(nx)], v_field_Roe, label='Roe')\r
+ axVitesse.set(xlabel='x (m)', ylabel='Vitesse (m/s)')\r
+ axVitesse.set_xlim(a,b)\r
+ #axVitesse.set_ylim(min_initial_v - 0.05*abs(min_initial_v), 15)\r
+ axVitesse.set_ylim(-0.5, 1)\r
+ axVitesse.ticklabel_format(axis='y', style='sci', scilimits=(0,0))\r
+ axVitesse.legend()\r
+\r
+ lineTemperature_Roe, = axTemperature.plot([a+0.5*dx + i*dx for i in range(nx)], T_field_Roe, label='Roe')\r
+ axTemperature.set(xlabel='x (m)', ylabel='Température (K)')\r
+ axTemperature.set_xlim(a,b)\r
+ #axTemperature.set_ylim(min_initial_T - 0.005*abs(min_initial_T), 604)\r
+ axTemperature.set_ylim(600, 601)\r
+ axTemperature.ticklabel_format(axis='y', style='sci', scilimits=(0,0))\r
+ axTemperature.legend()\r
+ \r
+ return(fig, lineDensity_Roe, lineMomentum_Roe, lineRhoE_Roe, linePressure_Roe, lineVitesse_Roe, lineTemperature_Roe, lineDensity_Roe, lineMomentum_Roe, lineRhoE_Roe, linePressure_Roe, lineVitesse_Roe, lineTemperature_Roe)\r
+\r
+\r
+def EulerSystemRoe(ntmax, tmax, cfl, a, b, nbCells, output_freq, meshName, state_law, isImplicit):\r
+ #state_law_parameters(state_law)\r
+ dim = 1\r
+ nbComp = 3\r
+ dt = 0.\r
+ time = 0.\r
+ it = 0\r
+ isStationary = False\r
+ dx = (b - a) / nx\r
+ dt = cfl * dx / c0\r
+ #dt = 5*10**(-6)\r
+ nbVoisinsMax = 2\r
+\r
+ # iteration vectors\r
+ Un_Roe = cdmath.Vector(nbCells * (nbComp))\r
+ dUn_Roe = cdmath.Vector(nbCells * (nbComp))\r
+ dUk_Roe = cdmath.Vector(nbCells * (nbComp))\r
+ Rhs_Roe = cdmath.Vector(nbCells * (nbComp))\r
+\r
+ # Initial conditions\r
+ print("Construction of the initial condition …")\r
+\r
+ rho_field_Roe, q_field_Roe, rho_E_field_Roe, p_field_Roe, v_field_Roe, T_field_Roe = initial_conditions_Riemann_problem(a, b, nx)\r
+ h_field_Roe = (rho_E_field_Roe + p_field_Roe) / rho_field_Roe - 0.5 * (q_field_Roe / rho_field_Roe) **2\r
+ p_field_Roe = p_field_Roe * 10 ** (-5)\r
+ \r
+\r
+ for k in range(nbCells):\r
+ Un_Roe[k * nbComp + 0] = rho_field_Roe[k]\r
+ Un_Roe[k * nbComp + 1] = q_field_Roe[k]\r
+ Un_Roe[k * nbComp + 2] = rho_E_field_Roe[k]\r
+\r
+ divMat_Roe = cdmath.SparseMatrixPetsc(nbCells * nbComp, nbCells * nbComp, (nbVoisinsMax + 1) * nbComp)\r
+ \r
+ # Picture settings\r
+ fig, lineDensity, lineMomentum, lineRhoE, linePressure, lineVitesse, lineTemperature, lineDensity_Roe, lineMomentum_Roe, lineRhoE_Roe, linePressure_Roe, lineVitesse_Roe, lineTemperature_Roe = SetPicture( rho_field_Roe, q_field_Roe, h_field_Roe, p_field_Roe, v_field_Roe, T_field_Roe, dx)\r
+ if(isImplicit):\r
+ ImplicitOrExplicit="Implicit" \r
+ else:\r
+ ImplicitOrExplicit="Explicit" \r
+\r
+ # Video settings\r
+ FFMpegWriter = manimation.writers['ffmpeg']\r
+ metadata = dict(title=ImplicitOrExplicit+" Roe scheme for the 1D Euler system", artist="CEA Saclay", comment="Shock tube")\r
+ writer = FFMpegWriter(fps=10, metadata=metadata, codec='h264')\r
+ with writer.saving(fig, "1DEulerEquations_RiemannProblem_"+ImplicitOrExplicit+"Roe" + ".mp4", ntmax):\r
+ writer.grab_frame()\r
+ plt.savefig("EulerEquations_RiemannProblem_" + str(dim) + "D_"+ImplicitOrExplicit+"Roe" + meshName + "0" + ".png")\r
+ np.savetxt( "EulerEquations_RiemannProblem_" + str(dim) + "D_"+ImplicitOrExplicit+"Roe" + meshName + "_rho" + "0" + ".txt", rho_field_Roe, delimiter="\n")\r
+ np.savetxt( "EulerEquations_RiemannProblem_" + str(dim) + "D_"+ImplicitOrExplicit+"Roe" + meshName + "_q" + "0" + ".txt", q_field_Roe, delimiter="\n")\r
+ iterGMRESMax = 50\r
+ newton_max = 100\r
+ \r
+ print("Starting computation of the non linear Euler non isentropic system with Roe scheme …")\r
+ # STARTING TIME LOOP\r
+ while (it < ntmax and time <= tmax and not isStationary):\r
+ dUn_Roe = Un_Roe.deepCopy()\r
+ Uk_Roe = Un_Roe.deepCopy()\r
+ residu_Roe = 1.\r
+ \r
+ k_Roe = 0\r
+ while (k_Roe < newton_max and residu_Roe > precision):\r
+ # STARTING NEWTON LOOP\r
+ divMat_Roe.zeroEntries() #sets the matrix coefficients to zero\r
+ for j in range(nbCells):\r
+ \r
+ # traitements des bords\r
+ if (j == 0):\r
+ FillEdges(j, Uk_Roe, nbComp, divMat_Roe, Rhs_Roe, Un_Roe, dt, dx, isImplicit)\r
+ elif (j == nbCells - 1):\r
+ FillEdges(j, Uk_Roe, nbComp, divMat_Roe, Rhs_Roe, Un_Roe, dt, dx, isImplicit)\r
+ \r
+ # traitement des cellules internes\r
+ else:\r
+ FillInnerCell(j, Uk_Roe, nbComp, divMat_Roe, Rhs_Roe, Un_Roe, dt, dx, isImplicit)\r
+ \r
+ #solving the linear system divMat * dUk = Rhs\r
+ \r
+ if(isImplicit):\r
+ divMat_Roe.diagonalShift(1.)\r
+ LS_Roe = cdmath.LinearSolver(divMat_Roe, Rhs_Roe, iterGMRESMax, precision, "GMRES", "LU")\r
+ dUk_Roe = LS_Roe.solve()\r
+ residu_Roe = dUk_Roe.norm()\r
+ else:\r
+ dUk_Roe=Rhs_Roe - divMat_Roe*Un_Roe\r
+ residu_Roe = 0.#Convergence schéma Newton\r
+ \r
+ if (isImplicit and (it == 1 or it % output_freq == 0 or it >= ntmax or isStationary or time >= tmax)):\r
+ print("Residu Newton : ", residu_Roe)\r
+ print("Linear system converged in ", LS_Roe.getNumberOfIter(), " GMRES iterations")\r
+ \r
+ #updates for Newton loop\r
+ Uk_Roe += dUk_Roe\r
+ k_Roe = k_Roe + 1\r
+ if (isImplicit and not LS_Roe.getStatus()):\r
+ print("Linear system did not converge ", LS_Roe.getNumberOfIter(), " GMRES iterations")\r
+ raise ValueError("No convergence of the linear system")\r
+ \r
+ if k_Roe == newton_max:\r
+ raise ValueError("No convergence of Newton Roe Scheme")\r
+ \r
+ #updating fields\r
+ Un_Roe = Uk_Roe.deepCopy()\r
+ dUn_Roe -= Un_Roe\r
+ if (dUn_Roe.norm()<precision):\r
+ isStationary = True\r
+ \r
+ for k in range(nbCells):\r
+ rho_field_Roe[k] = Un_Roe[k * nbComp + 0]\r
+ q_field_Roe[k] = Un_Roe[k * nbComp + 1]\r
+ rho_E_field_Roe[k] = Un_Roe[k * nbComp + 2]\r
+ \r
+ v_field_Roe = q_field_Roe / rho_field_Roe\r
+ p_field_Roe = rho_to_p_StiffenedGaz(rho_field_Roe, q_field_Roe, rho_E_field_Roe)\r
+ T_field_Roe = rhoE_to_T_StiffenedGaz(rho_field_Roe, q_field_Roe, rho_E_field_Roe)\r
+ h_field_Roe = (rho_E_field_Roe + p_field_Roe) / rho_field_Roe - 0.5 * (q_field_Roe / rho_field_Roe) **2\r
+ p_field_Roe = p_field_Roe * 10 ** (-5)\r
+ \r
+ if( min(p_field_Roe)<0) :\r
+ raise ValueError("Negative pressure, stopping calculation")\r
+ \r
+ #picture and video updates\r
+ lineDensity_Roe.set_ydata(rho_field_Roe)\r
+ lineMomentum_Roe.set_ydata(q_field_Roe)\r
+ lineRhoE_Roe.set_ydata(h_field_Roe)\r
+ linePressure_Roe.set_ydata(p_field_Roe)\r
+ lineVitesse_Roe.set_ydata(v_field_Roe)\r
+ lineTemperature_Roe.set_ydata(T_field_Roe)\r
+ \r
+ writer.grab_frame()\r
+ \r
+ time = time + dt\r
+ it = it + 1\r
+ \r
+ # Savings\r
+ if (it == 1 or it % output_freq == 0 or it >= ntmax or isStationary or time >= tmax):\r
+ \r
+ print("-- Time step : " + str(it) + ", Time: " + str(time) + ", dt: " + str(dt))\r
+ \r
+ plt.savefig("EulerEquations_RiemannProblem_" + str(dim) + "D_"+ImplicitOrExplicit+"Roe" + meshName + str(it) + '_time' + str(time) + ".png")\r
+\r
+ print("-- Iter: " + str(it) + ", Time: " + str(time) + ", dt: " + str(dt))\r
+ if (it >= ntmax):\r
+ print("Maximum number of time steps ntmax= ", ntmax, " reached")\r
+ return\r
+\r
+ elif (isStationary):\r
+ print("Stationary regime reached at time step ", it, ", t= ", time)\r
+ print("------------------------------------------------------------------------------------")\r
+ np.savetxt("EulerEquations_RiemannProblem_" + str(dim) + "D_"+ImplicitOrExplicit+"Roe" + meshName + "_rho_Stat.txt", rho_field_Roe, delimiter="\n")\r
+ np.savetxt("EulerEquations_RiemannProblem_" + str(dim) + "D_"+ImplicitOrExplicit+"Roe" + meshName + "_q_Stat.txt", q_field_Roe, delimiter="\n")\r
+ np.savetxt("EulerEquations_RiemannProblem_" + str(dim) + "D_"+ImplicitOrExplicit+"Roe" + meshName + "_rhoE_Stat.txt", rho_E_field_Roe, delimiter="\n")\r
+ np.savetxt("EulerEquations_RiemannProblem_" + str(dim) + "D_"+ImplicitOrExplicit+"Roe" + meshName + "_p_Stat.txt", p_field_Roe, delimiter="\n")\r
+ plt.savefig("EulerEquations_RiemannProblem_" + str(dim) + "D_"+ImplicitOrExplicit+"Roe" + meshName + "_Stat.png")\r
+ return\r
+ else:\r
+ print("Maximum time Tmax= ", tmax, " reached")\r
+ return\r
+\r
+\r
+def solve(a, b, nx, meshName, meshType, cfl, state_law, isImplicit):\r
+ print("Resolution of the Euler System in dimension 1 on " + str(nx) + " cells")\r
+ print("State Law Stiffened Gaz, " + state_law)\r
+ print("Initial data : ", "Riemann problem")\r
+ print("Boundary conditions : ", "Neumann")\r
+ print("Mesh name : ", meshName, ", ", nx, " cells")\r
+ # Problem data\r
+ tmax = 10.\r
+ ntmax = 25\r
+ output_freq = 1\r
+ EulerSystemRoe(ntmax, tmax, cfl, a, b, nx, output_freq, meshName, state_law, isImplicit)\r
+ return\r
+\r
+\r
+if __name__ == """__main__""":\r
+ a = 0.\r
+ b = 1.\r
+ nx = 50\r
+ cfl = 0.95\r
+ isImplicit = bool(int(sys.argv[1]))\r
+ #state_law = "Hermite590K"\r
+ #state_law_parameters(state_law)\r
+ solve(a, b, nx, "RegularSquares", "", cfl, state_law, isImplicit)\r