forked from ESCOMP/CAM-SIMA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0003-Declare-constants-at-the-native-precision-of-MPAS.patch
94 lines (83 loc) · 4.82 KB
/
0003-Declare-constants-at-the-native-precision-of-MPAS.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kuan-Chih Wang <kuanchihw@ucar.edu>
Date: Wed, 13 Nov 2024 17:19:10 -0700
Subject: [PATCH] Declare constants at the native precision of MPAS
When building MPAS as a dycore, certain constants in the `mpas_constants` module are
imported from the `physconst` module, which is a part of CAM/CAM-SIMA. However,
multiple issues arise if the precision of those constants differs from MPAS.
For example, building MPAS in single precision mode with CAM-SIMA fails due to
multiple occurrences of type mismatch between actual and dummy arguments.
mpas_geometry_utils.F:885:157:
885 | call mpas_log_write('$r', MPAS_LOG_ERR, realArgs=(/mpas_triangle_signed_area_sphere(a,b,c,sphereRadius) - pii/2.0_RKIND*sphereRadius*sphereRadius/))
| 1
Error: Type mismatch in argument 'realargs' at (1); passed REAL(8) to REAL(4)
Here, `pii` is declared by CAM-SIMA to be double precision, and it causes unintended
floating-point promotion in the expression.
The solution is to ensure that constants in the `mpas_constants` module are declared
at the native precision of MPAS.
This downstream patch is maintained by CAM-SIMA for its particular use case of MPAS.
---
src/framework/mpas_constants.F | 44 ++++++++++++++++++++++++++--------
1 file changed, 34 insertions(+), 10 deletions(-)
diff --git a/src/framework/mpas_constants.F b/src/framework/mpas_constants.F
index c98cb810..68164bab 100644
--- a/src/framework/mpas_constants.F
+++ b/src/framework/mpas_constants.F
@@ -23,16 +23,30 @@ module mpas_constants
use mpas_kind_types
#ifdef MPAS_CAM_DYCORE
- use physconst, only : pii => pi
- use physconst, only : gravity => gravit
- use physconst, only : omega
- use physconst, only : a => rearth
- use physconst, only : cp => cpair
- use physconst, only : rgas => rair
- use physconst, only : rv => rh2o
- real (kind=RKIND) :: rvord = huge(1.0_RKIND) ! Derived in mpas_constants_compute_derived
- real (kind=RKIND) :: cv = huge(1.0_RKIND) ! Derived in mpas_constants_compute_derived
- real (kind=RKIND) :: cvpm = huge(1.0_RKIND) ! Derived in mpas_constants_compute_derived
+ use physconst, only: external_pii => pi
+ use physconst, only: external_a => rearth
+ use physconst, only: external_omega => omega
+ use physconst, only: external_gravity => gravit
+ use physconst, only: external_rgas => rair
+ use physconst, only: external_rv => rh2o
+ use physconst, only: external_cp => cpair
+ private :: external_pii
+ private :: external_a
+ private :: external_omega
+ private :: external_gravity
+ private :: external_rgas
+ private :: external_rv
+ private :: external_cp
+ real (kind=RKIND), protected :: pii = huge(1.0_RKIND) ! Derived in mpas_constants_compute_derived
+ real (kind=RKIND), protected :: a = huge(1.0_RKIND) ! Derived in mpas_constants_compute_derived
+ real (kind=RKIND), protected :: omega = huge(1.0_RKIND) ! Derived in mpas_constants_compute_derived
+ real (kind=RKIND), protected :: gravity = huge(1.0_RKIND) ! Derived in mpas_constants_compute_derived
+ real (kind=RKIND), protected :: rgas = huge(1.0_RKIND) ! Derived in mpas_constants_compute_derived
+ real (kind=RKIND), protected :: rv = huge(1.0_RKIND) ! Derived in mpas_constants_compute_derived
+ real (kind=RKIND), protected :: cp = huge(1.0_RKIND) ! Derived in mpas_constants_compute_derived
+ real (kind=RKIND), protected :: rvord = huge(1.0_RKIND) ! Derived in mpas_constants_compute_derived
+ real (kind=RKIND), protected :: cv = huge(1.0_RKIND) ! Derived in mpas_constants_compute_derived
+ real (kind=RKIND), protected :: cvpm = huge(1.0_RKIND) ! Derived in mpas_constants_compute_derived
#else
real (kind=RKIND), parameter :: pii = 3.141592653589793_RKIND !< Constant: Pi
real (kind=RKIND), parameter :: a = 6371229.0_RKIND !< Constant: Spherical Earth radius [m]
@@ -77,6 +91,16 @@ module mpas_constants
implicit none
#ifdef MPAS_CAM_DYCORE
+ ! Convert external constants to the native precision of MPAS (i.e., `RKIND`).
+
+ pii = real(external_pii, RKIND)
+ a = real(external_a, RKIND)
+ omega = real(external_omega, RKIND)
+ gravity = real(external_gravity, RKIND)
+ rgas = real(external_rgas, RKIND)
+ rv = real(external_rv, RKIND)
+ cp = real(external_cp, RKIND)
+
!
! In the case of CAM-MPAS, rgas may depend on a CAM namelist option,
! so physical constants that depend on rgas must be computed here after
--
2.43.0