-
Notifications
You must be signed in to change notification settings - Fork 5
/
generate_chunk_kernel_c.c
161 lines (144 loc) · 5.73 KB
/
generate_chunk_kernel_c.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*Crown Copyright 2012 AWE.
*
* This file is part of CloverLeaf.
*
* CloverLeaf is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* CloverLeaf is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* CloverLeaf. If not, see http://www.gnu.org/licenses/. */
/**
* @brief C mesh chunk generator
* @author Wayne Gaudin
* @details Still just a stub.
*
* Note that state one is always used as the background state, which is then
* overwritten by further state definitions.
*/
#include <stdio.h>
#include <stdlib.h>
#include "ftocmacros.h"
#include <math.h>
void generate_chunk_kernel_c_(int *xmin,int *xmax,int *ymin,int *ymax,
double *vertexx,
double *vertexy,
double *cellx,
double *celly,
double *density0,
double *energy0,
double *xvel0,
double *yvel0,
int *nmbr_f_stts,
double *state_density,
double *state_energy,
double *state_xvel,
double *state_yvel,
double *state_xmin,
double *state_xmax,
double *state_ymin,
double *state_ymax,
double *state_radius,
int *state_geometry,
int *g_rct,
int *g_crc,
int *g_pnt)
{
int x_min=*xmin;
int x_max=*xmax;
int y_min=*ymin;
int y_max=*ymax;
int number_of_states=*nmbr_f_stts;
int g_rect=*g_rct;
int g_circ=*g_crc;
int g_point=*g_pnt;
double radius,x_cent,y_cent;
int state;
int j,k,jt,kt;
#pragma omp parallel
{
/* State 1 is always the background state */
#pragma omp for private(j,k)
for (k=y_min-2;k<=y_max+2;k++) {
#pragma ivdep
for (j=x_min-2;j<=x_max+2;j++) {
energy0[FTNREF2D(j ,k ,x_max+4,x_min-2,y_min-2)]=state_energy[FTNREF1D(1,1)];
}
}
#pragma omp for private(j,k)
for (k=y_min-2;k<=y_max+2;k++) {
#pragma ivdep
for (j=x_min-2;j<=x_max+2;j++) {
density0[FTNREF2D(j ,k ,x_max+4,x_min-2,y_min-2)]=state_density[FTNREF1D(1,1)];
}
}
#pragma omp for private(j,k)
for (k=y_min-2;k<=y_max+2;k++) {
#pragma ivdep
for (j=x_min-2;j<=x_max+2;j++) {
xvel0[FTNREF2D(j ,k ,x_max+5,x_min-2,y_min-2)]=state_xvel[FTNREF1D(1,1)];
}
}
#pragma omp for private(j,k)
for (k=y_min-2;k<=y_max+2;k++) {
#pragma ivdep
for (j=x_min-2;j<=x_max+2;j++) {
yvel0[FTNREF2D(j ,k ,x_max+5,x_min-2,y_min-2)]=state_yvel[FTNREF1D(1,1)];
}
}
for ( state=2;state<=number_of_states;state++) {
/* Could the velocity setting be thread unsafe? */
x_cent=state_xmin[FTNREF1D(state,1)];
y_cent=state_ymin[FTNREF1D(state,1)];
#pragma omp for private(radius,j,k)
for (k=y_min-2;k<=y_max+2;k++) {
#pragma ivdep
for (j=x_min-2;j<=x_max+2;j++) {
if(state_geometry[FTNREF1D(state,1)]==g_rect ) {
if(vertexx[FTNREF1D(j+1,x_min-2)]>=state_xmin[FTNREF1D(state,1)] && vertexx[FTNREF1D(j,x_min-2)]<state_xmax[FTNREF1D(state,1)]) {
if(vertexy[FTNREF1D(k+1,y_min-2)]>=state_ymin[FTNREF1D(state,1)] && vertexy[FTNREF1D(k,y_min-2)]<state_ymax[FTNREF1D(state,1)]) {
density0[FTNREF2D(j ,k ,x_max+4,x_min-2,y_min-2)]=state_density[FTNREF1D(state,1)];
energy0[FTNREF2D(j ,k ,x_max+4,x_min-2,y_min-2)]=state_energy[FTNREF1D(state,1)];
for (kt=k;kt<=k+1;kt++) {
for (jt=j;jt<=j+1;jt++) {
xvel0[FTNREF2D(jt,kt,x_max+5,x_min-2,y_min-2)]=state_xvel[FTNREF1D(state,1)];
yvel0[FTNREF2D(jt,kt,x_max+5,x_min-2,y_min-2)]=state_yvel[FTNREF1D(state,1)];
}
}
}
}
}else if(state_geometry[FTNREF1D(state,1)]==g_circ ) {
radius=sqrt((cellx[FTNREF1D(j,x_min-2)]-x_cent)*(cellx[FTNREF1D(j,x_min-2)]-x_cent)+(celly[FTNREF1D(k,y_min-2)]-y_cent)*(celly[FTNREF1D(k,y_min-2)]-y_cent));
if(radius<=state_radius[FTNREF1D(state,1)]) {
density0[FTNREF2D(j ,k ,x_max+4,x_min-2,y_min-2)]=state_density[FTNREF1D(state,1)];
energy0[FTNREF2D(j ,k ,x_max+4,x_min-2,y_min-2)]=state_density[FTNREF1D(state,1)];
for (kt=k;kt<=k+1;kt++) {
for (jt=j;jt<=j+1;jt++) {
xvel0[FTNREF2D(jt,kt,x_max+5,x_min-2,y_min-2)]=state_xvel[FTNREF1D(state,1)];
yvel0[FTNREF2D(jt,kt,x_max+5,x_min-2,y_min-2)]=state_yvel[FTNREF1D(state,1)];
}
}
}
}else if(state_geometry[FTNREF1D(state,1)]==g_point) {
if(vertexx[FTNREF1D(j,x_min-2)]==x_cent && vertexy[FTNREF1D(j,x_min-2)]==y_cent) {
density0[FTNREF2D(j ,k ,x_max+4,x_min-2,y_min-2)]=state_density[FTNREF1D(state,1)];
energy0[FTNREF2D(j ,k ,x_max+4,x_min-2,y_min-2)]=state_density[FTNREF1D(state,1)];
for (kt=k;kt<=k+1;kt++) {
for (jt=j;jt<=j+1;jt++) {
xvel0[FTNREF2D(jt,kt,x_max+5,x_min-2,y_min-2)]=state_xvel[FTNREF1D(state,1)];
yvel0[FTNREF2D(jt,kt,x_max+5,x_min-2,y_min-2)]=state_yvel[FTNREF1D(state,1)];
}
}
}
}
}
}
}
}
}