Skip to content

Commit

Permalink
#617 start adding 1D mesh generator
Browse files Browse the repository at this point in the history
  • Loading branch information
rtimms committed Oct 10, 2019
1 parent 4085dd5 commit 5f596a9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pybamm/meshes/meshes.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,18 @@ def add_ghost_meshes(self):

class MeshGenerator:
"""
Base class for mesh generator objects that are used to generate submeshes
that require input paramaters.
Base class for mesh generator objects that are used to generate submeshes.
Parameters
----------
submesh_type: str
The type of submeshes to use.
submesh_params: dict, optional
Contains any parameters required by the submesh.
"""

def __init__(self):
def __init__(self, submesh_type, submesh_params=None):
pass

def __call__(self):
Expand Down
47 changes: 47 additions & 0 deletions pybamm/meshes/one_dimensional_submeshes.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,53 @@ def near(x, point, tol=3e-16):
)


class MeshGenerator1D(MeshGenerator):
"""
A class to generate a submesh on a 1D domain.
Parameters
----------
submesh_type: str
The type of submeshes to use. Can be "Uniform", "Exponential", "Chebyshev"
or "User".
submesh_params: dict, optional
Contains any parameters required by the submesh.
"""

def __init__(self, submesh_type, submesh_params=None):
self.submesh_type = submesh_type
self.submesh_params = submesh_params

def __call__(self, lims, npts, tabs=None):

if self.submesh_type == "Uniform":
return Uniform1DSubMesh(lims, npts, tabs)

elif self.submesh_type == "Exponential":
try:
side = self.submesh_params["side"]
except KeyError:
raise pybamm.GeometryError("Exponenital mesh requires parameter 'side'")
if self.submesh_params["stretch"]:
stretch = self.submesh_params["stretch"]
elif side == "symmetric":
stretch = 1.15
elif side in ["left", "right"]:
stretch = 2.3
return Exponential1DSubMesh(lims, npts, tabs, side, stretch)

elif self.submesh_type == "Chebyshev":
return Chebyshev1DSubMesh(lims, npts, tabs)

elif self.submesh_type == "User":
try:
edges = self.submesh_params["edges"]
except KeyError:
raise pybamm.GeometryError("User mesh requires parameter 'edges'")
return UserSupplied1DSubMesh(lims, npts, tabs, edges)


class Uniform1DSubMesh(SubMesh1D):
"""
A class to generate a uniform submesh on a 1D domain
Expand Down

0 comments on commit 5f596a9

Please sign in to comment.