Skip to content

Commit 3f12a79

Browse files
committed
Various fixes for proper reading on input data
1 parent b09927e commit 3f12a79

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

src/festim/exports/surface_flux.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,8 @@ def compute(
4747
entity_maps: entity maps relating parent mesh and submesh
4848
"""
4949

50-
# obtain mesh normal from field
51-
# if case multispecies, solution is an index, use sub_function_space
52-
if isinstance(u, ufl.indexed.Indexed):
53-
mesh = self.field.sub_function_space.mesh
54-
else:
55-
mesh = u.function_space.mesh
50+
# obtain mesh normal from integration domain
51+
mesh = ds.ufl_domain()
5652
n = ufl.FacetNormal(mesh)
5753

5854
self.value = assemble_scalar(

src/festim/initial_condition.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def create_expr_fenics(
240240

241241

242242
def read_function_from_file(
243-
filename: str, name: str, timestamp: int | float, family="P", order: int = 1
243+
filename: str, name: str, timestamp: int | float, family="P", order: int = 1, mesh: dolfinx.mesh.Mesh|None = None
244244
) -> fem.Function:
245245
"""
246246
Read a function from a file
@@ -255,6 +255,7 @@ def read_function_from_file(
255255
timestamp: the timestamp of the function
256256
family: the family of the function space
257257
order: the order of the function space
258+
mesh: Mesh to create input space on.
258259
259260
Returns:
260261
the function
@@ -268,4 +269,14 @@ def read_function_from_file(
268269
name=name,
269270
time=timestamp,
270271
)
271-
return u_in
272+
if mesh is None:
273+
return u_in
274+
else:
275+
V = fem.functionspace(mesh, (family, order))
276+
u = fem.Function(V)
277+
num_cells = mesh.topology.index_map(mesh.topology.dim).size_local
278+
cells = np.arange(num_cells, dtype=np.int32)
279+
padding = 1e2 * np.finfo(mesh.geometry.x.dtype).eps
280+
idata = fem.create_interpolation_data(V, V_in, cells=cells, padding=padding)
281+
u.interpolate_nonmatching(u_in, cells, idata)
282+
return u

test/system_tests/test_io.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def test_writing_and_reading_of_species_function_using_checkpoints(tmpdir):
7474
filename=tmpdir + "/out_checkpoint.bp",
7575
name="H",
7676
timestamp=10,
77+
mesh=mesh
7778
),
7879
species=H,
7980
volume=vol,
@@ -83,6 +84,7 @@ def test_writing_and_reading_of_species_function_using_checkpoints(tmpdir):
8384
filename=tmpdir + "/out_checkpoint.bp",
8485
name="D",
8586
timestamp=10,
87+
mesh=mesh
8688
),
8789
species=D,
8890
volume=vol,

test/test_initial_condition.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def f(x):
173173
my_problem.subdomains = [vol]
174174

175175
function_initial_value = F.read_function_from_file(
176-
filename=filename, name="my_function", timestamp=0.2
176+
filename=filename, name="my_function", timestamp=0.2, mesh=mesh
177177
)
178178
my_problem.initial_conditions = [
179179
F.InitialConcentration(value=function_initial_value, species=H, volume=vol)
@@ -236,6 +236,7 @@ def f2(x):
236236
filename=filename,
237237
name="my_function1",
238238
timestamp=0.2,
239+
mesh=mesh
239240
),
240241
species=H,
241242
volume=vol,
@@ -245,6 +246,7 @@ def f2(x):
245246
filename=filename,
246247
name="my_function2",
247248
timestamp=0.3,
249+
mesh=mesh
248250
),
249251
species=D,
250252
volume=vol,

test/test_mesh.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import logging
22
import os
3-
3+
import pytest
44
from mpi4py import MPI
55

6-
import ipyparallel as ipp
6+
7+
ipp = pytest.importorskip("ipyparallel")
8+
79
import numpy as np
810
import pytest
911
from dolfinx import mesh as fenics_mesh

0 commit comments

Comments
 (0)