1- from pathsim .blocks import Block , ODE
1+ from pathsim .blocks import Block , ODE , Wrapper
22import pathsim .blocks
33import pathsim .events
44from pathsim import Subsystem , Interface , Connection
@@ -299,18 +299,25 @@ def create_reset_events(self) -> list[pathsim.events.ScheduleList]:
299299from pathsim .utils .register import Register
300300
301301
302- class FestimWall (Block ):
302+ class FestimWall (Wrapper ):
303303 _port_map_out = {"flux_0" : 0 , "flux_L" : 1 }
304304 _port_map_in = {"c_0" : 0 , "c_L" : 1 }
305305
306306 def __init__ (
307- self , thickness , temperature , D_0 , E_D , surface_area = 1 , n_vertices = 100
307+ self ,
308+ thickness ,
309+ temperature ,
310+ D_0 ,
311+ E_D ,
312+ T ,
313+ surface_area = 1 ,
314+ n_vertices = 100 ,
315+ tau = 0 ,
308316 ):
309317 try :
310- import festim as F
318+ import festim
311319 except ImportError :
312320 raise ImportError ("festim is needed for FestimWall node." )
313- super ().__init__ ()
314321
315322 self .inputs = Register (size = 2 , mapping = self ._port_map_in )
316323 self .outputs = Register (size = 2 , mapping = self ._port_map_out )
@@ -322,8 +329,10 @@ def __init__(
322329 self .E_D = E_D
323330 self .n_vertices = n_vertices
324331 self .t = 0.0
332+ self .stepsize = T
325333
326334 self .initialise_festim_model ()
335+ super ().__init__ (T = T , tau = tau , func = self .func )
327336
328337 def initialise_festim_model (self ):
329338 import festim as F
@@ -355,7 +364,7 @@ def initialise_festim_model(self):
355364 atol = 1e-10 , rtol = 1e-10 , transient = True , final_time = 1
356365 )
357366
358- model .settings .stepsize = F .Stepsize (initial_value = 1 )
367+ model .settings .stepsize = F .Stepsize (initial_value = self . stepsize )
359368
360369 self .surface_flux_0 = F .SurfaceFlux (field = H , surface = left_surf )
361370 self .surface_flux_L = F .SurfaceFlux (field = H , surface = right_surf )
@@ -365,36 +374,21 @@ def initialise_festim_model(self):
365374
366375 model .initialise ()
367376
368- self .dt = model .dt
369377 self .c_0 = model .boundary_conditions [0 ].value_fenics
370378 self .c_L = model .boundary_conditions [1 ].value_fenics
371379
372380 self .model = model
373381
374- def update_festim_model (self , c_0 , c_L , stepsize ):
382+ def update_festim_model (self , c_0 , c_L ):
375383 self .c_0 .value = c_0
376384 self .c_L .value = c_L
377- self .dt .value = stepsize
378385
379386 self .model .iterate ()
380387
381388 return self .surface_flux_0 .data [- 1 ], self .surface_flux_L .data [- 1 ]
382389
383- def update (self , t ):
384- # no internal algebraic operator -> early exit
385- # if self.op_alg is None:
386- # return 0.0
387-
388- # block inputs
389- c_0 = self .inputs ["c_0" ]
390- c_L = self .inputs ["c_L" ]
391-
392- if t == 0.0 :
393- flux_0 , flux_L = 0 , 0
394- else :
395- flux_0 , flux_L = self .update_festim_model (
396- c_0 = c_0 , c_L = c_L , stepsize = t - self .t
397- )
390+ def func (self , c_0 , c_L ):
391+ flux_0 , flux_L = self .update_festim_model (c_0 = c_0 , c_L = c_L )
398392
399393 flux_0 *= self .surface_area
400394 flux_L *= self .surface_area
0 commit comments