6

I am currently working through Solving Partial Differential Equations with Finite Elements specifically the fluid flow problems. I took the Stokes flow problem and replaced it with Euler's equations as well as the Navier-Stokes equations but the Euler equations are causing issues.

Ω = RegionUnion[Rectangle[{0, 0}, {1, 1/2}], Rectangle[{1, 1/10}, {2, 2/5}]];
RegionPlot[Ω, AspectRatio -> Automatic]

eqnsEuler = {ρ (u[x, y] D[u[x, y], x] + v[x, y] D[u[x, y], y]) + D[p[x, y], x] - μ (D[u[x, y], x, x] + D[u[x, y], y, y]), ρ (u[x, y] D[v[x, y], x] + v[x, y] D[v[x, y], y]) + D[p[x, y], y] - μ (D[v[x, y], x, x] + D[v[x, y], y, y]), D[u[x, y], x] + D[v[x, y], y]} /. {μ -> 0, ρ -> 1};

pde = eqnsEuler == {0, 0, 0};

bcs = {DirichletCondition[{u[x, y] == 40.3y*(0.5 - y)/(0.41)^2, v[x, y] == 0.}, x == 0.], DirichletCondition[{v[x, y] == 0.}, 0 < x < 2], DirichletCondition[p[x, y] == 0., x == 2]};

{xVel, yVel, pressure} = NDSolveValue[{pde, bcs}, {u, v, p}, {x, y} ∈ Ω, Method -> {"FiniteElement", "InterpolationOrder" -> {u -> 2, v -> 2, p -> 1}, "MeshOptions" -> {"MaxCellMeasure" -> 0.0005}}];

Which gives a few errors

InitializePDECoefficients::femcscd: The PDE is convection dominated and the result may not be stable. Adding artificial diffusion may help.

FindRoot::stfail: The method AffineCovariantNewton failed to compute the next step.

FindRoot::sszero: The step size in the search has become less than the tolerance prescribed by the PrecisionGoal option, but the function value is still greater than the tolerance prescribed by the AccuracyGoal option.

So referring to a few posts here on Stack Exchange as well as the documentation on Finite Element best practices and ElementMesh creation I added a mesh.

mesh = ToElementMesh[
  RegionUnion[Rectangle[{0, 0}, {1, 1/2}], 
   Rectangle[{1, 1/10}, {2, 2/5}]], 
  "MaxBoundaryCellMeasure" -> 0.0005, "MaxCellMeasure" -> 0.0005]

which I made really fine keeping in mind that it may cause a long running time. That didn't help.

I also tried defining a refinement region and then using MeshRefinementFunction in NDSolveValue with no luck as well.

With minimal changes to the code I've been successful with both Stokes and Navier-Stokes on different regions, including flow around cylinders etc. However with convection driven flow I am experiencing difficulties. The Stabilization of Convection-Dominated Equations in the above links doesn't help as I:

  1. Do not want to add artificial diffusion
  2. Am not having luck with different meshes (Maybe it's my choice of mesh? Runtime is not much of an issue, I am aiming for minimal changes to original code to compare the methods for the 3 cases)

Are there small changes that will allow the Euler equations to be solvable or do more complex changes need to be made? I am trying to avoid methods similar to what's described here or here

Kendall
  • 363
  • 1
  • 10
  • Are you trying to solve this system of equation using NDSolve with Automatic options? There are standard methods for solving incompressible flows, and these methods are still not programmed into NDSolve. – Alex Trounev Feb 13 '24 at 19:10
  • 1
    Euler equation (and in irregular domain)? I'm not that familiar with static case, but if the eventual goal is dealing with time-dependent case, it'll be troublesome, and even problem in regular domain is hard enough. Related: https://mathematica.stackexchange.com/a/267899/1871 – xzczd Feb 14 '24 at 08:23
  • @AlexTrounev I am aware of the standard methods, I was hoping to achieve it with NDSolve. Any idea why it's not programmed into NDSolve? – Kendall Feb 14 '24 at 14:16
  • @xzczd I am eventually moving to time-dependent cases yes. So it appears the only work around is to add artificial viscosity? – Kendall Feb 14 '24 at 14:19
  • @Kendall To be precise, the easiest work-around. More stable but advanced approaches are, as shown in the link above, turning to the packages in other languages in e.g. julia or python using ExternalEvaluate, or coding our own solver. "Any idea why it's not programmed into NDSolve?" Who knows, perhaps it's just too hard. – xzczd Feb 14 '24 at 14:54
  • The reason it's not programmed into NDSolve is that for convection dominated problems you have to use some form of artificial diffusion for FEM and FEM is NDSolve's way to work on non uniform regions. But as xzczd correctly points out even for FDM, you'd need something to stabilize it, Maybe ENO or WENO. – user21 Feb 14 '24 at 15:40
  • Concerning learning, what would you be looking for? Are the monographs that come with Mathematica not useful, to specific or something else? – user21 Feb 14 '24 at 15:42
  • @user21 My field of expertise is reducing the Reynolds Averaged Navier-Stokes to ODEs and getting analytic solutions. For more complex flow geometries I need to move to numerical techniques and so I am starting to self study that. Some users here just seem to "know" how to approach the problem and what Mathematica can and can't do with built in functions. I am sure this is a product of experience but perhaps there are useful resources that others have used that may be useful, esp. for fluid mechanics. – Kendall Feb 16 '24 at 10:35
  • @Kendall, there is a monograph on Laminar Flow that shows the scope of things in the laminar regime. If you find things that are unclear let me know and I'll try to improve them. I'd be very interested in the outcome of your research and I'd appreciate if you ping me once you have come to a conclusion. If you need information about RANS, contact me. – user21 Feb 20 '24 at 06:15
  • @user21 Thank you, that link is very useful. I'll make sure to reach out. – Kendall Feb 25 '24 at 09:14

1 Answers1

1

To be realistic, we can make boundary conditions as for inviscid flow and save small $\mu =10^{-3}$ to use FEM and NDSolve as it is, we have

Needs["NDSolve`FEM`"]

mesh = ToElementMesh[ RegionUnion[Rectangle[{0, 0}, {1, 1/2}], Rectangle[{1, 1/10}, {2, 2/5}]], "MaxBoundaryCellMeasure" -> .01, "MaxCellMeasure" -> 5 10^-4];

mesh["Wireframe"]

eqnsEuler = {[Rho] (u[x, y] D[u[x, y], x] + v[x, y] D[u[x, y], y]) + D[p[x, y], x] - [Mu] (D[u[x, y], x, x] + D[u[x, y], y, y]), [Rho] (u[x, y] D[v[x, y], x] + v[x, y] D[v[x, y], y]) + D[p[x, y], y] - [Mu] (D[v[x, y], x, x] + D[v[x, y], y, y]), D[u[x, y], x] + D[v[x, y], y]} /. {[Mu] -> 10^-3, [Rho] -> 1};

pde = eqnsEuler == {0, 0, 0};

bcs = {DirichletCondition[{u[x, y] == 1, v[x, y] == 0.}, x == 0.], DirichletCondition[{v[x, y] == 0.}, 0 < x < 1 || 1 < x < 2], DirichletCondition[{u[x, y] == 0.}, x == 1 && 0 <= y <= 1/10 || 2/5 <= y <= 1/2], DirichletCondition[{p[x, y] == 0., v[x, y] == 0}, x == 2]};

{xVel, yVel, pressure} = NDSolveValue[{pde, bcs}, {u, v, p}, {x, y} [Element] mesh, Method -> {"FiniteElement", "InterpolationOrder" -> {u -> 2, v -> 2, p -> 1}}];

Visualization

Show[DensityPlot[
  Norm[{xVel[x, y], yVel[x, y]}], {x, y} \[Element] mesh, 
  ColorFunction -> "AvocadoColors", AspectRatio -> Automatic, 
  PlotPoints -> 50, PlotLegends -> Automatic], 
 StreamPlot[{xVel[x, y], yVel[x, y]}, {x, y} \[Element] mesh, 
  StreamColorFunction -> Hue]]

Figure1

It is interesting, that flow is nonsymmetric around axis y=0.25. The reason is not clear. Probably mesh is not symmetric.

Alex Trounev
  • 44,369
  • 3
  • 48
  • 106
  • Thank you Alex, it seems I cannot avoid using an artificial diffusion? I've actually come across a few of your answers here on Stack Exchange that have been very helpful. How did you learn what you know? Can you recommend some resources please. – Kendall Feb 14 '24 at 14:21
  • 2
    It's much, much easier and much less error prone to just use the operator to generate the equations: vars = {{u[x, y], v[x, y], p[x, y]}, {x, y}}; pars = <|"DynamicViscosity" -> 10^-3, "MassDensity" -> 1|>; eqnsEuler = FluidFlowPDEComponent[vars, pars] You'd get the Euler equations for a DynamicViscosity of 0. But we currently can not solve them, unless you add artificial diffusion. Here are some tips for that. – user21 Feb 14 '24 at 15:50
  • @Kendall We use artificial diffusion even for Euler equations in a case of compressible flow as well, see for example https://mathematica.stackexchange.com/questions/287067/code-for-quasi-1d-nozzle-flows – Alex Trounev Feb 14 '24 at 15:52
  • @AlexTrounev Thank you Alex that is very helpful. It just makes comparing 2 solutions difficult where the only thing you can alter is the boundary conditions. I'll definitely do more reading up on this. – Kendall Feb 14 '24 at 17:33
  • @Kendall You are welcome! – Alex Trounev Feb 14 '24 at 20:11
  • 2
    @AlexTrounev The solution to the nonsymmetric part was bugging me so I played around a bit. It's due to how Mathematica is interpreting the boundary condition as well as the mesh.DirichletCondition[{u[x, y] == 0.}, x == 1 && 0 <= y <= 1/10 || 2/5 <= y <= 1/2]

    Adding brackets resolves the issue and the solution becomes symmetric. DirichletCondition[{u[x, y] == 0.}, x == 1 && (0 <= y <= 1/10 || 2/5 <= y <= 1/2)]

    I also decreased the "MaxBoundaryCellMeasure" -> .001, "MaxCellMeasure" -> 10^-4

    – Kendall Feb 16 '24 at 16:15
  • 1
    @Kendall Thank you very much for your efforts. This update works fine. – Alex Trounev Feb 16 '24 at 18:33