Skip to content

Commit

Permalink
Merge branch 'main' into restructure-net
Browse files Browse the repository at this point in the history
  • Loading branch information
tztsai committed Mar 1, 2024
2 parents 1a70414 + ccf28a4 commit 4fb3e7b
Show file tree
Hide file tree
Showing 8 changed files with 588 additions and 155 deletions.
26 changes: 15 additions & 11 deletions NN_module/Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
# compiler
FC = gfortran

# compile flags
# Set compiler and flags - uncomment for ifort or gfortran as appropriate
# Set free length and include netcdf-fortran
# Try using nf-config tool if available, otherwise manually add path as per examples below
FCFLAGS = -g -ffree-line-length-none $(shell nf-config --fflags)
# CSD3:
# FCFLAGS = -g -ffree-line-length-none -I/usr/local/software/spack/spack-views/rocky8-icelake-20220710/netcdf-fortran-4.5.4/gcc-11.3.0/intel-oneapi-mpi-2021.6.0/mscqvjsc7bwypshmhnqfc2u3zxnims3r/include
# jwa34 local:
# FCFLAGS = -g -ffree-line-length-none -I/opt/netcdf-fortran/include
# Try using nf-config tool if available, otherwise need to manually add path as per examples below

# ifort configuration
FC = ifort
FCFLAGS = $(shell nf-config --fflags)

# gfortran configuration
# FC = gfortran
# FCFLAGS = -g -ffree-line-length-none $(shell nf-config --fflags)

# link flags
# Link to netcdf and netcdf-fortran
# Try using nf-config tool if available, otherwise manually add path as per examples below
LDFLAGS = $(shell nf-config --flibs)

# If flags need adding manually this can be done here
# CSD3:
# FCFLAGS = -g -ffree-line-length-none -I/usr/local/software/spack/spack-views/rocky8-icelake-20220710/netcdf-fortran-4.5.4/gcc-11.3.0/intel-oneapi-mpi-2021.6.0/mscqvjsc7bwypshmhnqfc2u3zxnims3r/include
# LDFLAGS = -L/usr/local/software/spack/spack-views/rhel8-icelake-20211027_2/netcdf-fortran-4.5.3/gcc-11.2.0/intel-oneapi-mpi-2021.4.0/g4qjb23rucofcg5uitt4jwrkgyf7gba7/lib -lnetcdff -lnetcdf -lm
# jwa34 local:
# FCFLAGS = -g -ffree-line-length-none -I/opt/netcdf-fortran/include
# LDFLAGS = -L/opt/netcdf-c/lib -lnetcdf -L/opt/netcdf-fortran/lib -lnetcdff -lm


PROGRAM = test
SRC = nn_cf_net.f90 nn_convection_flux.f90 nn_interface_SAM.f90 test.f90
SRC = precision.f90 test_utils.f90 nn_cf_net.f90 nn_convection_flux.f90 nn_interface_SAM.f90 test.f90
OBJECTS = $(SRC:.f90=.o)


Expand Down
8 changes: 8 additions & 0 deletions NN_module/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ Files:
- `test.f90` - simple smoke tests for parameterisation routines
- `NN_weights_YOG_convection.nc` - NetCDF file with weights for the neural net
- Makefile - Makefile to compile these files

## Running tests

