Skip to main content

Solving a system of coupled non-linear partial differential equations


I am trying to solve a system of coupled non-linear partial differential equations, 2D spatially + time. The equations are:


enter image description here


where c, d, and p are constants. I am solving for the functions Az and Bz in polar coordinates, r -> x and theta -> y, and time, t (I am using x and y to visually simplify the code). To do so, I am using NDSolve. The equations in code form are:


azExt[x_, y_, t_] = -bo*(1 - E^(-t*2*Pi/(w*T)))*a*x*Sin[2*Pi*t - y];

eqns =
{c*D[az[x, y, t], t] == Laplacian[az[x, y, t], {x, y}, "Polar"] - 1/x*d*p*(D[az[x, y, t], x]*D[bz[x, y, t], y] - D[az[x, y, t], y]*D[bz[x, y,t],x] ),
c*D[bz[x, y, t], t] == Laplacian[bz[x, y, t], {x, y}, "Polar"] - 1/x*1/d*p(D[az[x, y, t], y]*D[Laplacian[az[x, y, t], {x, y}, "Polar"], x]-D[az[x, y, t], x]*D[Laplacian[az[x, y, t], {x, y}, "Polar"], y] ),
(*Initial Conditions*)
az[x, y, 0] == 0,
bz[x, y, 0] == 1,
(*Boundary Conditions*)
bz[x, Pi, t] == bz[x, -Pi, t],
az[x, Pi, t] == az[x, -Pi, t],
bz[1, y, t] == 1,

az[$MachineEpsilon, y, t] == 0,
(D[bz[x, y, t], x] /. x -> x0) == 0,
(D[az[x, y, t], x] /. x -> 1) == 2*azExt[1,y,t]/(bo*a) - az[1,y,t]};

Where the constants are defined as:


bo = 0.05; w = 5*10^6; T = 10^-5;
a = 0.05; t0 = 5/312;
c = 312;(*312*)d = 1.3;
p = 250; x0 = 10^-5;


I have left the third boundary condition for x open for Mathematica to find as the authors from whom I have taken the equations from did not clearly specify what it might be.


My current problem is that the solution becomes very stiff. To solve, I have tried using both Explicit Euler and Method of Lines and have played around with options such as MaxStepFraction, AccuracyGoal,PrecisionGoal, Max- and MinPoints. With the ExplicitEuler method, I get an overflow error and the solutions tends to explode. I will use the method of lines in the code below as it seems to be the go to method for many pde problems I've seen on the site. The code for NDSolve is:


sol = NDSolve[eqns, {az[x, y, t], bz[x, y, t]}, {x, $MachineEpsilon, 
5}, {y, -Pi, Pi}, {t, 0, 5}, "ExtrapolationHandler" -> {Indeterminate &,"WarningMessage" -> False}, Method -> {"MethodOfLines", "TemporalVariable" -> t, "SpatialDiscretization" -> {"TensorProductGrid"}}]

Depending on what method and options I'm messing around with but for this particular case, the error I get is:


