Skip to main content
edited tags
Link
user21
  • 40.7k
  • 8
  • 114
  • 170
Source Link
Avrana
  • 297
  • 1
  • 4
  • 14

Some conceptual doubts about steady and transient solvers of the NS + energy equations

Recently, I have been solving some transient and steady, flow and heat transfer problems in Mathematica. The transient problem is essentially the reciprocating (i.e., fully reversing) flow of a fluid over a thick heated block until the system reaches a cyclic steady-state (i.e., the system temperature oscillates around a mean when this point is reached). I received help regarding this in one of my earlier question on this site. Following is the code:

Needs["NDSolve`FEM`"]

{f = 0.5; L = 0.040, d = 0.003, e = 0.005, kf = 0.026499, ks = 16, 
 rho = 1.1492, rhos = 7860, mu = 18.923*10^-6, cp = 1.0069*10^3, 
 cps = 502.4}; u0 = 3; nu = mu/rho; om = 2 Pi f;
tflow = 100;
t0 = .3;
NV = 2 f tflow;
nn = Round[NV \[Pi]/(om t0)]
Ti = 307; q = 1000/Ti;

reg1 = ImplicitRegion[0 <= x <= L && 0 <= y <= d, {x, y}]; reg2 = 
 ImplicitRegion[0 <= x <= L && -e <= y <= d, {x, y}];
