SEVN
Loading...
Searching...
No Matches
params.h
Go to the documentation of this file.
1//
2// Created by iorio on 16/03/20.
3//
4
5#ifndef SEVN_PARAMS_H
6#define SEVN_PARAMS_H
7
8#include <map>
9#include <string>
10#include <errhand.h>
11#include <utilities.h>
12#include <sstream>
13#include <iostream>
14#include <set>
15#include <algorithm>
16#include <sevnlog.h>
18#include <lookup_and_phases.h>
19using namespace Lookup;
20
21/***
22 * This class stores and handles the various parameters used in SEVN.
23 *
24 * The parameters are divided in two big groups:
25 * - params_num: these are numerical parameters stored as doubles (even if they are integer);
26 * - params_str: these are litteral parameters stored as strings.
27 * - params_bool:
28 *
29 * Each parameter is composed by three value:
30 * - a name (string),
31 * - a value (double for params_num and string in params_str),
32 * - a short documentation (string).
33 *
34 * The parameters are also divided in groups depending on their "set" behaviour:
35 * - NOT SETTABLE: these parameters cannot be changed at runtime and have to be hardcoded in the class;
36 * - PRIVATE SETTABLE: these parameters cannot be set directly at runtime, but through auxilary methods (e.g. load);
37 * - PUBLIC SETTABLE: these parameters can be set directly at runtime with the method set(name, value).
38 *
39 * In order to retrieve a given parameter there are two get methods:
40 * - get_num(name) to retrieve a numerical parameter,
41 * - get_str(name) to retrieve a str parameter.
42 * - get_str(bool) to retrieve a str parameter.
43 *
44 * This class contains also an override version of the operator <<, so that it can print in a fancy way the
45 * current value of the parameters.
46 *
47 * @note There is a safety check in the constructors so that only one instance of this class can be present in code
48 * (to avoid to have different istance with different parameters value).
49 */
50
51typedef std::pair<double, std::string> num_entry;
52typedef std::pair<std::string, std::string> str_entry;
53typedef std::pair<bool, std::string> bool_entry;
54typedef std::map<std::string, num_entry> map_num;
55typedef std::map<std::string, str_entry> map_str;
56typedef std::map<std::string, bool_entry> map_bool;
57
58class SEVNpar{
59
60public:
61
63
67 if (++instance_counter<2)
68 init();
69 else
70 svlog.critical("Only one active instance of SEVNpar is allowed",__FILE__,__LINE__,sevnstd::params_error());
71 }
77 SEVNpar(int argc, char **argv){
78 if (++instance_counter<2)
79 load(argc,argv,true);
80 else
81 svlog.critical("Only one active instance of SEVNpar is allowed",__FILE__,__LINE__,sevnstd::params_error());
82 }
83
85
86 //load
100 int load(int n, char **val, bool initialise=false);
101
102
104 inline const map_num& get_num_map(){
105 return params_num;
106 }
107
108 inline const map_str& get_str_map(){
109 return params_str;
110 }
111
112 inline const map_bool& get_bool_map(){
113 return params_bool;
114 }
115
116
124 inline double get_num(std::string name){
125
126 auto it=params_num.find(name); //Check if the key is in the map
127
128 if (it!=params_num.end())
129 return params_num[name].first;
130 else {
131 svlog.critical("key " + name + " not present", __FILE__, __LINE__, sevnstd::params_error());
132 return -1.0;
133 }
134 }
142 inline std::string get_str(std::string name){
143 auto it=params_str.find(name); //Check if the key is in the map
144 if (it!=params_str.end())
145 return params_str[name].first;
146 else {
147 svlog.critical("key " + name + " not present", __FILE__, __LINE__, sevnstd::params_error());
148 return "error";
149 }
150 }
158 inline bool get_bool(std::string name){
159
160 auto it=params_bool.find(name); //Check if the key is in the map
161
162 if (it!=params_bool.end())
163 return params_bool[name].first;
164 else
165 svlog.critical("key "+name+" not present",__FILE__,__LINE__,sevnstd::params_error());
166
167 return false;
168 }
177 inline int get(std::string name, double& val){
178 val=get_num(name);
179 return EXIT_SUCCESS;
180 }
185 inline int get(std::string name, std::string& val){
186 val=get_str(name);
187 return EXIT_SUCCESS;
188 }
193 inline int get(std::string name, bool& val){
194 val=get_bool(name);
195 return EXIT_SUCCESS;
196 }
197
202 std::vector<std::string> keys(){
203
204 std::vector<std::string> keys_list;
205 for (auto& key : params_num)
206 keys_list.push_back(key.first);
207 for (auto& key : params_str)
208 keys_list.push_back(key.first);
209
210 return keys_list;
211 }
212
214 //These sets are only available for properties listed in public_settable
227 inline int set(std::string name, double val){
228
229 auto it=public_settable.find(name); //Check if the key is in the map
230 if (it!=public_settable.end())
231 params_num[name].first=val;
232 else
233 svlog.critical("Trying to set key "+name+". The key is not present or it is not directly settable",__FILE__,__LINE__,sevnstd::params_error());
234
235 if (!check()){
236 svlog.critical("Check failed", __FILE__,__LINE__,sevnstd::params_error());
237 }
238
239 return EXIT_SUCCESS;
240 }
245 inline int set(std::string name, std::string val){
246 auto it=public_settable.find(name); //Check if the key is in the map
247 if (it!=public_settable.end())
248 params_str[name].first=val;
249 else
250 svlog.critical("Trying to set key "+name+". The key is not present",__FILE__,__LINE__,sevnstd::params_error());
251
252 if (!check()){
253 svlog.critical("Check failed", __FILE__,__LINE__,sevnstd::params_error());
254 }
255
256
257 return EXIT_SUCCESS;
258 }
259
261
272 inline int set_zlimit(const std::vector<double >& Zlist){
273 //Direct set
274 params_num["min_z"].first=*std::min_element(Zlist.begin(), Zlist.end());
275 params_num["max_z"].first=*std::max_element(Zlist.begin(), Zlist.end());
276 if (check_z())
277 return EXIT_SUCCESS;
278 else
279 svlog.critical("Paramters check failed while settin min_Z, max_Z",__FILE__,__LINE__,sevnstd::params_error());
280
281 return EXIT_FAILURE;
282
283 }
284
295 inline int set_zlimit_HE(const std::vector<double >& Zlist_HE){
296 //Direct set
297 params_num["min_z_he"].first=*std::min_element(Zlist_HE.begin(), Zlist_HE.end());
298 params_num["max_z_he"].first=*std::max_element(Zlist_HE.begin(), Zlist_HE.end());
299 if (check_z_he())
300 return EXIT_SUCCESS;
301 else
302 svlog.critical("Paramters check failed while setting min_Z_he, max_Z_he",__FILE__,__LINE__,sevnstd::params_error());
303
304 return EXIT_FAILURE;
305
306 }
318 inline int set_zams_limit(const std::vector<std::vector<double>>& Zams_list){
319
320
321 // Notice: the max Zams is the minimum between the zams upper limits considering all the metallicites.
322 // The min zams is the maximum between the zams lower limits.
323 double minzams=-1e30, maxzams=1e30;
324 for (auto& zams_at_Z : Zams_list){
325 size_t last_track = zams_at_Z.size();
326 minzams = zams_at_Z[0]>minzams ? zams_at_Z[0] : minzams;
327 maxzams = zams_at_Z[last_track-1]<maxzams ? zams_at_Z[last_track-1] : maxzams;
328 }
329
330 params_num["min_zams"].first=minzams;
331 params_num["max_zams"].first=maxzams;
332
333 if (check_mzams())
334 return EXIT_SUCCESS;
335 else
336 svlog.critical("Paramters check failed while settin min_zams, max_zams",__FILE__,__LINE__,sevnstd::params_error());
337
338 return EXIT_FAILURE;
339 }
351 inline int set_zams_limit_he(const std::vector<std::vector<double>>& Zams_list_HE){
352
353
354 // Notice: the max Zams is the minimum between the zams upper limits considering all the metallicites.
355 // The min zams is the maximum between the zams lower limits.
356 double minzams=-1e30, maxzams=1e30;
357 for (auto& zams_at_Z : Zams_list_HE){
358 size_t last_track = zams_at_Z.size();
359 minzams = zams_at_Z[0]>minzams ? zams_at_Z[0] : minzams;
360 maxzams = zams_at_Z[last_track-1]<maxzams ? zams_at_Z[last_track-1] : maxzams;
361 }
362
363 params_num["min_zams_he"].first=minzams;
364 params_num["max_zams_he"].first=maxzams;
365
366 if (check_mzams_he())
367 return EXIT_SUCCESS;
368 else
369 svlog.critical("Paramters check failed while settin min_zams_he, max_zams_he",__FILE__,__LINE__,sevnstd::params_error());
370
371 return EXIT_FAILURE;
372
373 }
381 inline int set_myself(){
382 params_str["myself"].first=utilities::get_absolute_SEVN_path()+"/";
383 return EXIT_SUCCESS;
384 }
390 inline int set_tables(std::string tables){
391 params_str["tables"].first=tables;
392
393 return EXIT_SUCCESS;
394 }
400 inline int set_tablesHE(std::string tablesHE){
401 params_str["tables_HE"].first=tablesHE;
402
403 return EXIT_SUCCESS;
404 }
405
406
417 std::string print(bool use_default=false){
418
419 int col_width = 35;
420 std::ostringstream out;
421 std::string header;
422 map_num saved_params_num;
423 map_str saved_params_str;
424 map_bool saved_params_bool;
425
426
427 if (use_default){
428 header="#DEFAULT PARAMS";
429 saved_params_num = params_num;
430 saved_params_str = params_str;
431 saved_params_bool = params_bool;
432 init();
433 }
434 else{
435 header="#USED PARAMS";
436 }
437
438 //Header
439 out<<header<<std::endl;
440
441 std::string info_set;
442
443 for(auto& element : params_num){
444
445 if (public_settable.find(element.first)!=public_settable.end())
446 info_set="[N][S] ";
447 else if (private_settable.find(element.first)!=private_settable.end())
448 info_set="[N][PS] ";
449 else
450 info_set="[N][NS] ";
451
452 out<<std::setw(col_width)<<std::left<<element.first+": "<<
453 std::setw(col_width)<<element.second.first<<"//"+info_set+element.second.second<<std::endl;
454 }
455
456 for(auto& element : params_str){
457 if (public_settable.find(element.first)!=public_settable.end())
458 info_set="[L][S] ";
459 else if (private_settable.find(element.first)!=private_settable.end())
460 info_set="[L][PS] ";
461 else
462 info_set="[L][NS] ";
463
464 out<<std::setw(col_width)<<std::left<<element.first+": "<<
465 std::setw(col_width)<<element.second.first<<"//"+info_set+element.second.second<<std::endl;
466 }
467
468 for(auto& element : params_bool){
469
470 if (public_settable.find(element.first)!=public_settable.end())
471 info_set="[B][S] ";
472 else if (private_settable.find(element.first)!=private_settable.end())
473 info_set="[B][PS] ";
474 else
475 info_set="[B][NS] ";
476
477 std::string val = element.second.first==true ? "true" : "false";
478
479 out<<std::setw(col_width)<<std::left<<element.first+": "<<
480 std::setw(col_width)<<val<<"//"+info_set+element.second.second<<std::endl;
481 }
482
483
484 if (use_default){
485 params_num = saved_params_num;
486 params_str = saved_params_str;
487 params_bool = saved_params_bool;
488 }
489
490 return out.str();
491 }
492
493 //NB, since it is a friend function it not a method of the class
501 friend inline std::ostream& operator<< (std::ostream &os, SEVNpar &svpar){
502 os<<svpar.print();
503 return os;
504 }
505
506public:
507 //TODO Call all the parameters in that way, so that it can help IDE
509 inline double ts_maximum_variation() { return get_num("ts_maximum_variation");}
510
511
512protected:
513
515 static std::size_t instance_counter;
517private:
518
519
524 //set are faster than vector
525 static std::set<std::string> public_settable;
526 static std::set<std::string> private_settable;
529
540 inline int prv_set(std::string name, double val){
541
542 if (!is_num_par(name))
543 svlog.critical("Trying to set the num key "+name+". The key is not present",__FILE__,__LINE__,sevnstd::params_error());
544
545 if (is_settable(name))
546 params_num[name].first=val;
547 else{
548 svlog.warning("Trying to set the num key "+name+". The key is non settable ",__FILE__,__LINE__);
549 return EXIT_FAILURE;
550 }
551
552 return EXIT_SUCCESS;
553 };
559 inline int prv_set(std::string name, std::string val){
560
561 if (!is_str_par(name))
562 svlog.critical("Trying to set the str key "+name+". The key is not present",__FILE__,__LINE__,sevnstd::params_error());
563
564 if (is_settable(name))
565 params_str[name].first=val;
566 else{
567 svlog.warning("Trying to set the str key "+name+". The key is non settable ",__FILE__,__LINE__);
568 return EXIT_FAILURE;
569 }
570
571 return EXIT_SUCCESS;
572 }
578 inline int prv_set(std::string name, bool val){
579
580 if (!is_bool_par(name))
581 svlog.critical("Trying to set the boolean key "+name+". The key is not present",__FILE__,__LINE__,sevnstd::params_error());
582
583 if (is_settable(name))
584 params_bool[name].first=val;
585 else{
586 svlog.warning("Trying to set the boolean key "+name+". The key is non settable ",__FILE__,__LINE__);
587 return EXIT_FAILURE;
588 }
589
590 return EXIT_SUCCESS;
591 }
607 inline int set_from_string(std::string name, std::string val){
608
609 int ret;
610 std::string svalue=val;
611 //transform to lower letter
612 //std::transform(svalue.begin(), svalue.end(), svalue.begin(),
613 // [](unsigned char c){ return std::tolower(c); });
614 if (is_num_par(name)) {
615 double value;
616 value = utilities::s2n<double>(svalue, __FILE__, __LINE__);
617 ret = prv_set(name, value); //EXIT_SUCCESS if the value is settable (publicly or private)
618 if (ret==EXIT_FAILURE)
619 svlog.critical("The num key "+name+" is not settable at runtime");
620 } else if (is_str_par(name)) {
621 ret = prv_set(name, svalue); //EXIT_SUCCESS if the value is settable (publicly or private)
622 if (ret==EXIT_FAILURE)
623 svlog.critical("The str key "+name+" is not settable at runtime");
624 } else if (is_bool_par(name)) {
625 bool value;
626 if (val=="true" || val=="t" || val=="yes" || val=="y") value=true;
627 else if (val=="false" || val=="f" || val=="no" || val=="yn") value=false;
628 else svlog.critical("A boolean parameter can be set only with a string: (t)rue, (y)es,"
629 "(f)alse, (n)o",__FILE__,__LINE__,sevnstd::params_error());
630 ret = prv_set(name, value);
631 if (ret==EXIT_FAILURE)
632 svlog.critical("The bool key "+name+" is not settable at runtime");
633 }
634 else{
635 return EXIT_FAILURE;
636 }
637
638 return EXIT_SUCCESS;
639 }
640
641 //aux
647 inline bool is_public_settable(std::string name){
648 return public_settable.find(name)!=public_settable.end();
649 }
655 inline bool is_private_settable(std::string name){
656 return private_settable.find(name)!=private_settable.end();
657 }
663 inline bool is_settable(std::string name){
664 return is_public_settable(name)||is_private_settable(name);
665 }
671 inline bool is_num_par(std::string name){
672 return params_num.find(name)!=params_num.end();
673 }
679 inline bool is_str_par(std::string name){
680 return params_str.find(name)!=params_str.end();
681 }
687 inline bool is_bool_par(std::string name){
688 return params_bool.find(name)!=params_bool.end();
689 }
695 inline bool is_par(std::string name){
696 return is_num_par(name) || is_str_par(name) || is_bool_par(name);
697 }
698
700
706 int default_value_num();
713 int default_value_str();
720 int default_value_bool();
721
728 int init(){
732 if (!check())
733 svlog.critical("Parameters check failed",__FILE__,__LINE__,sevnstd::params_error());
734 return EXIT_SUCCESS;
735 }
736
737
739
746 bool inline check(){
747 bool ret=true;
748 ret=ret && check_star();
749 ret=ret &&check_ns();
750 ret=ret &&check_timestep();
751 ret=ret &&check_GW();
752 ret=ret &&check_mzams();
753 ret=ret &&check_z();
754 ret=ret &&check_jtrack();
755 ret=ret &&check_rlobe();
756 ret=ret &&check_accretion();
757 ret=ret &&check_sn();
758 ret=ret &&check_winds();
759 ret=ret &&check_ce();
760 ret=ret &&check_hard();
761 ret=ret && check_parameters();
762 ret=ret &&check_option_mode();
763 ret=ret &&check_log();
764 ret=ret &&check_ev();
765 ret=ret &&check_systems();
766 return ret;
767 }
768
769 //TODO put together check_star, mzams z
770 //Star
777 bool inline check_star(){
778 if (get_num("star_lambda")<0. and get_num("star_lambda")!=-1 and get_num("star_lambda")!=-11 and get_num("star_lambda")!=-12 and get_num("star_lambda")!=-13 and get_num("star_lambda")!=-2 and get_num("star_lambda")!=-21
779 and get_num("star_lambda")!=-3 and get_num("star_lambda")!=-31
780 and get_num("star_lambda")!=-4 and get_num("star_lambda")!=-41
781 and get_num("star_lambda")!=-5 and get_num("star_lambda")!=-51)
782 svlog.critical("star_lambda>0 or star_lambda=(-1,-11,-12,-13,-2,-21,-3,-31,-4,-41,,-5,-51), current value is "+n2s("star_lambda"),__FILE__,__LINE__,sevnstd::params_error());
783 if (get_num("star_lambda_pureHe")<=0)
784 svlog.critical("star_lambda_pureHe>0, current value is "+n2s("star_lambda_pureHe"),__FILE__,__LINE__,sevnstd::params_error());
785 if (get_num("star_lambda_fth")<0. or get_num("star_lambda_fth")>1.)
786 svlog.critical("0<=star_lambda_fth<=1, current value is "+n2s("star_lambda_fth"),__FILE__,__LINE__,sevnstd::params_error());
787 if (get_num("star_lambda")>0 and get_num("star_lambda_fth")!=0)
788 svlog.warning("The parameter star_lambda_fth is larger than 0, but the parameter star_lambda is not -1. The star_lambda_fth will not be used!",
789 __FILE__,__LINE__);
790 if (get_num("star_tshold_WR_envelope")<0 or get_num("star_tshold_WR_envelope")>1)
791 svlog.critical("0<=star_tshold_WR_envelope<=1, current value is "+n2s("star_tshold_WR_envelope"),__FILE__,__LINE__,sevnstd::params_error());
792
793
794
795 return true;
796 }
797
798 //NS
799 bool inline check_ns(){
800 if (get_num("ns_magnetic_tscale")<=0.)
801 svlog.critical("ns_magnetic_tscale>0, current value is "+n2s("ns_magnetic_tscale"),__FILE__,__LINE__,sevnstd::params_error());
802 if (get_num("ns_magnetic_mscale")<=0.)
803 svlog.critical("ns_magnetic_mscale>0, current value is "+n2s("ns_magnetic_mscale"),__FILE__,__LINE__,sevnstd::params_error());
804
805 return true;
806 }
807
808 //SN
809 bool inline check_sn(){
810 if (get_num("sn_co_lower_sn")<=0)
811 svlog.critical("sn_co_lower_sn>0, current value is "+n2s("sn_co_lower_sn"),__FILE__,__LINE__,sevnstd::params_error());
812 if (get_num("sn_co_lower_ecsn")<=0)
813 svlog.critical("sn_co_lower_ecsn>0, current value is "+n2s("sn_co_lower_ecsn"),__FILE__,__LINE__,sevnstd::params_error());
814 if (get_num("sn_co_lower_ecsn")>get_num("sn_co_lower_sn"))
815 svlog.critical("sn_co_lower_sn>sn_co_lower_ecsn, current value are "+n2s("sn_co_lower_sn")+" and " +n2s("sn_co_lower_ecsn"),__FILE__,__LINE__,sevnstd::params_error());
816 if (get_num("sn_max_ns_mass")<=0)
817 svlog.critical("sn_max_ns_mass>0, current value is "+n2s("sn_max_ns_mass"),__FILE__,__LINE__,sevnstd::params_error());
818 if (get_num("sn_Mchandra")<=0.)
819 svlog.critical("sn_Mchandra>0, current value is "+n2s("sn_Mchandra"),__FILE__,__LINE__,sevnstd::params_error());
820 if (get_num("sn_compact_csi25_tshold")<0. and get_num("sn_compact_csi25_tshold")!=-1)
821 svlog.critical("sn_compact_csi25_tshold>0 or -1, current value is "+n2s("sn_compact_csi25_tshold"),__FILE__,__LINE__,sevnstd::params_error());
822 if (get_num("sn_Mremnant_average_NS")<=0.)
823 svlog.critical("sn_Mremnant_average_NS>0, current value is "+n2s("sn_Mremnant_average_NS"),__FILE__,__LINE__,sevnstd::params_error());
824 if (get_num("sn_Mremnant_std_NS")>get_num("sn_max_ns_mass"))
825 svlog.critical("M_mean for NS mass distribution is larger than the maximum ns mass, this means that more than 50% of the sample will be rejected. Please use a different the input distribution.",__FILE__,__LINE__,sevnstd::params_error());
826 if (get_num("sn_Mremnant_std_NS")<=0.)
827 svlog.critical("sn_Mremnant_std_NS>0, current value is "+n2s("sn_Mremnant_std_NS"),__FILE__,__LINE__,sevnstd::params_error());
828 if (get_num("sn_compact_fallback")<0. or get_num("sn_compact_fallback")>1.)
829 svlog.critical("0.<sn_compact_fallback<1., current value is "+n2s("sn_compact_fallback"),__FILE__,__LINE__,sevnstd::params_error());
830 if (get_num("sn_Mremnant_average")<=0. and get_num("sn_Mremnant_average")!=-1.)
831 svlog.critical("sn_Mremnant_average>0 (or -1), current value is "+n2s("sn_Mremnant_average"),__FILE__,__LINE__,sevnstd::params_error());
832 if (get_num("sn_Mejected_average")<=0. and get_num("sn_Mremnant_average")!=-1.)
833 svlog.critical("sn_Mejected_average>0 (or -1), current value is "+n2s("sn_Mejected_average"),__FILE__,__LINE__,sevnstd::params_error());
834
835 return true;
836 }
837 //Timestep
844 bool inline check_timestep(){
845
846 if (get_num("ts_min_dt")<0. && get_num("ts_min_dt")!=-1.0)
847 svlog.critical("ts_min_dt>0 or ts_min_dt=-1, current value is "+n2s("ts_min_dt"),__FILE__,__LINE__,sevnstd::params_error());
848 if (get_num("ts_max_dt")<0. && get_num("ts_max_dt")!=-1.0)
849 svlog.critical("ts_max_dt>0 or ts_max_dt=-1, current value is "+n2s("ts_max_dt"),__FILE__,__LINE__,sevnstd::params_error());
850 if (get_num("ts_max_dt")<get_num("ts_min_dt") and get_num("ts_max_dt")!=-1.0)
851 svlog.critical("ts_max_dt>ts_min_dt, current values are ts_max_dt= "+n2s("ts_max_dt")+
852 " and ts_min_dt= "+n2s("ts_min_dt"),__FILE__,__LINE__,sevnstd::params_error());
853
854 return true;
855 };
856 //Mass
863 bool inline check_mzams(){
864
865 const double MIN_ZAMS=get_num("min_zams");
866 const double MAX_ZAMS=get_num("max_zams");
867
868 if (MIN_ZAMS<0)
869 svlog.critical("MIN_ZAMS>0, current value is "+ n2s(MIN_ZAMS),__FILE__,__LINE__,sevnstd::params_error());
870 if (MAX_ZAMS<0)
871 svlog.critical("MAX_ZAMS>0, current value is "+ n2s(MAX_ZAMS),__FILE__,__LINE__,sevnstd::params_error());
872 if (MAX_ZAMS<MIN_ZAMS)
873 svlog.critical("MAX_ZAMS>MIN_ZAMS, current values are: MAX_ZAMS= "+ n2s(MAX_ZAMS)
874 +", MIN_ZAMS= "+n2s(MIN_ZAMS),__FILE__,__LINE__,sevnstd::params_error());
875
876 return true;
877 }
878 //Mass HE
885 bool inline check_mzams_he(){
886
887 const double MIN_ZAMS=get_num("min_zams_he");
888 const double MAX_ZAMS=get_num("max_zams_he");
889
890 if (MIN_ZAMS<0)
891 svlog.critical("MIN_ZAMS_HE>0, current value is "+ n2s(MIN_ZAMS),__FILE__,__LINE__,sevnstd::params_error());
892 if (MAX_ZAMS<0)
893 svlog.critical("MAX_ZAMS_HE>0, current value is "+ n2s(MAX_ZAMS),__FILE__,__LINE__,sevnstd::params_error());
894 if (MAX_ZAMS<MIN_ZAMS)
895 svlog.critical("MAX_ZAMS_HE>MIN_ZAMS_HE, current values are: MAX_ZAMS_HE= "+ n2s(MAX_ZAMS)
896 +", MIN_ZAMS_HE= "+n2s(MIN_ZAMS),__FILE__,__LINE__,sevnstd::params_error());
897
898 return true;
899 }
900 //Z
907 bool inline check_z(){
908
909 const double MINZ=get_num("min_z");
910 const double MAXZ=get_num("max_z");
911
912 if (MINZ<0)
913 svlog.critical("MIN_Z>0, current value is "+ n2s(MINZ),__FILE__,__LINE__,sevnstd::params_error());
914 if (MAXZ<0)
915 svlog.critical("MAX_Z>0, current value is "+ n2s(MAXZ),__FILE__,__LINE__,sevnstd::params_error());
916 if (MAXZ<MINZ)
917 svlog.critical("MAX_Z>MIN_Z, current values are: MAX_Z= "+ n2s(MAXZ)
918 +", MIN_Z= "+n2s(MINZ),__FILE__,__LINE__,sevnstd::params_error());
919
920 return true;
921
922 }
923 //Z
930 bool inline check_z_he(){
931
932 const double MINZ=get_num("min_z_he");
933 const double MAXZ=get_num("max_z_he");
934
935 if (MINZ<0)
936 svlog.critical("MIN_Z_HE>0, current value is "+ n2s(MINZ),__FILE__,__LINE__,sevnstd::params_error());
937 if (MAXZ<0)
938 svlog.critical("MAX_Z_HE>0, current value is "+ n2s(MAXZ),__FILE__,__LINE__,sevnstd::params_error());
939 if (MAXZ<MINZ)
940 svlog.critical("MAX_Z_HE>MIN_Z_HE, current values are: MAX_Z_HE= "+ n2s(MAXZ)
941 +", MIN_Z_HE= "+n2s(MINZ),__FILE__,__LINE__,sevnstd::params_error());
942
943 return true;
944
945 }
946 //jtrack
953 bool inline check_jtrack(){
954
955
956 if (get_num("jtrack_tshold_dm_rel")<=0)
957 svlog.critical("jtrack_tshold_dm_rel>0, current value is "+ n2s("jtrack_tshold_dm_rel"),__FILE__,__LINE__,sevnstd::params_error());
958 if (get_num("jtrack_h_err_rel_max")<=0)
959 svlog.critical("jtrack_h_err_rel_max>0, current value is "+ n2s("jtrack_h_err_rel_max"),__FILE__,__LINE__,sevnstd::params_error());
960 if (get_num("jtrack_max_dm_factor")<0)
961 svlog.critical("jtrack_max_dm_factor>=0, current value is "+ n2s("jtrack_max_dm_factor"),__FILE__,__LINE__,sevnstd::params_error());
962 if (get_num("jtrack_min_dm_factor")<0)
963 svlog.critical("jtrack_min_dm_factor>=0, current value is "+ n2s("jtrack_min_dm_factor"),__FILE__,__LINE__,sevnstd::params_error());
964 if (get_num("jtrack_max_iteration")<=0)
965 svlog.critical("jtrack_max_iteration>=0, current value is "+ n2s("jtrack_max_iteration"),__FILE__,__LINE__,sevnstd::params_error());
966 if (get_num("jtrack_max_dm_factor")<=get_num("jtrack_min_dm_factor"))
967 svlog.critical("jtrack_max_dm_factor>jtrack_min_dm_factor, current values are: jtrack_max_dm_factor="+
968 n2s("jtrack_max_dm_factor")+" jtrack_min_dm_factor="+n2s("jtrack_min_dm_factor"),__FILE__,__LINE__,sevnstd::params_error());
969 if (get_num("jtrack_dm_step")<=0)
970 svlog.critical("jtrack_dm_step>0, currenta value is "+ n2s("jtrack_dm_step"),__FILE__,__LINE__,sevnstd::params_error());
971
972 return true;
973
974 }
975 //RLO
982 bool inline check_rlobe(){
983 if (get_num("rlo_f_mass_accreted")<0 || get_num("rlo_f_mass_accreted")>1)
984 svlog.critical("0<rlo_f_mass_accreted<1, current value is "+n2s("rlo_f_mass_accreted"),__FILE__,__LINE__,sevnstd::params_error());
985 if (get_num("rlo_eps_nova")<0 || get_num("rlo_eps_nova")>1)
986 svlog.critical("0<rlo_eps_nova<1, current value is "+n2s("rlo_eps_nova"),__FILE__,__LINE__,sevnstd::params_error());
987
988 bool negative_gamma_ok = (get_num("rlo_gamma_angmom")==-1.0) || (get_num("rlo_gamma_angmom")==-2.0);
989 if ( (get_num("rlo_gamma_angmom")<0) && (negative_gamma_ok==false) )
990 svlog.critical("rlo_gamma_angmom>0 or rlo_gamma_angmom=-1 or rlo_gamma_angmom=-2, current value is "+n2s("rlo_gamma_angmom"),__FILE__,__LINE__,sevnstd::params_error());
991 if (get_num("rlo_gamma_angmom")>1)
992 svlog.critical("rlo_gamma_angmom<=1, current value is "+n2s("rlo_gamma_angmom"),__FILE__,__LINE__,sevnstd::params_error());
993
994 if (get_num("rlo_max_nuclearmt")<0)
995 svlog.critical("rlo_max_nuclearmt>0, current value is "+n2s("rlo_max_nuclearmt"),__FILE__,__LINE__,sevnstd::params_error());
996
997
998 return true;
999 }
1000 //GW
1007 bool inline check_GW(){
1008
1009 if (get_num("gw_tshold")<0)
1010 svlog.critical("gw_tshold>0, current value is "+n2s("gw_tshold"),__FILE__,__LINE__,sevnstd::params_error());
1011 return true;
1012 }
1013 //Wind
1020 bool inline check_winds(){
1021
1022 if (get_num("w_alpha")<0.)
1023 svlog.critical("w_alpha>0, current value is "+n2s("w_alpha"),__FILE__,__LINE__,sevnstd::params_error());
1024 if (get_num("w_beta")<0.)
1025 svlog.critical("w_beta>0, current value is "+n2s("w_beta"),__FILE__,__LINE__,sevnstd::params_error());
1026
1027
1028 return true;
1029 }
1030 //General accretion
1031 bool inline check_accretion(){
1032 if (get_num("eddington_factor")<0)
1033 svlog.critical("eddington_factor>0, current value is "+n2s("eddington_factor"),__FILE__,__LINE__,sevnstd::params_error());
1034
1035 return true;
1036 }
1037 //CE
1044 bool inline check_ce(){
1045
1046
1047 if (get_num("ce_alpha")<0.)
1048 svlog.critical("ce_alpha>0, current value is "+n2s("ce_alpha"),__FILE__,__LINE__,sevnstd::params_error());
1049
1050
1051 if (get_num("ce_kce")!=-1){
1052 if (get_num("ce_kce")<0. || get_num("ce_kce")>1.)
1053 svlog.critical("ce_kce within [0,1] or -1, current value is "+n2s("ce_kce"),__FILE__,__LINE__,sevnstd::params_error());
1054 }
1055 if (get_num("ce_knce")!=-1){
1056 if (get_num("ce_knce")<0. || get_num("ce_kce")>1.)
1057 svlog.critical("ce_knce within [0,1] or -1, current value is "+n2s("ce_knce"),__FILE__,__LINE__,sevnstd::params_error());
1058 }
1059
1060
1061 return true;
1062 }
1063 //Hardening
1070 bool inline check_hard(){
1071
1072 if (get_num("hard_rhoc")<0.)
1073 svlog.critical("hard_rhoc>0, current value is "+n2s("hard_rhoc"),__FILE__,__LINE__,sevnstd::params_error());
1074 if (get_num("hard_sigma")<0.)
1075 svlog.critical("hard_sigma>0, current value is "+n2s("hard_sigma"),__FILE__,__LINE__,sevnstd::params_error());
1076 if (get_num("hard_xi")<0.)
1077 svlog.critical("hard_xi>0, current value is "+n2s("hard_xi"),__FILE__,__LINE__,sevnstd::params_error());
1078 if (get_num("hard_kappa")<0.)
1079 svlog.critical("hard_kappa>0, current value is "+n2s("hard_kappa"),__FILE__,__LINE__,sevnstd::params_error());
1080 if (get_num("hard_mass_average")<0.)
1081 svlog.critical("hard_mass_average>0, current value is "+n2s("hard_mass_average"),__FILE__,__LINE__,sevnstd::params_error());
1082
1083 return true;
1084 }
1085 //Parameters
1086 bool inline check_parameters(){
1087
1088 if( get_str("spin")!="list" and !utilities::string_is_number<double>(get_str("spin"))){
1089 svlog.critical("spin has to be 'list' or a number, current value is "+get_str("spin"),__FILE__,__LINE__,sevnstd::params_error());
1090 }
1091 else if(get_str("spin")!="list"){
1092 std::string s=get_str("spin");
1093 double spin = utilities::s2n<double>(s,__FILE__,__LINE__);
1094 if(spin<0 or spin>1){
1095 svlog.critical("spin (Omega/Omega_crit) has to be in the range [0,1] current value is "+get_str("spin"),__FILE__,__LINE__,sevnstd::params_error());
1096 }
1097 }
1098
1099 return true;
1100 }
1101 //Omode
1102 bool inline check_option_mode(){
1103
1104 if (windsmap.count(get_str("wmode"))==0)
1105 svlog.critical("Winds mode \"" + get_str("wmode") + "\" not available", __FILE__, __LINE__,sevnstd::params_error());
1106 if (rlmap.count(get_str("rlmode"))==0)
1107 svlog.critical("Roche Lobe mode \"" + get_str("rlmode") + "\" not available", __FILE__, __LINE__,sevnstd::params_error());
1108 if (tidesmap.count(get_str("tmode"))==0)
1109 svlog.critical("Tides mode \"" + get_str("tmode") + "\" not available", __FILE__, __LINE__,sevnstd::params_error());
1110 if (gwmap.count(get_str("gwmode"))==0)
1111 svlog.critical("Gravitational Wave mode \"" + get_str("gwmode") + "\" not available", __FILE__, __LINE__,sevnstd::params_error());
1112 if (mixmap.count(get_str("mixmode"))==0)
1113 svlog.critical("Mix mode \"" + get_str("mixmode") + "\" not available", __FILE__, __LINE__,sevnstd::params_error());
1114 if (snkmap.count(get_str("kmode"))==0)
1115 svlog.critical("SN kick mode \"" + get_str("kmode") + "\" not available", __FILE__, __LINE__,sevnstd::params_error());
1116 if (cemap.count(get_str("cemode"))==0)
1117 svlog.critical("CE mode \""+ get_str("cemode") + "\" not available", __FILE__, __LINE__,sevnstd::params_error());
1118 if (outputmap.count(get_str("omode"))==0)
1119 svlog.critical("Output mode \"" + get_str("omode") +"\" not available", __FILE__, __LINE__);
1120 #ifndef H5OUT
1121 if (outputmap.at(get_str("omode"))==OutputOption::_hdf5)
1122 svlog.critical("Output mode set to \"" + get_str("omode") +"\" but hdf5 is not available (you can make it available with the option -Dh5=ON in cmake)", __FILE__, __LINE__);
1123 #endif
1124 if (std::find(Lookup::xspinmodes.begin(), Lookup::xspinmodes.end(), get_str("xspinmode")) == Lookup::xspinmodes.end())
1125 svlog.critical("Black Hole Xspin mode \"" + get_str("xspinmode") + "\" not available", __FILE__, __LINE__,sevnstd::params_error());
1126
1127 return true;
1128
1129 }
1130 //Evolution
1137 bool inline check_ev(){
1138
1139 if (get_num("ev_max_repetitions")<=0)
1140 svlog.critical("ev_max_repetitions>0, current value is "+n2s("ev_max_repetitions"),__FILE__,__LINE__,sevnstd::params_error());
1141 if (get_num("ev_Nchunk")<=0)
1142 svlog.critical("ev_Nchunk>0, current value is "+n2s("ev_Nchunk"),__FILE__,__LINE__,sevnstd::params_error());
1143 if (get_num("ev_naked_tshold")>1e-4)
1144 svlog.critical("ev_naked_tshold<=1e-4, current value is "+n2s("ev_naked_tshold"),__FILE__,__LINE__,sevnstd::params_error());
1145
1146 if(get_str("ev_setwM")!="linear" and get_str("ev_setwM")!="rational" and get_str("ev_setwM")!="log"){
1147 svlog.critical("ev_setwM option "+get_str("ev_setwM") + " not available",__FILE__,__LINE__,sevnstd::params_error());
1148 }
1149 if(get_str("ev_setwM_log")!="linear" and get_str("ev_setwM_log")!="rational" and get_str("ev_setwM_log")!="log"){
1150 svlog.critical("ev_setwM_log option "+get_str("ev_setwM_log") + " not available",__FILE__,__LINE__,sevnstd::params_error());
1151 }
1152 if(get_str("ev_setwM_tphase")!="linear" and get_str("ev_setwM_tphase")!="rational" and get_str("ev_setwM_tphase")!="log"){
1153 svlog.critical("ev_setwM_tphase option "+get_str("ev_setwM_tphase") + " not available",__FILE__,__LINE__,sevnstd::params_error());
1154 }
1155
1156
1157 return true;
1158 }
1159 //LOG
1160 bool inline check_log(){
1161
1162 std::string allowed_log[5]={"debug","info","warning","error","critical"};
1163
1164 if( !utilities::isinlist(get_str("log_level"),std::begin(allowed_log),std::end(allowed_log)) )
1165 svlog.critical("Loglevel "+get_str("log_level")+" not allowed. The possible options are"
1166 ": debug, info, warning, error",__FILE__,__LINE__,sevnstd::params_error());
1167 return true;
1168 }
1169 //Systems
1170 bool inline check_systems(){
1171 if (get_num("nthreads")<=0)
1172 svlog.critical("nthreads>0, current value is "+n2s("nthreads"),__FILE__,__LINE__,sevnstd::params_error());
1173 if (get_num("check_stalling_time")<=0)
1174 svlog.critical("check_stalling_time>0, current value is "+n2s("check_stalling_time"),__FILE__,__LINE__,sevnstd::params_error());
1175
1176 return true;
1177 }
1178
1184 inline std::string n2s(std::string name){
1185 return utilities::n2s(get_num(name),__FILE__,__LINE__);
1186 }
1192 inline std::string n2s(double val){
1193 return utilities::n2s(val,__FILE__,__LINE__);
1194 }
1195
1196
1197};
1198
1199
1200
1201
1202
1203
1204#endif //SEVN_PARAMS_H
Definition: params.h:58
bool check()
CHECK.
Definition: params.h:746
int set(std::string name, double val)
SET and SET like stuff.
Definition: params.h:227
int init()
Definition: params.h:728
bool check_mzams()
Definition: params.h:863
int prv_set(std::string name, double val)
SET.
Definition: params.h:540
SevnLogging svlog
Definition: params.h:514
bool check_ns()
Definition: params.h:799
int set_zlimit(const std::vector< double > &Zlist)
SPECIAL SET.
Definition: params.h:272
const map_num & get_num_map()
GET and GET like stuff.
Definition: params.h:104
std::string print(bool use_default=false)
Definition: params.h:417
bool check_z_he()
Definition: params.h:930
bool check_parameters()
Definition: params.h:1086
double get_num(std::string name)
Definition: params.h:124
static std::size_t instance_counter
Definition: params.h:515
bool get_bool(std::string name)
Definition: params.h:158
double ts_maximum_variation()
Parameter function.
Definition: params.h:509
bool check_GW()
Definition: params.h:1007
bool check_winds()
Definition: params.h:1020
bool is_str_par(std::string name)
Definition: params.h:679
int get(std::string name, bool &val)
Definition: params.h:193
int set_tables(std::string tables)
Definition: params.h:390
bool check_mzams_he()
Definition: params.h:885
bool check_ce()
Definition: params.h:1044
int default_value_num()
Initialisation methods.
Definition: params.cpp:53
bool check_accretion()
Definition: params.h:1031
const map_bool & get_bool_map()
Definition: params.h:112
bool check_sn()
Definition: params.h:809
int load(int n, char **val, bool initialise=false)
load
Definition: params.cpp:307
std::string n2s(double val)
Definition: params.h:1192
int get(std::string name, double &val)
Definition: params.h:177
std::string n2s(std::string name)
Definition: params.h:1184
~SEVNpar()
Definition: params.h:84
static std::set< std::string > public_settable
Definition: params.h:525
bool check_timestep()
Definition: params.h:844
bool is_settable(std::string name)
Definition: params.h:663
int get(std::string name, std::string &val)
Definition: params.h:185
int set(std::string name, std::string val)
Definition: params.h:245
static std::set< std::string > private_settable
Definition: params.h:526
int prv_set(std::string name, bool val)
Definition: params.h:578
bool check_systems()
Definition: params.h:1170
SEVNpar(int argc, char **argv)
Definition: params.h:77
std::vector< std::string > keys()
Definition: params.h:202
bool check_rlobe()
Definition: params.h:982
map_str params_str
Definition: params.h:521
SEVNpar()
Constructor.
Definition: params.h:66
bool check_star()
Definition: params.h:777
int set_zlimit_HE(const std::vector< double > &Zlist_HE)
Definition: params.h:295
map_num params_num
Definition: params.h:520
int prv_set(std::string name, std::string val)
Definition: params.h:559
bool check_log()
Definition: params.h:1160
const map_str & get_str_map()
Definition: params.h:108
bool check_option_mode()
Definition: params.h:1102
bool is_private_settable(std::string name)
Definition: params.h:655
bool check_jtrack()
Definition: params.h:953
bool is_par(std::string name)
Definition: params.h:695
bool is_public_settable(std::string name)
Definition: params.h:647
bool is_num_par(std::string name)
Definition: params.h:671
int set_tablesHE(std::string tablesHE)
Definition: params.h:400
bool check_z()
Definition: params.h:907
int default_value_bool()
Definition: params.cpp:240
int default_value_str()
Definition: params.cpp:169
int set_from_string(std::string name, std::string val)
Definition: params.h:607
int set_zams_limit(const std::vector< std::vector< double > > &Zams_list)
Definition: params.h:318
int set_myself()
Definition: params.h:381
std::string get_str(std::string name)
Definition: params.h:142
map_bool params_bool
Definition: params.h:522
int set_zams_limit_he(const std::vector< std::vector< double > > &Zams_list_HE)
Definition: params.h:351
bool is_bool_par(std::string name)
Definition: params.h:687
friend std::ostream & operator<<(std::ostream &os, SEVNpar &svpar)
Definition: params.h:501
bool check_ev()
Definition: params.h:1137
bool check_hard()
Definition: params.h:1070
Definition: sevnlog.h:43
void critical(std::string errstate, const char *file_input=nullptr, int line_input=-1) const
Definition: sevnlog.cpp:85
void warning(std::string errstate, const char *file_input=nullptr, int line_input=-1) const
Definition: sevnlog.cpp:137
Definition: errhand.h:144
Definition: lookup_and_phases.h:17
const GWMAP gwmap
Definition: lookup_and_phases.cpp:172
const SNKMAP snkmap
Definition: lookup_and_phases.cpp:188
const OUTPUTMAP outputmap
Definition: lookup_and_phases.cpp:92
const WINDSMAP windsmap
Definition: lookup_and_phases.cpp:121
const std::vector< std::string > xspinmodes
Definition: lookup_and_phases.h:141
const RLMAP rlmap
Definition: lookup_and_phases.h:243
const TIDESMAP tidesmap
Definition: lookup_and_phases.cpp:157
const CEMAP cemap
Definition: lookup_and_phases.cpp:197
const MIXMAP mixmap
Definition: lookup_and_phases.cpp:181
std::string get_absolute_SEVN_path()
Definition: utilities.h:573
bool isinlist(T element, Iter it, Iter end)
Definition: utilities.h:642
const std::string n2s(T val, const char *file_input, const int line_input, const unsigned int precision=6)
Definition: utilities.h:144
std::pair< bool, std::string > bool_entry
Definition: params.h:53
std::map< std::string, bool_entry > map_bool
Definition: params.h:56
std::pair< double, std::string > num_entry
Definition: params.h:51
std::map< std::string, str_entry > map_str
Definition: params.h:55
std::map< std::string, num_entry > map_num
Definition: params.h:54
std::pair< std::string, std::string > str_entry
Definition: params.h:52