source: CIVL/examples/omp/HydroC/riemann.c@ 1aaefd4

main test-branch
Last change on this file since 1aaefd4 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 8.5 KB
Line 
1/*
2 A simple 2D hydro code
3 (C) Romain Teyssier : CEA/IRFU -- original F90 code
4 (C) Pierre-Francois Lavallee : IDRIS -- original F90 code
5 (C) Guillaume Colin de Verdiere : CEA/DAM -- for the C version
6*/
7
8/*
9
10 This software is governed by the CeCILL license under French law and
11 abiding by the rules of distribution of free software. You can use,
12 modify and/ or redistribute the software under the terms of the CeCILL
13 license as circulated by CEA, CNRS and INRIA at the following URL
14 "http://www.cecill.info".
15
16 As a counterpart to the access to the source code and rights to copy,
17 modify and redistribute granted by the license, users are provided only
18 with a limited warranty and the software's author, the holder of the
19 economic rights, and the successive licensors have only limited
20 liability.
21
22 In this respect, the user's attention is drawn to the risks associated
23 with loading, using, modifying and/or developing or reproducing the
24 software by the user in light of its specific status of free software,
25 that may mean that it is complicated to manipulate, and that also
26 therefore means that it is reserved for developers and experienced
27 professionals having in-depth computer knowledge. Users are therefore
28 encouraged to load and test the software's suitability as regards their
29 requirements in conditions enabling the security of their systems and/or
30 data to be ensured and, more generally, to use and operate it in the
31 same conditions as regards security.
32
33 The fact that you are presently reading this means that you have had
34 knowledge of the CeCILL license and that you accept its terms.
35
36*/
37
38#include <stdlib.h>
39#include <unistd.h>
40#include <math.h>
41#include <stdio.h>
42
43#include "parametres.h"
44#include "perfcnt.h"
45#include "utils.h"
46#include "riemann.h"
47
48#ifdef HMPP
49#undef HMPP
50#include "constoprim.c"
51#include "equation_of_state.c"
52#include "slope.c"
53#include "trace.c"
54#include "qleftright.c"
55#include "cmpflx.c"
56#include "conservar.c"
57#define HMPP
58#endif
59
60#define PRECISION 1e-6
61
62void
63Dmemset(size_t nbr, real_t t[nbr], real_t motif) {
64 int i;
65 for (i = 0; i < nbr; i++) {
66 t[i] = motif;
67 }
68}
69
70
71#define DABS(x) (real_t) fabs((x))
72#ifdef HMPP
73#define MAX(x,y) fmax(x,y)
74#endif
75
76#define MYSQRT sqrt
77
78void
79riemann(int narray, const real_t Hsmallr,
80 const real_t Hsmallc, const real_t Hgamma,
81 const int Hniter_riemann, const int Hnvar,
82 const int Hnxyt, const int slices,
83 const int Hstep,
84 real_t qleft[Hnvar][Hstep][Hnxyt],
85 real_t qright[Hnvar][Hstep][Hnxyt], //
86 real_t qgdnv[Hnvar][Hstep][Hnxyt], //
87 int sgnm[Hstep][Hnxyt],
88 hydrowork_t * Hw)
89{
90 int i, s, ii, iimx;
91 real_t smallp_ = Square(Hsmallc) / Hgamma;
92 real_t gamma6_ = (Hgamma + one) / (two * Hgamma);
93 real_t smallpp_ = Hsmallr * smallp_;
94
95 FLOPS(4, 2, 0, 0);
96 // __declspec(align(256)) thevariable
97
98 int *Fgoon = Hw->goon;
99 real_t *Fpstar = Hw->pstar;
100 real_t *Frl = Hw->rl;
101 real_t *Ful = Hw->ul;
102 real_t *Fpl = Hw->pl;
103 real_t *Fur = Hw->ur;
104 real_t *Fpr = Hw->pr;
105 real_t *Fcl = Hw->cl;
106 real_t *Fcr = Hw->cr;
107 real_t *Frr = Hw->rr;
108
109 real_t smallp = smallp_;
110 real_t gamma6 = gamma6_;
111 real_t smallpp = smallpp_;
112
113 // fprintf(stderr, "%d\n", __ICC );
114#pragma message "active pragma simd "
115#define SIMDNEEDED 1
116#if __ICC < 1300
117#define SIMD ivdep
118#else
119#define SIMD simd
120#endif
121 // #define SIMD novector
122
123 // Pressure, density and velocity
124#pragma omp parallel for private(s, i), shared(qgdnv, sgnm) reduction(+:flopsAri), reduction(+:flopsSqr), reduction(+:flopsMin), reduction(+:flopsTra)
125 for (s = 0; s < slices; s++) {
126 int ii, iimx;
127 int *goon;
128 real_t *pstar, *rl, *ul, *pl, *rr, *ur, *pr, *cl, *cr;
129 int iter;
130 pstar = &Fpstar[s * narray];
131 rl = &Frl[s * narray];
132 ul = &Ful[s * narray];
133 pl = &Fpl[s * narray];
134 rr = &Frr[s * narray];
135 ur = &Fur[s * narray];
136 pr = &Fpr[s * narray];
137 cl = &Fcl[s * narray];
138 cr = &Fcr[s * narray];
139 goon = &Fgoon[s * narray];
140
141 // Precompute values for this slice
142
143#ifdef SIMDNEEDED
144#if __ICC < 1300
145#pragma ivdep
146#else
147#pragma SIMD
148#endif
149#endif
150 for (i = 0; i < narray; i++) {
151 rl[i] = fmax(qleft[ID][s][i], Hsmallr);
152 ul[i] = qleft[IU][s][i];
153 pl[i] = fmax(qleft[IP][s][i], (real_t) (rl[i] * smallp));
154 rr[i] = fmax(qright[ID][s][i], Hsmallr);
155 ur[i] = qright[IU][s][i];
156 pr[i] = fmax(qright[IP][s][i], (real_t) (rr[i] * smallp));
157
158 // Lagrangian sound speed
159 cl[i] = Hgamma * pl[i] * rl[i];
160 cr[i] = Hgamma * pr[i] * rr[i];
161 // First guess
162
163 real_t wl_i = MYSQRT(cl[i]);
164 real_t wr_i = MYSQRT(cr[i]);
165 pstar[i] = fmax(((wr_i * pl[i] + wl_i * pr[i]) + wl_i * wr_i * (ul[i] - ur[i])) / (wl_i + wr_i), 0.0);
166 goon[i] = 1;
167 }
168
169#define Fmax(a,b) (((a) > (b)) ? (a): (b))
170#define Fabs(a) (((a) > 0) ? (a): -(a))
171
172 // solve the riemann problem on the interfaces of this slice
173 for (iter = 0; iter < Hniter_riemann; iter++) {
174#ifdef SIMDNEEDED
175#if __ICC < 1300
176#pragma simd
177#else
178#pragma SIMD
179#endif
180#endif
181 for (i = 0; i < narray; i++) {
182 if (goon[i]) {
183 real_t pst = pstar[i];
184 // Newton-Raphson iterations to find pstar at the required accuracy
185 real_t wwl = MYSQRT(cl[i] * (one + gamma6 * (pst - pl[i]) / pl[i]));
186 real_t wwr = MYSQRT(cr[i] * (one + gamma6 * (pst - pr[i]) / pr[i]));
187 real_t swwl = Square(wwl);
188 real_t ql = two * wwl * swwl / (swwl + cl[i]);
189 real_t qr = two * wwr * Square(wwr) / (Square(wwr) + cr[i]);
190 real_t usl = ul[i] - (pst - pl[i]) / wwl;
191 real_t usr = ur[i] + (pst - pr[i]) / wwr;
192 real_t tmp = (qr * ql / (qr + ql) * (usl - usr));
193 real_t delp_i = Fmax(tmp, (-pst));
194 // pstar[i] = pstar[i] + delp_i;
195 pst += delp_i;
196 // Convergence indicator
197 real_t tmp2 = delp_i / (pst + smallpp);
198 real_t uo_i = Fabs(tmp2);
199 goon[i] = uo_i > PRECISION;
200 // FLOPS(29, 10, 2, 0);
201 pstar[i] = pst;
202 }
203 }
204 } // iter_riemann
205
206#ifdef SIMDNEEDED
207#pragma SIMD
208#endif
209 for (i = 0; i < narray; i++) {
210 real_t wl_i = MYSQRT(cl[i]);
211 real_t wr_i = MYSQRT(cr[i]);
212
213 wr_i = MYSQRT(cr[i] * (one + gamma6 * (pstar[i] - pr[i]) / pr[i]));
214 wl_i = MYSQRT(cl[i] * (one + gamma6 * (pstar[i] - pl[i]) / pl[i]));
215
216 real_t ustar_i = half * (ul[i] + (pl[i] - pstar[i]) / wl_i + ur[i] - (pr[i] - pstar[i]) / wr_i);
217
218 int left = ustar_i > 0;
219
220 real_t ro_i, uo_i, po_i, wo_i;
221
222 if (left) {
223 sgnm[s][i] = 1;
224 ro_i = rl[i];
225 uo_i = ul[i];
226 po_i = pl[i];
227 wo_i = wl_i;
228 } else {
229 sgnm[s][i] = -1;
230 ro_i = rr[i];
231 uo_i = ur[i];
232 po_i = pr[i];
233 wo_i = wr_i;
234 }
235
236 real_t co_i = MYSQRT(fabs(Hgamma * po_i / ro_i));
237 co_i = fmax(Hsmallc, co_i);
238
239 real_t rstar_i = ro_i / (one + ro_i * (po_i - pstar[i]) / Square(wo_i));
240 rstar_i = fmax(rstar_i, Hsmallr);
241
242 real_t cstar_i = MYSQRT(fabs(Hgamma * pstar[i] / rstar_i));
243 cstar_i = fmax(Hsmallc, cstar_i);
244
245 real_t spout_i = co_i - sgnm[s][i] * uo_i;
246 real_t spin_i = cstar_i - sgnm[s][i] * ustar_i;
247 real_t ushock_i = wo_i / ro_i - sgnm[s][i] * uo_i;
248
249 if (pstar[i] >= po_i) {
250 spin_i = ushock_i;
251 spout_i = ushock_i;
252 }
253
254 real_t scr_i = fmax((real_t) (spout_i - spin_i), (real_t) (Hsmallc + fabs(spout_i + spin_i)));
255
256 real_t frac_i = (one + (spout_i + spin_i) / scr_i) * half;
257 frac_i = fmax(zero, (real_t) (fmin(one, frac_i)));
258
259 int addSpout = spout_i < zero;
260 int addSpin = spin_i > zero;
261 // real_t originalQgdnv = !addSpout & !addSpin;
262 real_t qgdnv_ID, qgdnv_IU, qgdnv_IP;
263
264 if (addSpout) {
265 qgdnv_ID = ro_i;
266 qgdnv_IU = uo_i;
267 qgdnv_IP = po_i;
268 } else if (addSpin) {
269 qgdnv_ID = rstar_i;
270 qgdnv_IU = ustar_i;
271 qgdnv_IP = pstar[i];
272 } else {
273 qgdnv_ID = (frac_i * rstar_i + (one - frac_i) * ro_i);
274 qgdnv_IU = (frac_i * ustar_i + (one - frac_i) * uo_i);
275 qgdnv_IP = (frac_i * pstar[i] + (one - frac_i) * po_i);
276 }
277
278 qgdnv[ID][s][i] = qgdnv_ID;
279 qgdnv[IU][s][i] = qgdnv_IU;
280 qgdnv[IP][s][i] = qgdnv_IP;
281
282 // transverse velocity
283 if (left) {
284 qgdnv[IV][s][i] = qleft[IV][s][i];
285 } else {
286 qgdnv[IV][s][i] = qright[IV][s][i];
287 }
288 }
289 }
290 {
291 int nops = slices * narray;
292 FLOPS(57 * nops, 17 * nops, 14 * nops, 0 * nops);
293 }
294
295 // other passive variables
296 if (Hnvar > IP) {
297 int invar;
298 for (invar = IP + 1; invar < Hnvar; invar++) {
299 for (s = 0; s < slices; s++) {
300#ifdef SIMDNEEDED
301#pragma SIMD
302#endif
303 for (i = 0; i < narray; i++) {
304 int left = (sgnm[s][i] == 1);
305 qgdnv[invar][s][i] = qleft[invar][s][i] * left + qright[invar][s][i] * !left;
306 }
307 }
308 }
309 }
310} // riemann_vec
311
312//EOF
Note: See TracBrowser for help on using the repository browser.