LHEEA/Grid2Grid

Problem to run the test program

Opened this issue · 8 comments

Dear Grid2Grid developers:
I have problem to run the test subroutine in the src/libGrid2Grid/main.f90 after compiling the grid2grid library.
I can successfully compile the grid2grid library. However, when I test the surboutine testSurf2Vol() in debug mode, the program has error. The program i tested is located at src/libGrid2Grid/main.f90
The program generated the following error:
HOS Ocean Surf2Vol ...

forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
Grid2GridTest 00000000006FC43A Unknown Unknown Unknown
libpthread-2.31.s 00007FFFF7E593C0 Unknown Unknown Unknown
Grid2GridTest 00000000004944A6 Unknown Unknown Unknown
Grid2GridTest 0000000000493F06 Unknown Unknown Unknown
Grid2GridTest 00000000004A48DA Unknown Unknown Unknown
Grid2GridTest 0000000000536384 Unknown Unknown Unknown
Grid2GridTest 0000000000534E90 Unknown Unknown Unknown
Grid2GridTest 000000000054A38F Unknown Unknown Unknown
Grid2GridTest 000000000040C4B8 Unknown Unknown Unknown
Grid2GridTest 0000000000403948 Unknown Unknown Unknown
Grid2GridTest 00000000004038D2 Unknown Unknown Unknown
libc-2.31.so 00007FFFF7C790B3 __libc_start_main Unknown Unknown
Grid2GridTest 00000000004037DE Unknown Unknown Unknown

I debug the code and fund the program will have error at line #209 of hosOcean.inc:

this%nXmode_ = nint(x1) * this%dict_%getIntOrDefault("extraInterpolationNumber", 1)

It looks like %this%dict_ is not initialized and the function getIntOrDefault() can't evaluate
this%nkey method.

The tested main program is changed to run the subroutine testSurf2Vol().

The program is as followings:
Program main

Implicit None
Character(Len =100) :: inputFileName
inputFileName = "postGrid2Grid.dict"

!Call testDict()
!Call testPost(inputFileName)

 Call testSurf2Vol()

! Call testVol2Vol()

End Program

I used the intel Fortran compiler with version 19.1.1.217

I fixed the bug by adding the following line at line #140 of file hosOcen.inc
CALL this%dict_%initialize("HOSOcean")
The code is just before the following code:
! Read and initalize HOS simulation parameter
Call this%init_read_mod()

I think the hosNWT has similar bug suggest to add following at #150 of hosNWT.inc
CALL this%dict_%initialize("HOSNWT")
The code is just above the following code:
! Read and initalize HOS simulation parameter depending on file extension
Call this%init_read_mod()

Dear trimtrim,

I understand your problem. The test routine called "testSurf2Vol()" was used in Grid2Grid version1.
As we updated to Grid2Grid version 2, we adopted the dictionary input format which may conflict.

There are two subroutines initializing HOS Ocean or NWT types.

  • initialize the type with basic arguments (no advanced feature will be updated, only default option)
  • initialize the type with dictionary input (we can control many parameters)

I recommend you to use dictionary format which allows us a flexible input format, you will understand after comparing two subroutines.

Here's what happens:

  • You tested with the original subroutine with basic input (no dictionary pointer allocated in this subroutine). You allocated the dictionary pointer (actually, the pointer (address) is allocated but no data is included). Of course, this is one way to solve it, but I would fix the code as:

1. hosOcean.typ

type, public :: typHOSOcean
...
Integer :: extraInterpolationNumber

end type

2. hosOcean.inc

Add the lines:
Subroutine initHOSOceanSurf2VolDict(this, HOSDict)
....
#78: this%extraInterpolationNumber = this%dict_%getIntOrDefault("extraInterpolationNumber", 1)
....
End Subroutine

Subroutine initHOSOcean(this, ...)
....
#138: this%extraInterpolationNumber = 1
....
End Subroutine

Change the code:
#209 : this%nXmode_ = nint(x1) * this%extraInterpolationNumber
#216 : this%nYmode_ = nint(x2) * this%extraInterpolationNumber

The same principles can be applied to HOSNWT. I will update the code and tutorials based on your comment.

Thank you for reporting the error:)

Have a nice day.

Best regards,
Young-Myung Choi

Dear Young-Myung Choi,
Thanks for the quick reply. The method you used is more appropriate. If possible, can you please upload more tutorial cases which can help the user further understand the features of the library?

Many thanks!
Regards

Dear trimtrim,

Thank you for the fast response. Then, I'll update the code as I recommended in the previous answer.

We are planning to update Grid2Grid (version 3) to have generalized structure & input/output and more options. I'll try to make many tutorials to understand the features of the library after update.

If you have suggestion or idea which could be good to include in the future, please let us know. We will very appreciate.

Thank you and have a nice day!

Best regards,
Young-Myung Choi

Dear Young-Myung Choi,
Can you share an example case, which uses dictionary to init the typHOSVol2Vol and carry out the computation like testVol2Vol subroutine ?
Many thanks!

Dear trimtrim,

You can take some code of "postGrid2Grid.inc". The class "typPostGrid2Grid" has a member class "typHOSVol2Vol" as:

postGrid2Grid.typ

Type, public :: typPostGrid2Grid
...
Type(typHOSVol2Vol) :: hosVol2Vol_
...
End Type

Then, you can see the initialize subroutine for "typPostGrid2Grid":

postGrid2Grid.inc

subroutine initializePostG2G(this, inputFileName)

! initialize HOS Vol2Vol with Dictionary
hosTypeName = this%dict_%getChar("Grid2Grid")
Call this%hosVol2Vol_%initialize(this%dict_%subDict(hosTypeName))

end subroutine

For the input file, you use the input for postGrid2Grid execution in the source code:

postGrid2Grid.dict

In this file format, there is keyword Grid2Grid with value "HOSOcean". Then, the sub-dictionary named "HOSOcean" given in the file will pass into the vol2vol class (dict_%subDict(HOSOcean) returns sub-dictionary).

HOSOcean
{
type Ocean;
...
}

Remark that there is $zMesh which contains the data of zMesh dictionary in the above (like a macro). If you just need a wrapper for HOS, you can simply look inside "example/fortGrid2Grid".

Have a nice day!

Best regards,
Young-Myung Choi