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

Refactor SPITFIRE - overhaul of fire behavior sections (but bit4bit) #1326

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

adrifoster
Copy link
Contributor

Description:

I have refactored the sections of the SPITFIRE code for better clarity and more sensible (IMO) calling order. I have also moved most of the equations into helper functions for testing purposes and better modularity

Expectation of Answer Changes:

None - everything is bit for bit.

One note on this - I was unable to update this method as I would like because of an order of operations (round off) difference. I would like to update this eventually but perhaps can wait until a non-b4b PR?

Or I can change it now...

Checklist

Contributor

  • The in-code documentation has been updated with descriptive comments
  • The documentation has been assessed to determine if updates are necessary

Integrator

  • FATES PASS/FAIL regression tests were run
  • Evaluation of test results for answer changes was performed and results provided

Test Results:

CTSM (or) E3SM (specify which) test hash-tag: ctsm5.3.020

CTSM (or) E3SM (specify which) baseline hash-tag: ctsm5.3.020

FATES baseline hash-tag: sci.1.80.11_api.37.0.0

Test Output:

Was b4b on last check - will run again after any suggested updates.

@glemieux glemieux requested review from samsrabin and mpaiao February 10, 2025 20:16
Copy link
Contributor

@samsrabin samsrabin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work cleaning this up and adding a lot of clever testing. I just have some minor suggestions.


if (windspeed_km_hr < 1.0_r8) then
LengthToBreadth = 1.0_r8
else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leading whitespace is misaligned in this block.

if (i /= fuel_classes%trunks()) then
! don't include 1000-hr fuels
! convert loading from kgC/m2 to g/cm2
tau_l = tau_l + 39.4_r8*(this%frac_loading(i)*this%non_trunk_loading/0.45_r8/10.0_r8)* &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary whitespace before the & here.

FireDuration = (SF_val_max_durat + 1.0_r8)/(1.0_r8 + SF_val_max_durat* &
exp(SF_val_durat_slope*FDI))

end function FireDuration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end function misaligned with function.

else
if (tree_fraction > lb_threshold) then
LengthToBreadth = (1.0_r8 + (8.729_r8* &
((1.0_r8 -(exp(-0.03_r8*m_per_min__to__km_per_hour*effective_windspeed)))**2.155_r8)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

windspeed_km_hr should be used here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the part that is not bit-for-bit if I change it. Maybe there is a way to set it so that it is b4b?

LengthToBreadth = (1.0_r8 + (8.729_r8* &
((1.0_r8 -(exp(-0.03_r8*m_per_min__to__km_per_hour*effective_windspeed)))**2.155_r8)))
else
LengthToBreadth = (1.1_r8*((m_per_min__to__km_per_hour*effective_windspeed)**0.464_r8))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

windspeed_km_hr should be used here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above


! fire size [m2]
fire_size = FireSize(length_to_breadth, currentPatch%ROS_back, &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary spacing before & here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a style thing... maybe it's just me. I try to put the & at a specific row, but I can discontinue that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok. I generally try not to do alignment stuff like that because it inevitably gets messed up or needs to be re-aligned, but if that's your style I won't fight you on it.


! convert to area burned per area patch per day
! i.e., fraction of the patch burned on that day
currentPatch%frac_burnt = min(0.99_r8, area_burnt/m2_per_km2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.99 is a magic number here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is from the old subroutine. I have no idea why this was put here. I'm not sure why we can't burn the entire patch, but 0.99 is seemingly arbitrary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure. See my previous comment though—it'd be good for this to be a named variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that works for me! though perhaps we want to add this to the list of things to scientifically validate?


@Test
subroutine OptimumPackingRatio_ReturnsReasonableValues(this)
! test that when SAV is some reasonable value, OptimumPackingRatio is correclty output
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"correclty" typo

class(TestFireEquations), intent(inout) :: this ! test object
real(r8) :: I_r(5) ! result
integer :: i ! looping index
real(r8), parameter :: moist = 0.2_r8 ! value for moiture
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"moiture" typo here and elsewhere

real(r8), parameter :: fuel = 10.0_r8 ! value for fuel
real(r8), parameter :: SAV = 50.0_r8 ! value for SAV
real(r8), parameter :: MEF = 0.5_r8 ! value for MEF
! hard-coded beta ratio values
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment could use an explanation of what "beta ratio" is.

@adrifoster
Copy link
Contributor Author

thanks for the review @samsrabin! Will work on suggested changes.

The request to change that windspeed_km_hr stuff is definitely something I want to do, but I wasn't able to update it without incurring roundoff diffs due to order of operations shenanigans. Is it acceptable to leave in for now (can add comment) and submit a subsequent PR to just update this?

@samsrabin
Copy link
Contributor

Ahh, that makes sense. In that case, this is such a simple change that I think it'd be fine to include it on this PR, after you've shown everything else is bit-for-bit.

@adrifoster
Copy link
Contributor Author

Ahh, that makes sense. In that case, this is such a simple change that I think it'd be fine to include it on this PR, after you've shown everything else is bit-for-bit.

@glemieux what do you think? You had mentioned you wanted this PR to be b4b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Under Review
Development

Successfully merging this pull request may close these issues.

2 participants