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

Remove "Abstract" from "AbstractXYZ" class names #101

Merged
merged 4 commits into from
Jan 26, 2024
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
4 changes: 2 additions & 2 deletions romtools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@

## Representative abstract base classes

- `AbstractTrialSpace`
- `TrialSpace`
- This class defines the minimum API requirements for a trial space

- Constructing a trial space relies on utilities like truncaters, orthogonalizers, etc. Abstract classes, and
Expand All @@ -92,7 +92,7 @@
- splitters
- truncaters

- `AbstractParameterSpace`
- `ParameterSpace`
- This class defines the minimum API of a parameter space. These parameter spaces are used in workflows for
running/building ROMs

Expand Down
12 changes: 6 additions & 6 deletions romtools/hyper_reduction/ecsw.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
import numpy as np


class AbstractECSWsolver(abc.ABC):
class ECSWsolver(abc.ABC):
'''
Abstract base class for ECSW solvers

Expand Down Expand Up @@ -129,7 +129,7 @@ def __call__(self, full_mesh_lhs: np.ndarray, full_mesh_rhs: np.array, tolerance
# this function because tau can't be specified


class ECSWsolverNNLS(AbstractECSWsolver):
class ECSWsolverNNLS(ECSWsolver):
'''
Given a linear system with left-hand side full_mesh_lhs and right-hand side full_mesh_rhs compute sample mesh indices and weights for ECSW using the non-negative least squares algorithm from Chapman et al. 2016
DOI: 10.1002/nme.5332.
Expand Down Expand Up @@ -330,7 +330,7 @@ def _construct_linear_system(residual_snapshots: np.ndarray,
return full_mesh_lhs, full_mesh_rhs


def ecsw_fixed_test_basis(ecsw_solver: AbstractECSWsolver,
def ecsw_fixed_test_basis(ecsw_solver: ECSWsolver,
residual_snapshots: np.ndarray,
test_basis: np.ndarray,
n_var: int,
Expand All @@ -340,7 +340,7 @@ def ecsw_fixed_test_basis(ecsw_solver: AbstractECSWsolver,
ECSW implementation for a fixed test basis, such as POD-Galerkin projection

Args:
ecsw_solver: AbstractECSWsolver object corresponding to a child class with concrete implementations such as ECSWsolverNNLS.
ecsw_solver: ECSWsolver object corresponding to a child class with concrete implementations such as ECSWsolverNNLS.
residual_snapshots: (n_dof*n_var, n_snap) numpy ndarray, where n_dof is the number of mesh degrees of freedom (DoFs) (nodes, volumes, or elements), n_var is the number of residual variables, and n_snap is the number of snapshots
test_basis: (n_dof*n_var, n_mode) numpy ndarray, where n_mode is the number of modes in the basis.
n_var: int, the number of residual variables (e.g. for fluid flow, residual variable could be mass, x-momentum, y-momentum, z-momentum, and energy)
Expand All @@ -361,15 +361,15 @@ def ecsw_fixed_test_basis(ecsw_solver: AbstractECSWsolver,

return ecsw_solver(full_mesh_lhs, full_mesh_rhs, tolerance)

def ecsw_varying_test_basis(ecsw_solver: AbstractECSWsolver,
def ecsw_varying_test_basis(ecsw_solver: ECSWsolver,
full_mesh_lhs: np.ndarray,
full_mesh_rhs: np.ndarray,
tolerance: np.double):
'''
ECSW implementation for a varying test basis, such as Least-Squares Petrov-Galerkin projection

Args:
ecsw_solver: AbstractECSWsolver object corresponding to a child class with concrete implementations such as ECSWsolverNNLS.
ecsw_solver: ECSWsolver object corresponding to a child class with concrete implementations such as ECSWsolverNNLS.
full_mesh_lhs: (n_snap*n_rom, n_dof) numpy ndarray, where n_snap is the number of residual snapshots, n_rom is the ROM dimension, and n_dof is the number of mesh degrees of freedom (DoFs) (nodes, volumes, or elements)
full_mesh_rhs: (n_snap*n_rom,) numpy array
tolerance: Double, the ECSW tolerance parameter. Lower values of tolerance will result in more mesh DoF samples
Expand Down
44 changes: 22 additions & 22 deletions romtools/trial_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@

import abc
import numpy as np
from romtools.trial_space_utils.truncater import AbstractTruncater, NoOpTruncater
from romtools.trial_space_utils.shifter import AbstractShifter, NoOpShifter
from romtools.trial_space_utils.scaler import AbstractScaler
from romtools.trial_space_utils.splitter import AbstractSplitter, NoOpSplitter
from romtools.trial_space_utils.orthogonalizer import AbstractOrthogonalizer, NoOpOrthogonalizer
from romtools.trial_space_utils.truncater import Truncater, NoOpTruncater
from romtools.trial_space_utils.shifter import Shifter, NoOpShifter
from romtools.trial_space_utils.scaler import Scaler
from romtools.trial_space_utils.splitter import Splitter, NoOpSplitter
from romtools.trial_space_utils.orthogonalizer import Orthogonalizer, NoOpOrthogonalizer


class AbstractTrialSpace(abc.ABC):
class TrialSpace(abc.ABC):
'''
Abstract base class for trial space implementations.

Expand Down Expand Up @@ -142,7 +142,7 @@ def matrix_to_tensor(n_var, matrix_input):
return output_matrix


class DictionaryTrialSpace(AbstractTrialSpace):
class DictionaryTrialSpace(TrialSpace):
'''
##Reduced basis trial space (no truncation).

Expand Down Expand Up @@ -205,7 +205,7 @@ def get_basis(self):
return self.__basis


class TrialSpaceFromPOD(AbstractTrialSpace):
class TrialSpaceFromPOD(TrialSpace):
'''
##POD trial space (constructed via SVD).

Expand All @@ -225,20 +225,20 @@ class TrialSpaceFromPOD(AbstractTrialSpace):

def __init__(self,
snapshot_tensor,
truncater: AbstractTruncater = NoOpTruncater(),
shifter: AbstractShifter = NoOpShifter(),
splitter: AbstractSplitter = NoOpSplitter(),
orthogonalizer: AbstractOrthogonalizer = NoOpOrthogonalizer(),
truncater: Truncater = NoOpTruncater(),
shifter: Shifter = NoOpShifter(),
splitter: Splitter = NoOpSplitter(),
orthogonalizer: Orthogonalizer = NoOpOrthogonalizer(),
svdFnc = None):
'''
Constructor for the POD trial space.

Args:
snapshot_tensor (np.ndarray): Snapshot data tensor
truncater (AbstractTruncater): Class that truncates the basis.
shifter (AbstractShifter): Class that shifts the basis.
splitter (AbstractSplitter): Class that splits the basis.
orthogonalizer (AbstractOrthogonalizer): Class that orthogonalizes
truncater (Truncater): Class that truncates the basis.
shifter (Shifter): Class that shifts the basis.
splitter (Splitter): Class that splits the basis.
orthogonalizer (Orthogonalizer): Class that orthogonalizes
the basis.
svdFnc: a callable to use for computing the SVD on the snapshots data.
IMPORTANT: must conform to the API of [np.linalg.svd](https://numpy.org/doc/stable/reference/generated/numpy.linalg.svd.html#numpy-linalg-svd).
Expand Down Expand Up @@ -296,7 +296,7 @@ def get_basis(self):
return self.__basis


class TrialSpaceFromScaledPOD(AbstractTrialSpace):
class TrialSpaceFromScaledPOD(TrialSpace):
'''
##POD trial space (constructed via scaled SVD).

Expand All @@ -315,11 +315,11 @@ class TrialSpaceFromScaledPOD(AbstractTrialSpace):
'''

def __init__(self, snapshot_tensor,
truncater: AbstractTruncater,
shifter: AbstractShifter,
scaler: AbstractScaler,
splitter: AbstractSplitter,
orthogonalizer: AbstractOrthogonalizer):
truncater: Truncater,
shifter: Shifter,
scaler: Scaler,
splitter: Splitter,
orthogonalizer: Orthogonalizer):
'''
Constructor for the POD trial space constructed via scaled SVD.

Expand Down
8 changes: 4 additions & 4 deletions romtools/trial_space_utils/orthogonalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import scipy.sparse


class AbstractOrthogonalizer(abc.ABC):
class Orthogonalizer(abc.ABC):
'''
Abstract base class
'''
Expand All @@ -68,7 +68,7 @@ def __call__(self, my_array: np.ndarray) -> np.ndarray:
pass


class NoOpOrthogonalizer(AbstractOrthogonalizer):
class NoOpOrthogonalizer(Orthogonalizer):
'''
No op class (doesn't do anything)
'''
Expand All @@ -79,7 +79,7 @@ def __call__(self, my_array: np.ndarray):
return my_array


class EuclideanL2Orthogonalizer(AbstractOrthogonalizer):
class EuclideanL2Orthogonalizer(Orthogonalizer):
'''
Orthogonalizes the basis in the standard Euclidean L2 inner product, i.e.,
the output basis will satisfy
Expand All @@ -104,7 +104,7 @@ def __call__(self, my_array: np.ndarray):
return my_array


class EuclideanVectorWeightedL2Orthogonalizer(AbstractOrthogonalizer):
class EuclideanVectorWeightedL2Orthogonalizer(Orthogonalizer):
'''
Orthogonalizes the basis in vector-weighted Euclidean L2 inner product,
i.e., the output basis will satisfy
Expand Down
14 changes: 7 additions & 7 deletions romtools/trial_space_utils/outputter.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import os
import math
import numpy as np
from romtools.trial_space import AbstractTrialSpace
from romtools.trial_space import TrialSpace

try:
import exodus
Expand All @@ -59,13 +59,13 @@
pass


def npz_output(filename: str, trial_space: AbstractTrialSpace, compress=True) -> None:
def npz_output(filename: str, trial_space: TrialSpace, compress=True) -> None:
'''
Save trial space information to a compressed or uncompressed NumPy .npz file.

Args:
filename (str): The name of the output file.
trial_space (AbstractTrialSpace): The trial space containing shift and basis information.
trial_space (TrialSpace): The trial space containing shift and basis information.
compress (bool, optional): Whether to compress the output file (default is True).

Example:
Expand All @@ -81,13 +81,13 @@ def npz_output(filename: str, trial_space: AbstractTrialSpace, compress=True) ->
basis=trial_space.get_basis())


def hdf5_output(output_filename: str, trial_space: AbstractTrialSpace) -> None:
def hdf5_output(output_filename: str, trial_space: TrialSpace) -> None:
'''
Save trial space information to an HDF5 file.

Args:
output_filename (str): The name of the output HDF5 file.
trial_space (AbstractTrialSpace): The trial space containing shift and basis information.
trial_space (TrialSpace): The trial space containing shift and basis information.

Example:
hdf5_output("trial_space.h5", my_trial_space)
Expand All @@ -97,14 +97,14 @@ def hdf5_output(output_filename: str, trial_space: AbstractTrialSpace) -> None:
f.create_dataset('basis', data=trial_space.get_basis())


def exodus_ouput(output_filename: str, mesh_filename: str, trial_space: AbstractTrialSpace, var_names: list = None) -> None:
def exodus_ouput(output_filename: str, mesh_filename: str, trial_space: TrialSpace, var_names: list = None) -> None:
'''
Save trial space information to an Exodus file.

Args:
output_filename (str): The name of the output Exodus file.
mesh_filename (str): The name of the mesh file.
trial_space (AbstractTrialSpace): The trial space containing shift and basis information.
trial_space (TrialSpace): The trial space containing shift and basis information.
var_names (list, optional): A list of variable names (default is None).

Example:
Expand Down
10 changes: 5 additions & 5 deletions romtools/trial_space_utils/scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
import numpy as np


class AbstractScaler(abc.ABC):
class Scaler(abc.ABC):
'''
Abstract base class
'''
Expand All @@ -95,7 +95,7 @@ def post_scaling(self, data_tensor: np.ndarray) -> np.ndarray:
pass


class NoOpScaler(AbstractScaler):
class NoOpScaler(Scaler):
'''
No op implementation
'''
Expand All @@ -109,7 +109,7 @@ def post_scaling(self, data_tensor):
return data_tensor


class VectorScaler(AbstractScaler):
class VectorScaler(Scaler):
'''
Concrete implementation designed to scale snapshot matrices by a vector.
For a snapshot tensor $\\mathbf{S} \\in \\mathbb{R}^{N_{\\mathrm{u}} \\times N \\times K}$, the VectorScaler
Expand Down Expand Up @@ -162,7 +162,7 @@ def post_scaling(self, data_tensor):
return self.__scaling_vector_matrix[None, :, None] * data_tensor


class VariableScaler(AbstractScaler):
class VariableScaler(Scaler):
'''
Concrete implementation designed for snapshot matrices involving multiple
state variables.
Expand Down Expand Up @@ -259,7 +259,7 @@ def post_scaling(self, data_tensor):
return data_tensor


class VariableAndVectorScaler(AbstractScaler):
class VariableAndVectorScaler(Scaler):
'''
Concrete implementation designed to scale snapshot matrices involving
multiple state variables by both the variable magnitudes and an additional
Expand Down
12 changes: 6 additions & 6 deletions romtools/trial_space_utils/shifter.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
import numpy as np


class AbstractShifter(abc.ABC):
class Shifter(abc.ABC):
'''
Abstract implmentation
'''
Expand All @@ -76,7 +76,7 @@ def __call__(self, my_array: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
pass


class NoOpShifter(AbstractShifter):
class NoOpShifter(Shifter):
'''
No op implementation
'''
Expand All @@ -88,7 +88,7 @@ def __call__(self, my_array: np.ndarray):
return my_array, shift_vector


class ConstantShifter(AbstractShifter):
class ConstantShifter(Shifter):
'''
Shifts the data by a constant value.
'''
Expand Down Expand Up @@ -118,7 +118,7 @@ def __call__(self, my_array: np.ndarray):
return my_array-shift_vector[:, :, None], shift_vector


class VectorShifter(AbstractShifter):
class VectorShifter(Shifter):
'''
Shifts the data by a user-input vector.
'''
Expand All @@ -135,7 +135,7 @@ def __call__(self, my_array: np.ndarray):
return my_array-self.__shift_vector[..., None], self.__shift_vector


class AverageShifter(AbstractShifter):
class AverageShifter(Shifter):
'''
Shifts the data by the average of a data matrix.
'''
Expand All @@ -147,7 +147,7 @@ def __call__(self, my_array: np.ndarray):
return my_array-shift_vector[:, :, None], shift_vector


class FirstVecShifter(AbstractShifter):
class FirstVecShifter(Shifter):
'''
Shifts the data by the first vector of a data matrix.
'''
Expand Down
6 changes: 3 additions & 3 deletions romtools/trial_space_utils/splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@
import numpy as np


class AbstractSplitter(abc.ABC):
class Splitter(abc.ABC):
'''Abstract class for a splitter'''

@abc.abstractmethod
def __call__(self, my_array: np.ndarray) -> np.ndarray:
pass


class NoOpSplitter(AbstractSplitter):
class NoOpSplitter(Splitter):
'''Concrete no-op implementation'''
def __init__(self) -> None:
pass
Expand All @@ -103,7 +103,7 @@ def __call__(self, my_array: np.ndarray):
return my_array


class BlockSplitter(AbstractSplitter):
class BlockSplitter(Splitter):
'''
Splits a data matrix into blocks defined by a list, e.g., for our Euler
equation example above, we could set
Expand Down
Loading