NDSolve::mxsst: Using maximum number of grid points 100 allowed by the MaxPoints or MinStepSize options for independent variable y.
NDSolve::bcart: Warning: an insufficient number of boundary conditions have been specified for the direction of independent variable x. Artificial boundary effects may be present in the solution.
NDSolve::ndcf: Repeated convergence test failure at t == 1.2163884257297997`*^-14; unable to continue.
NDSolve::eerr: Warning: scaled local spatial error estimate of 253.1320098824361` at t = 1.2163884257297997`*^-14 in the direction of independent variable y is much greater than the prescribed error tolerance. Grid spacing with 101 points may be too large to achieve the desired accuracy or precision. A singularity may have formed or a smaller grid spacing can be specified using the MaxStepSize or MinPoints method options.


And the solution is solved up to 1.22 * 10^-14.


Increasing the maxpoints tends to lead to excessively long computation that lead to nothing. Decreasing my accuracy and precision goals does allow me to calculate solutions further in time but usually not past ~2.5. I would like to be able to calculate up to t = 100 but I understand that that might not be possible.


I am pretty new to using Mathematica and even more green to solving systems of PDE's. I'm not sure if this system is too complicated for Mathematica or if I'm just going at it the wrong way. I've browsed similar questions with no luck. Any help with solving it would be appreciated! If you need more information or think I missed something, please let me know.



Answer



Make a replacement t->t/c, r->x, define constants T, w. Boundary conditions and error messages appear. But the solution of the system of equations converges, which is surprising.


azExt[x_, y_, t_] = -bo*(1 - E^(-t*2*Pi/(w*T)))*a*x*Sin[2*Pi*t - y];
eqns = {c*D[az[x, y, t], t] ==
Laplacian[az[x, y, t], {x, y}, "Polar"] -
1/x*d*p*(D[az[x, y, t], x]*D[bz[x, y, t], y] -

D[az[x, y, t], y]*D[bz[r, y, t], x]),
c*D[bz[x, y, t], t] ==
Laplacian[bz[x, y, t], {x, y}, "Polar"] -
1/x*1/d*p (D[az[x, y, t], y]*
D[Laplacian[az[x, y, t], {x, y}, "Polar"], x] -
D[az[x, y, t], x]*
D[Laplacian[az[x, y, t], {x, y}, "Polar"],
y]),(*Initial Conditions*)az[x, y, 0] == 0,
bz[x, y, 0] == 1,(*Boundary Conditions*)
bz[x, Pi, t] == bz[x, -Pi, t], az[x, Pi, t] == az[x, -Pi, t],

bz[1, y, t] == 1,
az[1, y, t] == 0, (D[az[x, y, t], x] /. x -> 1) ==
2*azExt[1, y, t]/(bo*a) - az[1, y, t]};

bo = 0.05; w = 1; T = .001;
a = 0.05; t0 = 5/312;
c = 1;(*312*)
d = 1.3;
p = 250; x0 = 10^-5;



sol = NDSolve[eqns, {az, bz}, {x, x0, 1}, {y, -Pi, Pi}, {t, 0, t0},
Method -> {"MethodOfLines",
"SpatialDiscretization" -> {"TensorProductGrid",
"MinPoints" -> 77, "MaxPoints" -> 77, "DifferenceOrder" -> 2}}]

{{ContourPlot[Evaluate[az[x, 0, t] /. sol], {x, x0, 1}, {t, 0, t0},
Contours -> 20, ColorFunction -> Hue, PlotLegends -> Automatic,
PlotRange -> All, FrameLabel -> {"x", "t"}, PlotLabel -> "Az"],
ContourPlot[Evaluate[bz[x, 0, t] /. sol], {x, x0, 1}, {t, 0, t0},

Contours -> 20, ColorFunction -> Hue, PlotLegends -> Automatic,
PlotRange -> All, FrameLabel -> {"x", "t"},
PlotLabel -> "Bz"]}, {ContourPlot[
Evaluate[az[x, y, t0] /. sol], {x, x0, 1}, {y, -Pi, Pi},
Contours -> 20, ColorFunction -> Hue, PlotLegends -> Automatic,
PlotRange -> All, FrameLabel -> {"x", "y"}, PlotLabel -> "Az"],
ContourPlot[Evaluate[bz[x, y, t0] /. sol], {x, x0, 1}, {y, -Pi, Pi},
Contours -> 20, ColorFunction -> Hue, PlotLegends -> Automatic,
PlotRange -> All, FrameLabel -> {"x", "t"}, PlotLabel -> "Bz"]}}


fig1


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...

How to thread a list

I have data in format data = {{a1, a2}, {b1, b2}, {c1, c2}, {d1, d2}} Tableform: I want to thread it to : tdata = {{{a1, b1}, {a2, b2}}, {{a1, c1}, {a2, c2}}, {{a1, d1}, {a2, d2}}} Tableform: And I would like to do better then pseudofunction[n_] := Transpose[{data2[[1]], data2[[n]]}]; SetAttributes[pseudofunction, Listable]; Range[2, 4] // pseudofunction Here is my benchmark data, where data3 is normal sample of real data. data3 = Drop[ExcelWorkBook[[Column1 ;; Column4]], None, 1]; data2 = {a #, b #, c #, d #} & /@ Range[1, 10^5]; data = RandomReal[{0, 1}, {10^6, 4}]; Here is my benchmark code kptnw[list_] := Transpose[{Table[First@#, {Length@# - 1}], Rest@#}, {3, 1, 2}] &@list kptnw2[list_] := Transpose[{ConstantArray[First@#, Length@# - 1], Rest@#}, {3, 1, 2}] &@list OleksandrR[list_] := Flatten[Outer[List, List@First[list], Rest[list], 1], {{2}, {1, 4}}] paradox2[list_] := Partition[Riffle[list[[1]], #], 2] & /@ Drop[list, 1] RM[list_] := FoldList[Transpose[{First@li...

front end - keyboard shortcut to invoke Insert new matrix

I frequently need to type in some matrices, and the menu command Insert > Table/Matrix > New... allows matrices with lines drawn between columns and rows, which is very helpful. I would like to make a keyboard shortcut for it, but cannot find the relevant frontend token command (4209405) for it. Since the FullForm[] and InputForm[] of matrices with lines drawn between rows and columns is the same as those without lines, it's hard to do this via 3rd party system-wide text expanders (e.g. autohotkey or atext on mac). How does one assign a keyboard shortcut for the menu item Insert > Table/Matrix > New... , preferably using only mathematica? Thanks! Answer In the MenuSetup.tr (for linux located in the $InstallationDirectory/SystemFiles/FrontEnd/TextResources/X/ directory), I changed the line MenuItem["&New...", "CreateGridBoxDialog"] to read MenuItem["&New...", "CreateGridBoxDialog", MenuKey["m", Modifiers-...