SEVN
Loading...
Searching...
No Matches
star.h
Go to the documentation of this file.
1//
2// Created by mario on 09/02/19.
3//
4
5#ifndef SEVN_STELLAR_H
6#define SEVN_STELLAR_H
7
8#include <vector>
9#include <IO.h>
10#include <lookup_and_phases.h>
11#include <property.h>
12#include <errhand.h>
13#include <iostream>
14#include <utilities.h>
15#include <memory>
16#include <params.h>
17#include <algorithm>
18#include <sevnlog.h>
19#include <chrono>
20#include <limits>
21
22
24
25//using namespace std;
26
27#define FOR4 for(size_t _i = 0; _i < 4; _i++)
28
29class Binstar;
30class supernova;
31class Staremnant;
32
33//TODO, Leave the class star free from binary method moving all of them to the binary class?
39class Star{
40
41private:
42
43 friend class Binstar;
44
45
46 supernova *SN = nullptr;
49 std::unique_ptr<utilities::ListGenerator> dtout_generator=nullptr;
51 if (dtout_generator!= nullptr){
52 if (!dtout_generator->empty()){
53 return true;
54 }
55 }
56
57 return false;
58 }
59
63 bool auxiliary_star=false;
65 bool tobe_SNIA=false;
66 bool isconaked;
78
79
80
81 std::vector<std::vector<double>> allstates;
82 std::string sntype;
83
84
86
87 IO *io;
88 std::vector<std::string> init_params;
89 size_t ID;
90 std::string name;
91
92 std::vector<double> state;
93 std::vector<std::vector<std::vector<double>*>> tables; //A vector of vector of pointers to a vector<double>
94 vector<Property*> properties;
95 //TODO transform raw pointers to unique_ptr? (see issue #47)
96 //vector<std::unique_ptr<Property>> properties;
97 std::vector<double> dtout_phase;
98 unsigned long rseed=0;
104 void set_rzams();
105
110 void reset_staremnant();
111
115 void default_destructor();
116
117protected:
118
119 double tphase[Nphases] = {0.}; //Initialise all the elements to 0
120
122 std::vector<std::vector<double>> tphase_neigh;
123 double tf,tini;
124 double dtout;
126
127 double Z0;
128 double Z;
129 double mzams0;
130 double mzams;
131 double rzams0;
132 double rzams=-1;
133 size_t jtrack_counter=0;
134 double MCO_max=std::nan("");
136 double MHE_min=std::nan("");
138
139 double Mtrack[4] = {0.}; //zams masses of the neighbors (per metallicity), initialise all the elements to 0
140 double Ztrack[2] = {0.}; //Z of the neighbor tracks, initialise all the elements to 0
141
142
143
149 inline double age_phase (std::string phase) {
150
151 if (phase=="zams")
152 return tphase[MainSequence];
153 else if (phase=="tms" or phase=="tams")
155 else if (phase=="hsb" or phase=="shb")
156 return tphase[ShellHBurning];
157 else if (phase=="cheb")
158 return tphase[CoreHeBurning];
159 else if (phase=="tcheb")
161 else if (phase=="hesb" or phase=="sheb")
162 return tphase[ShellHeBurning];
163 else if (phase=="end")
164 return tphase[Remnant];
165 else
166 svlog.critical("Phase "+phase+" unknown.",__FILE__,__LINE__,sevnstd::notimplemented_error());
167
168 }
169
170 void remnant(){
171
172 for (auto &prop : properties) {
173 prop->set_remnant(this);
174 }
175
176 }
177
179
180 for (auto &prop : properties) {
181 prop->set_remnant_in_bse(this,b);
182 }
183
184 }
185
186 void turn_into_remnant();
187
189
191
192
209 inline void initialise_auxiliary_star(const Star *s, double mzams, double Z, std::string tini, bool pureHE){
210 //Default initialiser reset the extern variable mtrand resetting the random seed by default.
211 auto saved_mtrand = utilities::mtrand;
212 //io and ID are already set now, we have just to define params and call the default_initialiser.
213 //params is a vector of string containing:
214 //0-mzams; 1-Z; 2-spin; 3-sn_type; 4-tini; 5-tf; 6-dtout;
215 init_params = s->get_initparams(true); //This is safe since the vector assignement op makes a deep copy.
216 change_params(mzams, Z, tini); //Modify init params
217 default_initialiser(false,pureHE);
218 //Now restore the extern variable mtrand so that its has been reseed inside default initaliser we can instead start
219 //again from the old generator (this avoid to restart the number generation after a change of track)
220 utilities::mtrand = saved_mtrand;
221 }
222
232 inline void initialise_auxiliary_star(const Star *s, double mzams, double Z, double tini, bool pureHE){
233 std::string tini_ss = tini==utilities::NULL_DOUBLE ? utilities::NULL_STR : utilities::n2s(tini,__FILE__,__LINE__);
234 initialise_auxiliary_star(s,mzams,Z,tini_ss,pureHE);
235 }
236
237
238
239public:
240
241
242 double ttimes[4];
245 size_t pos[4];
246 double *times_in[4];
249 double vkick[4];
250 inline double get_last_fromtable(Lookup::Tables tab_id, unsigned int interpolating_track) const {
251 return tables[tab_id][interpolating_track]->back();
252 }
253
254
255
266
275 Star(IO *_io, std::vector<std::string> &params, size_t &_ID, bool pureHE=false, unsigned long _rseed=0) : io{_io}, init_params{params}, ID{_ID}, rseed{_rseed}{
276
277 //GI 03/02/2023: Based on a issue regarding data leak after failed initialisation, I implement
278 //this solution to robustly clean the heap allocated variables after a failed object initilisation.
279 //Indeed, in such cases, the object is never build, so the desctructor is not available.
280 //So, I have implemented a private method default_destructor that is called from the destructor to clean the heap
281 //but can be called also here. So we use a try-catch-rethrow schema to check if the initilisation
282 //was successful, otherwise we clean the heap and then rethrow the error.
283 //We use this schema also for the other two constructors.
284
285 //Try the initialisation
286 try {
287 default_initialiser(false, pureHE);
288 //TODO, Notice set_rzams and the Inertia set could be in principle put inside the default initiliaser
289 //However in this case, each time a Star is initialised, even if just an auxiliary star, two stars are initialised
290 //instead (the second one is the star initialised at time zams to get rzmas). This could represent a significant overhead when
291 //a lot of auxiliary stars are created. Therefore, we decided to set rzams only when a true star is initialised (with the current constructor)
292 //set rzams and rzams0
293 set_rzams(); //set rzams
294 rzams0 = rzams;
295 //Set propertly the inertia that could need to know rzams
296 if (!get_svpar_bool("tabuse_inertia") and !amiremnant()) properties[Inertia::ID]->evolve(this);
297 }
298 //Catch any kind of error, dangerous in general, but we use it just to clean the heap and then
299 //the error is rethrown and handled somewhere else.
300 catch (...){ //Catch all errors
301 default_destructor(); //Clean the heap associated to class members
302 throw; //Rethrown the exact same error
303 }
304 }
305
306 /******** SPECIAL CONSTRUCTOR FOR AUXILIARY STARS *******************/
323 Star(const Star* s, size_t _ID, double mzams=utilities::NULL_DOUBLE, double Z=utilities::NULL_DOUBLE, std::string tini=utilities::NULL_STR, bool pureHE=false, unsigned long _rseed=0) : auxiliary_star{true},io{s->io}, ID{_ID}, rseed{_rseed}{
324 //NOTICE, if you make changes here remember to change also the constructor below (that just change because tini is a double)
325 //TODO Myabe it is better to have a template instead of two constructors
326
327 //Try the initialisation
328 try{
330 }
331 catch (...){ //Catch all errors
332 default_destructor(); //Clean the heap associated to class members
333 throw; //Rethrown the exact same error
334 }
335 }
350 Star(const Star* s, size_t _ID, double mzams=utilities::NULL_DOUBLE, double Z=utilities::NULL_DOUBLE, double tini=utilities::NULL_DOUBLE, bool pureHE=false, unsigned long _rseed=0) : auxiliary_star{true},io{s->io}, ID{_ID},rseed{_rseed}{
351 //NOTICE, if you make changes here remember to change also the constructor above (that just change because tini is as a string)
352 //TODO Myabe it is better to have a template instead of two constructors
353
354 //Try the initialisation
355 try {
357 }
358 catch (...){ //Catch all errors
359 default_destructor(); //Clean the heap associated to class members
360 throw; //Rethrown the exact same error
361 }
362 }
363
364
366 /********************************************************************/
367
368
369 /****************** Return M, Radius for core and envelope **********************/
370 /*
371 * Return the mass of the Core, if the star is nakedco Mcore=0
372 */
373 inline double Mcore(bool old=false){
374
375 const auto& getP = [this,&old](int _ID){
376 if (old)
377 return this->getp_0(_ID);
378 else
379 return this->getp(_ID);
380 };
381
382 if (utilities::areEqual(getP(MCO::ID),getP(Mass::ID)))
383 return 0.0;
384 else if (utilities::areEqual(getP(MHE::ID),getP(Mass::ID)))
385 return getP(MCO::ID);
386 else
387 return getP(MHE::ID);
388 }
389 /*
390 * Return the radius of the Core, if the star is nakedco Rcore=0
391 */
392 inline double Rcore(bool old=false){
393
394 const auto& getP = [this,&old](int _ID){
395 if (old)
396 return this->getp_0(_ID);
397 else
398 return this->getp(_ID);
399 };
400
401 if (utilities::areEqual(getP(MCO::ID),getP(Mass::ID)))
402 return 0.0;
403 else if (utilities::areEqual(getP(MHE::ID),getP(Mass::ID)))
404 return getP(RCO::ID);
405 else
406 return getP(RHE::ID);
407 }
408 /*
409 * Return the mass of the envelope, if the star is nakedco Menvelope=Mass
410 */
411 inline double Menvelope(bool old=false){
412
413 const auto& getP = [this,&old](int _ID){
414 if (old)
415 return this->getp_0(_ID);
416 else
417 return this->getp(_ID);
418 };
419
420 if (utilities::areEqual(getP(MCO::ID),getP(Mass::ID)))
421 return getP(Mass::ID);
422 else if (utilities::areEqual(getP(MHE::ID),getP(Mass::ID)))
423 return getP(Mass::ID)-getP(MCO::ID);
424 else
425 return getP(Mass::ID)-getP(MHE::ID);
426 }
427 /*
428 * Return the mass of the envelope, if the star is nakedco Renvelope=Radius
429 */
430 inline double Renvelope(bool old=false){
431
432 const auto& getP = [this,&old](int _ID){
433 if (old)
434 return this->getp_0(_ID);
435 else
436 return this->getp(_ID);
437 };
438
439 if (utilities::areEqual(getP(MCO::ID),getP(Mass::ID)))
440 return getP(Radius::ID);
441 else if (utilities::areEqual(getP(MHE::ID),getP(Mass::ID)))
442 return getP(Radius::ID)-getP(RCO::ID);
443 else
444 return getP(Radius::ID)-getP(RHE::ID);
445 }
446 /*******************************************************************************/
447
448 utilities::jump_convergence find_track_after_CE_Ebinding(double Ebind, double Min_Mass, double Max_mass, bool pureHE=false);
449
450 inline bool isoutputtime() {
451 if (printevents())
453
454 //return(properties[Worldtime::ID]->get() == properties[NextOutput::ID]->get());
455 //GI 12/07/2022 more robust alternative
457 }
458
459 inline bool printall() {return print_all_steps;}
460 inline bool notprint() {return print_only_end;}
461 inline bool printevents() {return print_events;}
462
463 template <class T> void castp(const size_t &id, T classtype){properties[id] = classtype;}
464
477 inline std::vector<std::string> get_initparams(bool effective_values=true) const{
478
479 if (!effective_values)
480 return init_params;
481
482 std::vector<std::string> init_params_tmp=init_params;
483
484 for (unsigned int i=0; i<init_params_tmp.size(); i++){
485
486 switch(i) {
488 init_params_tmp[i] = utilities::n2s(get_zams(),__FILE__,__LINE__);
489 break;
491 init_params_tmp[i] = utilities::n2s(get_Z(),__FILE__,__LINE__);
492 break;
494 init_params_tmp[i] = utilities::n2s(get_tini(),__FILE__,__LINE__);
495 break;
497 init_params_tmp[i] = utilities::n2s(get_tf(),__FILE__,__LINE__);
498 break;
500 init_params_tmp[i] = get_sn_type();
501 break;
503 init_params_tmp[i] = utilities::n2s(get_dtout_original(),__FILE__,__LINE__);
504 break;
506 init_params_tmp[i] = get_svpar_str("spin")=="list" ? init_params[i] : get_svpar_str("spin");
507 break;
508 default:
509 break;
510 }
511
512 }
513
514 return init_params_tmp;
515 }
516
517
518
519 std::vector<std::vector<double>> load_auxiliary_table(std::string tab_name) const {
520 return (io->load_auxiliary_table(tab_name));
521 }
522
527 for(size_t i = 0; i < io->printcolumns_star.size(); i++){
528 //Concerning the Timestep, put the used one not the proposed one
529 if ((size_t)io->printIDs_star[i]==Timestep::ID)
530 state[i] = getp_0((size_t)io->printIDs_star[i]);
531 else
532 state[i] = getp((size_t)io->printIDs_star[i]);
533 }
534
535
536
537 //svlog.debug("State star "+utilities::n2s(ID,__FILE__,__LINE__)+" "+utilities::n2s(state[0],__FILE__,__LINE__)+" "+utilities::n2s(state[1],__FILE__,__LINE__));
538
539 allstates.push_back(state);
540 }
541
542
543
551
553 evolution_guard(__FILE__,__LINE__);
554 //Record state
555 recordstate();
556 //update_nextoutput();
557
559 dtout_generator->next();
560 }
561
563 properties[NextOutput::ID]->special_evolve(this);
564 }
565
566 }
567
568
569
576 void inline print(){
577
578 io->print_log();
581
582 }
583
589 void inline print_to_log(std::string& message){
590 io->log_put(message);
591 }
592
600 void print_failed(bool include_in_output=false){
601 io->print_log();
603 if (include_in_output){
605 }
606 }
607
612 std::string log_message_SNIa();
613
614
619 inline bool just_exploded(){
620
622 return true;
623 return false;
624 }
625
626
628
633 inline bool aminakedhelium() const {
634 return ami_on_pureHE_track and getp(MHE::ID)!=0;
635 //TODO, this function return true also if the star is nakedC0, maybe we can separete and just check ami_on_pureHE_track when needed and add the condition aminakedco here
636 //return ami_on_pureHE_track and getp(MHE::ID)!=0 and !aminackedco();
637 }
638
643 inline bool amifollowingpureHetrack() const {
644 return ami_on_pureHE_track;
645 }
646
651 inline bool amiWR() const {
652 return getp(MHE::ID)>=(1- get_svpar_num("star_tshold_WR_envelope"))*getp(Mass::ID);
653 }
654
659 inline bool amiWR_0() const {
660 return getp_0(MHE::ID)>=(1- get_svpar_num("star_tshold_WR_envelope"))*getp_0(Mass::ID);
661 }
662
663
664 inline bool aminakedco() const {
665 return isconaked and getp(MCO::ID)!=0;
666 }
667
668
669 inline bool amiempty() const { return isempty;}
670
671 inline bool amiremnant() const {
672 return (int)getp(Phase::ID)==Remnant;
673 //TODO, isremnant should be deprecated
674 //return isremnant;
675 }
676
677 inline bool amiremnant_0() const {
678 return (int)getp_0(Phase::ID)==Remnant;
679 //TODO, isremnant should be deprecated
680 //return isremnant;
681 }
682
687 inline bool amiWD() const {
688
692 }
693
698 inline bool amiWD_0() const {
699
703 }
704
709 inline bool amiNS() const {
710
713 }
714
719 inline bool amiNS_0() const {
722 }
723
728 inline bool amiBH() const {
730 }
731
736 inline bool amiBH_0() const {
738 }
739
744 inline bool amiCompact() const {
745 return amiNS() or amiBH();
746 }
747
752 inline bool amiCompact_0() const {
753 return amiNS_0() or amiBH_0();
754 }
755
760 inline bool amIdegenerate() const {
761 return amiWD() or amiNS() or amiBH();
762 }
763
768 inline bool amIdegenerate_0() const {
769 return amiWD_0() or amiNS_0() or amiBH_0();
770 }
771
772
773
778 inline bool haveienvelope() const {
779 if (getp(MHE::ID)==0 or (aminakedhelium() and getp(MCO::ID)==0)
780 or aminakedco() or amiremnant())
781 return false;
782
783 return true;
784 }
785
786
792 inline bool amifollowingQHE() const {
793 return ami_following_QHE;
794 }
795
800 inline bool amiauxiliary() const {
801 return auxiliary_star;
802 }
803
815 inline bool amiRRL(double Lmin=1.3, double Lmax=1.9, bool just_He_core=false) const {
816
817 if (aminakedhelium() or amiremnant())
818 return false;
819
820 double Tred = -0.05*std::log10(getp(Luminosity::ID)) + 3.94; //Karczmarek+17, Eq. 4
821 double Tblue = -0.05*std::log10(getp(Luminosity::ID)) + 4.00; //Karczmarek+17, Eq. 4
822 bool temp_range = getp(Temperature::ID)>=Tred and getp(Temperature::ID)<=Tblue;
823 bool lum_range = getp(Luminosity::ID)>=Lmin and getp(Luminosity::ID)<=Lmax;
824 bool Hecore_condition;
825 if (just_He_core) Hecore_condition = getp(MHE::ID)>0;
826 else Hecore_condition=getp(Phase::ID)==Lookup::Phases::CoreHeBurning;
827
828 return temp_range and lum_range and Hecore_condition;
829 }
830
831
839
846
847 inline bool breaktrigger() const {
848
849 if(isremnant && break_at_remnant) return true;
850 else if (!isremnant && break_at_remnant) return false;
851 else if(!break_at_remnant){
853 }
854 else {
855 SevnLogging svlog_tmp;
856 svlog_tmp.critical("Star breaktrigger check failed",__FILE__,__LINE__);
857 }
858
859 return false;
860 }
861
862
863 int get_bse_phase() const;
864 int get_bse_phase_0() const;
865
866
867
868 inline unsigned long get_rseed(){
869 if (rseed==0)
870 svlog.critical("rseed has not been initialised",__FILE__,__LINE__,sevnstd::sse_error());
871 return rseed;}
872 inline double get_max_zams() const {
873 return ami_on_pureHE_track ? get_svpar_num("max_zams_he") : get_svpar_num("max_zams");
874 }
875 inline double get_min_zams() const {
876 return ami_on_pureHE_track ? get_svpar_num("min_zams_he") : get_svpar_num("min_zams");
877 }
878 inline double get_max_Z() const {
879 return ami_on_pureHE_track ? get_svpar_num("max_z_he") : get_svpar_num("max_z");
880 }
881 inline double get_min_Z() const {
882 return ami_on_pureHE_track ? get_svpar_num("min_z_he") : get_svpar_num("min_z");
883 }
884
885 inline double get_zams() const {return mzams;}
886 inline double get_Z() const {return Z;}
891 inline double get_rzams() {
892 if (rzams<0) set_rzams();
893 return rzams;
894 }
895 inline double get_zams0() const {
896 if (rzams0<0)
897 svlog.critical("Trying to get rzams0, but it has never been set.",__FILE__,__LINE__,sevnstd::sanity_error());
898 return mzams0;
899 }
900 inline double get_Z0() const {return Z0;}
901 inline double get_rzams0() const {return rzams0;}
902 inline double get_MCO_max() const {return MCO_max;}
903 inline double get_MHE_min() const {return MHE_min;}
904 inline double get_tf() const { return tf;}
905 inline double get_tini() const { return tini;}
906 inline double get_dtout_original() const {return dtout;}
907 inline size_t get_jcounter() const { return jtrack_counter;}
908 inline const supernova* get_supernova() const {return SN;} //The pointer returned cannot modify what is inside
909 double get_staremnant(size_t ID);
910 inline Staremnant* get_staremnant() const {return staremnant;}
911
912
914 inline double get_svpar_num(std::string name) const { return io->svpar.get_num(name);}
915 inline std::string get_svpar_str(std::string name) const { return io->svpar.get_str(name);}
916 inline bool get_svpar_bool(std::string name) const { return io->svpar.get_bool(name);}
917
918// inline double get_dtout() { return dtout;}; //NB GI: there is another definition of get_dtout that check also if print_per_phase is True. Myabe we have to decide how to manipulate the output directly from dtout
919
920 inline const std::vector<double> & getstate() {return state;} //Here I return a reference, because the state iterators are used in binstar::record to
921 // add the state elements to a bigger vectors. However, without reference this function returns a copy and using insert(..., getstate().begin, getstate().end())
922 // raises an errore beacsue the first (that calls begin) and the second elements (that calls end) are different objects.
923
924 inline double getp(const size_t &id) const {return properties[id]->get(this);}
925 inline double getp_fk(const size_t &id) const {return properties[id]->get_fk(this);}
926 inline double getp_0(const size_t &id) const {return properties[id]->get_0(this);}
927 inline double getp_fk0(const size_t &id) const {return properties[id]->get_0_fk(this);}
928 inline double get_Vlast(const size_t &id) const {return properties[id]->get_Vlast(this);}
936 inline double get_last_Timestep() const {
939 }
940 inline unsigned int get_dtout_type(){return dtout_type;}
941
942 //Get and return a string
943 inline std::string getps(const size_t &id) const {return utilities::n2s(getp(id),__FILE__,__LINE__);}
944 inline std::string getps_fk(const size_t &id) const {return utilities::n2s(getp_fk(id),__FILE__,__LINE__);}
945 inline std::string getps_0(const size_t &id) const {return utilities::n2s(getp_0(id),__FILE__,__LINE__);}
946 inline std::string getps_fk0(const size_t &id) const {return utilities::n2s(getp_fk0(id),__FILE__,__LINE__);}
947 inline std::string get_id_name() const {
948 std::string mss = "ID: "+utilities::n2s(ID,__FILE__,__LINE__) + " Name: "+utilities::n2s(name,__FILE__,__LINE__);
949 return mss;
950 }
951
952 //Get raw V,v values, Notice these functions just return the V,V0,value,value0 withouth processing them, therefore
953 //getp_raw(Radius::ID) will return log10(R) since V and V0 in the property radius are stored as log10
954 inline double getp_raw(const size_t &id) const {return properties[id]->get_raw(this);}
955 inline double getp_fk_raw(const size_t &id) const {return properties[id]->get_fk_raw(this);}
956 inline double getp_0_raw(const size_t &id) const {return properties[id]->get_0_raw(this);}
957 inline double getp_fk0_raw(const size_t &id) const {return properties[id]->get_0_fk_raw(this);}
958
959
960 inline bool table_loaded(size_t propID) const {return properties[propID]->are_table_loaded();}
961
962
963
975 inline double* get_table_pointer_atpos(size_t table_id, int interpolating_track, int pos){
976
977 if (tables[table_id][interpolating_track]==nullptr){
978 return nullptr;
979 } else{
980 return &tables[table_id][interpolating_track]->at(pos);
981 }
982
983 }
984
985 inline double get_current_tphase() const {return tphase[(int)properties[Phase::ID]->get()];}
986 inline double get_next_tphase() const {return tphase[(int)properties[Phase::ID]->get()+1];}
987 inline std::string get_phase_str () const { return Lookup::literal((Lookup::Phases)(int)(getp(Phase::ID)));}
988
989 inline size_t get_ID() const {return ID;}
990 inline std::string & get_name() {return name;}
991 inline std::string get_sn_type() const {return sntype;}
992
993 inline double* get_mtrack() {return &Mtrack[0];}
994 inline double* get_ztrack() {return &Ztrack[0];}
995
996 inline const double* get_tphase() const {return &tphase[0];}
997 inline double & costart() {return t_co_start;}
998 inline double & hestart() {return t_he_start;}
999 inline bool & kicked() {return iskicked;}
1000
1006 inline void copy_property_from(const size_t &prop_id, const size_t &copy_from_id){
1007 properties[prop_id]->copy_V_from(properties[copy_from_id]);
1008 }
1009
1011 inline void set_kicked() {iskicked = true;}
1012 inline void set_forcejump() {force_jump = true;}
1013 inline void set_empty(){
1014 isempty=true;
1015 set_remnant(); //Set remnant before setting property to empty otherwise Timestep set_empty will raise an error if the star is also nakedco
1016 for (auto &prop : properties) {
1017 prop->set_empty(this); //V0=V=nan
1018 }
1019 //Now safely delete staremnant
1021
1022 }
1023 inline void set_empty_in_bse(Binstar *b){
1024 isempty=true;
1025 set_remnant(); //Set remnant before setting property to empty otherwise Timestep set_empty will raise an error if the star is also nakedco
1026
1027 for (auto &prop : properties) {
1028 prop->set_empty_in_bse(this,b); //V0=V=nan
1029 }
1030 //Now safely delete staremnant
1032 }
1033
1035
1036
1037 inline void set_remnant(){
1038 //Reset conaked and henaked
1039 if (aminakedco()){
1040 isconaked = false; //Now this star is a remnant, reset nakedco
1041 once_conaked = true; //If the star was a nakedCO before to become a remnant, take memory of this (useful in case of repetition)
1042 }
1043 isremnant=true;
1044 }
1045
1046
1047 inline void set_COnaked(){
1048
1049
1050 //Check
1051 //TODO THis is a sanity check, myabe we can remove it at certain point
1052 //Notice we check the difference, beacuse since Radius is stored internally in log, there is always some round-off error when compared with RCO and RHE that are not log
1053 if (std::abs(getp(MCO::ID)-getp(Mass::ID))>get_svpar_num("ev_naked_tshold")){
1054 svlog.critical("Called set_COnaked, but MCO ("+getps(MCO::ID)+")" +
1055 " have not the same value of Mass (" +getps(Mass::ID)+
1056 ").", __FILE__,__LINE__,sevnstd::bse_error());
1057
1058 }
1059
1060 if (std::abs(getp(RCO::ID)-getp(Radius::ID))>1e-10){
1061 properties[RHE::ID]->copy_V_from(properties[RCO::ID]);
1062 properties[Radius::ID]->copy_V_from(properties[RCO::ID]);
1063 }
1064
1065
1066 if (getp(MCO::ID)<=get_svpar_num("sn_co_lower_ecsn")){
1067 //Notice, the order here is important: We have to 1) Adavance the Localtime 2)Let the Phase change 3)turno into remnant
1068 //Notice, the Phase is updated only in Phase special evolve the remnant type inside turno_into_remnant
1069 properties[Localtime::ID]->update_from_binary(this, 1.001*(get_tphase()[Remnant] - getp(Localtime::ID)));
1070 properties[Phase::ID]->special_evolve(this);
1072 return;
1073 }
1074 isconaked=true;
1075 once_conaked = false; //Reset
1076
1077 }
1078 inline void set_QHE(){
1079 if (getp(Phase::ID)>2 and getp_0(Phase::ID)>2)
1080 svlog.critical("Trying to set the flag ami_following_QHE when the star is more evolved than the MS phase",
1081 __FILE__,__LINE__,sevnstd::bse_error());
1082 ami_following_QHE = get_svpar_bool("rlo_QHE");
1083 std::string w = utilities::log_print("QHE", this,getp(Mass::ID),getp(Radius::ID),getp(dMcumul_RLO::ID));
1084 print_to_log(w);
1085 }
1086 inline void reset_QHE(){
1087 ami_following_QHE = false;
1088 }
1089
1096 inline void set_MCO_max_aftermerge(Star *merged_star){
1097
1098 if (!std::isnan(MCO_max) and !std::isnan(merged_star->MCO_max)){
1099 MCO_max = MCO_max + merged_star->MCO_max;
1100 }
1101 else if (std::isnan(MCO_max) and !std::isnan(merged_star->MCO_max)){
1102 MCO_max = merged_star->MCO_max;
1103 }
1104 }
1105
1112 inline void set_MHE_min_aftermerge(Star *merged_star){
1113
1114 if (!std::isnan(MHE_min) and !std::isnan(merged_star->MHE_min)){
1115 MHE_min = MHE_min + merged_star->MHE_min;
1116 }
1117 else if (std::isnan(MHE_min) and !std::isnan(merged_star->MHE_min)){
1118 MHE_min = merged_star->MHE_min;
1119 }
1120 }
1121
1125 inline void evolution_step_done(){
1127 }
1128 inline void evolution_guard(const char *file_input = nullptr, int line_input = -1){
1130 svlog.critical("The function recordstate_w_timeupdate can be called only after an evolution step",file_input,line_input,sevnstd::sse_error());
1131 }
1132
1133 inline bool get_COnaked(){return isconaked;}
1134
1135
1136 inline double get_dtout() {
1137
1138
1140 return dtout_generator->get()-getp(Worldtime::ID);
1141
1142 return 1E30;
1143
1144 //if(print_per_phase)
1145 // return dtout_phase[(size_t)properties[Phase::ID]->get()]; //TODO it can be or fixed or print all time steps or print all timesteps diveded by 2 (print every 2), or divided by 3 (print every 3) and so on...
1146 //else
1147 // return dtout;
1148
1149 }
1150
1151 inline double get_dtmax(){ //avoid big jumps in the look-up tables
1152
1153 double max_dt_tables = 1E30;
1154 double max_dt_phase = 1E30;
1155 double max_dt_dout=1E30;
1156
1158 //If we are already at the end of the simulation just set a fake max_tend
1159 double max_tend = get_tf() - getp(Worldtime::ID);
1160 if(max_tend==0) return 1E-15;
1161
1162
1165 //Notice, in case the time in dout generate is equal to the Worldtime, we use forecast instead of get
1166 //because we are going to the next step. We use forecast instead of next, because next is only used in recordstate_w_timeupdate.
1167 //This is necessary to avoid that we skip a dout due to a repeat that happens exactly at the same time in which dtout_generator->get()==getp(Worldtime::ID).
1168 //In that cases the Worldtime comes back but not the dtout. Instead the recordstate_w_timeupdate can be called only at the end of the evolution
1169 //step where we are sure all the necessary repetions have been already done.
1170
1171 if (dtout_generator->get()==getp(Worldtime::ID) and !std::isnan(dtout_generator->forecast()))
1172 max_dt_dout = dtout_generator->forecast()-getp(Worldtime::ID);
1173 else if (dtout_generator->get()>getp(Worldtime::ID))
1174 max_dt_dout = dtout_generator->get()-getp(Worldtime::ID);
1175
1176 if (max_dt_dout<0){
1177 std::cout<<dtout_generator->get()<<" "<<getp(Worldtime::ID)<<std::endl;
1178 svlog.critical("Max timestep from dtout check is negative.",__FILE__,__LINE__,sevnstd::sse_error());
1179 }
1180 }
1181
1182
1183
1185 if (!amiremnant() and !aminakedco()){
1187 FOR4 {
1188 if(tables[_Time][_i]->size() > pos[_i]+2)
1189 max_dt_tables = std::min(max_dt_tables, tables[_Time][_i]->at(pos[_i]+2) - tables[_Time][_i]->at(pos[_i])); //+2 means "maximum jump = 2 points in the look-up tables"
1190 else
1191 max_dt_tables = std::min(max_dt_tables, tables[_Time][_i]->at(pos[_i]+1) - tables[_Time][_i]->at(pos[_i]));
1192 }
1194 //TODO We have to write in the documentation that the parameter ts_min_point can be overwritten by the above criteria
1195 max_dt_phase = (get_next_tphase() - get_current_tphase())/get_svpar_num("ts_min_points_per_phase");
1196
1197 }
1198
1199 //TODO Write an utility function to the take the minimum of a variadic list
1200 return std::min(max_tend,std::min(max_dt_tables,std::min(max_dt_phase,max_dt_dout)));
1201 }
1202
1203
1204
1206
1207
1208 /*** NOTE: this is just a "fake" evolution that aim just to move the position on the interpolating tables
1209 * to the right value at given tini. This evolution is made with a single step and there are not checks that
1210 * ca repeat the step***/
1211 svlog.debug("Bringing star to the initial Localtime",__FILE__,__LINE__);
1212
1214 properties[Timestep::ID]->resynch(tini,false);
1215
1216
1217
1218 //Evolve Localtime and Phase, but not Worldtime since this is just a fake pre-evolution phase to bring
1219 //the stars to the correct initial position given by tini.
1220 properties[Localtime::ID]->special_evolve(this);
1221 properties[Phase::ID]->special_evolve(this);
1222
1223
1225 tracktimes();
1227
1228 //Evolve the properties (Essentially we are interested only on the fake evolution)
1229 //Essentially in this step we make fake evolution putting v to the right value considering the interpolating tracks and v0 is 0
1230 //Since v0 is 0, Dvalue is automatically set to 0 and as a consequence the evolution of V is just V=v.
1231 //Notice this is not true for OptionaTable, the properties override the synch method to take into account v is not set, see below.
1232 for (auto &prop : properties){
1233 prop->evolve(this);
1234 }
1235
1236
1237 //At this points V=v for all the properties and v=v0=0 except for the Timestep that does nothing in evolve but changes V and V0 in special evolve
1238 //Note if we print now properties like Radius, Luminosity and Inertia their v and v0 are equal to 1, this because
1239 //internally they are set to 0 as the other properties but they are log so get automatically calculate 10**v and 10**v0.
1240
1241
1242 //Now propose a conservative next tstep to be sure to not cross the next phase.
1243 double proposed_dt = get_dtmax();
1244 if (get_svpar_num("ts_min_dt")>0)
1245 proposed_dt = std::max(proposed_dt,get_svpar_num("ts_min_dt"));
1246 if (get_svpar_num("ts_max_dt")>0)
1247 proposed_dt = std::min(proposed_dt,get_svpar_num("ts_max_dt"));
1248 //get_dtmax do not take into account that with this timestep we can directly change phase or even became a remnant
1249 //With the following we avoid to jump directly to other phases
1250 proposed_dt = std::min(proposed_dt,0.99*(get_next_tphase()-getp(Localtime::ID)));
1251
1252 //Prepare Timestep
1253 //1-Reset all to 0, so that V0=0
1254 properties[Timestep::ID]->resynch(0.0, true);
1255 //2-Set the new timestep
1256 properties[Timestep::ID]->resynch(proposed_dt, false);
1257
1258
1259 //Now sync (V=V0=v0=v) all the properties to be ready to start the real evolution
1260 //Notice for the optional property synch is overrided and if the table are not loaded we have v0=v=V0=V.
1261 //Notice also that some optional properties can be disabled even if loaded, in this case, we cannot set v0=v=V0=V at this stage.
1262 //but the evolution without table handles this problem setting v0=V0 and v=V after each evolution.
1263 for (auto &prop : properties) prop->synch(); //init also the real star!!
1264
1265
1266 //GI 21/07/2022, not needed anymore, since MHE and RHE are properly set on the initialisation
1267 //If Naked Helium resynch MHE and RHE
1268 /*
1269 if (aminakedhelium()){
1270 copy_property_from(MHE::ID,Mass::ID);
1271 copy_property_from(RHE::ID,Radius::ID);
1272 }
1273 */
1274
1275
1276
1277 //initialize also the first value for the next output
1279 //Initialize OmegaSpin from Spin (given in input)
1281 //Initialize AngMomSpin from OmegaSpin
1283
1284
1285 svlog.debug("Star " + std::to_string(ID) + " has been evolvod to the inital LocalTime "+std::to_string(properties[Localtime::ID]->get())
1286 +". \n"+" Next proposed Timestep is "+std::to_string(properties[Timestep::ID]->get()),__FILE__,__LINE__);
1287 }
1288
1290
1291
1300
1306
1307 //Case 1: Star has an H envelope and a He core, it loses the H envelope
1308 if (!aminakedhelium() && !aminakedco() && getp(MHE::ID)>0){
1309 //The radius of the star is the radius of the RHE
1310 properties[Radius::ID]->copy_V_from(properties[RHE::ID]);
1311 //The new mass is MTOT=MHE
1312 properties[Mass::ID]->copy_V_from(properties[MHE::ID]);
1313 //Jump to pureHE tracks
1314 //jump_to_pureHE_tracks();
1315 //TODO in sevn1 in common_envelope.cpp::lose_the_envelope the radius is not changed
1316 }
1317 //Case 1: Star is a naked Helium, loosing the envelope we remain with a naked CO
1318 //TODO is it transformed to a WD?
1319 else if (aminakedhelium() && getp(MCO::ID)>0){
1320 //The radius of the star is the radius of the RCO, R=RHE=RCO
1321 properties[Radius::ID]->copy_V_from(properties[RCO::ID]);
1322 properties[RHE::ID]->copy_V_from(properties[RCO::ID]);
1323
1324 //The new mass is MCO=MHE=MTOT
1325 properties[Mass::ID]->copy_V_from(properties[MCO::ID]);
1326 properties[MHE::ID]->copy_V_from(properties[MCO::ID]);
1327 //set_COnaked();
1328 //utilities::hardwait("CO NAKED",get_ID(),__FILE__,__LINE__);
1329
1330 //TODO in sevn1 in common_envelope.cpp::lose_the_envelope the luminosity is forced to 1e-4
1331 }
1332 //Case 3: In all the other cases (nakedHe without CO, naked CO, MS star with only H) do nothing
1333 else{
1334 //svlog.pwarning("Star", ID, "does not have any envelope, it cannot lose the envelope.",
1335 // "\n Mass: ",getp(Mass::ID),
1336 // "\n Mass HE: ",getp(MHE::ID),
1337 // "\n Mass CO: ",getp(MCO::ID),
1338 // "\n",__FILE__,__LINE__);
1339 return EXIT_FAILURE;
1340 }
1341
1342 return EXIT_SUCCESS;
1343
1344 }
1345
1351 inline void update_from_binary(int Property_id, double DV, Binstar* b = nullptr){
1352
1353 properties[Property_id]->update_from_binary(this, DV,b);
1354
1355 }
1356
1357
1361 inline void restore(){
1362
1364 for (auto &prop : properties) prop->restore();
1366 //TODO Now isremnant is depreacted, since amiremnant check directly the phase, but the final transition to new formalism has to be completed
1367 //Check if the star came back from a SN explosion, in case reset isremnant
1369 isremnant=false;
1370 //Now, if the star is not nakedco but once_conaked is true
1371 //set again nakedCO. THis can happen when in the last step the star
1372 //becomes a remnants, but then a repeat is called, so we need to restore conaked.
1373 //once_conaked is set to true in turn_into_remnant if the star was a nakedCO and
1374 //it is reset to false in set_COnaked
1375 if (!aminakedco() and once_conaked)
1376 set_COnaked();
1377 }
1378 //Reset changed phase
1379 //In case the previous step starts the reduction of the timestep for the next change of phase, reset it since we are repeating
1380 changedphase = false;
1381
1382 }
1383
1384 inline void resynch(const double &dt){
1385 restore();
1386 properties[Timestep::ID]->resynch(dt);
1387 }
1388
1389
1390
1396 inline void sync_with(Star *s){
1397
1398 properties[Timestep::ID]->resynch(s);
1399
1400 }
1401
1402 //set only the Timestep V (not V0).
1403 inline void sync_with(double dt){
1404
1405 properties[Timestep::ID]->resynch(dt, false);
1406
1407 }
1408
1413 inline double plife() const {
1414 int currentphase = (int)getp(Phase::ID);
1415 return ((getp(Localtime::ID) - tphase[currentphase])/(tphase[currentphase+1] - tphase[currentphase]));
1416 }
1417
1418 inline void tracktimes(){
1419
1420 double perc = plife();
1421 int currentphase = (int)getp(Phase::ID);
1422
1423 for(int i = 0; i < 4; i++) {
1424
1425 double time_step = (tphase_neigh[i][currentphase + 1] - tphase_neigh[i][currentphase]);
1426 ttimes[i] = (tphase_neigh[i][currentphase] + perc * time_step);
1427
1428 //TODO THis is an experimental feature, we are artificially changing the plife for this track but of a very small amount
1429 if (ttimes[i]>=tphase_neigh[i][currentphase + 1]){
1430
1431 double smallest_difference=std::numeric_limits<double>::epsilon()*std::fabs(tphase_neigh[i][currentphase + 1]);
1432 ttimes[i]=tphase_neigh[i][currentphase + 1]-smallest_difference;
1433 std::string w = utilities::log_print("CPLIFE",this,i);
1434 print_to_log(w);
1435
1436 if (ttimes[i]>=tphase_neigh[i][currentphase + 1]){
1437 svlog.critical("In tracktimes at track " + utilities::n2s(i,__FILE__,__LINE__) +
1438 " the difference in timestep is smaller than the machine precision, therefore this track"
1439 " will use values of the next phase.",__FILE__,__LINE__,sevnstd::sanity_error());
1440 }
1441 else{
1442 svlog.warning("In tracktimes at track " + utilities::n2s(i,__FILE__,__LINE__) +
1443 " the difference in timestep is smaller than the machine precision, therefore this track"
1444 " will use values of the next phase. We used instead the smallest timestep possible",__FILE__,__LINE__);
1445 }
1446 }
1447
1448 /* HOLD IMPLEMENTATION
1449 if (ttimes[i]>=tphase_neigh[i][currentphase + 1]){
1450
1451
1452 svlog.critical("In tracktimes at track " + utilities::n2s(i,__FILE__,__LINE__) +
1453 " the difference in timestep is smaller than the machine precision, therefore this track"
1454 " will use values of the next phase.",__FILE__,__LINE__,sevnstd::sanity_error());
1455 }
1456 */
1457
1458
1459 }
1460
1461
1462
1463 }
1464
1465
1466 //calculate the actual positions on the lookup tables for all the interpolating tracks, given a target time
1467 inline void lookuppositions() {
1468
1469 //TODO We have a series of a call to vector.at instead of vector[], this robust against bugs, but maybe at certain point we can test what is the performance gain using directly the operator[]
1470
1471 // tables[starparameter::_time][0] is a pointer to a vector...
1472 // &tables[starparameter::_time][0]->at(0) is a pointer to the first element of the pointed vector
1473
1474
1475
1476 //unroll
1477 if(needsinit) { //if the star need to be (re-)initialized use binary search algorithms for tables
1478 FOR4 pos[_i] = utilities::binary_search(&tables[_Time][_i]->at(0), 0, tables[_Time][_i]->size() - 1, ttimes[_i]);
1479 needsinit=false; //reset needsinit
1480 }
1481 else{
1482
1483 for(size_t i = 0; i < 4; i++) {
1484
1485
1486
1487 //Sanity check to track possible errors on pointers
1488 if (pos[i]>tables[_Time][i]->size())
1489 svlog.critical("Position of lookup table pointer for interpolating track " + utilities::n2s(i,__FILE__,__LINE__) +
1490 " is " + utilities::n2s(pos[i],__FILE__,__LINE__)+
1491 " and it is larger than the table size " + utilities::n2s(tables[_Time][i]->size(),__FILE__,__LINE__),
1492 __FILE__,__LINE__,sevnstd::sse_error());
1493
1494 if (ttimes[i]==tables[_Time][i]->back())
1495 svlog.critical("The ttimes of interpolating track " + utilities::n2s(i,__FILE__,__LINE__) +
1496 " is equal to the last point in the time tables. This is likely due to time differences smaller than the machine precision.",__FILE__,__LINE__,sevnstd::sanity_error());
1497
1498
1499 //Time one step ahead of the current pointer position
1500 double time_right = tables[_Time][i]->at(pos[i] + 1);
1501
1502
1503
1504 // If ttimes is larger than just one step ahead try going another step ahead and so on
1505 //TODO maybe we need to check that pos is inside the Time table size
1506 while (ttimes[i] >= time_right) {
1507 pos[i]++;
1508 time_right = tables[_Time][i]->at(pos[i] + 1);
1509 }
1510
1511
1512
1513 //If for some reason ttimes is lower that current time pointe in the table use binary search
1514 //TODO the ttimes[i] > tables[_Time][i]->at(pos[i] + 1) seemes pointless here given the while above, check
1515 if (ttimes[i] < tables[_Time][i]->at(pos[i]) || ttimes[i] > tables[_Time][i]->at(pos[i] + 1)) {
1516 FOR4 pos[_i] = utilities::binary_search(&tables[_Time][_i]->at(0), 0, tables[_Time][_i]->size() - 1, ttimes[_i]);
1517 break;
1518 }
1519 }
1520 }
1521
1522
1523 FOR4 times_in[_i] = &tables[_Time][_i]->at(pos[_i]);
1524
1525
1526 }
1527
1531 void explode_as_SNI();
1532
1537 void tobe_exploded_as_SNI();
1538
1542 bool is_exploding_as_SNI() const;
1543
1548
1554
1555 //If it is not a remnant exit
1556 if (!amiremnant())
1558
1559 /* If the Chandrasekhar limit is exceeded for a white dwarf then destroy
1560 * the white dwarf in a supernova. If the WD is ONe then a neutron star
1561 * will survive the supernova.
1562 */
1563 double Mchandra = get_svpar_num("sn_Mchandra");
1564 double Mtov = get_svpar_num("sn_max_ns_mass"); //Tolman–Oppenheimer–Volkoff limit
1565 double const &Mass = getp(Mass::ID);
1566 double remnant = getp(RemnantType::ID);
1567
1568
1569
1570 if (Mass>Mchandra && amiWD()) {
1571 if (remnant == Remnants::HeWD or remnant == Remnants::COWD) {
1572 utilities::wait("SN1a triggered by accretion Mchandra limit", __FILE__, __LINE__);
1575 } else if (remnant == Remnants::ONeWD) {
1576 //TODO test if the transition is working
1577 //Check if the mass is larger than the maximum allowed NS mass
1578 if (Mass>Mtov)
1579 svlog.critical("We are transforming a ONeWD to a NS but the final mass (" + utilities::n2s(Mass,__FILE__,__LINE__) +
1580 " Msun) is larger than the maximum mass allowed for a NS (" + utilities::n2s(get_svpar_num("sn_max_ns_mass"),__FILE__,__LINE__) +
1581 " Msun).",__FILE__,__LINE__,sevnstd::bse_error());
1583 utilities::wait("We are transforming a WD to a NS (",Mass,
1584 " Msun) at Worldtime ",getp(Worldtime::ID), "Myr",__FILE__,__LINE__);
1586 }
1587 }
1588 else if(Mass>Mtov and amiNS()){
1590 utilities::wait("We are transforming a NS to a BH (",Mass,
1591 " Msun) at Worldtime ",getp(Worldtime::ID), "Myr",__FILE__,__LINE__);
1593 }
1594
1595
1596
1598 }
1599
1606 void init(std::vector<std::string> &params, bool isareset){
1607
1608 //Check if dimension is correct. The check is made here since init is publicly exposed (init_stars and init_binary are privates).
1609 //TODO put this as a constant static parameter?
1610 int par_expected_size = 7;
1611 //If rseed is provided we have an extra parameter that is the seed.
1612 if (io->rseed_provided())
1613 par_expected_size+=1;
1614
1615 if ((int)params.size()!=par_expected_size){
1616 std::string par_exp=utilities::n2s(par_expected_size, __FILE__, __LINE__);
1617 std::string inparam_size=utilities::n2s(params.size(), __FILE__, __LINE__);
1618 std::string this_ID=utilities::n2s(ID, __FILE__, __LINE__);
1619 svlog.critical("Number of Star params needs to be " +par_exp+", it is instead " + inparam_size + " (ID_bin: " + this_ID +")" , __FILE__, __LINE__);
1620 }
1621
1622
1623
1624 //If this is called by a reset we don't have to reset properties, random seed and name
1625 if (!isareset) {
1626
1627 /*** Load the properties ***/
1628 if (properties.size() == 0) {
1629 for (auto Prop : Property::all)
1630 //for (size_t i = 0; i < Property::all.size(); i++) {
1631 //svlog.debug("Property " + Property::all[i]->name() + " added");
1632 properties.push_back(Prop->Instance()); //create instances for all properties
1633 //TODO transform raw pointers to unique_ptr? (see issue #47)
1634 //std::unique_ptr<Property> prop_temp(Property::all[i]->Instance());
1635 //properties.push_back(std::move(prop_temp)); //create instances for all properties
1636 }
1637
1638
1639 /*** Resize tables ***/
1640 state.resize(io->printcolumns_star.size());
1641 tables.resize(Lookup::_Ntables);
1642 for (auto &i : tables) i.resize(4);
1643 tphase_neigh.resize(4);
1644
1645 //TODO Here happens that if parameter -rseed is in io, the rseed is got
1646 //from the initial parameters, otherwise we look for the rseed parameter of the function
1647 //This can be dangerous since one can believe that changing rseed in inpunt is possibile
1648 //to use a custom seed, but this is not always true, we should change this and create a
1649 //more clear and robust initialisation of rseed
1650 if (io->rseed_provided()) {
1651 set_rseed(inspect_param_rseed(init_params[7]), __FILE__, __LINE__); //7th column is the random seed, if provided
1652 }
1653 else if(rseed == 0) set_rseed(utilities::gen_rseed(), __FILE__, __LINE__);
1654
1655
1656 //initialize the random number generator with the seed (to generate IDs for binary systems)
1658
1659 //Generate name
1660 //TODO we should create a special constuctor taking a pointer to binary as parameter, so that stars inside a binary can be created in this way, and the information like the name and the ID of the binary can be know also at the Star initilisation
1662 }
1663
1664
1665
1666 //GIQ: I have used the same order of the original implementation. Is the this ordered needed?
1667 init_1(params);
1668 //If we are initialising the star as a remnant we don't need to init lookup tables
1669 //TODO We are to check if this lack of initialisation can create indefinite behaviour somewhere else
1670 //I think not because V and V0 are handled with set_remnant. In any case I already check that it seems
1671 //to work even if we remove this if and we let to initialise also for stars that are already remnants,
1672 //in case the mass of the remnant is lower or higher than the lower or upper zams limits, the interpolating
1673 // tracks will be the first two or the last two zams.
1676 }
1677
1678
1679
1680 init_2(params);
1681
1682
1683 svlog.debug("Init Done",__FILE__,__LINE__);
1684
1685
1686 }
1687
1693 double inspect_param_dt(std::string p);
1702 inline double inspect_param_tini(std::string p, bool ignore_global=false){
1703
1705 if (!ignore_global){
1706 if (get_svpar_str("tini")!="list"){
1707 p=get_svpar_str("tini");
1708 }
1709 else if(get_svpar_str("tini")=="list" and p==utilities::PLACEHOLDER){
1710 svlog.critical("Using placeholder option for tf but the parameter tini is"
1711 " set to list",__FILE__,__LINE__,sevnstd::params_error());
1712 }
1713 }
1714
1715 double _tini;
1716
1717 if(utilities::string_is_number<double>(p)){
1718 _tini = utilities::s2n<double>(p, __FILE__, __LINE__);
1719 }
1720 else{
1722 std::transform(p.begin(),p.end(),p.begin(),[](unsigned char c){ return std::tolower(c);});//using algorithm + lambda function
1723
1725 if (p=="zams") {
1727 svlog.critical("Using tini=zams when initialising a pureHE star. Maybe you are using a global tini overwriting list values?",__FILE__,__LINE__,sevnstd::sevnio_error(""));
1728 initialised_on_zams = true;
1729 _tini = tphase[MainSequence];
1730 }
1731 else if (p=="tms" or p=="tams"){
1733 svlog.critical("Using tini=tams when initialising a pureHE star. Maybe you are using a global tini overwriting list values?",__FILE__,__LINE__,sevnstd::sevnio_error(""));
1735 }
1736 else if (p=="hsb" or p=="shb"){
1738 svlog.critical("Using tini=shb when initialising a pureHE star. Maybe you are using a global tini overwriting list values?",__FILE__,__LINE__,sevnstd::sevnio_error(""));
1739 _tini = tphase[ShellHBurning];
1740 }
1741 else if (p=="cheb"){
1743 initialised_on_zams = true;
1744 _tini = tphase[CoreHeBurning];
1745 }
1746 else if (p=="tcheb"){
1748 }
1749 else if (p=="hesb" or p=="sheb"){
1750 _tini = tphase[ShellHeBurning];
1751 }
1752 //TODO ATM setting the stars to remant put bad values in the semimajor axis
1753 //else if (p.find("rem") != std::string::npos || p.find("REM") != std::string::npos){
1754 // return tphase[Remnant];
1755 //}
1756 else if ( p.find('%') == 0) {
1757 std::string token = p.substr(1);
1758
1759 std::stringstream ss(token);
1760 int phase;
1761 double perc;
1762 double tstart;
1763
1764 if (!(ss >> perc)) svlog.critical("Error while reading percentage of initial time", __FILE__, __LINE__,sevnstd::sevnio_error());
1765 if (ss.peek() == ':') ss.ignore();
1766 if (!(ss >> phase)) svlog.critical("Error while reading phase for the initial time", __FILE__, __LINE__,sevnstd::sevnio_error());
1767
1768
1769 if (phase > Remnant)
1770 svlog.critical("You want to evolve a star starting at " + utilities::n2s(perc, __FILE__, __LINE__) +
1771 " percent of its life as a remnant. This does not make any sense. Please provide meaningful values",
1772 __FILE__, __LINE__);
1773
1774 if (phase == Remnant) {
1775 tstart = (perc/100) * tphase[phase];
1776 } else {
1777 double time_begin = tphase[phase];
1778 double time_end = tphase[phase + 1];
1779 tstart = (perc/100) * (time_end - time_begin) + time_begin;
1780 }
1781
1782 if (tstart>tphase[Remnant])
1783 svlog.critical("You want to evolve a start starting at time "+utilities::n2s(tstart, __FILE__, __LINE__)+
1784 " Gyr that is larger than the star life time ["+utilities::n2s(tphase[Remnant], __FILE__, __LINE__)+ " Gyr].",__FILE__,__LINE__, sevnstd::sevnio_error());
1785
1786 _tini = tstart;
1787 }
1788 else
1789 svlog.critical("Option "+p+" not implemented for tini",__FILE__,__LINE__,sevnstd::notimplemented_error());
1790
1791 }
1792
1793
1794 if (_tini==0.)
1795 _tini = utilities::TINY;
1796 else if (_tini>=tphase[Remnant] and initialise_as_remnant==NotARemnant)
1797 svlog.critical("Tini ("+ utilities::n2s(_tini,__FILE__,__LINE__)+" Myr) is larger than the star lifetime ("+utilities::n2s(tphase[Remnant],__FILE__,__LINE__)+" Myr)");
1798
1799 return _tini;
1800
1801 }
1807 inline double inspect_param_tf(std::string p){
1808
1810 if (get_svpar_str("tf")!="list"){
1811 p=get_svpar_str("tf");
1812 }
1813 else if(get_svpar_str("tf")=="list" and p==utilities::PLACEHOLDER){
1814 svlog.critical("Using placeholder option for tf but the parameter tf is"
1815 " set to list",__FILE__,__LINE__,sevnstd::params_error());
1816 }
1817
1818 if(utilities::string_is_number<double>(p)){
1819 return utilities::s2n<double>(p, __FILE__, __LINE__);
1820 }
1821 else if(p=="end") {
1822 break_at_remnant = true;
1823 //return tphase[Remnant];
1824 //GI, 07/09/22, If tf=end just put a large value since
1825 //the evolution will be stopped when the object is a remnant
1826 //This is already what SEVN does for the binary evolution,
1827 //If tf end it sets tf=utilities::LARGE for both stars.
1828 //In this way, the evolution of timestep is also more robust.
1829 return utilities::LARGE;
1830 }
1831 else
1832 svlog.critical("Option "+p+" not implemented for tfin",__FILE__,__LINE__,sevnstd::notimplemented_error());
1833
1834 return EXIT_FAILURE;
1835 }
1841 inline double inspect_param_mass(std::string p){
1842
1843 std::size_t pos;
1844 double mass;
1845
1846
1847 if ( (pos=p.find("BH"))!=std::string::npos ){
1848
1849 std::string token = p.substr(0,pos);
1851 mass = utilities::s2n<double>(token, __FILE__, __LINE__);
1852 }
1853 else if ( (pos=p.find("NS"))!=std::string::npos ){
1854 std::string token = p.substr(0,pos);
1856 mass = utilities::s2n<double>(token, __FILE__, __LINE__);
1857 }
1858 else if ( (pos=p.find("NSEC"))!=std::string::npos ){
1859 std::string token = p.substr(0,pos);
1861 mass = utilities::s2n<double>(token, __FILE__, __LINE__);
1862 }
1863 else if ( (pos=p.find("HEWD"))!=std::string::npos ){
1864 std::string token = p.substr(0,pos);
1866 mass = utilities::s2n<double>(token, __FILE__, __LINE__);
1867 }
1868 else if ( (pos=p.find("COWD"))!=std::string::npos ){
1869 std::string token = p.substr(0,pos);
1871 mass = utilities::s2n<double>(token, __FILE__, __LINE__);
1872 }
1873 else if ( (pos=p.find("ONEWD"))!=std::string::npos ){
1874 std::string token = p.substr(0,pos);
1876 mass = utilities::s2n<double>(token, __FILE__, __LINE__);
1877 }
1878 else if( (pos=p.find("HE"))!=std::string::npos ){
1879 std::string token = p.substr(0,pos);
1881 mass = utilities::s2n<double>(token, __FILE__, __LINE__);
1882 }
1883 else if(utilities::string_is_number<double>(p)){
1884 mass = utilities::s2n<double>(p, __FILE__, __LINE__);
1885 }
1886 else
1887 return EXIT_FAILURE;
1888
1889 if (mass==0){
1891 }
1892
1893 return mass;
1894
1895 }
1902 inline double inspect_param_Z(std::string p, bool ignore_global=false){
1904
1905
1906 if (!ignore_global){
1907 if (get_svpar_str("Z")!="list"){
1908 p=get_svpar_str("Z");
1909 }
1910 else if(get_svpar_str("Z")=="list" and p==utilities::PLACEHOLDER){
1911 svlog.critical("Using placeholder option for Z but the parameter Z is"
1912 " set to list",__FILE__,__LINE__,sevnstd::params_error());
1913 }
1914 }
1915
1916
1917 return utilities::s2n<double>(p, __FILE__, __LINE__);
1918 }
1924 inline unsigned long inspect_param_rseed(std::string p){
1925
1926 if(utilities::string_is_number<unsigned long>(p)){
1927
1928 unsigned long _rseed = utilities::s2n<unsigned long>(p, __FILE__, __LINE__);
1929 if (_rseed <=0)
1930 svlog.critical("Rseed in input () "+p+" cannot be negative or zero",__FILE__,__LINE__,sevnstd::sevnio_error());
1931 else
1932 return _rseed;
1933 }
1934 else
1935 svlog.critical("Rseed in input () "+p+" cannot be intepreted as integer",__FILE__,__LINE__,sevnstd::sevnio_error());
1936
1937 return 1;
1938 }
1939
1940 inline std::string inspect_param_sntype(std::string p){
1942 if (get_svpar_str("snmode")!="list"){
1943 p=get_svpar_str("snmode");
1944 }
1945 else if(get_svpar_str("snmode")=="list" and p==utilities::PLACEHOLDER){
1946 svlog.critical("Using placeholder option for sntype but the parameter snmode is"
1947 " set to list",__FILE__,__LINE__,sevnstd::params_error());
1948 }
1949
1950 return p;
1951 }
1952
1953 inline double inspect_param_spin(std::string p){
1954
1956 if (get_svpar_str("spin")!="list"){
1957 p=get_svpar_str("spin");
1958 }
1959 else if(get_svpar_str("spin")=="list" and p==utilities::PLACEHOLDER){
1960 svlog.critical("Using placeholder option for sntype but the parameter spin is"
1961 " set to list",__FILE__,__LINE__,sevnstd::params_error());
1962 }
1963
1964
1965 return utilities::s2n<double>(p, __FILE__, __LINE__);
1966 }
1967
1968
1970
1977 utilities::jump_convergence find_new_track(bool is_merger=false);
1978
1984 set_forcejump();
1985 return find_new_track(true); //true is to set is_merging=true, this enable to search the mass within MIN_ZAMS - MAX_ZAMS
1986 }
1987
1988
1990
1993
1994
1995protected:
1996
2007 _Dtout
2009
2010
2011
2012
2014
2015 //TODO This implementation relies on the fact that params order remain constant. Use a more robust implementation with set?
2016
2017 //io and ID are already set now, we have just to define params and call the default_initialiser.
2018 //params is a vector of string containing:
2019 //0-mzams; 1-Z; 2-spin; 3-sn_type; 4-tini; 5-tf; 6-dtout;
2020 if (mzams!=utilities::NULL_DOUBLE) init_params[0] = utilities::n2s(mzams,__FILE__,__LINE__,20);
2021 if (Z!=utilities::NULL_DOUBLE) init_params[1] = utilities::n2s(Z,__FILE__,__LINE__,20);
2023 }
2024
2026
2027 //TODO This implementation relies on the fact that params order remain constant. Use a more robust implementation with set?
2028
2029 //io and ID are already set now, we have just to define params and call the default_initialiser.
2030 //params is a vector of string containing:
2031 //0-mzams; 1-Z; 2-spin; 3-sn_type; 4-tini; 5-tf; 6-dtout;
2032 if (mzams!=utilities::NULL_DOUBLE) init_params[0] = utilities::n2s(mzams,__FILE__,__LINE__,20);
2033 if (Z!=utilities::NULL_DOUBLE) init_params[1] = utilities::n2s(Z,__FILE__,__LINE__,20);
2034 if (tini!=utilities::NULL_DOUBLE) init_params[4] = utilities::n2s(tini,__FILE__,__LINE__,20);
2035 }
2036
2043 void default_initialiser(bool isareset = false, bool pureHE = false);
2044
2045
2055
2056 change_params(mzams, Z, tini); //Modify init params
2057
2058 //reset all the V,V0,value and value0 to 0. This is necessary for a number of reason.
2059 //E.g. the mass cannot increase in SSE, so it can happens the the value of the mass is restored to the old one
2060 //in correct_interpolation_errors and correct_interpolation_errors_real in property.h
2061 for (auto& prop:properties)
2062 prop->reset();
2063
2064 default_initialiser(true,ami_on_pureHE_track); //Initialise with the new values
2065
2066 jtrack_counter=0; //reset jump tracks counter
2067 }
2068
2077 std::string tini_str = utilities::n2s(tini,__FILE__,__LINE__);
2078 reset(mzams, Z, tini_str);
2079 }
2080
2082 //TODO, make find_mass_linear and find_mass_bisection as an utility function in utility.h?
2101 double find_mass_linear(double mlow, double mhigh, const double MAX_MASS, const double MIN_MASS, const double plife, const size_t Phase, const bool pureHE, double & best_rel_err, utilities::jump_convergence& convergence, const size_t property_id=Mass::ID, const double z_look=utilities::NULL_DOUBLE);
2102
2118 double find_mass_bisection(double mlow, double mhigh, const double MAX_MASS, const double MIN_MASS, const double plife, const size_t Phase, const bool pureHE, double & best_rel_err, utilities::jump_convergence& convergence, const size_t property_id=Mass::ID, const double z_look=utilities::NULL_DOUBLE);
2119
2126 utilities::jump_convergence match_M(double & best_rel_err, bool is_merger=false);
2134 utilities::jump_convergence match_core(double & best_rel_err, _UNUSED bool is_merger=false);
2135
2141 utilities::jump_convergence match_HE_and_binding(double Ebind, double & best_rel_err, double Min_Mass=utilities::NULL_DOUBLE, double Max_Mass=utilities::NULL_DOUBLE, bool pureHe=false);
2149
2154
2160
2161 for (auto& p : properties)
2162 p->correct_interpolation_errors_real(this);
2163
2164 }
2166
2173 int _main_get_bse_phase(bool old=false) const;
2174
2175 inline std::string log_mess_COnaked(){
2176
2178
2179 return w;
2180 }
2181
2183
2185
2186 return w;
2187 }
2188
2190
2191 //TODO juste temporarly, is nothing wrong just to reduce the amount of logprinting
2192 //std::string w = utilities::log_print("NEWTRACK",this,getp_0(Mass::ID),getp_0(MHE::ID),getp_0(MCO::ID),getp_0(Radius::ID),getp(Mass::ID),getp(MHE::ID),getp(MCO::ID),getp(Radius::ID),getp(Phase::ID),get_zams0(),get_zams(), outcome);
2193 std::string w="";
2194
2195 return w;
2196 }
2197
2198private:
2199
2200
2201 inline void set_mzams(const double a, const char* file, const int line) {
2202
2203 const double MAX_ZAMS=get_max_zams();
2204 const double MIN_ZAMS=get_min_zams();
2205
2206 if(std::isnan(a) or std::isinf(a))
2207 svlog.critical("Error on star initialisation (" + get_id_name() +"): MZAMS set to INF or NAN", file, line, sevnstd::sevnio_error());
2208 else if(a <= 0.0 and initialise_as_remnant!=Empty)
2209 svlog.critical("Error on star initialisation (" + get_id_name() +"): MZAMS cannot be zero and not initiliased as an Empty remnant, current value " +
2210 utilities::n2s(a, __FILE__, __LINE__), file, line,sevnstd::sevnio_error());
2211 else if(a < 0.0)
2212 svlog.critical("Error on star initialisation (" + get_id_name() +"): MZAMS cannot be negative, current value " +
2213 utilities::n2s(a, __FILE__, __LINE__), file, line,sevnstd::sevnio_error());
2214 else if ( (a > MAX_ZAMS or a < MIN_ZAMS) and initialise_as_remnant==NotARemnant){
2215 svlog.critical("Error on star initialisation (" + get_id_name() +"): MZAMS is " + utilities::n2s(a, __FILE__, __LINE__) + ": out of range", file, line,sevnstd::sevnio_error());
2216 }
2217 else
2218 mzams = a;
2219 }
2220
2221 inline void set_Z(const double a, const char* file, const int line) {
2222
2223 const double MAX_Z= get_max_Z();
2224 const double MIN_Z= get_min_Z();
2225
2226
2227 if(std::isnan(a) || std::isinf(a))
2228 svlog.critical("Error on star initialisation (" + get_id_name() +"): Z set to INF or NAN", file, line,sevnstd::sevnio_error());
2229 else if(a <= 0.0)
2230 svlog.critical("Error on star initialisation (" + get_id_name() +"): Z cannot be negative", file, line,sevnstd::sevnio_error());
2231 else if (a > MAX_Z || a < MIN_Z)
2232 svlog.critical("Error on star initialisation (" + get_id_name() +"): Z is " + utilities::n2s(a, __FILE__, __LINE__) + ": out of range", file, line,sevnstd::sevnio_error());
2233 else
2234 Z = a;
2235 }
2236
2237 inline void set_sntype(const std::string &a, _UNUSED const char* file, _UNUSED const int line) {
2238 sntype = a;
2239 }
2240
2241 inline void set_tf(const double a, const char* file, const int line) {
2242
2243 if(std::isnan(a) || std::isinf(a))
2244 svlog.critical("Error on star initialisation (" + get_id_name() +"): Tf set to INF or NAN", file, line,sevnstd::sevnio_error());
2245 else if(a < 0.0)
2246 svlog.critical("Error on star initialisation (" + get_id_name() +"): Tf cannot be negative", file, line,sevnstd::sevnio_error());
2247 else
2248 tf = a;
2249 }
2250
2251 inline void set_dtout(const double a, const char* file, const int line) {
2252
2253
2254 if(std::isnan(a) || std::isinf(a))
2255 svlog.critical("Error on star initialisation (" + get_id_name() +"): dtout set to INF or NAN", file, line,sevnstd::sevnio_error());
2256 else if(a <0.0)
2257 svlog.critical("Error on star initialisation (" + get_id_name() +"): dtout cannot be negative", file, line,sevnstd::sevnio_error());
2258 else
2259 dtout = a;
2260 }
2261
2262 inline void set_rseed(const unsigned long a, const char* file, const int line){
2263
2264 if(std::isnan(a) || std::isinf(a))
2265 svlog.critical("Error on star initialisation (" + get_id_name() +"): Rseed set to INF or NAN", file, line,sevnstd::sevnio_error());
2266 else if (a<=0)
2267 svlog.critical("Error on star initialisation (" + get_id_name() +"): Rseed cannot be negative or 0", file, line,sevnstd::sevnio_error());
2268 else
2269 rseed = a;
2270 }
2271
2277 void init_1(std::vector<std::string> &params){
2278
2279
2280 bool ignore_global = amiauxiliary();
2281
2282 set_mzams(inspect_param_mass(params[0]), __FILE__, __LINE__);
2283 set_Z(inspect_param_Z(params[1],ignore_global), __FILE__, __LINE__);
2284 set_sntype(inspect_param_sntype(params[3]), __FILE__, __LINE__);
2285 }
2286
2287
2293 void init_2(std::vector<std::string> &params){
2294
2295 bool ignore_global = amiauxiliary();
2296
2298
2299 //properties[Localtime::ID]->init(inspect_param(params[4]));
2300 tini=inspect_param_tini(params[4],ignore_global);
2301 //if (tini==0.) tini=utilities::TINY;
2302
2303 properties[Localtime::ID]->init(0);
2304 properties[Timestep::ID]->resynch(tini,false);
2305
2306 set_tf(inspect_param_tf(params[5]), __FILE__, __LINE__);
2307 dtout=inspect_param_dt(params[6]);
2308 set_dtout(dtout, __FILE__, __LINE__);
2309
2310 }
2311
2319
2320 //TODO this function is still a bit messy, there are a lot of prints and portion that are not executed. It should be cleaned a bit.
2321
2322 auto & _Z = ami_on_pureHE_track ? io->Z_HE : io->Z;
2323 auto & _allzams = ami_on_pureHE_track ? io->allzams_HE : io->allzams;
2324 auto & _tables = ami_on_pureHE_track ? io->tables_HE : io->tables;
2325
2326 auto *Z_id = new size_t [2];
2327
2328 /*************************************************************/
2329 /********** Z and zams of the 4 interpolating tracks *********/
2330 /*************************************************************/
2331 //By default we assume that the index of the interpolating tracks
2332 // i and i+1 (for z) and j, j+1 (for Mass) are always such that Z[i+1]>Z[i] and M[i+1]>M[i]
2333 // M[i][j+1]>M[i][j] and [i+1][j+1]>M[i+1][j].
2334 // The only problem is at the zams and Z upper limit because i+1 and j+1 will be out of index.
2335 // We solve this problem setting i and j has the minimum between the value obtained from the binary search and the dimension of the array -2.
2336 // Therefore when Z and/or Zams in input are coincident with the upper limit, i (j) corresponds to the second-last element of the tables and i+1 (j+1) to the last
2337
2339 Z_id[0] = std::min(utilities::binary_search(&_Z[0], 0, _Z.size()-1, Z),_Z.size()-2); //search the metallicity of the star (Z)
2340 Z_id[1] = Z_id[0] + 1;
2341
2342 //interpolating metallicity values
2343 Ztrack[0] = _Z[Z_id[0]];
2344 Ztrack[1] = _Z[Z_id[1]];
2345
2347 size_t *zams_id = new size_t [4];
2348
2349 for(size_t i = 0, k = 0; i < 2; i++, k+=2){
2350 size_t dim = _allzams[Z_id[i]].size();
2351 zams_id[k] = std::min(utilities::binary_search(&_allzams[Z_id[i]][0], 0, dim-1, mzams), dim-2); //search for the ZAMS of the star (mzams)
2352 zams_id[k+1] = zams_id[k] + 1;
2353 }
2354
2355
2356 //interpolating zams values
2357 Mtrack[0] = _allzams[Z_id[0]][zams_id[0]];
2358 Mtrack[1] = _allzams[Z_id[0]][zams_id[1]];
2359 Mtrack[2] = _allzams[Z_id[1]][zams_id[2]];
2360 Mtrack[3] = _allzams[Z_id[1]][zams_id[3]];
2361 /*************************************************************/
2362
2363
2364 //get the right table pointers
2365 for(size_t i = 0; i < 2; i++) {
2366 size_t zid = Z_id[i];
2367
2368 for(size_t k = 0; k < 2; k++) {
2369 size_t mid = zams_id[k + 2*i];
2370
2371 for (int j = 0; j < _Ntables; j++) {
2372 if (_tables[j][zid].empty()){
2373 tables[j][k + 2*i] = nullptr; //Tables have not be loaded, use a nullptr
2374 } else{
2375 tables[j][k + 2*i] = &_tables[j][zid][mid]; //points to the j-th table, at the zid-th metallicity, at the mid-th zams
2376 }
2377 //utilities::hardwait("A",j,tables[j][k + 2*i],__FILE__,__LINE__);
2378 //star is always init at t=0, then we call the evolve function to evolve it at the desired time (read from the param file)
2379 }
2380 }
2381 }
2382
2383 //std::cout<<" Star pointers set "<<tables[_Mass][0]->at(0)<<" "<<tables[_Mass][1]->at(0)<<std::endl;
2384 //std::cout<<" Star pointers set "<<tables[_Mass][2]->at(0)<<" "<<tables[_Mass][3]->at(0)<<std::endl;
2385 //exit(1);
2386
2387
2388 //We use linear weights that are functions of mzams to calculate the evolution of all the stellar
2389 //evolution parameters.
2390
2391 //1st point: maybe, we should use weights that use luminosities to calculate luminosities, radii to calculate
2392 //radii and so on... Example: if mzams=60 and the two interpolating tracks are at mzams_1 = 61 and mzams_2 = 59
2393 //the weights are both 0.5, therefore 0.5*61 + 0.5*59 = 60 (correct). But this is not true for luminosities,
2394 //for example, on the MS, L = C*M^3.5, which is not linear in masses!!
2395
2396 //2nd point: linear weights works well on the ZAMS because Mass vs ZAMS at t=tzams is, obviously, a linear relation.
2397 //Still, the relation Mass vs ZAMS at t!=tzams is NOT a linear relation therefore linear weights are wrong.
2398 //If the mass-grid of the look-up tables is dense enough we can assume that the relation Mass vs ZAMS is locally linear.
2399 //But, how dense that should be to obtain a good approximation? The same, of course, holds for the other physical
2400 //stellar parameters.
2401
2402
2403
2404
2405 for(size_t i = 0; i < 2; i++) {
2406 size_t zid = Z_id[i];
2407
2408 for (size_t k = 0; k < 2; k++) {
2409 size_t mid = zams_id[k + 2 * i];
2410
2411 //tphase_neigh[k + 2 * i].resize(_tables[_Phase][zid][mid].size()/2 + 1); //+1 = supernova time.. starparameter::Remnant
2412 tphase_neigh[k + 2 * i].resize(Nphases + 1); //+1 = supernova time.. starparameter::Remnant
2413
2414 //format file: time phase time phase time phase
2415
2416
2417 //check if there are too many phases in the look-up tables
2418 if(_tables[_Phase][zid][mid].size()/2. + 1 > Nphases)
2419 svlog.critical("Too many phases specified in the look-up tables. Please check your tables", __FILE__, __LINE__);
2420
2421 //initialize all tphase_neigh to -1
2422 for (double &j : tphase_neigh[k + 2 * i])
2423 j = -1;
2424
2425
2426 for (size_t t = 0; t < _tables[_Phase][zid][mid].size(); t+=2) {
2427 double value_t = _tables[_Phase][zid][mid][t];
2428 int value_p = (int) _tables[_Phase][zid][mid][t+1];
2429
2430
2431
2432 if(tphase_neigh[k + 2 * i][value_p] != -1)
2433 svlog.critical("Phase time has already been set. Do you have duplicated in the look-up tables?", __FILE__, __LINE__);
2434 else
2435 tphase_neigh[k + 2 * i][value_p] = value_t;
2436
2437 }
2438
2439 //set also remnant time, which is not included in the look-up tables
2440 size_t last_point = _tables[_Time][zid][mid].size();
2441 tphase_neigh[k + 2 * i][Remnant] = _tables[_Time][zid][mid][last_point-1];
2442
2443
2444#if 0
2445 bool heset = false;
2446 for (size_t j = 0; j < io->tables[_MCO][zid][mid].size(); j++) {
2447
2448 if (io->tables[_MCO][zid][mid][j] != 0.0) {
2449 t_neigh_co[k + 2 * i] = io->tables[_Time][zid][mid][j - 1];
2450 break;
2451 }
2452
2453 if (io->tables[_MHE][zid][mid][j] != 0.0 && !heset) {
2454 t_neigh_he[k + 2 * i] = io->tables[_Time][zid][mid][j - 1];
2455 heset = true;
2456 }
2457 }
2458#endif
2459 }
2460 }
2461
2462#if 0
2463 //check if some phase is missing and alert the user
2464 for(int i = 0; i < 4; i++) {
2465 for (int j = 0; j < starparameter::Nphases; j++) {
2466 if (tphase_neigh[i][j] == -1) {
2467 //TODO print a message that the following phase is missing...
2468 }
2469 }
2470 }
2471#endif
2472 /*
2473 std::cout<<" No weird phases... printout phases"<<std::endl;
2474 for(int i = 0; i < 4; i++) {
2475 for (int j = 0; j < Nphases; j++) {
2476 //std::cout<<tphase_neigh[i][j]<<" ";
2477 }
2478 //std::cout<<std::endl;
2479 }
2480 */
2481
2482 /*
2483 for(int i = 0; i < 4; i++) {
2484 std::cout<<" t(he_start) = "<<tphase_neigh[i][TerminalMainSequence]<<" t(co_start) = "<<tphase_neigh[i][TerminalCoreHeBurning]<<std::endl;
2485 }
2486 */
2487
2488 //cout<<" nphases = "<<Nphases<<endl;
2489
2490
2491
2492 //now I am ready to set all the weights
2493 for (auto &prop : properties) prop->set_w(this);
2494
2495 //Get weights from Phases
2496 double *massw = properties[Phase::ID]->get_wm();
2497 double *metalw = properties[Phase::ID]->get_wz();
2498 //initialize tphase vector of the star using the tphase_neigh vectors
2499 for (int j = 0; j < Nphases; j++){
2500 if(tphase_neigh[0][j] != -1 && tphase_neigh[1][j] != -1 && tphase_neigh[2][j] != -1 && tphase_neigh[3][j] != -1) {
2501 double tphase_zlow = tphase_neigh[0][j] * massw[0] + tphase_neigh[1][j] * massw[1];
2502 double tphase_zhigh = tphase_neigh[2][j] * massw[2] + tphase_neigh[3][j] * massw[3];
2503 tphase[j] = metalw[0] * tphase_zlow + metalw[1] * tphase_zhigh;
2504 //cout<<" pesi = "<<metalw[0]<<" "<<metalw[1]<<endl;
2505 //cout<<massw[0]<<" "<<massw[1]<<" "<<massw[2]<<" "<<massw[3]<<endl;
2506 }
2507 else
2508 tphase[j] = -1;
2509 }
2510
2511
2512 /*
2513 std::cout<<" time stellar phases "<<std::endl;
2514 for (int j = 0; j < Nphases; j++){
2515 if(tphase[j] != -1)
2516 //std::cout<<tphase[j]<<" ";
2517 }
2518 std::cout<<std::endl;
2519 */
2520
2521
2522
2523
2524 //calculate also t_he_start and t_co_start for the subphases
2525 double t_he_zlow = tphase_neigh[0][TerminalMainSequence] * massw[0] + tphase_neigh[1][TerminalMainSequence] * massw[1];
2526 double t_he_zhigh = tphase_neigh[2][TerminalMainSequence] * massw[2] + tphase_neigh[3][TerminalMainSequence] * massw[3];
2527 t_he_start = metalw[0] * t_he_zlow + metalw[1] * t_he_zhigh;
2528
2529 double t_co_zlow = tphase_neigh[0][TerminalCoreHeBurning] * massw[0] + tphase_neigh[1][TerminalCoreHeBurning] * massw[1];
2530 double t_co_zhigh = tphase_neigh[2][TerminalCoreHeBurning] * massw[2] + tphase_neigh[3][TerminalCoreHeBurning] * massw[3];
2531 t_co_start = metalw[0] * t_co_zlow + metalw[1] * t_co_zhigh;
2532
2533
2534 /*** Set the pointer of the interpolatinc tracks of the properties to the 0 position of the right table ***/
2535 for (auto &prop : properties) {
2536 svlog.pdebug(" Set pointer for property/TabID: ",prop->name(),"/",prop->TabID(),__FILE__,__LINE__);
2537 prop->set_refpointers(this);
2538 }
2539
2540
2541
2542 svlog.pdebug(" done pointers ",__FILE__,__LINE__);
2543
2544 delete [] Z_id;
2545 delete [] zams_id;
2546
2547
2548 }
2549
2550public:
2551
2552 /*** Define the copy/move constructor and assignement + destructor ***/
2553
2554 //TODO the following should be enabled if we start using unique_ptr
2555
2560 ~Star();
2561
2562
2567 Star (const Star&) = delete;
2568
2569
2575 Star& operator= (const Star&) = delete;
2576
2577
2583 Star (Star && other) = default;
2584
2585
2591 Star& operator=(Star&& other) = default;
2592
2593
2594
2595};
2596
2597//TODO This class should be used to generate auxiliary stars that are used on as temporary object (e.g. during changing of tracks)
2598class Star_auxiliary : public Star{
2599
2600};
2601
2602class Empty : public Star{
2603
2604};
2605
2606
2607//OVERLOAD OSTREAM FOR CLASS
2614inline std::ostream& operator<< (std::ostream &os, Star &s){
2615 os << "Name: " << s.get_name() << ", M: " << s.get_zams() << ", Z: " << s.get_Z() << ", sn_type: " << s.get_sn_type();
2616 os << ", tf: " << s.get_tf() << ", dtout: " << s.get_dtout_original();
2617 return os;
2618}
2619
2620
2621
2622
2623
2624#endif //SEVN_STAR_H
#define _UNUSED
Definition: BinaryProperty.h:20
static size_t ID
Definition: property.h:1656
Definition: binstar.h:26
Binding energy of the envelope.
Definition: property.h:2232
Definition: star.h:2602
static size_t ID
Definition: property.h:2338
Definition: IO.h:53
void print_evolved_summary(const std::string &_name, const unsigned long &_rseed, const size_t &_ID)
Definition: IO.cpp:406
void print_formatted_output(std::vector< std::vector< double > > &printmatrix, const std::string &_name, const unsigned long &_rseed, const size_t &_ID, const bool binaryprint=false)
Definition: IO.h:207
void print_log(std::string filename="logfile.dat")
Definition: IO.cpp:653
void print_failed_summary(const std::string &_name, const unsigned long &_rseed, const size_t &_ID)
Definition: IO.cpp:410
SEVNpar svpar
Definition: IO.h:198
std::vector< std::vector< double > > load_auxiliary_table(std::string name) const
Definition: IO.h:330
void log_put(std::string &loginfo)
Definition: IO.cpp:668
bool rseed_provided()
Parameters call.
Definition: IO.h:195
std::vector< std::vector< std::vector< std::vector< double > > > > tables_HE
Definition: IO.h:157
std::vector< std::vector< double > > allzams
Definition: IO.h:159
std::vector< size_t > printIDs_star
Definition: IO.h:171
std::vector< std::vector< double > > allzams_HE
Definition: IO.h:159
std::vector< std::vector< std::vector< std::vector< double > > > > tables
Definition: IO.h:157
std::vector< double > Z_HE
Definition: IO.h:158
std::vector< double > Z
Definition: IO.h:158
std::vector< std::string > printcolumns_star
Definition: IO.h:165
static size_t ID
Definition: property.h:1008
static size_t ID
Definition: property.h:391
static size_t ID
Definition: property.h:930
static size_t ID
Definition: property.h:856
static size_t ID
Definition: property.h:826
Definition: property.h:776
static size_t ID
Definition: property.h:785
static size_t ID
Definition: property.h:599
static size_t ID
Definition: property.h:1912
Definition: property.h:881
static size_t ID
Definition: property.h:890
static vector< Property * > all
Definition: property.h:313
static size_t ID
Definition: property.h:1167
static size_t ID
Definition: property.h:1127
static size_t ID
Definition: property.h:713
static size_t ID
Definition: property.h:1512
double get_num(std::string name)
Definition: params.h:124
bool get_bool(std::string name)
Definition: params.h:158
std::string get_str(std::string name)
Definition: params.h:142
static size_t ID
Definition: property.h:1930
Definition: star.h:2598
Definition: star.h:39
double get_dtout_original() const
Definition: star.h:906
void sync_with(Star *s)
Definition: star.h:1396
bool iskicked
Definition: star.h:64
bool ami_on_pureHE_track
Definition: star.h:75
double & hestart()
Definition: star.h:998
double get_max_zams() const
Definition: star.h:872
unsigned long rseed
Definition: star.h:98
bool amiBH() const
Definition: star.h:728
std::unique_ptr< utilities::ListGenerator > dtout_generator
Definition: star.h:49
double getp_raw(const size_t &id) const
Definition: star.h:954
void default_initialiser(bool isareset=false, bool pureHE=false)
Definition: star.cpp:968
std::string getps_fk0(const size_t &id) const
Definition: star.h:946
void evolution_guard(const char *file_input=nullptr, int line_input=-1)
Definition: star.h:1128
double inspect_param_dt(std::string p)
Definition: star.cpp:1486
std::string inspect_param_sntype(std::string p)
Definition: star.h:1940
double rzams
Definition: star.h:132
Staremnant * staremnant
Definition: star.h:47
void correct_evolution_error()
Definition: star.h:2159
std::string & get_name()
Definition: star.h:990
void set_staremnant(Staremnant *remnant)
Definition: star.cpp:1457
bool ami_following_QHE
Definition: star.h:76
bool isoutputtime()
Definition: star.h:450
void set_COnaked()
Definition: star.h:1047
size_t get_ID() const
Definition: star.h:989
double rzams0
Definition: star.h:131
void tracktimes()
Definition: star.h:1418
double inspect_param_tf(std::string p)
Definition: star.h:1807
bool table_loaded(size_t propID) const
Definition: star.h:960
void set_QHE()
Definition: star.h:1078
void remnant()
Definition: star.h:170
Material whatamidonating() const
Definition: star.cpp:1262
double Mtrack[4]
Definition: star.h:139
void set_sntype(const std::string &a, _UNUSED const char *file, _UNUSED const int line)
Definition: star.h:2237
double inspect_param_Z(std::string p, bool ignore_global=false)
Definition: star.h:1902
double get_dtout()
Definition: star.h:1136
Lookup::Remnants initialise_as_remnant
FLAGS.
Definition: star.h:61
void set_rseed(const unsigned long a, const char *file, const int line)
Definition: star.h:2262
double inspect_param_spin(std::string p)
Definition: star.h:1953
double Mcore(bool old=false)
Definition: star.h:373
std::string get_phase_str() const
Definition: star.h:987
std::string log_mess_COnaked()
Definition: star.h:2175
bool amiCompact() const
Definition: star.h:744
double Z0
Definition: star.h:127
std::string getps_fk(const size_t &id) const
Definition: star.h:944
Star(const Star *s, size_t _ID, double mzams=utilities::NULL_DOUBLE, double Z=utilities::NULL_DOUBLE, std::string tini=utilities::NULL_STR, bool pureHE=false, unsigned long _rseed=0)
Definition: star.h:323
double get_last_Timestep() const
Definition: star.h:936
double get_current_tphase() const
Definition: star.h:985
Staremnant * get_staremnant() const
Definition: star.h:910
void print_to_log(std::string &message)
Definition: star.h:589
void initialise_auxiliary_star(const Star *s, double mzams, double Z, std::string tini, bool pureHE)
Definition: star.h:209
void update_from_binary(int Property_id, double DV, Binstar *b=nullptr)
Definition: star.h:1351
void init(std::vector< std::string > &params, bool isareset)
Definition: star.h:1606
const supernova * get_supernova() const
Definition: star.h:908
void change_params(double mzams=utilities::NULL_DOUBLE, double Z=utilities::NULL_DOUBLE, double tini=utilities::NULL_DOUBLE)
Definition: star.h:2025
int _main_get_bse_phase(bool old=false) const
Definition: star.cpp:1328
Star(const Star *s, size_t _ID, double mzams=utilities::NULL_DOUBLE, double Z=utilities::NULL_DOUBLE, double tini=utilities::NULL_DOUBLE, bool pureHE=false, unsigned long _rseed=0)
Definition: star.h:350
void set_MHE_min_aftermerge(Star *merged_star)
Definition: star.h:1112
double vkick[4]
Definition: star.h:249
void restore()
Definition: star.h:1361
void explode_as_SNI()
Definition: star.cpp:1228
std::string get_svpar_str(std::string name) const
Definition: star.h:915
bool tobe_SNIA
Definition: star.h:65
double plife() const
Definition: star.h:1413
int get_bse_phase() const
Definition: star.cpp:1449
void recordstate()
Definition: star.h:526
size_t jtrack_counter
Definition: star.h:133
std::string sntype
Definition: star.h:82
bool amiNS_0() const
Definition: star.h:719
bool amiRRL(double Lmin=1.3, double Lmax=1.9, bool just_He_core=false) const
Definition: star.h:815
double age_phase(std::string phase)
Definition: star.h:149
double get_tf() const
Definition: star.h:904
double get_tini() const
Definition: star.h:905
void set_MCO_max()
Definition: star.h:135
bool amIdegenerate() const
Definition: star.h:760
bool amiremnant() const
Definition: star.h:671
double get_Vlast(const size_t &id) const
Definition: star.h:928
double * get_ztrack()
Definition: star.h:994
void change_params(double mzams=utilities::NULL_DOUBLE, double Z=utilities::NULL_DOUBLE, std::string tini=utilities::NULL_STR)
Definition: star.h:2013
void set_tf(const double a, const char *file, const int line)
Definition: star.h:2241
void turn_into_remnant()
Definition: star.cpp:1211
void crem_transition_to_BH()
Definition: star.cpp:1256
double getp_0_raw(const size_t &id) const
Definition: star.h:956
std::string log_mess_jumped(_UNUSED utilities::jump_convergence outcome)
Definition: star.h:2189
void evolve_to_tini_as_remnant()
Definition: star.cpp:1051
double Ztrack[2]
Definition: star.h:140
Star(Star &&other)=default
bool printevents()
Definition: star.h:461
utilities::jump_convergence find_track_after_CE_Ebinding(double Ebind, double Min_Mass, double Max_mass, bool pureHE=false)
Definition: star.cpp:317
bool break_at_remnant
Definition: star.h:68
double * get_mtrack()
Definition: star.h:993
bool amifollowingpureHetrack() const
Definition: star.h:643
bool faulty_initialisation
Definition: star.h:62
void set_empty()
Definition: star.h:1013
bool notprint()
Definition: star.h:460
double mzams
Definition: star.h:130
vector< Property * > properties
Definition: star.h:94
double get_MCO_max() const
Definition: star.h:902
void default_destructor()
Definition: star.cpp:1544
bool amiauxiliary() const
Definition: star.h:800
double get_dtmax()
Definition: star.h:1151
bool needsinit
Definition: star.h:64
void sync_with(double dt)
Definition: star.h:1403
unsigned int dtout_type
Definition: star.h:125
const double * get_tphase() const
Definition: star.h:996
void init_2(std::vector< std::string > &params)
Definition: star.h:2293
bool changedphase
Definition: star.h:248
double get_zams0() const
Definition: star.h:895
bool printall()
Definition: star.h:459
double get_zams() const
Definition: star.h:885
bool get_svpar_bool(std::string name) const
Definition: star.h:916
int lose_the_envelope()
Definition: star.h:1305
void castp(const size_t &id, T classtype)
Definition: star.h:463
double tini
Definition: star.h:123
bool amiWD_0() const
Definition: star.h:698
utilities::jump_convergence match_M(double &best_rel_err, bool is_merger=false)
Definition: star.cpp:613
void initialise_auxiliary_star(const Star *s, double mzams, double Z, double tini, bool pureHE)
Definition: star.h:232
bool amiWR_0() const
Definition: star.h:659
void set_remnant()
Definition: star.h:1037
bool force_jump
Definition: star.h:74
utilities::jump_convergence match_core(double &best_rel_err, _UNUSED bool is_merger=false)
Definition: star.cpp:858
double get_max_Z() const
Definition: star.h:878
std::vector< std::vector< double > > allstates
Definition: star.h:81
double getp_fk0(const size_t &id) const
Definition: star.h:927
utilities::sn_explosion check_remnant_mass_limits()
Definition: star.h:1553
bool amiBH_0() const
Definition: star.h:736
void lookuppositions()
Definition: star.h:1467
bool amiNS() const
Definition: star.h:709
utilities::jump_convergence jump_tracks(Star *s)
Definition: star.cpp:943
double find_mass_bisection(double mlow, double mhigh, const double MAX_MASS, const double MIN_MASS, const double plife, const size_t Phase, const bool pureHE, double &best_rel_err, utilities::jump_convergence &convergence, const size_t property_id=Mass::ID, const double z_look=utilities::NULL_DOUBLE)
Definition: star.cpp:465
double * get_table_pointer_atpos(size_t table_id, int interpolating_track, int pos)
Definition: star.h:975
double get_Z() const
Definition: star.h:886
double dtout
Definition: star.h:124
void copy_property_from(const size_t &prop_id, const size_t &copy_from_id)
Definition: star.h:1006
void reset_staremnant()
Definition: star.cpp:1044
std::vector< std::vector< double > > load_auxiliary_table(std::string tab_name) const
Definition: star.h:519
double t_he_start
Definition: star.h:121
Star(const Star &)=delete
void crem_transition_to_NS()
Definition: star.cpp:1250
std::vector< std::string > init_params
Definition: star.h:88
Material whatamidonating_0() const
Definition: star.cpp:1296
bool evolution_step_completed
Definition: star.h:77
size_t ID
Definition: star.h:89
bool isempty
Definition: star.h:64
double get_Z0() const
Definition: star.h:900
int get_bse_phase_0() const
Definition: star.cpp:1453
double get_rzams()
Definition: star.h:891
double Z
Definition: star.h:128
std::string getps_0(const size_t &id) const
Definition: star.h:945
IO * io
Definition: star.h:87
double find_mass_linear(double mlow, double mhigh, const double MAX_MASS, const double MIN_MASS, const double plife, const size_t Phase, const bool pureHE, double &best_rel_err, utilities::jump_convergence &convergence, const size_t property_id=Mass::ID, const double z_look=utilities::NULL_DOUBLE)
CHANGE OF TRACKS METHODS.
Definition: star.cpp:330
size_t pos[4]
Definition: star.h:245
void set_MHE_min()
Definition: star.h:137
bool is_exploding_as_SNI() const
Definition: star.cpp:1239
bool amifollowingQHE() const
Definition: star.h:792
double get_MHE_min() const
Definition: star.h:903
void evolution_step_done()
Definition: star.h:1125
bool isconaked
Definition: star.h:66
bool is_dtout_generator_callable()
Definition: star.h:50
size_t get_jcounter() const
Definition: star.h:907
SevnLogging svlog
Definition: star.h:85
const std::vector< double > & getstate()
Definition: star.h:920
std::vector< double > state
Definition: star.h:92
double ttimes[4]
Definition: star.h:242
std::string getps(const size_t &id) const
Definition: star.h:943
double getp_fk0_raw(const size_t &id) const
Definition: star.h:957
void recordstate_w_timeupdate()
Definition: star.h:550
double get_last_fromtable(Lookup::Tables tab_id, unsigned int interpolating_track) const
Definition: star.h:250
std::string log_mess_HEnaked(utilities::jump_convergence outcome)
Definition: star.h:2182
std::string log_message_SNIa()
Definition: star.cpp:1476
supernova * SN
Definition: star.h:46
double get_rzams0() const
Definition: star.h:901
bool amIdegenerate_0() const
Definition: star.h:768
bool print_all_steps
Definition: star.h:69
bool amiWD() const
Definition: star.h:687
void resynch(const double &dt)
Definition: star.h:1384
bool haveienvelope() const
Definition: star.h:778
bool repeatstep
Definition: star.h:247
bool amiremnant_0() const
Definition: star.h:677
Star & operator=(const Star &)=delete
double Rcore(bool old=false)
Definition: star.h:392
Init_params
Definition: star.h:2000
@ _Dtout
Definition: star.h:2007
@ _Z
Definition: star.h:2002
@ _Tini
Definition: star.h:2005
@ _Tfin
Definition: star.h:2006
@ _Mzams
Definition: star.h:2001
@ _Spin
Definition: star.h:2003
@ _SN_type
Definition: star.h:2004
bool initialised_on_zams
Definition: star.h:73
double Renvelope(bool old=false)
Definition: star.h:430
unsigned int get_dtout_type()
Definition: star.h:940
void set_rzams()
Definition: star.cpp:1026
double inspect_param_tini(std::string p, bool ignore_global=false)
Definition: star.h:1702
std::string get_id_name() const
Definition: star.h:947
void init_on_lookup()
Definition: star.h:2318
void explode_as_SNI(_UNUSED Binstar *b)
void tobe_exploded_as_SNI()
Definition: star.cpp:1235
utilities::jump_convergence find_new_track_after_merger()
Definition: star.h:1983
void remnant_in_bse(Binstar *b)
Definition: star.h:178
void set_empty_in_bse(Binstar *b)
Definition: star.h:1023
double tphase[Nphases]
Definition: star.h:119
double get_svpar_num(std::string name) const
Get the value of the parameters store in the svpar class in io.
Definition: star.h:914
bool once_conaked
Definition: star.h:67
double & costart()
Definition: star.h:997
bool get_COnaked()
Definition: star.h:1133
Star()
Definition: star.h:265
~Star()
Definition: star.cpp:1569
bool has_been_properly_initiliased()
Definition: star.h:365
void init_1(std::vector< std::string > &params)
Definition: star.h:2277
std::string get_sn_type() const
Definition: star.h:991
Star & operator=(Star &&other)=default
unsigned long inspect_param_rseed(std::string p)
Definition: star.h:1924
utilities::jump_convergence match_HE_and_binding(double Ebind, double &best_rel_err, double Min_Mass=utilities::NULL_DOUBLE, double Max_Mass=utilities::NULL_DOUBLE, bool pureHe=false)
Definition: star.cpp:726
double MHE_min
Definition: star.h:136
std::vector< std::string > get_initparams(bool effective_values=true) const
Definition: star.h:477
bool aminakedco() const
Definition: star.h:664
double get_min_zams() const
Definition: star.h:875
utilities::jump_convergence jump_to_pureHE_tracks()
Definition: star.cpp:132
bool amiempty() const
Definition: star.h:669
utilities::evolution evolve()
Definition: star.cpp:1075
double get_min_Z() const
Definition: star.h:881
bool amiWR() const
Definition: star.h:651
void set_Z(const double a, const char *file, const int line)
Definition: star.h:2221
bool aminakedhelium() const
Flag check.
Definition: star.h:633
double mzams0
Definition: star.h:129
void reset(double mzams=utilities::NULL_DOUBLE, double Z=utilities::NULL_DOUBLE, std::string tini=utilities::NULL_STR)
Definition: star.h:2054
void set_dtout(const double a, const char *file, const int line)
Definition: star.h:2251
std::string name
Definition: star.h:90
double getp_fk_raw(const size_t &id) const
Definition: star.h:955
void set_mzams(const double a, const char *file, const int line)
Definition: star.h:2201
utilities::jump_convergence jump_to_normal_tracks()
Definition: star.cpp:298
void print_failed(bool include_in_output=false)
Definition: star.h:600
bool print_only_end
Definition: star.h:71
void update_jtrack_counter()
Definition: star.h:2153
double Menvelope(bool old=false)
Definition: star.h:411
double * times_in[4]
Definition: star.h:246
void print()
Definition: star.h:576
void set_forcejump()
Definition: star.h:1012
double tf
Definition: star.h:123
double getp_0(const size_t &id) const
Definition: star.h:926
std::vector< double > dtout_phase
Definition: star.h:97
Star(IO *_io, std::vector< std::string > &params, size_t &_ID, bool pureHE=false, unsigned long _rseed=0)
Definition: star.h:275
void evolve_to_tini()
Definition: star.h:1205
double getp_fk(const size_t &id) const
Definition: star.h:925
double get_next_tphase() const
Definition: star.h:986
void set_kicked()
Set flags.
Definition: star.h:1011
bool breaktrigger() const
Definition: star.h:847
void reset(double mzams=utilities::NULL_DOUBLE, double Z=utilities::NULL_DOUBLE, double tini=utilities::NULL_DOUBLE)
Definition: star.h:2076
bool just_exploded()
Definition: star.h:619
void reset_QHE()
Definition: star.h:1086
utilities::jump_convergence find_new_track(bool is_merger=false)
CHANGE OF TRACKS METHODS.
Definition: star.cpp:17
bool amiCompact_0() const
Definition: star.h:752
std::vector< std::vector< double > > tphase_neigh
Definition: star.h:122
bool print_events
Definition: star.h:72
double t_co_start
Definition: star.h:121
double getp(const size_t &id) const
Definition: star.h:924
std::vector< std::vector< std::vector< double > * > > tables
Definition: star.h:93
unsigned long get_rseed()
Definition: star.h:868
bool auxiliary_star
Definition: star.h:63
bool print_per_phase
Definition: star.h:70
double MCO_max
Definition: star.h:134
bool isremnant
Definition: star.h:64
void set_MCO_max_aftermerge(Star *merged_star)
Definition: star.h:1096
double inspect_param_mass(std::string p)
Definition: star.h:1841
bool & kicked()
Definition: star.h:999
Definition: remnant.h:23
static size_t ID
Definition: property.h:1860
static size_t ID
Definition: property.h:488
static size_t ID
Definition: property.h:429
static size_t ID
Definition: property.h:1595
Definition: sevnlog.h:43
void debug(std::string errstate, const char *file_input=nullptr, int line_input=-1) const
Definition: sevnlog.cpp:194
void critical(std::string errstate, const char *file_input=nullptr, int line_input=-1) const
Definition: sevnlog.cpp:85
void pdebug() const
Variadic prints.
Definition: sevnlog.h:191
void warning(std::string errstate, const char *file_input=nullptr, int line_input=-1) const
Definition: sevnlog.cpp:137
Definition: errhand.h:79
Definition: errhand.h:156
Definition: errhand.h:144
Definition: errhand.h:167
Definition: errhand.h:53
Definition: errhand.h:66
Definition: supernova.h:256
Remnants
NOTICE, the order is important (mass ordered): WD, NS, BH.
Definition: lookup_and_phases.h:78
@ COWD
Definition: lookup_and_phases.h:83
@ HeWD
Definition: lookup_and_phases.h:82
@ ONeWD
Definition: lookup_and_phases.h:84
@ Empty
Definition: lookup_and_phases.h:80
@ NS_ECSN
Definition: lookup_and_phases.h:85
@ NS_CCSN
Definition: lookup_and_phases.h:86
@ NotARemnant
Definition: lookup_and_phases.h:81
@ BH
Definition: lookup_and_phases.h:87
Phases
NOTICE: The order is important from less evolved to more evolved.
Definition: lookup_and_phases.h:42
@ TerminalMainSequence
Definition: lookup_and_phases.h:45
@ ShellHeBurning
Definition: lookup_and_phases.h:49
@ Nphases
Definition: lookup_and_phases.h:51
@ ShellHBurning
Definition: lookup_and_phases.h:46
@ Remnant
Definition: lookup_and_phases.h:50
@ MainSequence
Definition: lookup_and_phases.h:44
@ CoreHeBurning
Definition: lookup_and_phases.h:47
@ TerminalCoreHeBurning
Definition: lookup_and_phases.h:48
Tables
Definition: lookup_and_phases.h:19
@ _Phase
Definition: lookup_and_phases.h:28
@ _MHE
Definition: lookup_and_phases.h:23
@ _MCO
Definition: lookup_and_phases.h:24
@ _Time
Definition: lookup_and_phases.h:20
@ _Ntables
Definition: lookup_and_phases.h:38
@ _DTUNKNOWN
Definition: lookup_and_phases.h:185
Material
Definition: lookup_and_phases.h:65
std::string literal(Phases A)
Definition: lookup_and_phases.cpp:8
@ NoEvent
Definition: lookup_and_phases.h:158
bool areEqual(double x, double y)
Definition: utilities.cpp:141
static double omega_crit(double Mass, double Rpolar)
Definition: utilities.h:214
void wait()
Definition: utilities.h:244
const std::string n2s(T val, const char *file_input, const int line_input, const unsigned int precision=6)
Definition: utilities.h:144
const std::string random_keygen(std::mt19937_64 *mtrand)
Definition: utilities.h:346
unsigned int evolution
Definition: utilities.h:103
std::string log_print(const std::string &label, Star *star, ListP... args)
Definition: utilities.h:320
unsigned int jump_convergence
Definition: utilities.h:108
constexpr double TINY
Definition: utilities.h:98
const std::string PLACEHOLDER
Definition: utilities.h:85
const std::string NULL_STR
Definition: utilities.h:93
unsigned int sn_explosion
Definition: utilities.h:114
size_t binary_search(T *array, const size_t left, const size_t right, const T value)
Definition: utilities.h:374
constexpr int SN_NOT_EXPLODE
Definition: utilities.h:117
constexpr int SNIA_EXPLODE
Definition: utilities.h:115
constexpr double NULL_DOUBLE
Definition: utilities.h:89
unsigned long gen_rseed()
Definition: utilities.cpp:11
std::mt19937_64 mtrand
Definition: utilities.cpp:9
constexpr double LARGE
Definition: utilities.h:97
#define FOR4
Definition: star.h:27
std::ostream & operator<<(std::ostream &os, Star &s)
Definition: star.h:2614