Skip to content

Commit

Permalink
remove unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasVin committed Dec 12, 2024
1 parent b6e6a03 commit dec87a2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 50 deletions.
47 changes: 0 additions & 47 deletions fenicsxprecice/adapter_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,53 +86,6 @@ def determine_function_type(input_obj):
raise Exception("Error determining type of given dolfin FunctionSpace")


def convert_fenicsx_to_precice(fenicsx_function, local_ids):
"""
Converts data of type dolfinx.Function into Numpy array for all x and y coordinates on the boundary.
Parameters
----------
fenicsx_function : FEniCSx function
A FEniCSx function referring to a physical variable in the problem.
local_ids: numpy array
Array of local indices of vertices on the coupling interface and owned by this rank.
Returns
-------
precice_data : array_like
Array of FEniCSx function values at each point on the boundary.
"""

if not isinstance(fenicsx_function, fem.Function):
raise Exception("Cannot handle data type {}".format(type(fenicsx_function)))

precice_data = []

# sampled_data = fenicsx_function.x.array # that works only for 1st order elements where dofs = grid points
# TODO begin dirty fix. See https://github.com/precice/fenicsx-adapter/issues/17 for details.
x_mesh = fenicsx_function.function_space.mesh.geometry.x #
x_dofs = fenicsx_function.function_space.tabulate_dof_coordinates() # returns coordinates of the degrees of freedom
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
raise Exception("Functions from VectorFunctionSpaces are currently not supported.")
else: # function space is FunctionSpace (scalar)
for lid in local_ids:
precice_data.append(sampled_data[lid])
else:
precice_data = np.array([])

return np.array(precice_data)


def convert_fenicsx_to_precice_coordinateBased(fenicsx_function, local_coords):
"""
Converts data of type dolfinx.Function into Numpy array for all x and y coordinates on the boundary.
Expand Down
5 changes: 2 additions & 3 deletions fenicsxprecice/fenicsxprecice.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .config import Config
import logging
import precice
from .adapter_core import FunctionType, determine_function_type, convert_fenicsx_to_precice, get_fenicsx_vertices, CouplingMode, Vertices, convert_fenicsx_to_precice_coordinateBased
from .adapter_core import FunctionType, determine_function_type, get_fenicsx_vertices, CouplingMode, Vertices, convert_fenicsx_to_precice_coordinateBased
from .expression_core import SegregatedRBFInterpolationExpression
from .solverstate import SolverState
from dolfinx.fem import Function, FunctionSpace
Expand Down Expand Up @@ -183,8 +183,7 @@ def write_data(self, write_function):

# Check that the function provided lives on the same function space provided during initialization
assert (self._write_function_type == determine_function_type(w_func))
# TODO this raises AssertionError, not sure why. I just commented it out, still works...
# assert (write_function.function_space == self._write_function_space)
assert (write_function.function_space == self._write_function_space)

#write_data_id = self._participant.get_data_id(self._config.get_write_data_name(),
# self._participant.get_mesh_id(self._config.get_coupling_mesh_name()))
Expand Down

0 comments on commit dec87a2

Please sign in to comment.