SPH
MeshToSsf.cpp
Go to the documentation of this file.
1 #include "Sph.h"
2 #include "post/MeshFile.h"
4 #include <iostream>
5 
6 using namespace Sph;
7 
8 int main(int argc, char* argv[]) {
9  if (argc != 3) {
10  std::cout << "Usage: meshtossf mesh.ext out.ssf" << std::endl;
11  return 0;
12  }
13 
14  Path meshPath(argv[1]);
15  AutoPtr<IMeshFile> meshLoader;
16  if (meshPath.extension() == Path("ply")) {
17  meshLoader = makeAuto<PlyFile>();
18  } else if (meshPath.extension() == Path("tab")) {
19  meshLoader = makeAuto<TabFile>();
20  } else if (meshPath.extension() == Path("obj")) {
21  meshLoader = makeAuto<ObjFile>();
22  } else {
23  std::cout << "Unknown file format: " << meshPath.extension().native() << std::endl;
24  return -1;
25  }
26 
27  Expected<Array<Triangle>> triangles = meshLoader->load(meshPath);
28  if (!triangles) {
29  std::cout << "Cannot load mesh file: " << triangles.error() << std::endl;
30  return -1;
31  }
32 
33  MeshDomain domain(std::move(triangles.value())); // , AffineMatrix::rotateX(PI / 2._f));
34  HexagonalPacking packing;
35  Array<Vector> r = packing.generate(SEQUENTIAL, 500000, domain);
36  for (Size i = 0; i < r.size(); ++i) {
37  r[i][H] *= 1.5_f; // eta
38  }
39  Storage storage(makeAuto<NullMaterial>(BodySettings::getDefaults()));
40  storage.insert<Vector>(QuantityId::POSITION, OrderEnum::SECOND, std::move(r));
41  Statistics stats;
42  stats.set(StatisticsId::RUN_TIME, 0._f);
43  stats.set(StatisticsId::TIMESTEP_VALUE, 1._f);
44  Path ssfPath(argv[2]);
45  BinaryOutput output(ssfPath);
46 
47  output.dump(storage, stats);
48 
49  return 0;
50 }
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
Domain represented by triangular mesh.
int main(int argc, char *argv[])
Definition: MeshToSsf.cpp:8
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
@ SECOND
Quantity with 1st and 2nd derivative.
SequentialScheduler SEQUENTIAL
Global instance of the sequential scheduler.
Definition: Scheduler.cpp:43
Includes common headers.
@ RUN_TIME
Current time of the simulation in code units. Does not necessarily have to be 0 when run starts.
@ TIMESTEP_VALUE
Current value of timestep.
@ H
Definition: Vector.h:25
Generic dynamically allocated resizable storage.
Definition: Array.h:43
INLINE TCounter size() const noexcept
Definition: Array.h:193
Wrapper of pointer that deletes the resource from destructor.
Definition: AutoPtr.h:15
Output saving data to binary data without loss of precision.
Definition: Output.h:335
virtual Expected< Path > dump(const Storage &storage, const Statistics &stats) override
Saves data from particle storage into the file.
Definition: Output.cpp:512
Wrapper of type that either contains a value of given type, or an error message.
Definition: Expected.h:25
const Error & error() const
Returns the error message.
Definition: Expected.h:94
Type & value()
Returns the reference to expected value.
Definition: Expected.h:69
Hexagonal close packing.
Definition: Distribution.h:72
virtual Array< Vector > generate(IScheduler &scheduler, const Size n, const IDomain &domain) const override
Generates the requested number of particles in the domain.
Domain represented by triangular mesh.
Definition: MeshDomain.h:30
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 extension() const
Returns the extension of the filename.
Definition: Path.cpp:59
static const Settings & getDefaults()
\brief Returns a reference to object containing default values of all settings.
Object holding various statistics about current run.
Definition: Statistics.h:22
Statistics & set(const StatisticsId idx, TValue &&value)
Sets new values of a statistic.
Definition: Statistics.h:52
Container storing all quantities used within the simulations.
Definition: Storage.h:230
Quantity & insert(const QuantityId key, const OrderEnum order, const TValue &defaultValue)
Creates a quantity in the storage, given its key, value type and order.
Definition: Storage.cpp:270
Definition: MemoryPool.h:5