Remove repetitive code in module_sf_urban.F#1593
Conversation
| IF( IVGTYP(I,J) == LCZ_1) THEN | ||
| UTYPE_URB2D(I,J) = 1 ! high-intensity | ||
| UTYPE_URB = UTYPE_URB2D(I,J) ! high-intensity | ||
| IF (HGT_URB2D(I,J)>0.) THEN | ||
| CONTINUE | ||
| ELSE | ||
| WRITE(mesg,*) 'USING DEFAULT URBAN MORPHOLOGY' | ||
| WRITE_MESSAGE(mesg) | ||
| LP_URB2D(I,J)=0. | ||
| LB_URB2D(I,J)=0. | ||
| HGT_URB2D(I,J)=0. | ||
| IF ( sf_urban_physics == 1 ) THEN | ||
| MH_URB2D(I,J)=0. | ||
| STDH_URB2D(I,J)=0. | ||
| DO K=1,4 | ||
| LF_URB2D(I,K,J)=0. | ||
| ENDDO | ||
| ELSE IF ( ( sf_urban_physics == 2 ) .or. ( sf_urban_physics == 3 ) ) THEN | ||
| DO K=1,num_urban_hi | ||
| HI_URB2D(I,K,J)=0. | ||
| ENDDO | ||
| ENDIF | ||
| ENDIF | ||
| IF (FRC_URB2D(I,J)>0.and.FRC_URB2D(I,J)<=1.) THEN | ||
| CONTINUE | ||
| ELSE | ||
| WRITE(mesg,*) 'WARNING, FRC_URB2D = 0 BUT IVGTYP IS URBAN' | ||
| WRITE_MESSAGE(mesg) | ||
| WRITE(mesg,*) 'WARNING, THE URBAN FRACTION WILL BE READ FROM URBPARM.TBL' | ||
| WRITE_MESSAGE(mesg) | ||
| FRC_URB2D(I,J) = FRC_URB_TBL(UTYPE_URB) | ||
| ENDIF | ||
| SWITCH_URB=1 | ||
| ENDIF |
There was a problem hiding this comment.
Should this repeated block appear one time? Do you remove all occurrences?
There was a problem hiding this comment.
@davegill One occurrence is kept in the end. I'll do one test with the urban options, but where should I upload the test result to?
|
@epn09 |
|
@CenLin He ***@***.***> This refers to the LCZ changes where each
LCZ has a duplicate code section.
Can you check this?
…On Tue, Dec 7, 2021 at 6:02 AM Dave Gill ***@***.***> wrote:
@epn09 <https://github.com/epn09>
It looks as if there is missing code that needs to be included at least
one time.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#1593 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEIZ77BELULC6F6JMETANM3UPYAYFANCNFSM5JRDALHA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
|
No, these parts should not be removed. These if-statements are used to assign the correct values to UTYPE_URB2D and UTYPE_URB according to the LCZ value in each grid. But I agree that there are some repeated codes within each if-statement that could be further refined. However, since this will not affect the model efficiency or accuracy, I suggest not doing any changes to this part right now, or at least the person who submitted this PR should first check with the original code developer @andreazonato |
|
@cenlinhe I understand the purpose of the original code but from LCZ_1 to LCZ_11, the difference is only in the first two lines (written below), the following lines are purely copy and paste. |
| IF( IVGTYP(I,J) == LCZ_9) THEN | ||
| UTYPE_URB2D(I,J) = 9 ! high-intensity | ||
| UTYPE_URB = UTYPE_URB2D(I,J) ! high-intensity | ||
| IF (SWITCH_URB == 1) THEN |
There was a problem hiding this comment.
@davegill The diff is too large. The "missing code" that you mentioned starts from here.
|
@epn09 Yes, you are right. Could you please do a test to see if your refined code produces exactly the same results as the original code? If so, we can approve the change. Also, another suggestion: it seems that your modifications are too scattered (e.g., insert or remove things in between if-else statement, etc.), which makes it difficult to check in the 'Files changed' part. It may be better to remove all the repeated parts first, and then lump together your refined code in one integrated part so that it would be easier to compare the new code and original code. |
7a714dd to
3ac1417
Compare
|
@cenlinhe I have split the original commit into 6 smaller commits. Is it easier to understand for you? |
|
Hi all, I think these modifications make sense, they decrease the computational time for sure. The only doubt I have regards the first SWITCH_URB=1. Is it in the right position? Andrea |
|
Hi @andreazonato, For your concern, you can take a look at this comit a8d55d7 or the explanation below. Originally, the code was SWITCH_URB = 0
IF (IVGTYP(I,J) == ISURBAN) THEN
! do some thing for ISURBAN
SWITCH_URB = 1
ENDIF
IF (IVGTYP(I,J) == LCZ_1) THEN
! do some thing for LCZ_1
SWITCH_URB = 1
ENDIF
IF (SWITCH_URB == 0) THEN
CONTINUE
ELSE
! do something for non-urban
ENDIFThe first two ifs are mutually exclusive, so we can combine with SWITCH_URB = 0
IF (IVGTYP(I,J) == ISURBAN) THEN
! do some thing for ISURBAN
SWITCH_URB = 1
ELSE IF (IVGTYP(I,J) == LCZ_1) THEN
! do some thing for LCZ_1
SWITCH_URB = 1
ENDIF
IF (SWITCH_URB == 0) THEN
CONTINUE
ELSE
! do something for non-urban
ENDIFThe role of SWITCH_URB = 1
IF (IVGTYP(I,J) == ISURBAN) THEN
! do some thing for ISURBAN
ELSE IF (IVGTYP(I,J) == LCZ_1) THEN
! do some thing for LCZ_1
ELSE
SWITCH_URB = 0
ENDIF
IF (SWITCH_URB == 0) THEN
CONTINUE
ELSE
! do something for non-urban
ENDIF |
|
@andreazonato @cenlinhe |
|
@davegill @andreazonato @cenlinhe |
|
Yes, in my opinion it makes sense. I agree with the modifications! |
|
It looks good to me too. |
|
@cenlinhe Can you approve this PR? Click on the 'Files changed' option and see if you can see 'Review changes' in a green box on top right. If not, I will do that. |
cenlinhe
left a comment
There was a problem hiding this comment.
This re-structuring of the code looks good and the developer has also confirmed the same results before and after this re-structure.
|
@epn09 To keep a record, could you please also send us the results of your bit-by-bit comparison before and after the change? Any summary tables, figures, and/or small-size data files will be good. My email: cenlinhe@ucar.edu |
weiwangncar
left a comment
There was a problem hiding this comment.
The LSM/urban experts have said ok to this code change.
|
@davegill I have added my affiliation. |
TYPE: enhancement KEYWORDS: urban physics SOURCE: Do Ngoc Khanh (Tokyo Institute of Technology) DESCRIPTION OF CHANGES: Problem: There was a code block repeated 12 times. Solution: Purely refactor, no change in algorithm. LIST OF MODIFIED FILES: M phys/module_sf_urban.F TESTS CONDUCTED 1. Confirmed bit-by-bit identical output, before vs after. 2. Jenkins tests are all passing. RELEASE NOTE: Remove repetitive code in module_sf_urban.F


TYPE: enhancement
KEYWORDS: urban physics
SOURCE: Do Ngoc Khanh (Tokyo Institute of Technology)
DESCRIPTION OF CHANGES:
Problem: There was a code block repeated 12 times.
Solution: Purely refactor, no change in algorithm.
LIST OF MODIFIED FILES:
M phys/module_sf_urban.F
TESTS CONDUCTED
RELEASE NOTE: Remove repetitive code in module_sf_urban.F