Skip to content

Bug fix for HRLDAS urban array allocation with SF_URBAN_PHYSICS 2 and 3#241

Closed
sashanksilwal wants to merge 16 commits into
NCAR:developfrom
sashanksilwal:fix/urban-physics-allocation-bug
Closed

Bug fix for HRLDAS urban array allocation with SF_URBAN_PHYSICS 2 and 3#241
sashanksilwal wants to merge 16 commits into
NCAR:developfrom
sashanksilwal:fix/urban-physics-allocation-bug

Conversation

@sashanksilwal
Copy link
Copy Markdown

In the HRLDAS driver's NoahmpIOVarInitMod.F90, urban arrays (e.g. TR_URB2D, QC_URB2D, DZR, DZB, DZG, TRL_URB3D) were only allocated and initialized inside the SF_URBAN_PHYSICS == 1 (SLUCM) block. These arrays are passed as non-optional arguments to urban_param_init, urban_var_init, and noahmp_urban, all called when SF_URBAN_PHYSICS > 0.

Issue I faced: Using BEP (SF_URBAN_PHYSICS=2) or BEM (SF_URBAN_PHYSICS=3) causes a segmentation fault due to unallocated arrays

Fix: remove the SF_URBAN_PHYSICS == 1 guards so these arrays are allocated/initialized for all urban modes. The WRF driver is unaffected as its equivalent section is disabled (if (0 == 1))

cenlinhe and others added 14 commits March 6, 2024 16:20
Sync with Develop branch for bug fix
Sync with Develop branch for adding LIS driver folder
Sync with Develop branch for bug fix and new snow compaction
Merge develop branch for release of v5.1
Update RELEASE_NOTES for v5.1.0 release
Update README file for v5.1.0 release
Update RELEASE_NOTES.md
Update RELEASE_NOTES.md
Merge with Develop branch for v5.2.0
@cenlinhe cenlinhe requested review from cenlinhe and tslin2 March 15, 2026 21:46
Copy link
Copy Markdown
Collaborator

@tslin2 tslin2 left a comment

Choose a reason for hiding this comment

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

will also need to update HRLDAS driver codes

@cenlinhe
Copy link
Copy Markdown
Collaborator

cenlinhe commented Apr 8, 2026

Thank you for identifying this issue. Instead of entirely removing the if-statement for SF_URBAN_PHYSICS = 1, I prefer identifying the variables shared by SF_URBAN_PHYSICS = 1-3 and then keep the if-statement for SF_URBAN_PHYSICS = 1 for those variables only used by SLUCM.

@tslin2 tslin2 self-requested a review April 10, 2026 03:47
Copy link
Copy Markdown
Collaborator

@tslin2 tslin2 left a comment

Choose a reason for hiding this comment

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

@sashanksilwal have you tested it? I am still getting error

I suggest we can revise codes in the module_sf_urban.f90 but not here, @cenlinhe how do you think

Because the issue happen in urban_param_init, urban_var_init, and noahmp_urban,

@cenlinhe
Copy link
Copy Markdown
Collaborator

cenlinhe commented Apr 10, 2026

@tslin2 I do not suggest modifying module_sf_urban.F as these files should be as close as the version inside WRF model, so I would avoid additional code changes within module_sf_urban.F if it can be fixed on the noahmp part. However, if it cannot be fixed from the noahmp urban driver part only and it is indeed a bug inside module_sf_urban.F, then we can modify module_sf_urban.F.

@sashanksilwal sashanksilwal marked this pull request as draft April 10, 2026 04:53
@tslin2
Copy link
Copy Markdown
Collaborator

tslin2 commented Apr 10, 2026

@tslin2 I do not suggest modifying module_sf_urban.F as these files should be as close as the version inside WRF model, so I would avoid additional code changes within module_sf_urban.F if it can be fixed on the noahmp part. However, if it cannot be fixed from the noahmp urban driver part only and it is indeed a bug inside module_sf_urban.F, then we can modify module_sf_urban.F.

For example there is the issue below:
when running urban 2 or 3, QC_URB2D is not allocated,
https://github.com/NCAR/hrldas/blob/0dc57ea6cda02f89ca0eb8634ffcb3c5b55476a0/urban/wrf/module_sf_urban.F#L2822

Either change to IF (sf_urban_physics == 1) QC_URB2D(I,J)=0.01 for this line in module_sf_urban.F

or need to allocate QC_URB2D in NoahmpIOVarInitMod.F90

Another example is https://github.com/NCAR/hrldas/blob/0dc57ea6cda02f89ca0eb8634ffcb3c5b55476a0/urban/wrf/module_sf_urban.F#L2826-L2840

  XXXR_URB2D(I,J)=0.
  XXXB_URB2D(I,J)=0.
  XXXG_URB2D(I,J)=0.
  XXXC_URB2D(I,J)=0.

can move to the loop inside IF ( sf_urban_physics == 1 ) THEN

or allocate these four variables in NoahmpIOVarInitMod.F90

I think both method can fix this issue.

@cenlinhe
Copy link
Copy Markdown
Collaborator

OK, I see. I would recommend allocating those variables in NoahmpIOVarInitMod.F90

@tslin2
Copy link
Copy Markdown
Collaborator

tslin2 commented Apr 10, 2026

I submit a PR to fix this at #243

@cenlinhe
Copy link
Copy Markdown
Collaborator

OK, I am closing this PR since the new PR #243 is submitted.

@cenlinhe cenlinhe closed this Apr 10, 2026
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