- 
                Notifications
    You must be signed in to change notification settings 
- Fork 250
Fix getbc not passing extra args for discrete BC functions #4816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| I think this is intentional, i.e. the signature of a discrete boundary condition function is @inline discrete_bc_function(i, j, grid, clock, fields, parameters)where  discrete_bc = FluxBoundaryCondition(discrete_bc_function, discrete_form=true, parameters=my_parameters) | 
| The extra  continuous_bc_function(x, y, z, t, u, v) = ....where, in this case,  continuous_bc = FluxBoundaryConditions(continuous_bc_function, field_dependencies = (:u, :v))note that the model must contain  | 
| Actually, now that I look more in detail, I think the  | 
| Oh, ok. But then what is the point of having the extra  | 
| To pass  fill_halo_regions!(field)for fields that do not have field dependencies and fill_halo_regions!(field, model.clock, fields(model))for fields that do. | 
9bbebb8    to
    899aba5      
    Compare
  
    getbc for ContinuousBoundaryFunction
      | Ok I updated the PR to remove the reundant  | 
| @simone-silvestri Do you know what's going on with the tests? | 
| Apparently those  | 
| Not sure why we were passing also closures and buoyancy in the hydrostatic model that were eventually thrown away... | 
| Just to add here --- the design is such that any extra arguments to  
 | 
| # Return ContinuousBoundaryFunction on east or west boundaries. | ||
| @inline function getbc(cbf::XBoundaryFunction{LY, LZ, S}, j::Integer, k::Integer, | ||
| grid::AbstractGrid, clock, model_fields, args...) where {LY, LZ, S} | ||
| grid::AbstractGrid, clock, model_fields) where {LY, LZ, S} | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest keeping the original behavior so that future model developers can support more arguments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless we can articulate why removing this aspect of the code design is undesirable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want this, we need to pass the args... to the continuous boundary function, which is not the original behavior. If we want to support more arguments, there is some structural work to be done on the ContinuousBoundaryFunctions to make sure that field dependencies do not conflict with the extra arguments passed to the getbc.
It might be easier to allow this only for a DiscreteBoundaryFunction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, we want to have a generic args... so that a model implementation can pass additional arguments into fill_halo_regions! (which then are propagated into getbc). However, having args... does not imply that ContinuousBoundaryFunction has to support interpreting it. ContinuousBoundaryFunction can have an interface which only utilizes the first two arguments clock, model_fields and discards the rest. Then the extra args... are only used by DiscreteBoundaryFunction.
| ``` | ||
| func(i, j, grid, clock, model_fields, parameters) | ||
| func(i, j, grid, clock, model_fields, parameters, args...) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrt to the above comment, this docstring indeed would be misleading for any model that chooses to use arguments other than clock, model_fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if such models are developed we may want to replace this with a comment that the function signature should refer to the model documentation.
| 
 Great, that's what I originally had assumed and also what I wanted! Does this mean that the original change was the correct one? i.e. fcdecfb | 
| Not really, a  Oceananigans.jl/src/BoundaryConditions/continuous_boundary_function.jl Lines 126 to 134 in c75a112 
 Therefore, a generic number of arguments is not supported (at the moment), neither for continuous nor for discrete boundary functions.  Allowing it for a  To be honest, I like the simple design of passing a time (clock), field dependencies (fields), and some parameters that hold other user-defined arguments. It makes the interface simple, unique, and easily documentable for any boundary condition. I also think it covers most (if not all) of the use cases. However, if this design is not sufficient for other models' needs, we could expand it. @bgroenks96, what is the pattern that you need to achieve? Adding args... at the end might be a simple enough change to just cover more cases for both the countinuous and discrete boundary functions | 
| In general, the idea to answer before starting to change things is: how do you want your function signature to look for a generic (continuous or discrete) boundary condition that can be passed to your model? | 
| It seems like a fairly useful situation would be one in which the boundary conditions depend on a diffusivity or viscosity. This has been requested a number of times for  
 Can we change this so the code isn't so confusing to read? | 
| Let me add a few points here: 
 | 
| @bgroenks96 can you state the aim of this PR (not just its literal content)? Ie what outcome is it trying to achieve. | 
| I had the idea to pass additional arguments to  Edit: Also, I am fine with proposed design of passing arbitrary additional  | 
getbc for ContinuousBoundaryFunctiongetbc not passing extra args for discrete BC functions
      getbc not passing extra args for discrete BC functions| Ah I see, this breaks GPU support because the closure and buoyancy are passed into  I don't think this is a super critical change (I have been able to make do without it so far), so maybe we could just add a note to the docstring of  | 
| 
 Ok, now I see with the latest code changes what is needed! I think this is a positive addition --- thank you @bgroenks96 There are two additional changes that I think are needed, which I am happy to add here. First, we need to clean up / change  Also, because  Happy to take this on @bgroenks96 if you are ok with me sending a few commits here. | 
| 
 I think the problem is that the user interface for  
 I'm ok to take this up and push it through if you like! I understand the objective now --- allow args to propagate into  | 
| Feel free to push those changes! Thanks! | 
This is a quick fix for what seems to be a bug in the implementation of
getbcforDiscreteBoundaryFunctions. The extraargsare not passed through to the function as they are forContinuousBoundaryFunction.Let me know @glwagner and/or @simone-silvestri if this is actually intentional and I am missing something.