From 047fd9ec0cfef1138f661cee95fa63edd3ce3ef4 Mon Sep 17 00:00:00 2001 From: Ludger Paehler Date: Sat, 16 Mar 2024 01:05:14 -0700 Subject: [PATCH] Yank modred from the package as it is unused. --- hydrogym/firedrake/utils/linalg.py | 83 -------------------- hydrogym/firedrake/utils/modred_interface.py | 44 ----------- pyproject.toml | 1 - 3 files changed, 128 deletions(-) delete mode 100644 hydrogym/firedrake/utils/modred_interface.py diff --git a/hydrogym/firedrake/utils/linalg.py b/hydrogym/firedrake/utils/linalg.py index 54df8e3..a7fdd2d 100644 --- a/hydrogym/firedrake/utils/linalg.py +++ b/hydrogym/firedrake/utils/linalg.py @@ -4,7 +4,6 @@ import numpy as np import ufl from firedrake import logging -from modred import PODHandles, VectorSpaceHandles from scipy import sparse # Type suggestions @@ -91,88 +90,6 @@ def inner_product(u, v): return inner_product -def pod( - flow: FlowConfig, - snapshot_handles: Iterable[Snapshot], - r: int, - mass_matrix, - decomp_indices=None, - remove_mean=True, - mean_dest="mean", - atol=1e-13, - rtol=None, - max_vecs_per_node=None, - verbosity=1, - output_dir=".", - modes_dest="pod", - eigvals_dest="eigvals.dat", - pvd_dest=None, - coeffs_dest="coeffs.dat", - field_name="q", -): - """ - Args: - ``flow``: ``FlowConfig`` for the POD (used for weighted inner product) - - ``snapshots``: List of Snapshot handles - - ``r``: Number of modes to compute - - Kwargs: - ``decomp_indices``: Indices to use in method of snapshots (defaults to ``range(r)``) - - NOTE: could actually take the "flow" dependence out if we replaced the PVD with a postprocessing callback... - """ - if fd.COMM_WORLD.size > 1: - raise NotImplementedError("Not yet supported in parallel") - - # Compute actual POD - if decomp_indices is None: - decomp_indices = range(r) - - inner_product = define_inner_product(mass_matrix) - - if remove_mean: - base_vec_handle = Snapshot(f"{output_dir}/{mean_dest}") - base_vec_handle.put(vec_handle_mean(snapshot_handles)) - - # Redefine snapshots with mean subtraction - snapshot_handles = [ - Snapshot(snap.filename, base_vec_handle=base_vec_handle) - for snap in snapshot_handles - ] - logging.log(logging.DEBUG, "Mean subtracted") - - logging.log(logging.DEBUG, "Computing POD") - POD = PODHandles( - inner_product=inner_product, - max_vecs_per_node=max_vecs_per_node, - verbosity=verbosity, - ) - POD.compute_decomp(snapshot_handles, atol=atol, rtol=rtol) - - # Vector handles for storing snapshots - mode_handles = [ - Snapshot(filename=f"{output_dir}/{modes_dest}{i}") for i in range(r) - ] - POD.compute_modes(range(r), mode_handles) - - POD.put_eigvals(f"{output_dir}/{eigvals_dest}") - - # Save for visualization - if pvd_dest is not None: - pvd = fd.File(f"{output_dir}/{pvd_dest}", "w") - for i, mode in enumerate(mode_handles): - u, p = mode.get().as_function().subfunctions - pvd.write(u, p, flow.vorticity(u)) - - # Compute temporal coefficients - coeffs = POD.compute_proj_coeffs().T # If all snapshots used for POD - np.savetxt(f"{output_dir}/{coeffs_dest}", coeffs, fmt="%0.6f", delimiter="\t") - - return coeffs, mode_handles - - def project(basis_handles, data_handles, mass_matrix): inner_product = define_inner_product(mass_matrix) vec_space = VectorSpaceHandles(inner_product) diff --git a/hydrogym/firedrake/utils/modred_interface.py b/hydrogym/firedrake/utils/modred_interface.py deleted file mode 100644 index 3e365aa..0000000 --- a/hydrogym/firedrake/utils/modred_interface.py +++ /dev/null @@ -1,44 +0,0 @@ -import firedrake as fd -import modred as mr -import numpy as np - -from .utils import set_from_array - - -class Snapshot(mr.VecHandle): - """Interface between time series in numpy binaries and modred""" - - def __init__(self, filename: str, base_vec_handle=None, scale=None): - super().__init__(base_vec_handle=base_vec_handle, scale=scale) - - if filename[-4:] != ".npy": - filename += ".npy" - self.filename = filename - - def _get(self, filename=None): - # with fd.CheckpointFile(self.filename, 'r') as chk: - # q = chk.load_function(self.flow.mesh, name=self.name, idx=self.idx) - if filename is None: - filename = self.filename - return np.load(filename) - - def _put(self, q, filename=None): - if filename is None: - filename = self.filename - np.save(filename, q) - - def as_function(self, flow): - if fd.COMM_WORLD.size > 1: - raise NotImplementedError - - q = fd.Function(flow.mixed_space) - set_from_array(q, self.get()) - return q - - -def vec_handle_mean(vec_handles): - """Compute the mean of the vector handles and return as SnapshotVector""" - from functools import reduce - - data = [h.get() for h in vec_handles] - return reduce(lambda x1, x2: x1 + x2, data) * (1 / len(data)) diff --git a/pyproject.toml b/pyproject.toml index 656be1e..cdff794 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,7 +45,6 @@ control = "^0.9.2" dmsuite = "^0.1.1" gmsh = "^4.11.1" gym = "^0.26.2" -modred = "^2.1.0" python = "^3.10" torch = "^2.0"