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

NWTC_Lib: Adding Yaml and VTK to library (moved from SD and AD) #1333

Merged
merged 10 commits into from
Nov 29, 2022

Conversation

ebranlard
Copy link
Contributor

@ebranlard ebranlard commented Nov 18, 2022

This pull request is ready to be merged

Feature or improvement description
This pull request:

  • moves the VTK.f90 and YAML.f90 files which were respectively stored in AeroDyn and SubDyn.
  • adds JSON.f90 file (instead of having if statements in the YAML.f90)
  • fix a couple of vfproj solutions

I believe these modules fit within the "NWTC library" as they deal with generic IO operations.

Both AeroDyn and WakeDynamics have dependencies on VTK.f90.

Only SubDyn depends on Yaml.f90 for now, but I think it would be valuable to write the BeamDyn summary file in Yaml format, and the HydroDyn linearized matrices in that format too, so that their output can more easily be parsed (it's human and machine readable).

I'm happy to hear from @bjonkman as well if these changes are fine.

Impacted areas of the software
NWTC lib

Test results, if applicable
No change of tests

Example usage

Typical usage of the YAML library:

   call yaml_write_var  (UnSum, 'Mass', 10      , 'ES15.6E2', ErrStat2, ErrMsg2, comment='Total Mass')
   call yaml_write_list (UnSum, 'ID'  ,(/1,2,5/), 'I3'      , ErrStat2, ErrMsg2)
   call yaml_write_array(UnSum, 'Rib' , eye(3)  , 'ES15.6E2', ErrStat2, ErrMsg2, comment='Transformation matrix')

Should produce the following output:

Mass:    1.000000E+01 # Total Mass
ID: [  1,  2,  5]
Rib: # 3 x 3 Transformation matrix
  - [   1.000000E+00,   0.000000E+00,   0.000000E+00]
  - [   0.000000E+00,   1.000000E+00,   0.000000E+00]
  - [   0.000000E+00,   0.000000E+00,   1.000000E+00]

Typical usage of the VTK libray:

    call vtk_misc_init(mvtk) ! initialize vtk options
    ! Open VTK file write data for points and cells
    if ( vtk_new_ascii_file(filename, '', mvtk)) then
        call vtk_dataset_polydata(Points, mvtk) ! Points
        call vtk_quad(Connectivity, mvtk)       ! Connectivity table
        call vtk_cell_data_init(mvtk)           ! Initialize cell data (defined by connectivity)
        call vtk_cell_data_scalar(CellValues, 'Gamma', mvtk) ! Scalar value per cell
        call vtk_point_data_init(mvtk)           ! Initialize point data
        call vtk_point_data_vector(PointDataVec, 'Vel', mvtk) ! Vector data per point
     endif
     ! Open VTK file write data for structured points (e.g. plane, 3d grids)
    if ( vtk_new_ascii_file(filename2, '', mvtk)) then
        call vtk_dataset_structured_points((x0, y0, z0/), (/dx, dy, dz/), (/nx,ny,nz/), mvtk)
        call vtk_point_data_init(mvtk) ! Initialize point data
        call vtk_point_data_scalar(Vx, 'Vx', mvtk)  ! Scalar data on grid points
     endif

@andrew-platt
Copy link
Collaborator

Do we need to include use vtk and use yaml statements in the NWTC_Library.f90 file, or do we just want to lump these module into the library and require explicit use statements in the code for them?

@ebranlard
Copy link
Contributor Author

So far I've put the modules outside of the "library module", but inside the library.
I'm fine putting it into the module as well. I will just have to update of couple of vfproj and remove the "use VTK" and "use YAML" statements.

@ebranlard
Copy link
Contributor Author

@bjonkman do you have an opinion on whether these should be integrated into the library module?

@bjonkman
Copy link
Contributor

I like having these routines contained in the NWTC_Library directory.

I could go either way on having them in the NWTC_Library module. If they were linking with or using other (external) modules, I would say to just keep them separated. Do you have plans to link with any other standard yaml or vtk libraries in the future? (I haven't looked what kind of standard libraries there are, though I've used C/C++ versions in other projects.) What about the existing ReadVTK_* and WrVTK_* subroutines that are in NWTC_IO.f90?

One comment about the YAML Write Array 2D routines: it seems like they have optional arguments to output as json format. I'd be inclined to make separate subroutines for the json formats so that the routines always write yaml format, as their names indicate.

@ebranlard
Copy link
Contributor Author

Thanks Bonnie for the feedback.

I think it will make sense to add the ReadVTK_ and WriteVTK routines to VTK.f90.

I agree that it's nice to put the JSON routines separately. I think it might make sense to put this into JSON.f90 (comparing the YAML.f90 and JSON.f90 would then be easy, as I expect some similar code between the two.

I'll try to do that this afternoon.

@bjonkman
Copy link
Contributor

@ebranlard: FYI, it is possible that the ModMesh.f90 routines that write meshes to VTK may use those routines, so moving them into VTK.f90 might require putting module VTK in module NWTC_Library.

@ebranlard
Copy link
Contributor Author

ebranlard commented Nov 28, 2022

Hi @bjonkman , yes, I'm currently noticing that.

We could:

  • put the header and footer VTK writer in modmesh
  • or have modmesh depend on VTK.

@ebranlard
Copy link
Contributor Author

ebranlard commented Nov 28, 2022

I've put the WrWTK_* and ReadVTK* routines into VTK.
Now ModMesh requires VTK, which means VTK is part of the NWTC_Library somehow. I personally don't mind explicit imports (like use VTK instead of use NWTC_Library).

YAML, JSON, and VTK depends on NWTC_IO.

I've done explicit imports at the beginning of these modules, let me know if you don't like that. I like it because it makes it clearer what the module relies on, see here:

https://github.com/ebranlard/openfast/blob/f/nwtc-io-libs/modules/nwtc-library/src/JSON.f90#L21
https://github.com/ebranlard/openfast/blob/f/nwtc-io-libs/modules/nwtc-library/src/VTK.f90#L7
https://github.com/ebranlard/openfast/blob/f/nwtc-io-libs/modules/nwtc-library/src/YAML.f90#L21

If you have some quick feedback, I'm happy to include it. Otherwise, I'd like to move on, and let you free to rearrange this in future pull requests.

modules/nwtc-library/src/JSON.f90 Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
vs-build/MoorDyn/MoorDynDriver.vfproj Outdated Show resolved Hide resolved
@ebranlard ebranlard merged commit 381660f into OpenFAST:dev Nov 29, 2022
@ebranlard ebranlard deleted the f/nwtc-io-libs branch November 30, 2022 02:30
@rafmudaf rafmudaf mentioned this pull request Dec 19, 2022
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants