SPH
IoJobs.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "run/Job.h"
5 
7 
8 enum class UnitEnum {
9  SI,
10  CGS,
11  NBODY,
12 };
13 
14 class LoadFileJob : public IParticleJob {
15 private:
16  Path path;
18 
19 public:
20  LoadFileJob(const Path& path = Path("file.ssf"))
21  : IParticleJob("")
22  , path(path.native()) {}
23 
24  virtual std::string instanceName() const override {
25  if (instName.empty()) {
26  return "Load '" + path.fileName().native() + "'";
27  } else {
28  return instName;
29  }
30  }
31 
32  virtual std::string className() const override {
33  return "load file";
34  }
35 
37  return {};
38  }
39 
40  virtual VirtualSettings getSettings() override;
41 
42  virtual void evaluate(const RunSettings& global, IRunCallbacks& callbacks) override;
43 };
44 
45 FlatMap<Size, Path> getFileSequence(const Path& firstFile);
46 
47 class FileSequenceJob : public IParticleJob {
48 private:
49  Path firstFile;
50 
51  int maxFps = 10;
52 
53 public:
54  FileSequenceJob(const std::string& name, const Path& firstFile = Path("file_0000.ssf"))
55  : IParticleJob(name)
56  , firstFile(firstFile.native()) {}
57 
58  virtual std::string className() const override {
59  return "load sequence";
60  }
61 
63  return {};
64  }
65 
66  virtual VirtualSettings getSettings() override;
67 
68  virtual void evaluate(const RunSettings& global, IRunCallbacks& callbacks) override;
69 };
70 
71 class SaveFileJob : public IParticleJob {
72 private:
73  RunSettings settings;
74 
75 public:
76  explicit SaveFileJob(const std::string& name);
77 
78  virtual std::string instanceName() const override {
79  if (instName.empty()) {
80  const Path path(settings.get<std::string>(RunSettingsId::RUN_OUTPUT_NAME));
81  return "Save to '" + path.fileName().native() + "'";
82  } else {
83  return instName;
84  }
85  }
86 
87  virtual std::string className() const override {
88  return "save file";
89  }
90 
92  return { { "particles", JobType::PARTICLES } };
93  }
94 
95  virtual VirtualSettings getSettings() override;
96 
97  virtual void evaluate(const RunSettings& global, IRunCallbacks& callbacks) override;
98 };
99 
100 class SaveMeshJob : public IParticleJob {
101 private:
102  Path path = Path("surface.ply");
103  Float resolution = 1.e4_f;
104  Float level = 0.13_f;
105  Float smoothingMult = 1._f;
106  bool anisotropic = false;
107  bool scaleToUnit = false;
108  bool refine = false;
109 
110 public:
111  explicit SaveMeshJob(const std::string& name)
112  : IParticleJob(name) {}
113 
114  virtual std::string className() const override {
115  return "save mesh";
116  }
117 
119  return { { "particles", JobType::PARTICLES } };
120  }
121 
122  virtual VirtualSettings getSettings() override;
123 
124  virtual void evaluate(const RunSettings& global, IRunCallbacks& UNUSED(callbacks)) override;
125 };
126 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Definition: Globals.h:13
FlatMap< Size, Path > getFileSequence(const Path &firstFile)
Definition: IoJobs.cpp:107
UnitEnum
Definition: IoJobs.h:8
@ PARTICLES
Job providing particles.
#define UNUSED(x)
Definition: Object.h:37
#define NAMESPACE_SPH_END
Definition: Object.h:12
@ NBODY
Main N-body simulation, using initial conditions either from SPH (handoff) or manually specified.
virtual void evaluate(const RunSettings &global, IRunCallbacks &callbacks) override
Runs the operation provided by the job.
Definition: IoJobs.cpp:139
virtual std::string className() const override
Name representing the type of the job (e.e. "SPH").
Definition: IoJobs.h:58
virtual UnorderedMap< std::string, ExtJobType > getSlots() const override
Lists all potential inputs of the job.
Definition: IoJobs.h:62
FileSequenceJob(const std::string &name, const Path &firstFile=Path("file_0000.ssf"))
Definition: IoJobs.h:54
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
Definition: IoJobs.cpp:93
Container of key-value pairs.
Definition: FlatMap.h:19
std::string instName
Definition: Job.h:100
Base class for all jobs providing particle data.
Definition: Job.h:242
Callbacks executed by the simulation to provide feedback to the user.
Definition: IRun.h:27
virtual void evaluate(const RunSettings &global, IRunCallbacks &callbacks) override
Runs the operation provided by the job.
Definition: IoJobs.cpp:36
virtual UnorderedMap< std::string, ExtJobType > getSlots() const override
Lists all potential inputs of the job.
Definition: IoJobs.h:36
LoadFileJob(const Path &path=Path("file.ssf"))
Definition: IoJobs.h:20
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
Definition: IoJobs.cpp:24
virtual std::string className() const override
Name representing the type of the job (e.e. "SPH").
Definition: IoJobs.h:32
virtual std::string instanceName() const override
Unique name representing this job.
Definition: IoJobs.h:24
Object representing a path on a filesystem.
Definition: Path.h:17
std::string native() const
Returns the native version of the path.
Definition: Path.cpp:71
Path fileName() const
Returns the filename of the path.
Definition: Path.cpp:47
SaveFileJob(const std::string &name)
Definition: IoJobs.cpp:195
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
Definition: IoJobs.cpp:204
virtual void evaluate(const RunSettings &global, IRunCallbacks &callbacks) override
Runs the operation provided by the job.
Definition: IoJobs.cpp:222
virtual UnorderedMap< std::string, ExtJobType > getSlots() const override
Lists all potential inputs of the job.
Definition: IoJobs.h:91
virtual std::string instanceName() const override
Unique name representing this job.
Definition: IoJobs.h:78
virtual std::string className() const override
Name representing the type of the job (e.e. "SPH").
Definition: IoJobs.h:87
SaveMeshJob(const std::string &name)
Definition: IoJobs.h:111
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
Definition: IoJobs.cpp:241
virtual void evaluate(const RunSettings &global, IRunCallbacks &UNUSED(callbacks)) override
Definition: IoJobs.cpp:264
virtual UnorderedMap< std::string, ExtJobType > getSlots() const override
Lists all potential inputs of the job.
Definition: IoJobs.h:118
virtual std::string className() const override
Name representing the type of the job (e.e. "SPH").
Definition: IoJobs.h:114
TValue get(const TEnum idx, std::enable_if_t<!std::is_enum< std::decay_t< TValue >>::value, int >=0) const
Returns a value of given type from the settings.
Definition: Settings.h:326
Holds a map of virtual entries, associated with a unique name.
@ RUN_OUTPUT_NAME
File name of the output file (including extension), where d is a placeholder for output number.
Wrapper of an enum.
Definition: Settings.h:37