-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinite_differences.py
41 lines (35 loc) · 1.22 KB
/
finite_differences.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
This is the finite differnces engine.
It runs the given time step operator for a given time.
"""
class FiniteDifferences(object):
def __init__(self, fill_distance, time_step, operator, initial_value):
self._fill_distance = fill_distance
self._time_step = time_step
self._operator = operator
self._initial_value = initial_value
self._current_state = self._initial_value
self._current_time = 0
self._all_states = list()
self.last_plot = 0
def tick(self):
self._all_states.append(self._current_state)
self._current_state = self._operator(
self._current_state, self._all_states, self._current_time
)
self._current_time += self._time_step
# if self._current_time - self.last_plot > 0.05:
# plt.plot(self._current_state)
# plt.title(f"Time: {self._current_time}")
# plt.show()
self.last_plot = self._current_time
def run(self, final_time):
while self._current_time < final_time + self._time_step:
self.tick()
# pass
@property
def state(self):
return self._current_state
@property
def time(self):
return self._current_time