Free Electron
Stepper.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #pragma once
8 
9 namespace fe
10 {
11 namespace ext
12 {
13 
14 /// @brief Time Stepping System
15 class FE_DL_EXPORT Stepper
16  : virtual public SystemI,
17  public CastableAs<Stepper>
18 {
19  public:
20  Stepper(void) { }
21  void compileStepper(const t_note_id &a_note_id);
22 virtual void perform(const t_note_id &a_note_id);
23 
24 virtual void connectOrchestrator(sp<OrchestratorI> a_spOrchestrator);
25 
26  /** Compile internal structure for dataset */
27 virtual void compile(const t_note_id &a_note_id) {}
28 
29  /** Move system forward in time by a timestep */
30 virtual void step(t_moa_real a_dt) = 0;
31 
32  protected:
33  t_moa_real m_time;
34  AsTime m_asTime;
35  Record r_time;
36  t_note_id m_note_step;
37  sp<RecordGroup> m_rg_dataset;
38  sp<OrchestratorI> m_spOrchestrator;
39 
40 };
41 
42 inline void Stepper::compileStepper(const t_note_id &a_note_id)
43 {
44  m_time = 0.0;
45  r_time = m_asTime.simClock(m_rg_dataset);
46 }
47 
48 inline void Stepper::perform(const t_note_id &a_note_id)
49 {
50  if(r_time.isValid())
51  {
52  t_moa_real dt = m_spOrchestrator->getTime() - m_time;
53  step(dt);
54  m_time += dt;
55  }
56 }
57 
58 inline void Stepper::connectOrchestrator(sp<OrchestratorI> a_spOrchestrator)
59 {
60  m_note_step = a_spOrchestrator->connect(this, FE_NOTE_STEP);
61  m_rg_dataset = a_spOrchestrator->dataset();
62  a_spOrchestrator->connect(this, &Stepper::compileStepper,FE_NOTE_COMPILE);
63  a_spOrchestrator->connect(this, &Stepper::compile, FE_NOTE_COMPILE);
64  m_spOrchestrator = a_spOrchestrator;
65 };
66 
67 } /* namespace ext */
68 } /* namespace fe */
kernel
Definition: namespace.dox:3
virtual void perform(const t_note_id &a_note_id)
Perform processing due to having been signaled.
Definition: Stepper.h:48
virtual void connectOrchestrator(sp< OrchestratorI > a_spOrchestrator)
Callback for the System to register itself to the orchestrator.
Definition: Stepper.h:58
Time Stepping System.
Definition: Stepper.h:15
Clock.
Definition: moaAS.h:104
virtual void compile(const t_note_id &a_note_id)
Compile internal structure for dataset.
Definition: Stepper.h:27
Reference to an instance of a Layout.
Definition: RecordSB.h:35
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
System Interface for MOA.
Definition: SystemI.h:18
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192