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
1 change: 0 additions & 1 deletion modules/aerodyn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ set(FVW_LIBS_SOURCES
src/FVW_BiotSavart.f90
src/FVW_Tests.f90
src/FVW_Types.f90
src/FVW_VTK.f90
)

# ADI lib
Expand Down
2 changes: 1 addition & 1 deletion modules/aerodyn/src/FVW.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ end subroutine CalcOutputForAD
!----------------------------------------------------------------------------------------------------------------------------------
!> Routine for computing outputs, used in both loose and tight coupling.
subroutine FVW_CalcOutput(t, u, p, x, xd, z, OtherState, y, m, ErrStat, ErrMsg)
use FVW_VTK, only: set_vtk_coordinate_transform
use VTK, only: set_vtk_coordinate_transform
use FVW_VortexTools, only: interpextrap_cp2node
real(DbKi), intent(in ) :: t !< Current simulation time in seconds
type(FVW_InputType), intent(in ) :: u !< Inputs at Time t
Expand Down
16 changes: 8 additions & 8 deletions modules/aerodyn/src/FVW_IO.f90
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ end function is_int
!> Export FVW variables to VTK
!! NOTE: when entering this function nNW and nFW has been incremented by 1
subroutine WrVTK_FVW(p, x, z, m, FileRootName, VTKcount, Twidth, bladeFrame, HubOrientation, HubPosition)
use FVW_VTK ! for all the vtk_* functions
use VTK ! for all the vtk_* functions
type(FVW_ParameterType), intent(in ) :: p !< Parameters
type(FVW_ContinuousStateType), intent(in ) :: x !< States
type(FVW_ConstraintStateType), intent(in ) :: z !< Constraints
Expand All @@ -373,7 +373,7 @@ subroutine WrVTK_FVW(p, x, z, m, FileRootName, VTKcount, Twidth, bladeFrame, Hub
real(Reki), dimension(:,:,:), allocatable :: Arr3D !<
real(Reki), dimension(:,:), allocatable :: Arr2D !<

type(FVW_VTK_Misc) :: mvtk
type(VTK_Misc) :: mvtk

call vtk_misc_init(mvtk)

Expand Down Expand Up @@ -473,7 +473,7 @@ end subroutine WrVTK_FVW
!> Export Grid velocity field to VTK
subroutine WrVTK_FVW_Grid(p, x, z, m, iGrid, FileRootName, VTKcount, Twidth, HubOrientation, HubPosition)
use FVW_VortexTools, only: curl_regular_grid
use FVW_VTK ! for all the vtk_* functions
use VTK ! for all the vtk_* functions
type(FVW_ParameterType), intent(in ) :: p !< Parameters
type(FVW_ContinuousStateType), intent(in ) :: x !< States
type(FVW_ConstraintStateType), intent(in ) :: z !< Constraints
Expand All @@ -490,7 +490,7 @@ subroutine WrVTK_FVW_Grid(p, x, z, m, iGrid, FileRootName, VTKcount, Twidth, Hub
character(Twidth) :: Tstr ! string for current VTK write-out step (padded with zeros)
real(ReKi), dimension(3) :: dx
type(GridOutType), pointer :: g
type(FVW_VTK_Misc) :: mvtk
type(VTK_Misc) :: mvtk

call vtk_misc_init(mvtk)
call set_vtk_binary_format(.false.,mvtk) ! TODO binary fails
Expand Down Expand Up @@ -524,9 +524,9 @@ end subroutine WrVTK_FVW_Grid


subroutine WrVTK_Segments(filename, mvtk, SegPoints, SegConnct, SegGamma, SegEpsilon, bladeFrame)
use FVW_VTK
use VTK
character(len=*),intent(in) :: filename
type(FVW_VTK_Misc), intent(inout) :: mvtk !< miscvars for VTK output
type(VTK_Misc), intent(inout) :: mvtk !< miscvars for VTK output
real(ReKi), dimension(:,:), intent(in) :: SegPoints !<
integer(IntKi), dimension(:,:), intent(in) :: SegConnct !<
real(ReKi), dimension(:) , intent(in) :: SegGamma !<
Expand All @@ -545,9 +545,9 @@ subroutine WrVTK_Segments(filename, mvtk, SegPoints, SegConnct, SegGamma, SegEps
end subroutine

subroutine WrVTK_Lattice(filename, mvtk, LatticePoints, LatticeGamma, LatticeData3d, bladeFrame)
use FVW_VTK ! for all the vtk_* functions
use VTK ! for all the vtk_* functions
character(len=*), intent(in) :: filename
type(FVW_VTK_Misc), intent(inout) :: mvtk !< miscvars for VTK output
type(VTK_Misc), intent(inout) :: mvtk !< miscvars for VTK output
real(Reki), dimension(:,:,:), intent(in ) :: LatticePoints !< Array of points 3 x nSpan x nDepth
real(Reki), dimension(:,:), intent(in ) :: LatticeGamma !< Array of nSpan x nDepth
real(Reki), dimension(:,:,:), intent(in ), optional :: LatticeData3d !< Array of n x nSpan x nDepth KEEP ME
Expand Down
4 changes: 2 additions & 2 deletions modules/aerodyn/src/FVW_Tests.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module FVW_Tests
use FVW_Wings
use FVW_IO
use FVW_BiotSavart
use FVW_VTK, only : FVW_VTK_Misc
use VTK, only : VTK_Misc

implicit none

Expand Down Expand Up @@ -602,7 +602,7 @@ end subroutine Test_SegmentsToPart

!>
subroutine Test_LatticeToSegment(mvtk,iStat)
type(FVW_VTK_Misc),intent(inout) :: mvtk !< miscvars for VTK output
type(VTK_Misc),intent(inout) :: mvtk !< miscvars for VTK output
integer(IntKi), intent( out) :: iStat !< Status for test
! Local
integer(IntKi),dimension(:,:), allocatable :: SegConnct !< Segment connectivity
Expand Down
1 change: 1 addition & 0 deletions modules/awae/src/AWAE.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,7 @@ subroutine AWAE_CalcOutput( t, u, p, x, xd, z, OtherState, y, m, errStat, errMsg
! placed in the y%WriteOutput(:) array.
!..................................................................................................................................

use VTK
real(DbKi), intent(in ) :: t !< Current simulation time in seconds
type(AWAE_InputType), intent(in ) :: u !< Inputs at Time t
type(AWAE_ParameterType), intent(in ) :: p !< Parameters
Expand Down
1 change: 1 addition & 0 deletions modules/awae/src/AWAE_IO.f90
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
MODULE AWAE_IO

use NWTC_Library
use VTK
use AWAE_Types


Expand Down
3 changes: 3 additions & 0 deletions modules/nwtc-library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#

set(NWTCLIBS_SOURCES
src/JSON.f90
src/ModMesh.f90
src/ModMesh_Mapping.f90
src/ModMesh_Types.f90
Expand All @@ -25,6 +26,8 @@ set(NWTCLIBS_SOURCES
src/NWTC_RandomNumber.f90
src/SingPrec.f90
src/NWTC_Library_Types.f90
src/VTK.f90
src/YAML.f90

# RanLux sources
src/ranlux/RANLUX.f90
Expand Down
215 changes: 215 additions & 0 deletions modules/nwtc-library/src/JSON.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
!..................................................................................................................................
! LICENSING
! Copyright (C) 2013-2016 National Renewable Energy Laboratory
!
! This file is part of NWTC_Library.
!
! Licensed under the Apache License, Version 2.0 (the "License");
! you may not use this file except in compliance with the License.
! You may obtain a copy of the License at
!
! http://www.apache.org/licenses/LICENSE-2.0
!
! Unless required by applicable law or agreed to in writing, software
! distributed under the License is distributed on an "AS IS" BASIS,
! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
! See the License for the specific language governing permissions and
! limitations under the License.
!
!**********************************************************************************************************************************
module JSON
use Precision, only: IntKi, SiKi, R8Ki, QuKi
use NWTC_Base, only: ErrID_None, ErrID_Fatal
use NWTC_IO, only: num2lstr

implicit none

!> Write 2D array to file in JSON format
interface json_write_array
module procedure json_write_array2R4 ! Two dimension array of SiKi
module procedure json_write_array2I ! Two dimension array of IntKi
module procedure json_write_array2R8 ! Two dimension array of R8Ki
module procedure json_write_array2R16 ! Two dimension array of QuKi
end interface

private

public :: json_write_array

contains


! --------------------------------------------------------------------------------}
! --- Write Array 2D
! --------------------------------------------------------------------------------{
subroutine json_write_array2I(fid, key, A, VarFmt, ErrStat, ErrMsg)
integer(IntKi), intent(in ) :: fid !< File Unit
character(len=*), intent(in ) :: key !< Array name
integer(IntKi), dimension(:,:), intent(in ) :: A !< Array
character(len=*), intent(in ) :: VarFmt !< Format for printing real numbers
integer, intent( out) :: ErrStat !< A non-zero value indicates an error occurred
character(len=*), intent( out) :: ErrMsg !< Error message if errstat /= errid_none
integer :: nr, nc, i ! size (rows and columns) of A
character(256) :: Fmt
ErrStat = ErrID_None
ErrMsg = ""
nr = size(A,1)
nc = size(A,2)

! Key
write(fid, '(A,": [")', iostat=ErrStat, advance='no') trim(key)
if (nr==0) then
write(fid, '("[]]")', iostat=ErrStat)
else
! JSON Line format
if (nc==1) then
Fmt = '("[",'//VarFmt//',"],")'
else
Fmt = '("[",'//trim(Num2LStr(nc-1))//'('//VarFmt//',","),'//VarFmt//',"]")'
endif
! Write line by line
do i=1,nr
write(fid, Fmt, iostat=ErrStat, advance='no') A(i,:)
if (i<nr) then
write(fid, '(A)', iostat=ErrStat, advance='no') ','
endif
enddo
write(fid, '("]")', iostat=ErrStat, advance='no')
endif
if (ErrStat /= 0) then
ErrStat = ErrID_Fatal
ErrMsg = 'Error writing array '//trim(key)//' to JSON file'
end if
end subroutine json_write_array2I

subroutine json_write_array2R4(fid, key, A, VarFmt, ErrStat, ErrMsg, AllFmt)
integer(IntKi), intent(in ) :: fid !< File Unit
character(len=*), intent(in ) :: key !< Array name
real(SiKi), dimension(:,:), intent(in ) :: A !< Array
character(len=*), intent(in ) :: VarFmt !< Format for printing real numbers
integer, intent( out) :: ErrStat !< A non-zero value indicates an error occurred
character(len=*), intent( out) :: ErrMsg !< Error message if errstat /= errid_none
character(len=*), optional, intent(in ) :: AllFmt !< Format for printing a line
integer :: nr, nc, i ! size (rows and columns) of A
character(256) :: Fmt
ErrStat = ErrID_None
ErrMsg = ""
nr = size(A,1)
nc = size(A,2)

! Key
write(fid, '(A,": [")', iostat=ErrStat, advance='no') trim(key)
if (nr==0) then
write(fid, '("[]]")', iostat=ErrStat)
else
! JSON Line format
if (present(AllFmt)) then
Fmt = '("[",'//trim(AllFmt)//'"]")'
elseif (nc==1) then
Fmt = '("[",'//VarFmt//',"],")'
else
Fmt = '("[",'//trim(Num2LStr(nc-1))//'('//VarFmt//',","),'//VarFmt//',"]")'
endif
! Write line by line
do i=1,nr
write(fid, Fmt, iostat=ErrStat, advance='no') A(i,:)
if (i<nr) then
write(fid, '(A)', iostat=ErrStat, advance='no') ','
endif
enddo
write(fid, '("]")', iostat=ErrStat, advance='no')
endif
if (ErrStat /= 0) then
ErrStat = ErrID_Fatal
ErrMsg = 'Error writing array '//trim(key)//' to JSON file'
end if
end subroutine json_write_array2R4

subroutine json_write_array2R8(fid, key, A, VarFmt, ErrStat, ErrMsg, AllFmt)
integer(IntKi), intent(in ) :: fid !< File Unit
character(len=*), intent(in ) :: key !< Array name
real(R8Ki), dimension(:,:), intent(in ) :: A !< Array
character(len=*), intent(in ) :: VarFmt !< Format for printing real numbers
integer, intent( out) :: ErrStat !< A non-zero value indicates an error occurred
character(len=*), intent( out) :: ErrMsg !< Error message if errstat /= errid_none
character(len=*), optional, intent(in ) :: AllFmt !< Format for printing a line
integer :: nr, nc, i ! size (rows and columns) of A
character(256) :: Fmt
ErrStat = ErrID_None
ErrMsg = ""
nr = size(A,1)
nc = size(A,2)

! Key
write(fid, '(A,": [")', iostat=ErrStat, advance='no') trim(key)
if (nr==0) then
write(fid, '("[]]")', iostat=ErrStat)
else
! YSON Line format
if (present(AllFmt)) then
Fmt = '("[",'//trim(AllFmt)//'"]")'
elseif (nc==1) then
Fmt = '("[",'//VarFmt//',"],")'
else
Fmt = '("[",'//trim(Num2LStr(nc-1))//'('//VarFmt//',","),'//VarFmt//',"]")'
endif
! Write line by line
do i=1,nr
write(fid, Fmt, iostat=ErrStat, advance='no') A(i,:)
if (i<nr) then
write(fid, '(A)', iostat=ErrStat, advance='no') ','
endif
enddo
write(fid, '("]")', iostat=ErrStat, advance='no')
endif
if (ErrStat /= 0) then
ErrStat = ErrID_Fatal
ErrMsg = 'Error writing array '//trim(key)//' to JSON file'
end if
end subroutine json_write_array2R8

subroutine json_write_array2R16(fid, key, A, VarFmt, ErrStat, ErrMsg, AllFmt)
integer(IntKi), intent(in ) :: fid !< File Unit
character(len=*), intent(in ) :: key !< Array name
real(QuKi), dimension(:,:), intent(in ) :: A !< Array
character(len=*), intent(in ) :: VarFmt !< Format for printing real numbers
integer, intent( out) :: ErrStat !< A non-zero value indicates an error occurred
character(len=*), intent( out) :: ErrMsg !< Error message if errstat /= errid_none
character(len=*), optional, intent(in ) :: AllFmt !< Format for printing a line
integer :: nr, nc, i ! size (rows and columns) of A
character(256) :: Fmt
ErrStat = ErrID_None
ErrMsg = ""
nr = size(A,1)
nc = size(A,2)

! Key
write(fid, '(A,": [")', iostat=ErrStat, advance='no') trim(key)
if (nr==0) then
write(fid, '("[]]")', iostat=ErrStat)
else
! JSON Line format
if (present(AllFmt)) then
Fmt = '("[",'//trim(AllFmt)//'"]")'
elseif (nc==1) then
Fmt = '("[",'//VarFmt//',"],")'
else
Fmt = '("[",'//trim(Num2LStr(nc-1))//'('//VarFmt//',","),'//VarFmt//',"]")'
endif
! Write line by line
do i=1,nr
write(fid, Fmt, iostat=ErrStat, advance='no') A(i,:)
if (i<nr) then
write(fid, '(A)', iostat=ErrStat, advance='no') ','
endif
enddo
write(fid, '("]")', iostat=ErrStat, advance='no')
endif
if (ErrStat /= 0) then
ErrStat = ErrID_Fatal
ErrMsg = 'Error writing array '//trim(key)//' to JSON file'
end if
end subroutine json_write_array2R16


end module JSON
1 change: 1 addition & 0 deletions modules/nwtc-library/src/ModMesh.f90
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
!! mesh definition, initialization of fields, accessing field data, updating field data, copying, deallocating, and destroying meshes.
!! See https://nwtc.nrel.gov/FAST-Developers and https://nwtc.nrel.gov/system/files/ProgrammingHandbook_Mod20130717.pdf
MODULE ModMesh
use VTK, only: WrVTK_header, WrVTK_footer

USE ModMesh_Types
IMPLICIT NONE
Expand Down
Loading