Commit 1ed80141 authored by Quentin Khan's avatar Quentin Khan

Add more comments to fuseDistributions

parent 72aadd98
...@@ -18,7 +18,13 @@ ...@@ -18,7 +18,13 @@
#include "Files/FFmaGenericLoader.hpp" #include "Files/FFmaGenericLoader.hpp"
/**
* \brief Print programe usage
*
* \param progname The name of the program.
*
* \note Use `argv[0]` as progname.
*/
void usage(const std::string& progname) { void usage(const std::string& progname) {
std::size_t start = progname.find_last_of('/'); std::size_t start = progname.find_last_of('/');
std::string name = progname.substr(start+1); std::string name = progname.substr(start+1);
...@@ -64,12 +70,19 @@ void usage(const std::string& progname) { ...@@ -64,12 +70,19 @@ void usage(const std::string& progname) {
using FReal = double; using FReal = double;
/**
* \brief Particle object
*/
struct Particle { struct Particle {
FPoint<FReal> pos; FPoint<FReal> pos; ///< Particle position in space
FReal val; FReal val; ///< Particle physical value
}; };
/// Distribution options /**
* \brief Distribution options
*
* Holds the tranformations that must be applied to a particle distribution.
*/
struct distribution { struct distribution {
/// Distribution filename /// Distribution filename
std::string filename = ""; std::string filename = "";
...@@ -81,14 +94,26 @@ struct distribution { ...@@ -81,14 +94,26 @@ struct distribution {
FReal scale = 1; FReal scale = 1;
}; };
/**
* \brief Main program parameters
*/
struct parameters { struct parameters {
/// Output distribution file
std::string output_filename; std::string output_filename;
/// Particles distributions to combine
std::vector<distribution> distributions; std::vector<distribution> distributions;
/// Length to add to the output distribution box
FReal extra_length; FReal extra_length;
}; };
/**
* \brief Helper method to parse the arguments that apply to one distribution.
*
* \param args A vector holding the command line arguments
* \param i Index of the current argument in args
*
* \return A vector of distribution objects
*/
std::vector<distribution> subparse_file(const std::vector<std::string>& args, std::size_t& i) { std::vector<distribution> subparse_file(const std::vector<std::string>& args, std::size_t& i) {
std::stringstream sstr; std::stringstream sstr;
// Grid layout // Grid layout
...@@ -100,22 +125,26 @@ std::vector<distribution> subparse_file(const std::vector<std::string>& args, st ...@@ -100,22 +125,26 @@ std::vector<distribution> subparse_file(const std::vector<std::string>& args, st
while(i < args.size() && args[i] != "--file") { while(i < args.size() && args[i] != "--file") {
sstr.clear(); sstr.clear();
if(false) { if(false) {// false for alignment of the other cases
} else if(args[i] == "-s") { } else if(args[i] == "-s") {
// Parse scale argument
++i; ++i;
sstr.str(args.at(i)); sstr.str(args.at(i));
sstr >> dist.scale; sstr >> dist.scale;
} else if (args[i] == "-c") { } else if (args[i] == "-c") {
// Parse offset from center argument
++i; ++i;
char c; // Used to discard the ':' from argument format char c; // Used to discard the ':' from argument format
sstr.str(args.at(i)); sstr.str(args.at(i));
sstr >> dist.offset[0] >> c >> dist.offset[1] >> c >> dist.offset[2]; sstr >> dist.offset[0] >> c >> dist.offset[1] >> c >> dist.offset[2];
} else if(args[i] == "-g") { } else if(args[i] == "-g") {
// Parse grid layout
++i; ++i;
char c; // Used to discard the ':' from argument format char c; // Used to discard the ':' from argument format
sstr.str(args.at(i)); sstr.str(args.at(i));
sstr >> gx >> c >> gy >> c >> gz; sstr >> gx >> c >> gy >> c >> gz;
} else if(args[i] == "-r") { } else if(args[i] == "-r") {
// Parse rotation angle
++i; ++i;
char c; // Used to discard the ':' from argument format char c; // Used to discard the ':' from argument format
sstr.str(args.at(i)); sstr.str(args.at(i));
...@@ -134,8 +163,9 @@ std::vector<distribution> subparse_file(const std::vector<std::string>& args, st ...@@ -134,8 +163,9 @@ std::vector<distribution> subparse_file(const std::vector<std::string>& args, st
--i; --i;
} }
// If a grid layout was specified, duplicate the distribution for each cell
// in the grid
if(gx > 1 || gy > 1 || gz > 1) { if(gx > 1 || gy > 1 || gz > 1) {
// Compute offset of lowest left grid offset // Compute offset of lowest left grid offset
FFmaGenericLoader<FReal> loader(dist.filename); FFmaGenericLoader<FReal> loader(dist.filename);
FReal box_width = loader.getBoxWidth() * dist.scale; FReal box_width = loader.getBoxWidth() * dist.scale;
...@@ -162,24 +192,31 @@ std::vector<distribution> subparse_file(const std::vector<std::string>& args, st ...@@ -162,24 +192,31 @@ std::vector<distribution> subparse_file(const std::vector<std::string>& args, st
return distributions; return distributions;
} }
/**
* \brief Main argument parse function
*
* \param args A vector holding the command line arguments
*/
parameters parse(const std::vector<std::string>& args) { parameters parse(const std::vector<std::string>& args) {
parameters params; parameters params;
std::stringstream sstr; std::stringstream sstr; // Use to convert strings to numbers
for(std::size_t i = 1; i < args.size(); ++i) { for(std::size_t i = 1; i < args.size(); ++i) {
if(args[i] == "--help") { if(args[i] == "--help") {
usage(args[0]); usage(args[0]);
exit(0); exit(0);
} else if(args[i] == "--file") { } else if(args[i] == "--file") {
// Parse a new distribution specification
++i; ++i;
auto ds = subparse_file(args, i); auto ds = subparse_file(args, i);
params.distributions.insert(params.distributions.end(), params.distributions.insert(params.distributions.end(),
ds.begin(), ds.end()); ds.begin(), ds.end());
} else if(args[i] == "--extra-length") { } else if(args[i] == "--extra-length") {
// Parse extra length parameter
++i; ++i;
sstr.str(args.at(i)); sstr.str(args.at(i));
sstr >> params.extra_length; sstr >> params.extra_length;
} else if(args[i] == "-fout") { } else if(args[i] == "-fout") {
// Parse output file name
++i; ++i;
params.output_filename = args.at(i); params.output_filename = args.at(i);
} else { } else {
...@@ -189,7 +226,12 @@ parameters parse(const std::vector<std::string>& args) { ...@@ -189,7 +226,12 @@ parameters parse(const std::vector<std::string>& args) {
return params; return params;
} }
/**
* \brief Rotate a particle around the origin
*
* \param p particle to rotate
* \param dist distribution transformation specification
*/
void rotate(Particle& p, const distribution& dist) { void rotate(Particle& p, const distribution& dist) {
// Rotate around x axis // Rotate around x axis
if(dist.rot[0] > 1e-5 || dist.rot[0] < -1e-5) { if(dist.rot[0] > 1e-5 || dist.rot[0] < -1e-5) {
...@@ -213,9 +255,6 @@ void rotate(Particle& p, const distribution& dist) { ...@@ -213,9 +255,6 @@ void rotate(Particle& p, const distribution& dist) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
auto params = parse({argv,argv+argc}); auto params = parse({argv,argv+argc});
...@@ -235,7 +274,7 @@ int main(int argc, char** argv) { ...@@ -235,7 +274,7 @@ int main(int argc, char** argv) {
FPoint<FReal> center = loader.getBoxCenter(); FPoint<FReal> center = loader.getBoxCenter();
// Temp particle // Load each particle and apply the distribution transformations
Particle p; Particle p;
for(std::size_t i = 0; i < count; ++i) { for(std::size_t i = 0; i < count; ++i) {
loader.fillParticle(&p.pos, &p.val); loader.fillParticle(&p.pos, &p.val);
...@@ -257,8 +296,8 @@ int main(int argc, char** argv) { ...@@ -257,8 +296,8 @@ int main(int argc, char** argv) {
} }
} }
// Write final distribution // Write final distribution
FPoint<FReal> center(0,0,0); FPoint<FReal> center(0,0,0);
// Compute final box width // Compute final box width
FReal box_width = 2 * (axis_max + params.extra_length); FReal box_width = 2 * (axis_max + params.extra_length);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment