SEVN
Loading...
Searching...
No Matches
binstar.h
Go to the documentation of this file.
1//
2// Created by mario on 04/12/18.
3//
4
5#ifndef SEVN_BINSTAR_H
6#define SEVN_BINSTAR_H
7
8#include <BinaryProperty.h>
9#include <Processes.h>
10#include <star.h>
11#include <cmath>
12#include <utilities.h>
13#include <string>
14#include <sstream>
15#include <params.h>
16
17#include <sevnlog.h>
19
20#include <lookup_and_phases.h>
21#include "Orbit.h"
22
23using namespace Lookup;
24
25
26class Binstar {
27
28public:
30 bool broken;
32 bool empty;
36 bool mix;
37 bool comenv;
38 bool is_swallowed[2];
41 //TODO the print options should be removed from the classes stars and binaries and handled by another class only devoted to that
47 bool print_rlo;
49 //Check disable, some process can force the e or a to jump to some values
50 //in that case we have to disable the check for adaptive time step.
58 //Other variables
61 //Guard
63
65
69
70 //Proper constructors
71 Binstar(IO *_io, std::vector<std::string> &params, size_t &_ID, unsigned long _rseed=0){
72
73
74 //GI 03/02/2023: Based on a issue regarding data leak after failed initialisation, I implement
75 //this solution to robustly clean the heap allocated variables after a failed object initilisation.
76 //Indeed, in such cases, the object is never build, so the desctructor is not available.
77 //So, I have implemented a private method default_destructor that is called from the destructor to clean the heap
78 //but can be called also here. So we use a try-catch-rethrow schema to check if the initilisation
79 //was successful, otherwise we clean the heap and then rethrow the error.
80 //We use this schema also for the other two constructors.
81
82 //Try the initialisation
83 try {
84 /***********************************
85 * Some variable assignment
86 ************************************/
87 io = _io;
88 ID = _ID;
89 break_at_remnant = false;
90 broken = onesurvived = empty = false;
92 init_params = params;
93
95 print_all_steps = false;
96 print_per_phase = false;
97 print_events = false;
98 print_rlo = false;
99
100 last_Timestep = 0.0;
101 repeatstep = false;
102 mix = false;
103 comenv = false;
105 is_swallowed[0] = is_swallowed[1] = false;
107 rseed = _rseed;
108 /************************************/
109
110
111 state.resize(io->printcolumns_binary.size());
112
113 for (size_t i = 0; i < BinaryProperty::all.size(); i++) {
114 property.push_back(BinaryProperty::all[i]->Instance()); //create instances for all properties
115 }
116
117 for (size_t i = 0; i < Process::all.size(); i++) {
118 //std:cout<<"Procss "<< Process::all[i]->name() << " " << i <<std::endl;
119 process.push_back(Process::all[i]->Instance(_io)); //create instances for all properties
120 }
121
122
123
124 /***********************************
125 * Init Stars and binary params
126 ************************************/
128 /************************************/
129 }
130 //Catch any kind of error, dangerous in general, but we use it just to clean the heap and then
131 //the error is rethrown and handled somewhere else.
132 catch (...){ //Catch all errors
133 default_destructor(); //Clean the heap associated to class members
134 throw; //Rethrown the exact same error
135 }
136
137
138 }
140
142 inline double getp(const size_t &id) const {return property[id]->get(this);}
143 inline double getp_0(const size_t &id) const {return property[id]->get_0(this);}
144 inline std::string get_name() const {return name;}
145 inline size_t get_ID() const {return ID;}
146 inline Star *getstar(const size_t &id) {return star[id];}
147 inline Process *getprocess(const size_t &id) {return process[id];}
148 inline const std::vector<Process*>& getprocesses() const {return process;}
149 inline const std::vector<double> & getstate() {return state;}
154 inline double get_last_Timestep() const {return last_Timestep;}
155
164 inline unsigned int get_id_more_evolved_star() const{
165 //If one of the star is empty return the other one
166 if (star[0]->isempty and !star[1]->isempty)
167 return 1;
168 else if (star[1]->isempty)
169 return 0;
170 //If both are remnant the older is the more compact following the order HeWD,COWD,ONEWD,NS,BH
171 else if (star[0]->isremnant and star[1]->isremnant and star[0]->getp(RemnantType::ID)!=star[1]->getp(RemnantType::ID))
172 return star[0]->getp(RemnantType::ID)>star[1]->getp(RemnantType::ID) ? 0 : 1;
173 //If both are remnant of the same type, the more evolved is the one with the largest mass
174 else if (star[0]->isremnant and star[1]->isremnant)
175 return star[0]->getp(Mass::ID)>star[1]->getp(Mass::ID) ? 0 : 1;
176 //In the stars have the same phase (not remnant handled before), return the more evolved is the one with the larger plife
177 else if (star[0]->getp(Phase::ID)==star[1]->getp(Phase::ID))
178 return star[0]->plife()>=star[1]->plife() ? 0 : 1;
179 //Finally, if the stars are not empty, not remnant and don't have the same phase
180 //the more evolved is the one with the largest phase.
181 else
182 return star[0]->getp(Phase::ID)>=star[1]->getp(Phase::ID) ? 0 : 1;
183 }
184
194
195 unsigned int _id=get_id_more_evolved_star();
196
197 return getstar(_id);
198 }
199
207 double Radx(size_t starID);
208
209
210
212 inline double get_svpar_num(std::string name) { return io->svpar.get_num(name);};
213 inline std::string get_svpar_str(std::string name) { return io->svpar.get_str(name);};
214 inline bool get_svpar_bool(std::string name) { return io->svpar.get_bool(name);};
215 inline unsigned long get_rseed(){
216 if (rseed==0)
217 svlog.critical("rseed has not been initialised",__FILE__,__LINE__,sevnstd::bse_error());
218 return rseed;
219 }
220
221 //TODO Move to the src file
222 virtual void evolve() {
223
225
226 svlog.debug(std::to_string(property[BTimestep::ID]->get()));
227 svlog.debug(std::to_string(property[BTimestep::ID]->get_0()));
228 //utilities::wait(__PRETTY_FUNCTION__);
229
230
231 //double twait=4.5668373678e+01;
232 double twait=1E30;
233 if (getp(BWorldtime::ID)>twait){
234 svlog.debug("S0 T= " + utilities::n2s(star[0]->getp(Timestep::ID),__FILE__,__LINE__) + " T0=" + utilities::n2s(star[0]->getp_0(Timestep::ID),__FILE__,__LINE__) + " WT=" + utilities::n2s(star[0]->getp(Worldtime::ID),__FILE__,__LINE__),__FILE__,__LINE__);
235 svlog.debug("S1 T= " + utilities::n2s(star[1]->getp(Timestep::ID),__FILE__,__LINE__) + " T0=" + utilities::n2s(star[1]->getp_0(Timestep::ID),__FILE__,__LINE__) + " WT=" + utilities::n2s(star[1]->getp(Worldtime::ID),__FILE__,__LINE__),__FILE__,__LINE__);
236 svlog.debug("B T= " + utilities::n2s(getp(BTimestep::ID),__FILE__,__LINE__) + " T0=" + utilities::n2s(getp_0(BTimestep::ID),__FILE__,__LINE__) + " WT=" + utilities::n2s(getp(BWorldtime::ID),__FILE__,__LINE__),__FILE__,__LINE__);
237 utilities::wait("Before synch_dt");
238 }
239
240
241
242 /*************************************
243 * Synchronise proposed timesteps
244 *************************************/
246
247
248
249 if (getp(BWorldtime::ID)>twait){
250 svlog.debug("S0 T= " + utilities::n2s(star[0]->getp(Timestep::ID),__FILE__,__LINE__) + " T0=" + utilities::n2s(star[0]->getp_0(Timestep::ID),__FILE__,__LINE__) + " WT=" + utilities::n2s(star[0]->getp(Worldtime::ID),__FILE__,__LINE__),__FILE__,__LINE__);
251 svlog.debug("S1 T= " + utilities::n2s(star[1]->getp(Timestep::ID),__FILE__,__LINE__) + " T0=" + utilities::n2s(star[1]->getp_0(Timestep::ID),__FILE__,__LINE__) + " WT=" + utilities::n2s(star[1]->getp(Worldtime::ID),__FILE__,__LINE__),__FILE__,__LINE__);
252 svlog.debug("B T= " + utilities::n2s(getp(BTimestep::ID),__FILE__,__LINE__) + " T0=" + utilities::n2s(getp_0(BTimestep::ID),__FILE__,__LINE__) + " WT=" + utilities::n2s(getp(BWorldtime::ID),__FILE__,__LINE__),__FILE__,__LINE__);
253 utilities::wait("After synch_dt");
254 }
255
256 /*************************************
257 * Single stellar evolution
258 *************************************/
259 //At this point timesteps are in sync
260 star[0]->evolve();
261 //timestep of star 0 may have changed at this point
262 star[1]->evolve();
263 //timestep of star 1 may have changed at this point
264
265
266
267 //std::cout<<" 0: "<<star[0]->getp_0(Timestep::ID)<<" "<<star[0]->getp(Timestep::ID)<<std::endl;
268 //std::cout<<" 1: "<<star[1]->getp_0(Timestep::ID)<<" "<<star[1]->getp(Timestep::ID)<<std::endl;
269
270 if (getp(BWorldtime::ID)>twait){
271 svlog.debug("S0 T= " + utilities::n2s(star[0]->getp(Timestep::ID),__FILE__,__LINE__) + " T0=" + utilities::n2s(star[0]->getp_0(Timestep::ID),__FILE__,__LINE__) + " WT=" + utilities::n2s(star[0]->getp(Worldtime::ID),__FILE__,__LINE__),__FILE__,__LINE__);
272 svlog.debug("S1 T= " + utilities::n2s(star[1]->getp(Timestep::ID),__FILE__,__LINE__) + " T0=" + utilities::n2s(star[1]->getp_0(Timestep::ID),__FILE__,__LINE__) + " WT=" + utilities::n2s(star[1]->getp(Worldtime::ID),__FILE__,__LINE__),__FILE__,__LINE__);
273 svlog.debug("B T= " + utilities::n2s(getp(BTimestep::ID),__FILE__,__LINE__) + " T0=" + utilities::n2s(getp_0(BTimestep::ID),__FILE__,__LINE__) + " WT=" + utilities::n2s(getp(BWorldtime::ID),__FILE__,__LINE__),__FILE__,__LINE__);
274 svlog.pdebug("S0 type",star[0]->getp(Phase::ID),__FILE__,__LINE__);
275 utilities::wait("After evolve star");
276 }
277
278 //Check if the the two stars have been evolved with the same timestep.
279 //If not repeat the evolution of the star with the largest used timestep (V0).
280 //Plus update the new timestep of the binary.
282
283
284
285 if (getp(BWorldtime::ID)>twait){
286 svlog.debug("S0 T= " + utilities::n2s(star[0]->getp(Timestep::ID),__FILE__,__LINE__) + " T0=" + utilities::n2s(star[0]->getp_0(Timestep::ID),__FILE__,__LINE__) + " WT=" + utilities::n2s(star[0]->getp(Worldtime::ID),__FILE__,__LINE__),__FILE__,__LINE__);
287 svlog.debug("S1 T= " + utilities::n2s(star[1]->getp(Timestep::ID),__FILE__,__LINE__) + " T0=" + utilities::n2s(star[1]->getp_0(Timestep::ID),__FILE__,__LINE__) + " WT=" + utilities::n2s(star[1]->getp(Worldtime::ID),__FILE__,__LINE__),__FILE__,__LINE__);
288 svlog.debug("B T= " + utilities::n2s(getp(BTimestep::ID),__FILE__,__LINE__) + " T0=" + utilities::n2s(getp_0(BTimestep::ID),__FILE__,__LINE__) + " WT=" + utilities::n2s(getp(BWorldtime::ID),__FILE__,__LINE__),__FILE__,__LINE__);
289 utilities::wait("After check and synch");
290 }
291
292
293 /*************************************
294 * Binary stellar evolution
295 *************************************/
296 //Here the timestep of the binary is equal to the one just done by the single stars (s->getp_0(Timestep::ID)).
297 //So it is equal to one defined in synchronise_dt_star if the stars have not repeated the evoluion in evolve.
298 //In that case it is equal to the actual timestep of the single stellar evolution
300 //NOT NEEDED ANYMORE
301 //binary_evolution_status = evolve_binary();
302 //Now if the the Binary properties have not been uptated, update in any case the BTimestep to be syncrhonised with stars Timestepgit
303 //if (binary_evolution_status==utilities::BIN_EV_NOT_DONE){
304 // std::cout<<" WE "<<std::endl;
305 //property[BTimestep::ID]->evolve(this);
306 // std::cout<<" WE2 "<<std::endl;
307 //}
308
309 if (getp(BWorldtime::ID)>twait){
310 svlog.debug("S0 T= " + utilities::n2s(star[0]->getp(Timestep::ID),__FILE__,__LINE__) + " T0=" + utilities::n2s(star[0]->getp_0(Timestep::ID),__FILE__,__LINE__) + " WT=" + utilities::n2s(star[0]->getp(Worldtime::ID),__FILE__,__LINE__),__FILE__,__LINE__);
311 svlog.debug("S1 T= " + utilities::n2s(star[1]->getp(Timestep::ID),__FILE__,__LINE__) + " T0=" + utilities::n2s(star[1]->getp_0(Timestep::ID),__FILE__,__LINE__) + " WT=" + utilities::n2s(star[1]->getp(Worldtime::ID),__FILE__,__LINE__),__FILE__,__LINE__);
312 svlog.debug("B T= " + utilities::n2s(getp(BTimestep::ID),__FILE__,__LINE__) + " T0=" + utilities::n2s(getp_0(BTimestep::ID),__FILE__,__LINE__) + " WT=" + utilities::n2s(getp(BWorldtime::ID),__FILE__,__LINE__),__FILE__,__LINE__);
313 utilities::wait("After evolv binary");
314 }
315
316
317
318 //Check if the binary evolution has re-evolved the system with a smaller timestep
319 //In that case just re-evolve the stars with this timestep and again the binary.
320 //NB: This check assumes that the stars are already synchronised (check_and_sync_sse) and that
321 //the binary has been evolved with the actual time step of the stellar evolution. Therefore,
322 // the new proposed binary dt can be only smaller than the stellar dt. If it is larger
324 //property[BTimestep::ID]->resynch(1e30);
325 //At this point stars and binary processes have been evolved with the same timestep
326
328
329
330 /****************************************************************
331 * FINAL STUFF. All the updates that need to be done after a complete evolution step (all the repetitions already done) go here
332 * Last checks, change tracks and check mass limits for remnants
333 * Plus, evolve the derived property so that they are updated considering processes and change of tracks
334 *****************************************************************/
335 //TODO The points below can be completely skipped if the binary is broken
337 Star * this_star = star[0];
338 Star * other_star = star[1];
339
340 for (int i=0; i<2; i++){
341 //First of all check if it has to explode
342 //TODO this is a temporary solution, we have to think about how to handle SNIa
343 if (this_star->is_exploding_as_SNI()){
344 //TODO Can we remove the difference between explode_as_SNI(binstar *b) and explode_as_SNI(), i.e. between Star::set_empty and Star::set_empty_in_bse
345 this_star->explode_as_SNI(this); //Use explode_as_SNI(Binstar* b) so that timestep_0 is reset to the current value
346 set_broken();
348 //TODO, Here we are using a arbitrary process just to set the event, we should have a proper way to set the event without calling the preoceese
350 }
351 check_and_set_QHE(this_star); //Check if we have to flag QHE evolution
352 this_star->find_new_track(); //Check if we have to change tracks
353 this_star->check_remnant_mass_limits(); //Check if we have to performe a Crem transition (e.g. from NS to BH)
354 //If the Mass is extremely small set it to empty.
355 if (this_star->getp(Mass::ID)<1e-3){this_star->set_empty();}
356
357 //Update derived properties (basic properties could have been changes during binary processes)
358 //TODO Now this check is made also inside binary_evolution. I have to check if we can remove this call from here
360
361 //update Maximum CO and minimum HE (only after the CO core has been formed)
362 if (get_svpar_bool("ev_set_maxCO") and std::isnan(this_star->get_MCO_max()) and this_star->getp(Phase::ID) >= TerminalCoreHeBurning and !this_star->amiremnant()){
363 this_star->set_MCO_max();
364 }
365 if (get_svpar_bool("ev_set_minHE") and std::isnan(this_star->get_MHE_min()) and this_star->getp(Phase::ID) >= TerminalCoreHeBurning and !this_star->amiremnant()){
366 this_star->set_MHE_min();
367 }
368 utilities::swap_stars(this_star,other_star);
369 }
370
371 //Very last thing Binary event special evolve
372 property[BEvent::ID]->special_evolve(this);
373
374 }
375
376 //TODO tO save space maybe we can flush the allstates data to the output file after a given number of stored elements.
377 //TODO use a binary property NextOutput
379
381 evolution_guard(__FILE__,__LINE__);
382
383 //TODO check that they are in sync
386
388
389 }
390 inline void recordstate() {
391
392 //TODO check that they are in sync
393 star[0]->recordstate();
394 star[1]->recordstate();
395
397 }
398 inline void recordstate_binary(){
399
400 for(size_t i = 0; i < io->printcolumns_binary.size(); i++){
401 //Concerning the Timestep, put the used one not the proposed one
402 if ((size_t)io->printIDs_binary[i]==BTimestep::ID)
403 state[i] = getp_0((size_t)io->printIDs_binary[i]);
404 //state[i] = star[0]->getp_0(Timestep::ID);
405 else
406 state[i] = getp((size_t)io->printIDs_binary[i]);
407
408 }
409
410
412 combinedstate.insert(combinedstate.end(), star[1]->getstate().begin(), star[1]->getstate().end());
413 combinedstate.insert(combinedstate.end(), state.begin(), state.end());
414
415 allstates.push_back(combinedstate);
416
417 //TODO The single recordstate of the two stars are now stored in combinedstate. Can we reset and free the memory of star.allstates?
418 for (auto & cc: combinedstate)
419 svlog.debug("Combined state: "+utilities::n2s(cc,__FILE__,__LINE__));
420 }
421
422 inline void set_broken(){
423 broken = true;
425 //std::string w = utilities::log_print("BROKEN", this);
426 //print_to_log(w);
427 }
428 inline void set_empty(){onesurvived=false; empty=true;}
429 inline void set_onesurvived(){
430 //set_onesurvived is triggered when a star in the system becomes empty:
431 //if oneservived is already true, the binasry system is now empty
432 //if empty the binary is empty and onesurvived has to be false.
433 if (empty)
434 onesurvived = false;
435 //if true and not empty, not the binary system becomes empty and onesurvived is reset to false
436 if (onesurvived){
437 onesurvived = false;
438 empty = true;
439 }
440 //If binary is not empty and onesurvived was false set onesurvived to true
441 else
442 onesurvived= true;
443 }
444 inline bool breaktrigger() const {
445
446
447 //if (star[0]->isempty and star[1]->isempty) return true; //the system is empty
448 if ( (broken or onesurvived) and break_at_broken) return true; //system is broken or just one object in the system
449 else if (star[0]->isremnant and star[1]->isremnant and break_at_remnant) return true;
450 else if ( (!star[0]->isremnant or !star[1]->isremnant) and break_at_remnant ){
451 return false;
452 }
453 else if(!break_at_remnant){
455 }
456 else{
457 SevnLogging svlog_tmp;
458 svlog_tmp.critical("Star breaktrigger check failed (Maybe Worldtimes are not synchronised?)",__FILE__,__LINE__);
459 }
460
461
462 return false;
463
464 }
465
471 inline bool is_process_ongoing(const size_t &id) const {return process[id]->is_process_ongoing();}
472
474
479 inline bool processes_alarm(const size_t &id) const {return process[id]->is_special_evolution_alarm_on();}
480
485 bool process_alarm_any() const;
486
491 inline void reset_all_processes_alarms(){for (auto& proc : process) proc->special_evolution_alarm_switch_off();};
492
494
497 inline void reset_events(){
498 for (auto& proc : process)
499 proc->reset_event();
500 }
509
510 bool RLOB_triggered=false;
511 bool Merger_triggered=false;
512 bool Collision_triggered=false;
513 bool CE_triggered=false;
514
515 double event=-1.0;
516 for (const auto& proc : process){
517 double this_event=proc->get_event();
518 if (this_event==EventsList::RLOBegin) RLOB_triggered=true;
519 else if (this_event==EventsList::Merger) Merger_triggered=true;
520 else if (this_event==EventsList::Collision) Collision_triggered=true;
521 else if (this_event==EventsList::CE) CE_triggered=true;
522 else if (this_event==EventsList::CE_Merger){CE_triggered=true;Merger_triggered=true;}
523 if (this_event>event){
524 event=this_event;
525 }
526 }
527
528 //Check composite events
529 if (Collision_triggered and CE_triggered and Merger_triggered) event=EventsList::Collision_CE_Merger;
530 else if (Collision_triggered and CE_triggered) event=EventsList::Collision_CE;
531 else if (Collision_triggered and Merger_triggered) event=EventsList::Collision_Merger;
532 else if (RLOB_triggered and CE_triggered and Merger_triggered) event=EventsList::RLOB_CE_Merger;
533 else if (RLOB_triggered and CE_triggered) event=EventsList::RLOB_CE;
534 else if (RLOB_triggered and Merger_triggered) event=EventsList::RLOB_Merger;
535 else if (CE_triggered and Merger_triggered) event=EventsList::CE_Merger;
536
537 return event;
538 }
539
541
542 //TODO, outoput stuff should be removed from the star and binary classes and handeld by a separate class
547 bool isoutputtime();
548
549 inline bool printall() {return print_all_steps;}
550 inline bool notprint() {return print_only_end;}
557 void print(){
558 io->print_log();
561 }
576 void print_failed(bool include_in_output=false){
577 io->print_log();
579 if (include_in_output)
581 }
582
588 void inline print_to_log(std::string& message){
589 io->log_put(message);
590 }
591
599 void init(const std::vector<std::string> &params);
600
601 inline std::vector<double> get_zams() {
602
603 std::vector<double> zams{star[0]->get_zams(), star[1]->get_zams()};
604 return zams;
605 };
606
607 inline std::vector<double> get_Z() {
608
609 std::vector<double> Z{star[0]->get_Z(), star[1]->get_Z()};
610 return Z;
611 };
612
619 inline void set_tf(const double a, const char* file, const int line) {
620
621 if(std::isnan(a) || std::isinf(a))
622 svlog.critical("Tf set to INF or NAN", file, line);
623 else if(a < 0.0)
624 svlog.critical("Tf cannot be negative", file, line);
625 else
626 tf = a;
627 }
628
635 inline void set_dtout(const double a, const char* file, const int line) {
636
637 if(std::isnan(a) || std::isinf(a))
638 svlog.critical("dtout set to INF or NAN", file, line);
639 else if(a <0.0)
640 svlog.critical("dtout cannot be negative", file, line);
641 else
642 dtout = a;
643 }
644
645
646 inline void evolution_step_done(){
647 last_Timestep = getp_0(BTimestep::ID); //V0 in BTimestep contains the Timestep of the step currently done, V is the time predicted for the new Timestep
649 }
650 inline void evolution_guard(const char *file_input = nullptr, int line_input = -1){
652 svlog.critical("The function recordstate_w_timeupdate can be called only after an evolution step",file_input,line_input,sevnstd::bse_error());
653 }
654 inline double get_tf() const { return tf;};
655
656 //TODO We have to take into account that the two stars can have different phases times. For now we just disable the print_per_phase option
657 inline double get_dtout() {
658 //if(print_per_phase)
659 // 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...
660 //else
661 // return dtout;
662 return dtout;
663 }
664
665 inline std::string get_id_name() const {
666 std::string mss = "ID: "+utilities::n2s(ID,__FILE__,__LINE__) + " Name: "+utilities::n2s(name,__FILE__,__LINE__);
667 return mss;
668 }
669
677 utilities::sn_explosion check_accretion_on_compact(size_t donorID, size_t accretorID, double DMaccreted);
678
684
685 Star *donor = star[0];
686 Star *accretor = star[1];
687 double DM_accretor;
688
689 for (size_t i=0; i<2; i++){
690
692 //Consider all the process, NB DM can be negative
693 //Cycle over all the processes to get the total DM variation.
694 DM_accretor=0;
695 for (auto &proc : process){
696 DM_accretor += proc->get_var(accretor->get_ID(), Mass::ID);
697 }
698
699 //Check only if it is really accreting
700 if (DM_accretor>0)
701 check_accretion_on_compact(donor->get_ID(), accretor->get_ID(), DM_accretor);
702
703
704 utilities::swap_stars(donor, accretor);
705 }
706 }
707
713 //If broken or onesurvived or empty set properties to broken and return true
714 if (broken or onesurvived or empty) {
715 for (auto &prop: property)
716 prop->set_broken(this);
717 return true;
718 }
719
720 return false;
721 }
722
723
726 double SetXspinBavera(const double, const double) const; // Computes the Xspin following Bavera et al. (2021). Used only for the second BH spin in the case of a binary undergoing WR+BH --> BH+BH.
728
729
730
731protected:
732
734 double tf;
735 double dtout;
736 std::vector<double> state;
737 std::vector<double> combinedstate;
738 std::vector<std::vector<double>> allstates;
740
743
746 void synchronise_dt_star();
747
752 void check_and_sync_sse();
753
754
759 void check_and_sync_bse();
760
762
773
781
793 std::size_t mass_limiting_property_id);
794
806 bool check_and_set_QHE(Star *accretor);
807
815
817
821
823
824protected:
828private:
829
831 vector<Process*> process;
832 vector<BinaryProperty*> property;
833 Star *star[2]={nullptr, nullptr};
835 size_t ID;
836 std::vector<std::string> init_params;
837 std::string name;
838 unsigned long rseed;
840
843
844 inline void resynch(const double &dt){
845
846 for (auto &prop : property) prop->restore();
847 property[BTimestep::ID]->resynch(dt);
848
849 }
850
854 void default_destructor();
855
863 void call_stars_constructor(std::vector<std::string> &params_star1, std::vector<std::string> &params_star2);
864
874 void init_stars(const std::vector<std::string> &params);
875
885 void init_stars_legacy(const std::vector<std::string> &params);
886
891 inline void set_initial_semimajor(double a_ini){
892 if (a_ini<=0){
893 svlog.critical("Error on binary initialisation (" + get_id_name() +"): Semimajor is " + utilities::n2s(a_ini, __FILE__, __LINE__) + ": out of range (Semimajor>0)", __FILE__, __LINE__,sevnstd::sevnio_error());
894 }
895 property[Semimajor::ID]->init(a_ini);
896 }
897
903 inline void set_initial_semimajor(std::string a_ini){
904
905 double a_inid;
906 try{
907 a_inid = utilities::s2n<double>(a_ini, __FILE__, __LINE__);
908 }
909 catch(sevnstd::sevnio_error& e){
910 svlog.critical("Impossible to transform the given initial Semimajor axis to a number ("+
911 get_id_name()+"): its value is "+a_ini,__FILE__,__LINE__,sevnstd::sevnio_error());
912 }
913 set_initial_semimajor(a_inid);
914 }
915
916
921 inline void set_initial_eccentricity(double ecc_ini){
922 if (ecc_ini<0 or ecc_ini>=1){
923 svlog.critical("Error on binary initialisation (" + get_id_name() +"): Eccentricity is " + utilities::n2s(ecc_ini, __FILE__, __LINE__) + ": out of range (0<=Eccentricity<1)", __FILE__, __LINE__,sevnstd::sevnio_error());
924 }
925 property[Eccentricity::ID]->init(ecc_ini);
926 }
927
933 inline void set_initial_eccentricity(std::string ecc_ini){
934
935 double ecc_inid;
936 try{
937 ecc_inid = utilities::s2n<double>(ecc_ini, __FILE__, __LINE__);
938 }
939 catch(sevnstd::sevnio_error& e){
940 svlog.critical("Impossible to transform the given initial Eccentricity to a number ("+
941 get_id_name()+"): its value is "+ecc_ini,__FILE__,__LINE__,sevnstd::sevnio_error());
942 }
943 set_initial_eccentricity(ecc_inid);
944 }
945
946
953 inline void init_binary_properties(const std::vector<std::string> &params){
954
955 int inchoice=inputmapbin.at(io->binput_mode).first;
956
957 std::string a,ecc;
958
959 if (inchoice==InputBinaryOption::_new){
960 a=params[10];
961 ecc=params[11];
962 }
963 else if (inchoice==InputBinaryOption::_legacy){
964 a=params[6];
965 ecc=params[7];
966 }
967
968 //Init semimajor
970
971 //Init eccentricity
973
974 }
975
982 void init_other_params();
983
988 void set_break_at_broken(std::string &tf){
989 if (tf=="broken"){
990 break_at_broken=true;
991 tf="14000"; //Set time to Hubble time
992 }
993 else{
994 break_at_broken=false;
995 }
996 }
997
998 inline void set_rseed(const unsigned long a, const char* file, const int line){
999
1000 if(std::isnan(a) || std::isinf(a))
1001 svlog.critical("Rseed set to INF or NAN", file, line);
1002 else if (a<=0)
1003 svlog.critical("Rseed cannot be negative or 0", file, line);
1004 else
1005 rseed = a;
1006 }
1007
1012 void inline check_init_param(const std::vector<std::string> &params){
1013
1014
1015 int par_expected_size = inputmapbin.at(io->binput_mode).second; //Number of expected parameters given the binput_mode stored in io.
1016 //If rseed is provided we have an extra parameter that is the seed.
1017 if (io->rseed_provided())
1018 par_expected_size+=1;
1019 if ((int)params.size()!=par_expected_size){
1020 std::string par_exp=utilities::n2s(par_expected_size, __FILE__, __LINE__);
1021 std::string inparam_size=utilities::n2s(params.size(), __FILE__, __LINE__);
1022 std::string this_ID=utilities::n2s(ID, __FILE__, __LINE__);
1023 svlog.critical("Number of Binary params needs to be " +par_exp+", it is instead " + inparam_size + " (ID_bin: " + this_ID +"). Maybe you are using inputs containing the ran"
1024 "dom seed, but rseed parameter is false." , __FILE__, __LINE__);
1025 }
1026 }
1028
1029public:
1030
1032 ~Binstar();
1033
1034};
1035
1036
1037
1038#endif //SEVN_BINSTAR_H
static size_t ID
Definition: BinaryProperty.h:579
static size_t ID
Definition: BinaryProperty.h:498
static size_t ID
Definition: BinaryProperty.h:466
static std::vector< BinaryProperty * > all
Definition: BinaryProperty.h:34
Definition: binstar.h:26
void update_derived_properties_star(Star *s)
Definition: binstar.cpp:440
bool print_all_steps
Definition: binstar.h:43
Process * getprocess(const size_t &id)
Definition: binstar.h:147
Star * get_more_evolved_star()
Definition: binstar.h:193
void print_failed(bool include_in_output=false)
Definition: binstar.h:576
bool process_alarm_any() const
Definition: binstar.cpp:1021
bool comenv
Definition: binstar.h:37
void check_init_param(const std::vector< std::string > &params)
Definition: binstar.h:1012
void set_onesurvived()
Definition: binstar.h:429
void set_initial_eccentricity(double ecc_ini)
Definition: binstar.h:921
void recordstate_binary()
Definition: binstar.h:398
void print_to_log(std::string &message)
Definition: binstar.h:588
void set_empty()
Definition: binstar.h:428
void init(const std::vector< std::string > &params)
Definition: binstar.cpp:513
void synchronise_dt_star()
Definition: binstar.cpp:230
void check_AngMomSpin_after_binary_evolution()
Definition: binstar.cpp:984
vector< BinaryProperty * > property
Definition: binstar.h:832
unsigned long get_rseed()
Definition: binstar.h:215
double CE_E_tomatch
Definition: binstar.h:59
std::vector< std::vector< double > > allstates
Definition: binstar.h:738
bool notprint()
Definition: binstar.h:550
void default_destructor()
Definition: binstar.cpp:1047
void resynch(const double &dt)
Definition: binstar.h:844
double SetXspinBavera(const double, const double) const
void set_initial_semimajor(double a_ini)
Definition: binstar.h:891
double tf
MEMBERS///.
Definition: binstar.h:734
double last_Timestep
Definition: binstar.h:39
void set_dtout(const double a, const char *file, const int line)
Definition: binstar.h:635
bool broken
MEMBERS///.
Definition: binstar.h:30
IO * io
Definition: binstar.h:834
SevnLogging svlog
Definition: binstar.h:825
Star * star[2]
Definition: binstar.h:833
std::string get_name() const
Definition: binstar.h:144
void reset_all_processes_alarms()
Definition: binstar.h:491
void check_and_sync_sse()
Definition: binstar.cpp:254
bool print_rlo
Definition: binstar.h:47
bool disable_OmegaRem_NS_check
Definition: binstar.h:54
bool check_and_set_broken()
Definition: binstar.h:712
bool get_svpar_bool(std::string name)
Definition: binstar.h:214
double get_tf() const
Definition: binstar.h:654
bool disable_e_check
Definition: binstar.h:51
size_t get_ID() const
Definition: binstar.h:145
bool force_tiny_dt
Definition: binstar.h:56
double Radx(size_t starID)
Definition: binstar.cpp:1003
unsigned long rseed
Definition: binstar.h:838
unsigned int get_id_more_evolved_star() const
Definition: binstar.h:164
void check_accretion_on_compact()
Definition: binstar.h:683
bool onesurvived
Definition: binstar.h:31
bool break_at_broken
Definition: binstar.h:34
bool empty
Definition: binstar.h:32
std::string name
Definition: binstar.h:837
bool breaktrigger() const
Definition: binstar.h:444
std::vector< double > state
Definition: binstar.h:736
double get_svpar_num(std::string name)
Get the value of the parameters store in the svpar class in io.
Definition: binstar.h:212
virtual void evolve()
Definition: binstar.h:222
bool is_process_ongoing(const size_t &id) const
Definition: binstar.h:471
void check_if_applied_bavera_xspin()
bool isoutputtime()
Outputs.
Definition: binstar.cpp:1030
void print()
Definition: binstar.h:557
~Binstar()
DENSTRUCTORS.
Definition: binstar.cpp:1043
std::vector< double > get_zams()
Definition: binstar.h:601
void set_break_at_broken(std::string &tf)
Definition: binstar.h:988
void check_nakedHe_or_nakedCO_after_binary_evolution()
CHECKS AND CORRECT.
Definition: binstar.cpp:865
void reset_events()
Handle events.
Definition: binstar.h:497
void call_stars_constructor(std::vector< std::string > &params_star1, std::vector< std::string > &params_star2)
Definition: binstar.cpp:589
bool disable_a_check
Definition: binstar.h:52
bool repeatstep
Definition: binstar.h:35
void set_rseed(const unsigned long a, const char *file, const int line)
Definition: binstar.h:998
bool evolution_step_completed
Definition: binstar.h:62
bool print_per_phase
Definition: binstar.h:44
void check_and_sync_bse()
Definition: binstar.cpp:286
double get_dtout()
Definition: binstar.h:657
void init_stars_legacy(const std::vector< std::string > &params)
Definition: binstar.cpp:632
std::vector< std::string > init_params
Definition: binstar.h:836
void set_tf(const double a, const char *file, const int line)
Definition: binstar.h:619
double getp_0(const size_t &id) const
Definition: binstar.h:143
bool mix
Definition: binstar.h:36
void limit_and_correct_mass_transfer_for_donor_from_binary(Star *donor, Star *accretor, std::size_t mass_limiting_property_id)
Definition: binstar.cpp:716
vector< Process * > process
MEMBERS///.
Definition: binstar.h:831
const std::vector< Process * > & getprocesses() const
Definition: binstar.h:148
std::vector< double > get_Z()
Definition: binstar.h:607
double dtout
Definition: binstar.h:735
bool printall()
Definition: binstar.h:549
bool check_and_set_QHE(Star *accretor)
Definition: binstar.cpp:391
Binstar()
Definition: binstar.h:68
bool print_only_end
Definition: binstar.h:45
void set_initial_semimajor(std::string a_ini)
Definition: binstar.h:903
double get_event_from_processes()
Definition: binstar.h:508
size_t ID
Definition: binstar.h:835
Binstar(IO *_io, std::vector< std::string > &params, size_t &_ID, unsigned long _rseed=0)
Definition: binstar.h:71
void init_stars(const std::vector< std::string > &params)
Definition: binstar.cpp:612
std::vector< double > combinedstate
Definition: binstar.h:737
void recordstate_w_timeupdate()
Definition: binstar.h:378
bool break_at_remnant
Definition: binstar.h:33
void set_initial_eccentricity(std::string ecc_ini)
Definition: binstar.h:933
bool is_swallowed[2]
Definition: binstar.h:38
bool disable_stellar_rotation_check
Definition: binstar.h:55
std::string get_id_name() const
Definition: binstar.h:665
double get_last_Timestep() const
Definition: binstar.h:154
void reset_evolution_flags()
RESET.
Definition: binstar.h:820
double getp(const size_t &id) const
METHODS///.
Definition: binstar.h:142
std::string get_svpar_str(std::string name)
Definition: binstar.h:213
const std::vector< double > & getstate()
Definition: binstar.h:149
void check_and_set_bavera_xspin()
Definition: binstar.cpp:365
void recordstate()
Definition: binstar.h:390
void evolution_step_done()
Definition: binstar.h:646
void evolution_guard(const char *file_input=nullptr, int line_input=-1)
Definition: binstar.h:650
utilities::bse_evolution evolve_binary()
METHODS///.
Definition: binstar.cpp:21
bool processes_alarm(const size_t &id) const
Handle processes alarms.
Definition: binstar.h:479
void init_other_params()
Definition: binstar.cpp:655
bool disable_DM_check
Definition: binstar.h:53
Star * getstar(const size_t &id)
Definition: binstar.h:146
void set_broken()
Definition: binstar.h:422
bool print_events
Definition: binstar.h:46
void init_binary_properties(const std::vector< std::string > &params)
Definition: binstar.h:953
static size_t ID
Definition: BinaryProperty.h:110
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
std::vector< std::string > printcolumns_binary
Definition: IO.h:168
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< size_t > printIDs_binary
Definition: IO.h:172
void log_put(std::string &loginfo)
Definition: IO.cpp:668
bool rseed_provided()
Parameters call.
Definition: IO.h:195
std::string binput_mode
Definition: IO.h:179
static size_t ID
Definition: property.h:785
static size_t ID
Definition: property.h:890
Definition: Processes.h:43
static std::vector< Process * > all
Definition: Processes.h:59
static size_t ID
Definition: property.h:1512
static size_t ID
Definition: Processes.h:249
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: BinaryProperty.h:148
Definition: star.h:39
size_t get_ID() const
Definition: star.h:989
void explode_as_SNI()
Definition: star.cpp:1228
double plife() const
Definition: star.h:1413
void recordstate()
Definition: star.h:526
void set_MCO_max()
Definition: star.h:135
bool amiremnant() const
Definition: star.h:671
void set_empty()
Definition: star.h:1013
double get_MCO_max() const
Definition: star.h:902
double get_zams() const
Definition: star.h:885
utilities::sn_explosion check_remnant_mass_limits()
Definition: star.h:1553
double get_Z() const
Definition: star.h:886
void set_MHE_min()
Definition: star.h:137
bool is_exploding_as_SNI() const
Definition: star.cpp:1239
double get_MHE_min() const
Definition: star.h:903
const std::vector< double > & getstate()
Definition: star.h:920
void recordstate_w_timeupdate()
Definition: star.h:550
utilities::evolution evolve()
Definition: star.cpp:1075
utilities::jump_convergence find_new_track(bool is_merger=false)
CHANGE OF TRACKS METHODS.
Definition: star.cpp:17
double getp(const size_t &id) const
Definition: star.h:924
static size_t ID
Definition: property.h:488
static size_t ID
Definition: property.h:429
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
Definition: errhand.h:79
Definition: errhand.h:53
Definition: lookup_and_phases.h:17
@ TerminalCoreHeBurning
Definition: lookup_and_phases.h:48
const INPUTMAPBIN inputmapbin
Definition: lookup_and_phases.cpp:112
@ SNIa
Definition: lookup_and_phases.h:179
bool areEqual(double x, double y)
Definition: utilities.cpp:141
void wait()
Definition: utilities.h:244
bool bse_evolution
Definition: utilities.h:125
const std::string n2s(T val, const char *file_input, const int line_input, const unsigned int precision=6)
Definition: utilities.h:144
void swap_stars(Star *&s1, Star *&s2)
Definition: utilities.h:617
unsigned int sn_explosion
Definition: utilities.h:114
constexpr double NULL_DOUBLE
Definition: utilities.h:89