csdms / bmi

The Basic Model Interface is a standardized set of functions allowing coupling of models to models and models to data
https://bmi.readthedocs.io
MIT License
49 stars 17 forks source link

Harmonize MODFLOW 6 and CSDMS BMI implementation approaches #66

Open mdpiper opened 4 years ago

mdpiper commented 4 years ago

I'm opening this issue to facilitate discussion of how we can harmonize the BMI implementation techniques used by the MODFLOW development team and CSDMS.

The MODFLOW development team of @jdhughes-usgs and @langevin-usgs at USGS, working with @mjr-deltares at Deltares, has developed a BMI implementation for MODFLOW 6 that includes extensions (the AMI) that allow internal MODFLOW components to be tightly coupled within a time step as they iterate to a solution. The goal of this interstitial coupling is to eventually allow other models, such as PRMS or MetaSWAP, to be coupled with MODFLOW. Further, this team has developed a Python package, amipy, that wraps both BMI and AMI and allows MODFLOW 6 to be called from and run within Python (example).

The CSDMS development team of @mcflugen and @mdpiper has a slightly different approach that yields similar results. A model developer implements the Fortran BMI specification for their model. At CSDMS, we then wrap the BMI with an interoperability layer (similar to what's integrated into the BMI/AMI above), then compile and link the Fortran code into a C library through Cython, creating a Python package that can be called standalone or from pymt. This process has been templated and automated, so that once a model with a BMI is provided to CSDMS, it can be quickly processed into a Python package. The PRMS Surface component provides an example of this process. Here are the key points:

jdhughes-usgs commented 2 years ago

Maybe there could be an Basin Model Interface for Fortran (iso_c_binding) bmi-fortran-isoc version like there is for standard Fortran bmi-fortran?

mdpiper commented 2 years ago

Yeah, having a separate BMI for Fortran would solve this. The more I think about it, though, I think you guys did it right. The iso_c_binding module has been standard since Fortran 2003, and because we have an eye toward coupling (and cross-language compiling) whenever we implement a BMI, we should just use it. I was maybe being too dogmatic in wanting to use object-oriented Fortran (Fortran 2003), but not wanting to use this module. Perhaps it's stuck in my mind as an extension.

Updating the Fortran BMI language spec would be a great task for BMI v3.0!