@@ -294,21 +294,14 @@ def check_and_update_parameter_values(self, values):
294
294
295
295
return values
296
296
297
- def process_model (self , unprocessed_model , processing = "process" , inplace = True ):
297
+ def process_model (self , unprocessed_model , inplace = True ):
298
298
"""Assign parameter values to a model.
299
299
Currently inplace, could be changed to return a new model.
300
300
301
301
Parameters
302
302
----------
303
303
unprocessed_model : :class:`pybamm.BaseModel`
304
304
Model to assign parameter values for
305
- processing : str, optional
306
- Flag to indicate how to process model (default 'process')
307
-
308
- * 'process': Calls :meth:`process_symbol()` (walk through the symbol \
309
- and replace any Parameter with a Value)
310
- * 'update': Calls :meth:`update_scalars()` for use on already-processed \
311
- model (update the value of any Scalars in the expression tree.)
312
305
inplace: bool, optional
313
306
If True, replace the parameters in the model in place. Otherwise, return a
314
307
new model with parameter values set. Default is True.
@@ -335,32 +328,21 @@ def process_model(self, unprocessed_model, processing="process", inplace=True):
335
328
if len (unprocessed_model .rhs ) == 0 and len (unprocessed_model .algebraic ) == 0 :
336
329
raise pybamm .ModelError ("Cannot process parameters for empty model" )
337
330
338
- if processing == "process" :
339
- processing_function = self .process_symbol
340
- elif processing == "update" :
341
- processing_function = self .update_scalars
342
-
343
331
for variable , equation in model .rhs .items ():
344
- pybamm .logger .debug (
345
- "{} parameters for {!r} (rhs)" .format (processing .capitalize (), variable )
346
- )
347
- model .rhs [variable ] = processing_function (equation )
332
+ pybamm .logger .debug ("Processing parameters for {!r} (rhs)" .format (variable ))
333
+ model .rhs [variable ] = self .process_symbol (equation )
348
334
349
335
for variable , equation in model .algebraic .items ():
350
336
pybamm .logger .debug (
351
- "{} parameters for {!r} (algebraic)" .format (
352
- processing .capitalize (), variable
353
- )
337
+ "Processing parameters for {!r} (algebraic)" .format (variable )
354
338
)
355
- model .algebraic [variable ] = processing_function (equation )
339
+ model .algebraic [variable ] = self . process_symbol (equation )
356
340
357
341
for variable , equation in model .initial_conditions .items ():
358
342
pybamm .logger .debug (
359
- "{} parameters for {!r} (initial conditions)" .format (
360
- processing .capitalize (), variable
361
- )
343
+ "Processing parameters for {!r} (initial conditions)" .format (variable )
362
344
)
363
- model .initial_conditions [variable ] = processing_function (equation )
345
+ model .initial_conditions [variable ] = self . process_symbol (equation )
364
346
365
347
# Boundary conditions are dictionaries {"left": left bc, "right": right bc}
366
348
# in general, but may be imposed on the tabs (or *not* on the tab) for a
@@ -369,17 +351,15 @@ def process_model(self, unprocessed_model, processing="process", inplace=True):
369
351
new_boundary_conditions = {}
370
352
sides = ["left" , "right" , "negative tab" , "positive tab" , "no tab" ]
371
353
for variable , bcs in model .boundary_conditions .items ():
372
- processed_variable = processing_function (variable )
354
+ processed_variable = self . process_symbol (variable )
373
355
new_boundary_conditions [processed_variable ] = {}
374
356
for side in sides :
375
357
try :
376
358
bc , typ = bcs [side ]
377
359
pybamm .logger .debug (
378
- "{} parameters for {!r} ({} bc)" .format (
379
- processing .capitalize (), variable , side
380
- )
360
+ "Processing parameters for {!r} ({} bc)" .format (variable , side )
381
361
)
382
- processed_bc = (processing_function (bc ), typ )
362
+ processed_bc = (self . process_symbol (bc ), typ )
383
363
new_boundary_conditions [processed_variable ][side ] = processed_bc
384
364
except KeyError as err :
385
365
# don't raise error if the key error comes from the side not being
@@ -394,42 +374,24 @@ def process_model(self, unprocessed_model, processing="process", inplace=True):
394
374
395
375
for variable , equation in model .variables .items ():
396
376
pybamm .logger .debug (
397
- "{} parameters for {!r} (variables)" .format (
398
- processing .capitalize (), variable
399
- )
377
+ "Processing parameters for {!r} (variables)" .format (variable )
400
378
)
401
- model .variables [variable ] = processing_function (equation )
379
+ model .variables [variable ] = self . process_symbol (equation )
402
380
for event , equation in model .events .items ():
403
- pybamm .logger .debug (
404
- "{} parameters for event '{}''" .format (processing .capitalize (), event )
405
- )
406
- model .events [event ] = processing_function (equation )
381
+ pybamm .logger .debug ("Processing parameters for event '{}''" .format (event ))
382
+ model .events [event ] = self .process_symbol (equation )
407
383
408
384
pybamm .logger .info ("Finish setting parameters for {}" .format (model .name ))
409
385
410
386
return model
411
387
412
388
def update_model (self , model , disc ):
413
- """Process a discretised model.
414
- Currently inplace, could be changed to return a new model.
415
-
416
- Parameters
417
- ----------
418
- model : :class:`pybamm.BaseModel`
419
- Model to assign parameter values for
420
- disc : :class:`pybamm.Discretisation`
421
- The class that was used to discretise
422
-
423
- """
424
- # process parameter values for the model
425
- self .process_model (model , processing = "update" )
426
-
427
- # update discretised quantities using disc
428
- model .concatenated_rhs = disc ._concatenate_in_order (model .rhs )
429
- model .concatenated_algebraic = disc ._concatenate_in_order (model .algebraic )
430
- model .concatenated_initial_conditions = disc ._concatenate_in_order (
431
- model .initial_conditions
432
- ).evaluate (0 , None )
389
+ raise NotImplementedError (
390
+ """
391
+ update_model functionality has been deprecated.
392
+ Use pybamm.InputParameter to quickly change a parameter value instead
393
+ """
394
+ )
433
395
434
396
def process_geometry (self , geometry ):
435
397
"""
@@ -561,30 +523,6 @@ def _process_symbol(self, symbol):
561
523
)
562
524
)
563
525
564
- def update_scalars (self , symbol ):
565
- """Update the value of any Scalars in the expression tree.
566
-
567
- Parameters
568
- ----------
569
- symbol : :class:`pybamm.Symbol`
570
- Symbol or Expression tree to update
571
-
572
- Returns
573
- -------
574
- symbol : :class:`pybamm.Symbol`
575
- Symbol with Scalars updated
576
-
577
- """
578
- for x in symbol .pre_order ():
579
- if isinstance (x , pybamm .Scalar ):
580
- # update any Scalar nodes if their name is in the parameter dict
581
- if x .name in self ._dict_items .keys ():
582
- x .value = self ._dict_items [x .name ]
583
- # update id
584
- x .set_id ()
585
-
586
- return symbol
587
-
588
526
def evaluate (self , symbol ):
589
527
"""
590
528
Process and evaluate a symbol.
0 commit comments