Skip to main content

finite element method - Solving Navier-Stokes equations for a steady-state compressible viscous flow in a 2D axisymmetric step


Note: you may apply or follow the edits on the code here in this GitHub Gist


I'm trying to follow this post to solve Navier-Stokes equations for a compressible viscous flow in a 2D axisymmetric step. The geometry is :


enter image description here



lc = 0.03;
rc = 0.01;
xp = 0.01;
c = 0.005;
rp = rc - c;
lp = lc - xp;
Subscript[T, 0] = 300;
Subscript[\[Eta], 0] = 1.846*10^-5;
Subscript[P, 1] = 6*10^5 ;
Subscript[P, 0] = 10^5;

Subscript[c, P] = 1004.9;
Subscript[c, \[Nu]] = 717.8;
Subscript[R, 0] = Subscript[c, P] - Subscript[c, \[Nu]];
\[CapitalOmega] = RegionDifference[
Rectangle[{0, 0}, {lc, rc}],
Rectangle[{xp, 0}, {xp + lp, rp}]];

And meshing:


Needs["NDSolve`FEM`"];
mesh = ToElementMesh[\[CapitalOmega],

"MaxBoundaryCellMeasure" -> 0.00001,
MaxCellMeasure -> {"Length" -> 0.0008},
"MeshElementConstraint" -> 20, MeshQualityGoal -> "Maximal"][
"Wireframe"]

enter image description here


Where the model is axisymmetric around the x axis, the governing equations including conservation equations of mass, momentum and heat can be written as:


x(ρνx)+1rr(rρνr)=0


x(ρν2x+˚RρT)+1rr(r(ρνrνx+ηνxr))


x(ρνxνr+ηνrx)+1rr(r(ρν2r+˚RρT))=0



ρcν(νxTx+νrTr)+˚RρT(1rr(rνr)+νxx)+η(2(νxx)2+2(νrr)2+(νrx+νxr)223(1rr(rνr)+νxx)2)=0


eqn1 = D[\[Rho][x, r]*Subscript[\[Nu], x][x, r], x] + 
D[r*\[Rho][x, r]*Subscript[\[Nu], r][x, r], r]/r == 0 ;
eqn2 = D[\[Rho][x, r]*Subscript[\[Nu], x][x, r]^2 +
Subscript[R, 0] \[Rho][x, r]*T[x, r], x] +
D[r*(\[Rho][x, r]*Subscript[\[Nu], x][x, r]*
Subscript[\[Nu], r][x, r] +
Subscript[\[Eta], 0]*D[Subscript[\[Nu], x][x, r], r]), r]/
r == 0 ;
eqn3 = D[\[Rho][x, r]*Subscript[\[Nu], x][x, r]*

Subscript[\[Nu], r][x, r] +
Subscript[\[Eta], 0]*D[Subscript[\[Nu], r][x, r], x], x] +
D[r*(\[Rho][x, r]*Subscript[\[Nu], r][x, r]^2 +
Subscript[R, 0] \[Rho][x, r]*T[x, r]), r]/r == 0;
eqn4 = Subscript[
c, \[Nu]]*\[Rho][x,
r]*(Subscript[\[Nu], x][x, r]*D[T[x, r], x] +
Subscript[\[Nu], r][x, r]*D[T[x, r], r]) +
Subscript[R, 0]*\[Rho][x, r]*
T[x, r]*(D[Subscript[\[Nu], x][x, r], x] +

D[r*Subscript[\[Nu], r][x, r], x]/r) + (2*
D[Subscript[\[Nu], x][x, r], x]^2 +
2*D[Subscript[\[Nu], r][x, r],
r]^2 + (D[Subscript[\[Nu], x][x, r], r] +

D[Subscript[\[Nu], r][x, r],
x])^2 - ((D[Subscript[\[Nu], x][x, r], x] +
D[r*Subscript[\[Nu], r][x, r], x]/r)^2)*2/3)*
Subscript[\[Eta], 0] == 0;
eqns = {eqn1, eqn2, eqn3, eqn4};


And the boundary conditions are:



  1. constant pressure at inlet

  2. constant pressure at outlet

  3. axis of symmetry

  4. no slip


Implemented as


bc1 = Subscript[R, 0] \[Rho][0, r]*Subscript[T, 0] == Subscript[P, 1] 

bc2 = Subscript[R, 0] \[Rho][lc, r]*Subscript[T, 0] == Subscript[P, 0]
bc3 = DirichletCondition[{Subscript[\[Nu], r][x, 0] == 0,
D[Subscript[\[Nu], r][x, r], r] == 0,
D[Subscript[\[Nu], x][x, r], r] == 0, D[\[Rho][x, r], r] == 0,
D[T[x, r], r] == 0}, r == 0 && (0 <= x <= xp )]
bc4 = DirichletCondition[{Subscript[\[Nu], r][x, r] == 0,
Subscript[\[Nu], x][x, r] ==
0}, (0 <= r <= rp && x == xp ) || (r == rp &&
xp <= x <= xp + lp) || (r == rc && 0 <= x <= lc) ] == 0
bcs = {bc1, bc2, bc3, bc4};


When I try to solve the equations:


{\[Nu]xsol, \[Nu]rsol, \[Rho]sol, Tsol} = 
NDSolveValue[{eqns, , bcs}, {Subscript[\[Nu], x], Subscript[\[Nu],
r], \[Rho], T}, {x, r} \[Element] mesh,
Method -> {"FiniteElement",
"InterpolationOrder" -> {Subscript[\[Nu], x] -> 2,
Subscript[\[Nu], r] -> 2, \[Rho] -> 1, T -> 1},
"IntegrationOrder" -> 5}];


I get the errors:



NDSolveValue::femnr: {x,r}[Element] is not a valid region specification.



and



Set::shape: Lists {[Nu]xsol,[Nu]rsol,Tsol,[Rho]sol} and NDSolveValue[<<1>>] are not the same shape.



Googling the errors does not offer that much of help (e.g. here). I would appreciate if you could help me know What is the issue and how I can solve it.


P.S.1. The NDSolveValue femnr error was caused by [ "Wireframe"] term at the end of meshing command changing it to



mesh = ToElementMesh[\[CapitalOmega], 
"MaxBoundaryCellMeasure" -> 0.00001,
MaxCellMeasure -> {"Length" -> 0.0008},
"MeshElementConstraint" -> 20, MeshQualityGoal -> "Maximal"];
mesh["Wireframe"]

resolves the issue.


P.S.2. There is an extra ==0 at the end of boundary condition 4 it was edited to:


bc4 = DirichletCondition[{Subscript[\[Nu], r][x, r] == 0, 
Subscript[\[Nu], x][x, r] ==

0}, (0 <= r <= rp && x == xp) || (r == rp &&
xp <= x <= xp + lp) || (r == rc && 0 <= x <= lc)];

at this moment the second error still persists and a new error was added:



NDSolveValue::deqn Equation or list of equations expected instead of Null in the first argument ...



P.S.3 There were multiple issues. So I decided to use this Github Gist to further edit the code.




Comments

Popular posts from this blog

functions - Get leading series expansion term?

Given a function f[x] , I would like to have a function leadingSeries that returns just the leading term in the series around x=0 . For example: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x)] x and leadingSeries[(1/x + 2 + (1 - 1/x^3)/4)/(4 + x)] -(1/(16 x^3)) Is there such a function in Mathematica? Or maybe one can implement it efficiently? EDIT I finally went with the following implementation, based on Carl Woll 's answer: lds[ex_,x_]:=( (ex/.x->(x+O[x]^2))/.SeriesData[U_,Z_,L_List,Mi_,Ma_,De_]:>SeriesData[U,Z,{L[[1]]},Mi,Mi+1,De]//Quiet//Normal) The advantage is, that this one also properly works with functions whose leading term is a constant: lds[Exp[x],x] 1 Answer Update 1 Updated to eliminate SeriesData and to not return additional terms Perhaps you could use: leadingSeries[expr_, x_] := Normal[expr /. x->(x+O[x]^2) /. a_List :> Take[a, 1]] Then for your examples: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x), x] leadingSeries[Exp[x], x] leadingSeries[(1/x + 2 + (1 - 1/x...

mathematical optimization - Minimizing using indices, error: Part::pkspec1: The expression cannot be used as a part specification

I want to use Minimize where the variables to minimize are indices pointing into an array. Here a MWE that hopefully shows what my problem is. vars = u@# & /@ Range[3]; cons = Flatten@ { Table[(u[j] != #) & /@ vars[[j + 1 ;; -1]], {j, 1, 3 - 1}], 1 vec1 = {1, 2, 3}; vec2 = {1, 2, 3}; Minimize[{Total@((vec1[[#]] - vec2[[u[#]]])^2 & /@ Range[1, 3]), cons}, vars, Integers] The error I get: Part::pkspec1: The expression u[1] cannot be used as a part specification. >> Answer Ok, it seems that one can get around Mathematica trying to evaluate vec2[[u[1]]] too early by using the function Indexed[vec2,u[1]] . The working MWE would then look like the following: vars = u@# & /@ Range[3]; cons = Flatten@{ Table[(u[j] != #) & /@ vars[[j + 1 ;; -1]], {j, 1, 3 - 1}], 1 vec1 = {1, 2, 3}; vec2 = {1, 2, 3}; NMinimize[ {Total@((vec1[[#]] - Indexed[vec2, u[#]])^2 & /@ R...

What is and isn't a valid variable specification for Manipulate?

I have an expression whose terms have arguments (representing subscripts), like this: myExpr = A[0] + V[1,T] I would like to put it inside a Manipulate to see its value as I move around the parameters. (The goal is eventually to plot it wrt one of the variables inside.) However, Mathematica complains when I set V[1,T] as a manipulated variable: Manipulate[Evaluate[myExpr], {A[0], 0, 1}, {V[1, T], 0, 1}] (*Manipulate::vsform: Manipulate argument {V[1,T],0,1} does not have the correct form for a variable specification. >> *) As a workaround, if I get rid of the symbol T inside the argument, it works fine: Manipulate[ Evaluate[myExpr /. T -> 15], {A[0], 0, 1}, {V[1, 15], 0, 1}] Why this behavior? Can anyone point me to the documentation that says what counts as a valid variable? And is there a way to get Manpiulate to accept an expression with a symbolic argument as a variable? Investigations I've done so far: I tried using variableQ from this answer , but it says V[1...