SPH
Job.h
Go to the documentation of this file.
1 #pragma once
2 
7 #include "quantities/Storage.h"
8 #include "run/VirtualSettings.h"
9 #include "system/Settings.h"
10 #include "system/Statistics.h"
11 
13 
14 class IMaterial;
15 class IRunCallbacks;
16 class IRun;
17 
18 class IJobData : public Polymorphic {};
19 
20 enum class JobType {
22  PARTICLES,
23 
25  MATERIAL,
26 
28  GEOMETRY,
29 };
30 
32 
33 struct ParticleData {
36 
39 
44 };
45 
52 class JobContext : public Polymorphic {
53 private:
55 
56 public:
57  JobContext() = default;
58 
59  template <typename TValue>
61 
66  template <typename TValue>
68 
73  template <typename TValue>
75 
80  JobContext clone() const;
81 
83  void release();
84 };
85 
96 class IJob : public Polymorphic {
97  friend class JobNode;
98 
99 protected:
100  std::string instName;
101 
104 
105 public:
106  explicit IJob(const std::string& name)
107  : instName(name) {}
108 
110  virtual std::string instanceName() const {
111  return instName;
112  }
113 
115  virtual std::string className() const = 0;
116 
122  requires() const {
123  return this->getSlots();
124  }
125 
131 
135  virtual Optional<ExtJobType> provides() const = 0;
136 
142 
150  virtual void evaluate(const RunSettings& global, IRunCallbacks& callbacks) = 0;
151 
156  virtual JobContext getResult() const = 0;
157 
158 protected:
160  template <typename T>
161  SharedPtr<T> getInput(const std::string& name) const;
162 };
163 
170 class IJobDesc : public Polymorphic {
171 public:
176  virtual std::string className() const = 0;
177 
182  virtual std::string category() const = 0;
183 
185  virtual std::string tooltip() const {
186  return "";
187  }
188 
193  virtual AutoPtr<IJob> create(Optional<std::string> instanceName) const = 0;
194 };
195 
196 using CreateJobFunc = Function<AutoPtr<IJob>(std::string name)>;
197 
203 struct JobRegistrar {
210  JobRegistrar(std::string className, std::string category, CreateJobFunc func, std::string tooltip);
211 
219  JobRegistrar(std::string className,
220  std::string shortName,
221  std::string category,
222  CreateJobFunc func,
223  std::string tooltip);
224 };
225 
228 
233 RawPtr<IJobDesc> getJobDesc(const std::string& name);
234 
238 VirtualSettings::Category& addGenericCategory(VirtualSettings& connector, std::string& instanceName);
239 
240 
242 class IParticleJob : public IJob {
243 protected:
246 
247 public:
248  explicit IParticleJob(const std::string& name);
249 
250  ~IParticleJob() override;
251 
252  virtual Optional<ExtJobType> provides() const override final {
253  return JobType::PARTICLES;
254  }
255 
256  virtual JobContext getResult() const override final {
257  return result;
258  }
259 };
260 
266 class IRunJob : public IParticleJob {
267 public:
268  explicit IRunJob(const std::string& name);
269 
270  ~IRunJob() override;
271 
277  virtual AutoPtr<IRun> getRun(const RunSettings& overrides) const = 0;
278 
279 protected:
280  virtual void evaluate(const RunSettings& global, IRunCallbacks& callbacks) override final;
281 };
282 
284 class IGeometryJob : public IJob {
285 protected:
288 
289 public:
290  explicit IGeometryJob(const std::string& name)
291  : IJob(name) {}
292 
293  virtual Optional<ExtJobType> provides() const override final {
294  return JobType::GEOMETRY;
295  }
296 
297  virtual JobContext getResult() const override final {
298  return result;
299  }
300 };
301 
303 class IMaterialJob : public IJob {
304 protected:
307 
308 public:
309  explicit IMaterialJob(const std::string& name)
310  : IJob(name) {}
311 
312  virtual Optional<ExtJobType> provides() const override final {
313  return JobType::MATERIAL;
314  }
315 
316  virtual JobContext getResult() const override final {
317  return result;
318  }
319 };
320 
322 class INullJob : public IJob {
323 public:
324  explicit INullJob(const std::string& name)
325  : IJob(name) {}
326 
327  virtual Optional<ExtJobType> provides() const override final {
328  return NOTHING;
329  }
330 
331  virtual JobContext getResult() const override final {
332  return {};
333  }
334 };
335 
337 
338 #include "Job.inl.h"
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Object defining computational domain.
ArrayView< const AutoPtr< IJobDesc > > enumerateRegisteredJobs()
Returns a view of all currently registered jobs.
Definition: Job.cpp:30
JobType
Definition: Job.h:20
@ GEOMETRY
Job providing geometry.
@ MATERIAL
Job providing a material.
@ PARTICLES
Job providing particles.
VirtualSettings::Category & addGenericCategory(VirtualSettings &connector, std::string &instanceName)
Adds a common settings category, used by all jobs.
Definition: Job.cpp:43
RawPtr< IJobDesc > getJobDesc(const std::string &name)
Returns a job descriptor for given class name.
Definition: Job.cpp:34
#define NAMESPACE_SPH_END
Definition: Object.h:12
const NothingType NOTHING
Definition: Optional.h:16
Statistics gathered and periodically displayed during the run.
Container for storing particle quantities and materials.
Key-value associative container.
Object providing connection between component parameters and values exposed to the user.
Object providing safe access to continuous memory of data.
Definition: ArrayView.h:17
Base class for jobs providing a geometric shape.
Definition: Job.h:284
IGeometryJob(const std::string &name)
Definition: Job.h:290
virtual Optional< ExtJobType > provides() const override final
Specifies the type of the job, i.e. what kind of data the job provides.
Definition: Job.h:293
SharedPtr< IDomain > result
Data filled by the job when it finishes.
Definition: Job.h:287
virtual JobContext getResult() const override final
Returns the result of the job.
Definition: Job.h:297
Definition: Job.h:18
Provides a descriptor of a job that allows to create new instances.
Definition: Job.h:170
virtual AutoPtr< IJob > create(Optional< std::string > instanceName) const =0
Creates a new job instance.
virtual std::string category() const =0
Returns a name of the category of job.
virtual std::string className() const =0
Returns the class name of the job.
virtual std::string tooltip() const
Returns a help message, explaining what the job does and how it should be used.
Definition: Job.h:185
Base class for all object performing an operation in a simulation hierarchy.
Definition: Job.h:96
virtual JobContext getResult() const =0
Returns the result of the job.
virtual UnorderedMap< std::string, ExtJobType > getSlots() const =0
Lists all potential inputs of the job.
virtual VirtualSettings getSettings()=0
Returns a settings object which allows to query and modify the state of the job.
virtual std::string instanceName() const
Unique name representing this job.
Definition: Job.h:110
virtual std::string className() const =0
Name representing the type of the job (e.e. "SPH").
virtual UnorderedMap< std::string, ExtJobType > requires() const
List of slots that need to be connected to evaluate the job.
Definition: Job.h:122
SharedPtr< T > getInput(const std::string &name) const
Convenient function to return input data for slot of given name.
Definition: Job.inl.h:45
virtual Optional< ExtJobType > provides() const =0
Specifies the type of the job, i.e. what kind of data the job provides.
std::string instName
Definition: Job.h:100
IJob(const std::string &name)
Definition: Job.h:106
virtual void evaluate(const RunSettings &global, IRunCallbacks &callbacks)=0
Runs the operation provided by the job.
UnorderedMap< std::string, JobContext > inputs
Contains all input data, identified by names of input slots.
Definition: Job.h:103
Base class for jobs providing a material.
Definition: Job.h:303
IMaterialJob(const std::string &name)
Definition: Job.h:309
virtual Optional< ExtJobType > provides() const override final
Specifies the type of the job, i.e. what kind of data the job provides.
Definition: Job.h:312
SharedPtr< IMaterial > result
Data filled by the job when it finishes.
Definition: Job.h:306
virtual JobContext getResult() const override final
Returns the result of the job.
Definition: Job.h:316
Material settings and functions specific for one material.
Definition: IMaterial.h:110
Base class for jobs providing no data.
Definition: Job.h:322
virtual Optional< ExtJobType > provides() const override final
Specifies the type of the job, i.e. what kind of data the job provides.
Definition: Job.h:327
INullJob(const std::string &name)
Definition: Job.h:324
virtual JobContext getResult() const override final
Returns the result of the job.
Definition: Job.h:331
Base class for all jobs providing particle data.
Definition: Job.h:242
virtual JobContext getResult() const override final
Returns the result of the job.
Definition: Job.h:256
virtual Optional< ExtJobType > provides() const override final
Specifies the type of the job, i.e. what kind of data the job provides.
Definition: Job.h:252
~IParticleJob() override
SharedPtr< ParticleData > result
Data filled by the job when it finishes.
Definition: Job.h:245
IParticleJob(const std::string &name)
Definition: Job.cpp:105
Callbacks executed by the simulation to provide feedback to the user.
Definition: IRun.h:27
Base class for jobs running a simulation.
Definition: Job.h:266
IRunJob(const std::string &name)
Definition: Job.cpp:110
~IRunJob() override
virtual AutoPtr< IRun > getRun(const RunSettings &overrides) const =0
Returns the actual simulation object.
virtual void evaluate(const RunSettings &global, IRunCallbacks &callbacks) override final
Runs the operation provided by the job.
Definition: Job.cpp:126
Defines the interface for a run.
Definition: IRun.h:61
Data exchanged by jobs.
Definition: Job.h:52
JobContext()=default
JobContext clone() const
Duplicates the stored data.
Definition: Job.cpp:11
void release()
Releases all allocated data.
Definition: Job.cpp:24
SharedPtr< TValue > tryGetValue() const
Returns the stored value or nullptr if the provided type TValue does not match the type of the stored...
Definition: Job.inl.h:35
SharedPtr< TValue > getValue() const
Returns the stored value.
Definition: Job.inl.h:25
Building block of a simulation hierarchy.
Definition: Node.h:88
Wrapper of type value of which may or may not be present.
Definition: Optional.h:23
Non-owning wrapper of pointer.
Definition: RawPtr.h:19
Object holding various statistics about current run.
Definition: Statistics.h:22
Container storing all quantities used within the simulations.
Definition: Storage.h:230
Holds a map of virtual entries, associated with a unique name.
Generic storage and input/output routines of settings.
const EmptySettingsTag EMPTY_SETTINGS
Definition: Settings.h:32
Helper class, allowing to register job into the global list of jobs.
Definition: Job.h:203
JobRegistrar(std::string className, std::string category, CreateJobFunc func, std::string tooltip)
Registers a new job.
Definition: Job.cpp:98
Storage storage
Holds all particle positions and other quantities.
Definition: Job.h:35
Statistics stats
Final statistics of the simulation.
Definition: Job.h:38
RunSettings overrides
Overrides associated with the particle state.
Definition: Job.h:43
Base class for all polymorphic objects.
Definition: Object.h:88