Skip to content

Commit 346e7a3

Browse files
committed
chore(time_integration): lfortran workarounds
With LFortran version < 0.67.0, work around compiler issues: * Issue 13202: replace `deferred type` with `type deferred` * Issue 13231: replace `deferred interface` with `interface` * Issue 13239: replace `{}` with `()` in template statement Set HAVE_TEMPLATE_SUPPORT 1 for LFortran.
1 parent ba32233 commit 346e7a3

2 files changed

Lines changed: 31 additions & 29 deletions

File tree

‎include/formal-language-support.F90‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#ifndef HAVE_TEMPLATE_SUPPORT
2727
# if defined(__LFORTRAN__)
28-
# define HAVE_TEMPLATE_SUPPORT 0
28+
# define HAVE_TEMPLATE_SUPPORT 1
2929
# else
3030
# define HAVE_TEMPLATE_SUPPORT 0
3131
# endif
Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,24 @@ module time_integration_m
55
logical prevent_empty_module
66
#else
77

8-
requirement unary_op_r(op, T, U)
8+
private
9+
public :: runge_kutta_4th_order_t
10+
public :: binary_operator_r
911

10-
type, deferred :: T
11-
type, deferred :: U
12-
13-
!deferred interface
14-
interface
15-
function op(x) result(y)
16-
type(T), intent(in) :: x
17-
type(U) :: y
18-
end function
19-
end interface
20-
21-
end requirement
22-
23-
requirement binary_op_r(op, T, U, V)
12+
requirement binary_operator_r(T, U, V, op)
2413

14+
#if defined(__LFORTRAN__) && (__lfortran_major__ < 1) && (__lfortran_minor__ < 67)
2515
type, deferred :: T
2616
type, deferred :: U
2717
type, deferred :: V
2818

29-
!deferred interface
3019
interface
31-
function op(x,y) result(z)
20+
#else
21+
deferred type :: T, U, V
22+
23+
deferred interface
24+
#endif
25+
pure function op(x,y) result(z)
3226
type(T), intent(in) :: x
3327
type(U), intent(in) :: y
3428
type(V) :: z
@@ -37,21 +31,30 @@ function op(x,y) result(z)
3731

3832
end requirement
3933

40-
template runge_kutta_4th_order_t( &
41-
TFA, TFB, TFC, TFD & ! types
42-
,tmult, rtmult, taplus, tcplus, rhs & ! functions
43-
)
34+
#if defined(__LFORTRAN__) && (__lfortran_major__ < 1) && (__lfortran_minor__ < 67)
35+
template runge_kutta_4th_order_t( &
36+
TFA, TFB, TFC, TFD, R & ! types
37+
,tmult, rtmult, taplus, tcplus, rhs, rdiv & ! functions
38+
)
4439
type, deferred :: TFA
4540
type, deferred :: TFB
4641
type, deferred :: TFC
4742
type, deferred :: TFD
43+
type, deferred :: R
44+
#else
45+
template runge_kutta_4th_order_t{ &
46+
TFA, TFB, TFC, TFD, R & ! types
47+
,tmult, rtmult, taplus, tcplus, rhs, rdiv & ! functions
48+
}
49+
deferred type :: TFA, TFB, TFC, TFD, R
50+
#endif
4851

49-
require :: binary_op_r(integer, TFC, TFC, tmult) ! report lfortran bug on intrinsic types
50-
require :: binary_op_r( TFC, R, TFB, rtmult)
51-
require :: binary_op_r( TFA, TFB, TFA, taplus)
52-
require :: binary_op_r( TFC, TFC, TFC, tcplus)
53-
require :: binary_op_r( TFA, TFD, TFC, rhs)
54-
require :: binary_op_r( R, integer, R, rdiv)
52+
require :: binary_operator_r(integer, TFC, TFC, tmult)
53+
require :: binary_operator_r( TFC, R, TFB, rtmult)
54+
require :: binary_operator_r( TFA, TFB, TFA, taplus)
55+
require :: binary_operator_r( TFC, TFC, TFC, tcplus)
56+
require :: binary_operator_r( TFA, TFD, TFC, rhs)
57+
require :: binary_operator_r( R, integer, R, rdiv)
5558

5659
interface operator(+)
5760
module procedure taplus, tcplus
@@ -78,7 +81,6 @@ pure function step(s, v, dt) result(s_next)
7881
associate(k3 => rhs(s + k2*(dt/2), v))
7982
associate(k4 => rhs(s + k3* dt, v))
8083
s_next = s + (k1 + 2*k2 + 2*k3 + k4) * (dt/6)
81-
!s_next = s + k1*(dt/6) + k2*(dt/3) + k3*(dt/3) + k4*(dt/6)
8284
end associate; end associate; end associate; end associate
8385
end function
8486

0 commit comments

Comments
 (0)