Skip to content

Commit b42f703

Browse files
authored
Merge pull request #63 from VTT-ProperTune/ahojukka5/free_function_step
Add free function void(Simulator &s, Model &m)
2 parents 1578270 + 1af9d41 commit b42f703

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

apps/tungsten.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,22 @@ void from_json(const json &j, Tungsten &m) {
285285
p.q4_bar = p.q40_bar;
286286
}
287287

288+
/*
289+
Sometimes, one need to get access to the simulator during stepping. This can be
290+
done by overriding the following function. The default implementation just runs
291+
m.step(t) so if there's no need to access the simulator, it's not necessary to
292+
override this function.
293+
*/
294+
void step(Simulator &s, Tungsten &m) {
295+
#ifdef TUNGSTEN_DEBUG
296+
if (m.rank0) cout << "Performing Tungsten step" << endl;
297+
#endif
298+
double t = s.get_time().get_current();
299+
m.step(t);
300+
// perform some extra logic after the step, which can access both simulator
301+
// and model
302+
}
303+
288304
int main(int argc, char *argv[]) {
289305
cout << std::fixed;
290306
cout.precision(3);

include/openpfc/simulator.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ along with this program. If not, see https://www.gnu.org/licenses/.
3232

3333
namespace pfc {
3434

35+
void step(class Simulator &s, Model &m);
36+
3537
/**
3638
* @brief The Simulator class is responsible for running the simulation of the
3739
* model.
@@ -270,6 +272,10 @@ class Simulator {
270272
}
271273
};
272274

275+
void step(Simulator &s, Model &m) {
276+
m.step(s.get_time().get_current());
277+
}
278+
273279
} // namespace pfc
274280

275281
#endif // PFC_SIMULATOR_HPP

include/openpfc/ui.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ template <class ConcreteModel> class App {
681681
double l_fft_time = 0.0;
682682
MPI_Barrier(m_comm);
683683
l_steptime = -MPI_Wtime();
684-
model.step(time.get_current());
684+
step(simulator, model);
685685
MPI_Barrier(m_comm);
686686
l_steptime += MPI_Wtime();
687687
l_fft_time = fft.get_fft_time();

0 commit comments

Comments
 (0)