Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 12 additions & 10 deletions smart/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,14 +756,14 @@ def _init_4_0_initialize_dolfin_parameters(self):
if parameter.type == ParameterType.constant:
parameter.dolfin_constant = d.Constant(parameter.value, name=parameter.name)
elif parameter.type == ParameterType.expression and parameter.is_space_dependent:
c_code = sym.printing.ccode(parameter.sym_expr)
c_code = c_code.replace("log(", "std::log(")
# use higher degree to avoid interpolation error
parameter.dolfin_expression = d.Expression(
sym.printing.ccode(parameter.sym_expr), t=self.T, degree=3
)
parameter.dolfin_expression = d.Expression(c_code, t=self.T, degree=3)
elif parameter.type == ParameterType.expression and not parameter.use_preintegration:
parameter.dolfin_expression = d.Expression(
sym.printing.ccode(parameter.sym_expr), t=self.T, degree=1
)
c_code = sym.printing.ccode(parameter.sym_expr)
c_code = c_code.replace("log(", "std::log(")
parameter.dolfin_expression = d.Expression(c_code, t=self.T, degree=1)
elif parameter.type == ParameterType.expression and parameter.use_preintegration:
parameter.dolfin_constant = d.Constant(parameter.value, name=parameter.name)
elif parameter.type == ParameterType.from_file:
Expand Down Expand Up @@ -1909,9 +1909,9 @@ def update_time_dependent_parameters(self):
a = parameter.preint_sym_expr.subs({"t": tn}).evalf()
b = parameter.preint_sym_expr.subs({"t": t}).evalf()
if parameter.is_space_dependent:
parameter.dolfin_expression = d.Expression(
sym.printing.ccode((b - a) / dt), degree=3
)
c_code = sym.printing.ccode((b - a) / dt)
c_code = c_code.replace("log(", "std::log(")
parameter.dolfin_expression = d.Expression(c_code, degree=3)
logger.debug(
f"Time-dependent parameter {parameter_name} updated by "
f"pre-integrated expression",
Expand Down Expand Up @@ -2006,7 +2006,9 @@ def dolfin_set_function_values(self, sp, ukey, unew):
else:
x = d.SpatialCoordinate(sp.compartment.dolfin_mesh)
curv = sp.compartment.curv_func
full_expr = d.Expression(sym.printing.ccode(sym_expr), curv=curv, degree=1)
c_code = sym.printing.ccode(sym_expr)
c_code = c_code.replace("log(", "std::log(")
full_expr = d.Expression(c_code, curv=curv, degree=1)
ufunc = d.interpolate(full_expr, sp.V)
d.assign(sp.u[ukey], ufunc)
elif isinstance(unew, d.Expression):
Expand Down
10 changes: 6 additions & 4 deletions smart/model_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,9 @@ def from_expression(
if is_time_dependent and not is_space_dependent:
value = float(sym_expr.subs({"t": 0.0}))
else:
dolfin_expression = d.Expression(sym.printing.ccode(sym_expr), t=0.0, degree=3)
c_code = sym.printing.ccode(sym_expr)
c_code = c_code.replace("log(", "std::log(")
dolfin_expression = d.Expression(c_code, t=0.0, degree=3)
value = float(sym_expr.subs({"t": 0.0, "x[0]": 0.0, "x[1]": 0.0, "x[2]": 0.0}))

parameter = cls(
Expand Down Expand Up @@ -1002,9 +1004,9 @@ def __post_init__(self):
f"Creating dolfin object for space-dependent initial condition {self.name}",
extra=dict(format_type="log"),
)
self.initial_condition_expression = d.Expression(
sym.printing.ccode(sym_expr), degree=1
)
c_code = sym.printing.ccode(sym_expr)
c_code = c_code.replace("log(", "std::log(")
self.initial_condition_expression = d.Expression(c_code, degree=1)
elif isinstance(self.initial_condition, Path):
pass # keep as path
else:
Expand Down