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

Compatibility update for v3.0.0 #153

Merged
merged 33 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8d48839
Remove API functions that are removed in v3.0.0. Fix data initializat…
BenjaminRodenberg Jul 12, 2022
41d5f0a
Forward dt to python bindings.
BenjaminRodenberg Jul 12, 2022
db80fd6
Fix formatting.
BenjaminRodenberg Jul 12, 2022
d9c93fe
Merge branch 'develop' into compatibility-v3.0.0
IshaanDesai Mar 28, 2023
24814d5
Updates according to precice:develop
IshaanDesai Mar 28, 2023
60ba637
Formatting
IshaanDesai Mar 28, 2023
dee8c4f
Set mesh connectivity information only if it is required. Closes #138
IshaanDesai Mar 28, 2023
e9494b4
Add mock call to requires_mesh_connectivity_for in tests
IshaanDesai Mar 29, 2023
069f7fb
Add mock call to requires_initial_data in tests
IshaanDesai Mar 29, 2023
8945805
Update links of contributors
IshaanDesai Mar 29, 2023
10e2d5f
Update CHANGELOG.md
BenjaminRodenberg Mar 29, 2023
cfec85d
Call checkpointing functions from the interface
IshaanDesai Mar 29, 2023
641aa04
Making adapter and tests compatible with the latest development stage
IshaanDesai Jun 13, 2023
b0a612e
Formatting
IshaanDesai Jun 13, 2023
ff99c95
Repair set_mesh_edges unit test
IshaanDesai Jun 13, 2023
52eecbe
Merge branch 'develop' into compatibility-v3.0.0
BenjaminRodenberg Jul 10, 2023
d6e5989
Merge branch 'develop' into compatibility-v3.0.0
BenjaminRodenberg Jul 10, 2023
87af390
Merge branch 'develop' into compatibility-v3.0.0
BenjaminRodenberg Jul 10, 2023
748c934
Get tests working again.
BenjaminRodenberg Jul 11, 2023
127fdd3
Change required version of pyprecice to >=3.0.0.0
IshaanDesai Aug 1, 2023
f661455
Formatting
IshaanDesai Aug 1, 2023
9935467
Fix version requirement to also support dev version.
BenjaminRodenberg Sep 27, 2023
2ae1de5
Use develop docker image.
BenjaminRodenberg Sep 27, 2023
ef63119
Fix assertion.
BenjaminRodenberg Sep 28, 2023
90d533a
Merge branch 'develop' into compatibility-v3.0.0
BenjaminRodenberg Sep 28, 2023
4aff969
Use run.sh.
BenjaminRodenberg Sep 28, 2023
5e8c632
Fix metadata for mocked bindings
BenjaminRodenberg Sep 28, 2023
3beffd7
Add test.
BenjaminRodenberg Sep 28, 2023
5ffe18b
Comment out nearest projection volume coupling.
BenjaminRodenberg Sep 28, 2023
53ecec0
Merge branch 'compatibility-v3.0.0' of github.com:precice/fenics-adap…
BenjaminRodenberg Sep 28, 2023
86f2d4a
Update changelog.
BenjaminRodenberg Sep 28, 2023
0a96fd5
Fix format.
BenjaminRodenberg Sep 28, 2023
92b3eac
Explicitly mention that this is a breaking release of the FEniCS adap…
BenjaminRodenberg Sep 28, 2023
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
39 changes: 22 additions & 17 deletions fenicsprecice/adapter_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,29 +383,29 @@ 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 = []
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())
fenics_edges_ids.append(edge.index())

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

return vertices1_ids, vertices2_ids, edges_ids
return vertices1_ids, vertices2_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 +415,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 (v2 != v2)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this problem by running channel-transport-reaction. But even fixing this obviously wrong assertion does not help. There seems to be some issue with the function get_coupling_triangles. We obviously need a test for this function and need to fix it. @IshaanDesai can you take a look?

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)
BenjaminRodenberg marked this conversation as resolved.
Show resolved Hide resolved
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