MODFLOW 6  version 6.8.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 422 of file DisvNCMesh.f90.

424  class(Mesh2dDisvExportType), intent(inout) :: this
425  integer(I4B), dimension(:), contiguous, pointer :: ncvert => null()
426  integer(I4B), dimension(:), contiguous, pointer :: icvert => null()
427  real(DP), dimension(:), contiguous, pointer :: cell_xt => null()
428  real(DP), dimension(:), contiguous, pointer :: cell_yt => null()
429  real(DP), dimension(:), contiguous, pointer :: vert_xt => null()
430  real(DP), dimension(:), contiguous, pointer :: vert_yt => null()
431  real(DP) :: x_transform, y_transform
432  integer(I4B) :: n, m, idx, cnt, iv, maxvert, k
433  integer(I4B), dimension(:), allocatable :: verts, layers
434  real(DP), dimension(:), allocatable :: bnds
435  integer(I4B) :: istop
436 
437  ! set pointers to input context
438  call mem_setptr(ncvert, 'NCVERT', this%dis_mempath)
439  call mem_setptr(icvert, 'ICVERT', this%dis_mempath)
440 
441  ! allocate x, y transform arrays
442  allocate (cell_xt(this%disv%ncpl))
443  allocate (cell_yt(this%disv%ncpl))
444  allocate (vert_xt(this%disv%nvert))
445  allocate (vert_yt(this%disv%nvert))
446 
447  ! set mesh container variable value to 1
448  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh, 1), &
449  this%nc_fname)
450 
451  ! write layer coordinate data
452  allocate (layers(this%nlay))
453  do k = 1, this%nlay
454  layers(k) = k
455  end do
456  call nf_verify(nf90_put_var(this%ncid, this%var_ids%layer, layers), &
457  this%nc_fname)
458  deallocate (layers)
459 
460  ! transform vert x and y
461  do n = 1, this%disv%nvert
462  call dis_transform_xy(this%disv%vertices(1, n), this%disv%vertices(2, n), &
463  this%disv%xorigin, &
464  this%disv%yorigin, &
465  this%disv%angrot, &
466  x_transform, y_transform)
467  vert_xt(n) = x_transform
468  vert_yt(n) = y_transform
469  end do
470 
471  ! transform cell x and y
472  do n = 1, this%disv%ncpl
473  call dis_transform_xy(this%disv%cellxy(1, n), this%disv%cellxy(2, n), &
474  this%disv%xorigin, &
475  this%disv%yorigin, &
476  this%disv%angrot, &
477  x_transform, y_transform)
478  cell_xt(n) = x_transform
479  cell_yt(n) = y_transform
480  end do
481 
482  ! write node_x and node_y arrays to netcdf file
483  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_node_x, &
484  vert_xt), this%nc_fname)
485  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_node_y, &
486  vert_yt), this%nc_fname)
487 
488  ! write face_x and face_y arrays to netcdf file
489  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_x, &
490  cell_xt), this%nc_fname)
491  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_y, &
492  cell_yt), this%nc_fname)
493 
494  ! initialize max vertices required to define cell
495  maxvert = maxval(ncvert)
496 
497  ! allocate temporary arrays
498  allocate (verts(maxvert))
499  allocate (bnds(maxvert))
500 
501  ! set face nodes array
502  cnt = 0
503  do n = 1, this%disv%ncpl
504  verts = nf90_fill_int
505  idx = cnt + ncvert(n)
506  iv = 0
507  istop = cnt + 1
508  do m = idx, istop, -1
509  cnt = cnt + 1
510  iv = iv + 1
511  verts(iv) = icvert(m)
512  end do
513 
514  ! don't close the cell
515  if (verts(iv) == verts(1)) verts(iv) = nf90_fill_int
516 
517  ! write face nodes array to netcdf file
518  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_nodes, &
519  verts, start=(/1, n/), &
520  count=(/maxvert, 1/)), &
521  this%nc_fname)
522 
523  ! set face y bounds array
524  bnds = nf90_fill_double
525  do m = 1, size(bnds)
526  if (verts(m) /= nf90_fill_int) then
527  bnds(m) = vert_yt(verts(m))
528  end if
529  ! write face y bounds array to netcdf file
530  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_ybnds, &
531  bnds, start=(/1, n/), &
532  count=(/maxvert, 1/)), &
533  this%nc_fname)
534  end do
535 
536  ! set face x bounds array
537  bnds = nf90_fill_double
538  do m = 1, size(bnds)
539  if (verts(m) /= nf90_fill_int) then
540  bnds(m) = vert_xt(verts(m))
541  end if
542  ! write face x bounds array to netcdf file
543  call nf_verify(nf90_put_var(this%ncid, this%var_ids%mesh_face_xbnds, &
544  bnds, start=(/1, n/), &
545  count=(/maxvert, 1/)), &
546  this%nc_fname)
547  end do
548  end do
549 
550  ! cleanup
551  deallocate (bnds)
552  deallocate (verts)
553  deallocate (cell_xt)
554  deallocate (cell_yt)
555  deallocate (vert_xt)
556  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 
372  ! set pointers to input context
373  call mem_setptr(ncvert, 'NCVERT', this%dis_mempath)
374 
375  if (isim_mode /= mvalidate .or. this%pkglist%Count() > 0) then
376  ! time
377  call nf_verify(nf90_def_dim(this%ncid, 'time', this%totnstp, &
378  this%dim_ids%time), this%nc_fname)
379  call nf_verify(nf90_def_var(this%ncid, 'time', nf90_double, &
380  this%dim_ids%time, this%var_ids%time), &
381  this%nc_fname)
382  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'calendar', &
383  'standard'), this%nc_fname)
384  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'units', &
385  this%datetime), this%nc_fname)
386  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'axis', 'T'), &
387  this%nc_fname)
388  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'standard_name', &
389  'time'), this%nc_fname)
390  call nf_verify(nf90_put_att(this%ncid, this%var_ids%time, 'long_name', &
391  'time'), this%nc_fname)
392  end if
393 
394  ! mesh
395  call nf_verify(nf90_def_dim(this%ncid, 'nmesh_node', this%disv%nvert, &
396  this%dim_ids%nmesh_node), this%nc_fname)
397  call nf_verify(nf90_def_dim(this%ncid, 'nmesh_face', this%disv%ncpl, &
398  this%dim_ids%nmesh_face), this%nc_fname)
399  call nf_verify(nf90_def_dim(this%ncid, 'max_nmesh_face_nodes', &
400  maxval(ncvert), &
401  this%dim_ids%max_nmesh_face_nodes), &
402  this%nc_fname)
403 
404  ! layer
405  call nf_verify(nf90_def_dim(this%ncid, 'layer', this%nlay, &
406  this%dim_ids%layer), this%nc_fname)
407  call nf_verify(nf90_def_var(this%ncid, 'layer', nf90_int, &
408  this%dim_ids%layer, this%var_ids%layer), &
409  this%nc_fname)
410  call nf_verify(nf90_put_att(this%ncid, this%var_ids%layer, 'units', '1'), &
411  this%nc_fname)
412  call nf_verify(nf90_put_att(this%ncid, this%var_ids%layer, 'axis', 'Z'), &
413  this%nc_fname)
414  call nf_verify(nf90_put_att(this%ncid, this%var_ids%layer, 'positive', &
415  'down'), this%nc_fname)
416  call nf_verify(nf90_put_att(this%ncid, this%var_ids%layer, 'long_name', &
417  'model layer'), this%nc_fname)
This module contains simulation constants.
Definition: Constants.f90:9
@ mvalidate
validation mode - do not run time steps
Definition: Constants.f90:205
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 756 of file DisvNCMesh.f90.

759  use tdismodule, only: kper
760  real(DP), dimension(:), pointer, contiguous, intent(in) :: p_mem
761  integer(I4B), intent(in) :: ncid
762  type(MeshNCDimIdType), intent(inout) :: dim_ids
763  type(MeshNCVarIdType), intent(inout) :: var_ids
764  type(DisvType), pointer, intent(in) :: disv
765  type(InputParamDefinitionType), pointer :: idt
766  character(len=*), intent(in) :: mempath
767  character(len=*), intent(in) :: nc_tag
768  character(len=*), intent(in) :: pkgname
769  character(len=*), intent(in) :: gridmap_name
770  integer(I4B), intent(in) :: deflate
771  integer(I4B), intent(in) :: shuffle
772  integer(I4B), intent(in) :: chunk_face
773  integer(I4B), intent(in) :: iper
774  integer(I4B), intent(in) :: iaux
775  character(len=*), intent(in) :: nc_fname
776  real(DP), dimension(:), pointer, contiguous :: dbl1d
777  real(DP), dimension(:, :), pointer, contiguous :: dbl2d
778  integer(I4B) :: axis_sz, k
779  integer(I4B), dimension(:), allocatable :: var_id
780  character(len=LINELENGTH) :: longname, varname
781 
782  if (idt%shape == 'NCPL' .or. &
783  idt%shape == 'NAUX NCPL') then
784 
785  if (iper == 0) then
786  ! set names
787  varname = export_varname(pkgname, idt%tagname, mempath, &
788  iaux=iaux)
789  longname = export_longname(idt%longname, pkgname, idt%tagname, &
790  mempath, iaux=iaux, &
791  component_type=idt%component_type, &
792  subcomponent_type=idt%subcomponent_type)
793 
794  allocate (var_id(1))
795  axis_sz = dim_ids%nmesh_face
796 
797  ! reenter define mode and create variable
798  call nf_verify(nf90_redef(ncid), nc_fname)
799  call nf_verify(nf90_def_var(ncid, varname, nf90_double, &
800  (/axis_sz/), var_id(1)), &
801  nc_fname)
802 
803  ! apply chunking parameters
804  call ncvar_chunk(ncid, var_id(1), chunk_face, nc_fname)
805  ! deflate and shuffle
806  call ncvar_deflate(ncid, var_id(1), deflate, shuffle, nc_fname)
807 
808  ! put attr
809  call nf_verify(nf90_put_att(ncid, var_id(1), '_FillValue', &
810  (/nf90_fill_double/)), nc_fname)
811  call nf_verify(nf90_put_att(ncid, var_id(1), 'long_name', &
812  longname), nc_fname)
813 
814  ! add grid mapping and mf6 attr
815  call ncvar_gridmap(ncid, var_id(1), gridmap_name, nc_fname)
816  call ncvar_mf6attr(ncid, var_id(1), 0, iaux, nc_tag, nc_fname)
817 
818  ! exit define mode and write data
819  call nf_verify(nf90_enddef(ncid), nc_fname)
820  call nf_verify(nf90_put_var(ncid, var_id(1), p_mem), &
821  nc_fname)
822  else
823  ! timeseries
824  call nf_verify(nf90_put_var(ncid, &
825  var_ids%export(1), p_mem, &
826  start=(/1, kper/), &
827  count=(/disv%ncpl, 1/)), nc_fname)
828  end if
829 
830  else
831 
832  dbl2d(1:disv%ncpl, 1:disv%nlay) => p_mem(1:disv%nodesuser)
833 
834  if (iper == 0) then
835  allocate (var_id(disv%nlay))
836 
837  ! reenter define mode and create variable
838  call nf_verify(nf90_redef(ncid), nc_fname)
839  do k = 1, disv%nlay
840  ! set names
841  varname = export_varname(pkgname, idt%tagname, mempath, layer=k, &
842  iaux=iaux)
843  longname = export_longname(idt%longname, pkgname, idt%tagname, &
844  mempath, layer=k, iaux=iaux, &
845  component_type=idt%component_type, &
846  subcomponent_type=idt%subcomponent_type)
847 
848  call nf_verify(nf90_def_var(ncid, varname, nf90_double, &
849  (/dim_ids%nmesh_face/), var_id(k)), &
850  nc_fname)
851 
852  ! apply chunking parameters
853  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
854  ! deflate and shuffle
855  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
856 
857  ! put attr
858  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
859  (/nf90_fill_double/)), nc_fname)
860  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
861  longname), nc_fname)
862 
863  ! add grid mapping and mf6 attr
864  call ncvar_gridmap(ncid, var_id(k), gridmap_name, nc_fname)
865  call ncvar_mf6attr(ncid, var_id(k), k, iaux, nc_tag, nc_fname)
866  end do
867 
868  ! exit define mode and write data
869  call nf_verify(nf90_enddef(ncid), nc_fname)
870  do k = 1, disv%nlay
871  call nf_verify(nf90_put_var(ncid, var_id(k), dbl2d(:, k)), nc_fname)
872  end do
873 
874  ! cleanup
875  deallocate (var_id)
876  else
877  ! timeseries, add period data
878  do k = 1, disv%nlay
879  dbl1d(1:disv%ncpl) => dbl2d(:, k)
880  call nf_verify(nf90_put_var(ncid, &
881  var_ids%export(k), dbl1d, &
882  start=(/1, kper/), &
883  count=(/disv%ncpl, 1/)), nc_fname)
884  end do
885  end if
886  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 891 of file DisvNCMesh.f90.

894  real(DP), dimension(:, :), pointer, contiguous, intent(in) :: p_mem
895  integer(I4B), intent(in) :: ncid
896  type(MeshNCDimIdType), intent(inout) :: dim_ids
897  type(MeshNCVarIdType), intent(inout) :: var_ids
898  type(DisvType), pointer, intent(in) :: disv
899  type(InputParamDefinitionType), pointer :: idt
900  character(len=*), intent(in) :: mempath
901  character(len=*), intent(in) :: nc_tag
902  character(len=*), intent(in) :: pkgname
903  character(len=*), intent(in) :: gridmap_name
904  integer(I4B), intent(in) :: deflate
905  integer(I4B), intent(in) :: shuffle
906  integer(I4B), intent(in) :: chunk_face
907  character(len=*), intent(in) :: nc_fname
908  integer(I4B), dimension(:), allocatable :: var_id
909  character(len=LINELENGTH) :: longname, varname
910  integer(I4B) :: k
911 
912  allocate (var_id(disv%nlay))
913 
914  ! reenter define mode and create variable
915  call nf_verify(nf90_redef(ncid), nc_fname)
916  do k = 1, disv%nlay
917  ! set names
918  varname = export_varname(pkgname, idt%tagname, mempath, layer=k)
919  longname = export_longname(idt%longname, pkgname, idt%tagname, &
920  mempath, layer=k, &
921  component_type=idt%component_type, &
922  subcomponent_type=idt%subcomponent_type)
923 
924  call nf_verify(nf90_def_var(ncid, varname, nf90_double, &
925  (/dim_ids%nmesh_face/), var_id(k)), &
926  nc_fname)
927 
928  ! apply chunking parameters
929  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
930  ! deflate and shuffle
931  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
932 
933  ! put attr
934  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
935  (/nf90_fill_double/)), nc_fname)
936  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
937  longname), nc_fname)
938 
939  ! add grid mapping and mf6 attr
940  call ncvar_gridmap(ncid, var_id(k), gridmap_name, nc_fname)
941  call ncvar_mf6attr(ncid, var_id(k), k, 0, nc_tag, nc_fname)
942  end do
943 
944  ! exit define mode and write data
945  call nf_verify(nf90_enddef(ncid), nc_fname)
946  do k = 1, disv%nlay
947  call nf_verify(nf90_put_var(ncid, var_id(k), p_mem(:, k)), nc_fname)
948  end do
949 
950  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 561 of file DisvNCMesh.f90.

