Skip to content

Commit

Permalink
add Fortran API for MDPI initial functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrdar committed Nov 21, 2023
1 parent 99207ce commit ba80220
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/atlas/util/function/MDPI_functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ double MDPI_gulfstream(double lon, double lat) {
return background_func + dc * (std::max(1000. * std::sin(0.4 * (0.5 * dr + dth) + 0.007 * std::cos(50. * dth) + 0.37 * M_PI), 999.) - 999.);
}

extern "C" {
double atlas__function__MDPI_sinusoid(double lon, double lat) {
MDPI_sinusoid(lon, lat);
}
double atlas__function__MDPI_harmonic(double lon, double lat) {
MDPI_harmonic(lon, lat);
}
double atlas__function__MDPI_vortex(double lon, double lat) {
MDPI_vortex(lon, lat);
}
double atlas__function__MDPI_gulfstream(double lon, double lat) {
MDPI_gulfstream(lon, lat);
}
}

} // namespace function
} // namespace util
} // namespace atlas
7 changes: 7 additions & 0 deletions src/atlas/util/function/MDPI_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ double MDPI_harmonic(double lon, double lat);
double MDPI_vortex(double lon, double lat);
double MDPI_gulfstream(double lon, double lat);

extern "C" {
double atlas__function__MDPI_sinusoid(double lon, double lat);
double atlas__function__MDPI_harmonic(double lon, double lat);
double atlas__function__MDPI_vortex(double lon, double lat);
double atlas__function__MDPI_gulfstream(double lon, double lat);
}

} // namespace function

} // namespace util
Expand Down
4 changes: 4 additions & 0 deletions src/atlas_f/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ generate_fortran_bindings(FORTRAN_BINDINGS ../atlas/functionspace/detail/PointCl
generate_fortran_bindings(FORTRAN_BINDINGS ../atlas/redistribution/detail/RedistributionInterface.h
MODULE atlas_redistribution_c_binding
OUTPUT redistribution_c_binding.f90)
generate_fortran_bindings(FORTRAN_BINDINGS ../atlas/util/function/MDPI_functions.h
MODULE atlas_function_c_binding
OUTPUT function_c_binding.f90)

if( atlas_HAVE_ATLAS_NUMERICS )
generate_fortran_bindings(FORTRAN_BINDINGS ../atlas/numerics/Nabla.h)
Expand Down Expand Up @@ -205,6 +208,7 @@ ecbuild_add_library( TARGET atlas_f
SOURCES
${FORTRAN_BINDINGS}
atlas_module.F90
util/atlas_function_module.F90
util/atlas_kinds_module.F90
util/atlas_JSON_module.F90
util/atlas_Config_module.F90
Expand Down
112 changes: 112 additions & 0 deletions src/atlas_f/util/atlas_function_module.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
! (C) Copyright 2013 ECMWF.
!
! This software is licensed under the terms of the Apache Licence Version 2.0
! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
! In applying this licence, ECMWF does not waive the privileges and immunities
! granted to it by virtue of its status as an intergovernmental organisation nor
! does it submit to any jurisdiction.

#include "atlas/atlas_f.h"

module atlas_function_module

use, intrinsic :: iso_c_binding
use fckit_owned_object_module, only : fckit_owned_object

implicit none

private :: fckit_owned_object

public :: atlas_function

private

!------------------------------------------------------------------------------
TYPE, extends(fckit_owned_object) :: atlas_function

! Purpose :
! -------
! *function* : Analytic functions for idealised initial data

! Methods :
! -------

! Author :
! ------
! Nov 2023 Slavko Brdar (ECMWF)

!------------------------------------------------------------------------------
contains
procedure, public :: MDPI_sinusoid => atlas_function__MDPI_sinusoid
procedure, public :: MDPI_harmonic => atlas_function__MDPI_harmonic
procedure, public :: MDPI_vortex => atlas_function__MDPI_vortex
procedure, public :: MDPI_gulfstream => atlas_function__MDPI_gulfstream
#if FCKIT_FINAL_NOT_INHERITING
final :: atlas_function__final_auto
#endif

END TYPE atlas_function

!------------------------------------------------------------------------------

!========================================================
contains
!========================================================


! -----------------------------------------------------------------------------

function atlas_function__MDPI_sinusoid(this, lon, lat) result(val)
use atlas_function_c_binding
class(atlas_function), intent(in) :: this
real(c_double), intent(in) :: lon, lat
real(c_double) :: val
val = atlas__function__MDPI_sinusoid(lon, lat)
end function atlas_function__MDPI_sinusoid

! -----------------------------------------------------------------------------

function atlas_function__MDPI_harmonic(this, lon, lat) result(val)
use atlas_function_c_binding
class(atlas_function), intent(in) :: this
real(c_double), intent(in) :: lon, lat
real(c_double) :: val
val = atlas__function__MDPI_harmonic(lon, lat)
end function atlas_function__MDPI_harmonic

! -----------------------------------------------------------------------------

function atlas_function__MDPI_vortex(this, lon, lat) result(val)
use atlas_function_c_binding
class(atlas_function), intent(in) :: this
real(c_double), intent(in) :: lon, lat
real(c_double) :: val
val = atlas__function__MDPI_vortex(lon, lat)
end function atlas_function__MDPI_vortex

! -----------------------------------------------------------------------------

function atlas_function__MDPI_gulfstream(this, lon, lat) result(val)
use atlas_function_c_binding
class(atlas_function), intent(in) :: this
real(c_double), intent(in) :: lon, lat
real(c_double) :: val
val = atlas__function__MDPI_gulfstream(lon, lat)
end function atlas_function__MDPI_gulfstream

!-------------------------------------------------------------------------------

#if FCKIT_FINAL_NOT_INHERITING
ATLAS_FINAL subroutine atlas_function__final_auto(this)
type(atlas_function), intent(inout) :: this
#if FCKIT_FINAL_DEBUGGING
write(0,*) "atlas_function__final_auto"
#endif
#if FCKIT_FINAL_NOT_PROPAGATING
call this%final()
#endif
FCKIT_SUPPRESS_UNUSED( this )
end subroutine
#endif

end module atlas_function_module

0 comments on commit ba80220

Please sign in to comment.