Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Include Page
TOOLS:Header, DesignTOOLS:
Header, Design
scrollbar

...

Implementation steps

We will implement running of Sobek through a dll using the following approach:

...

setvalues will be defined in new interface (not in iwlaccess !)
fortran c / code will implement methods in interface

Steps to follow

step 1
Convert cf_openmi to vs2005 sln (debugging fortran will be easier and is a requirement)

step 2
Define derived types for 1d model:

  • Network
    Code Block
    
    Type Network
     int nNodes 
     Node Nodes [nNodes]
     int nBranches
     Branch Branches []
    End Type
    
    Type Node
    End Type
    
    Type Branch
    End Type
    
  • Model parameters
  • Boundary Conditions
  • Initial Conditions
  • Structures
  • Output variables

step 3
create an adapter inside cf_openmi with an interface to 1d model with at least the following kind of methods:
-setnetwork
-setboundaryandinitial
-setparameters

we want our c# model to look like this (user friendly)

No Format

        [Test]
        public void RunSobek()
        {
            double startTime = 0.0;
            double endTime = 10.0;
            double timeStep = 1.0;

            Model1D.Initialize();

            // create simple network
            //
            // n1           n2             n3
            // x|----|--------|x|-------------|x
            //      r1             r2
            //

            Model1D.SetBranches(...);
            Model1D.SetGridSteps(...);
            
            Model1D.SetRunTimeParameter(startTime, endTime, timeStep);
            
            Model1D.RunTimeStep();

            double time = Model1D.GetCurrentTime();

            Assert.AreEqual(1.0, time);
        }

 

see similar implementation for modflow

examples

Notes

  1. Sobek OpenMI module: 
    Useful function for initialising and performing one or more timesteps and finalizing.
    •  'SE_OpenMI.f90' communicates with OEM buffer.
    • 'SE_OpenMI.f90' has calls to module OMI_CF_control in (OMI_CF_control.f90), which in turn calls directly sobeksim subroutines
  1. Present SOBEK reads nefis files during initialisation (using m_nefisinput.mod). Nefis is used in subroutines: read_initial_values_strpar_etc, soedef, sogetm and wetcrs.

SOBEK variables read from NEFIS

interface

General structure of the Deltshell - Sobeksim interface

The sobeksim interface now consists of the projects:

  1. DelftModelApi.Net
  2. delft_model_api
  3. delft_model_data

furthermore a module called GUI_communication is added to the project kernel_sobek_f

In DelftModelApi.Net the static class modelApi is defined. This class contains functions to transfer data from C# to the SOBEKSIM kernel. The functions in class modelApi are implemented in delft_model_api.dll. In module modelApi the exported functions of delft_model_api.dll are defined. The relevant data is stored in ModelGlobalData. ModelGlobalData uses derived types which are defined in ModelTypes and NetworkTypes. ModelTypes contains the run-time parameters and model state variables, whereas NetworkTypes contains the derived types to define a network. The module GUI_communication transfers the data from ModelGlobalData to the data structure of Sobeksim.

DelftModelApi.Net and GUI_Communication are described in the next subsections

DelftModelApi.Net

DelftModelApi.net contains the static class ModelApi. ModelApi in its turn contains functions to transfer data from C# to the SOBEKSIM kernel.
Available functions are:

Name

Description

setUsePluginData

Sets the flag for the computational kernel to use the modelapi

NetworkSetDimensions

Sets the dimensions of the network (number of branches, nodes, cross sections, ...

NetworkSetNode

Define a new node in the network

NetworkSetBranch

Define a new branch in the network

NetworkGetBranch

Get a branch

NetworkSetQBoundary

Set a Q-boundary at an end node of the network (limitation: at this time only constant boundary conditions are allowed)

NetworkSetHBoundary

Set an H-boundary at an end node of the network (limitation: at this time only constant boundary conditions are allowed)

NetworkSetTabCrossSection

Define a cross section in terms of widths with respect to height

NetworkSetCS

connect a cross section definition to a branch (limitation: Momentarily only one cross section per branch is allowed)

ModelInitialize

Start the SOBEK initialisation

ModelSetSimulationTimes

Set the simulation times for the model

ModelFinalize

Close/terminate the simulation

ModelGetCurrentTime

Gets the SOBEK current simulation time

ModelPerformTimeStep

Perform one time step

GUI_communication

In GUI_communication the datastructure of Sobeksim is filled. Since the initialisation of the arrays is performed at different locations in Sobeksim, there is a number of subroutines that perform a part of the initialisation, namely setValues, setValuesinMempool, getcsnam, setFlsData, setIds and setArrays.

Subroutine dumppool of GUI_Communication can be used for debugging purposes. Because dumppool writes the datastructure of sobeksim to file.

Todo

network

  1. More options for definition of grid

Structures

  1. Add structures to interface
  2. Add controllers and triggers to interface

Cross sections

  1. Add different types of cross sections, other than tabulated.
  2. Possibility to add more than one cross section on a branch (interpolation)
  3. Generation of conveyance tables

Boundary conditions

  1. QH-tables
  2. Time dependent boundary conditions
  3. Lateral discharges

Other

  1. Replace reading of Sobeksim.fnm
  2. Replace reading of Sobeksim.ini

Examples

In this example a network with three branches is defined. ModelApi example

Notes

  1. Sobek OpenMI module: 
    Useful function for initialising and performing one or more timesteps and finalizing.
    •  'SE_OpenMI.f90' communicates with OEM buffer.
    • 'SE_OpenMI.f90' has calls to module OMI_CF_control in (OMI_CF_control.f90), which in turn calls directly sobeksim subroutines
  1. Present SOBEK reads nefis files during initialisation (using m_nefisinput.mod). Nefis is used in subroutines: read_initial_values_strpar_etc, soedef, sogetm and wetcrs.

SOBEK variables read from NEFIS

Code Block
Code Block

module DS_communication

   type Sobek_Data	
      integer                         :: nnode         ! nr of sobek nodes
      integer                         :: nbran         ! nr of branches
      integer                         :: nstdb
      integer                         :: nstru         ! number of structures
      integer                         :: ntrigrnnode         ! numbernr of triggerssobek nodes
      integer                         :: nbran ncontr        ! numbernr of controllersbranches
      integer                         :: ntcrel        ! number of trigger-controller relations nstdb
      integer                         :: ncsrelnstru         ! number of controller-structure relationsstructures
      integer                         :: nqlatntrigr         ! number of lateral inflowstriggers
      integer                         :: ngridncontr         ! nrnumber of sobek pointscontrollers
      integer                         :: nbounntcrel         ! number of opentrigger-controller boundariesrelations
      integer                         :: nhstatncsrel        ! number of 1D waterlevel boundariescontroller-structure relations
      integer                         :: nqstatnqlat         ! number of 1Dlateral discharge boundariesinflows
      integer                         :: ngrid         ! nr of ::sobek ntabmpoints
      integer                         :: maxtab
nboun      integer   ! number of open boundaries
      integer            :: maxlev
      integer      :: nhstat        ! number of 1D       :: ncrosswaterlevel boundaries
      integer                         :: nevents
nqstat      integer  ! number of 1D discharge boundaries
      integer            :: mxstrpar      ! leading dimension of strpar
      integer  :: ntabm
      integer                 :: mxistrtyp     ! leading dimension of istrtyp:: maxtab
      integer                         :: mxstrmu       !maxlev
      integer                         :: mxcrossncross
      integer                         :: mxqltparnevents
      integer                         :: mxtrigermxstrpar      ! leading dimension of trigerstrpar
      integer                         :: mxcontrlmxistrtyp      ! leading dimension of contrlistrtyp
      integer                         :: mxconhis = 5  ! leading dimension of conhis
      integer      :: mxstrmu       !
      integer     :: mxconhis      ! leading dimension of conhis
      integer   :: mxcross
      integer               :: mxtrcnrl      ! leading dimension of:: trcnrlmxqltpar
      integer                         :: mxcnstrlmxtriger      ! leading dimension of cnstrl = 2triger
      integer                         :: mxengparmxcontrl      ! leading dimension of engparcontrl
      integer                         :: mxbranchmxconhis = 5    ! leadleading dimdimension of branchconhis
      integer                         :: nupt           
mxconhis      integer! leading dimension of conhis
      integer               :: msect
      integer   :: mxtrcnrl      ! leading dimension of trcnrl
      integer     :: lcnvmax

      real   , allocatable         :: mxcnstrl  :: strpar (:,:)  ! structureleading parametersdimension of cnstrl = 2
      (mxstrpar,nstru)
integer      real   , allocatable            :: strmu  (:,:)  !mxengpar structure mu    ! dimension of engpar
      integer     (mxstrmu,nstru)
      integer, allocatable            :: istrtyp(:,:) mxbranch ! structure type   ! lead dim of branch
      integer   (mxistrtyp,nstru)
      character(len=40), allocatable  :: contrnam(:)   ! names of controllers      :: nupt   (ncontr)
      character(len=40), allocatable  
  :: trigrnam(:)   !integer names of triggers             (ntrigr)
      character(len=40), allocatable  :: qlatnm(:)msect
      integer     ! ids of qlats                  (nqlat):: lcnvmax

      real   , allocatable            :: qlatstrpar  (:,:)     ! lateralstructure inflowparameters                (nqlat(mxstrpar,nstru)
      real   , allocatable            :: qltparstrmu  (:,:)  ! structure mu         !  lateral inflow parameters     (mxqltparmxstrmu,nqlatnstru)
      integer, allocatable            :: nodeistrtyp(:,:)     ! sobekstructure nodetype administration     (nnode)
      integer, allocatable   (mxistrtyp,nstru)
      character(len=40), allocatable  :: branchcontrnam(:,:)   ! sobeknames branchof admin  controllers          (mxbranch,nbranncontr)
      integercharacter(len=40), allocatable            :: trigertrigrnam(:,:)   ! triggernames dataof triggers                 (mxtriger,ntrigr)
      real   character(len=40), allocatable  :: qlatnm(:)     ! ids of qlats :: contrl(:,:)   ! controller data               (mxcontrl,ncontrnqlat)
      integerreal   , allocatable            :: qlat trcnrl (:,:)   ! trigger controller! relation   (mxtrcnrl,ntcrel)
lateral inflow      integer, allocatable            :: cnstrl(:,:)(nqlat)
   ! controller structure relation (mxcnstrl,ncsrel)
real       integer, allocatable            :: hbdparqltpar(:,:)   ! integerlateral parameters (3,*), 1=?, 2=iopt, 3=itab (3,nhstatinflow parameters     (mxqltpar,nqlat)
      integer, allocatable            :: qbdparnode(:,:)     ! integersobek node parameters (3,*), 1=?, 2=iopt, 3=itab (3,nqstatadministration     (nnode)
      real   integer, allocatable            :: engparbranch(:,:)   ! sobek  ! Engelund-Hansen parametersbranch admin            (mxengparmxbranch,nbran)
      real   integer, allocatable            :: hpacktriger(:,:)   ! trigger data  !   s0 voor sobek points          (ngridmxtriger,ntrigr)
      real   , allocatable            :: qpackcontrl(:,:)   ! controller data ! q  voor sobek points          (ngridmxcontrl,ncontr)
      double precisioninteger, allocatable            :: xycoortrcnrl(:,:)   ! (2,ngrid) x,y coordinates for sobek points (2,ngrid trigger controller relation   (mxtrcnrl,ntcrel)
      integer, allocatable allocatable           :: nlevu   cnstrl(:,:)   ! controller structure relation (mxcnstrl,ncsrel)
      integer, allocatable            :: hbdpar(:,:)   ! integer  parameters (nupt3,*)
, 1=?, 2=iopt, 3=itab (3,nhstat)
  real,    integer, allocatable            :: chan_hu qbdpar(:,:)   ! integer parameters (3,*), 1=?, 2=iopt, 3=itab (3,nqstat)
      real   , allocatable            ::  engpar(ngrid:)
     ! real,Engelund-Hansen parameters    allocatable(mxengpar)
      real   , allocatable :: chan_af (:,:,:)    !     :: hpack(:)      ! s0 voor sobek points          (nupt,lcnvmax,msectngrid)
      real,   , allocatable allocatable           :: chan_wf qpack(:,:,:)      ! q  voor sobek points          (ngrid)
      double precision, allocatable   :: xycoor(:,:)   ! (2,ngrid) x,y coordinates for sobek  points (nupt2,lcnvmax,msectngrid)
      realinteger,     allocatable           :: chan_pfnlevu   (:,:,:)   ! !                              (nupt,lcnvmax,msect)
      real,     allocatable           :: chan_cohu (:,:,:) !    !                           (nupt,lcnvmax,msectngrid)
      real,     allocatable           :: chan_cnaf (:,:,:)    !                          (nupt,lcnvmax,msect)
      real,     allocatable           :: chan_cz1wf (:,:,:)    !                          (nupt,lcnvmax,msect)
      real,     allocatable           :: chan_cz2pf (:,:,:)    !                          (nupt,lcnvmax,msect)
      integerreal,     allocatable            :: nlevh chan_co  (:,:,:)        !                          (nupt,lcnvmax,msect)
      real,     allocatable            :: chan_hhcn (:,:,:)      !                          (ngridnupt,lcnvmax,msect)
      real,     allocatable            :: chan_at cz1(:,:,:)      !                          (ngridnupt,lcnvmax,msect)
      real,     allocatable            :: chan_wt cz2(:,:,:)    !  !                        (nupt,lcnvmax,msect)
  (ngrid,lcnvmax)
    integer, allocatable            :: nlevh   character(len=CharLen ), allocatable, save :: nodenm  (:)        !               !           (nnodenupt,lcnvmax,msect)
      character(len=CharLen )real, allocatable, save :: gridnnmallocatable            :: chan_hh (:,:)  !    !       (ngrid)
   end type Sobek_Data
end module
Code Block

network
   branch
   grid_point (h + u)
      name(ngrid,lcnvmax)
      xreal, y
    allocatable    node
      name
  :: cross_section
chan_at (:,:)      !  location
      A(H), W(H), P(H), Cup(H), Cdown(H)
      type (there are 2 types: free form, wetted-perimeter formula (ngrid,lcnvmax)

   structure
   real,   name
 allocatable     location
      type
 :: chan_wt (:,:)   parameters

   trigger
!      name
      location
      controller

   controller
      name(ngrid,lcnvmax)
      location
      structure
character(len=CharLen ), allocatable, save :: nodenm    
data
   initial
      y(L), Q(L), H(L), t =! 0

   boundary conditions
      name(nnode)
      type character(len= Q(t), H(t), Q(HCharLen ), Ql(L,t)
allocatable, save :: gridnnm          value_type = table or value or time! series

   parameters
      Engelund-Hansen parameters (ngrid)

Q1: What is relation trigger-contoller, contoller-structure

Code Block

  integer, allocatable            :: trcnrl(:,

...

:)   ! trigger controller

...

 relation   (mxtrcnrl,ntcrel)

...


  integer, allocatable            :: cnstrl(:,

...

:)   ! controller structure relation (mxcnstrl,ncsrel)

Q2: Engelund-Hansen parameters - isn't it morphology? is it required for flow

Q3: Give definition of a structure, controller, trigger and give full list of their parameter names.

Q4: Cross-section type currently of two types - describe them

  • free form
  • wetted-perimeter formula