6
$\begingroup$

I am trying to solve the convection-coupled melting benchmark in MMA 12.3 as presented in FEniCS/03-ConvectionCoupledMelting-MixedElement-AMR.ipynb. This model in MMA is based on the solution from user21 and energy-transport. In the simulation, "Matrix SparseArray is singular" problem cannot be solved. The final solution may look like this:

enter image description here (see reference 1)

This notebook shows

Needs["NDSolve`FEM`"]

sizes = {length -> 1, hight -> 1};
\[CapitalOmega] = Rectangle[{0, 0}, {length, hight}] /. sizes;


\[Phi][temp_, tr_, r_] := 1/2 (1 + Tanh[(tr - temp)/r])

Plot[\[Phi][T, 0.01, 0.025], {T, -0.6, 0.6}, PlotRange -> All]

tvars = {T[t, x, y], t, {x, y}};
regParam = 0.025;
steNr = 0.045;
Tnr = 0.01;
pars = <|"MassDensity" -> 1, "SpecificHeatCapacity" -> 1, 
   "ThermalConductivity" -> 1/Pr*IdentityMatrix[2], 
   "HeatConvectionVelocity" -> {u[t, x, y], v[t, x, y]}, 
   "HeatSource" -> (1/steNr)*\[Phi][T[t, x, y], Tnr , regParam]|>;
TransientHeatModel = HeatTransferPDEComponent[tvars, pars];


muL = 1.0;
muS = 10^8;

\[Mu][muL_, muS_, phi_] := muL + (muS - muL)*phi;

CFDModel = {
   
\!\(\*SuperscriptBox[\(u\), 
TagBox[
RowBox[{"(", 
RowBox[{"1", ",", "0", ",", "0"}], ")"}],
Derivative],
MultilineFunction->None]\)[t, x, 
     y] + \[Mu][muL, muS, \[Phi][T[t, x, y], Tnr, regParam]]*
     Inactive[Div][(-\[Nu] Inactive[Grad][u[t, x, y], {x, y}]), {x, 
       y}] + {u[t, x, y], v[t, x, y]} . 
     Inactive[Grad][u[t, x, y], {x, y}] + 
\!\(\*SuperscriptBox[\(p\), 
TagBox[
RowBox[{"(", 
RowBox[{"0", ",", "1", ",", "0"}], ")"}],
Derivative],
MultilineFunction->None]\)[t, x, y], 
   
\!\(\*SuperscriptBox[\(v\), 
TagBox[
RowBox[{"(", 
RowBox[{"1", ",", "0", ",", "0"}], ")"}],
Derivative],
MultilineFunction->None]\)[t, x, 
     y] + \[Mu][muL, muS, \[Phi][T[t, x, y], Tnr, regParam]]*
     Inactive[Div][(-\[Nu] Inactive[Grad][v[t, x, y], {x, y}]), {x, 
       y}] + {u[t, x, y], v[t, x, y]} . 
     Inactive[Grad][v[t, x, y], {x, y}] + 
\!\(\*SuperscriptBox[\(p\), 
TagBox[
RowBox[{"(", 
RowBox[{"0", ",", "0", ",", "1"}], ")"}],
Derivative],
MultilineFunction->None]\)[t, x, y] - Ra/Pr*T[t, x, y], 
   
\!\(\*SuperscriptBox[\(u\), 
TagBox[
RowBox[{"(", 
RowBox[{"0", ",", "1", ",", "0"}], ")"}],
Derivative],
MultilineFunction->None]\)[t, x, y] + 
\!\(\*SuperscriptBox[\(v\), 
TagBox[
RowBox[{"(", 
RowBox[{"0", ",", "0", ",", "1"}], ")"}],
Derivative],
MultilineFunction->None]\)[t, x, y]};


parameters = {\[Nu] -> 1, Pr -> 56.2, Ra -> 327000.0};

tHot = 1.0;
tCold = -0.01;
ics = T[0, x, y] == 
   With[{tHot = tHot, tCold = tCold, tMeltThickness = 0.1}, 
    If[x < tMeltThickness, tHot, tCold]];
icuvp = {u[0, x, y] == 0, v[0, x, y] == 0, p[0, x, y] == 0};

Subscript[\[CapitalGamma], 
  temp] = {HeatTemperatureCondition[x == 0, tvars, 
    pars, <|"SurfaceTemperature" -> tHot|>],
   HeatTemperatureCondition[x == 1, tvars, 
    pars, <|"SurfaceTemperature" -> tCold|>]};
Subscript[\[CapitalGamma], wall] = 
  DirichletCondition[{u[t, x, y] == 0, v[t, x, y] == 0}, True];
Subscript[\[CapitalGamma], p] = 
  DirichletCondition[p[t, x, y] == 0, x == 0 && y == 0];

bcs = {Subscript[\[CapitalGamma], wall], Subscript[\[CapitalGamma], 
   p], Subscript[\[CapitalGamma], temp]};

pde =
  {CFDModel == {0, 0, 0}, TransientHeatModel == 0, bcs, ics, 
    icuvp} /. parameters;

tEnd = 0.001;


{uVel, vVel, pressure, Tfun} = 
  NDSolveValue[
   pde, {u, v, p, T}, {t, 0, 
    tEnd}, {x, y} \[Element] \[CapitalOmega], Method -> {
     "PDEDiscretization" -> {"MethodOfLines",
       "SpatialDiscretization" -> {"FiniteElement", 
         "MeshOptions" -> {"MaxCellMeasure" -> 0.0001}, 
         "InterpolationOrder" -> {u -> 2, v -> 2, p -> 1, T -> 2}}}}];

Your help would be much appreciated!

Remark:

1.) do we have time increments problem in this model? To debug the code, tEnd = 0.001 is already chosen in the original model (tEnd means the total time).

2.) energy-transport model has linear parameters in CFD model, in our case we have nonlinear term (\mu) in CFD model.

3.) (Very) fine mesh is used in this benchmark test, since the adaptive mesh is applied (Fenics solver).

[enter image description here] (see reference 1)

Updates:

1.) MeshOptions

If we test the model from AlexTrounev, we can find the following error in case we set: "MeshOptions" -> {"MaxCellMeasure" -> 0.001}

enter image description here

If we set "MeshOptions" -> {"MaxCellMeasure" -> 0.0001}

enter image description here

Thus, a numerical issue still remains in this post, namely, why we cannot use very fine mesh (e.g. {"MaxCellMeasure" -> 0.0001}) for modeling convection-coupled melting in Mathematica 12.3.

Reference:

Zimmerman, Alexander & Kowalski, Julia. (2018). Monolithic Simulation of Convection-Coupled Phase-Change: Verification and Reproducibility: Proceedings of the 4th International Conference on Computational Engineering (ICCE 2017) in Darmstadt. 10.1007/978-3-319-93891-2_11.

$\endgroup$
14
  • 1
    $\begingroup$ Concerning your remark, no you can mix and match PDEComponents with other forms of PDEs to your hearts content. The purpose of the xyzPDEComponents and xyzPDETerms is to make it easier to set up equations. Since in V13. there is not CFDPDEComponent or such you have to use the standard way to set up the equations. $\endgroup$
    – user21
    Commented Dec 8, 2021 at 14:34
  • $\begingroup$ Unfortunately, I have other things to attend to so I can not look at this in more detail now, perhaps in a few days. $\endgroup$
    – user21
    Commented Dec 8, 2021 at 14:34
  • $\begingroup$ Can you share a PDF of the referenced document? $\endgroup$
    – user21
    Commented Dec 9, 2021 at 6:02
  • 1
    $\begingroup$ @user21 There is one paper in open access on arxiv.org/pdf/1801.03429.pdf $\endgroup$ Commented Dec 9, 2021 at 6:51
  • $\begingroup$ @AlexTrounev, thanks, this the link is already very useful. I could swear that when I looked at the ref yesterday the ipynb did not render; it does now so I can see what is going on. $\endgroup$
    – user21
    Commented Dec 9, 2021 at 8:18

1 Answer 1

6
$\begingroup$

This problem can be solved with using method described on my page. We set timestep dt=10 same as used in Python code on https://github.com/geo-fluid-dynamics/phaseflow-fenics/blob/master/tutorials/FEniCS/03-ConvectionCoupledMelting-MixedElement-AMR.ipynb

