Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

abstract class stabdardization #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 josie/FourEq/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: BSD-3-Clause

from josie.twofluid.state import PhasePair
import abc
from abc import ABC, abstractmethod
import numpy as np


Expand All @@ -12,19 +12,19 @@
ArrayAndScalar = Union[np.ndarray, float]


class BarotropicEOS(metaclass=abc.ABCMeta):
class BarotropicEOS(ABC):
"""An Abstract Base Class representing a barotropic EOS for an
Euler System"""

@abc.abstractmethod
@abstractmethod
def p(self, rho: ArrayAndScalar) -> ArrayAndScalar:
raise NotImplementedError

@abc.abstractmethod
@abstractmethod
def rho(self, p: ArrayAndScalar) -> ArrayAndScalar:
raise NotImplementedError

@abc.abstractmethod
@abstractmethod
def sound_velocity(self, rho: ArrayAndScalar) -> ArrayAndScalar:
raise NotImplementedError

Expand Down
8 changes: 4 additions & 4 deletions josie/bn/closure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
#
# SPDX-License-Identifier: BSD-3-Clause

import abc
from abc import ABC, abstractmethod
import numpy as np

from .state import Q


class Closure(metaclass=abc.ABCMeta):
class Closure(ABC):
r"""A class representing the closure relation for :math:`p_I` and
:math:`\vb{u}_I`. Use them as mixin with the Equation of State in order
to provide full closure for the system
"""

@abc.abstractmethod
@abstractmethod
def pI(self, state_array: Q) -> np.ndarray:
r"""
Parameters
Expand All @@ -32,7 +32,7 @@ def pI(self, state_array: Q) -> np.ndarray:

raise NotImplementedError

@abc.abstractmethod
@abstractmethod
def uI(self, state_array: Q) -> np.ndarray:
r"""
Parameters
Expand Down
6 changes: 3 additions & 3 deletions josie/boundary/boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
from __future__ import annotations

import abc
from abc import ABC, abstractmethod
import matplotlib.pyplot as plt
import numpy as np

Expand Down Expand Up @@ -89,7 +89,7 @@ def apply_bc(self, cells: MeshCellSet, t: float):
self.curve.bc(cells, self, t)


class BoundaryCurve(metaclass=abc.ABCMeta):
class BoundaryCurve(ABC):
r"""A class representing a :class:`BoundaryCurve`. A
:class:`BoundaryCurve` is parametrized with a single parameter. It
implements a :meth:`__call__` method that returns the :math:`(x,y)` values
Expand All @@ -104,7 +104,7 @@ def bc(self):
def bc(self, bc: BoundaryCondition):
self._bc = bc

@abc.abstractmethod
@abstractmethod
def __call__(self, xi):
r"""The effective parametrization of the BoundaryCurve. Assume ``xi``
(:math:`\xi`) to range into :math:`[0, 1]`
Expand Down
12 changes: 6 additions & 6 deletions josie/euler/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@
""" This module contains the different Equation of State (EOS) implementations
"""

import abc
from abc import ABC, abstractmethod
import numpy as np

from typing import Union

ArrayAndScalar = Union[np.ndarray, float]


class EOS(metaclass=abc.ABCMeta):
class EOS(ABC):
"""An Abstract Base Class representing an EOS for an Euler System"""

@abc.abstractmethod
@abstractmethod
def rhoe(self, rho: ArrayAndScalar, p: ArrayAndScalar) -> ArrayAndScalar:
raise NotImplementedError

@abc.abstractmethod
@abstractmethod
def p(self, rho: ArrayAndScalar, e: ArrayAndScalar) -> ArrayAndScalar:
raise NotImplementedError

@abc.abstractmethod
@abstractmethod
def rho(self, p: ArrayAndScalar, e: ArrayAndScalar) -> ArrayAndScalar:
raise NotImplementedError

@abc.abstractmethod
@abstractmethod
def sound_velocity(
self, rho: ArrayAndScalar, p: ArrayAndScalar
) -> ArrayAndScalar:
Expand Down
2 changes: 1 addition & 1 deletion josie/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __repr__(self):


class FieldsMeta(type):
"""This metaclass reproduces in a simpler form the behaviour of
"""This metaclass reproduces in a simpler form the behavior of
:class:`Enum`. It tracks all the defined attributes of a class, it
precomputes the number of fields and replaces the fields that have no int
value with the corresponding int
Expand Down
24 changes: 12 additions & 12 deletions josie/mesh/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from __future__ import annotations

import abc
from abc import ABC, abstractmethod

import numpy as np

Expand All @@ -22,7 +22,7 @@
from josie.mesh import Mesh


class Cell(metaclass=abc.ABCMeta):
class Cell(ABC):
"""This is a class interface representing a generic cell of a
:class:`Mesh`.

Expand All @@ -44,55 +44,55 @@ class Cell(metaclass=abc.ABCMeta):
"""

@property
@abc.abstractmethod
@abstractmethod
def num_points(self) -> int:
raise NotImplementedError

@property
@abc.abstractmethod
@abstractmethod
def num_dofs(self) -> int:
raise NotImplementedError

@property
@abc.abstractmethod
@abstractmethod
def _meshio_cell_type(self) -> str:
raise NotImplementedError

@classmethod
@abc.abstractmethod
@abstractmethod
def _generate_ghosts(cls, mesh: Mesh):
"""Generate ghost cells centroids"""
raise NotImplementedError

@classmethod
@abc.abstractmethod
@abstractmethod
def centroid(
cls, nw: PointType, sw: PointType, se: PointType, ne: PointType
) -> PointType:
"""Compute the centroid of the cell"""

@classmethod
@abc.abstractmethod
@abstractmethod
def volume(
cls, nw: PointType, sw: PointType, se: PointType, ne: PointType
) -> np.ndarray:
"""Compute the volume of a cell from its points."""
raise NotImplementedError

@classmethod
@abc.abstractmethod
@abstractmethod
def face_surface(cls, p0: PointType, p1: PointType) -> np.ndarray:
"""Compute the surface of a face from its points."""
raise NotImplementedError

@classmethod
@abc.abstractmethod
@abstractmethod
def face_normal(cls, p0: PointType, p1: PointType) -> np.ndarray:
"""Compute the normal vector to a face."""
raise NotImplementedError

@classmethod
@abc.abstractmethod
@abstractmethod
def create_connectivity(cls, mesh: Mesh):
r"""This method creates the connectivity from the given points of
a mesh. It modifies attributes of the :class:`Mesh` instance.
Expand Down Expand Up @@ -123,7 +123,7 @@ def create_connectivity(cls, mesh: Mesh):
mesh.cells.compute_min_length()

@classmethod
@abc.abstractmethod
@abstractmethod
def export_connectivity(cls, mesh: "Mesh") -> MeshIO:
"""This method exports the connectivity of the mesh in the format
accepted by the :class:`~meshio.Mesh`.
Expand Down
16 changes: 8 additions & 8 deletions josie/plot/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
""" Backends used to display mesh and mesh results """
from __future__ import annotations

import abc
from abc import ABC, abstractmethod

from typing import List, Union, TYPE_CHECKING

Expand All @@ -14,10 +14,10 @@
from josie.solver import Solver


class PlotBackend(metaclass=abc.ABCMeta):
class PlotBackend(ABC):
"""An abstract interface representing a plot backend"""

@abc.abstractmethod
@abstractmethod
def plot(self, mesh: Mesh):
"""Allocate a drawing instance in order to draw a single image plot.
The drawing state is stored in :attr:`plot_state`.
Expand All @@ -30,7 +30,7 @@ def plot(self, mesh: Mesh):

raise NotImplementedError

@abc.abstractmethod
@abstractmethod
def append(self, solver: Solver, t):
"""Appends a new simulation time state

Expand All @@ -46,7 +46,7 @@ def append(self, solver: Solver, t):

raise NotImplementedError

@abc.abstractmethod
@abstractmethod
def update(self, solver: Solver):
"""Updates the :attr:`plot_state` with the state (i.e. the field data
stored in the mesh, e.g. cell data) in the Solver.
Expand All @@ -63,7 +63,7 @@ def update(self, solver: Solver):

raise NotImplementedError

@abc.abstractmethod
@abstractmethod
def show(self, fields: Union[List, str]):
"""Show on screen a list of fields.

Expand All @@ -76,12 +76,12 @@ def show(self, fields: Union[List, str]):

raise NotImplementedError

@abc.abstractmethod
@abstractmethod
def show_grid(self):
"""Show the grid on screen"""
raise NotImplementedError

@abc.abstractmethod
@abstractmethod
def show_all(self):
"""Show on screen all the fields"""

Expand Down
10 changes: 7 additions & 3 deletions josie/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

from __future__ import annotations

import abc
from abc import ABC, abstractmethod
import numpy as np

from typing import Union

from josie.mesh.cellset import CellSet, MeshCellSet


class Problem(metaclass=abc.ABCMeta):
class Problem(ABC):
r"""A class representing a physical problem to be solved (governed by
a PDE).

Expand All @@ -32,6 +32,7 @@ class Problem(metaclass=abc.ABCMeta):
def __init__(self, **kwargs):
super().__init__()

@abstractmethod
def F(self, values) -> np.ndarray:
r"""The convective flux operator :math:`\pdeConvective`

Expand All @@ -47,8 +48,9 @@ def F(self, values) -> np.ndarray:
\times N_\text{dim}` containing the computed convective flux for
the given problem
"""
pass
...

@abstractmethod
def B(self, values) -> np.ndarray:
r"""This returns the tensor that pre-multiplies the non-conservative
term of the problem.
Expand Down Expand Up @@ -76,6 +78,7 @@ def B(self, values) -> np.ndarray:
"""
pass

@abstractmethod
def K(self, cells: Union[CellSet, MeshCellSet]) -> np.ndarray:
r"""This returns the tensor that pre-multiplies the gradient in the
diffusive term of the problem.
Expand Down Expand Up @@ -103,6 +106,7 @@ def K(self, cells: Union[CellSet, MeshCellSet]) -> np.ndarray:
"""
pass

@abstractmethod
def s(self, values, t: float) -> np.ndarray:
r"""This returns the values of the source terms

Expand Down