564  use tdismodule, only: kper
565  integer(I4B), dimension(:), pointer, contiguous, intent(in) :: p_mem
566  integer(I4B), intent(in) :: ncid
567  type(MeshNCDimIdType), intent(inout) :: dim_ids
568  type(MeshNCVarIdType), intent(inout) :: var_ids
569  type(DisvType), pointer, intent(in) :: disv
570  type(InputParamDefinitionType), pointer :: idt
571  character(len=*), intent(in) :: mempath
572  character(len=*), intent(in) :: nc_tag
573  character(len=*), intent(in) :: pkgname
574  character(len=*), intent(in) :: gridmap_name
575  integer(I4B), intent(in) :: deflate
576  integer(I4B), intent(in) :: shuffle
577  integer(I4B), intent(in) :: chunk_face
578  integer(I4B), intent(in) :: iper
579  character(len=*), intent(in) :: nc_fname
580  integer(I4B), dimension(:), pointer, contiguous :: int1d
581  integer(I4B), dimension(:, :), pointer, contiguous :: int2d
582  integer(I4B) :: axis_sz, k
583  integer(I4B), dimension(:), allocatable :: var_id
584  character(len=LINELENGTH) :: longname, varname
585 
586  if (idt%shape == 'NCPL' .or. &
587  idt%shape == 'NAUX NCPL') then
588 
589  if (iper == 0) then
590  ! set names
591  varname = export_varname(pkgname, idt%tagname, mempath)
592  longname = export_longname(idt%longname, pkgname, idt%tagname, mempath, &
593  component_type=idt%component_type, &
594  subcomponent_type=idt%subcomponent_type)
595 
596  allocate (var_id(1))
597  axis_sz = dim_ids%nmesh_face
598 
599  ! reenter define mode and create variable
600  call nf_verify(nf90_redef(ncid), nc_fname)
601  call nf_verify(nf90_def_var(ncid, varname, nf90_int, &
602  (/axis_sz/), var_id(1)), &
603  nc_fname)
604 
605  ! apply chunking parameters
606  call ncvar_chunk(ncid, var_id(1), chunk_face, nc_fname)
607  ! deflate and shuffle
608  call ncvar_deflate(ncid, var_id(1), deflate, shuffle, nc_fname)
609 
610  ! put attr
611  call nf_verify(nf90_put_att(ncid, var_id(1), '_FillValue', &
612  (/nf90_fill_int/)), nc_fname)
613  call nf_verify(nf90_put_att(ncid, var_id(1), 'long_name', &
614  longname), nc_fname)
615 
616  ! add grid mapping and mf6 attr
617  call ncvar_gridmap(ncid, var_id(1), gridmap_name, nc_fname)
618  call ncvar_mf6attr(ncid, var_id(1), 0, 0, nc_tag, nc_fname)
619 
620  ! exit define mode and write data
621  call nf_verify(nf90_enddef(ncid), nc_fname)
622  call nf_verify(nf90_put_var(ncid, var_id(1), p_mem), &
623  nc_fname)
624  else
625  ! timeseries
626  call nf_verify(nf90_put_var(ncid, &
627  var_ids%export(1), p_mem, &
628  start=(/1, kper/), &
629  count=(/disv%ncpl, 1/)), nc_fname)
630  end if
631 
632  else
633 
634  int2d(1:disv%ncpl, 1:disv%nlay) => p_mem(1:disv%nodesuser)
635 
636  if (iper == 0) then
637  allocate (var_id(disv%nlay))
638 
639  ! reenter define mode and create variable
640  call nf_verify(nf90_redef(ncid), nc_fname)
641  do k = 1, disv%nlay
642  ! set names
643  varname = export_varname(pkgname, idt%tagname, mempath, layer=k)
644  longname = export_longname(idt%longname, pkgname, idt%tagname, &
645  mempath, layer=k, &
646  component_type=idt%component_type, &
647  subcomponent_type=idt%subcomponent_type)
648 
649  call nf_verify(nf90_def_var(ncid, varname, nf90_int, &
650  (/dim_ids%nmesh_face/), var_id(k)), &
651  nc_fname)
652 
653  ! apply chunking parameters
654  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
655  ! deflate and shuffle
656  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
657 
658  ! put attr
659  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
660  (/nf90_fill_int/)), nc_fname)
661  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
662  longname), nc_fname)
663 
664  ! add grid mapping and mf6 attr
665  call ncvar_gridmap(ncid, var_id(k), gridmap_name, nc_fname)
666  call ncvar_mf6attr(ncid, var_id(k), k, 0, nc_tag, nc_fname)
667  end do
668 
669  ! exit define mode and write data
670  call nf_verify(nf90_enddef(ncid), nc_fname)
671  do k = 1, disv%nlay
672  call nf_verify(nf90_put_var(ncid, var_id(k), int2d(:, k)), nc_fname)
673  end do
674 
675  ! cleanup
676  deallocate (var_id)
677  else
678  ! timeseries, add period data
679  do k = 1, disv%nlay
680  int1d(1:disv%ncpl) => int2d(:, k)
681  call nf_verify(nf90_put_var(ncid, &
682  var_ids%export(k), int1d, &
683  start=(/1, kper/), &
684  count=(/disv%ncpl, 1/)), nc_fname)
685  end do
686  end if
687  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 692 of file DisvNCMesh.f90.

695  integer(I4B), dimension(:, :), pointer, contiguous, intent(in) :: p_mem
696  integer(I4B), intent(in) :: ncid
697  type(MeshNCDimIdType), intent(inout) :: dim_ids
698  type(MeshNCVarIdType), intent(inout) :: var_ids
699  type(DisvType), pointer, intent(in) :: disv
700  type(InputParamDefinitionType), pointer :: idt
701  character(len=*), intent(in) :: mempath
702  character(len=*), intent(in) :: nc_tag
703  character(len=*), intent(in) :: pkgname
704  character(len=*), intent(in) :: gridmap_name
705  integer(I4B), intent(in) :: deflate
706  integer(I4B), intent(in) :: shuffle
707  integer(I4B), intent(in) :: chunk_face
708  character(len=*), intent(in) :: nc_fname
709  integer(I4B), dimension(:), allocatable :: var_id
710  character(len=LINELENGTH) :: longname, varname
711  integer(I4B) :: k
712 
713  allocate (var_id(disv%nlay))
714 
715  ! reenter define mode and create variable
716  call nf_verify(nf90_redef(ncid), nc_fname)
717  do k = 1, disv%nlay
718  ! set names
719  varname = export_varname(pkgname, idt%tagname, mempath, layer=k)
720  longname = export_longname(idt%longname, pkgname, idt%tagname, &
721  mempath, layer=k, &
722  component_type=idt%component_type, &
723  subcomponent_type=idt%subcomponent_type)
724 
725  call nf_verify(nf90_def_var(ncid, varname, nf90_int, &
726  (/dim_ids%nmesh_face/), var_id(k)), &
727  nc_fname)
728 
729  ! apply chunking parameters
730  call ncvar_chunk(ncid, var_id(k), chunk_face, nc_fname)
731  ! deflate and shuffle
732  call ncvar_deflate(ncid, var_id(k), deflate, shuffle, nc_fname)
733 
734  ! put attr
735  call nf_verify(nf90_put_att(ncid, var_id(k), '_FillValue', &
736  (/nf90_fill_int/)), nc_fname)
737  call nf_verify(nf90_put_att(ncid, var_id(k), 'long_name', &
738  longname), nc_fname)
739 
740  ! add grid mapping and mf6 attr
741  call ncvar_gridmap(ncid, var_id(k), gridmap_name, nc_fname)
742  call ncvar_mf6attr(ncid, var_id(k), k, 0, nc_tag, nc_fname)
743  end do
744 
745  ! exit define mode and write data
746  call nf_verify(nf90_enddef(ncid), nc_fname)
747  do k = 1, disv%nlay
748  call nf_verify(nf90_put_var(ncid, var_id(k), p_mem(:, k)), nc_fname)
749  end do
750 
751  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: