Skip to content

Commit eea21fb

Browse files
Added code
1 parent 196cc62 commit eea21fb

14 files changed

+1727
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Running the code
2+
3+
Run the code by typing ```python main.py```. You need numpy and scipy for executing the code. Output folders with experimental results are created. The folders are named in the following way: ```seriesX_SHORTNAME_DATETIME```. See below for details on the different experimental series.
4+
5+
You can plot the results by running ```python postproc.py <foldername>```. You need matplotlib for plotting.
6+
7+
# Convergence Study
8+
9+
This code can be used to perform convergence studies in a partitioned multi-physics multi-scale setup. As a benchmark scenario the 1D heat transport equations is solved. For details see [1]. The convergence studies performed by this code are identical to the ones described in [1]. However, for a lower runtime, the discretization slightly differs for [1].
10+
11+
## Experimental Series 1
12+
13+
Order degradation to first order if classical implicit coupling is used with higher order schemes a regular domain
14+
15+
![](./series1.png)
16+
17+
## Experimental Series 2
18+
19+
Second order if customized coupling schemes are used with second order schemes a regular domain
20+
21+
![](./series2.png)
22+
23+
## Experimental Series 3
24+
25+
Second order if Strang splitting coupling is used with higher order schemes on a non-regular domain
26+
27+
![](./series3.png)
28+
29+
## Experimental Series 4
30+
31+
High order if waveform relaxation coupling is used with higher order schemes on a non-regular domain
32+
33+
![](./series4.png)
34+
35+
# Reference
36+
37+
If you want to refer to this code, please use the following reference:
38+
39+
[1] Rüth, B., Uekermann, B., Mehl, M., & Bungartz, H.-J. (2018). Time Stepping Algorithms for Partitioned Multi-Scale Multi-Physics. In ??? Glasgow: ???

coupling_schemes.py

Lines changed: 586 additions & 0 deletions
Large diffs are not rendered by default.

domain.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import numpy as np
2+
import abc
3+
from time_integration import TimeIntegrationScheme
4+
5+
6+
class Domain():
7+
__metaclass__ = abc.ABCMeta
8+
9+
def __init__(self, grid):
10+
"""
11+
Simulation domain with a grid, corresponding function values u, boundary conditions and a time integration scheme
12+
:param grid: grid discretizing domain
13+
:type grid: OneDimensionalGrid
14+
"""
15+
self.grid = grid
16+
self.u = np.zeros(self.grid.N_gridpoints) # :type : np.array
17+
self.left_BC = {}
18+
self.right_BC = {}
19+
self.time_integration_scheme = None # :type : TimeIntegrationScheme
20+
21+
def update_u(self, new_u):
22+
"""
23+
updates u on the domain
24+
:param new_u:
25+
:type new_u: np.array
26+
:return:
27+
"""
28+
assert self.u.shape == new_u.shape
29+
self.u = new_u
30+
31+
32+
class OneDimensionalGrid():
33+
__metaclass__ = abc.ABCMeta
34+
35+
def __init__(self, x):
36+
"""
37+
:param x: array of points on 1D grid
38+
"""
39+
self.x = np.array(x)
40+
self.N_gridpoints = self.x.__len__() # :type : int
41+
self.x_left = self.x[0] # :type : float
42+
self.x_right = self.x[-1] # :type : float
43+
44+
45+
class RegularGrid(OneDimensionalGrid):
46+
47+
def __init__(self, N_gridpoints, x_left, x_right):
48+
"""
49+
Regular grid with N_gridpoints between x_left and x_right
50+
:param N_gridpoints: number of gridpoints
51+
:type N_gridpoints: int
52+
:param x_left: leftmost coordinate
53+
:type x_left: float
54+
:param x_right: rightmost coordinate
55+
:type x_right: float
56+
"""
57+
# meshwidth of grid
58+
self.h = (x_right - x_left) / (N_gridpoints-1) # :type : float
59+
# vector of mesh points
60+
x = np.linspace(x_left, x_right, N_gridpoints) # :type : np.array
61+
super(RegularGrid, self).__init__(x)
62+
63+
64+
class IrregularGrid(OneDimensionalGrid):
65+
66+
def __init__(self, x):
67+
"""
68+
Irregular grid defined by ascending vector of gridpoints
69+
:param x: vector of gridpoints
70+
"""
71+
super(IrregularGrid, self).__init__(x)

experiment_documentation.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import datetime
2+
import json
3+
import os
4+
5+
6+
class Experiment():
7+
def __init__(self, name, h, tau, errors_left, errors_right, additional_numerical_parameters = None):
8+
self.h = h
9+
self.temporal_resolution = tau
10+
self.numerical_parameters = additional_numerical_parameters
11+
self.errors_left = errors_left
12+
self.errors_right = errors_right
13+
self.time = datetime.datetime.now().strftime("%Y-%m-%d--%H-%M-%S_%f")
14+
self.experiment_name = name
15+
16+
def save(self, save_path):
17+
if not os.path.exists(save_path): # create empty directory
18+
os.mkdir(save_path)
19+
20+
filename = save_path + "/" + self.experiment_name + "_" + self.time + ".json"
21+
with open(filename, 'w') as outfile:
22+
s = json.dumps(self.__dict__, outfile)
23+
outfile.write(s)

finite_difference_schemes.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
def central_FD_at(i, h, u, derivative=1, order=2):
2+
"""
3+
computes the n_th central finite difference at x_i on the basis of u_i.
4+
:param i:
5+
:param h:
6+
:param u:
7+
:param derivative:
8+
:param order:
9+
:return:
10+
"""
11+
12+
du = 0
13+
14+
if derivative == 1:
15+
if order == 2:
16+
du = 1.0/(2.0 * h) * (-1.0 * u[i-1] + 1.0 * u[i+1])
17+
else:
18+
print "not implemented!"
19+
else:
20+
print "not implemented!"
21+
22+
return du
23+
24+
25+
def one_sided_forward_FD_at(i, h, u, derivative=1, order=1):
26+
"""
27+
computes the n_th one-sided forward finite difference derivative at x_i on the basis of u_i.
28+
29+
Coefficients from https://en.wikipedia.org/wiki/Finite_difference_coefficient
30+
31+
d^n u/dn (x_i)= a*u_i + b*u_i+1 + c*u_i+2 + ...
32+
33+
:param i:
34+
:param u:
35+
:param order:
36+
:param derivative:
37+
:return:
38+
"""
39+
40+
du = 0
41+
42+
if derivative == 1:
43+
if order == 1:
44+
du = 1.0/h * (- 1.0 * u[i] + 1.0 * u[i+1] )
45+
elif order == 2:
46+
du = 1.0/h * (-1.5 * u[i] + 2.0 * u[i+1] - 0.5 * u[i+2])
47+
elif order == 3:
48+
du = 1.0/h * (-11.0/6.0 * u[i] + 3.0 * u[i+1] - 3.0/2.0 * u[i+2] + 1.0/3.0 * u[i+3])
49+
elif order == 4:
50+
du = 1.0/h * (-25.0/12.0 * u[i] + 4.0 * u[i+1] - 3.0 * u[i+2] + 4.0/3.0 * u[i+3] - 1.0/4.0 * u[i+4])
51+
elif order == 5:
52+
du = 1.0/h * (-137.0/60.0 * u[i] + 5.0 * u[i+1] - 5.0 * u[i+2] + 10.0/3.0 * u[i+3] - 5.0/4.0 * u[i+4] + 1.0/5.0 * u[i+5])
53+
else:
54+
print "not implemented!"
55+
else:
56+
print "not implemented!"
57+
58+
return du

0 commit comments

Comments
 (0)