9 #define BUILDING_LIBRARY 15 const std::streamsize max_line_length=1000;
18 mass_iter(orig.mass_iter), age_iter(orig.age_iter),
19 radius_iter(orig.radius_iter), luminosity_iter(orig.luminosity_iter),
20 rad_mass_iter(orig.rad_mass_iter),
21 core_boundary_iter(orig.core_boundary_iter),
22 conv_inertia_iter(orig.conv_inertia_iter),
23 rad_inertia_iter(orig.rad_inertia_iter) {}
58 const std::string mass_word=
"Mtot/Msun", age_word=
"Age(Gyr)",
59 radius_word=
"log(R/Rsun)", log_luminosity_word=
"log(L/Lsun)",
60 env_mass_word=
"m_envp/M", env_radius_word1=
"r_envp/M",
61 env_radius_word2=
"r_envp/R", Irad_word=
"I_rad", Iconv_word=
"I_env";
62 char word[max_line_length+1];
63 char line_characters[max_line_length+1];
64 while(track.get()==
'#') {
65 track.getline(line_characters, max_line_length);
67 throw Error::IO(filename,
"while reading header.");
68 std::istringstream line(line_characters);
70 for(
int word_index=0; !line.eof(); word_index++) {
74 std::string error_msg=
"failed to read track mass: ";
76 throw Error::IO(filename, error_msg +
77 (line.eof() ?
"end of line before =" :
78 "read error before ="));
80 if(!line.good())
throw Error::IO(filename, error_msg +
81 (line.eof() ?
"end of line after =" :
84 if(!line.good())
throw Error::IO(filename, error_msg +
85 (line.eof() ?
"end of line before value" :
86 "error parsing value"));
88 if(word==age_word) age_col=word_index;
89 else if(word==radius_word) radius_col=word_index;
90 else if(word==log_luminosity_word) log_luminosity_col=word_index;
91 else if(word==env_mass_word)
92 envelope_mass_col=word_index;
93 else if(word==env_radius_word1 || word==env_radius_word2)
94 rad_conv_boundary_col=word_index;
95 else if(word==Irad_word) rad_inertia_col=word_index;
96 else if(word==Iconv_word) conv_inertia_col=word_index;
104 std::cerr <<
"Reading: " << filename << std::endl;
105 std::ifstream file(filename.c_str());
107 mass_list.push_back(header.get_mass());
108 int required_columns=std::max(header.get_age_col(),
109 header.get_radius_col());
110 required_columns=std::max(required_columns,
111 header.get_log_luminosity_col());
112 required_columns=std::max(required_columns,
113 header.get_envelope_mass_col());
114 required_columns=std::max(required_columns,
115 header.get_core_boundary_col());
116 required_columns=std::max(required_columns,
117 header.get_rad_inertia_col());
118 required_columns=std::max(required_columns,
119 header.get_conv_inertia_col());
120 char line_characters[max_line_length+1];
121 std::list<double> track_ages, track_radii, track_luminosities,
122 track_rad_masses, track_core_boundaries, track_conv_inertias,
126 for(
int line_number=0; !file.eof(); line_number++) {
127 std::cerr <<
"Reading line " << line_number <<
"\r";
129 std::ostringstream error_message;
130 error_message <<
"while reading data line " << line_number;
131 if(!file.good())
throw Error::IO(filename, error_message.str());
132 file.getline(line_characters, max_line_length);
133 if(file.gcount()==0)
continue;
134 std::istringstream line(line_characters);
136 for(; !line.eof(); column++) {
139 if(column==header.get_age_col()) track_ages.push_back(value);
140 else if(column==header.get_radius_col())
141 track_radii.push_back(std::pow(10.0, value));
142 else if(column==header.get_log_luminosity_col())
143 track_luminosities.push_back(std::pow(10.0, value));
144 else if(column==header.get_envelope_mass_col())
145 track_rad_masses.push_back(value*header.get_mass());
146 else if(column==header.get_core_boundary_col())
147 track_core_boundaries.push_back(value*track_radii.back());
148 else if(column==header.get_rad_inertia_col())
149 track_rad_inertias.push_back(value/inertia_norm);
150 else if(column==header.get_conv_inertia_col())
151 track_conv_inertias.push_back(value/inertia_norm);
153 if(column<=required_columns)
154 throw Error::IO(filename, error_message.str());
156 ages.push_back(list_to_valarray(track_ages));
157 radii.push_back(list_to_valarray(track_radii));
158 luminosities.push_back(list_to_valarray(track_luminosities));
159 rad_masses.push_back(list_to_valarray(track_rad_masses));
160 core_boundaries.push_back(list_to_valarray(track_core_boundaries));
161 rad_inertias.push_back(list_to_valarray(track_rad_inertias));
162 conv_inertias.push_back(list_to_valarray(track_conv_inertias));
213 while(iter!=stop_iter) {
214 while(*iter.
mass_iter>=largest_sorted && iter!=stop_iter) {
218 if(iter==stop_iter)
break;
227 double smooth_radius,
228 double smooth_conv_inertia,
229 double smooth_rad_inertia,
230 double smooth_rad_mass,
231 double smooth_core_env_boundary,
233 int conv_inertia_nodes,
234 int rad_inertia_nodes,
236 int core_env_boundary_nodes)
238 DIR *dirstream=opendir(model_directory.c_str());
240 if(model_directory[model_directory.size()-1]==
'/') join=
"";
242 if(dirstream==NULL)
throw Error::PathNotFound(
243 "in YRECEvolution constructor.", model_directory);
244 struct dirent *entry;
245 while((entry=readdir(dirstream))) {
246 std::string fname(entry->d_name);
247 if(fname[0]!=
'.' && fname.substr(fname.size()-6)==
".track")
248 read_model_file(model_directory+join+entry->d_name);
250 if(closedir(dirstream))
throw Error::Runtime(
251 "Failed to close directory stream tied to "+model_directory+
252 " in YRECEvolution constructor.");
254 std::valarray<double> masses = list_to_valarray(mass_list);
255 interpolate_from(masses,
266 smooth_core_env_boundary,
271 core_env_boundary_nodes,
std::list< std::valarray< double > >::iterator luminosity_iter
Iterator over the arrays of stellar lg(luminosity) of the tracks.
std::list< std::valarray< double > >::iterator core_boundary_iter
Iterator over the arrays of core-envelope boundaries of the tracks.
void read_model_file(const std::string &filename)
Reads a single evolution track file.
Defines the classes for generating stellar evolution interpolators from the YREC tracks.
EvolutionIterator & operator++()
Advance all iterators to the next track.
void move(EvolutionIterator &dest, EvolutionIterator &source)
Moves source to right before destination.
std::list< double >::iterator mass_iter
Iterator over the masses of the tracks.
std::list< std::valarray< double > >::iterator conv_inertia_iter
Iterator over the arrays of convective envelope moments of inertia of the tracks. ...
An iterator over the list of extracted tracks.
YRECEvolution()
Default constructor, use load_state to get a working interpolator.
EvolutionIterator & operator=(const EvolutionIterator &rhs)
Copy rhs to *this.
void sort_masses()
Sorts the data by mass.
const double solar_radius
Radius of the sun [m].
EvolutionIterator end()
Returns an EvolutionIterator pointing to the end of all quantities.
EvolutionIterator()
Create an iterator, which must have all its *_iter members set before it can be used.
std::list< std::valarray< double > >::iterator rad_inertia_iter
Iterator over the arrays of radiative core moments of inertia of the tracks.
const double solar_mass
Mass of the sun [kg].
std::list< std::valarray< double > >::iterator age_iter
Iterator over the arrays of ages of the tracks.
bool operator==(const EvolutionIterator &rhs)
Is RHS at the same position as this?
EvolutionIterator begin()
Returns an EvolutionIterator pointing to the beginning of all quantities.
std::list< std::valarray< double > >::iterator radius_iter
Iterator over the arrays of stellar radii of the tracks.
std::list< std::valarray< double > >::iterator rad_mass_iter
Iterator over the arrays of core masses of the tracks.