From 8141de7d5de4ec7b6089eba4c1d0f54daa7b6aad Mon Sep 17 00:00:00 2001 From: Ian Hinder Date: Thu, 13 Oct 2011 02:39:35 +0200 Subject: Add Laplace equation example This uses Jacobi iteration to solve Laplace's equation in 2D on a square grid. --- Examples/Laplace.m | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Examples/Laplace.m (limited to 'Examples/Laplace.m') diff --git a/Examples/Laplace.m b/Examples/Laplace.m new file mode 100644 index 0000000..ad8a28f --- /dev/null +++ b/Examples/Laplace.m @@ -0,0 +1,68 @@ + +groups = {{"phi_group", {phi}}}; + +derivatives = +{ + PDstandard[i_] -> + StandardCenteredDifferenceOperator[1,fdOrder/2,i], + PDstandard[i_, i_] -> + StandardCenteredDifferenceOperator[2,fdOrder/2,i], + PDstandard[i_, j_] -> + StandardCenteredDifferenceOperator[1,fdOrder/2,i] StandardCenteredDifferenceOperator[1,fdOrder/2,j] +}; + +PD = PDstandard; + +initialCalc = +{ + Name -> "Laplace_initial", + Schedule -> {"AT INITIAL"}, + Where -> Interior, + Equations -> + { + phi -> phi0 Sum[4/(Pi n) Sin[n Pi x/Lx] Sinh[n Pi y/Lx]/Sinh[n Pi Ly/Lx], {n, 1, 1, 2}] + } +}; + +initialBoundaryCalc = +{ + Name -> "Laplace_initial_boundary", + Schedule -> {"AT INITIAL after Laplace_initial"}, + Where -> Boundary, + Equations -> + { + phi -> IfThen[Abs[y-Ly]<10^-10, phi0, 0] + } +}; + +evolveCalc = +{ + Name -> "Laplace_relax", + Schedule -> {"in MoL_CalcRHS", "AT ANALYSIS"}, + Equations -> + { + dot[phi] -> mu Euc[ui,uj] PD[phi,li,lj] + } +}; + +boundaryCalc = +{ + Name -> "Laplace_boundary", + Schedule -> {"in MoL_RHSBoundaries", "AT ANALYSIS"}, + Where -> Boundary, + Equations -> + { + dot[phi] -> 0 + } +}; + + +CreateKrancThornTT[ + groups, ".", + "Laplace", + Calculations -> {initialCalc, initialBoundaryCalc, evolveCalc, boundaryCalc}, + PartialDerivatives -> derivatives, + ZeroDimensions -> {3}, + RealParameters -> {Lx,Ly,phi0,mu}, + IntParameters -> {{Name -> fdOrder, Default -> 2, AllowedValues -> {2, 4}}}, + DeclaredGroups -> {"phi_group"}]; -- cgit v1.2.3