@@ -140,10 +140,6 @@ class Simulation:
140140 signal_sparging : callable [pint .Quantity ]
141141 profile_source_T : callable [pint .Quantity ] | None = None
142142
143- def __post_init__ (self ):
144- if self .profile_source_T is None :
145- self .profile_source_T = lambda x : 1
146-
147143 def solve (self , dt : pint .Quantity | None = None , dx : pint .Quantity | None = None ):
148144 # unpack pint.Quantities
149145 t_final = self .t_final .to ("seconds" ).magnitude
@@ -188,10 +184,18 @@ def solve(self, dt: pint.Quantity | None = None, dx: pint.Quantity | None = None
188184
189185 h_l_const = dolfinx .fem .Constant (mesh , PETSc .ScalarType (h_l ))
190186
191- # gen_T2 = dolfinx.fem.Constant(
192- # mesh, PETSc.ScalarType(source_T2)
193- # ) # generation term [mol T2 /m3/s]
194- gen_T2 = dolfinx .fem .Function (V_profile )
187+ gen_T2_mag = dolfinx .fem .Constant (
188+ mesh , source_T2 * self .signal_irr (0 * ureg .s )
189+ ) # magnitude of the generation term
190+ gen_T2 = None
191+ if self .profile_source_T is not None : # spatially varying profile is provided
192+ gen_T2_prof = dolfinx .fem .Function (V_profile )
193+ gen_T2_prof .interpolate (
194+ lambda x : x [0 ] * 0 + self .profile_source_T (x [0 ] * ureg .m )
195+ )
196+ gen_T2 = gen_T2_mag * gen_T2_prof
197+ else : # homogeneous generation
198+ gen_T2 = gen_T2_mag
195199
196200 # VARIATIONAL FORMULATION
197201
@@ -282,14 +286,7 @@ def solve(self, dt: pint.Quantity | None = None, dx: pint.Quantity | None = None
282286 # SOLVE
283287 t = 0
284288 while t < t_final :
285- gen_T2 .interpolate (
286- lambda x : (
287- x [0 ] * 0 # why do I need to put x[0] at all cost???
288- + self .profile_source_T (x [0 ] * ureg .m )
289- * source_T2
290- * self .signal_irr (t * ureg .s )
291- )
292- )
289+ gen_T2_mag .value = source_T2 * self .signal_irr (t * ureg .s )
293290 h_l_const .value = h_l * self .signal_sparging (t * ureg .s )
294291 """ utiliser ufl.conditional TODO"""
295292
0 commit comments