-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtimestep.cpp
107 lines (79 loc) · 3.32 KB
/
timestep.cpp
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
/*
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 Calculate the minimum timestep for all mesh chunks.
// @author Wayne Gaudin
// @details Invokes the kernels needed to calculate the timestep and finds
// the minimum across all chunks. Checks if the timestep falls below the
// user specified limitand outputs the timestep information.
#include "timestep.h"
#include "calc_dt.h"
#include "ideal_gas.h"
#include "timer.h"
#include "update_halo.h"
#include "viscosity.h"
#include "report.h"
extern std::ostream g_out;
void timestep(global_variables& globals, parallel_& parallel) {
globals.dt = g_big;
int small = 0;
int fields[NUM_FIELDS];
double kernel_time;
if (globals.profiler_on) kernel_time = timer();
for (int tile = 0; tile < globals.tiles_per_chunk; ++tile) {
ideal_gas(globals, tile, false);
}
if (globals.profiler_on) globals.profiler.ideal_gas += timer()-kernel_time;
for (int i = 0; i < NUM_FIELDS; ++i) fields[i] = 0;
fields[field_pressure] = 1;
fields[field_energy0] = 1;
fields[field_density0] = 1;
fields[field_xvel0] = 1;
fields[field_yvel0] = 1;
update_halo(globals, fields, 1);
if (globals.profiler_on) kernel_time = timer();
viscosity(globals);
if (globals.profiler_on) globals.profiler.viscosity += timer()-kernel_time;
for (int i = 0; i < NUM_FIELDS; ++i) fields[i] = 0;
fields[field_viscosity] = 1;
update_halo(globals, fields, 1);
if (globals.profiler_on) kernel_time = timer();
int jldt, kldt;
double dtlp;
double x_pos, y_pos, xl_pos, yl_pos;
std::string dt_control, dtl_control;
for (int tile = 0; tile < globals.tiles_per_chunk; ++tile) {
calc_dt(globals, tile, dtlp, dtl_control, xl_pos, yl_pos, jldt, kldt);
if (dtlp <= globals.dt) {
globals.dt = dtlp;
dt_control = dtl_control;
x_pos = xl_pos;
y_pos = yl_pos;
globals.jdt = jldt;
globals.kdt = kldt;
}
}
globals.dt = std::min(std::min(globals.dt, globals.dtold * globals.dtrise), globals.dtmax);
clover_min(globals.dt);
if (globals.profiler_on) globals.profiler.timestep += timer() - kernel_time;
if (globals.dt < globals.dtmin) small = 1;
if (parallel.boss) {
g_out << " Step " << globals.step << " time " << globals.time << " control " << dt_control << " timestep " << globals.dt << " " << globals.jdt << "," << globals.kdt << " x " << x_pos << " y " << y_pos << std::endl;
std::cout << " Step " << globals.step << " time " << globals.time << " control " << dt_control << " timestep " << globals.dt << " " << globals.jdt << "," << globals.kdt << " x " << x_pos << " y " << y_pos << std::endl;
}
if (small == 1) {
report_error((char*)"timestep", (char*)"small timestep");
}
globals.dtold = globals.dt;
}