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
 
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

◆ StringVector

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

Function Documentation

◆ CompareFunction()

bool CompareFunction ( std::string  a,
std::string  b 
)
50 {return a < b;}

Referenced by LoadConf().

◆ LoadClumps()

void LoadClumps ( ClumpData data,
bool  VERBOSE = false 
)

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

211 {
212 
213  logger(INFO, "LOAD CLUMP DATA");
214  LoadConf(data);
215  LoadPebbles(data);
216  LoadMass(data);
217  LoadTOI(data);
218  LoadPD(data);
219  if (VERBOSE) {
220  std::cout<<"LOADED CLUMPS"<<std::endl;
221  for (int i = 0; i < data.pebblesX.size(); i++) {
222  std::cout << data.clumpNames[i] << " mass:" << data.mass[i] << std::endl;
223  std::cout << data.clumpNames[i] << " list of pebbles:" << std::endl;
224  for (int j = 0; j < data.pebblesX[i].size(); j++) {
225  std::cout << "Pebble " << j << ": (" << data.pebblesX[i][j] << "," << data.pebblesY[i][j] << ","
226  << data.pebblesZ[i][j] << ")," << data.pebblesR[i][j] << std::endl;
227  }
228 
229  std::cout << data.clumpNames[i] << " TOI:" << std::endl;
230  std::cout << data.toi[i][0] << "," << data.toi[i][1] << "," << data.toi[i][2] << std::endl;
231  std::cout << data.toi[i][3] << "," << data.toi[i][4] << "," << data.toi[i][5] << std::endl;
232  std::cout << data.toi[i][6] << "," << data.toi[i][7] << "," << data.toi[i][8] << std::endl;
233 
234  std::cout << data.clumpNames[i] << " Principal directions:" << std::endl;
235  std::cout << data.pd[i][0] << "," << data.pd[i][1] << "," << data.pd[i][2] << std::endl;
236  std::cout << data.pd[i][3] << "," << data.pd[i][4] << "," << data.pd[i][5] << std::endl;
237  std::cout << data.pd[i][6] << "," << data.pd[i][7] << "," << data.pd[i][8] << std::endl;
238  }
239  }
240 
241 }
void LoadConf(ClumpData &a)
Definition: ClumpInput.h:82
void LoadPD(ClumpData &a)
Definition: ClumpInput.h:185
void LoadPebbles(ClumpData &a)
Definition: ClumpInput.h:111
void LoadTOI(ClumpData &a)
Definition: ClumpInput.h:161
void LoadMass(ClumpData &a)
Definition: ClumpInput.h:141
LL< Log::VERBOSE > VERBOSE
Verbose information.
Definition: Logger.cc:57
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:55
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
Double2DVector toi
Definition: ClumpInput.h:72
Double2DVector pd
Definition: ClumpInput.h:73
StringVector clumpNames
Definition: ClumpInput.h:65
Double2DVector pebblesX
Definition: ClumpInput.h:67
DoubleVector mass
Definition: ClumpInput.h:66
Double2DVector pebblesZ
Definition: ClumpInput.h:69
Double2DVector pebblesY
Definition: ClumpInput.h:68
Double2DVector pebblesR
Definition: ClumpInput.h:70

References ClumpData::clumpNames, constants::i, INFO, LoadConf(), LoadMass(), LoadPD(), LoadPebbles(), LoadTOI(), logger, ClumpData::mass, ClumpData::pd, ClumpData::pebblesR, ClumpData::pebblesX, ClumpData::pebblesY, ClumpData::pebblesZ, ClumpData::toi, and VERBOSE.

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

◆ LoadConf()

void LoadConf ( ClumpData a)

Loading available Clumps and their names

83 {
84  // Path to MCLump tool
85  a.path = getMercuryDPMSourceDir() + "/Tools/MClump/Clumps/";
86 
87  struct dirent *entry;
88  DIR *dir = opendir(a.path.c_str());
89  while ((entry = readdir(dir)) != NULL) {
90  if (entry->d_type == DT_DIR){
91  a.clumpNames.push_back(entry->d_name);
92  }
93  }
94  closedir(dir);
95 
96  // remove "." and ".." from the list of dirs (position of those in the list is OS-sensitive, hence this code)
97 
98  std::sort(a.clumpNames.begin(), a.clumpNames.end(), CompareFunction);//sort the vector
99  a.clumpNames.erase(a.clumpNames.begin());
100  a.clumpNames.erase(a.clumpNames.begin());
101 
102  // Show the names of available Clumps
103  for (int i = 0; i<a.clumpNames.size(); i++) std::cout << a.clumpNames[i] << std::endl;
104 
105 }
const std::string getMercuryDPMSourceDir()
This file is used for generating definitions that give access to CMakeVariables from within a cpp fil...
Definition: CMakeDefinitions.cc:32
bool CompareFunction(std::string a, std::string b)
Definition: ClumpInput.h:50
std::string path
Definition: ClumpInput.h:64

References ClumpData::clumpNames, CompareFunction(), getMercuryDPMSourceDir(), constants::i, and ClumpData::path.

Referenced by LoadClumps().

◆ LoadMass()

void LoadMass ( ClumpData a)

Load mass of a clump

142 {
143  logger(INFO, "Loading clump masses...");
144 
145  a.mass.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/Mass.txt").c_str(), std::ios::in | std::ios::binary);
149  std::string mass;
150  infile >> mass;
151  a.mass[i] = std::stof(mass);
152  infile.close();
153  }
154  logger(INFO, "\t OK\n");
155 }

References ClumpData::clumpNames, constants::i, INFO, logger, ClumpData::mass, and ClumpData::path.

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.

186 {
187  logger(INFO, "Loading clump PD..");
188  a.pd.resize(a.clumpNames.size());
189 
190  for (int i = 0; i < a.clumpNames.size(); i++ ){
191  std::ifstream infile((a.path + a.clumpNames[i] + "/Inertia/PD.txt").c_str(), std::ios::in | std::ios::binary);
192  std::string line{};
193  while (std::getline(infile, line)) {
194  std::istringstream iss(line);
195  std::string substring{};
196  StringVector val;
197  while (std::getline(iss, substring, ',')) val.push_back(substring);
198  for (int k = 0; k < 3; k++) a.pd[i].push_back(std::stof(val[k]));
199  }
200  infile.close();
201  }
202  logger(INFO, "\t OK\n");
203 }
std::vector< std::string > StringVector
Definition: ClumpInput.h:47

References ClumpData::clumpNames, constants::i, INFO, logger, ClumpData::path, and ClumpData::pd.

Referenced by LoadClumps().

◆ LoadPebbles()

void LoadPebbles ( ClumpData a)

Loading pebbles of a clump

112 {
113  logger(INFO, "Loading clump pebbles...");
114 
115  a.pebblesX.resize(a.clumpNames.size());
116  a.pebblesY.resize(a.clumpNames.size());
117  a.pebblesZ.resize(a.clumpNames.size());
118  a.pebblesR.resize(a.clumpNames.size());
119 
120  for (int i = 0; i < a.clumpNames.size(); i++ ){
121  std::ifstream infile((a.path + a.clumpNames[i] + "/Clump/Clump.txt").c_str(), std::ios::in | std::ios::binary);
122  std::string line{};
123  while (std::getline(infile, line)) {
124  std::istringstream iss(line);
125  std::string substring{};
126  StringVector val;
127  while (std::getline(iss, substring, ',')) val.push_back(substring);
128  a.pebblesX[i].push_back(std::stof(val[0]));
129  a.pebblesY[i].push_back(std::stof(val[1]));
130  a.pebblesZ[i].push_back(std::stof(val[2]));
131  a.pebblesR[i].push_back(std::stof(val[3]));
132  }
133  infile.close();
134  }
135  logger(INFO, "\t OK\n");
136 }

References ClumpData::clumpNames, constants::i, INFO, logger, ClumpData::path, ClumpData::pebblesR, ClumpData::pebblesX, ClumpData::pebblesY, and ClumpData::pebblesZ.

Referenced by LoadClumps().

◆ LoadTOI()

void LoadTOI ( ClumpData a)

Load tensor of inertia (TOI) of a clump

162 {
163  logger(INFO, "Loading clump TOI..");
164  a.toi.resize(a.clumpNames.size());
165 
166  for (int i = 0; i < a.clumpNames.size(); i++ ){
167  std::ifstream infile((a.path + a.clumpNames[i] + "/Inertia/TOI.txt").c_str(), std::ios::in | std::ios::binary);
168  std::string line{};
169  while (std::getline(infile, line)) {
170  std::istringstream iss(line);
171  std::string substring{};
172  StringVector val;
173  while (std::getline(iss, substring, ',')) val.push_back(substring);
174  for (int k = 0; k < 3; k++) a.toi[i].push_back(std::stof(val[k]));
175  }
176  infile.close();
177  }
178  logger(INFO, "\t OK\n");
179 }

References ClumpData::clumpNames, constants::i, INFO, logger, ClumpData::path, and ClumpData::toi.

Referenced by LoadClumps().

◆ RandomDouble()

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

Referenced by multiParticleT1::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

248 {
249  ClumpData new_data = data;
250  new_data.pd[clump_index] = new_pd;
251  return new_data;
252 }
Definition: ClumpInput.h:61

References ClumpData::pd.

Referenced by multiParticleT1::setupInitialConditions().

◆ UniformRandomPDs()

DoubleVector UniformRandomPDs ( )

Generate random (and isotropically distributed) principal directions frame

262  {
263 
264  Vec3D n1, n2, n3, ref;
265 
266  // basis vector n1
267  double r1 = RandomDouble(2) - 1.0;
268  double r2 = RandomDouble(1);
269 
270  double theta = acos(r1); // Note that for isotropy of n1 theta is NOT uniform!
271  double phi = 2 * M_PI * r2;
272 
273  n1 = Vec3D(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
274 
275  // basis vector n2
276  r1 = RandomDouble(1);
277  r2 = RandomDouble(1);
278 
279  theta = acos(2 * r1 - 1); // Note that for isotropy of n1 theta is NOT uniform!
280  phi = 2 * M_PI * r2;
281 
282  ref = Vec3D(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
283  n2 = Vec3D::cross(ref, n1); n2.normalise();
284  n3 = Vec3D::cross(n1, n2); n3.normalise();
285  return DoubleVector{n1.X, n1.Y, n1.Z, n2.X, n2.Y, n2.Z, n3.X, n3.Y, n3.Z};
286 
287 }
double RandomDouble(double Max)
Definition: ClumpInput.h:53
std::vector< double > DoubleVector
Definition: ClumpInput.h:45
Definition: Vector.h:51
Mdouble Y
Definition: Vector.h:66
Mdouble Z
Definition: Vector.h:66
static Vec3D cross(const Vec3D &a, const Vec3D &b)
Calculates the cross product of two Vec3D: .
Definition: Vector.cc:163
Mdouble X
the vector components
Definition: Vector.h:66
void normalise()
Makes this Vec3D unit length.
Definition: Vector.cc:123
Mdouble cos(Mdouble x)
Definition: ExtendedMath.cc:64
Mdouble sin(Mdouble x)
Definition: ExtendedMath.cc:44

References mathsFunc::cos(), Vec3D::cross(), Vec3D::normalise(), RandomDouble(), mathsFunc::sin(), Vec3D::X, Vec3D::Y, and Vec3D::Z.

Referenced by multiParticleT1::setupInitialConditions().