MODFLOW 6  version 6.9.0.dev0
USGS Modular Hydrologic Model
meshdisvmodelmodule Module Reference

This module contains the MeshDisvModelModule. More...

Data Types

type  mesh2ddisvexporttype
 

Functions/Subroutines

subroutine disv_export_init (this, modelname, modeltype, modelfname, nc_fname, disenum, nctype, iout)
 netcdf export disv init More...
 
subroutine disv_export_destroy (this)
 netcdf export disv destroy More...
 
subroutine df (this)
 netcdf export define More...
 
subroutine step (this)
 netcdf export step More...
 
subroutine package_step (this, export_pkg)
 netcdf export package dynamic input More...
 
subroutine export_input_array (this, pkgtype, pkgname, mempath, idt)
 netcdf export an input array More...
 
subroutine define_dim (this)
 netcdf export define dimensions More...
 
subroutine add_mesh_data (this)
 netcdf export add mesh information More...
 
subroutine nc_export_int1d (p_mem, ncid, dim_ids, var_ids, disv, idt, mempath, nc_tag, pkgname, gridmap_name, deflate, shuffle, chunk_face, iper, nc_fname)
 netcdf export 1D integer array More...
 
subroutine nc_export_int2d (p_mem, ncid, dim_ids, var_ids, disv, idt, mempath, nc_tag, pkgname, gridmap_name, deflate, shuffle, chunk_face, nc_fname)
 netcdf export 2D integer array More...
 
subroutine nc_export_dbl1d (p_mem, ncid, dim_ids, var_ids, disv, idt, mempath, nc_tag, pkgname, gridmap_name, deflate, shuffle, chunk_face, iper, iaux, nc_fname)
 netcdf export 1D double array More...
 
subroutine nc_export_dbl2d (p_mem, ncid, dim_ids, var_ids, disv, idt, mempath, nc_tag, pkgname, gridmap_name, deflate, shuffle, chunk_face, nc_fname)
 netcdf export 2D double array More...
 

Detailed Description

This module defines UGRID layered mesh compliant netcdf export type for DISV models. It is dependent on netcdf libraries.

Function/Subroutine Documentation

◆ add_mesh_data()

subroutine meshdisvmodelmodule::add_mesh_data ( class(mesh2ddisvexporttype), intent(inout)  this)

Definition at line 455 of file DisvNCMesh.f90.

457  class(Mesh2dDisvExportType), intent(inout) :: this
458  integer(I4B), dimension(:), contiguous, pointer :: ncvert => null()
459  integer(I4B), dimension(:), contiguous, pointer :: icvert => null()
460  real(DP), dimension(:), contiguous, pointer :: cell_xt => null()
461  real(DP), dimension(:), contiguous, pointer :: cell_yt => null()
462  real(DP), dimension(:), contiguous, pointer :: vert_xt => null()
463  real(DP), dimension(:), contiguous, pointer :: vert_yt => null()
464  real(DP) :: x_transform, y_transform
465  integer(I4B) :: n, m, idx, cnt, iv, maxvert, k
466  integer(I4B), dimension(:), allocatable :: verts, layers
467  real(DP), dimension(:), allocatable :: bnds
468  real(DP), dimension(:), allocatable :: elev_face
469  integer(I4B) :: istop
470 
471  ! set pointers to input context
472  call mem_setptr(ncvert, 'NCVERT', this%dis_mempath)
473  call mem_setptr(icvert, 'ICVERT', this%dis_mempath)
474 
475  ! allocate x, y transform arrays
476  allocate (cell_xt(this%disv%ncpl))
477  allocate (cell_yt(this%disv%ncpl))
478  allocate (vert_xt(this%disv%nvert))
479  allocate (vert_yt(this%disv%nvert))
480 
481  ! set mesh container variable value to 1
482  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh, 1), &
483  this%nc_fname)
484 
485  ! write layer coordinate data
486  allocate (layers(this%nlay))
487  do k = 1, this%nlay
488  layers(k) = k
489  end do
490  call nf_verify(nf90_put_var(this%ncid, this%var_ids%layer, layers), &
491  this%nc_fname)
492  deallocate (layers)
493 
494  ! transform vert x and y
495  do n = 1, this%disv%nvert
496  call dis_transform_xy(this%disv%vertices(1, n), this%disv%vertices(2, n), &
497  this%disv%xorigin, &
498  this%disv%yorigin, &
499  this%disv%angrot, &
500  x_transform, y_transform)
501  vert_xt(n) = x_transform
502  vert_yt(n) = y_transform
503  end do
504 
505  ! transform cell x and y
506  do n = 1, this%disv%ncpl
507  call dis_transform_xy(this%disv%cellxy(1, n), this%disv%cellxy(2, n), &
508  this%disv%xorigin, &
509  this%disv%yorigin, &
510  this%disv%angrot, &
511  x_transform, y_transform)
512  cell_xt(n) = x_transform
513  cell_yt(n) = y_transform
514  end do
515 
516  ! write node_x and node_y arrays to netcdf file
517  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_node_x, &
518  vert_xt), this%nc_fname)
519  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_node_y, &
520  vert_yt), this%nc_fname)
521 
522  ! write face_x and face_y arrays to netcdf file
523  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_x, &
524  cell_xt), this%nc_fname)
525  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_y, &
526  cell_yt), this%nc_fname)
527 
528  ! set and write z_l1, z_l2, ... cell center elevation arrays -- already
529  ! face-indexed (ncpl), no flattening needed, unlike DIS-mesh
530  allocate (elev_face(this%disv%ncpl))
531  do k = 1, this%nlay
532  if (k == 1) then
533  elev_face(:) = (this%disv%top1d(:) + this%disv%bot2d(:, k)) * dhalf
534  else
535  elev_face(:) = (this%disv%bot2d(:, k - 1) + &
536  this%disv%bot2d(:, k)) * dhalf
537  end if
538  call nf_verify(nf90_put_var(this%ncid, this%var_ids%elevation(k), &
539  elev_face), this%nc_fname)
540  end do
541  deallocate (elev_face)
542 
543  ! initialize max vertices required to define cell
544  maxvert = maxval(ncvert)
545 
546  ! allocate temporary arrays
547  allocate (verts(maxvert))
548  allocate (bnds(maxvert))
549 
550  ! set face nodes array
551  cnt = 0
552  do n = 1, this%disv%ncpl
553  verts = nf90_fill_int
554  idx = cnt + ncvert(n)
555  iv = 0
556  istop = cnt + 1
557  do m = idx, istop, -1
558  cnt = cnt + 1
559  iv = iv + 1
560  verts(iv) = icvert(m)
561  end do
562 
563  ! don't close the cell
564  if (verts(iv) == verts(1)) verts(iv) = nf90_fill_int
565 
566  ! write face nodes array to netcdf file
567  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_nodes, &
568  verts, start=(/1, n/), &
569  count=(/maxvert, 1/)), &
570  this%nc_fname)
571 
572  ! set face y bounds array
573  bnds = nf90_fill_double
574  do m = 1, size(bnds)
575  if (verts(m) /= nf90_fill_int) then
576  bnds(m) = vert_yt(verts(m))
577  end if
578  ! write face y bounds array to netcdf file
579  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_ybnds, &
580  bnds, start=(/1, n/), &
581  count=(/maxvert, 1/)), &
582  this%nc_fname)
583  end do
584 
585  ! set face x bounds array
586  bnds = nf90_fill_double
587  do m = 1, size(bnds)
588  if (verts(m) /= nf90_fill_int) then
589  bnds(m) = vert_xt(verts(m))
590  end if
591  ! write face x bounds array to netcdf file
592  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_xbnds, &
593  bnds, start=(/1, n/), &
594  count=(/maxvert, 1/)), &
595  this%nc_fname)
596  end do
597  end do
598 
599  ! cleanup
600  deallocate (bnds)
601  deallocate (verts)
602  deallocate (cell_xt)
603  deallocate (cell_yt)
604  deallocate (vert_xt)
605  deallocate (vert_yt)
subroutine, public dis_transform_xy(x, y, xorigin, yorigin, angrot, xglo, yglo)
Get global (x, y) coordinates from cell-local coordinates.
Here is the call graph for this function:

◆ define_dim()

subroutine meshdisvmodelmodule::define_dim ( class(mesh2ddisvexporttype), intent(inout)  this)
private

Definition at line 366 of file DisvNCMesh.f90.

367  use constantsmodule, only: mvalidate
368  use simvariablesmodule, only: isim_mode
369  class(Mesh2dDisvExportType), intent(inout) :: this
370  integer(I4B), dimension(:), contiguous, pointer :: ncvert
371  integer(I4B) :: k
372  character(len=LINELENGTH) :: varname
373  character(len=LINELENGTH) :: elev_longname
374 
375  ! set pointers to input context
376  call mem_setptr(ncvert, 'NCVERT', this%dis_mempath)
377 
378  if (isim_mode /= mvalidate .or. this%pkglist%Count() > 0) then
379  ! time
380  call nf_verify(nf90_def_dim(this%ncid, 'time', this%totnstp, &
381  this%dim_ids%time), this%nc_fname)
382  call nf_verify(nf90_def_var(this%ncid, 'time', nf90_double, &
383  this%dim_ids%time, this%var_ids%time), &
384  this%nc_fname)
385  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'calendar', &
386  'standard'), this%nc_fname)
387  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'units', &
388  this%datetime), this%nc_fname)
389  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'axis', 'T'), &
390  this%nc_fname)
391  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'standard_name', &
392  'time'), this%nc_fname)
393  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'long_name', &
394  'time'), this%nc_fname)
395  end if
396 
397  ! mesh
398  call nf_verify(nf90_def_dim(this%ncid, 'nmesh_node', this%disv%nvert, &
399  this%dim_ids%nmesh_node), this%nc_fname)
400  call nf_verify(nf90_def_dim(this%ncid, 'nmesh_face', this%disv%ncpl, &
401  this%dim_ids%nmesh_face), this%nc_fname)
402  call nf_verify(nf90_def_dim(this%ncid, 'max_nmesh_face_nodes', &
403  maxval(ncvert), &
404  this%dim_ids%max_nmesh_face_nodes), &
405  this%nc_fname)
406 
407  ! layer
408  call nf_verify(nf90_def_dim(this%ncid, 'layer', this%nlay, &
409  this%dim_ids%layer), this%nc_fname)
410  call nf_verify(nf90_def_var(this%ncid, 'layer', nf90_int, &
411  this%dim_ids%layer, this%var_ids%layer), &
412  this%nc_fname)
413  call nf_verify(nf90_put_att(this%ncid, this%var_ids%layer, 'units', '1'), &
414  this%nc_fname)
415  call nf_verify(nf90_put_att(this%ncid, this%var_ids%layer, 'axis', 'Z'), &
416  this%nc_fname)
417  call nf_verify(nf90_put_att(this%ncid, this%var_ids%layer, 'positive', &
418  'down'), this%nc_fname)
419  call nf_verify(nf90_put_att(this%ncid, this%var_ids%layer, 'long_name', &
420  'model layer'), this%nc_fname)
421 
422  ! z_l1, z_l2, ... : per-layer cell center elevation auxiliary
423  ! coordinates -- real vertical position, unlike the discrete layer
424  ! index. Always written, independent of CRS/NCF configuration; split
425  ! per layer since face-indexed variables carry no layer dimension to
426  ! legally reference a combined z(layer, nmesh_face) coordinate
427  ! (CF-1.13 5.2).
428  allocate (this%var_ids%elevation(this%nlay))
429  do k = 1, this%nlay
430  write (varname, '(a,i0)') 'z_l', k
431  call nf_verify(nf90_def_var(this%ncid, trim(varname), nf90_double, &
432  (/this%dim_ids%nmesh_face/), &
433  this%var_ids%elevation(k)), this%nc_fname)
434  call ncvar_chunk(this%ncid, this%var_ids%elevation(k), this%chunk_face, &
435  this%nc_fname)
436  call ncvar_deflate(this%ncid, this%var_ids%elevation(k), this%deflate, &
437  this%shuffle, this%nc_fname)
438  call nf_verify(nf90_put_att(this%ncid, this%var_ids%elevation(k), &
439  'units', this%lenunits), this%nc_fname)
440  call nf_verify(nf90_put_att(this%ncid, this%var_ids%elevation(k), &
441  'standard_name', 'altitude'), this%nc_fname)
442  call nf_verify(nf90_put_att(this%ncid, this%var_ids%elevation(k), &
443  'positive', 'up'), this%nc_fname)
444  write (elev_longname, '(a,i0,a)') 'cell center elevation (layer ', &
445  k, ')'
446  call nf_verify(nf90_put_att(this%ncid, this%var_ids%elevation(k), &
447  'long_name', trim(elev_longname)), &
448  this%nc_fname)
449  call ncvar_layer(this%ncid, this%var_ids%elevation(k), k, this%nc_fname)
450  end do
This module contains simulation constants.
Definition: Constants.f90:9
@ mvalidate
validation mode - do not run time steps
Definition: Constants.f90:206
This module contains simulation variables.
Definition: SimVariables.f90:9
integer(i4b) isim_mode
simulation mode
Here is the call graph for this function:

◆ df()

subroutine meshdisvmodelmodule::df ( class(mesh2ddisvexporttype), intent(inout)  this)
private

Definition at line 84 of file DisvNCMesh.f90.

85  use constantsmodule, only: mvalidate
86  use simvariablesmodule, only: isim_mode
87  class(Mesh2dDisvExportType), intent(inout) :: this
88  ! put root group file scope attributes
89  call this%add_global_att()
90  ! define root group dimensions and coordinate variables
91  call this%define_dim()
92  ! define mesh variables
93  call this%create_mesh()
94  if (isim_mode == mvalidate) then
95  ! define period input arrays
96  call this%df_export()
97  else
98  ! define the dependent variable
99  call this%define_dependent()
100  end if
101  ! exit define mode
102  call nf_verify(nf90_enddef(this%ncid), this%nc_fname)
103  ! create mesh
104  call this%add_mesh_data()
105  if (isim_mode == mvalidate) then
106  ! define and set package input griddata
107  call this%add_pkg_data()
108  end if
109  ! define and set gridmap variable
110  call this%define_gridmap()
111  ! synchronize file
112  call nf_verify(nf90_sync(this%ncid), this%nc_fname)
Here is the call graph for this function:

◆ disv_export_destroy()

subroutine meshdisvmodelmodule::disv_export_destroy ( class(mesh2ddisvexporttype), intent(inout)  this)

Definition at line 74 of file DisvNCMesh.f90.

75  class(Mesh2dDisvExportType), intent(inout) :: this
76  deallocate (this%var_ids%dependent)
77  ! destroy base class
78  call this%mesh_destroy()
79  call this%NCModelExportType%destroy()

◆ disv_export_init()

subroutine meshdisvmodelmodule::disv_export_init ( class(mesh2ddisvexporttype), intent(inout)  this,
character(len=*), intent(in)  modelname,
character(len=*), intent(in)  modeltype,
character(len=*), intent(in)  modelfname,
character(len=*), intent(in)  nc_fname,
integer(i4b), intent(in)  disenum,
integer(i4b), intent(in)  nctype,
integer(i4b), intent(in)  iout 
)
private

Definition at line 48 of file DisvNCMesh.f90.

51  class(Mesh2dDisvExportType), intent(inout) :: this
52  character(len=*), intent(in) :: modelname
53  character(len=*), intent(in) :: modeltype
54  character(len=*), intent(in) :: modelfname
55  character(len=*), intent(in) :: nc_fname
56  integer(I4B), intent(in) :: disenum
57  integer(I4B), intent(in) :: nctype
58  integer(I4B), intent(in) :: iout
59 
60  ! set nlay
61  this%nlay = this%disv%nlay
62 
63  ! allocate var_id arrays
64  allocate (this%var_ids%dependent(this%nlay))
65  allocate (this%var_ids%export(this%nlay))
66 
67  ! initialize base class
68  call this%mesh_init(modelname, modeltype, modelfname, nc_fname, disenum, &
69  nctype, this%disv%lenuni, iout)

◆ export_input_array()

subroutine meshdisvmodelmodule::export_input_array ( class(mesh2ddisvexporttype), intent(inout)  this,
character(len=*), intent(in)  pkgtype,
character(len=*), intent(in)  pkgname,
character(len=*), intent(in)  mempath,
type(inputparamdefinitiontype), intent(in), pointer  idt 
)

Definition at line 315 of file DisvNCMesh.f90.

316  class(Mesh2dDisvExportType), intent(inout) :: this
317  character(len=*), intent(in) :: pkgtype
318  character(len=*), intent(in) :: pkgname
319  character(len=*), intent(in) :: mempath
320  type(InputParamDefinitionType), pointer, intent(in) :: idt
321  integer(I4B), dimension(:), pointer, contiguous :: int1d
322  integer(I4B), dimension(:, :), pointer, contiguous :: int2d
323  real(DP), dimension(:), pointer, contiguous :: dbl1d
324  real(DP), dimension(:, :), pointer, contiguous :: dbl2d
325  character(len=LINELENGTH) :: nc_tag
326  integer(I4B) :: iper, iaux
327 
328  iper = 0
329  iaux = 0
330 
331  ! set variable input tag
332  nc_tag = this%input_attribute(pkgname, idt)
333 
334  select case (idt%datatype)
335  case ('INTEGER1D')
336  call mem_setptr(int1d, idt%mf6varname, mempath)
337  call nc_export_int1d(int1d, this%ncid, this%dim_ids, this%var_ids, &
338  this%disv, idt, mempath, nc_tag, pkgname, &
339  this%gridmap_name, this%deflate, this%shuffle, &
340  this%chunk_face, iper, this%nc_fname)
341  case ('INTEGER2D')
342  call mem_setptr(int2d, idt%mf6varname, mempath)
343  call nc_export_int2d(int2d, this%ncid, this%dim_ids, this%var_ids, &
344  this%disv, idt, mempath, nc_tag, pkgname, &
345  this%gridmap_name, this%deflate, this%shuffle, &
346  this%chunk_face, this%nc_fname)
347  case ('DOUBLE1D')
348  call mem_setptr(dbl1d, idt%mf6varname, mempath)
349  call nc_export_dbl1d(dbl1d, this%ncid, this%dim_ids, this%var_ids, &
350  this%disv, idt, mempath, nc_tag, pkgname, &
351  this%gridmap_name, this%deflate, this%shuffle, &
352  this%chunk_face, iper, iaux, this%nc_fname)
353  case ('DOUBLE2D')
354  call mem_setptr(dbl2d, idt%mf6varname, mempath)
355  call nc_export_dbl2d(dbl2d, this%ncid, this%dim_ids, this%var_ids, &
356  this%disv, idt, mempath, nc_tag, pkgname, &
357  this%gridmap_name, this%deflate, this%shuffle, &
358  this%chunk_face, this%nc_fname)
359  case default
360  ! no-op, no other datatypes exported
361  end select
Here is the call graph for this function:

