Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions docs/notebooks/10-appendix-convergence-testing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"id": "23f1215b",
"metadata": {},
"source": [
"# Appendix: Code testing and verification"
"# Appendix: Code testing and verification with Manufactured Solutions"
]
},
{
Expand All @@ -24,16 +24,22 @@
"\n",
"This has been included in this project in two ways:\n",
"- For each ODE class a ``rhs_analytic`` function needs to be defined which can be used for probing the right (i.e. expected) order of convergence for the spatial discretization of the numerical right-hand side.\n",
"- The method of manufactured solutions (MMS) can be used to test the order of time integration and compare various discretizations of the same initial-boundary-value problem."
"- The method of manufactured solutions (MMS) can also be used to test the order of time integration and compare various discretizations of the same initial-boundary-value problem."
]
},
{
"cell_type": "markdown",
"id": "26409459",
"metadata": {},
"source": [
"## Method of Manufactured Solution (MMS)"
]
},
{
"cell_type": "markdown",
"id": "a1413cf5",
"metadata": {},
"source": [
"# Method of Manufactured Solution (MMS)\n",
"\n",
"The main idea of this approach is to construct test cases where the solution to a problem is known a-priori. This means for example when testing the discretization of a spatial derivative, one considers functions, where the continuous counterpart can be computed analytically. We make this more precise in the following sections.\n",
"A detailed introduction to MMS can be found [here](https://www.osti.gov/servlets/purl/759450-wLI4Ux/native/).\n"
]
Expand All @@ -43,8 +49,6 @@
"id": "eb058f7c",
"metadata": {},
"source": [
"## 1. Testing spatial order of convergence\n",
"\n",
"In the following we show some examples which are all part of the CI testing of the codebase. They can be found in the test folder in the files `test_laplace.py` and `test_rhs.py`.\n",
"\n",
"In a nutshell, it is as simple as this (for the leading example $-\\Delta u = \\text{rhs}$)\n",
Expand All @@ -66,7 +70,7 @@
"id": "843c121d",
"metadata": {},
"source": [
"### Combining the Laplacian stencil with various BCs"
"## Spatial order of convergence for Laplacian stencils"
]
},
{
Expand Down Expand Up @@ -355,7 +359,7 @@
"id": "f2a3c20e",
"metadata": {},
"source": [
"### Testing ODE right-hand sides\n",
"## Testing ODE right-hand sides\n",
"\n",
"The ODEs are all given in the form $\\partial_t u = \\text{rhs}(t,u)$, e.g. for Allen-Cahn in the form $\\text{rhs}(t,u) = \\Delta u + g(t,u)$.\n",
"\n",
Expand Down Expand Up @@ -432,7 +436,7 @@
"id": "da5b50fd",
"metadata": {},
"source": [
"## 2. Time-dependent problems"
"## Time-dependent problems"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion evoxels/precompiled_solvers/allen_cahn.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def run_allen_cahn_solver(
plot_bounds = None,
):
"""
Runs the Cahn-Hilliard solver with a predefined problem and timestepper.
Solves time-dependent Allen-Cahn problem with ForwardEuler timestepper.
"""
solver = TimeDependentSolver(
voxelfields,
Expand Down
2 changes: 1 addition & 1 deletion evoxels/precompiled_solvers/cahn_hilliard.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def run_cahn_hilliard_solver(
plot_bounds = None,
):
"""
Runs the Cahn-Hilliard solver with a predefined problem and timestepper.
Solves time-dependent Cahn-Hilliard problem with PseudoSpectralIMEX timestepper.
"""
solver = TimeDependentSolver(
voxelfields,
Expand Down
8 changes: 4 additions & 4 deletions evoxels/problem_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ def pad_bc(self, u):
return self.pad_boundary(u, self.bcs[0], self.bcs[1])

def rhs_analytic(self, mask, u, t):
grad = spv.gradient(u)
norm_grad = sp.sqrt(grad.dot(grad))
grad_m = spv.gradient(mask)
norm_grad_m = sp.sqrt(grad_m.dot(grad_m))

divergence = spv.divergence(self.D*(grad - u/mask*spv.gradient(mask)))
du = divergence + norm_grad*self.bc_flux + mask*self._eval_f(u/mask, t, sp)
divergence = spv.divergence(self.D*(spv.gradient(u) - u/mask*grad_m))
du = divergence + norm_grad_m*self.bc_flux + mask*self._eval_f(u/mask, t, sp)
return du

def rhs(self, u, t):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_rhs.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_coupled_reaction_diffusion_rhs():
def test_reaction_diffusion_smoothed_boundary_rhs():
_, _, slope, order = rhs_convergence_test(
ODE_class = ReactionDiffusionSBM,
problem_kwargs = {"D": 1.0, "BC_type": 'dirichlet', "bcs": (0,1),},
problem_kwargs = {"D": 1.0, "BC_type": 'dirichlet', "bcs": (0,1), "bc_flux": 1},
test_function = test_fun_sbm,
mask_function = mask_fun,
convention = 'staggered_x',
Expand Down