Skip to content

Commit

Permalink
Compatibility update for v3.0.0 (#153)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
BenjaminRodenberg and IshaanDesai authored Sep 28, 2023
1 parent 283bba9 commit 8a21819
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 276 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: |
mkdir -p precice
echo "from setuptools import setup" >> precice/setup.py
echo "setup(name='pyprecice', version='2.0.2.1')" >> precice/setup.py
echo "setup(name='pyprecice', version='3.0.0.0')" >> precice/setup.py
python3 -m pip install ./precice/
- name: Run unit tests
run: python3 setup.py test -s tests.unit
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/run-tutorials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ on:
pull_request:
paths:
- '**'
jobs:

jobs:
run_ht_simple:
name: Run HT, simple
runs-on: ubuntu-latest
container: precice/precice
container: precice/precice:develop
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v2
- name: Install Dependencies & FEniCS
run: |
apt-get -qq update
Expand All @@ -30,17 +30,17 @@ jobs:
- name: Get tutorials
run: git clone -b develop https://github.com/precice/tutorials.git
- name: Run tutorial
run: |
run: |
cd tutorials/partitioned-heat-conduction/fenics
python3 heat.py -d & python3 heat.py -n
./run.sh -d & ./run.sh -n
run_ht_complex:
name: Run HT, complex
runs-on: ubuntu-latest
container: precice/precice
container: precice/precice:develop
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v2
- name: Install Dependencies & FEniCS
run: |
apt-get -qq update
Expand All @@ -57,4 +57,4 @@ jobs:
- name: Run tutorial
run: |
cd tutorials/partitioned-heat-conduction-complex/fenics
python3 heat.py -d -i complex & python3 heat.py -n -i complex
./run.sh -d & ./run.sh -n
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# FEniCS-preCICE adapter changelog

## latest

* Drop support for preCICE 2.x version, as this is a breaking release.
* Update adapter to use preCICE v3 API [#153](https://github.com/precice/fenics-adapter/pull/153).
* 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).

## 1.4.0

* Adding CITATION.cff to link the adapter repository to the relevant publication in the journal SoftwareX.
Expand Down
48 changes: 25 additions & 23 deletions fenicsprecice/adapter_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,29 +383,26 @@ def edge_is_on(subdomain, this_edge):
"""
Check whether edge lies within subdomain
"""
assert(len(list(vertices(this_edge))) == 2)
assert (len(list(vertices(this_edge))) == 2)
return all([subdomain.inside(v.point(), True) for v in vertices(this_edge)])

vertices1_ids = []
vertices2_ids = []
edges_ids = []
edge_vertices_ids = []
fenics_edges_ids = []

for edge in edges(function_space.mesh()):
if edge_is_on(coupling_subdomain, edge):
v1, v2 = list(vertices(edge))
if v1.global_index() in global_ids and v2.global_index() in global_ids:
vertices1_ids.append(id_mapping[v1.global_index()])
vertices2_ids.append(id_mapping[v2.global_index()])
edges_ids.append(edge.index())
edge_vertices_ids.append([id_mapping[v1.global_index()], id_mapping[v2.global_index()]])
fenics_edges_ids.append(edge.index())

vertices1_ids = np.array(vertices1_ids)
vertices2_ids = np.array(vertices2_ids)
edges_ids = np.array(edges_ids)
edge_vertices_ids = np.array(edge_vertices_ids)
fenics_edges_ids = np.array(fenics_edges_ids)

return vertices1_ids, vertices2_ids, edges_ids
return edge_vertices_ids, fenics_edges_ids


def get_coupling_triangles(function_space, coupling_subdomain, precice_edge_dict):
def get_coupling_triangles(function_space, coupling_subdomain, fenics_edge_ids, id_mapping):
"""
Extracts triangles of mesh which lie on the coupling region.
Expand All @@ -415,31 +412,36 @@ def get_coupling_triangles(function_space, coupling_subdomain, precice_edge_dict
Function space on which the finite element problem definition lives.
coupling_subdomain : FEniCS Domain
FEniCS domain of the coupling interface region.
precice_edge_dict: dict
Dictionary with FEniCS IDs of coupling mesh edges as keys and preCICE IDs of the edges as values
fenics_edge_ids: numpy array
Array with FEniCS IDs of coupling mesh edges
Returns
-------
edges : numpy array
Array of edges indices (3 per triangle)
vertex_ids : numpy array
Array of indices of vertices which make up triangles (3 per triangle)
"""

def cell_is_in(subdomain, this_cell):
"""
Check whether edge lies within subdomain
"""
assert(len(list(vertices(this_cell))) == 3), "Only triangular meshes are supported"
assert (len(list(vertices(this_cell))) == 3), "Only triangular meshes are supported"
return all([subdomain.inside(v.point(), True) for v in vertices(this_cell)])

edges_ids = []

vertex_ids = []
for cell in cells(function_space.mesh()):
if cell_is_in(coupling_subdomain, cell):
e1, e2, e3 = list(edges(cell))
if all(edge in precice_edge_dict.keys() for edge in [e1.index(), e2.index(), e3.index()]):
edges_ids.append([e1.index(), e2.index(), e3.index()])

return np.array(edges_ids)
if all(edge_ids in fenics_edge_ids for edge_ids in [e1.index(), e2.index(), e3.index()]):
v1, v2 = vertices(e1)
_, v3 = vertices(e2)
assert (v3 != v1)
assert (v3 != v2)
vertex_ids.append([id_mapping[v1.global_index()],
id_mapping[v2.global_index()],
id_mapping[v3.global_index()]])

return np.array(vertex_ids)


def get_forces_as_point_sources(fixed_boundary, function_space, data):
Expand Down
14 changes: 7 additions & 7 deletions fenicsprecice/expression_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def update_boundary_data(self, vals, coords):
self._vals = vals
_, self._dimension = coords.shape

assert(self._dimension == 2), "Coordinates are of incorrect dimensions"
assert (self._dimension == 2), "Coordinates are of incorrect dimensions"

self._coords_x = coords[:, 0]
self._coords_y = coords[:, 1]
Expand Down Expand Up @@ -128,10 +128,10 @@ def is_scalar_valued(self):
"""
try:
if self._vals.ndim == 1:
assert(self._function_type is FunctionType.SCALAR)
assert (self._function_type is FunctionType.SCALAR)
return True
elif self._vals.ndim > 1:
assert(self._function_type is FunctionType.VECTOR)
assert (self._function_type is FunctionType.VECTOR)
return False
else:
raise Exception("Dimension of the function is 0 or negative!")
Expand All @@ -149,10 +149,10 @@ def is_vector_valued(self):
"""
try:
if self._vals.ndim > 1:
assert(self._function_type is FunctionType.VECTOR)
assert (self._function_type is FunctionType.VECTOR)
return True
elif self._vals.ndim == 1:
assert(self._function_type is FunctionType.SCALAR)
assert (self._function_type is FunctionType.SCALAR)
return False
else:
raise Exception("Dimension of the function is 0 or negative!")
Expand All @@ -170,7 +170,7 @@ class SegregatedRBFInterpolationExpression(CouplingExpression):
"""

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

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]
Expand Down Expand Up @@ -242,7 +242,7 @@ def eval(self, value, x):
:param x: coordinate where expression has to be evaluated
:param value: buffer where result has to be returned to
"""
assert(MPI.COMM_WORLD.Get_size() > 1)
assert (MPI.COMM_WORLD.Get_size() > 1)
for i in range(self._vals.ndim):
value[i] = 0

Expand Down
Loading

0 comments on commit 8a21819

Please sign in to comment.