◆ nc_export_dbl1d()

subroutine meshdisvmodelmodule::nc_export_dbl1d ( real(dp), dimension(:), intent(in), pointer, contiguous  p_mem,
integer(i4b), intent(in)  ncid,
type(meshncdimidtype), intent(inout)  dim_ids,
type(meshncvaridtype), intent(inout)  var_ids,
type(disvtype), intent(in), pointer  disv,
type(inputparamdefinitiontype), pointer  idt,
character(len=*), intent(in)  mempath,
character(len=*), intent(in)  nc_tag,
character(len=*), intent(in)  pkgname,
character(len=*), intent(in)  gridmap_name,
integer(i4b), intent(in)  deflate,
integer(i4b), intent(in)  shuffle,
integer(i4b), intent(in)  chunk_face,
integer(i4b), intent(in)  iper,
integer(i4b), intent(in)  iaux,
character(len=*), intent(in)  nc_fname 
)
private

Definition at line 805 of file DisvNCMesh.f90.

808  use tdismodule, only: kper
809  real(DP), dimension(:), pointer, contiguous, intent(in) :: p_mem
810  integer(I4B), intent(in) :: ncid
811  type(MeshNCDimIdType), intent(inout) :: dim_ids
812  type(MeshNCVarIdType), intent(inout) :: var_ids
813  type(DisvType), pointer, intent(in) :: disv
814  type(InputParamDefinitionType), pointer :: idt
815  character(len=*), intent(in) :: mempath
816  character(len=*), intent(in) :: nc_tag
817  character(len=*), intent(in) :: pkgname
818  character(len=*), intent(in) :: gridmap_name
819  integer(I4B), intent(in) :: deflate
820  integer(I4B), intent(in) :: shuffle
821  integer(I4B), intent(in) :: chunk_face
822  integer(I4B), intent(in) :: iper
823  integer(I4B), intent(in) :: iaux
824  character(len=*), intent(in) :: nc_fname
825  real(DP), dimension(:), pointer, contiguous :: dbl1d
826  real(DP), dimension(:, :), pointer, contiguous :: dbl2d
827  integer(I4B) :: axis_sz, k
828  integer(I4B), dimension(:), allocatable :: var_id
829  character(len=LINELENGTH) :: longname, varname
830 
831  if (idt%shape == 'NCPL' .or. &
832  idt%shape == 'NAUX NCPL') then
833 
834  if (iper == 0) then
835  ! set names
836  varname = export_varname(pkgname, idt%tagname, mempath, &
837  iaux=iaux)
838  longname = export_longname(idt%longname, pkgname, idt%tagname, &
839  mempath, iaux=iaux, &
840  component_type=idt%component_type, &
841  subcomponent_type=idt%subcomponent_type)
842 
843  allocate (var_id(1))
844  axis_sz = dim_ids%nmesh_face
845 
846  ! reenter define mode and create variable
847  call nf_verify(nf90_redef(ncid), nc_fname)
848  call nf_verify(nf90_def_var(ncid, varname, nf90_double, &
849  (/axis_sz/), var_id(1)), &
850  nc_fname)
851 
852  ! apply chunking parameters
853  call ncvar_chunk(ncid, var_id(1), chunk_face, nc_fname)
854  ! deflate and shuffle
855  call ncvar_deflate(ncid, var_id(1), deflate, shuffle, nc_fname)
856 
857  ! put attr
858  call nf_verify(nf90_put_att(ncid, var_id(1), '_FillValue', &
859  (/nf90_fill_double/)), nc_fname)
860  call nf_verify(nf90_put_att(ncid, var_id(1), 'long_name', &
861  longname), nc_fname)
862 
863  ! add grid mapping and mf6 attr
864  call ncvar_gridmap(ncid, var_id(1), gridmap_name, 0, nc_fname)
865  call ncvar_mf6attr(ncid, var_id(1), 0, iaux, nc_tag, nc_fname)
866 
867  ! exit define mode and write data
868  call nf_verify(nf90_enddef(ncid), nc_fname)
869  call nf_verify(nf90_put_var(ncid, var_id(1), p_mem), &
870  nc_fname)
871  else
872  ! timeseries
873  call nf_verify(nf90_put_var(ncid, &
874  var_ids%export(1), p_mem, &
875  start=(/1, kper/), &
876  count=(/disv%ncpl, 1/)), nc_fname)
877  end if
878 
879  else
880 
881  dbl2d(1:disv%ncpl, 1:disv%nlay) => p_mem(1:disv%nodesuser)
882 
883  if (iper == 0) then
884  allocate (var_id(disv%nlay))
885 
886  ! reenter define mode and create variable
887  call nf_verify(nf90_redef(ncid), nc_fname)
888  do k = 1, disv%nlay
889  ! set names
890  varname = export_varname(pkgname, idt%tagname, mempath, layer=k, &
891  iaux=iaux)
892  longname = export_longname(idt%longname, pkgname, idt%tagname, &
893  mempath, layer=k, iaux=iaux, &
894  component_type=idt%component_type, &
895  subcomponent_type=idt%subcomponent_type)
896 
897  call nf_verify(nf90_def_var(ncid, varname, nf90_double, &
898  (/dim_ids%nmesh_face/), var_id(k)), &
899  nc_fname)
900 
901  ! apply chunking parameters
902  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
903  ! deflate and shuffle
904  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
905 
906  ! put attr
907  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
908  (/nf90_fill_double/)), nc_fname)
909  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
910  longname), nc_fname)
911 
912  ! add grid mapping and mf6 attr
913  call ncvar_gridmap(ncid, var_id(k), gridmap_name, k, nc_fname)
914  call ncvar_mf6attr(ncid, var_id(k), k, iaux, nc_tag, nc_fname)
915  end do
916 
917  ! exit define mode and write data
918  call nf_verify(nf90_enddef(ncid), nc_fname)
919  do k = 1, disv%nlay
920  call nf_verify(nf90_put_var(ncid, var_id(k), dbl2d(:, k)), nc_fname)
921  end do
922 
923  ! cleanup
924  deallocate (var_id)
925  else
926  ! timeseries, add period data
927  do k = 1, disv%nlay
928  dbl1d(1:disv%ncpl) => dbl2d(:, k)
929  call nf_verify(nf90_put_var(ncid, &
930  var_ids%export(k), dbl1d, &
931  start=(/1, kper/), &
932  count=(/disv%ncpl, 1/)), nc_fname)
933  end do
934  end if
935  end if
integer(i4b), pointer, public kper
current stress period number
Definition: tdis.f90:26
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nc_export_dbl2d()

subroutine meshdisvmodelmodule::nc_export_dbl2d ( real(dp), dimension(:, :), intent(in), pointer, contiguous  p_mem,
integer(i4b), intent(in)  ncid,
type(meshncdimidtype), intent(inout)  dim_ids,
type(meshncvaridtype), intent(inout)  var_ids,
type(disvtype), intent(in), pointer  disv,
type(inputparamdefinitiontype), pointer  idt,
character(len=*), intent(in)  mempath,
character(len=*), intent(in)  nc_tag,
character(len=*), intent(in)  pkgname,
character(len=*), intent(in)  gridmap_name,
integer(i4b), intent(in)  deflate,
integer(i4b), intent(in)  shuffle,
integer(i4b), intent(in)  chunk_face,
character(len=*), intent(in)  nc_fname 
)

Definition at line 940 of file DisvNCMesh.f90.

943  real(DP), dimension(:, :), pointer, contiguous, intent(in) :: p_mem
944  integer(I4B), intent(in) :: ncid
945  type(MeshNCDimIdType), intent(inout) :: dim_ids
946  type(MeshNCVarIdType), intent(inout) :: var_ids
947  type(DisvType), pointer, intent(in) :: disv
948  type(InputParamDefinitionType), pointer :: idt
949  character(len=*), intent(in) :: mempath
950  character(len=*), intent(in) :: nc_tag
951  character(len=*), intent(in) :: pkgname
952  character(len=*), intent(in) :: gridmap_name
953  integer(I4B), intent(in) :: deflate
954  integer(I4B), intent(in) :: shuffle
955  integer(I4B), intent(in) :: chunk_face
956  character(len=*), intent(in) :: nc_fname
957  integer(I4B), dimension(:), allocatable :: var_id
958  character(len=LINELENGTH) :: longname, varname
959  integer(I4B) :: k
960 
961  allocate (var_id(disv%nlay))
962 
963  ! reenter define mode and create variable
964  call nf_verify(nf90_redef(ncid), nc_fname)
965  do k = 1, disv%nlay
966  ! set names
967  varname = export_varname(pkgname, idt%tagname, mempath, layer=k)
968  longname = export_longname(idt%longname, pkgname, idt%tagname, &
969  mempath, layer=k, &
970  component_type=idt%component_type, &
971  subcomponent_type=idt%subcomponent_type)
972 
973  call nf_verify(nf90_def_var(ncid, varname, nf90_double, &
974  (/dim_ids%nmesh_face/), var_id(k)), &
975  nc_fname)
976 
977  ! apply chunking parameters
978  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
979  ! deflate and shuffle
980  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
981 
982  ! put attr
983  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
984  (/nf90_fill_double/)), nc_fname)
985  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
986  longname), nc_fname)
987 
988  ! add grid mapping and mf6 attr
989  call ncvar_gridmap(ncid, var_id(k), gridmap_name, k, nc_fname)
990  call ncvar_mf6attr(ncid, var_id(k), k, 0, nc_tag, nc_fname)
991  end do
992 
993  ! exit define mode and write data
994  call nf_verify(nf90_enddef(ncid), nc_fname)
995  do k = 1, disv%nlay
996  call nf_verify(nf90_put_var(ncid, var_id(k), p_mem(:, k)), nc_fname)
997  end do
998 
999  deallocate (var_id)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nc_export_int1d()

subroutine meshdisvmodelmodule::nc_export_int1d ( integer(i4b), dimension(:), intent(in), pointer, contiguous  p_mem,
integer(i4b), intent(in)  ncid,
type(meshncdimidtype), intent(inout)  dim_ids,
type(meshncvaridtype), intent(inout)  var_ids,
type(disvtype), intent(in), pointer  disv,
type(inputparamdefinitiontype), pointer  idt,
character(len=*), intent(in)  mempath,
character(len=*), intent(in)  nc_tag,
character(len=*), intent(in)  pkgname,
character(len=*), intent(in)  gridmap_name,
integer(i4b), intent(in)  deflate,
integer(i4b), intent(in)  shuffle,
integer(i4b), intent(in)  chunk_face,
integer(i4b), intent(in)  iper,
character(len=*), intent(in)  nc_fname 
)

Definition at line 610 of file DisvNCMesh.f90.

613  use tdismodule, only: kper
614  integer(I4B), dimension(:), pointer, contiguous, intent(in) :: p_mem
615  integer(I4B), intent(in) :: ncid
616  type(MeshNCDimIdType), intent(inout) :: dim_ids
617  type(MeshNCVarIdType), intent(inout) :: var_ids
618  type(DisvType), pointer, intent(in) :: disv
619  type(InputParamDefinitionType), pointer :: idt
620  character(len=*), intent(in) :: mempath
621  character(len=*), intent(in) :: nc_tag
622  character(len=*), intent(in) :: pkgname
623  character(len=*), intent(in) :: gridmap_name
624  integer(I4B), intent(in) :: deflate
625  integer(I4B), intent(in) :: shuffle
626  integer(I4B), intent(in) :: chunk_face
627  integer(I4B), intent(in) :: iper
628  character(len=*), intent(in) :: nc_fname
629  integer(I4B), dimension(:), pointer, contiguous :: int1d
630  integer(I4B), dimension(:, :), pointer, contiguous :: int2d
631  integer(I4B) :: axis_sz, k
632  integer(I4B), dimension(:), allocatable :: var_id
633  character(len=LINELENGTH) :: longname, varname
634 
635  if (idt%shape == 'NCPL' .or. &
636  idt%shape == 'NAUX NCPL') then
637 
638  if (iper == 0) then
639  ! set names
640  varname = export_varname(pkgname, idt%tagname, mempath)
641  longname = export_longname(idt%longname, pkgname, idt%tagname, mempath, &
642  component_type=idt%component_type, &
643  subcomponent_type=idt%subcomponent_type)
644 
645  allocate (var_id(1))
646  axis_sz = dim_ids%nmesh_face
647 
648  ! reenter define mode and create variable
649  call nf_verify(nf90_redef(ncid), nc_fname)
650  call nf_verify(nf90_def_var(ncid, varname, nf90_int, &
651  (/axis_sz/), var_id(1)), &
652  nc_fname)
653 
654  ! apply chunking parameters
655  call ncvar_chunk(ncid, var_id(1), chunk_face, nc_fname)
656  ! deflate and shuffle
657  call ncvar_deflate(ncid, var_id(1), deflate, shuffle, nc_fname)
658 
659  ! put attr
660  call nf_verify(nf90_put_att(ncid, var_id(1), '_FillValue', &
661  (/nf90_fill_int/)), nc_fname)
662  call nf_verify(nf90_put_att(ncid, var_id(1), 'long_name', &
663  longname), nc_fname)
664 
665  ! add grid mapping and mf6 attr
666  call ncvar_gridmap(ncid, var_id(1), gridmap_name, 0, nc_fname)
667  call ncvar_mf6attr(ncid, var_id(1), 0, 0, nc_tag, nc_fname)
668 
669  ! exit define mode and write data
670  call nf_verify(nf90_enddef(ncid), nc_fname)
671  call nf_verify(nf90_put_var(ncid, var_id(1), p_mem), &
672  nc_fname)
673  else
674  ! timeseries
675  call nf_verify(nf90_put_var(ncid, &
676  var_ids%export(1), p_mem, &
677  start=(/1, kper/), &
678  count=(/disv%ncpl, 1/)), nc_fname)
679  end if
680 
681  else
682 
683  int2d(1:disv%ncpl, 1:disv%nlay) => p_mem(1:disv%nodesuser)
684 
685  if (iper == 0) then
686  allocate (var_id(disv%nlay))
687 
688  ! reenter define mode and create variable
689  call nf_verify(nf90_redef(ncid), nc_fname)
690  do k = 1, disv%nlay
691  ! set names
692  varname = export_varname(pkgname, idt%tagname, mempath, layer=k)
693  longname = export_longname(idt%longname, pkgname, idt%tagname, &
694  mempath, layer=k, &
695  component_type=idt%component_type, &
696  subcomponent_type=idt%subcomponent_type)
697 
698  call nf_verify(nf90_def_var(ncid, varname, nf90_int, &
699  (/dim_ids%nmesh_face/), var_id(k)), &
700  nc_fname)
701 
702  ! apply chunking parameters
703  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
704  ! deflate and shuffle
705  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
706 
707  ! put attr
708  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
709  (/nf90_fill_int/)), nc_fname)
710  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
711  longname), nc_fname)
712 
713  ! add grid mapping and mf6 attr
714  call ncvar_gridmap(ncid, var_id(k), gridmap_name, k, nc_fname)
715  call ncvar_mf6attr(ncid, var_id(k), k, 0, nc_tag, nc_fname)
716  end do
717 
718  ! exit define mode and write data
719  call nf_verify(nf90_enddef(ncid), nc_fname)
720  do k = 1, disv%nlay
721  call nf_verify(nf90_put_var(ncid, var_id(k), int2d(:, k)), nc_fname)
722  end do
723 
724  ! cleanup
725  deallocate (var_id)
726  else
727  ! timeseries, add period data
728  do k = 1, disv%nlay
729  int1d(1:disv%ncpl) => int2d(:, k)
730  call nf_verify(nf90_put_var(ncid, &
731  var_ids%export(k), int1d, &
732  start=(/1, kper/), &
733  count=(/disv%ncpl, 1/)), nc_fname)
734  end do
735  end if
736  end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nc_export_int2d()

subroutine meshdisvmodelmodule::nc_export_int2d ( integer(i4b), dimension(:, :), intent(in), pointer, contiguous  p_mem,
integer(i4b), intent(in)  ncid,
type(meshncdimidtype), intent(inout)  dim_ids,
type(meshncvaridtype), intent(inout)  var_ids,
type(disvtype), intent(in), pointer  disv,
type(inputparamdefinitiontype), pointer  idt,
character(len=*), intent(in)  mempath,
character(len=*), intent(in)  nc_tag,
character(len=*), intent(in)  pkgname,
character(len=*), intent(in)  gridmap_name,
integer(i4b), intent(in)  deflate,
integer(i4b), intent(in)  shuffle,
integer(i4b), intent(in)  chunk_face,
character(len=*), intent(in)  nc_fname 
)

