ModelSpace
All Classes Namespaces Functions Variables Enumerations Pages
DispersionEngine.h
1/******************************************************************************
2* Copyright (c) ATTX LLC 2024. All Rights Reserved.
3*
4* This software and associated documentation (the "Software") are the
5* proprietary and confidential information of ATTX, LLC. The Software is
6* furnished under a license agreement between ATTX and the user organization
7* and may be used or copied only in accordance with the terms of the agreement.
8* Refer to 'license/attx_license.adoc' for standard license terms.
9*
10* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
11* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION
12* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or
13* transmitted in any form or by any means, for any purpose, without the express
14* written permission of ATTX, LLC.
15******************************************************************************/
16/*
17Normal Random Distribution Header File
18
19Author: Alex Reynolds
20*/
21#ifndef DISPERSION_ENGINE_H
22#define DISPERSION_ENGINE_H
23
24#include <vector>
25
26#include "data_management/GraphTreeObject.h"
27#include "data_management/DataIO.hpp"
29#include "NormalRandom.hpp"
30#include "architecture/Executive.h"
31
32namespace modelspace {
33
34 /**
35 * @brief Struct to store all data associated with dispersion
36 */
37 struct Dispersion {
38 Dispersion(std::string nme, double d_v, clockwerk::GraphTreeObject* parent)
39 : default_val(d_v), value(parent, nme, 0.0) {}
40 double default_val;
41 clockwerk::DataIO<double> value;
42 clockwerk::DataIO<double>& operator () () {return value;}
43 };
44
45 /**
46 * @brief Struct to store all data associated with uniform dispersion
47 */
48 struct UniformDispersion : public Dispersion {
49 UniformDispersion(std::string nme, double d_v, double mn, double mx, clockwerk::GraphTreeObject* parent)
50 : Dispersion(nme, d_v, parent), min(mn), max(mx) {}
51 double min;
52 double max;
53 };
54
55 /**
56 * @brief Struct to store all data associated with normal dispersion
57 */
58 struct NormalDispersion : public Dispersion {
59 NormalDispersion(std::string nme, double d_v, double mn, double sd, clockwerk::GraphTreeObject* parent)
60 : Dispersion(nme, d_v, parent), mean(mn), stdev(sd) {}
61 double mean;
62 double stdev;
63 };
64
65 const int HASH_MULTIPLIER = 37;
66 const int HASH_ADDER = 3;
67
68 /**
69 * @brief Class to generate input dispersions for the simulation
70 *
71 * The dispersion engine class is used to generate input dispersions
72 * for use in Monte Carlo and similar simulations. It generates
73 * dispersion values which parameters and inputs on models can map
74 * to, allowing for full dispersion-->model traceability.
75 *
76 * The dispersion engine registers dispersions
77 */
78 class DispersionEngine : public clockwerk::GraphTreeObject {
79 public:
80 // Standard constructor. Takes executive
81 DispersionEngine(clockwerk::Executive &e) : exc(&e) {}
82 ~DispersionEngine();
83
84 /// @brief Function to initialize the dispersion engine
85 /// @param seed The seed to be used in hashing the rng
86 /// @param run The run number
87 /// @param nruns The number of runs to generate dispersions for
88 void initialize(int seed, int run, int nruns=1000);
89
90 /// @brief Function to set the value of a dispersion
91 /// @param dispersion The dispersion to set the value for
92 void setUniformValue(UniformDispersion* dispersion_ptr);
93
94 /// @brief Function to set the value of a dispersion
95 /// @param dispersion The dispersion to set the value for
96 void setNormalValue(NormalDispersion* dispersion_ptr);
97
98 /// @brief Function to generate a uniform input dispersion
99 /// @param name The name of the dispersion
100 /// @param default_value The "run zero" value for the undispersed case
101 /// @param min The minimum for the uniform distribution
102 /// @param max The maximum for the uniform distribution
103 /// @return The uniform dispersion struct created in the generation process
104 UniformDispersion& createUniformInputDispersion(const std::string &name,
105 double default_val, double min, double max);
106
107 /// @brief Function to generate a normal input dispersion
108 /// @param name The name of the dispersion
109 /// @param default_value The "run zero" value for the undispersed case
110 /// @param mean The mean for the normal distribution
111 /// @param stdev The standard deviation of the normal distribution
112 /// @return The normal dispersion struct created in the generation process
113 NormalDispersion& createNormalInputDispersion(const std::string &name,
114 double default_val, double mean, double stdev);
115
116 /// @brief Call operator to get pointer to dispersion matching string
117 /// @param The name of the knob to search for
118 /// @return Pointer to the base dispersion object. nullptr if match not found
119 Dispersion* operator () (const std::string &query);
120
121 /// @brief Function to dump all knob information
122 void dump();
123
124 // Pointer to the executive object
125 clockwerk::Executive* exc;
126
127 // The has seed generated by the dispersion engine
128 int hash_seed = 0;
129 protected:
130 /// @brief Function to generate a hashed seed from run number and seed
131 /// @param run_number The monte carlo run number
132 /// @param seed The seed to affect hash generation
133 /// @return Seed generated by hash function
134 int _hash(int run_number, int seed);
135
136 // Variable to store our hash value
137 int _hash_value;
138
139 // Variable to store the current run number
140 int _run_number;
141
142 // Variable to set the number of runs
143 int _nruns;
144
145 // Our lists to store each type of dispersion info
146 std::vector<UniformDispersion*> _uniform_dispersions;
147 std::vector<NormalDispersion*> _normal_dispersions;
148
149 // Our distribution engines for generating varied inputs
150 UniformRandom<double>* _uniform_dist = nullptr;
151 NormalRandom<double>* _normal_dist = nullptr;
152 };
153
154}
155
156#endif
Class for inter-object communication.
Definition DataIO.hpp:46
DataIO(GraphTreeObject *data_parent, std::string data_name, T initial_value)
Constructor for the DataIO object.
Definition DataIO.hpp:134
Central control mechanism to run simulations and software.
Definition Executive.h:43
Base class for object organization.
Definition GraphTreeObject.h:87
Class to generate input dispersions for the simulation.
Definition DispersionEngine.h:78
int _hash(int run_number, int seed)
Function to generate a hashed seed from run number and seed.
Definition DispersionEngine.cpp:134
NormalDispersion & createNormalInputDispersion(const std::string &name, double default_val, double mean, double stdev)
Function to generate a normal input dispersion.
Definition DispersionEngine.cpp:86
Dispersion * operator()(const std::string &query)
Call operator to get pointer to dispersion matching string.
Definition DispersionEngine.cpp:100
void setNormalValue(NormalDispersion *dispersion_ptr)
Function to set the value of a dispersion.
Definition DispersionEngine.cpp:57
void setUniformValue(UniformDispersion *dispersion_ptr)
Function to set the value of a dispersion.
Definition DispersionEngine.cpp:42
UniformDispersion & createUniformInputDispersion(const std::string &name, double default_val, double min, double max)
Function to generate a uniform input dispersion.
Definition DispersionEngine.cpp:72
void dump()
Function to dump all knob information.
Definition DispersionEngine.cpp:116
void initialize(int seed, int run, int nruns=1000)
Function to initialize the dispersion engine.
Definition DispersionEngine.cpp:31
Class to generate random numbers according to normal distribution.
Definition NormalRandom.hpp:40
Class to generate random numbers according to uniform distribution.
Definition UniformRandom.hpp:42
Class to propagate CR3BP dynamics in characteristic units.
Definition ConfigurationWriter.cpp:18
Struct to store all data associated with dispersion.
Definition DispersionEngine.h:37
Struct to store all data associated with normal dispersion.
Definition DispersionEngine.h:58
Struct to store all data associated with uniform dispersion.
Definition DispersionEngine.h:48