ExaDG
Toggle main menu visibility
Loading...
Searching...
No Matches
include
exadg
postprocessor
spectral_analysis
setup.h
1
/* ______________________________________________________________________
2
*
3
* ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4
*
5
* Copyright (C) 2021 by the ExaDG authors
6
*
7
* This program is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19
* ______________________________________________________________________
20
*/
21
22
#ifndef EXADG_POSTPROCESSOR_SPECTRAL_ANALYSIS_SETUP_H_
23
#define EXADG_POSTPROCESSOR_SPECTRAL_ANALYSIS_SETUP_H_
24
25
// C/C++
26
#include <mpi.h>
27
28
// define helper funtions
29
#ifndef MIN
30
# define MIN(a, b) (((a) < (b)) ? (a) : (b))
31
#endif
32
33
#ifndef MAX
34
# define MAX(a, b) (((a) > (b)) ? (a) : (b))
35
#endif
36
37
namespace
dealspectrum
38
{
55
class
Setup
56
{
57
public
:
58
// length of header (8 ints)
59
static
int
const
HEADER_LENGTH = 8;
60
61
MPI_Comm
const
comm;
62
63
// is initialized?
64
bool
initialized;
65
// file type (0) sfc + cell-wise (1) row-wise
66
int
type;
67
// nr. of dimensions
68
int
dim;
69
// nr. of cells in each direction
70
int
cells;
71
72
private
:
73
// degree of cell
74
int
degree;
75
76
public
:
77
// points in each direction in cell (i.e.: degree+1)
78
int
points_src;
79
// points in each direction for evaluation in cell
80
int
points_dst;
81
// mpi-rank
82
int
rank;
83
// mpi-size
84
int
size;
85
// nr. of bins for postprocessing
86
int
bins;
87
// time stemp
88
double
time = 0.0;
89
93
Setup
(MPI_Comm
const
& comm) : comm(comm), initialized(false), points_dst(0)
94
{
95
// extract mpi-rank and ...
96
MPI_Comm_rank(comm, &rank);
97
// ... mpi-size
98
MPI_Comm_size(comm, &size);
99
}
100
109
void
110
init
(
int
dim,
int
cells,
int
points_src,
int
points_dst)
111
{
112
this->initialized =
true
;
113
114
this->type = 0;
115
this->dim = dim;
116
this->cells = cells;
117
this->degree = points_src - 1;
118
this->points_src = points_src;
119
this->points_dst = points_dst;
120
this->bins = 1;
121
}
122
128
int
129
readHeader
(
char
*& filename)
130
{
131
FILE * fp;
132
int
crit[1 + 4];
133
crit[0] = 0;
134
135
if
(this->rank == 0)
136
{
137
// read header only by rank 0 ...
138
if
((fp = fopen(filename,
"r"
)) != NULL)
139
{
140
// ... read header in one go
141
fread(crit + 1,
sizeof
(
int
), 4, fp);
142
143
// read time
144
fread(&this->time,
sizeof
(
double
), 1, fp);
145
146
// ... close file
147
fclose(fp);
148
}
149
else
150
{
151
// ... reading the file failed
152
crit[0] = 0;
153
}
154
}
155
156
// broadcast header to all processes
157
MPI_Bcast(&crit, 5, MPI_INT, 0, comm);
158
MPI_Bcast(&this->time, 1, MPI_DOUBLE, 0, comm);
159
160
if
(this->initialized)
161
{
162
// ... extract header by each process and set properties
163
crit[0] += this->type != crit[1];
164
crit[0] += this->dim != crit[2];
165
crit[0] += this->cells != crit[3];
166
crit[0] += this->degree != crit[4];
167
}
168
else
169
{
170
// ... extract header by each process and set properties
171
this->type = crit[1];
172
this->dim = crit[2];
173
this->cells = crit[3];
174
this->degree = crit[4];
175
this->points_src = this->degree + 1;
176
if
(this->points_dst == 0)
177
this->points_dst = this->points_src;
// equal if nothing specified
178
}
179
180
// success or failure?
181
return
crit[0];
182
}
183
189
void
190
writeHeader
(
char
const
* filename)
191
{
192
FILE * fp;
193
194
if
(this->rank == 0)
195
{
196
// write header only by rank 0 ...
197
if
((fp = fopen(filename,
"w"
)) != NULL)
198
{
199
// ... write type
200
fwrite(&this->type,
sizeof
(
int
), 1, fp);
201
// ... write dim
202
fwrite(&this->dim,
sizeof
(
int
), 1, fp);
203
204
if
(this->type == 0)
205
{
206
// ... cell wise:
207
fwrite(&this->cells,
sizeof
(
int
), 1, fp);
208
fwrite(&this->degree,
sizeof
(
int
), 1, fp);
209
}
210
else
211
{
212
// ... row wise (degree is redundant):
213
int
temp1 = this->cells * this->points_dst;
214
int
temp2 = 0;
215
fwrite(&temp1,
sizeof
(
int
), temp1, fp);
216
fwrite(&temp2,
sizeof
(
int
), temp2, fp);
217
}
218
219
// write time
220
fwrite(&this->time,
sizeof
(
double
), 1, fp);
221
222
// ... close file
223
fclose(fp);
224
}
225
}
226
227
// synchronize all processes (not necessary)
228
MPI_Barrier(comm);
229
}
230
};
231
232
}
// namespace dealspectrum
233
234
#endif
/* EXADG_POSTPROCESSOR_SPECTRAL_ANALYSIS_SETUP_H_ */
dealspectrum::Setup::readHeader
int readHeader(char *&filename)
Definition
setup.h:129
dealspectrum::Setup::writeHeader
void writeHeader(char const *filename)
Definition
setup.h:190
dealspectrum::Setup::init
void init(int dim, int cells, int points_src, int points_dst)
Definition
setup.h:110
dealspectrum::Setup::Setup
Setup(MPI_Comm const &comm)
Definition
setup.h:93
Generated by
1.17.0