To run the tests (requires `ifort` or `gfortran` and `netcdf`):
Edit `Makefile` to select the appropriate compiler (`ifort` or `gfortran`) and then build with:
```bash
make test
```
4 changes: 2 additions & 2 deletions NN_module/nn_convection_flux.f90
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ subroutine nn_convection_flux(tabs_i, q_i, y_in, &
!! Vector of input features for the NN
real(4), dimension(n_outputs) :: outputs
!! vector of output features from the NN
real, dimension(nrf) :: t_flux_adv, q_flux_adv, q_tend_auto, &
q_sed_flux
nx = size(tabs_i, 1)
ny = size(tabs_i, 2)
nzm = size(tabs_i, 3)
! NN outputs
real, dimension(nrf) :: t_flux_adv, q_flux_adv, q_tend_auto, &
q_sed_flux
! Output variable t_rad_rest_tend is also an output from the NN (defined above)


Expand Down
148 changes: 148 additions & 0 deletions NN_module/nn_ones.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
-1.548654079437
-1.019196391106
-0.797004640102
-0.510117173195
-0.385661870241
-0.495599985123
-1.240013718605
-1.892510175705
-0.581315040588
-0.359731495380
-0.586395740509
-0.714409291744
-0.583598196507
-0.282303869724
-0.258652120829
-0.378690242767
-0.432278931141
-0.338912516832
-0.186107128859
-0.017364665866
0.139586955309
0.260299444199
0.331388920546
0.386305928230
0.428786695004
0.434366226196
0.435577899218
0.455284386873
0.526996791363
0.610138535500
-0.057859659195
-0.219089031219
-0.206303104758
-0.094517558813
0.067444443703
0.094589412212
0.043635398149
0.371261000633
0.423852056265
0.272715002298
0.252417802811
0.259922802448
0.237769454718
0.239017575979
0.227276831865
0.199871718884
0.176855623722
0.182130187750
0.181883573532
0.180479094386
0.180221661925
0.184932529926
0.185359880328
0.193712815642
0.204352051020
0.205779701471
0.209363222122
0.215554103255
0.213893324137
-1.202421665192
-1.255304813385
-1.070469856262
-0.605962812901
-0.148154020309
0.248896420002
-0.074281871319
-1.016677975655
-1.852268099785
-1.268948078156
-0.997557282448
-1.173674106598
-1.406493425369
-1.447221517563
-1.352780103683
-1.280928015709
-1.267250061035
-1.276774883270
-1.280700206757
-1.271878838539
-1.266510248184
-1.263604521751
-1.259351134300
-1.250584840775
-1.236418008804
-1.221935629845
-1.209158539772
-1.200800895691
-1.197698116302
0.547356724739
0.541226983070
0.486596643925
0.325039625168
0.369046747684
0.247089684010
-0.085400015116
0.015755124390
0.722970366478
0.675642728806
0.442468702793
0.440599977970
0.478552460670
0.464282572269
0.445607423782
0.442082822323
0.430344402790
0.413671255112
0.380288362503
0.367297232151
0.360955625772
0.362972438335
0.372948408127
0.382159471512
0.387978047132
0.389867186546
0.389176517725
0.387510210276
0.385305345058
0.383541584015
0.404772669077
0.397490769625
0.385760128498
0.386608541012
0.422613054514
0.463099241257
0.455268323421
0.308662593365
0.524466514587
0.566737413406
0.454918086529
0.346627175808
0.443202495575
0.478479027748
0.382643520832
0.354028671980
0.385809838772
0.406863689423
0.439339756966
0.465253412724
0.485793352127
0.503615021706
0.509339690208
0.497745215893
0.477612733841
0.450194656849
0.430692702532
0.420731335878
0.415764302015
0.414340615273
31 changes: 31 additions & 0 deletions NN_module/param_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-0.15258199E+03 -0.59331436E-01 -0.27831873E+03 0.11130974E+00 0.13943182E+02 -0.49222764E-02 -0.12378716E+03
-0.14338339E+03 -0.59102684E-01 -0.77372841E+02 0.30944204E-01 -0.30485462E+02 0.10762096E-01 -0.99609421E+02
-0.12325390E+03 -0.94135292E-01 0.97592537E+02 -0.39030794E-01 -0.47757668E+02 0.16859598E-01 -0.81354347E+02
-0.10417913E+03 -0.18035039E+00 0.26003372E+03 -0.10399691E+00 -0.83319756E+02 0.29413866E-01 -0.76795265E+02
-0.18704465E+03 -0.10708020E+00 0.45196835E+03 -0.18075854E+00 -0.30860632E+02 0.10894541E-01 -0.74161324E+02
-0.13310071E+03 0.00000000E+00 0.70741974E+03 -0.28292280E+00 0.20239415E+03 -0.71449973E-01 -0.85394409E+02
0.61529816E+02 0.00000000E+00 0.11190435E+04 -0.44754606E+00 0.10683840E+02 -0.37716506E-02 -0.10791988E+03
0.14473958E+01 0.00000000E+00 0.12501992E+04 -0.50000000E+00 -0.10559273E+03 0.37276756E-01 -0.13053223E+03
0.51176235E+02 0.00000000E+00 0.12501992E+04 -0.50000000E+00 0.00000000E+00 0.00000000E+00 -0.16328114E+03
0.93860085E+02 0.00000000E+00 0.12501992E+04 -0.50000000E+00 0.00000000E+00 0.00000000E+00 -0.13449281E+03
0.14911021E+03 0.00000000E+00 0.12501992E+04 -0.50000000E+00 0.00000000E+00 0.00000000E+00 -0.87997696E+02
0.14079984E+03 0.00000000E+00 0.12501992E+04 -0.50000000E+00 0.00000000E+00 0.00000000E+00 -0.31148405E+02
0.21945201E+03 0.49292561E-01 0.13734503E+04 -0.54929256E+00 0.00000000E+00 0.00000000E+00 0.40992861E+01
0.27411746E+03 0.46004165E-01 0.13652280E+04 -0.54600418E+00 0.00000000E+00 0.00000000E+00 0.42614012E+01
0.33452908E+03 -0.63766092E-01 0.10907585E+04 -0.43623391E+00 0.00000000E+00 0.00000000E+00 -0.13481074E+02
0.25489995E+03 -0.31530634E-01 0.11713601E+04 -0.46846938E+00 -0.61843784E+02 0.21832334E-01 -0.70356183E+01
0.17641861E+02 0.00000000E+00 0.73373505E+03 -0.29344726E+00 -0.15497134E+03 0.54708585E-01 0.26573279E+01
-0.17049492E+03 0.36195751E-01 0.42922144E+03 -0.17166121E+00 -0.68361343E+02 0.24133189E-01 0.79629316E+01
-0.11305133E+03 0.10003121E+00 0.31256876E+03 -0.12500758E+00 -0.18950542E+03 0.66899940E-01 0.96100616E+01
-0.48079750E+02 0.66902570E-01 0.19118565E+03 -0.76462075E-01 -0.12471986E+03 0.44029091E-01 0.62052822E+01
-0.78505005E+02 0.65000609E-01 0.12925836E+03 -0.51695105E-01 0.12382239E+03 -0.43712262E-01 0.13433976E+01
-0.40449608E+02 0.25606329E-01 0.90200867E+02 -0.36074597E-01 0.30558572E+03 -0.10787906E+00 -0.33138554E+01
0.34186165E+02 0.11162106E-01 0.74156761E+02 -0.29657977E-01 0.23453377E+03 -0.82796022E-01 -0.56750917E+01
0.84712524E+02 -0.32118667E-01 0.69470520E+02 -0.27783781E-01 0.74060410E+02 -0.26145093E-01 -0.32166588E+01
0.78100677E+02 -0.38102403E-01 0.70230988E+02 -0.28087918E-01 -0.15935593E+02 0.56256452E-02 -0.20918531E+01
0.48418488E+02 -0.28241172E-01 0.71406212E+02 -0.28557934E-01 -0.37185413E+02 0.13127340E-01 -0.19065496E+01
-0.38718097E+01 -0.66498751E-02 0.71594452E+02 -0.28633216E-01 -0.38420971E+02 0.13563521E-01 0.37559479E-01
-0.19452473E+02 0.16073607E-01 0.67622612E+02 -0.27044734E-01 -0.26526558E+02 0.93645090E-02 0.30559354E+01
0.10720540E+02 0.28101396E-01 0.60303963E+02 -0.24117742E-01 -0.22085796E+02 0.77968142E-02 0.63656316E+01
-0.53725366E+03 0.25603855E+00 0.51792259E+02 -0.20713603E-01 0.15537941E+01 -0.54852647E-03 0.81452036E+01
-3.0075550E-02
14 changes: 14 additions & 0 deletions NN_module/precision.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module precision

use, intrinsic :: iso_fortran_env, only : sp=>real32, dp=>real64
! Imports primitives used to interface with C
use, intrinsic :: iso_c_binding, only: c_sp=>c_float, c_dp=>c_double

implicit none

public
integer, parameter :: c_wp = c_sp
integer, parameter :: wps = sp
integer, parameter :: wpc = dp

end module precision
Loading

0 comments on commit 4fb3e7b

Please sign in to comment.