Skip to content

Commit d660bca

Browse files
added comments
1 parent dc5c21f commit d660bca

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

src/festim/exports/vtx.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,29 +250,35 @@ def set_dolfinx_expression(
250250
temperature: The temperature field to use in the expression
251251
time: The time to use in the expression
252252
"""
253-
# check
253+
# check if we are in a mixed domain/discontinuous case
254+
mixed_domain = any(
255+
spe.subdomain_to_post_processing_solution
256+
for spe in self.species_dependent_value.values()
257+
) or (self.subdomain.sub_T if self.subdomain else None)
258+
259+
# get the arguments of the user-provided expression
254260
arguments = inspect.signature(self.expression).parameters
261+
262+
# create a dictionary mapping the arguments to the appropriate values
255263
kwargs = {}
256264
if "t" in arguments:
257265
kwargs["t"] = time
258266
if "x" in arguments:
259267
x = ufl.SpatialCoordinate(time._ufl_domain)
260268
kwargs["x"] = x
261269
if "T" in arguments:
262-
if (
263-
isinstance(temperature, fem.Function)
264-
and self.subdomain.sub_T is not None
265-
):
266-
kwargs["T"] = (
267-
self.subdomain.sub_T
268-
) # NOTE I'm not sure that sub_T is updated at every time step
270+
if isinstance(temperature, fem.Function) and mixed_domain:
271+
# fem.Function in mixed domain/discontinuous case, use sub_T
272+
# NOTE I'm not sure that sub_T is updated at every time step
273+
kwargs["T"] = self.subdomain.sub_T
269274
else:
275+
# else use the provided temperature
270276
kwargs["T"] = temperature
271277
# check if there are other arguments and if they are in species_dependent_value
272278
for arg in arguments:
273279
if arg in self.species_dependent_value:
274280
spe = self.species_dependent_value[arg]
275-
if spe.subdomain_to_post_processing_solution:
281+
if mixed_domain:
276282
kwargs[arg] = spe.subdomain_to_post_processing_solution[
277283
self.subdomain
278284
]
@@ -281,6 +287,9 @@ def set_dolfinx_expression(
281287
assert kwargs[arg] is not None, (
282288
f"Argument {arg} not found in species_dependent_value"
283289
)
290+
291+
# evaluate the user-provided expression with the appropriate arguments and create a
292+
# dolfinx.fem.Expression
284293
self.dolfinx_expression = fem.Expression(
285294
self.expression(**kwargs),
286295
get_interpolation_points(self.function.function_space.element),

0 commit comments

Comments
 (0)