Needs["NDSolve`FEM`"]

sizes = {length -> 1, hight -> 1};
\[CapitalOmega] = Rectangle[{0, 0}, {length, hight}] /. sizes;



\[Phi][temp_, tr_, r_] := 1/2 (1 + Tanh[(tr - temp)/r])

Plot[\[Phi][T, 0.01, 0.025], {T, -0.6, 0.6}, PlotRange -> All]

tvars = {T[t, x, y], t, {x, y}};
regParam = 0.025;
steNr = 0.045;
Tnr = 0.01;
muL = 1.0;
muS = 10^8;

\[Mu][muL_, muS_, phi_] := muL + (muS - muL)*phi;
dt = 10;
pde = Inactivate[{
    (u[ x, y] - Us[i - 1][x, y])/dt + 
          
     Div[\[Mu][muL, 
        muS, \[Phi][T[x, y], Tnr, 
         regParam]]*(-\[Nu] Grad[u[x, y], {x, y}]), {x, 
              y}] + {u[x, y], v[x, y]} . 
           Grad[u[x, y], {x, y}] + 
     D[p[x, y], x], 
       
    ( v[ x, y] - Vs[i - 1][x, y])/dt +
          
     Div[ \[Mu][muL, 
        muS, \[Phi][T[x, y], Tnr, 
         regParam]]*(-\[Nu] Grad[v[x, y], {x, y}]), {x, 
              y}] + {u[x, y], v[ x, y]} . 
           Grad[v[x, y], {x, y}] + 
     D[p[x, y], y] - Ra/Pr*T[x, y], 
       
    D[u[x, y], x] + 
     D[v[ x, y], y], (T[ x, y] - Ts[i - 1][x, y])/dt + 
     Div[{u[x, y], v[x, y]} T[x, y], {x, y}] - 
     1/Pr Laplacian[T[x, y], {x, y}] - 
     1/steNr (\[Phi][T[x, y], Tnr , regParam] - \[Phi][
          Ts[i - 1][x, y], Tnr , regParam])/dt}, 
   D | Grad | Laplacian | Div];


parameters = {\[Nu] -> 1, Pr -> 56.2, Ra -> 327000.0};

