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
10 changes: 5 additions & 5 deletions docs/notebooks/01-using-solvers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"source": [
"## Assembling custom solvers\n",
"\n",
"We can unwrap what is actually happening under the hood a bit more by manually assembling this solver based on the predefined problem definition, timestepper and solver framework. The `TimeDependentSolver` is a pre-defined class which initialises a scalar field and solves a time-dependent PDE (as opposed to a steady-state problem). This is done by combining a backend (`torch/jax`) with a timestepper class (e.g. `PseudoSpectralIMEX`) and a problem class which defines the numerical discretisation of the right-hand side of a PDE (e.g. `PeriodicCahnHilliard`)."
"We can unwrap what is actually happening under the hood a bit more by manually assembling this solver based on the predefined problem definition, timestepper and solver framework. The `TimeDependentSolver` is a pre-defined class which initialises a scalar field and solves a time-dependent PDE (as opposed to a steady-state problem). This is done by combining a backend (`torch/jax`) with a timestepper class (e.g. `PseudoSpectralIMEX`) and a problem class which defines the numerical discretisation of the right-hand side of a PDE (e.g. `CahnHilliard`)."
]
},
{
Expand All @@ -148,7 +148,7 @@
}
],
"source": [
"from evoxels.problem_definition import PeriodicCahnHilliard\n",
"from evoxels.problem_definition import CahnHilliard\n",
"from evoxels.solvers import TimeDependentSolver\n",
"from evoxels.timesteppers import PseudoSpectralIMEX\n",
"\n",
Expand All @@ -160,7 +160,7 @@
" vf, # VoxelFields object\n",
" 'c2', # Name of initial field\n",
" 'torch', # Backend\n",
" problem_cls = PeriodicCahnHilliard, # Problem definition\n",
" problem_cls = CahnHilliard, # Problem definition\n",
" timestepper_cls = PseudoSpectralIMEX, # Timestepping scheme\n",
" device='cuda',\n",
" )\n",
Expand Down Expand Up @@ -244,7 +244,7 @@
"\n",
"solver = TimeDependentSolver(\n",
" vf, 'c3', 'torch', device='cuda',\n",
" problem_cls = PeriodicCahnHilliard,\n",
" problem_cls = CahnHilliard,\n",
" timestepper_cls = PseudoSpectralIMEX\n",
" )\n",
"\n",
Expand Down Expand Up @@ -306,7 +306,7 @@
"\n",
"solver = TimeDependentSolver(\n",
" vf, 'c4', 'torch', device='cuda',\n",
" problem_cls = PeriodicCahnHilliard,\n",
" problem_cls = CahnHilliard,\n",
" timestepper_cls = ForwardEuler\n",
" )\n",
"\n",
Expand Down
6 changes: 3 additions & 3 deletions docs/notebooks/04-parameter-estimation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We create an `InversionModel` for the ``PeriodicCahnHilliard`` problem which sets up the voxel grid and the parameters of the PDE."
"We create an `InversionModel` for the ``CahnHilliard`` problem which sets up the voxel grid and the parameters of the PDE."
]
},
{
Expand All @@ -71,10 +71,10 @@
"metadata": {},
"outputs": [],
"source": [
"from evoxels.problem_definition import PeriodicCahnHilliard\n",
"from evoxels.problem_definition import CahnHilliard\n",
"fixed_problem_kwargs={\"mu_hom\": None}\n",
"pos_params = [\"D\", \"eps\"]\n",
"model = evo.InversionModel(vf, PeriodicCahnHilliard, pos_params, fixed_problem_kwargs)"
"model = evo.InversionModel(vf, CahnHilliard, pos_params, fixed_problem_kwargs)"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions evoxels/boundary_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def pad_fft_periodic(self, field):

def pad_fft_dirichlet_periodic(self, field):
"""Pad with inverse of flipped field in x direction."""
return self.vg.concatenate((field, -self.vg.lib.flip(field, [0])), 1)
return self.vg.concatenate((field, -self.vg.lib.flip(field, [1])), 1)

def pad_fft_zero_flux_periodic(self, field):
"""Pad with flipped field in x direction."""
return self.vg.concatenate((field, self.vg.lib.flip(field, [0])), 1)
return self.vg.concatenate((field, self.vg.lib.flip(field, [1])), 1)

def trim_boundary_nodes(self, field):
return field
Expand Down Expand Up @@ -114,7 +114,7 @@ def pad_fft_periodic(self, field):
def pad_fft_dirichlet_periodic(self, field):
"""Pad with inverse of flipped field in x direction."""
bc = self.vg.lib.zeros_like(field[:,0:1])
return self.vg.concatenate((field, bc, -self.vg.lib.flip(field, [0]), bc), 1)
return self.vg.concatenate((field, bc, -self.vg.lib.flip(field, [1]), bc), 1)

def pad_fft_zero_flux_periodic(self, field):
"""Pad with flipped field in x direction."""
Expand Down
4 changes: 2 additions & 2 deletions evoxels/precompiled_solvers/cahn_hilliard.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ..problem_definition import PeriodicCahnHilliard
from ..problem_definition import CahnHilliard
from ..solvers import TimeDependentSolver
from ..timesteppers import PseudoSpectralIMEX
from typing import Callable
Expand Down Expand Up @@ -26,7 +26,7 @@ def run_cahn_hilliard_solver(
voxelfields,
fieldnames,
backend,
problem_cls = PeriodicCahnHilliard,
problem_cls = CahnHilliard,
timestepper_cls = PseudoSpectralIMEX,
device=device,
)
Expand Down
3 changes: 2 additions & 1 deletion evoxels/problem_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,13 @@ def rhs(self, t, u):


@dataclass
class PeriodicCahnHilliard(SemiLinearODE):
class CahnHilliard(SemiLinearODE):
vg: VoxelGrid
eps: float = 3.0
D: float = 1.0
mu_hom: Callable | None = None
A: float = 0.25
bc: tuple = ('periodic', 'periodic', 'periodic')
_fourier_symbol: Any = field(init=False, repr=False)

def __post_init__(self):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import pytest
import evoxels as evo
from evoxels.inversion import InversionModel
from evoxels.problem_definition import PeriodicCahnHilliard
from evoxels.problem_definition import CahnHilliard

diffrax_available = importlib.util.find_spec("diffrax") is not None

def test_train_validates_sequence_length():
vf = evo.VoxelFields((4, 4, 4))
model = InversionModel(vf, PeriodicCahnHilliard)
model = InversionModel(vf, CahnHilliard)
data = {
"ts": np.array([0.0, 1.0, 2.0]),
"ys": np.zeros((3, 4, 4, 4), dtype=np.float32),
Expand All @@ -27,7 +27,7 @@ def test_inversion_forward_solve_constant_solution():

vf = evo.VoxelFields((4, 4, 4))
vf.add_field('c', np.full((4, 4, 4), 0.5, dtype=np.float32))
model = InversionModel(vf, PeriodicCahnHilliard, {'eps': 3.0})
model = InversionModel(vf, CahnHilliard, {'eps': 3.0})
saveat = dfx.SaveAt(ts=jnp.array([0.0, 0.1, 0.2], dtype=jnp.float32))
sol = model.forward_solve({'D': 1.0}, 'c', saveat, dt0=0.1, verbose=False)
assert sol.shape == (3, 4, 4, 4)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_rhs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import sympy as sp
import sympy.vector as spv
from evoxels.problem_definition import PeriodicCahnHilliard, \
from evoxels.problem_definition import CahnHilliard, \
TwoPhaseAllenCahn, CoupledReactionDiffusion, ReactionDiffusionSBM, \
MultiPhaseAllenCahn
from evoxels.utils import rhs_convergence_test
Expand All @@ -12,7 +12,7 @@

def test_Cahn_Hilliard_rhs():
_ ,_ , slope, order = rhs_convergence_test(
ODE_class = PeriodicCahnHilliard,
ODE_class = CahnHilliard,
problem_kwargs = {'eps': 3.0, 'D': 1.0, 'A': 0.25},
test_function = test_fun_ch,
convention = 'cell_center',
Expand Down
Loading