UX[0][x_, y_] := 0;
VY[0][x_, y_] := 0;
P[0][x_, y_] := 0;
Tfs[0][x_, y_] := 307/Ti; appro = 
 With[{k = 2. 10^6}, ArcTan[k #]/Pi + 1/2 &];
ade[y_] := (ks + (kf - ks) appro[y])
rde[y_] := (cps rhos + (cp rho - cps rhos) appro[y]);

Monitor[Do[{UX[i], VY[i], P[i]} = 
    NDSolveValue[{{Inactive[
            Div][({{-\[Mu], 0}, {0, -\[Mu]}}.Inactive[Grad][
              u[x, y], {x, y}]), {x, y}] + D[p[x, y], x] + 
          UX[i - 1][x, y]*D[u[x, y], x] + 
          VY[i - 1][x, y]*D[u[x, y], y] + (u[x, y] - UX[i - 1][x, y])/
           t0, Inactive[
            
            Div][({{-\[Mu], 0}, {0, -\[Mu]}}.Inactive[Grad][
              v[x, y], {x, y}]), {x, y}] + D[p[x, y], y] + 
          UX[i - 1][x, y]*D[v[x, y], x] + 
          VY[i - 1][x, y]*D[v[x, y], y] + (v[x, y] - VY[i - 1][x, y])/
           t0, D[u[x, y], x] + D[v[x, y], y]} == {0, 0, 0} /. \[Mu] ->
         nu, {DirichletCondition[{u[x, y] == u0*Sin[om*i*t0], 
         v[x, y] == 0}, 
        x == L (1 - Sign[Sin[om*i*t0]])/2 && 0 < y < d], 
       DirichletCondition[{u[x, y] == 0, v[x, y] == 0}, 
        y == 0 || y == d]}, 
      DirichletCondition[p[x, y] == 0, 
       x == L (1 + Sign[Sin[om*i*t0]])/2 && 0 < y < d]}, {u, v, 
      p}, {x, y} \[Element] reg1, 
     Method -> {"FiniteElement", 
       "InterpolationOrder" -> {u -> 2, v -> 2, p -> 1}, 
       "MeshOptions" -> {"MaxCellMeasure" -> 0.0000005}}];
   ux = If[y <= 0, 0, UX[i][x, y]]; vy = If[y <= 0, 0, VY[i][x, y]];
   Tfs[i] = 
    NDSolveValue[{rde[
           y] ((ux*D[T[x, y], x] + 
              vy*D[T[x, y], y]) + (T[x, y] - Tfs[i - 1][x, y])/t0) - 
         Inactive[Div][
          ade[y]*Inactive[Grad][T[x, y], {x, y}], {x, y}] == 
        NeumannValue[q, y == -e], 
       DirichletCondition[{T[x, y] == 1}, 
        x == L (1 - Sign[Sin[om*i*t0]])/2 && 0 <= y <= d]}, 
      T, {x, y} \[Element] reg2, 
      Method -> {"FiniteElement", "InterpolationOrder" -> {T -> 2}, 
        "MeshOptions" -> {"MaxCellMeasure" -> 0.0000001}}] // 
     Quiet;, {i, 1, nn}],ProgressIndicator[i,{1,nn}]]; // AbsoluteTiming

ListLinePlot[
 Table[{i t0, Tfs[i][0.5*L, -e/2]*Ti - 273.16}, {i, 0, nn}], 
 AxesLabel -> {"t(s)", "T(K)"}, PlotRange -> Full]

The above code runs the simulation for 100s flow-time for a flow oscillating with a frequency of 0.5Hz using the velocity profile $u = 3\sin(2*\pi*0.5*t)$. As can be seen in the above code the Do loop marches forward in time. Inside the loop the flow and temperature field is being solved at each iteration nn.

I modified the above code for a uni-directional flow, i.e., find a steady-state solution for a flow from left to right over the heated block. I removed the time-dependent terms inside the loop and the nn, instead of a time-stepper becomes an iterator to reach a converged solution. The code is:

Needs["NDSolve`FEM`"]

{f = 0.5; L = 0.040, d = 0.003, e = 0.005, kf = 0.026499, ks = 16, 
 rho = 1.1492, rhos = 7860, mu = 18.923*10^-6, cp = 1.0069*10^3, 
 cps = 502.4}; u0 = 3; nu = mu/rho; om = 2 Pi f;
Ti = 307; q = 1000/Ti;
uavg = (1/(Pi/om)) Integrate[u0*Sin[om*t], {t, 0, Pi/om}] // N
nn = 10;

reg1 = ImplicitRegion[0 <= x <= L && 0 <= y <= d, {x, y}]; reg2 = 
 ImplicitRegion[0 <= x <= L && -e <= y <= d, {x, y}];
UX[0][x_, y_] := 0;
VY[0][x_, y_] := 0;
P[0][x_, y_] := 0;
Tfs[0][x_, y_] := 307/Ti; appro = 
 With[{k = 2. 10^6}, ArcTan[k #]/Pi + 1/2 &];
ade[y_] := (ks + (kf - ks) appro[y])
rde[y_] := (cps rhos + (cp rho - cps rhos) appro[y]);

Do[{UX[i], VY[i], P[i]} = 
    NDSolveValue[{{Inactive[
            Div][({{-\[Mu], 0}, {0, -\[Mu]}}.Inactive[Grad][
              u[x, y], {x, y}]), {x, y}] + D[p[x, y], x] + 
          UX[i - 1][x, y]*D[u[x, y], x] + 
          VY[i - 1][x, y]*D[u[x, y], y], 
         Inactive[
            Div][({{-\[Mu], 0}, {0, -\[Mu]}}.Inactive[Grad][
              v[x, y], {x, y}]), {x, y}] + D[p[x, y], y] + 
          UX[i - 1][x, y]*D[v[x, y], x] + 
          VY[i - 1][x, y]*D[v[x, y], y], 
         D[u[x, y], x] + D[v[x, y], y]} == {0, 0, 0} /. \[Mu] -> 
        nu, {DirichletCondition[{u[x, y] == uavg, v[x, y] == 0}, 
        x == 0 && 0 < y < d], 
       DirichletCondition[{u[x, y] == 0, v[x, y] == 0}, 
        y == 0 || y == d]}, 
      DirichletCondition[p[x, y] == 0, x == L && 0 < y < d]}, {u, v, 
      p}, {x, y} \[Element] reg1, 
     Method -> {"FiniteElement", 
       "InterpolationOrder" -> {u -> 2, v -> 2, p -> 1}, 
       "MeshOptions" -> {"MaxCellMeasure" -> 0.0000005}}];
   ux = If[y <= 0, 0, UX[i][x, y]]; vy = If[y <= 0, 0, VY[i][x, y]];
   Tfs[i] = 
    NDSolveValue[{rde[y] ((ux*D[T[x, y], x] + vy*D[T[x, y], y])) - 
         Inactive[Div][
          ade[y]*Inactive[Grad][T[x, y], {x, y}], {x, y}] == 
        NeumannValue[q, y == -e], 
       DirichletCondition[{T[x, y] == 1}, x == 0 && 0 <= y <= d]}, 
      T, {x, y} \[Element] reg2, 
      Method -> {"FiniteElement", "InterpolationOrder" -> {T -> 2}, 
        "MeshOptions" -> {"MaxCellMeasure" -> 0.0000001}}] // 
     Quiet;, {i, 1, nn}]; // AbsoluteTiming

My question is:

Why do we need an iterator to reach a steady-state solution?

In other words, the time-dependent code solved for the flow and temperature field at each time-step (but within each time-step there seemed to be no need for further iterations to reach a converged solution). Going by that logic, NDSolve should have been able to directly solve for the steady-state solution (i.e, without the time-dependent terms), but it cannot as I tried below:

{U, V, P} = 
 NDSolveValue[{{Inactive[
         Div][({{-\[Mu], 0}, {0, -\[Mu]}}.Inactive[Grad][
           u[x, y], {x, y}]), {x, y}] + D[p[x, y], x] + 
       u[x, y]*D[u[x, y], x] + v[x, y]*D[u[x, y], y], 
      Inactive[
         Div][({{-\[Mu], 0}, {0, -\[Mu]}}.Inactive[Grad][
           v[x, y], {x, y}]), {x, y}] + D[p[x, y], y] + 
       u[x, y]*D[v[x, y], x] + v[x, y]*D[v[x, y], y], 
      D[u[x, y], x] + D[v[x, y], y]} == {0, 0, 0} /. \[Mu] -> 
     nu, {DirichletCondition[{u[x, y] == uavg, v[x, y] == 0}, 
     x == 0 && 0 < y < d], 
    DirichletCondition[{u[x, y] == 0, v[x, y] == 0}, 
     y == 0 || y == d]}, 
   DirichletCondition[p[x, y] == 0, x == L && 0 < y < d]}, {u, v, 
   p}, {x, y} \[Element] reg1, 
  Method -> {"FiniteElement", 
    "InterpolationOrder" -> {u -> 2, v -> 2, p -> 1}, 
    "MeshOptions" -> {"MaxCellMeasure" -> 0.0000005}

I would like to have a descriptive explanation of this difference between modelling a transient system and a steady-state solution? In essence, why within each time-step in the transient solver there is no need of iteration ? However, a steady-state solution requires one to iterate. I hope I could clearly explain my query.