tHot = 1.0;
tCold = -0.01; tMeltThickness = 0.05;
appro = With[{k = 2. 10^4}, ArcTan[k #]/Pi + 1/2 &];
tin = Simplify`PWToUnitStep@
    PiecewiseExpand@If[x < tMeltThickness, tHot, tCold] /. 
   UnitStep -> appro;
Ts[0][ x_, y_] := 
  Simplify`PWToUnitStep@
    PiecewiseExpand@If[x < tMeltThickness, tHot, tCold] /. 
   UnitStep -> appro;
Us[0][x_, y_] := 0; Vs[0][ x_, y_] := 0; Ps[0][ x_, y_] := 0;

Subscript[\[CapitalGamma], 
     temp] = {DirichletCondition[T[x, y] == tHot, x == 0],
      DirichletCondition[T[x, y] == tCold, x == 1]};
Subscript[\[CapitalGamma], wall] = 
    DirichletCondition[{u[x, y] == 0, v[x, y] == 0}, True];
Subscript[\[CapitalGamma], p] = 
    DirichletCondition[p[ x, y] == Ps[0][x, y], x == 0 && y == 0];

bcs = {Subscript[\[CapitalGamma], wall], Subscript[\[CapitalGamma], 
       p], Subscript[\[CapitalGamma], temp]};
Do[{Us[t], Vs[t], Ps[t], Ts[t]} = 
     NDSolveValue[
       {Table[ Activate[pde[[j]]] == 0, {j, 4}], bcs} /. 
      parameters /. i -> t, {u, v, p, 
     T}, {x, y} \[Element] \[CapitalOmega] , 
    Method -> {"FiniteElement", 
               
      "InterpolationOrder" -> {u -> 2, v -> 2, p -> 1, T -> 2}}];, {t,
   1, 8}]
 

Visualization of temperature

Table[DensityPlot[Ts[i][x, y], {x, y} \[Element]  \[CapitalOmega], 
  ColorFunction -> "Rainbow", PlotRange -> All, 
  PlotLabel -> Row[{"t = ", 10 i}]], {i, 8}]

Figure 1

Visualization of velocity

Table[Show[
  DensityPlot[
   Norm[{Us[i][x, y], Vs[i][x, y]}], {x, y} \[Element] \CapitalOmega], 
   ColorFunction -> "Rainbow", PlotLegends -> Automatic, 
   PlotRange -> All, PlotPoints -> 50, 
   PlotLabel -> Row[{"t = ", 10 i}]], 
  StreamPlot[{Us[i][x, y], 
    Vs[i][x, y]}, {x, y} \[Element] \[CapitalOmega] , 
   VectorPoints -> Fine]], {i, 3, 8}]

Figure 2

Update 1. This method working well for time step dt=10 on the quad element mesh with element number N from 225 to 1024 including N=400 in the benchmark solution above.

Example 1.

Needs["NDSolve`FEM`"]

sizes = {length -> 1, hight -> 1};
\[CapitalOmega] = Rectangle[{0, 0}, {length, hight}] /. sizes; mesh = 
 ToElementMesh[\[CapitalOmega], AccuracyGoal -> 5, PrecisionGoal -> 5,
   "MeshElementType" -> "QuadElement", 
  "MaxCellMeasure" -> .005]; mesh["Wireframe"]



\[Phi][temp_, tr_, r_] := 1/2 (1 + Tanh[(tr - temp)/r])

Plot[\[Phi][T, 0.01, 0.025], {T, -0.6, 0.6}, PlotRange -> All]

tvars = {T[t, x, y], t, {x, y}};
regParam = 0.025;
steNr = 0.045;
Tnr = 0.01;
muL = 1.0;
muS = 10^8;

\[Mu][muL_, muS_, phi_] := muL + (muS - muL)*phi;
dt = 10;
pde = Inactivate[{
    (u[ x, y] - Us[i - 1][x, y])/dt + 
          
     Div[\[Mu][muL, 
        muS, \[Phi][T[x, y], Tnr, 
         regParam]]*(-\[Nu] Grad[u[x, y], {x, y}]), {x, 
              y}] + {u[x, y], v[x, y]} . 
           Grad[u[x, y], {x, y}] + 
     D[p[x, y], x], 
       
    ( v[ x, y] - Vs[i - 1][x, y])/dt +
          
     Div[ \[Mu][muL, 
        muS, \[Phi][T[x, y], Tnr, 
         regParam]]*(-\[Nu] Grad[v[x, y], {x, y}]), {x, 
              y}] + {u[x, y], v[ x, y]} . 
           Grad[v[x, y], {x, y}] + 
     D[p[x, y], y] - Ra/Pr*T[x, y], 
       
    D[u[x, y], x] + 
     D[v[ x, y], y], (T[ x, y] - Ts[i - 1][x, y])/dt + 
     Div[{u[x, y], v[x, y]} T[x, y], {x, y}] - 
     1/Pr Laplacian[T[x, y], {x, y}] - 
     1/steNr (\[Phi][T[x, y], Tnr , regParam] - \[Phi][
          Ts[i - 1][x, y], Tnr , regParam])/dt}, 
   D | Grad | Laplacian | Div];


parameters = {\[Nu] -> 1, Pr -> 56.2, Ra -> 327000.0};

tHot = 1.0;
tCold = -0.01; tMeltThickness = 0.05;
appro = With[{k = 2. 10^4}, ArcTan[k #]/Pi + 1/2 &];
tin = Simplify`PWToUnitStep@
    PiecewiseExpand@If[x < tMeltThickness, tHot, tCold] /. 
   UnitStep -> appro;
Ts[0][ x_, y_] := 
  Simplify`PWToUnitStep@
    PiecewiseExpand@If[x < tMeltThickness, tHot, tCold] /. 
   UnitStep -> appro;
Us[0][x_, y_] := 0; Vs[0][ x_, y_] := 0; Ps[0][ x_, y_] := 0;

Subscript[\[CapitalGamma], 
     temp] = {DirichletCondition[T[x, y] == tHot, x == 0],
      DirichletCondition[T[x, y] == tCold, x == 1]};
Subscript[\[CapitalGamma], wall] = 
    DirichletCondition[{u[x, y] == 0, v[x, y] == 0}, True];
Subscript[\[CapitalGamma], p] = 
    DirichletCondition[p[ x, y] == Ps[0][x, y], x == 0 && y == 0];

bcs = {Subscript[\[CapitalGamma], wall], Subscript[\[CapitalGamma], 
       p], Subscript[\[CapitalGamma], temp]};
Do[{Us[t], Vs[t], Ps[t], Ts[t]} = 
    NDSolveValue[
      {Table[ Activate[pde[[j]]] == 0, {j, 4}], bcs} /. parameters /. 
    i -> t, {u, v, p, T}, {x, y} \[Element] mesh, 
   Method -> {"FiniteElement", 
              
     "InterpolationOrder" -> {u -> 2, v -> 2, p -> 1, T -> 2}}], {t, 
  1, 5}]

Visualization

Table[DensityPlot[Ts[i][x, y], {x, y} \[Element] mesh, 
  ColorFunction -> "Rainbow", PlotLegends -> Automatic, 
  PlotRange -> All], {i,3, 5}]
{mesh["Wireframe"], 
 Show[DensityPlot[
   Norm[{Us[5][x, y], Vs[5][x, y]}], {x, y} \[Element] mesh, 
   ColorFunction -> "Rainbow", PlotLegends -> Automatic, 
   PlotRange -> All, PlotPoints -> 50], 
  StreamPlot[{Us[5][x, y], Vs[5][x, y]}, {x, y} \[Element] mesh, 
   VectorPoints -> Fine]]}

Figure3

Test 2 (this example not working with automatic mesh generation as mentioned by ABCDEMMM)

mesh = ToElementMesh[\[CapitalOmega], AccuracyGoal -> 5, 
   PrecisionGoal -> 5, "MeshElementType" -> "QuadElement", 
   "MaxCellMeasure" -> .001];

Visualization Figure 4

We also can handle case with dt=2.5 and mesh of 2025 quad elements given by

Needs["NDSolve`FEM`"]

sizes = {length -> 1, hight -> 1};
\[CapitalOmega] = Rectangle[{0, 0}, {length, hight}] /. sizes; mesh = 
 ToElementMesh[\[CapitalOmega], AccuracyGoal -> 5, PrecisionGoal -> 5,
   "MeshElementType" -> "QuadElement", 
  "MaxCellMeasure" -> .0005]; mesh["Wireframe"]

Figure 5

$\endgroup$
20
  • $\begingroup$ Trounex thanks! what is the numerical issue in the original model, since the original model is based on wolfram.com/language/12/nonlinear-finite-elements/… $\endgroup$
    – ABCDEMMM
    Commented Dec 10, 2021 at 9:30
  • $\begingroup$ There is no any issue, and it is possible to make several steps up to $t=1.35$ with your code. But we can't compute up to $t=80$ as with a code above. The problem is that DAE solver used for time integration in your code can't make steps with $dt=10$ due to stability condition. Also we have message LinearSolve::sing: Matrix SparseArray[<<1>>] is singular. $\endgroup$ Commented Dec 10, 2021 at 9:44
  • $\begingroup$ A plot error here: DensityPlot::idomdim: {x,y}[Element]mesh does not have a valid dimension as a plotting domain. $\endgroup$
    – ABCDEMMM
    Commented Dec 10, 2021 at 9:49
  • $\begingroup$ for the time step issue, since tEnd = 0.001 is ued in the original model, even not working for tEnd = 0.00001; tEnd means the total time! $\endgroup$
    – ABCDEMMM
    Commented Dec 10, 2021 at 10:19
  • 1
    $\begingroup$ @ABCDEMMM We can use any mesh, but not with dt=10. Practically my algorithm is explicit-implicit, therefore it has bound for dt like $dt<c h^2/\mu$ with c dependent on gradient $\mu$. In a case of fine mesh we need to reduce dt, also it takes a time to compute result even with dt=2.5. $\endgroup$ Commented Dec 13, 2021 at 1:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.