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

explicit time dependence #6

Open
wants to merge 1 commit into
base: master
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
16 changes: 8 additions & 8 deletions pde_superresolution_2d/advection/equations.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def __init__(self, *args, **kwargs):
super(FiniteDifferenceAdvectionDiffusion, self).__init__(*args, **kwargs)

def time_derivative(
self, grid, concentration, x_velocity, y_velocity, concentration_x,
self, time, grid, concentration, x_velocity, y_velocity, concentration_x,
concentration_y, concentration_xx, concentration_yy):
"""See base class."""
del grid, concentration # unused
Expand Down Expand Up @@ -331,7 +331,7 @@ def __init__(self, *args, **kwargs):
super(FiniteDifferenceAdvection, self).__init__(*args, **kwargs)

def time_derivative(
self, grid, concentration, x_velocity, y_velocity,
self, time, grid, concentration, x_velocity, y_velocity,
concentration_x, concentration_y):
"""See base class."""
del grid, concentration # unused
Expand Down Expand Up @@ -378,7 +378,7 @@ def __init__(self, *args, **kwargs):
super(FiniteVolumeAdvectionDiffusion, self).__init__(*args, **kwargs)

def time_derivative(
self, grid, concentration, x_velocity, y_velocity, concentration_edge_x,
self, time, grid, concentration, x_velocity, y_velocity, concentration_edge_x,
concentration_edge_y, concentration_x_edge_x, concentration_y_edge_y):
"""See base class."""
del concentration # unused
Expand Down Expand Up @@ -412,7 +412,7 @@ def __init__(self, *args, **kwargs):
super(FiniteVolumeAdvection, self).__init__(*args, **kwargs)

def time_derivative(
self, grid, concentration, x_velocity, y_velocity, concentration_edge_x,
self, time, grid, concentration, x_velocity, y_velocity, concentration_edge_x,
concentration_edge_y):
"""See base class."""
del concentration # unused
Expand Down Expand Up @@ -445,7 +445,7 @@ def __init__(self, *args, **kwargs):
super(UpwindAdvectionDiffusion, self).__init__(*args, **kwargs)

def time_derivative(
self, grid, concentration, x_velocity, y_velocity, concentration_x_edge_x,
self, time, grid, concentration, x_velocity, y_velocity, concentration_x_edge_x,
concentration_y_edge_y):
"""See base class."""
c = concentration
Expand Down Expand Up @@ -479,7 +479,7 @@ def __init__(self, *args, **kwargs):
self.constant_keys = {'x_velocity', 'y_velocity'}
super(UpwindAdvection, self).__init__(*args, **kwargs)

def time_derivative(self, grid, concentration, x_velocity, y_velocity):
def time_derivative(self, time, grid, concentration, x_velocity, y_velocity):
"""See base class."""
c = concentration
c_right = tensor_ops.roll_2d(c, (-1, 0))
Expand Down Expand Up @@ -606,7 +606,7 @@ def __init__(self, *args, **kwargs):
super(VanLeerMono5AdvectionDiffusion, self).__init__(*args, **kwargs)

def take_time_step(
self, grid, concentration, x_velocity, y_velocity, concentration_x_edge_x,
self, time, grid, concentration, x_velocity, y_velocity, concentration_x_edge_x,
concentration_y_edge_y):
"""See base class."""
dx = dy = grid.step
Expand Down Expand Up @@ -658,7 +658,7 @@ def __init__(self, *args, **kwargs):

super(VanLeerAdvection, self).__init__(*args, **kwargs)

def take_time_step(self, grid, concentration, x_velocity, y_velocity):
def take_time_step(self, time, grid, concentration, x_velocity, y_velocity):
"""See base class."""
dx = dy = grid.step
dt = self.get_time_step(grid)
Expand Down
6 changes: 3 additions & 3 deletions pde_superresolution_2d/core/equations.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def find_base_key(self, key: str) -> str:
raise AssertionError # should be impossible per _validate_keys()

def time_derivative(
self, grid: grids.Grid, **inputs: tf.Tensor
self, time: tf.float32, grid: grids.Grid, **inputs: tf.Tensor
) -> Dict[str, tf.Tensor]:
"""Returns time derivative of the given state.

Expand All @@ -174,7 +174,7 @@ def time_derivative(
raise NotImplementedError

def take_time_step(
self, grid: grids.Grid, **inputs: tf.Tensor
self, time: tf.float32, grid: grids.Grid, **inputs: tf.Tensor
) -> Dict[str, tf.Tensor]:
"""Take single time-step.

Expand All @@ -189,7 +189,7 @@ def take_time_step(
Returns:
Updated values for each non-constant term in the state.
"""
time_derivs = self.time_derivative(grid, **inputs)
time_derivs = self.time_derivative(time, grid, **inputs)
dt = self.get_time_step(grid)
new_state = {k: inputs[k] + dt * time_derivs[k]
for k in self.evolving_keys}
Expand Down
3 changes: 1 addition & 2 deletions pde_superresolution_2d/core/integrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ def integrate_steps(
if k in model.equation.evolving_keys}

def advance_one_step(evolving_state, time):
del time # unused
inputs = dict(evolving_state)
inputs.update(constant_state)
outputs = model.take_time_step(inputs)
outputs = model.take_time_step(time, inputs)
return outputs

def advance_until_saved_step(evolving_state, start_stop):
Expand Down
13 changes: 7 additions & 6 deletions pde_superresolution_2d/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def advance(evolving_state, _):
return advanced

def time_derivative(
self, state: Mapping[str, tf.Tensor]) -> Dict[str, tf.Tensor]:
self, time: tf.float32, state: Mapping[str, tf.Tensor]) -> Dict[str, tf.Tensor]:
"""Compute the time derivative.

Args:
Expand All @@ -136,10 +136,11 @@ def time_derivative(
raise NotImplementedError

def take_time_step(
self, state: Mapping[str, tf.Tensor]) -> Dict[str, tf.Tensor]:
self, time: tf.float32, state: Mapping[str, tf.Tensor]) -> Dict[str, tf.Tensor]:
"""Take a single time-step.

Args:
time: current time
state: current state of the solution.

Returns:
Expand Down Expand Up @@ -169,17 +170,17 @@ def spatial_derivatives(
raise NotImplementedError

def time_derivative(
self, state: Mapping[str, tf.Tensor]) -> Dict[str, tf.Tensor]:
self, time: tf.float32, state: Mapping[str, tf.Tensor]) -> Dict[str, tf.Tensor]:
"""See base class."""
inputs = self.spatial_derivatives(state)
outputs = self.equation.time_derivative(self.grid, **inputs)
outputs = self.equation.time_derivative(time, self.grid, **inputs)
return outputs

def take_time_step(
self, state: Mapping[str, tf.Tensor]) -> Dict[str, tf.Tensor]:
self, time: tf.float32, state: Mapping[str, tf.Tensor]) -> Dict[str, tf.Tensor]:
"""See base class."""
inputs = self.spatial_derivatives(state)
outputs = self.equation.take_time_step(self.grid, **inputs)
outputs = self.equation.take_time_step(time, self.grid, **inputs)
return outputs


Expand Down