ClumpInput.h File Reference
#include <algorithm>
#include <dirent.h>
#include <sys/types.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <sstream>
#include "Math/Matrix.h"
#include <CMakeDefinitions.h>

Go to the source code of this file.

Classes

struct  ClumpData
 

Typedefs

typedef std::vector< doubleDoubleVector
 loads clump configuration More...
 
typedef std::vector< DoubleVectorDouble2DVector
 
typedef std::vector< std::string > StringVector
 

Functions

bool CompareFunction (std::string a, std::string b)
 
double RandomDouble (double Max)
 
void LoadConf (ClumpData &a)
 
void LoadPebbles (ClumpData &a)
 
void LoadMass (ClumpData &a)
 
void LoadTOI (ClumpData &a)
 
void LoadPD (ClumpData &a)
 
void LoadClumps (ClumpData &data, bool VERBOSE=false)
 
ClumpData RotateClump (ClumpData data, int clump_index, DoubleVector new_pd)
 
DoubleVector UniformRandomPDs ()
 

Typedef Documentation

◆ Double2DVector

typedef std::vector<DoubleVector> Double2DVector

◆ DoubleVector

typedef std::vector<double> DoubleVector

loads clump configuration

This module loads clump configuration produced by MClump tool

◆ StringVector

typedef std::vector<std::string> StringVector

Function Documentation

◆ CompareFunction()

bool CompareFunction ( std::string  a,
std::string  b 
)
31 {return a < b;}
Scalar * b
Definition: benchVecAdd.cpp:17
const Scalar * a
Definition: level2_cplx_impl.h:32

References a, and b.

Referenced by LoadConf().

◆ LoadClumps()

void LoadClumps ( ClumpData data,
bool  VERBOSE = false 
)

// Main function that loads all the necessary files to initiate Clumps

