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

chore(cleanup useless abstractions) #102

Open
wants to merge 4 commits into
base: main
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
4 changes: 2 additions & 2 deletions examples/explosion_multi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
realplot=False,
profile=True,
fluid=air,
nx=150,
ny=150,
nx=50,
ny=50,
nghost=1,
use_JIT=True,
)
100 changes: 29 additions & 71 deletions pyhype/blocks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,41 +605,6 @@ def plot_mesh(self):


class BaseBlock:
def __init__(self, config: SolverConfig):
self.config = config

@staticmethod
def _is_all_blk_conservative(blks: dict.values):
return all(map(lambda blk: isinstance(blk.state, ConservativeState), blks))

@staticmethod
def _is_all_blk_primitive(blks: dict.values):
return all(map(lambda blk: isinstance(blk.state, PrimitiveState), blks))


class BaseBlockMesh(BaseBlock):
"""
BaseBlock class that contains a mesh and quadrature point object.
This is the basic building block for all block types.

:ivar config: SolverConfigs object
:ivar mesh: QuadMesh object containing the block's mesh
:ivar qp: QuadraturePointData object that contains the quadrature point
locations and methods for quadrature point calculations.
"""

def __init__(
self,
config: SolverConfig,
mesh: QuadMesh = None,
qp: QuadraturePointData = None,
):
super().__init__(config=config)
self.mesh = mesh
self.qp = qp


class BaseBlockState(BaseBlockMesh):
"""
Block object that inherits from BaseBlockMesh,
which also contains the solution State and relevant methods.
Expand Down Expand Up @@ -670,13 +635,30 @@ class BaseBlockState(BaseBlockMesh):
def __init__(
self,
config: SolverConfig,
mesh: QuadMesh,
qp: QuadraturePointData,
state_type: Type[State],
qp: QuadraturePointData = None,
mesh: QuadMesh = None,
):
super().__init__(config=config, mesh=mesh, qp=qp)
self.qp = qp
self.mesh = mesh
self.config = config
self.state = state_type(fluid=config.fluid, shape=(mesh.ny, mesh.nx, 4))

self.grad = GradientsFactory.create(
config=config,
reconstruction_order=config.fvm_spatial_order,
nx=mesh.nx,
ny=mesh.ny,
)

@staticmethod
def _is_all_blk_conservative(blks: dict.values):
return all(map(lambda blk: isinstance(blk.state, ConservativeState), blks))

@staticmethod
def _is_all_blk_primitive(blks: dict.values):
return all(map(lambda blk: isinstance(blk.state, PrimitiveState), blks))

def row(self, index: Union[int, slice]) -> State:
"""
Return the solution stored in the index-th row of the mesh.
Expand Down Expand Up @@ -705,38 +687,6 @@ def col(self, index: int) -> State:
"""
return self.state[NumpySlice.col(index=index)]

def realizable(self) -> bool:
"""
Runs a physical realizability check on the block's State.

:return: bool representing the State's realizability
"""
return self.state.realizable()


class BaseBlockGrad(BaseBlockState):
"""
Class that inherits from BaseBlockState and adds a SolutionGradient
object.

:ivar grad: SolutionGradients object
"""

def __init__(
self,
config: SolverConfig,
mesh: QuadMesh,
qp: QuadraturePointData,
state_type: Type[State],
):
super().__init__(config, mesh=mesh, qp=qp, state_type=state_type)
self.grad = GradientsFactory.create(
config=config,
reconstruction_order=config.fvm_spatial_order,
nx=mesh.nx,
ny=mesh.ny,
)

def high_order_term_at_location(
self,
x_c: np.ndarray,
Expand All @@ -747,8 +697,16 @@ def high_order_term_at_location(
) -> np.ndarray:
return self.grad.get_high_order_term(x_c, x_p, y_c, y_p, slicer)

def realizable(self) -> bool:
"""
Runs a physical realizability check on the block's State.

:return: bool representing the State's realizability
"""
return self.state.realizable()


class BaseBlockFVM(BaseBlockGrad):
class BaseBlockFVM(BaseBlock):
"""
Class that inherits from BaseBlockGrad and adds a finite volume method
object and approriate functions.
Expand Down
14 changes: 7 additions & 7 deletions pyhype/blocks/ghost.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
if TYPE_CHECKING:
from pyhype.states.base import State
from pyhype.solvers.base import SolverConfig
from pyhype.blocks.quad_block import QuadBlock
from pyhype.blocks.quad_block import BaseBlockGhost
from pyhype.mesh.quadratures import QuadraturePointData


Expand All @@ -48,7 +48,7 @@ def __init__(
self,
config: SolverConfig,
block_data: BlockDescription,
parent_block: QuadBlock,
parent_block: BaseBlockGhost,
state_type: Type[State],
) -> None:
"""
Expand Down Expand Up @@ -103,7 +103,7 @@ def __init__(
self,
config: SolverConfig,
bc_type: Union[str, Callable],
parent_block: QuadBlock,
parent_block: BaseBlockGhost,
state_type: Type[State],
direction: int,
mesh: QuadMesh = None,
Expand Down Expand Up @@ -283,7 +283,7 @@ def __init__(
self,
config: SolverConfig,
bc_type: str,
parent_block: QuadBlock,
parent_block: BaseBlockGhost,
state_type: Type[State],
) -> None:

Expand Down Expand Up @@ -336,7 +336,7 @@ def __init__(
self,
config: SolverConfig,
bc_type: str,
parent_block: QuadBlock,
parent_block: BaseBlockGhost,
state_type: Type[State],
):
# Calculate coordinates of all four vertices
Expand Down Expand Up @@ -391,7 +391,7 @@ def __init__(
self,
config: SolverConfig,
bc_type: str,
parent_block: QuadBlock,
parent_block: BaseBlockGhost,
state_type: Type[State],
):
# Calculate coordinates of all four vertices
Expand Down Expand Up @@ -446,7 +446,7 @@ def __init__(
self,
config: SolverConfig,
bc_type: str,
parent_block: QuadBlock,
parent_block: BaseBlockGhost,
state_type: Type[State],
) -> None:
# Calculate coordinates of all four vertices
Expand Down
Loading