Skip to content

Commit

Permalink
debug adapter_core.convert_fenicsx_to_precice
Browse files Browse the repository at this point in the history
  • Loading branch information
arvedes committed Jun 22, 2022
1 parent a5c28d0 commit 5af2065
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion fenicsxprecice/adapter_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,18 @@ def convert_fenicsx_to_precice(fenicsx_function, local_ids):
raise Exception("Cannot handle data type {}".format(type(fenicsx_function)))

precice_data = []
sampled_data = fenicsx_function.x.array
# sampled_data = fenicsx_function.x.array # that works only for 1st order elements where dofs = grid points
# TODO begin dirty fix
x_mesh = fenicsx_function.function_space.mesh.geometry.x
x_dofs = fenicsx_function.function_space.tabulate_dof_coordinates()
mask = [] # where dof coordinate == mesh coordinate
for i in range(x_dofs.shape[0]):
for j in range(x_mesh.shape[0]):
if np.allclose(x_dofs[i, :], x_mesh[j, :], 1e-15):
mask.append(i)
break
sampled_data = fenicsx_function.x.array[mask]
# end dirty fix

if len(local_ids):
if fenicsx_function.function_space.num_sub_spaces > 0: # function space is VectorFunctionSpace
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_adapter_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __call__(self, x):
v = mesh.geometry.x[i]
local_ids.append(i)
manual_sampling.append([fun_lambda(v[0], v[1])])
manual_sampling = np.array(manual_sampling).squeeze()

data = convert_fenicsx_to_precice(fenicsx_function, local_ids)

Expand Down

0 comments on commit 5af2065

Please sign in to comment.