8 #define BUILDING_LIBRARY 11 #include "../Core/Functions.h" 16 const std::valarray<double> &core_mass
19 int first_core_index = 0;
21 first_core_index < static_cast<int>(core_mass.size())
23 core_mass[first_core_index] == 0
25 return first_core_index;
35 interpolation_queue.
calculate(num_threads);
43 ] = interpolation_queue.
result();
48 const std::valarray<double> &tabulated_masses,
49 const std::valarray<double> &tabulated_feh,
50 const std::list< std::valarray<double> > &tabulated_ages,
51 const std::vector< std::list< std::valarray<double> > >
52 &tabulated_quantities,
53 const std::vector<double> &smoothing,
54 const std::vector<int> &nodes,
55 const std::vector<bool> &vs_log_age,
56 const std::vector<bool> &log_quantity,
66 size_t num_tracks = (tabulated_masses.size()
68 tabulated_feh.size());
70 assert(tabulated_ages.size() == num_tracks);
77 typedef std::list< std::valarray<double> >::const_iterator
80 track_quantity_iter ages_iter=tabulated_ages.begin();
84 std::list< std::valarray<double> > log_ages;
87 int quantity_index = 0;
91 assert(tabulated_quantities[quantity_index].size()
95 track_iter[quantity_index] =
96 tabulated_quantities[quantity_index].begin();
99 std::list<const std::valarray<double> *> to_delete;
103 for(
size_t grid_index = 0; grid_index < num_tracks; ++grid_index) {
105 std::clog <<
"Grid point " << grid_index
107 << tabulated_masses[grid_index % tabulated_masses.size()]
109 << tabulated_feh[grid_index
111 tabulated_masses.size()]
114 int first_core_index = (
115 tabulated_quantities[
MRAD].empty()
121 first_core_index ==
static_cast<int>(
122 track_iter[
MRAD]->size()
125 (*(track_iter[MRAD]))[first_core_index] == 0
131 (*ages_iter)[std::max(0, first_core_index - 1)]
134 log_ages.push_back(std::log(*ages_iter));
137 int quantity_index = 0;
150 int first_interp_index;
151 const std::valarray<double> *interp_quantity;
152 if(log_quantity[quantity_index]) {
153 interp_quantity =
new std::valarray<double>(
154 std::log(*(track_iter[quantity_index]))
156 to_delete.push_back(interp_quantity);
158 interp_quantity = &(*(track_iter[quantity_index]));
160 first_interp_index = 0;
161 else if(log_quantity[quantity_index])
162 first_interp_index = first_core_index;
164 first_interp_index = std::max(0, first_core_index - 1);
168 vs_log_age[quantity_index]
169 ? &(log_ages.back()[first_interp_index])
170 : &((*ages_iter)[first_interp_index])
172 &((*interp_quantity)[first_interp_index]),
173 ages_iter->size() - first_interp_index,
174 nodes[quantity_index],
175 smoothing[quantity_index],
183 size_t quantity_index = 0;
187 ++track_iter[quantity_index];
191 std::list<
const std::valarray<double> *>::iterator
192 del_iter = to_delete.begin();
193 del_iter != to_delete.end();
221 std::vector<const OneArgumentDiffFunction*>
227 std::vector<const OneArgumentDiffFunction*>::iterator
228 track = quantity_tracks->begin();
229 track != quantity_tracks->end();
232 if(*track)
delete *track;
239 std::cerr <<
"Loading interpolator from " << filename << std::endl;
242 std::ifstream ifs(filename.c_str());
243 boost::archive::text_iarchive ia(ifs);
251 std::cerr <<
"Saving interpolator to " << filename << std::endl;
253 std::ofstream ofs(filename.c_str());
254 boost::archive::text_oarchive oa(ofs);
std::valarray< double > __track_masses
The index of the first core quantity.
struct LIB_PUBLIC EvolvingStellarQuantity
Opaque struct to cast to/from StellarEvolution::EvolvingStellarQuantity pointers. ...
std::vector< bool > __log_quantity
Was the interpolation of the log(corresponding quantity)?
Declare a class for a stellar evolution quantity which is the sum of two other quantities.
std::valarray< double > __track_feh
The stellar [Fe/H] values for which evolution tracks are available.
int grid_index() const
The grid index of the currently selected result.
Core::InterpolatingFunctionALGLIB * result() const
The currently selected interupolation result.
A class for stellar properties that depend on age.
int find_first_core_index(const std::valarray< double > &core_mass) const
Return the index of the first non-zero value in the argument.
std::vector< std::vector< const OneArgumentDiffFunction * > > __interpolated_quantities
The interpolated stellar evolution quantities for each track.
void push_back(const double *x, const double *y, size_t npoints, int nodes, double smoothing, int quantity_id, int grid_index)
Add an interpolation taks to the queue.
A class that handles a queue of interpolation tasks. Also functions as an iterator over the results...
virtual void save_state(const std::string &filename="../interp_state_data") const
Serializes the interpolation state to file.
double __core_formation
The age at which the core starts forming in Gyr.
int quantity_id() const
The quantity ID of the currently selected result.
void perform_queued_interpolations(InterpolationQueue &interpolation_queue, unsigned num_threads=1)
Perform all queued interpolations.
A class representing a function that is identically zero.
void pop_front()
Move to the next result in the queue (earlier results are no longer accessible.
void create_from(const std::valarray< double > &tabulated_masses, const std::valarray< double > &tabulated_feh, const std::list< std::valarray< double > > &tabulated_ages, const std::vector< std::list< std::valarray< double > > > &tabulated_quantities, const std::vector< double > &smoothing, const std::vector< int > &nodes, const std::vector< bool > &vs_log_age, const std::vector< bool > &log_quantity, unsigned num_threads)
Fully setup an object created by the default constructor.
const int NUM_QUANTITIES
The number of interpolation quantities currentyl supported.
virtual void load_state(const std::string &filename="../interp_state_data")
Loads data from serialization.
QuantityID
Defines the quantities tracked by stellar evolution and their order.
void delete_tracks()
Free all evolution tracks, rendering all created quantities unuseable!
virtual EvolvingStellarQuantity * operator()(QuantityID quantity, double mass, double feh) const
Return a single quantity interpolation to a given mass and [Fe/H].
std::vector< bool > __vs_log_age
Was the interpolation of the corresponding quantity vs. log(age)?
void calculate(unsigned num_threads)
Mass of the stellar core in (low mass stars only).
Defines the StellarEvolution class needed for interpolating among stellar evolution tracks...