Skip to content
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

Update src/drivers/schism/fabm_driver.h with MASK definitions #64

Merged
merged 5 commits into from
Apr 23, 2024

Conversation

platipodium
Copy link
Contributor

Recent versions of SCHISM need the MASK_TYPE and MASK_VALUE to be defined in the driver. This Commit adds the relevant definitions. We also update copyright and license (placed in public domain).

Recent versions of SCHISM need the MASK_TYPE and MASK_VALUE to be defined in the driver.  This Commit adds the relevant definitions.  We also update copyright and license (placed in public domain).
@bolding
Copy link
Contributor

bolding commented Apr 18, 2024

Hi Carsten

Will it break older versions of SCHISM?

Karsten

@platipodium
Copy link
Contributor Author

Will it break older versions of SCHISM?

No, it will not break older versions of SCHISM. As there is no mask in those, the defines will simply be not used at all.

@jornbr
Copy link
Member

jornbr commented Apr 18, 2024

Just to note that if you do provide _FABM_MASK_TYPE_, FABM will demand that the mask has been provided when you call model%start. Thus, in theory, this PR could break backward compatibility. But the question is whether there is a SCHISM-FABM coupler out there that is (a) mask-free and (b) compatible with the latest FABM releases. If not, there is no harm updating SCHISM's fabm_driver.h in the current master.

A separate question that has no implication for this PR, but maybe for future development: does the mask really need to be depth-explicit? If SCHISM either uses all vertical layers (wet point), or none at all (dry point), you could tell FABM that the mask is horizontal-only by defining _FABM_HORIZONTAL_MASK_. That can offer noticeable performance gains.

@platipodium
Copy link
Contributor Author

in theory, this PR could break backward compatibility. But the question is whether there is a SCHISM-FABM coupler out there that is (a) mask-free and (b) compatible with the latest FABM releases.

Thanks for the hint to this implicit code breaking potential. There is as far as I know only one fabm_schism coupler under the control of the schism-dev community, and I lead that development. There are uses of this coupler in very old versions with FABM0, not setting a mask. Set_mask was implemented in the coupler in May 2016, for both FABM0 and FABM1. We should be willing to risk breaking code that is > 8 years old and FABM0.

@platipodium
Copy link
Contributor Author

If SCHISM either uses all vertical layers (wet point), or none at all (dry point), you could tell FABM that the mask is horizontal-only by defining FABM_HORIZONTAL_MASK. That can offer noticeable performance gains.

Thanks for this hint, I checked the code, there are no uses of a non-horizontal mask, so we should indeed define _FABM_HORIZONTAL_MASK_

@bolding
Copy link
Contributor

bolding commented Apr 18, 2024

@platipodium
Copy link
Contributor Author

right now there are errors :-)
https://github.com/fabm-model/fabm/actions/runs/8737222365/job/23974279396?pr=64

I am looking into these, and can reproduce them locally. schism host is very similar to fvcom host. The only difference is that in schism the _FABM_DEPTH_DIMENSION_INDEX_ 1 whereas in fvcom _FABM_DEPTH_DIMENSION_INDEX_ 2. In fact, changing the depth dimension index to 2 in the schism host for test_host passes the test harness. I can reproducibly produce the test harness failure by changing this value only. Is this potentially a problem in the test harness itself and not in the driver?

SCHISM does not need a 3D mask, so for performance reasons `_FABM_HORIZONTAL_MASK_` should be defined
@jornbr
Copy link
Member

jornbr commented Apr 18, 2024

Exactly right - it's a problem in the test harness (SCHISM uses a quite unique combination of settings in fabm_driver.h, so it shows up only there). Looking into it...

@jornbr
Copy link
Member

jornbr commented Apr 19, 2024

The test harness has now been updated. Can you pull the latest changes from FABM master into your PR branch? Then the tests should pass, and we'll merge it in.

Breaks existing code, we might reintroduce as soon as the 
1) discussion about performance is resolved
2) the SCHISM code respects this #define
@platipodium
Copy link
Contributor Author

The test harness fails with two models:

2 ERRORS! Check the logs:
test_harness_schism_fabm-nersc-ecosmo.log
test_harness_schism_fabm-npzd-carbonate.log

The error is similar:

Simulating with 542 wet cells...
 S,T,P   30.000000000000000        15.000000000000000        1.0000000000000000     
 CONCS  -196078431372549.03        2.0573000000000002E-003   6.0134700169990685E-154   100.00000000000000        2.3164141992681716E-155   0.0000000000000000       -196078431372549.03        1.4917138461599308E-154   3.5382693357715792E-004
co2_dyn:POLYCO: Haltafall iteration did not converge.
Note: The following floating-point exceptions are signalling: IEEE_DIVIDE_BY_ZERO IEEE_UNDERFLOW_FLAG IEEE_DENORMAL

@jornbr
Copy link
Member

jornbr commented Apr 22, 2024

These runtime failures likely relate to the test harness requesting source terms in masked cells. I have updated the test harness code in master to avoid this, and also added more logic to skip calculations in masked cells/below bottom for models like SCHISM (i.e., with the vertical dimension vectorized, variable bottom index). That's in preparation for use with _FABM_HORIZONTAL_MASK_. Can you try merging in the latest master? We'll the rerun the tests.

@jornbr jornbr merged commit 561264d into fabm-model:master Apr 23, 2024
24 checks passed
@platipodium platipodium deleted the patch-1 branch April 23, 2024 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants