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

Restructure ReferenceBase/SolutionBase #105

Open
schmoelder opened this issue Mar 14, 2024 · 2 comments
Open

Restructure ReferenceBase/SolutionBase #105

schmoelder opened this issue Mar 14, 2024 · 2 comments
Milestone

Comments

@schmoelder
Copy link
Contributor

  • What interfaces must be implemented by which subclasses (e.g. resampling, smoothing, slicing etc.?)
  • Alternatively, unify everything in SolutionBase and make use of internal dimensions.
@schmoelder
Copy link
Contributor Author

As mentioned, for this endeavor, we should also reconsider the resampling / interpolation methods of Solution objects. Currently, this is only possible for 1D solutions (i.e. SolutionIO). However, we might want to also do this with ND-objects.

Here is a prototype that works for multiple dimensions:

import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import RegularGridInterpolator
from scipy import stats

time = np.linspace(0, 10, 11)
axial_positions = np.linspace(0, 1, 5)
components = np.arange(0, 2)

dimensions = {
    'time': np.linspace(0, 10, 11),
    'axial_positions': np.linspace(0, 10, 11),
    # 'radial_positions': np.linspace(0, 10, 11),
    'channels': [0, 1, 2],
    'components': ['A', 'B'],
}

continuous_dimensions = [key for key, value in dimensions.items() if isinstance(value, np.ndarray)]
discrete_dimensions = [key for key, value in dimensions.items() if not isinstance(value, np.ndarray)]

fig, ax = plt.subplots()

c = np.zeros((len(time), len(axial_positions), len(components)))

for i in range(len(axial_positions)):
    solution = stats.norm.pdf(time, i + 3, 1)
    c[:, i, 1] = solution
    ax.plot(time, solution)

interpolators = []
for comp in components:
    interp = RegularGridInterpolator((time, axial_positions), c[..., comp], method='linear')
    interpolators.append(interp)

time_new = np.linspace(0, 10, 101)
axial_directions_new = np.linspace(0, 1, 11)

arrs = np.meshgrid(time_new, axial_directions_new, indexing='ij')

test_points = np.array([dim.ravel() for dim in arrs]).T

foo = interpolators[1](test_points).reshape(len(time_new), len(axial_directions_new))
for i in range(len(axial_directions_new)):
    solution = foo[:, i]
    ax.plot(time_new, solution, 'k--')

A challenge here is that we have independent (i.e. discrete) dimensions (e.g. components, channels) and continuous dimensions (space-time). While for interpolation, we only want to interpolate between the continuous dimensions, we still want to provide a uniform interface...

Tagging @hannahlanzrath

@schmoelder schmoelder added this to the v0.11.0 milestone Dec 5, 2024
@schmoelder
Copy link
Contributor Author

Some work on this was done in cadet/CADET-Python-Simulator#19.

I think, we could migrate this to CADET-Process.
For this purpose, we should

  • Improve testing the Field class
  • Include the state structure / coordinates in the different UnitOperation implementations in CADET-Process, which could/should also be used for initial conditions
  • Open question: How to provide backwards compatibility / How to structure simple setters (e.g. set all to 0) / Automatically interpolate?
  • Derive a Solution implementation from state structure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant