Skip to content

Commit d1e7286

Browse files
authored
Combine open PRs for v2.0.7 (#92)
* Merge of last small commits that were not already merged in the separate PRs, and cherrypick the viscosity improvements without importing the quadtree infiltration changes * - Set new default combination that since new advection scheme seems robust: alpha=0.50, theta=1.0, adveciont=1, viscosity=1 * - Fix quadtree hmax output * - set/check random seed for random_number for wave_maker - Todo: check whether this is best implementation and results in actual random seed if wmrandom = 1 * - SnapWave doesn't output directional spreading, and in sfincs_snapwave the mean wave direction is actually added, which gives wrong values in hisfile. Turn off for now * Cherrypick from PR#89/branch 88 determine viscosity per refinement level for quadtree simulation - so quadtree infiltration is not imported too: - Move whole viscosity value nuvisc determination to sfincs_domain.f90 - Now determine nuvisc per grid cell, depending on refinement level (min of dx-dy)! - crsgeo true or false is still considered - removed option for direct 'nuvisc' input, still possible to scale through 'nuviscdim' * - Fix '-1' mistake for using correct dx/dy when determining viscosity * - Index was wrong in wavemaker for case subgrid * - Add again fix in quadtree for weirs, couldn't find back original commit to cherry pick * Cherrypick from 80-add-option-for-netcdf-infiltration-quadtree-file-input: - Remove double write cuminf - add needed 'if (nm>0) ' checks for quadtree max output * - Cumprcp is already in meters now !? > so then no conversion from mm to m needed anymore * - Units of 'cumprcp' are changed from mm to m, just like cuminf output, now change it in the netcdf attribute too * - Fix missing point_prcp because of meteo3d that was turned to false - fix debug mode issues with extra (nm > 0) checks * - Give more useful Error where depth SnapWave input data is too shallow by giving the x&y-locations * - After review Maarten change implementation so that nuvisc is a value per level, not grid cell, to save computation time in sfincs_momentum * - Change input specification for nuvisc, so we don't put in a default value of 1.0 that is later divided by 100, but make this 0.01 directly - This is the 'viscosity per meter grid cell length' - Note, to prevent issues with old input, I use in sfincs.inp the 'nuvisc' keyword instead of 'nuviscdim', so people with nuviscdim=1 in their older sfincs.inp suddenly do not have a lot of visco, but have the same default * - Update the documentation as well
1 parent 701b541 commit d1e7286

13 files changed

+149
-130
lines changed

docs/input.rst

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -717,23 +717,17 @@ Recommended is to turn the advection term always on.
717717
718718
**viscosity**
719719

720-
'viscosity' turns on the viscosity term in the momentum equation (viscosity = 1, default).
721-
The recommended value of viscosity 'nuvisc' to add to your model, depends on your grid size.
722-
For ease, SFINCS internally automatically determines the optimal value for you, which is displayed when running the model: 'Turning on process: Viscosity, with nuvisc= 0.5000000'. In this example corresponding to a grid resolution of 50 meters.
723-
In case you would want to increase the viscosity term, you can either specify the exact value you want 'nuvisc = XXX', or e.g. multiply it by a factor 2: nuviscdim = 2.0 (default = 1.0, dimensionless).
724-
By default the value of nuvisc is determined like this:
725-
726-
dx = 50 > nuvisc = 0.5
727-
728-
dx = 100 > nuvisc = 1.0
729-
730-
dx = 500 > nuvisc = 5.0
720+
'viscosity' turns on the viscosity term in the momentum equation (viscosity = 1).
721+
The recommended value of 'nuvisc', the viscosity coefficient 'per meter of grid cell length' to add to your model is 0.01.
722+
This coefficient is multiplied internally with the grid cell size (per quadtree level in quadtree mesh mode).
723+
For ease, this is displayed when running the model: 'Viscosity - nuvisc= [0.1000000 - 0.5000000]'.
724+
Increasing the value of 'nuvisc' increases the viscosity term and effectively internal smoothing of the flow.
731725

732726
.. code-block:: text
733727
734728
viscosity = 1
735-
nuviscdim = 1.0 (default)
736-
nuvisc = XXX (automatically determined, or specify a value yourself that overrules this)
729+
nuvisc = 0.01
730+
nuviscdim = Depricated after Cauberg release of SFINCS.
737731
738732
**Drag Coefficients:**
739733

docs/parameters.rst

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,18 @@ Parameters for model input
7676
:min: 0.8
7777
:max: 1.0
7878
viscosity
79-
:description: Turns on the viscosity term in the momentum equation (viscosity = 1), advised to combine with theta = 1.0. Value of viscosity term 'nuvisc' automatically determined based on grid size..
79+
:description: Turns on the viscosity term in the momentum equation (viscosity = 1), advised to combine with theta = 1.0.
8080
:units: -
8181
:default: 1
8282
:min: 0
8383
:max: 1
8484
nuviscdim
85-
:description: Dimensionless viscosity coefficient, multiplies the automatically determined value for 'nuvisc' with the specified factor for 'nuviscdim'.
86-
:units: -
87-
:default: 1.0
88-
:min: 0.0
89-
:max: Inf
85+
:description: Depricated after Cauberg release of SFINCS.
86+
:units: -
9087
nuvisc
91-
:description: Viscosity coefficient, by default turned off, but automatically determined if 'viscosity=1'. specifying a value for 'nuvisc' overrule default value.
88+
:description: Viscosity coefficient 'per meter of grid cell length', used if 'viscosity=1' and multiplied internally with the grid cell size (per quadtree level in quadtree mesh mode).
9289
:units: -
93-
:default: -999.0 (=off)
90+
:default: 0.01
9491
:min: 0.0
9592
:max: Inf
9693
zsini

source/src/quadtree.F90

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,13 +852,19 @@ subroutine find_uv_points_intersected_by_polyline(uv_indices,vertices,nint,xpol,
852852
do m = m0, m1
853853
do n = n0, n1
854854
!
855+
! First check whether point is on the quadtree grid at all
855856
nm = find_quadtree_cell_by_index(n, m, iref)
856857
!
857858
if (nm==0) then
858859
cycle
859860
endif
860861
!
862+
! Second check is whether it is on the active SFINCS mask
861863
nm = index_sfincs_in_quadtree(nm)
864+
!
865+
if (nm==0) then
866+
cycle
867+
endif
862868
!
863869
! Right (same level or coarser)
864870
!

source/src/sfincs_data.f90

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ module sfincs_data
7272
real*4 sfacinf
7373
real*4 dym
7474
real*4 dym2
75-
real*4 nuvisc
7675
real*4 nuviscdim
7776
real*4 nuviscinp
7877
real*4 spw_merge_frac
@@ -316,6 +315,7 @@ module sfincs_data
316315
real*4, dimension(:), allocatable :: dxrinvc
317316
real*4, dimension(:), allocatable :: dyrinvc
318317
real*4, dimension(:), allocatable :: cell_area
318+
real*4, dimension(:), allocatable :: dxyr
319319
!
320320
! Cell sizes
321321
!
@@ -328,6 +328,7 @@ module sfincs_data
328328
real*4, dimension(:), allocatable :: z_xz
329329
real*4, dimension(:), allocatable :: z_yz
330330
real*4, dimension(:), allocatable :: cell_area_m2
331+
real*4, dimension(:), allocatable :: nuvisc
331332
!
332333
! UV-points
333334
!
@@ -844,7 +845,7 @@ subroutine finalize_parameters()
844845
if(allocated(qinffield)) deallocate(qinffield)
845846
if(allocated(ksfield)) deallocate(ksfield)
846847
if(allocated(scs_Se)) deallocate(scs_Se)
847-
848+
if(allocated(nuvisc)) deallocate(nuvisc)
848849
!
849850
! Boundary velocity points
850851
!

source/src/sfincs_domain.f90

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ subroutine initialize_processes()
8888
!
8989
! Check for time-spatially varying meteo
9090
!
91-
if (spwfile(1:4) /= 'none' .or. amufile(1:4) /= 'none' .or. amprfile(1:4) /= 'none' .or. ampfile(1:4) /= 'none' .or. netampfile(1:4) /= 'none' .or. netamprfile(1:4) /= 'none' .or. netamuamvfile(1:4) /= 'none' .or. netspwfile(1:4) /= 'none') then
91+
if (prcpfile(1:4) /= 'none' .or. spwfile(1:4) /= 'none' .or. amufile(1:4) /= 'none' .or. amprfile(1:4) /= 'none' .or. ampfile(1:4) /= 'none' .or. netampfile(1:4) /= 'none' .or. netamprfile(1:4) /= 'none' .or. netamuamvfile(1:4) /= 'none' .or. netspwfile(1:4) /= 'none') then
9292
meteo3d = .true.
9393
write(*,*)'Turning on flag: meteo3d'
9494
endif
@@ -1258,13 +1258,15 @@ subroutine initialize_mesh()
12581258
!
12591259
allocate(dxr(nref))
12601260
allocate(dyr(nref))
1261+
allocate(dxyr(nref))
12611262
!
12621263
! Determine grid spacing for different refinement levels
12631264
!
12641265
do iref = 1, nref
12651266
!
12661267
dxr(iref) = dx/(2**(iref - 1))
12671268
dyr(iref) = dy/(2**(iref - 1))
1269+
dxyr(iref) = min(dxr(iref), dyr(iref))
12681270
!
12691271
enddo
12701272
!
@@ -1413,6 +1415,47 @@ subroutine initialize_mesh()
14131415
!
14141416
endif
14151417
!
1418+
! Determine viscosity per refinement level
1419+
!
1420+
allocate(nuvisc(nref))
1421+
!
1422+
if (viscosity) then
1423+
!
1424+
if (crsgeo) then
1425+
!
1426+
do iref = 1, nref
1427+
!
1428+
nuvisc(iref) = max(nuviscdim * dxyr(iref) / 0.00001, 0.0) ! take min of dx and dy, don't allow to be negative
1429+
!
1430+
! with default nuviscdim = 0.01 (dimensionless per meter grid cell length):
1431+
! dx = 1 degree ~ 100km > nuvisc = 1000.0
1432+
! dx = 0.001 degree~ 100m > nuvisc = 1.0
1433+
!
1434+
enddo
1435+
!
1436+
else
1437+
!
1438+
do iref = 1, nref
1439+
!
1440+
nuvisc(iref) = max(nuviscdim * dxyr(iref), 0.0) ! take min of dx and dy, don't allow to be negative
1441+
!
1442+
! with default nuviscdim = 0.01 (dimensionless per meter grid cell length):
1443+
! dx = 50 > nuvisc = 0.5
1444+
! dx = 100 > nuvisc = 1.0
1445+
! dx = 500 > nuvisc = 5.0
1446+
!
1447+
enddo
1448+
!
1449+
endif
1450+
!
1451+
if (use_quadtree) then
1452+
write(*,*)'Viscosity - nuvisc = [', minval(nuvisc),'- ',maxval(nuvisc),']'
1453+
else
1454+
write(*,*)'Viscosity - nuvisc = ', maxval(nuvisc)
1455+
endif
1456+
!
1457+
endif
1458+
!
14161459
end subroutine
14171460

14181461
subroutine initialize_bathymetry()

source/src/sfincs_input.f90

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,8 @@ subroutine read_sfincs_input()
104104
call read_real_input(500,'spwmergefrac',spw_merge_frac,0.5)
105105
call read_int_input(500,'usespwprecip',ispwprecip,1)
106106
call read_int_input(500,'global',iglobal,0)
107-
call read_real_input(500,'nuvisc',nuviscinp,-999.0)
108-
call read_real_input(500,'nuviscdim',nuviscdim,1.0)
109-
call read_logical_input(500,'viscosity',iviscosity,.true.)
107+
call read_real_input(500,'nuvisc',nuviscdim,0.01)
108+
call read_logical_input(500,'viscosity',iviscosity,.false.)
110109
call read_int_input(500,'spinup_meteo', ispinupmeteo, 0)
111110
call read_real_input(500,'waveage',waveage,-999.0)
112111
call read_int_input(500,'snapwave', isnapwave, 0)
@@ -423,41 +422,11 @@ subroutine read_sfincs_input()
423422
store_tsunami_arrival_time = .true.
424423
endif
425424
!
426-
viscosity = .false.
427-
!
428-
if (nuviscinp>0.0 .or. iviscosity) then
429-
!
430-
if (nuviscinp>0.0) then ! if nuvisc given by user, this overrules the dimensionless default use of nuvisc, for backwards compatability
431-
!
432-
nuvisc = nuviscinp
433-
viscosity = .true.
434-
!
435-
else ! user defined viscosity = 1
436-
!
437-
if (qtrfile(1:4) == 'none') then ! this works only for a regular grid model, for quadtree use 'nuvisc' option
438-
!
439-
viscosity = .true.
440-
!
441-
if (crsgeo .eqv. .true.) then ! simplified conversion for spherical grids
442-
nuvisc = max(nuviscdim * min(dx,dy) / 0.001, 0.0) ! take min of dx and dy, don't allow to be negative
443-
! dx = 1 degree ~ 100km
444-
! dx = 0.001 degree~ 100m > nuvisc = 1.0
445-
else
446-
nuvisc = max(nuviscdim * min(dx,dy) / 100.0, 0.0) ! take min of dx and dy, don't allow to be negative
447-
! dx = 50 > nuvisc = 0.5
448-
! dx = 100 > nuvisc = 1.0
449-
! dx = 500 > nuvisc = 5.0
450-
! nuviscdim = 1.0
451-
! nuvisc = nuviscdim * dx / 100
452-
endif
453-
endif
454-
!
455-
endif
456-
!
457-
if (viscosity .eqv. .true.) then
458-
write(*,*)'Turning on process: Viscosity, with nuvisc = ', nuvisc
459-
endif
460-
!
425+
!
426+
viscosity = .false.
427+
if (iviscosity) then
428+
viscosity = .true.
429+
write(*,*)'Turning on process: Viscosity'
461430
endif
462431
!
463432
spinup_meteo = .true. ! Default use data in ampr file as block rather than linear interpolation

source/src/sfincs_lib.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function sfincs_initialize(config_file) result(ierr)
8585
!
8686
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
8787
!
88-
build_revision = '$Rev: v2.0.6'
88+
build_revision = '$Rev: v2.0.7'
8989
build_date = '$Date: 2024-05-31'
9090
!
9191
write(*,'(a)')''

source/src/sfincs_momentum.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ subroutine compute_fluxes(dt, min_dt, tloop)
449449
!
450450
if (viscosity) then
451451
!
452-
frc = frc + nuvisc * hu * ( (uu_nmu - 2*uu_nm + uu_nmd ) * dxuv2inv + (uu_num - 2*uu_nm + uu_ndm ) * dyuv2inv )
452+
frc = frc + nuvisc(iref) * hu * ( (uu_nmu - 2*uu_nm + uu_nmd ) * dxuv2inv + (uu_num - 2*uu_nm + uu_ndm ) * dyuv2inv )
453453
!
454454
endif
455455
!

0 commit comments

Comments
 (0)