Opened 18 years ago
Closed 13 years ago
#90 closed enhancement (wontfix)
How about having boundary conditions take keyword arguments
Reported by: | ole | Owned by: | ole |
---|---|---|---|
Priority: | lowest | Milestone: | ANUGA maintenance |
Component: | Architecture and API | Version: | 1.0 |
Severity: | normal | Keywords: | |
Cc: |
Description
Currently Dirichlet and Time Boundaries take triplets (in case of the shallow water eq) as in Bd = Dirichlet_boundary([0.,0.,0.]) or Bw = Time_boundary(domain=domain,
f=lambda t: [sin(t), 0.0, 0.0])
These triplets represent conserved quantities in a specific order (eg stage, xmomentum, ymomentum).
It would be better to have something like
Bd = Dirichlet_boundary({'stage': 0, 'xmomentum': 0, 'ymomentum': 0}) with default values of 0 if anything is omitted.
Similarly for the time boundary Bw = Time_boundary(domain=domain,
{'stage': lambda t: sin(t)})
again with constant 0 as default.
This will also fit the new Transmissive_Momentum_Set_Stage_boundary make more sense as it only need on quantity, namely stage.
What do the other developers think?
Change History (3)
comment:1 Changed 18 years ago by jack
comment:2 Changed 18 years ago by ole
SUGGESTION FROM JACK KELLY
Specify explicit keyword arguments, and make it also take the kwargs parameter. This way you're sticking to the same interface as the parent class (and you can pass the kwargs to the parent constructor, though it might be necessary to add some of the parameters by hand). Hopefully the following snippet will explain what I mean:
class Boundary:
def init(kwargs):
pass
class Dirichlet_boundary(Boundary):
def init(stage=0, xmomentum=0, ymomentum=0, kwargs):
# Suppose, for some bizarre reason, the parent class needs the # stage parameter. kwargsstage? = stage # Then pass the kwargs up to the superclass constructor Boundary.init(self, kwargs) # ...
Now if you want to add a new keyword argument to Boundary.init, the subclasses Dirichlet_boundary class won't have to change at all unless they need to override the default value of the new keyword argument.
comment:3 Changed 13 years ago by habili
- Resolution set to wontfix
- Status changed from new to closed
Interesting idea, but have you considered using keyword arguments instead?
Declare the constructor for (say) Dirichlet_boundary as: def init(self, kwargs):
Internally, you can access the arguments as you would with the above scheme (e.g.) kwargsstage?, kwargsxmomentum?, etc. The name kwargs is unimportant, but the in front is required.
Externally, the interface becomes simpler as all keyword arguments that aren't explicitly specified get put into the kwargs dictionary. This allows for calls such as:
Bd = Dirichlet_boundary(stage=0, xmomentum=0, ymomentum=0)
Or, if you have a prebuilt dictionary (from a config file perhaps?), it can be passed as the arguments:
dict = {'stage': 0, 'xmomentum': 0, 'ymomentum': 0} Bd = Dirichlet_boundary(dict)