Definition at line 741 of file DisvNCMesh.f90.

744  integer(I4B), dimension(:, :), pointer, contiguous, intent(in) :: p_mem
745  integer(I4B), intent(in) :: ncid
746  type(MeshNCDimIdType), intent(inout) :: dim_ids
747  type(MeshNCVarIdType), intent(inout) :: var_ids
748  type(DisvType), pointer, intent(in) :: disv
749  type(InputParamDefinitionType), pointer :: idt
750  character(len=*), intent(in) :: mempath
751  character(len=*), intent(in) :: nc_tag
752  character(len=*), intent(in) :: pkgname
753  character(len=*), intent(in) :: gridmap_name
754  integer(I4B), intent(in) :: deflate
755  integer(I4B), intent(in) :: shuffle
756  integer(I4B), intent(in) :: chunk_face
757  character(len=*), intent(in) :: nc_fname
758  integer(I4B), dimension(:), allocatable :: var_id
759  character(len=LINELENGTH) :: longname, varname
760  integer(I4B) :: k
761 
762  allocate (var_id(disv%nlay))
763 
764  ! reenter define mode and create variable
765  call nf_verify(nf90_redef(ncid), nc_fname)
766  do k = 1, disv%nlay
767  ! set names
768  varname = export_varname(pkgname, idt%tagname, mempath, layer=k)
769  longname = export_longname(idt%longname, pkgname, idt%tagname, &
770  mempath, layer=k, &
771  component_type=idt%component_type, &
772  subcomponent_type=idt%subcomponent_type)
773 
774  call nf_verify(nf90_def_var(ncid, varname, nf90_int, &
775  (/dim_ids%nmesh_face/), var_id(k)), &
776  nc_fname)
777 
778  ! apply chunking parameters
779  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
780  ! deflate and shuffle
781  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
782 
783  ! put attr
784  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
785  (/nf90_fill_int/)), nc_fname)
786  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
787  longname), nc_fname)
788 
789  ! add grid mapping and mf6 attr
790  call ncvar_gridmap(ncid, var_id(k), gridmap_name, k, nc_fname)
791  call ncvar_mf6attr(ncid, var_id(k), k, 0, nc_tag, nc_fname)
792  end do
793 
794  ! exit define mode and write data
795  call nf_verify(nf90_enddef(ncid), nc_fname)
796  do k = 1, disv%nlay
797  call nf_verify(nf90_put_var(ncid, var_id(k), p_mem(:, k)), nc_fname)
798  end do
799 
800  deallocate (var_id)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ package_step()

subroutine meshdisvmodelmodule::package_step ( class(mesh2ddisvexporttype), intent(inout)  this,
class(exportpackagetype), intent(in), pointer  export_pkg 
)

Definition at line 184 of file DisvNCMesh.f90.

