| 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 | This software is governed by the CeCILL license under French law and
|
|---|
| 10 | abiding by the rules of distribution of free software. You can use,
|
|---|
| 11 | modify and/ or redistribute the software under the terms of the CeCILL
|
|---|
| 12 | license as circulated by CEA, CNRS and INRIA at the following URL
|
|---|
| 13 | "http://www.cecill.info".
|
|---|
| 14 |
|
|---|
| 15 | As a counterpart to the access to the source code and rights to copy,
|
|---|
| 16 | modify and redistribute granted by the license, users are provided only
|
|---|
| 17 | with a limited warranty and the software's author, the holder of the
|
|---|
| 18 | economic rights, and the successive licensors have only limited
|
|---|
| 19 | liability.
|
|---|
| 20 |
|
|---|
| 21 | In this respect, the user's attention is drawn to the risks associated
|
|---|
| 22 | with loading, using, modifying and/or developing or reproducing the
|
|---|
| 23 | software by the user in light of its specific status of free software,
|
|---|
| 24 | that may mean that it is complicated to manipulate, and that also
|
|---|
| 25 | therefore means that it is reserved for developers and experienced
|
|---|
| 26 | professionals having in-depth computer knowledge. Users are therefore
|
|---|
| 27 | encouraged to load and test the software's suitability as regards their
|
|---|
| 28 | requirements in conditions enabling the security of their systems and/or
|
|---|
| 29 | data to be ensured and, more generally, to use and operate it in the
|
|---|
| 30 | same conditions as regards security.
|
|---|
| 31 |
|
|---|
| 32 | The fact that you are presently reading this means that you have had
|
|---|
| 33 | knowledge of the CeCILL license and that you accept its terms.
|
|---|
| 34 |
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #include <stdlib.h>
|
|---|
| 38 | #include <unistd.h>
|
|---|
| 39 | #include <math.h>
|
|---|
| 40 | #include <stdio.h>
|
|---|
| 41 |
|
|---|
| 42 | #ifndef HMPP
|
|---|
| 43 | #include "parametres.h"
|
|---|
| 44 | #include "utils.h"
|
|---|
| 45 | #include "conservar.h"
|
|---|
| 46 | #include "perfcnt.h"
|
|---|
| 47 |
|
|---|
| 48 | #define BLOCKING 0
|
|---|
| 49 | #define SSST 32
|
|---|
| 50 | #define JJST 32
|
|---|
| 51 |
|
|---|
| 52 | void
|
|---|
| 53 | gatherConservativeVars(const int idim,
|
|---|
| 54 | const int rowcol,
|
|---|
| 55 | const int Himin,
|
|---|
| 56 | const int Himax,
|
|---|
| 57 | const int Hjmin,
|
|---|
| 58 | const int Hjmax,
|
|---|
| 59 | const int Hnvar,
|
|---|
| 60 | const int Hnxt,
|
|---|
| 61 | const int Hnyt,
|
|---|
| 62 | const int Hnxyt,
|
|---|
| 63 | const int slices, const int Hstep,
|
|---|
| 64 | real_t uold[Hnvar * Hnxt * Hnyt], real_t u[Hnvar][Hstep][Hnxyt]
|
|---|
| 65 | ) {
|
|---|
| 66 | int i, j, ivar, s;
|
|---|
| 67 |
|
|---|
| 68 | #define IHU(i, j, v) ((i) + Hnxt * ((j) + Hnyt * (v)))
|
|---|
| 69 | #define IHST(v,s,i) ((i) + Hstep * ((j) + Hnvar * (v)))
|
|---|
| 70 |
|
|---|
| 71 | WHERE("gatherConservativeVars");
|
|---|
| 72 | if (idim == 1) {
|
|---|
| 73 | // Gather conservative variables
|
|---|
| 74 | #pragma omp parallel for private(i, s), shared(u) COLLAPSE
|
|---|
| 75 | for (s = 0; s < slices; s++) {
|
|---|
| 76 | for (i = Himin; i < Himax; i++) {
|
|---|
| 77 | int idxuoID = IHU(i, rowcol + s, ID);
|
|---|
| 78 | u[ID][s][i] = uold[idxuoID];
|
|---|
| 79 |
|
|---|
| 80 | int idxuoIU = IHU(i, rowcol + s, IU);
|
|---|
| 81 | u[IU][s][i] = uold[idxuoIU];
|
|---|
| 82 |
|
|---|
| 83 | int idxuoIV = IHU(i, rowcol + s, IV);
|
|---|
| 84 | u[IV][s][i] = uold[idxuoIV];
|
|---|
| 85 |
|
|---|
| 86 | int idxuoIP = IHU(i, rowcol + s, IP);
|
|---|
| 87 | u[IP][s][i] = uold[idxuoIP];
|
|---|
| 88 | }
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | if (Hnvar > IP) {
|
|---|
| 92 | for (ivar = IP + 1; ivar < Hnvar; ivar++) {
|
|---|
| 93 | for (s = 0; s < slices; s++) {
|
|---|
| 94 | for (i = Himin; i < Himax; i++) {
|
|---|
| 95 | u[ivar][s][i] = uold[IHU(i, rowcol + s, ivar)];
|
|---|
| 96 | }
|
|---|
| 97 | }
|
|---|
| 98 | }
|
|---|
| 99 | }
|
|---|
| 100 | //
|
|---|
| 101 | } else {
|
|---|
| 102 | // Gather conservative variables
|
|---|
| 103 | #pragma omp parallel for private(j, s), shared(u)
|
|---|
| 104 | for (s = 0; s < slices; s++) {
|
|---|
| 105 | for (j = Hjmin; j < Hjmax; j++) {
|
|---|
| 106 | u[ID][s][j] = uold[IHU(rowcol + s, j, ID)];
|
|---|
| 107 | u[IU][s][j] = uold[IHU(rowcol + s, j, IV)];
|
|---|
| 108 | u[IV][s][j] = uold[IHU(rowcol + s, j, IU)];
|
|---|
| 109 | u[IP][s][j] = uold[IHU(rowcol + s, j, IP)];
|
|---|
| 110 | }
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | if (Hnvar > IP) {
|
|---|
| 114 | for (ivar = IP + 1; ivar < Hnvar; ivar++) {
|
|---|
| 115 | for (s = 0; s < slices; s++) {
|
|---|
| 116 | for (j = Hjmin; j < Hjmax; j++) {
|
|---|
| 117 | u[ivar][s][j] = uold[IHU(rowcol + s, j, ivar)];
|
|---|
| 118 | }
|
|---|
| 119 | }
|
|---|
| 120 | }
|
|---|
| 121 | }
|
|---|
| 122 | }
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | #undef IHU
|
|---|
| 126 |
|
|---|
| 127 | void
|
|---|
| 128 | updateConservativeVars(const int idim,
|
|---|
| 129 | const int rowcol,
|
|---|
| 130 | const real_t dtdx,
|
|---|
| 131 | const int Himin,
|
|---|
| 132 | const int Himax,
|
|---|
| 133 | const int Hjmin,
|
|---|
| 134 | const int Hjmax,
|
|---|
| 135 | const int Hnvar,
|
|---|
| 136 | const int Hnxt,
|
|---|
| 137 | const int Hnyt,
|
|---|
| 138 | const int Hnxyt,
|
|---|
| 139 | const int slices, const int Hstep,
|
|---|
| 140 | real_t uold[Hnvar * Hnxt * Hnyt], real_t u[Hnvar][Hstep][Hnxyt], real_t flux[Hnvar][Hstep][Hnxyt]
|
|---|
| 141 | ) {
|
|---|
| 142 | int i, j, ivar, s;
|
|---|
| 143 | WHERE("updateConservativeVars");
|
|---|
| 144 |
|
|---|
| 145 | #define IHU(i, j, v) ((i) + Hnxt * ((j) + Hnyt * (v)))
|
|---|
| 146 |
|
|---|
| 147 | if (idim == 1) {
|
|---|
| 148 |
|
|---|
| 149 | // Update conservative variables
|
|---|
| 150 | #pragma omp parallel for private(ivar, s,i), shared(uold) COLLAPSE
|
|---|
| 151 | for (s = 0; s < slices; s++) {
|
|---|
| 152 | for (ivar = 0; ivar <= IP; ivar++) {
|
|---|
| 153 | for (i = Himin + ExtraLayer; i < Himax - ExtraLayer; i++) {
|
|---|
| 154 | uold[IHU(i, rowcol + s, ivar)] = u[ivar][s][i] + (flux[ivar][s][i - 2] - flux[ivar][s][i - 1]) * dtdx;
|
|---|
| 155 | }
|
|---|
| 156 | }
|
|---|
| 157 | }
|
|---|
| 158 | {
|
|---|
| 159 | int nops = (IP+1) * slices * ((Himax - ExtraLayer) - (Himin + ExtraLayer));
|
|---|
| 160 | FLOPS(3 * nops, 0 * nops, 0 * nops, 0 * nops);
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | if (Hnvar > IP) {
|
|---|
| 164 | for (ivar = IP + 1; ivar < Hnvar; ivar++) {
|
|---|
| 165 | for (s = 0; s < slices; s++) {
|
|---|
| 166 | for (i = Himin + ExtraLayer; i < Himax - ExtraLayer; i++) {
|
|---|
| 167 | uold[IHU(i, rowcol + s, ivar)] = u[ivar][s][i] + (flux[ivar][s][i - 2] - flux[ivar][s][i - 1]) * dtdx;
|
|---|
| 168 | }
|
|---|
| 169 | }
|
|---|
| 170 | }
|
|---|
| 171 | }
|
|---|
| 172 | } else {
|
|---|
| 173 | // Update conservative variables
|
|---|
| 174 | #pragma omp parallel for private(j, s), shared(uold)
|
|---|
| 175 | for (s = 0; s < slices; s++) {
|
|---|
| 176 | for (j = (Hjmin + ExtraLayer); j < (Hjmax - ExtraLayer); j++) {
|
|---|
| 177 | uold[IHU(rowcol + s, j, ID)] = u[ID][s][j] + (flux[ID][s][j - 2] - flux[ID][s][j - 1]) * dtdx;
|
|---|
| 178 | uold[IHU(rowcol + s, j, IV)] = u[IU][s][j] + (flux[IU][s][j - 2] - flux[IU][s][j - 1]) * dtdx;
|
|---|
| 179 | uold[IHU(rowcol + s, j, IU)] = u[IV][s][j] + (flux[IV][s][j - 2] - flux[IV][s][j - 1]) * dtdx;
|
|---|
| 180 | uold[IHU(rowcol + s, j, IP)] = u[IP][s][j] + (flux[IP][s][j - 2] - flux[IP][s][j - 1]) * dtdx;
|
|---|
| 181 | }
|
|---|
| 182 | }
|
|---|
| 183 | {
|
|---|
| 184 | int nops = slices * ((Hjmax - ExtraLayer) - (Hjmin + ExtraLayer));
|
|---|
| 185 | FLOPS(12 * nops, 0 * nops, 0 * nops, 0 * nops);
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | if (Hnvar > IP) {
|
|---|
| 189 | for (ivar = IP + 1; ivar < Hnvar; ivar++) {
|
|---|
| 190 | for (s = 0; s < slices; s++) {
|
|---|
| 191 | for (j = Hjmin + ExtraLayer; j < Hjmax - ExtraLayer; j++) {
|
|---|
| 192 | uold[IHU(rowcol + s, j, ivar)] = u[ivar][s][j] + (flux[ivar][s][j - 2] - flux[ivar][s][j - 1]) * dtdx;
|
|---|
| 193 | }
|
|---|
| 194 | }
|
|---|
| 195 | }
|
|---|
| 196 | }
|
|---|
| 197 | }
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | #undef IHU
|
|---|
| 201 | #endif
|
|---|
| 202 | //EOF
|
|---|