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 unused variables #77

Merged
merged 4 commits into from
Jul 16, 2023
Merged
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
36 changes: 25 additions & 11 deletions eulerpi/examples/heat/heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,30 @@ def forward(cls, param: np.ndarray) -> np.ndarray:

solution = cls.perform_simulation(kappa=param)

# the indices of the wanted evaluation points
evaluation_indices = jnp.multiply(
cls.evaluation_points,
jnp.array(solution.shape),
).astype(int)

solution_at_evaluation_points = jnp.array(
solution[
evaluation_indices[:, 0],
evaluation_indices[:, 1],
]
# linearly interpolate the solution at the evaluation points, use own interpolation function as jax doesn't support scipy.interpolate.interp2d and doesn't provide a 2d interpolation function
x = jnp.linspace(0, cls.plate_length[0], cls.num_grid_points)
y = jnp.linspace(0, cls.plate_length[1], cls.num_grid_points)

# compute the indices between which the evaluation points lie
x_indices = jnp.searchsorted(x, cls.evaluation_points[:, 0]) - 1
y_indices = jnp.searchsorted(y, cls.evaluation_points[:, 1]) - 1
dx = cls.plate_length[0] / cls.num_grid_points
dy = cls.plate_length[1] / cls.num_grid_points

# interpolate the solution at the evaluation points
solution_at_evaluation_points = (1 / (dx * dy)) * (
solution[x_indices, y_indices]
* (x[x_indices + 1] - cls.evaluation_points[:, 0])
* (y[y_indices + 1] - cls.evaluation_points[:, 1])
+ solution[x_indices + 1, y_indices]
* (cls.evaluation_points[:, 0] - x[x_indices])
* (y[y_indices + 1] - cls.evaluation_points[:, 1])
+ solution[x_indices, y_indices + 1]
* (x[x_indices + 1] - cls.evaluation_points[:, 0])
* (cls.evaluation_points[:, 1] - y[y_indices])
+ solution[x_indices + 1, y_indices + 1]
* (cls.evaluation_points[:, 0] - x[x_indices])
* (cls.evaluation_points[:, 1] - y[y_indices])
)
return solution_at_evaluation_points

Expand Down Expand Up @@ -196,6 +209,7 @@ class HeatArtificial(Heat, ArtificialModelInterface):

CENTRAL_PARAM = np.array([1.5, 1.5, 0.5])
PARAM_LIMITS = np.array([[1.0, 2.0], [1.0, 2.0], [0.0, 1.0]])
num_grid_points = 20

def __init__(
self,
Expand Down