185  use tdismodule, only: totim, kper
188  class(Mesh2dDisvExportType), intent(inout) :: this
189  class(ExportPackageType), pointer, intent(in) :: export_pkg
190  type(InputParamDefinitionType), pointer :: idt
191  integer(I4B), dimension(:), pointer, contiguous :: int1d
192  real(DP), dimension(:), pointer, contiguous :: dbl1d, nodes
193  real(DP), dimension(:, :), pointer, contiguous :: dbl2d
194  character(len=LINELENGTH) :: nc_tag
195  integer(I4B) :: iaux, iparam, nvals
196  integer(I4B) :: k, n
197  integer(I4B), pointer :: nbound
198 
199  ! initialize
200  iaux = 0
201 
202  ! export defined period input
203  do iparam = 1, export_pkg%nparam
204  ! check if variable was read this period
205  if (export_pkg%param_reads(iparam)%invar < 1) cycle
206 
207  ! set input definition
208  idt => &
209  get_param_definition_type(export_pkg%mf6_input%param_dfns, &
210  export_pkg%mf6_input%component_type, &
211  export_pkg%mf6_input%subcomponent_type, &
212  'PERIOD', export_pkg%param_names(iparam), '')
213 
214  ! set variable input tag
215  nc_tag = this%input_attribute(export_pkg%mf6_input%subcomponent_name, &
216  idt)
217 
218  ! export arrays
219  select case (idt%datatype)
220  case ('INTEGER1D')
221  call mem_setptr(int1d, idt%mf6varname, export_pkg%mf6_input%mempath)
222  this%var_ids%export(1) = export_pkg%varids_param(iparam, 1)
223  call nc_export_int1d(int1d, this%ncid, this%dim_ids, this%var_ids, &
224  this%disv, idt, export_pkg%mf6_input%mempath, &
225  nc_tag, export_pkg%mf6_input%subcomponent_name, &
226  this%gridmap_name, this%deflate, this%shuffle, &
227  this%chunk_face, kper, this%nc_fname)
228  case ('DOUBLE1D')
229  call mem_setptr(dbl1d, idt%mf6varname, export_pkg%mf6_input%mempath)
230  select case (idt%shape)
231  case ('NCPL')
232  this%var_ids%export(1) = export_pkg%varids_param(iparam, 1)
233  call nc_export_dbl1d(dbl1d, this%ncid, this%dim_ids, this%var_ids, &
234  this%disv, idt, export_pkg%mf6_input%mempath, &
235  nc_tag, export_pkg%mf6_input%subcomponent_name, &
236  this%gridmap_name, this%deflate, this%shuffle, &
237  this%chunk_face, kper, iaux, this%nc_fname)
238  case ('NODES')
239  nvals = this%disv%nodesuser
240  allocate (nodes(nvals))
241  nodes = dnodata
242  do k = 1, this%disv%nlay
243  this%var_ids%export(k) = export_pkg%varids_param(iparam, k)
244  end do
245  call mem_setptr(dbl1d, idt%mf6varname, export_pkg%mf6_input%mempath)
246  call mem_setptr(int1d, 'NODEULIST', export_pkg%mf6_input%mempath)
247  call mem_setptr(nbound, 'NBOUND', export_pkg%mf6_input%mempath)
248  do n = 1, nbound
249  nodes(int1d(n)) = dbl1d(n)
250  end do
251  call nc_export_dbl1d(nodes, this%ncid, this%dim_ids, this%var_ids, &
252  this%disv, idt, export_pkg%mf6_input%mempath, &
253  nc_tag, export_pkg%mf6_input%subcomponent_name, &
254  this%gridmap_name, this%deflate, this%shuffle, &
255  this%chunk_face, kper, iaux, this%nc_fname)
256  deallocate (nodes)
257  case default
258  end select
259  case ('DOUBLE2D')
260  call mem_setptr(dbl2d, idt%mf6varname, export_pkg%mf6_input%mempath)
261  select case (idt%shape)
262  case ('NAUX NCPL')
263  nvals = this%disv%ncpl
264  allocate (nodes(nvals))
265  do iaux = 1, size(dbl2d, dim=1) !naux
266  this%var_ids%export(1) = export_pkg%varids_aux(iaux, 1)
267  do n = 1, nvals
268  nodes(n) = dbl2d(iaux, n)
269  end do
270  call nc_export_dbl1d(dbl1d, this%ncid, this%dim_ids, this%var_ids, &
271  this%disv, idt, export_pkg%mf6_input%mempath, &
272  nc_tag, export_pkg%mf6_input%subcomponent_name, &
273  this%gridmap_name, this%deflate, this%shuffle, &
274  this%chunk_face, kper, iaux, this%nc_fname)
275  end do
276  deallocate (nodes)
277  case ('NAUX NODES')
278  nvals = this%disv%nodesuser
279  allocate (nodes(nvals))
280  call mem_setptr(int1d, 'NODEULIST', export_pkg%mf6_input%mempath)
281  call mem_setptr(nbound, 'NBOUND', export_pkg%mf6_input%mempath)
282  do iaux = 1, size(dbl2d, dim=1) ! naux
283  nodes = dnodata
284  do k = 1, this%disv%nlay
285  this%var_ids%export(k) = export_pkg%varids_aux(iaux, k)
286  end do
287  do n = 1, nbound
288  nodes(int1d(n)) = dbl2d(iaux, n)
289  end do
290  call nc_export_dbl1d(nodes, this%ncid, this%dim_ids, this%var_ids, &
291  this%disv, idt, export_pkg%mf6_input%mempath, &
292  nc_tag, export_pkg%mf6_input%subcomponent_name, &
293  this%gridmap_name, this%deflate, this%shuffle, &
294  this%chunk_face, kper, iaux, this%nc_fname)
295  end do
296  deallocate (nodes)
297  case default
298  end select
299  case default
300  ! no-op, no other datatypes exported
301  end select
302  end do
303 
304  ! write to time coordinate variable
305  call nf_verify(nf90_put_var(this%ncid, this%var_ids%time, &
306  totim, start=(/kper/)), &
307  this%nc_fname)
308 
309  ! synchronize file
310  call nf_verify(nf90_sync(this%ncid), this%nc_fname)
This module contains the DefinitionSelectModule.
type(inputparamdefinitiontype) function, pointer, public get_param_definition_type(input_definition_types, component_type, subcomponent_type, blockname, tagname, filename, found)
Return parameter definition.
This module contains the NCModelExportModule.
Definition: NCModel.f90:8
real(dp), pointer, public totim
time relative to start of simulation
Definition: tdis.f90:35
Here is the call graph for this function:

◆ step()

subroutine meshdisvmodelmodule::step ( class(mesh2ddisvexporttype), intent(inout)  this)

Definition at line 117 of file DisvNCMesh.f90.

118  use constantsmodule, only: dhnoflo
119  use tdismodule, only: totim
120  class(Mesh2dDisvExportType), intent(inout) :: this
121  real(DP), dimension(:), pointer, contiguous :: dbl1d
122  integer(I4B) :: n, k, nvals, istp
123  integer(I4B), dimension(2) :: dis_shape
124  real(DP), dimension(:, :), pointer, contiguous :: dbl2d
125 
126  ! initialize
127  nullify (dbl1d)
128  nullify (dbl2d)
129 
130  ! set global step index
131  istp = this%istp()
132 
133  dis_shape(1) = this%disv%ncpl
134  dis_shape(2) = this%disv%nlay
135 
136  nvals = product(dis_shape)
137 
138  ! add data to dependent variable
139  if (size(this%disv%nodeuser) < &
140  size(this%disv%nodereduced)) then
141  ! allocate nodereduced size 1d array
142  allocate (dbl1d(size(this%disv%nodereduced)))
143 
144  ! initialize DHNOFLO for non-active cells
145  dbl1d = dhnoflo
146 
147  ! update active cells
148  do n = 1, size(this%disv%nodereduced)
149  if (this%disv%nodereduced(n) > 0) then
150  dbl1d(n) = this%x(this%disv%nodereduced(n))
151  end if
152  end do
153 
154  dbl2d(1:dis_shape(1), 1:dis_shape(2)) => dbl1d(1:nvals)
155  else
156  dbl2d(1:dis_shape(1), 1:dis_shape(2)) => this%x(1:nvals)
157  end if
158 
159  do k = 1, this%disv%nlay
160  ! extend array with step data
161  call nf_verify(nf90_put_var(this%ncid, &
162  this%var_ids%dependent(k), dbl2d(:, k), &
163  start=(/1, istp/), &
164  count=(/this%disv%ncpl, 1/)), &
165  this%nc_fname)
166  end do
167 
168  ! write to time coordinate variable
169  call nf_verify(nf90_put_var(this%ncid, this%var_ids%time, &
170  totim, start=(/istp/)), &
171  this%nc_fname)
172 
173  ! update file
174  call nf_verify(nf90_sync(this%ncid), this%nc_fname)
175 
176  ! cleanup
177  if (associated(dbl1d)) deallocate (dbl1d)
178  nullify (dbl1d)
179  nullify (dbl2d)
real(dp), parameter dhnoflo
real no flow constant
Definition: Constants.f90:93
Here is the call graph for this function: