Skip to content

Commit 8a21819

Browse files
Compatibility update for v3.0.0 (#153)
* Remove API functions that are removed in v3.0.0. Fix data initialization. * Forward dt to python bindings. * Set mesh connectivity information only if it is required. Closes #138 * Update tests * Update links of contributors * Update CHANGELOG.md * Call checkpointing functions from the interface * Change required version of pyprecice to >=3.0.0.0 * Comment out nearest projection volume coupling. --------- Co-authored-by: Ishaan Desai <ishaandesai@gmail.com>
1 parent 283bba9 commit 8a21819

11 files changed

+242
-276
lines changed

.github/workflows/build-and-test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
run: |
3737
mkdir -p precice
3838
echo "from setuptools import setup" >> precice/setup.py
39-
echo "setup(name='pyprecice', version='2.0.2.1')" >> precice/setup.py
39+
echo "setup(name='pyprecice', version='3.0.0.0')" >> precice/setup.py
4040
python3 -m pip install ./precice/
4141
- name: Run unit tests
4242
run: python3 setup.py test -s tests.unit

.github/workflows/run-tutorials.yml

+10-10
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ on:
77
pull_request:
88
paths:
99
- '**'
10-
11-
jobs:
10+
11+
jobs:
1212
run_ht_simple:
1313
name: Run HT, simple
1414
runs-on: ubuntu-latest
15-
container: precice/precice
15+
container: precice/precice:develop
1616
steps:
1717
- name: Checkout Repository
18-
uses: actions/checkout@v2
18+
uses: actions/checkout@v2
1919
- name: Install Dependencies & FEniCS
2020
run: |
2121
apt-get -qq update
@@ -30,17 +30,17 @@ jobs:
3030
- name: Get tutorials
3131
run: git clone -b develop https://github.com/precice/tutorials.git
3232
- name: Run tutorial
33-
run: |
33+
run: |
3434
cd tutorials/partitioned-heat-conduction/fenics
35-
python3 heat.py -d & python3 heat.py -n
36-
35+
./run.sh -d & ./run.sh -n
36+
3737
run_ht_complex:
3838
name: Run HT, complex
3939
runs-on: ubuntu-latest
40-
container: precice/precice
40+
container: precice/precice:develop
4141
steps:
4242
- name: Checkout Repository
43-
uses: actions/checkout@v2
43+
uses: actions/checkout@v2
4444
- name: Install Dependencies & FEniCS
4545
run: |
4646
apt-get -qq update
@@ -57,4 +57,4 @@ jobs:
5757
- name: Run tutorial
5858
run: |
5959
cd tutorials/partitioned-heat-conduction-complex/fenics
60-
python3 heat.py -d -i complex & python3 heat.py -n -i complex
60+
./run.sh -d & ./run.sh -n

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# FEniCS-preCICE adapter changelog
22

3+
## latest
4+
5+
* Drop support for preCICE 2.x version, as this is a breaking release.
6+
* Update adapter to use preCICE v3 API [#153](https://github.com/precice/fenics-adapter/pull/153).
7+
* Remove functionality to define mesh connectivity in 2D cases in the form of triangles due to lack of testing and compatibility problems (might be added again). See [#162](https://github.com/precice/fenics-adapter/issues/162).
8+
39
## 1.4.0
410

511
* Adding CITATION.cff to link the adapter repository to the relevant publication in the journal SoftwareX.

fenicsprecice/adapter_core.py

+25-23
Original file line numberDiff line numberDiff line change
@@ -383,29 +383,26 @@ def edge_is_on(subdomain, this_edge):
383383
"""
384384
Check whether edge lies within subdomain
385385
"""
386-
assert(len(list(vertices(this_edge))) == 2)
386+
assert (len(list(vertices(this_edge))) == 2)
387387
return all([subdomain.inside(v.point(), True) for v in vertices(this_edge)])
388388

389-
vertices1_ids = []
390-
vertices2_ids = []
391-
edges_ids = []
389+
edge_vertices_ids = []
390+
fenics_edges_ids = []
392391

393392
for edge in edges(function_space.mesh()):
394393
if edge_is_on(coupling_subdomain, edge):
395394
v1, v2 = list(vertices(edge))
396395
if v1.global_index() in global_ids and v2.global_index() in global_ids:
397-
vertices1_ids.append(id_mapping[v1.global_index()])
398-
vertices2_ids.append(id_mapping[v2.global_index()])
399-
edges_ids.append(edge.index())
396+
edge_vertices_ids.append([id_mapping[v1.global_index()], id_mapping[v2.global_index()]])
397+
fenics_edges_ids.append(edge.index())
400398

401-
vertices1_ids = np.array(vertices1_ids)
402-
vertices2_ids = np.array(vertices2_ids)
403-
edges_ids = np.array(edges_ids)
399+
edge_vertices_ids = np.array(edge_vertices_ids)
400+
fenics_edges_ids = np.array(fenics_edges_ids)
404401

405-
return vertices1_ids, vertices2_ids, edges_ids
402+
return edge_vertices_ids, fenics_edges_ids
406403

407404

408-
def get_coupling_triangles(function_space, coupling_subdomain, precice_edge_dict):
405+
def get_coupling_triangles(function_space, coupling_subdomain, fenics_edge_ids, id_mapping):
409406
"""
410407
Extracts triangles of mesh which lie on the coupling region.
411408
@@ -415,31 +412,36 @@ def get_coupling_triangles(function_space, coupling_subdomain, precice_edge_dict
415412
Function space on which the finite element problem definition lives.
416413
coupling_subdomain : FEniCS Domain
417414
FEniCS domain of the coupling interface region.
418-
precice_edge_dict: dict
419-
Dictionary with FEniCS IDs of coupling mesh edges as keys and preCICE IDs of the edges as values
415+
fenics_edge_ids: numpy array
416+
Array with FEniCS IDs of coupling mesh edges
420417
421418
Returns
422419
-------
423-
edges : numpy array
424-
Array of edges indices (3 per triangle)
420+
vertex_ids : numpy array
421+
Array of indices of vertices which make up triangles (3 per triangle)
425422
"""
426423

427424
def cell_is_in(subdomain, this_cell):
428425
"""
429426
Check whether edge lies within subdomain
430427
"""
431-
assert(len(list(vertices(this_cell))) == 3), "Only triangular meshes are supported"
428+
assert (len(list(vertices(this_cell))) == 3), "Only triangular meshes are supported"
432429
return all([subdomain.inside(v.point(), True) for v in vertices(this_cell)])
433430

434-
edges_ids = []
435-
431+
vertex_ids = []
436432
for cell in cells(function_space.mesh()):
437433
if cell_is_in(coupling_subdomain, cell):
438434
e1, e2, e3 = list(edges(cell))
439-
if all(edge in precice_edge_dict.keys() for edge in [e1.index(), e2.index(), e3.index()]):
440-
edges_ids.append([e1.index(), e2.index(), e3.index()])
441-
442-
return np.array(edges_ids)
435+
if all(edge_ids in fenics_edge_ids for edge_ids in [e1.index(), e2.index(), e3.index()]):
436+
v1, v2 = vertices(e1)
437+
_, v3 = vertices(e2)
438+
assert (v3 != v1)
439+
assert (v3 != v2)
440+
vertex_ids.append([id_mapping[v1.global_index()],
441+
id_mapping[v2.global_index()],
442+
id_mapping[v3.global_index()]])
443+
444+
return np.array(vertex_ids)
443445

444446

445447
def get_forces_as_point_sources(fixed_boundary, function_space, data):

fenicsprecice/expression_core.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def update_boundary_data(self, vals, coords):
4949
self._vals = vals
5050
_, self._dimension = coords.shape
5151

52-
assert(self._dimension == 2), "Coordinates are of incorrect dimensions"
52+
assert (self._dimension == 2), "Coordinates are of incorrect dimensions"
5353

5454
self._coords_x = coords[:, 0]
5555
self._coords_y = coords[:, 1]
@@ -128,10 +128,10 @@ def is_scalar_valued(self):
128128
"""
129129
try:
130130
if self._vals.ndim == 1:
131-
assert(self._function_type is FunctionType.SCALAR)
131+
assert (self._function_type is FunctionType.SCALAR)
132132
return True
133133
elif self._vals.ndim > 1:
134-
assert(self._function_type is FunctionType.VECTOR)
134+
assert (self._function_type is FunctionType.VECTOR)
135135
return False
136136
else:
137137
raise Exception("Dimension of the function is 0 or negative!")
@@ -149,10 +149,10 @@ def is_vector_valued(self):
149149
"""
150150
try:
151151
if self._vals.ndim > 1:
152-
assert(self._function_type is FunctionType.VECTOR)
152+
assert (self._function_type is FunctionType.VECTOR)
153153
return True
154154
elif self._vals.ndim == 1:
155-
assert(self._function_type is FunctionType.SCALAR)
155+
assert (self._function_type is FunctionType.SCALAR)
156156
return False
157157
else:
158158
raise Exception("Dimension of the function is 0 or negative!")
@@ -170,7 +170,7 @@ class SegregatedRBFInterpolationExpression(CouplingExpression):
170170
"""
171171

172172
def segregated_interpolant_2d(self, coords_x, coords_y, data):
173-
assert(coords_x.shape == coords_y.shape)
173+
assert (coords_x.shape == coords_y.shape)
174174
# create least squares system to approximate a * x ** 2 + b * x + c ~= y
175175

176176
def lstsq_interp(x, y, w): return w[0] * x ** 2 + w[1] * y ** 2 + w[2] * x * y + w[3] * x + w[4] * y + w[5]
@@ -242,7 +242,7 @@ def eval(self, value, x):
242242
:param x: coordinate where expression has to be evaluated
243243
:param value: buffer where result has to be returned to
244244
"""
245-
assert(MPI.COMM_WORLD.Get_size() > 1)
245+
assert (MPI.COMM_WORLD.Get_size() > 1)
246246
for i in range(self._vals.ndim):
247247
value[i] = 0
248248

0 commit comments

Comments
 (0)