VerticalGridAspect.F90 Source File


This file depends on

sourcefile~~verticalgridaspect.f90~~EfferentGraph sourcefile~verticalgridaspect.f90 VerticalGridAspect.F90 sourcefile~componentdriver.f90 ComponentDriver.F90 sourcefile~verticalgridaspect.f90->sourcefile~componentdriver.f90 sourcefile~errorhandling.f90 ErrorHandling.F90 sourcefile~verticalgridaspect.f90->sourcefile~errorhandling.f90 sourcefile~extensionaction.f90 ExtensionAction.F90 sourcefile~verticalgridaspect.f90->sourcefile~extensionaction.f90 sourcefile~nullaction.f90 NullAction.F90 sourcefile~verticalgridaspect.f90->sourcefile~nullaction.f90 sourcefile~stateitemaspect.f90 StateItemAspect.F90 sourcefile~verticalgridaspect.f90->sourcefile~stateitemaspect.f90 sourcefile~verticaldimspec.f90 VerticalDimSpec.F90 sourcefile~verticalgridaspect.f90->sourcefile~verticaldimspec.f90 sourcefile~verticalgrid.f90 VerticalGrid.F90 sourcefile~verticalgridaspect.f90->sourcefile~verticalgrid.f90 sourcefile~verticalregridaction.f90 VerticalRegridAction.F90 sourcefile~verticalgridaspect.f90->sourcefile~verticalregridaction.f90 sourcefile~verticalregridmethod.f90 VerticalRegridMethod.F90 sourcefile~verticalgridaspect.f90->sourcefile~verticalregridmethod.f90 sourcefile~componentdriver.f90->sourcefile~errorhandling.f90 sourcefile~maplshared.f90 MaplShared.F90 sourcefile~componentdriver.f90->sourcefile~maplshared.f90 sourcefile~multistate.f90 MultiState.F90 sourcefile~componentdriver.f90->sourcefile~multistate.f90 sourcefile~mapl_throw.f90 MAPL_Throw.F90 sourcefile~errorhandling.f90->sourcefile~mapl_throw.f90 sourcefile~extensionaction.f90->sourcefile~errorhandling.f90 sourcefile~nullaction.f90->sourcefile~errorhandling.f90 sourcefile~nullaction.f90->sourcefile~extensionaction.f90 sourcefile~stateitemaspect.f90->sourcefile~errorhandling.f90 sourcefile~verticaldimspec.f90->sourcefile~errorhandling.f90 sourcefile~mapl_esmf_infokeys.f90 MAPL_ESMF_InfoKeys.F90 sourcefile~verticaldimspec.f90->sourcefile~mapl_esmf_infokeys.f90 sourcefile~verticalgrid.f90->sourcefile~errorhandling.f90 sourcefile~verticalregridaction.f90->sourcefile~componentdriver.f90 sourcefile~verticalregridaction.f90->sourcefile~errorhandling.f90 sourcefile~verticalregridaction.f90->sourcefile~extensionaction.f90 sourcefile~verticalregridaction.f90->sourcefile~verticalregridmethod.f90 sourcefile~couplerphases.f90 CouplerPhases.F90 sourcefile~verticalregridaction.f90->sourcefile~couplerphases.f90 sourcefile~csr_sparsematrix.f90 CSR_SparseMatrix.F90 sourcefile~verticalregridaction.f90->sourcefile~csr_sparsematrix.f90 sourcefile~fieldcondensedarray.f90 FieldCondensedArray.F90 sourcefile~verticalregridaction.f90->sourcefile~fieldcondensedarray.f90 sourcefile~verticallinearmap.f90 VerticalLinearMap.F90 sourcefile~verticalregridaction.f90->sourcefile~verticallinearmap.f90

Files dependent on this one

sourcefile~~verticalgridaspect.f90~~AfferentGraph sourcefile~verticalgridaspect.f90 VerticalGridAspect.F90 sourcefile~aspectcollection.f90 AspectCollection.F90 sourcefile~aspectcollection.f90->sourcefile~verticalgridaspect.f90 sourcefile~fieldspec.f90 FieldSpec.F90 sourcefile~fieldspec.f90->sourcefile~verticalgridaspect.f90 sourcefile~fieldspec.f90->sourcefile~aspectcollection.f90 sourcefile~variablespec.f90 VariableSpec.F90 sourcefile~fieldspec.f90->sourcefile~variablespec.f90 sourcefile~variablespec.f90->sourcefile~verticalgridaspect.f90 sourcefile~variablespec.f90->sourcefile~aspectcollection.f90 sourcefile~bracketspec.f90 BracketSpec.F90 sourcefile~bracketspec.f90->sourcefile~fieldspec.f90 sourcefile~componentspec.f90 ComponentSpec.F90 sourcefile~componentspec.f90->sourcefile~variablespec.f90 sourcefile~componentspecparser.f90 ComponentSpecParser.F90 sourcefile~componentspecparser.f90->sourcefile~variablespec.f90 sourcefile~historycollectiongridcomp_private.f90 HistoryCollectionGridComp_private.F90 sourcefile~historycollectiongridcomp_private.f90->sourcefile~variablespec.f90 sourcefile~initialize_advertise.f90 initialize_advertise.F90 sourcefile~initialize_advertise.f90->sourcefile~variablespec.f90 sourcefile~make_itemspec.f90 make_itemSpec.F90 sourcefile~make_itemspec.f90->sourcefile~fieldspec.f90 sourcefile~make_itemspec.f90->sourcefile~variablespec.f90 sourcefile~mapl_generic.f90~2 MAPL_Generic.F90 sourcefile~mapl_generic.f90~2->sourcefile~variablespec.f90 sourcefile~mockitemspec.f90 MockItemSpec.F90 sourcefile~mockitemspec.f90->sourcefile~aspectcollection.f90 sourcefile~mockitemspec.f90->sourcefile~variablespec.f90 sourcefile~modelverticalgrid.f90 ModelVerticalGrid.F90 sourcefile~modelverticalgrid.f90->sourcefile~fieldspec.f90 sourcefile~servicespec.f90 ServiceSpec.F90 sourcefile~servicespec.f90->sourcefile~variablespec.f90 sourcefile~stateitemspec.f90 StateItemSpec.F90 sourcefile~stateitemspec.f90->sourcefile~aspectcollection.f90 sourcefile~statespec.f90 StateSpec.F90 sourcefile~statespec.f90->sourcefile~variablespec.f90 sourcefile~test_addfieldspec.pf Test_AddFieldSpec.pf sourcefile~test_addfieldspec.pf->sourcefile~fieldspec.f90 sourcefile~test_bracketspec.pf Test_BracketSpec.pf sourcefile~test_bracketspec.pf->sourcefile~fieldspec.f90 sourcefile~test_fieldspec.pf Test_FieldSpec.pf sourcefile~test_fieldspec.pf->sourcefile~aspectcollection.f90 sourcefile~test_fieldspec.pf->sourcefile~fieldspec.f90 sourcefile~test_modelverticalgrid.pf Test_ModelVerticalGrid.pf sourcefile~test_modelverticalgrid.pf->sourcefile~variablespec.f90 sourcefile~variablespecvector.f90 VariableSpecVector.F90 sourcefile~variablespecvector.f90->sourcefile~variablespec.f90 sourcefile~wildcardspec.f90 WildcardSpec.F90 sourcefile~wildcardspec.f90->sourcefile~aspectcollection.f90

Source Code

#include "MAPL_Generic.h"

module mapl3g_VerticalGridAspect
   use mapl3g_StateItemAspect
   use mapl3g_ExtensionAction
   use mapl3g_VerticalGrid
   use mapl3g_NullAction
   use mapl3g_VerticalRegridAction
   use mapl3g_VerticalRegridMethod
   use mapl3g_VerticalDimSpec
   use mapl3g_VerticalRegridMethod
   use mapl3g_ComponentDriver
   use mapl_ErrorHandling
   use ESMF
   implicit none
   private

   public :: VerticalGridAspect


   type, extends(StateItemAspect) :: VerticalGridAspect
!#      private
      class(VerticalGrid), allocatable :: vertical_grid
      type(VerticalRegridMethod) :: regrid_method = VERTICAL_REGRID_LINEAR
!#      type(VerticalStaggerLoc), allocatable :: vertical_staggerloc
      type(VerticalDimSpec), allocatable :: vertical_dim_spec

      ! These might be updated due to intervening couplers
      type(ESMF_Geom), allocatable :: geom
      type(ESMF_Typekind_Flag) :: typekind
   contains
      procedure :: matches
      procedure :: supports_conversion_general
      procedure :: supports_conversion_specific
      procedure :: make_action
      procedure :: typesafe_make_action

      procedure :: set_vertical_grid
      procedure :: set_geom
      procedure :: set_typekind
   end type VerticalGridAspect

   interface VerticalGridAspect
      procedure new_VerticalGridAspect_specific
   end interface

contains

   function new_VerticalGridAspect_specific(vertical_grid, regrid_method, vertical_dim_spec, geom, typekind, time_dependent) result(aspect)
      type(VerticalGridAspect) :: aspect
      class(VerticalGrid), optional, intent(in) :: vertical_grid
      type(VerticalRegridMethod), optional, intent(in) :: regrid_method
      type(VerticalDimSpec), optional, intent(in) :: vertical_dim_spec
      type(ESMF_Geom), optional, intent(in) :: geom
      type(ESMF_Typekind_Flag), optional, intent(in) :: typekind
      logical, optional, intent(in) :: time_dependent

      call aspect%set_mirror(.true.)
      if (present(vertical_grid)) then
         aspect%vertical_grid = vertical_grid
         call aspect%set_mirror(.false.)
      end if

      if (present(regrid_method)) then
         aspect%regrid_method = regrid_method
      end if

      if (present(vertical_dim_spec)) then
         aspect%vertical_dim_spec = vertical_dim_spec
      end if
    
      if (present(geom)) then
         aspect%geom = geom
      end if

      if (present(typekind)) then
         aspect%typekind = typekind
      end if

      call aspect%set_time_dependent(time_dependent)

   end function new_VerticalGridAspect_specific

   function new_VerticalGridAspect_mirror() result(aspect)
      type(VerticalGridAspect) :: aspect

      call aspect%set_mirror(.true.)

   end function new_VerticalGridAspect_mirror

   logical function supports_conversion_general(src)
      class(VerticalGridAspect), intent(in) :: src
      supports_conversion_general = .true.
   end function supports_conversion_general

   logical function supports_conversion_specific(src, dst)
      class(VerticalGridAspect), intent(in) :: src
      class(StateItemAspect), intent(in) :: dst

      integer :: status
      
      supports_conversion_specific = .false.

      select type (dst)
      class is (VerticalGridAspect)
         ! Note: "grid%can_connect_to()" reverses dst and src.   Something that should be fixed.
         supports_conversion_specific = src%vertical_grid%can_connect_to(dst%vertical_grid)
      end select

   end function supports_conversion_specific

   logical function matches(src, dst)
      class(VerticalGridAspect), intent(in) :: src
      class(StateItemAspect), intent(in) :: dst

      select type(dst)
      class is (VerticalGridAspect)
         matches = dst%vertical_grid%is_identical_to(src%vertical_grid)
      class default
         matches = .false.
      end select

   end function matches

   function make_action(src, dst, rc) result(action)
      class(ExtensionAction), allocatable :: action
      class(VerticalGridAspect), intent(in) :: src
      class(StateItemAspect), intent(in)  :: dst
      integer, optional, intent(out) :: rc

      select type (dst)
      class is (VerticalGridAspect)
         action = src%typesafe_make_action(dst, rc)
      class default
         action = NullAction()
         _FAIL('dst is not a VerticalGridAspect')
      end select

      _RETURN(_SUCCESS)
   end function make_action

   function typesafe_make_action(src, dst, rc) result(action)
      class(ExtensionAction), allocatable :: action
      class(VerticalGridAspect), intent(in) :: src
      class(VerticalGridAspect), intent(in)  :: dst
      integer, optional, intent(out) :: rc

      class(ComponentDriver), pointer :: v_in_coupler
      class(ComponentDriver), pointer :: v_out_coupler
      type(ESMF_Field) :: v_in_field, v_out_field

      type(ESMF_Geom) :: geom
      type(ESMF_TypeKind_Flag) :: typekind
      character(:), allocatable :: units
      integer :: status

      geom = src%geom
      typekind = src%typekind
      units = src%vertical_grid%get_units()

!#      call src%vertical_grid%get_coordinate_field(v_in_field, v_in_coupler, geom, typekind, src%vertical_staggerloc, _RC)
!#      call dst%vertical_grid%get_coordinate_field(v_out_field, v_out_coupler, geom, typekind, dst%vertical_staggerloc, _RC)

      call src%vertical_grid%get_coordinate_field(v_in_field, v_in_coupler, 'ignore', geom, typekind, units, src%vertical_dim_spec, _RC)
      call dst%vertical_grid%get_coordinate_field(v_out_field, v_out_coupler, 'ignore', geom, typekind, units, dst%vertical_dim_spec, _RC)

      action = VerticalRegridAction(v_in_field, v_in_coupler, v_out_field, v_out_coupler, dst%regrid_method)

      _RETURN(_SUCCESS)
   end function typesafe_make_action

   subroutine set_vertical_grid(self, vertical_grid)
      class(VerticalGridAspect), intent(inout) :: self
      class(VerticalGrid), intent(in) :: vertical_grid

      self%vertical_grid = vertical_grid
      call self%set_mirror(.false.)
   end subroutine set_vertical_grid

   subroutine set_geom(self, geom)
      class(VerticalGridAspect), intent(inout) :: self
      type(ESMF_Geom), intent(in) :: geom

      self%geom = geom
   end subroutine set_geom

   subroutine set_typekind(self, typekind)
      class(VerticalGridAspect), intent(inout) :: self
      type(ESMF_Typekind_Flag), intent(in) :: typekind

      self%typekind = typekind
   end subroutine set_typekind

end module mapl3g_VerticalGridAspect