Skip to content

Commit 18c20c3

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
1 parent ba32233 commit 18c20c3

3 files changed

Lines changed: 92 additions & 90 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

‎src/formal/time_integration_m.F90‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
module time_integration_m
2+
implicit none
3+
4+
#ifndef HAVE_TEMPLATE_SUPPORT
5+
logical prevent_empty_module
6+
#else
7+
8+
private
9+
public :: runge_kutta_4th_order_t
10+
public :: binary_operator_r
11+
12+
requirement binary_operator_r(T, U, V, op)
13+
14+
#if defined(__LFORTRAN__) && (__lfortran_major__ < 1) && (__lfortran_minor__ < 1) && (__lfortran_patch_level__ < 1)
15+
type, deferred :: T
16+
type, deferred :: U
17+
type, deferred :: V
18+
19+
interface
20+
#else
21+
deferred type :: T, U, V
22+
23+
deferred interface
24+
#endif
25+
pure function op(x,y) result(z)
26+
type(T), intent(in) :: x
27+
type(U), intent(in) :: y
28+
type(V) :: z
29+
end function
30+
end interface
31+
32+
end requirement
33+
34+
#if defined(__LFORTRAN__) && (__lfortran_major__ < 1) && (__lfortran_minor__ < 1) && (__lfortran_patch_level__ < 1)
35+
template runge_kutta_4th_order_t( &
36+
TFA, TFB, TFC, TFD, R & ! types
37+
,tmult, rtmult, taplus, tcplus, rhs, rdiv & ! functions
38+
)
39+
type, deferred :: TFA
40+
type, deferred :: TFB
41+
type, deferred :: TFC
42+
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
51+
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)
58+
59+
interface operator(+)
60+
module procedure taplus, tcplus
61+
end interface
62+
63+
interface operator(*)
64+
module procedure rtmult, tmult
65+
end interface
66+
67+
interface operator(/)
68+
module procedure rdiv
69+
end interface
70+
71+
contains
72+
73+
pure function step(s, v, dt) result(s_next)
74+
type(TFA), intent(in) :: s
75+
type(TFD), intent(in) :: v
76+
type(R) , intent(in) :: dt
77+
type(TFA) s_next
78+
79+
associate(k1 => rhs(s, v))
80+
associate(k2 => rhs(s + k1*(dt/2), v))
81+
associate(k3 => rhs(s + k2*(dt/2), v))
82+
associate(k4 => rhs(s + k3* dt, v))
83+
s_next = s + (k1 + 2*k2 + 2*k3 + k4) * (dt/6)
84+
end associate; end associate; end associate; end associate
85+
end function
86+
87+
end template
88+
89+
#endif
90+
91+
end module

‎src/formal/time_integration_t.F90‎

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)