4 #ifndef ERF_LINEAR_INTERP_H_
5 #define ERF_LINEAR_INTERP_H_
7 #include "rrtmgp_const.h"
8 using yakl::fortran::parallel_for;
9 using yakl::fortran::SimpleBounds;
40 static void init (
const real1d& yin,
67 bool increasing =
true;
69 interp_wgts.
jjm = int1d(
"jjm", nout);
70 interp_wgts.
jjp = int1d(
"jjp", nout);
71 interp_wgts.
wgts = real1d(
"wgts", nout);
72 interp_wgts.
wgtn = real1d(
"wgtn", nout);
74 parallel_for(SimpleBounds<1>(n_in-1), YAKL_LAMBDA (
int j)
76 if(yin(j) > yin(j+1)) {
77 printf(
"init: inputs are not monotonic!\n");
85 parallel_for(SimpleBounds<1>(nout), YAKL_LAMBDA (
int j)
87 interp_wgts.
jjm(j) = 0;
88 interp_wgts.
jjp(j) = 0;
91 switch (extrap_method) {
98 parallel_for(SimpleBounds<1>(nout), YAKL_LAMBDA (
int j)
100 if (yout(j) < yin(1)) {
101 interp_wgts.
jjm(j) = 1;
102 interp_wgts.
jjp(j) = 1;
103 interp_wgts.
wgts(j) = 0.;
104 interp_wgts.
wgtn(j) = 0.;
106 else if (yout(j) > yin(n_in)) {
107 interp_wgts.
jjm(j) = n_in;
108 interp_wgts.
jjp(j) = n_in;
109 interp_wgts.
wgts(j) = 0.;
110 interp_wgts.
wgtn(j) = 0.;
115 parallel_for(SimpleBounds<1>(nout), YAKL_LAMBDA (
int j)
117 if (yout(j) > yin(1)) {
118 interp_wgts.
jjm(j) = 1;
119 interp_wgts.
jjp(j) = 1;
120 interp_wgts.
wgts(j) = 0.;
121 interp_wgts.
wgtn(j) = 0.;
123 else if (yout(j) < yin(n_in)) {
124 interp_wgts.
jjm(j) = n_in;
125 interp_wgts.
jjp(j) = n_in;
126 interp_wgts.
wgts(j) = 0.;
127 interp_wgts.
wgtn(j) = 0.;
138 parallel_for(SimpleBounds<1>(nout), YAKL_LAMBDA (
int j)
140 if (yout(j) <= yin(1)) {
141 interp_wgts.
jjm(j) = 1;
142 interp_wgts.
jjp(j) = 1;
143 interp_wgts.
wgts(j) = 1.;
144 interp_wgts.
wgtn(j) = 0.;
146 else if (yout(j) > yin(n_in)) {
147 interp_wgts.
jjm(j) = n_in;
148 interp_wgts.
jjp(j) = n_in;
149 interp_wgts.
wgts(j) = 1.;
150 interp_wgts.
wgtn(j) = 0.;
155 parallel_for(SimpleBounds<1>(nout), YAKL_LAMBDA (
int j)
157 if (yout(j) > yin(1)) {
158 interp_wgts.
jjm(j) = 1;
159 interp_wgts.
jjp(j) = 1;
160 interp_wgts.
wgts(j) = 1.;
161 interp_wgts.
wgtn(j) = 0.;
163 else if (yout(j) <= yin(n_in)) {
164 interp_wgts.
jjm(j) = n_in;
165 interp_wgts.
jjp(j) = n_in;
166 interp_wgts.
wgts(j) = 1.;
167 interp_wgts.
wgtn(j) = 0.;
177 dyinwrap = yin(1) + (cmax-cmin) - yin(n_in);
178 avgdyin = abs(yin(n_in)-yin(1))/(n_in-1.);
179 auto ratio = dyinwrap/avgdyin;
180 if (ratio < 0.9 || ratio > 1.1) {
181 printf(
"ratio is too large, dyinwrap= %13.6e, avgdyin= %13.6e, yin(1) = %13.6e, yin(n_in)= %13.6e\n",
182 dyinwrap, avgdyin, yin(1), yin(n_in));
186 parallel_for(SimpleBounds<1>(nout), YAKL_LAMBDA (
int j)
188 if (yout(j) <= yin(1)) {
189 interp_wgts.
jjm(j) = n_in;
190 interp_wgts.
jjp(j) = 1;
191 interp_wgts.
wgts(j) = (yin(1)-yout(j))/dyinwrap;
192 interp_wgts.
wgtn(j) = (yout(j)+(cmax-cmin) - yin(n_in))/dyinwrap;
194 else if (yout(j) > yin(n_in)) {
195 interp_wgts.
jjm(j) = n_in;
196 interp_wgts.
jjp(j) = 1;
197 interp_wgts.
wgts(j) = (yin(1)+(cmax-cmin)-yout(j))/dyinwrap;
198 interp_wgts.
wgtn(j) = (yout(j)-yin(n_in))/dyinwrap;
203 parallel_for(SimpleBounds<1>(nout), YAKL_LAMBDA (
int j)
205 if (yout(j) > yin(1)) {
206 interp_wgts.
jjm(j) = n_in;
207 interp_wgts.
jjp(j) = 1;
208 interp_wgts.
wgts(j) = (yin(1)-yout(j))/dyinwrap;
209 interp_wgts.
wgtn(j) = (yout(j)+(cmax-cmin) - yin(n_in))/dyinwrap;
211 else if (yout(j) <= yin(n_in)) {
212 interp_wgts.
jjm(j) = n_in;
213 interp_wgts.
jjp(j) = 1;
214 interp_wgts.
wgts(j) = (yin(1)+(cmax-cmin)-yout(j))/dyinwrap;
215 interp_wgts.
wgtn(j) = (yout(j)+(cmax-cmin)-yin(n_in))/dyinwrap;
225 parallel_for(SimpleBounds<2>(nout, n_in-1), YAKL_LAMBDA (
int j,
int jj)
227 if (yout(j) > yin(jj) && yout(j) <= yin(jj+1)) {
228 interp_wgts.
jjm(j) = jj;
229 interp_wgts.
jjp(j) = jj + 1;
230 interp_wgts.
wgts(j) = (yin(jj+1)-yout(j))/(yin(jj+1)-yin(jj));
231 interp_wgts.
wgtn(j) = (yout(j)-yin(jj))/(yin(jj+1)-yin(jj));
237 parallel_for(SimpleBounds<2>(nout, n_in-1), YAKL_LAMBDA (
int j,
int jj)
239 if (yout(j) <= yin(jj) && yout(j) > yin(jj+1)) {
240 interp_wgts.
jjm(j) = jj;
241 interp_wgts.
jjp(j) = jj + 1;
242 interp_wgts.
wgts(j) = (yin(jj+1)-yout(j))/(yin(jj+1)-yin(jj));
243 interp_wgts.
wgtn(j) = (yout(j)-yin(jj))/(yin(jj+1)-yin(jj));
252 parallel_for(SimpleBounds<1>(nout), YAKL_LAMBDA (
int j)
255 amrex::ignore_unused(count);
256 if (interp_wgts.
jjm(j) == 0 || interp_wgts.
jjp(j) == 0) count += 1;
257 auto frac = interp_wgts.
wgts(j) + interp_wgts.
wgtn(j);
258 if ((frac < 0.9 || frac > 1.1) && extrap_method != 0)
259 printf(
"interpolation error!\n");
270 const real1d& arrout,
277 parallel_for(SimpleBounds<1>(m1), YAKL_LAMBDA (
int j)
279 arrout(j) = arrin(interp_wgts.
jjm(j))*interp_wgts.
wgts(j) +
280 arrin(interp_wgts.
jjp(j))*interp_wgts.
wgtn(j);
288 const real2d& arrout,
295 real2d arrtmp(
"arrtmp",n1,m2);
297 parallel_for(SimpleBounds<2>(n1, m2), YAKL_LAMBDA (
int i,
int j)
299 arrtmp(i,j) = arrin(i,wgt2.
jjm(j))*wgt2.
wgts(j) + arrin(i,wgt2.
jjp(j))*wgt2.
wgtn(j);
302 parallel_for(SimpleBounds<2>(n1, m2), YAKL_LAMBDA (
int i,
int j)
304 arrout(i,j) = arrtmp(wgt1.
jjm(i),j)*wgt1.
wgts(i) + arrtmp(wgt1.
jjp(i),j)*wgt1.
wgtn(i);
312 const real1d& arrout,
317 parallel_for(SimpleBounds<1>(m1), YAKL_LAMBDA (
int i)
329 const real2d& arrout,
335 parallel_for(SimpleBounds<2>(m1, n3), YAKL_LAMBDA (
int i,
int k)
Definition: ERF_LinearInterpolate.H:12
static YAKL_INLINE void init(const real1d &yin, const int &n_in, const real1d &yout, const int &nout, const InterpMethod &extrap_method, InterpType &interp_wgts, real cyclicmin=0., real cyclicmax=0.)
Definition: ERF_LinearInterpolate.H:40
InterpMethod
Definition: ERF_LinearInterpolate.H:14
@ extrap_method_zero
Definition: ERF_LinearInterpolate.H:15
@ extrap_method_bndry
Definition: ERF_LinearInterpolate.H:16
@ extrap_method_cycle
Definition: ERF_LinearInterpolate.H:17
static YAKL_INLINE void interp3d2d(const real3d &arrin, const int &n1, const int &n2, const int &n3, const real2d &arrout, const int &m1, const int &len1, const InterpType &wgt1, const InterpType &wgt2)
Definition: ERF_LinearInterpolate.H:325
static YAKL_INLINE void interp2d2d(const real2d &arrin, const int &n1, const int &n2, const real2d &arrout, const int &m1, const int &m2, const InterpType &wgt1, const InterpType &wgt2)
Definition: ERF_LinearInterpolate.H:285
static YAKL_INLINE void interp1d(const real1d &arrin, const int &n1, const real1d &arrout, const int &m1, const InterpType &interp_wgts)
Definition: ERF_LinearInterpolate.H:268
static YAKL_INLINE void interp2d1d(const real2d &arrin, const int &n1, const int &n2, const real1d &arrout, const int &m1, const InterpType &wgt1, const InterpType &wgt2)
Definition: ERF_LinearInterpolate.H:309
Definition: ERF_LinearInterpolate.H:20
real1d wgts
Definition: ERF_LinearInterpolate.H:21
int1d jjp
Definition: ERF_LinearInterpolate.H:24
real1d wgtn
Definition: ERF_LinearInterpolate.H:22
int1d jjm
Definition: ERF_LinearInterpolate.H:23