SPH
Sandbox.cpp
Go to the documentation of this file.
1 #include "Sph.h"
2 #include "physics/Functions.h"
3 #include "post/Analysis.h"
4 #include <fstream>
5 #include <iostream>
6 
7 using namespace Sph;
8 
9 int main(int argc, char** argv) {
10  /* BinaryInput input;
11  Storage storage;
12  Statistics stats;
13  input.load(Path(argv[1]), storage, stats);
14  TotalAngularMomentum angmom;
15  Float L0 = angmom.evaluate(storage)[2];
16 
17  std::ofstream ofs("angmom.txt");
18  for (Size i = 1; i < argc; ++i) {
19  std::cout << "Processing " << argv[i] << std::endl;
20  input.load(Path(argv[i]), storage, stats);
21  const Float L = angmom.evaluate(storage)[2];
22  const Float t = stats.get<Float>(StatisticsId::RUN_TIME);
23  ofs << t << " " << (L - L0) / L0 << std::endl;
24  }*/
25 
26  /*std::ofstream ts("tillotson.txt");
27  TillotsonEos eos(BodySettings::getDefaults());
28  for (Float u = 0._f; u < 1.e7_f; u += 1.e5_f) {
29  for (Float rho = 1000._f; rho < 4000._f; rho += 30) {
30  Float p = eos.evaluate(rho, u)[0];
31  ts << rho << " " << u << " " << p << "\n";
32  }
33  ts << "\n";
34  }
35  return 0;*/
36 
37  /*CompressedInput input;
38  Storage storage;
39  Statistics dummy;
40  input.load(Path(argv[1]), storage, dummy);
41 
42  ArrayView<const Float> m = storage.getValue<Float>(QuantityId::MASS);
43  Float m_tot = std::accumulate(m.begin(), m.end(), 0._f);
44 
45  ArrayView<const Float> damage = storage.getValue<Float>(QuantityId::DAMAGE);
46  Array<Size> idxs;
47  for (Size i = 0; i < damage.size(); ++i) {
48  if (damage[i] == 1.) {
49  idxs.push(i);
50  }
51  }
52  storage.remove(idxs, Storage::IndicesFlag::INDICES_SORTED);
53 
54  m = storage.getValue<Float>(QuantityId::MASS);
55  Array<Size> comp = Post::findLargestComponent(storage, 1._f, EMPTY_FLAGS);
56  Float m_core = 0._f;
57  for (Size i : comp) {
58  m_core += m[i];
59  }
60  std::cout << "Core mass fraction = " << m_core / m_tot << std::endl;
61 
62 
63  return 0;
64 
65  // SharedPtr<IScheduler> scheduler = Factory::getScheduler();
66  std::ofstream ofs("converg.txt");*/
67 
68  /*Storage reference;
69  input.load(Path(argv[argc - 1]), reference, dummy);*/
70 
71 
72  struct Stats {
73  Float core;
74  Float fragment;
75  Float damaged;
76  };
77 
78  std::map<Size, Stats> stats;
80  std::mutex mutex;
81  parallelFor(*scheduler, 1, argc, [&](Size i) {
82  std::cout << "Processing " << argv[i] << std::endl;
83  Storage storage;
84  Statistics dummy;
85  BinaryInput input;
86  input.load(Path(argv[i]), storage, dummy);
87  const Size numParticles = storage.getParticleCnt();
88 
89  Array<Size> idxs;
91  for (Size i = 0; i < damage.size(); ++i) {
92  if (damage[i] > 0.9_f) {
93  idxs.push(i);
94  }
95  }
97  Array<Size> comps;
99  Size comp1 = std::count(comps.begin(), comps.end(), 0);
100  Size comp2 = std::count_if(comps.begin(), comps.end(), [](Size i) { return i != 0; });
101  std::unique_lock<std::mutex> lock(mutex);
102  stats[numParticles] = {
103  Float(comp1) / numParticles,
104  Float(comp2) / numParticles,
105  Float(idxs.size()) / numParticles,
106  };
107  });
108 
109  std::ofstream ofs("converg.txt");
110  for (const auto& p : stats) {
111  ofs << p.first << " " << p.second.core << " " << p.second.fragment << " " << p.second.damaged
112  << "\n";
113  }
114 
115  /*std::map<float, float> map;
116  map[3.f] = 10;
117  map[2.6f] = 14;
118  map[2.2f] = 18;
119  map[1.8f] = 25;
120  map[1.4f] = 34;
121  map[1.f] = 46;
122 
123  Float Q1 = getImpactEnergy(50.e3_f, map.at(1.8f) * 1.e3_f / 2._f, 6.e3_f);
124  Float Q1_D = evalBenzAsphaugScalingLaw(100.e3_f, 2700._f);
125  Float d = getImpactorRadius(381.e3_f / 2._f, 6.e3_f, Q1 / Q1_D, 2700._f);*/
126  // std::cout << "Q/Q_D^* = " << Q1 / Q1_D << std::endl;
127  // std::cout << "d_imp = " << 2 * d / 1.e3_f << " km " << std::endl;
128  // std::cout << "d_check = " << 2 * getImpactorRadius(50.e3_f, 4.e3_f, Q1 / Q1_D, 2700._f) << std::endl;
129 
130  return 0;
131 }
Various function for interpretation of the results of a simulation.
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Definition: Globals.h:13
@ DAMAGE
Damage.
int main(int argc, char **argv)
Definition: Sandbox.cpp:9
INLINE void parallelFor(IScheduler &scheduler, const Size from, const Size to, TFunctor &&functor)
Executes a functor concurrently from all available threads.
Definition: Scheduler.h:98
Includes common headers.
INLINE TCounter size() const
Definition: ArrayView.h:101
INLINE Iterator< StorageType > end() noexcept
Definition: Array.h:462
INLINE void push(U &&u)
Adds new element to the end of the array, resizing the array if necessary.
Definition: Array.h:306
INLINE TCounter size() const noexcept
Definition: Array.h:193
INLINE Iterator< StorageType > begin() noexcept
Definition: Array.h:450
Input for the binary file, generated by BinaryOutput.
Definition: Output.h:352
virtual Outcome load(const Path &path, Storage &storage, Statistics &stats) override
Loads data from the file into the storage.
Definition: Output.cpp:718
Object representing a path on a filesystem.
Definition: Path.h:17
Object holding various statistics about current run.
Definition: Statistics.h:22
Definition: Stats.h:13
Container storing all quantities used within the simulations.
Definition: Storage.h:230
Size getParticleCnt() const
Returns the number of particles.
Definition: Storage.cpp:445
@ INDICES_SORTED
Use if the given array is already sorted (optimization)
void remove(ArrayView< const Size > idxs, const Flags< IndicesFlag > flags=EMPTY_FLAGS)
Removes specified particles from the storage.
Definition: Storage.cpp:756
Array< TValue > & getValue(const QuantityId key)
Retrieves a quantity values from the storage, given its key and value type.
Definition: Storage.cpp:191
SharedPtr< IScheduler > getScheduler(const RunSettings &settings=RunSettings::getDefaults())
Definition: Factory.cpp:178
Size findComponents(const Storage &storage, const Float particleRadius, const Flags< ComponentFlag > flags, Array< Size > &indices)
Finds and marks connected components (a.k.a. separated bodies) in the array of vertices.
Definition: Analysis.cpp:86
Definition: MemoryPool.h:5