mirror of
https://github.com/nasa/trick.git
synced 2024-12-30 09:58:53 +00:00
Merge pull request #487 from nasa/VariableInformation
Added additional variable information to the Monte_Runs data file.
This commit is contained in:
commit
24894ea08a
@ -42,6 +42,9 @@ namespace Trick {
|
||||
*/
|
||||
void set_unit(std::string in_unit) { this->unit = in_unit; }
|
||||
|
||||
// Composite the various elements of this MonteVar.
|
||||
virtual std::string describe_variable() = 0;
|
||||
|
||||
/** Class MonteCarlo is a friend so it can use the get_next_value method.
|
||||
* The get_next_value method needs to be protected so users cannot use it in the input file
|
||||
*/
|
||||
|
@ -56,6 +56,9 @@ namespace Trick {
|
||||
*/
|
||||
MonteVarCalculated(std::string name, std::string unit = "");
|
||||
|
||||
// Describes the various properties of this variable.
|
||||
std::string describe_variable();
|
||||
|
||||
protected:
|
||||
virtual std::string get_next_value();
|
||||
|
||||
|
@ -94,6 +94,8 @@ namespace Trick {
|
||||
*
|
||||
* @param in_file_name the name of the file containing this variable's values
|
||||
*/
|
||||
|
||||
|
||||
void set_file_name(std::string in_file_name);
|
||||
|
||||
/**
|
||||
@ -103,6 +105,9 @@ namespace Trick {
|
||||
*/
|
||||
void set_column(unsigned int in_column);
|
||||
|
||||
// Describes the various properties of this variable.
|
||||
std::string describe_variable();
|
||||
|
||||
protected:
|
||||
virtual std::string get_next_value();
|
||||
|
||||
|
@ -51,6 +51,9 @@ namespace Trick {
|
||||
|
||||
void set_value(double in_value);
|
||||
|
||||
// Describes the properties of this variable.
|
||||
std::string describe_variable();
|
||||
|
||||
protected:
|
||||
virtual std::string get_next_value();
|
||||
|
||||
|
@ -185,6 +185,9 @@ namespace Trick {
|
||||
*/
|
||||
double get_absolute_max() const { return (randist.rel_max) ? (randist.mu + randist.max) : randist.max; }
|
||||
|
||||
// Describes the properties of this variable.
|
||||
std::string describe_variable();
|
||||
|
||||
protected:
|
||||
virtual std::string get_next_value();
|
||||
|
||||
|
@ -87,7 +87,6 @@ public:
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
///@brief Sub class for object that includes a <random> engine and a distribution
|
||||
///
|
||||
///@note partial specialization exists for Distribution = std::poisson_distribution<int>
|
||||
@ -134,7 +133,6 @@ public:
|
||||
|
||||
virtual ~StlRandomGeneratorSub() { }
|
||||
|
||||
|
||||
///@brief return next pseudo-random number
|
||||
virtual TRICK_GSL_RETURN_TYPE operator()()
|
||||
{
|
||||
@ -148,7 +146,6 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
///@brief reset seed for underlying uniform pseudo-random number generator
|
||||
virtual void set_seed(unsigned long in_seed)
|
||||
{
|
||||
@ -156,7 +153,6 @@ public:
|
||||
engine.seed(initialSeed);
|
||||
}
|
||||
|
||||
|
||||
///@brief reset parameters for the distribution
|
||||
///
|
||||
///@param a is min for FLAT, mean for GAUSSION and POISSON
|
||||
@ -210,8 +206,6 @@ private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#ifdef _HAVE_TR1_RANDOM
|
||||
|
||||
// implement one of these template FULL specializations
|
||||
|
@ -440,10 +440,10 @@ int Trick::MonteCarlo::prepare_run(MonteRun *curr_run) {
|
||||
}
|
||||
}
|
||||
/** <li> Create the data file </ul>*/
|
||||
fprintf(run_data_file, "%05u ", curr_run->id);
|
||||
fprintf(run_data_file, "%05u\t", curr_run->id);
|
||||
for (std::vector<std::string>::size_type i = 0; i < variables.size(); ++i) {
|
||||
if (i>0) {
|
||||
fprintf(run_data_file, " ");
|
||||
fprintf(run_data_file, "\t");
|
||||
}
|
||||
fprintf(run_data_file, "%s", variables[i]->value.c_str());
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <libgen.h>
|
||||
|
||||
@ -57,25 +56,36 @@ int Trick::MonteCarlo::open_file(std::string file_name, FILE** file_ptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Trick::MonteCarlo::write_to_run_files(std::string file_name) {
|
||||
|
||||
/** <li> Write the number of runs. */
|
||||
fprintf(run_header_file, "trick.mc_set_num_runs(%d)\n", num_runs);
|
||||
|
||||
/** <li> Write the variables. */
|
||||
fprintf(run_data_file, "#run_num ");
|
||||
for (std::vector<std::string>::size_type i = 0; i < variables.size(); ++i) {
|
||||
if (variables[i]->unit.empty()) {
|
||||
fprintf(run_header_file, "\nvar%zu = trick.MonteVarFile(\"%s\", \"%s\", %zu)\n",
|
||||
i, variables[i]->name.c_str(), file_name.c_str(), i + 2);
|
||||
}
|
||||
else {
|
||||
fprintf(run_header_file, "\nvar%zu = trick.MonteVarFile(\"%s\", \"%s\", %zu, \"%s\")\n",
|
||||
i, variables[i]->name.c_str(), file_name.c_str(), i + 2, variables[i]->unit.c_str());
|
||||
}
|
||||
fprintf(run_header_file, "trick_mc.mc.add_variable(var%zu)\n", i);
|
||||
fprintf(run_data_file, "%s ", variables[i]->name.c_str());
|
||||
void Trick::MonteCarlo::write_to_run_files(std::string file_name)
|
||||
{
|
||||
// Write a description of each variable.
|
||||
for(std::vector<std::string>::size_type i = 0; i < variables.size(); ++i)
|
||||
{
|
||||
fprintf(run_data_file, "%s\n", variables[i]->describe_variable().c_str());
|
||||
}
|
||||
|
||||
// Data file header.
|
||||
fprintf(run_data_file, "# RUN\t");
|
||||
for(std::vector<std::string>::size_type i = 0; i < variables.size(); ++i)
|
||||
{
|
||||
fprintf(run_data_file, "%s\t", variables[i]->name.c_str());
|
||||
}
|
||||
fprintf(run_data_file, "\n");
|
||||
|
||||
// Write the input file lines that configured the initial state of the Monte Carlo simulation.
|
||||
fprintf(run_header_file, "trick.mc_set_num_runs(%d)\n", num_runs);
|
||||
for (std::vector<std::string>::size_type i = 0; i < variables.size(); ++i)
|
||||
{
|
||||
if (variables[i]->unit.empty())
|
||||
{
|
||||
fprintf(run_header_file, "\nvar%zu = trick.MonteVarFile(\"%s\", \"%s\", %zu)\n",
|
||||
i, variables[i]->name.c_str(), file_name.c_str(), i + 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(run_header_file, "\nvar%zu = trick.MonteVarFile(\"%s\", \"%s\", %zu, \"%s\")\n",
|
||||
i, variables[i]->name.c_str(), file_name.c_str(), i + 2, variables[i]->unit.c_str());
|
||||
}
|
||||
fprintf(run_header_file, "trick_mc.mc.add_variable(var%zu)\n", i);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "trick/MonteVarCalculated.hh"
|
||||
#include "trick/memorymanager_c_intf.h"
|
||||
@ -15,6 +16,18 @@ Trick::MonteVarCalculated::MonteVarCalculated(std::string in_name, std::string i
|
||||
}
|
||||
}
|
||||
|
||||
// Composite the various properties of this MonteVarCalculated.
|
||||
std::string Trick::MonteVarCalculated::describe_variable()
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "#NAME:\t" << this->name << "\n"
|
||||
<< "#TYPE:\tCALCULATED\n"
|
||||
<< "#UNIT:\t" << this->unit << "\n";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string Trick::MonteVarCalculated::get_next_value() {
|
||||
char buffer[128];
|
||||
if (ref2 != NULL) {
|
||||
|
@ -17,7 +17,6 @@ Trick::MonteVarFile::MonteVarFile(std::string in_name, std::string in_file_name,
|
||||
|
||||
set_file_name(in_file_name);
|
||||
buffer = new char[4096];
|
||||
|
||||
}
|
||||
|
||||
Trick::MonteVarFile::~MonteVarFile() {
|
||||
@ -25,6 +24,20 @@ Trick::MonteVarFile::~MonteVarFile() {
|
||||
delete buffer;
|
||||
}
|
||||
|
||||
// Composite the various properties of this MonteVarFile.
|
||||
std::string Trick::MonteVarFile::describe_variable()
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "#NAME:\t\t" << this->name << "\n"
|
||||
<< "#TYPE:\t\tFILE\n"
|
||||
<< "#UNIT:\t\t" << this->unit << "\n"
|
||||
<< "#FILE:\t\t" << this->file_name << "\n"
|
||||
<< "#COLUMN:\t" << this->column << "\n";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string Trick::MonteVarFile::get_next_value() {
|
||||
if (input_file_stream->good()) {
|
||||
double file_value;
|
||||
|
@ -9,13 +9,24 @@ Trick::MonteVarFixed::MonteVarFixed(std::string in_name, double in_value, std::s
|
||||
this->unit = in_unit;
|
||||
}
|
||||
|
||||
// Composite the various properties of this MonteVarFixed.
|
||||
std::string Trick::MonteVarFixed::describe_variable()
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "#NAME:\t" << this->name << "\n"
|
||||
<< "#TYPE:\tFIXED\n"
|
||||
<< "#UNIT:\t" << this->unit << "\n";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void Trick::MonteVarFixed::set_value(double in_value) {
|
||||
std::ostringstream string_stream;
|
||||
string_stream << std::setprecision(15) << in_value ;
|
||||
this->value = string_stream.str();
|
||||
}
|
||||
|
||||
|
||||
std::string Trick::MonteVarFixed::get_next_value() {
|
||||
std::ostringstream string_stream;
|
||||
if (unit.empty()) {
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
|
||||
#include "trick/MonteVar.hh"
|
||||
#include "trick/MonteVarRandom.hh"
|
||||
#include "trick/exec_proto.h"
|
||||
|
||||
@ -66,6 +67,27 @@ Trick::MonteVarRandom::~MonteVarRandom()
|
||||
delete stlGenPtr;
|
||||
}
|
||||
|
||||
// Composite the various properties of this MonteVarRandom.
|
||||
std::string Trick::MonteVarRandom::describe_variable()
|
||||
{
|
||||
std::string dist_list[] = {"GAUSSIAN", "FLAT", "POISSON"};
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "#NAME:\t\t\t" << this->name << "\n"
|
||||
<< "#TYPE:\t\t\tRANDOM\n"
|
||||
<< "#UNIT:\t\t\t" << this->unit << "\n"
|
||||
<< "#DISTRIBUTION:\t" << dist_list[this->randist.type] << "\n"
|
||||
<< "#SEED:\t\t\t" << this->randist.seed << "\n"
|
||||
<< "#SIGMA:\t\t\t" << this->randist.sigma << "\n"
|
||||
<< "#MU:\t\t\t" << this->randist.mu << "\n"
|
||||
<< "#MIN:\t\t\t" << this->randist.min << "\n"
|
||||
<< "#MAX:\t\t\t" << this->randist.max << "\n"
|
||||
<< "#REL_MIN:\t\t" << this->randist.rel_min << "\n"
|
||||
<< "#REL_MAX:\t\t" << this->randist.rel_max << "\n";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void Trick::MonteVarRandom::set_seed(unsigned long seed) {
|
||||
randist.seed = seed;
|
||||
if (engineType != NO_ENGINE && stlGenPtr) {
|
||||
|
Loading…
Reference in New Issue
Block a user