192 {
193 
194  logger(INFO, "LOAD CLUMP DATA");
195  LoadConf(data);
196  LoadPebbles(data);
197  LoadMass(data);
198  LoadTOI(data);
199  LoadPD(data);
200  if (VERBOSE) {
201  std::cout<<"LOADED CLUMPS"<<std::endl;
202  for (int i = 0; i < data.pebblesX.size(); i++) {
203  std::cout << data.clumpNames[i] << " mass:" << data.mass[i] << std::endl;
204  std::cout << data.clumpNames[i] << " list of pebbles:" << std::endl;
205  for (int j = 0; j < data.pebblesX[i].size(); j++) {
206  std::cout << "Pebble " << j << ": (" << data.pebblesX[i][j] << "," << data.pebblesY[i][j] << ","
207  << data.pebblesZ[i][j] << ")," << data.pebblesR[i][j] << std::endl;
208  }
209 
210  std::cout << data.clumpNames[i] << " TOI:" << std::endl;
211  std::cout << data.toi[i][0] << "," << data.toi[i][1] << "," << data.toi[i][2] << std::endl;
212  std::cout << data.toi[i][3] << "," << data.toi[i][4] << "," << data.toi[i][5] << std::endl;
213  std::cout << data.toi[i][6] << "," << data.toi[i][7] << "," << data.toi[i][8] << std::endl;
214 
215  std::cout << data.clumpNames[i] << " Principal directions:" << std::endl;
216  std::cout << data.pd[i][0] << "," << data.pd[i][1] << "," << data.pd[i][2] << std::endl;
217  std::cout << data.pd[i][3] << "," << data.pd[i][4] << "," << data.pd[i][5] << std::endl;
218  std::cout << data.pd[i][6] << "," << data.pd[i][7] << "," << data.pd[i][8] << std::endl;
219  }
220  }
221 
222 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
void LoadConf(ClumpData &a)
Definition: ClumpInput.h:63
void LoadPD(ClumpData &a)
Definition: ClumpInput.h:166
void LoadPebbles(ClumpData &a)
Definition: ClumpInput.h:92
void LoadTOI(ClumpData &a)
Definition: ClumpInput.h:142
void LoadMass(ClumpData &a)
Definition: ClumpInput.h:122
LL< Log::VERBOSE > VERBOSE
Verbose information.
Definition: Logger.cc:36
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
int data[]
Definition: Map_placement_new.cpp:1
#define INFO(i)
Definition: mumps_solver.h:54
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References data, i, INFO, j, LoadConf(), LoadMass(), LoadPD(), LoadPebbles(), LoadTOI(), logger, and VERBOSE.

Referenced by ChangingTOIParticle::ChangingTOIParticle(), and clumpTest::clumpTest().

◆ LoadConf()

void LoadConf ( ClumpData a)

Loading available Clumps and their names

64 {
65  // Path to MCLump tool
66  a.path = getMercuryDPMSourceDir() + "/Tools/MClump/Clumps/";
67 
68  struct dirent *entry;
69  DIR *dir = opendir(a.path.c_str());
70  while ((entry = readdir(dir)) != NULL) {
71  if (entry->d_type == DT_DIR){
72  a.clumpNames.push_back(entry->d_name);
73  }
74  }
75  closedir(dir);
76 
77  // remove "." and ".." from the list of dirs (position of those in the list is OS-sensitive, hence this code)
78 
79  std::sort(a.clumpNames.begin(), a.clumpNames.end(), CompareFunction);//sort the vector
80  a.clumpNames.erase(a.clumpNames.begin());
81  a.clumpNames.erase(a.clumpNames.begin());
82 
83  // Show the names of available Clumps
84  for (int i = 0; i<a.clumpNames.size(); i++) std::cout << a.clumpNames[i] << std::endl;
85 
86 }
bool CompareFunction(std::string a, std::string b)
Definition: ClumpInput.h:31
const std::string getMercuryDPMSourceDir()
This file is used for generating definitions that give access to CMakeVariables from within a cpp fil...
Definition: Configuration/CMakeDefinitions.cc:10

References a, CompareFunction(), getMercuryDPMSourceDir(), and i.

Referenced by LoadClumps().

◆ LoadMass()

void LoadMass ( ClumpData a)

Load mass of a clump

123 {
124  logger(INFO, "Loading clump masses...");
125 
126  a.mass.resize(a.clumpNames.size());
127 
128  for (int i = 0; i < a.clumpNames.size(); i++ ){
129  std::ifstream infile((a.path + a.clumpNames[i] + "/Inertia/Mass.txt").c_str(), std::ios::in | std::ios::binary);
130  std::string mass;
131  infile >> mass;
132  a.mass[i] = std::stof(mass);
133  infile.close();
134  }
135  logger(INFO, "\t OK\n");
136 }
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286

References a, i, INFO, logger, and oomph::Global_string_for_annotation::string().

Referenced by LoadClumps().

◆ LoadPD()

void LoadPD ( ClumpData a)

Load pre-computed principal directions (PDs) of a clump. Normally MClump tool aligns PDs with the global Cartesian axes.

167 {
168  logger(INFO, "Loading clump PD..");
169  a.pd.resize(a.clumpNames.size());
170 
171  for (int i = 0; i < a.clumpNames.size(); i++ ){
172  std::ifstream infile((a.path + a.clumpNames[i] + "/Inertia/PD.txt").c_str(), std::ios::in | std::ios::binary);
173  std::string line{};
174  while (std::getline(infile, line)) {
175  std::istringstream iss(line);
176  std::string substring{};
178  while (std::getline(iss, substring, ',')) val.push_back(substring);
179  for (int k = 0; k < 3; k++) a.pd[i].push_back(std::stof(val[k]));
180  }
181  infile.close();
182  }
183  logger(INFO, "\t OK\n");
184 }
std::vector< std::string > StringVector
Definition: ClumpInput.h:28
char char char int int * k
Definition: level2_impl.h:374
val
Definition: calibrate.py:119
line
Definition: calibrate.py:103

References a, i, INFO, k, calibrate::line, logger, oomph::Global_string_for_annotation::string(), and calibrate::val.

Referenced by LoadClumps().

◆ LoadPebbles()

void LoadPebbles ( ClumpData a)

Loading pebbles of a clump

93 {
94  logger(INFO, "Loading clump pebbles...");
95 
96  a.pebblesX.resize(a.clumpNames.size());
97  a.pebblesY.resize(a.clumpNames.size());
98  a.pebblesZ.resize(a.clumpNames.size());
99  a.pebblesR.resize(a.clumpNames.size());
100 
101  for (int i = 0; i < a.clumpNames.size(); i++ ){
102  std::ifstream infile((a.path + a.clumpNames[i] + "/Clump/Clump.txt").c_str(), std::ios::in | std::ios::binary);
103  std::string line{};
104  while (std::getline(infile, line)) {
105  std::istringstream iss(line);
106  std::string substring{};
108  while (std::getline(iss, substring, ',')) val.push_back(substring);
109  a.pebblesX[i].push_back(std::stof(val[0]));
110  a.pebblesY[i].push_back(std::stof(val[1]));
111  a.pebblesZ[i].push_back(std::stof(val[2]));
112  a.pebblesR[i].push_back(std::stof(val[3]));
113  }
114  infile.close();
115  }
116  logger(INFO, "\t OK\n");
117 }

References a, i, INFO, calibrate::line, logger, oomph::Global_string_for_annotation::string(), and calibrate::val.

Referenced by LoadClumps(), and MClump::main().

◆ LoadTOI()

void LoadTOI ( ClumpData a)

Load tensor of inertia (TOI) of a clump

143 {
144  logger(INFO, "Loading clump TOI..");
145  a.toi.resize(a.clumpNames.size());
146 
147  for (int i = 0; i < a.clumpNames.size(); i++ ){
148  std::ifstream infile((a.path + a.clumpNames[i] + "/Inertia/TOI.txt").c_str(), std::ios::in | std::ios::binary);
149  std::string line{};
150  while (std::getline(infile, line)) {
151  std::istringstream iss(line);
152  std::string substring{};
154  while (std::getline(iss, substring, ',')) val.push_back(substring);
155  for (int k = 0; k < 3; k++) a.toi[i].push_back(std::stof(val[k]));
156  }
157  infile.close();
158  }
159  logger(INFO, "\t OK\n");
160 }

References a, i, INFO, k, calibrate::line, logger, oomph::Global_string_for_annotation::string(), and calibrate::val.

Referenced by LoadClumps().

◆ RandomDouble()

double RandomDouble ( double  Max)
35 {return Max*((double) rand() / (RAND_MAX));}

Referenced by ChangingTOIParticle::setupInitialConditions(), and UniformRandomPDs().

◆ RotateClump()

ClumpData RotateClump ( ClumpData  data,
int  clump_index,
DoubleVector  new_pd 
)

Changes PDs of the clump - sufficient for clump to be properly rotated

229 {
230  ClumpData new_data = data;
231  new_data.pd[clump_index] = new_pd;
232  return new_data;
233 }
Definition: ClumpInput.h:42
Double2DVector pd
Definition: ClumpInput.h:54

References data, and ClumpData::pd.

Referenced by ChangingTOIParticle::setupInitialConditions().

◆ UniformRandomPDs()

DoubleVector UniformRandomPDs ( )

Generate random (and isotropically distributed) principal directions frame

243  {
244 
245  Vec3D n1, n2, n3, ref;
246 
247  // basis vector n1
248  double r1 = RandomDouble(2) - 1.0;
249  double r2 = RandomDouble(1);
250 
251  double theta = acos(r1); // Note that for isotropy of n1 theta is NOT uniform!
252  double phi = 2 * M_PI * r2;
253 
254  n1 = Vec3D(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
255 
256  // basis vector n2
257  r1 = RandomDouble(1);
258  r2 = RandomDouble(1);
259 
260  theta = acos(2 * r1 - 1); // Note that for isotropy of n1 theta is NOT uniform!
261  phi = 2 * M_PI * r2;
262 
263  ref = Vec3D(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
264  n2 = Vec3D::cross(ref, n1); n2.normalise();
265  n3 = Vec3D::cross(n1, n2); n3.normalise();
266  return DoubleVector{n1.X, n1.Y, n1.Z, n2.X, n2.Y, n2.Z, n3.X, n3.Y, n3.Z};
267 
268 }
AnnoyingScalar cos(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:136
AnnoyingScalar acos(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:138
AnnoyingScalar sin(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:137
double RandomDouble(double Max)
Definition: ClumpInput.h:34
std::vector< double > DoubleVector
loads clump configuration
Definition: ClumpInput.h:26
Definition: Kernel/Math/Vector.h:30
Mdouble Y
Definition: Kernel/Math/Vector.h:45
Mdouble Z
Definition: Kernel/Math/Vector.h:45
static Vec3D cross(const Vec3D &a, const Vec3D &b)
Calculates the cross product of two Vec3D: .
Definition: Vector.cc:143
Mdouble X
the vector components
Definition: Kernel/Math/Vector.h:45
void normalise()
Makes this Vec3D unit length.
Definition: Vector.cc:103
#define M_PI
Definition: main.h:121
double theta
Definition: two_d_biharmonic.cc:236

References acos(), cos(), Vec3D::cross(), M_PI, Vec3D::normalise(), RandomDouble(), sin(), BiharmonicTestFunctions2::theta, Vec3D::X, Vec3D::Y, and Vec3D::Z.

Referenced by ChangingTOIParticle::setupInitialConditions().