source: CIVL/examples/omp/HydroC/trace.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: 5.9 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 "utils.h"
45#include "trace.h"
46#include "perfcnt.h"
47
48#ifndef HMPP
49
50void
51trace(const real_t dtdx,
52 const int n,
53 const int Hscheme,
54 const int Hnvar,
55 const int Hnxyt,
56 const int slices, const int Hstep,
57 real_t q[Hnvar][Hstep][Hnxyt],
58 real_t dq[Hnvar][Hstep][Hnxyt], real_t c[Hstep][Hnxyt], real_t qxm[Hnvar][Hstep][Hnxyt],
59 real_t qxp[Hnvar][Hstep][Hnxyt]) {
60 int ijmin, ijmax;
61 int i, IN, s;
62 real_t zerol = 0.0, zeror = 0.0, project = 0.;
63
64 WHERE("trace");
65 ijmin = 0;
66 ijmax = n;
67
68 // if (strcmp(Hscheme, "muscl") == 0) { // MUSCL-Hancock method
69 if (Hscheme == HSCHEME_MUSCL) { // MUSCL-Hancock method
70 zerol = -hundred / dtdx;
71 zeror = hundred / dtdx;
72 project = one;
73 }
74 // if (strcmp(Hscheme, "plmde") == 0) { // standard PLMDE
75 if (Hscheme == HSCHEME_PLMDE) { // standard PLMDE
76 zerol = zero;
77 zeror = zero;
78 project = one;
79 }
80 // if (strcmp(Hscheme, "collela") == 0) { // Collela's method
81 if (Hscheme == HSCHEME_COLLELA) { // Collela's method
82 zerol = zero;
83 zeror = zero;
84 project = zero;
85 }
86
87#pragma omp parallel for private(s,i), shared(qxp, qxm)
88 for (s = 0; s < slices; s++) {
89 for (i = ijmin + 1; i < ijmax - 1; i++) {
90 real_t cc, csq, r, u, v, p;
91 real_t dr, du, dv, dp;
92 real_t alpham, alphap, alpha0r, alpha0v;
93 real_t spminus, spplus, spzero;
94 real_t apright, amright, azrright, azv1right;
95 real_t apleft, amleft, azrleft, azv1left;
96
97 real_t upcc, umcc, upccx, umccx, ux;
98 real_t rOcc, OrOcc, dprcc;
99
100 cc = c[s][i];
101 csq = Square(cc);
102 r = q[ID][s][i];
103 u = q[IU][s][i];
104 v = q[IV][s][i];
105 p = q[IP][s][i];
106 dr = dq[ID][s][i];
107 du = dq[IU][s][i];
108 dv = dq[IV][s][i];
109 dp = dq[IP][s][i];
110 rOcc = r / cc;
111 OrOcc = cc / r;
112 dprcc = dp / (r * cc);
113 alpham = half * (dprcc - du) * rOcc;
114 alphap = half * (dprcc + du) * rOcc;
115 alpha0r = dr - dp / csq;
116 alpha0v = dv;
117 upcc = u + cc;
118 umcc = u - cc;
119 upccx = upcc * dtdx;
120 umccx = umcc * dtdx;
121 ux = u * dtdx;
122
123 // Right state
124 spminus = (umcc >= zeror) ? (project) : umccx + one;
125 spplus = (upcc >= zeror) ? (project) : upccx + one;
126 spzero = (u >= zeror) ? (project) : ux + one;
127 apright = -half * spplus * alphap;
128 amright = -half * spminus * alpham;
129 azrright = -half * spzero * alpha0r;
130 azv1right = -half * spzero * alpha0v;
131 qxp[ID][s][i] = r + (apright + amright + azrright);
132 qxp[IU][s][i] = u + (apright - amright) * OrOcc;
133 qxp[IV][s][i] = v + (azv1right);
134 qxp[IP][s][i] = p + (apright + amright) * csq;
135
136 // Left state
137 spminus = (umcc <= zerol) ? (-project) : umccx - one;
138 spplus = (upcc <= zerol) ? (-project) : upccx - one;
139 spzero = (u <= zerol) ? (-project) : ux - one;
140 apleft = -half * spplus * alphap;
141 amleft = -half * spminus * alpham;
142 azrleft = -half * spzero * alpha0r;
143 azv1left = -half * spzero * alpha0v;
144 qxm[ID][s][i] = r + (apleft + amleft + azrleft);
145 qxm[IU][s][i] = u + (apleft - amleft) * OrOcc;
146 qxm[IV][s][i] = v + (azv1left);
147 qxm[IP][s][i] = p + (apleft + amleft) * csq;
148 }
149 }
150
151 {
152 int nops = slices * ((ijmax - 1) - (ijmin + 1));
153 FLOPS(77 * nops, 7 * nops, 0 * nops, 0 * nops);
154 }
155
156 if (Hnvar > IP) {
157 for (IN = IP + 1; IN < Hnvar; IN++) {
158 for (s = 0; s < slices; s++) {
159 for (i = ijmin + 1; i < ijmax - 1; i++) {
160 real_t u, a;
161 real_t da;
162 real_t spzero;
163 real_t acmpright;
164 real_t acmpleft;
165 u = q[IU][s][i];
166 a = q[IN][s][i];
167 da = dq[IN][s][i];
168
169 // Right state
170 spzero = u * dtdx + one;
171 if (u >= zeror) {
172 spzero = project;
173 }
174 acmpright = -half * spzero * da;
175 qxp[IN][s][i] = a + acmpright;
176
177 // Left state
178 spzero = u * dtdx - one;
179 if (u <= zerol) {
180 spzero = -project;
181 }
182 acmpleft = -half * spzero * da;
183 qxm[IN][s][i] = a + acmpleft;
184 }
185 }
186 }
187 }
188} // trace
189
190#endif /* HMPP */
191
192//EOF
Note: See TracBrowser for help on using the repository browser.