aboutsummaryrefslogtreecommitdiffstats
path: root/models/models.cc
blob: 8a6303710a2544a2c4b263e79ccdf183d3095276 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include "models.hpp"
#include <core/opt_exception.hpp>
#include "gauss1d.hpp"
#include "bl1d.hpp"
#include "nfw1d.hpp"
#include "bpl1d.hpp"
#include "beta1d.hpp"
#include "nbeta1d.hpp"
#include "dbeta1d.hpp"
#include "lin1d.hpp"
#include "pl1d.hpp"
#include "poly1d.hpp"
#include "bremss.hpp"
#include "beta2d2.hpp"
#include "beta2d.hpp"
#include "dbeta2d2.hpp"
#include "dbeta2d3.hpp"
#include "dbeta2d.hpp"
#include "dl_model.hpp"
#include <iostream>
using namespace std;


namespace opt_utilities
{
  strmodel1d strm1d;
  std::map<std::string,model<double,double,std::vector<double>,std::string>* > model_map;
  std::map<std::string,model<double,vecn<double,2>,std::vector<double>,std::string>* > model2d_map;
  std::list<std::string> get_model_name_list()
  {
    std::list<std::string> result;
    for(std::map<std::string,model<double,double,std::vector<double>,std::string>* >::iterator i=model_map.begin();
	i!=model_map.end();++i)
      {
	result.push_back(i->first);
      }
	return result;
  }

  std::list<std::string> get_model2d_name_list()
  {
    std::list<std::string> result;
    for(map<std::string,model<double,vecn<double,2>,std::vector<double>,std::string>* > ::iterator i=model2d_map.begin();
	i!=model2d_map.end();++i)
      {
	result.push_back(i->first);
      }
    return result;
  }

model<double,double,std::vector<double>,std::string>& get_1dmodel_by_name(const char* name)
  {
    std::map<std::string,model<double,double,std::vector<double>,std::string >* >::iterator iter;
    iter=model_map.find(name);
    if(iter==model_map.end()||iter->second==0)
      {
	throw opt_exception("model does not exist");
      }
    return *(iter->second);
  }

  strmodel1d& get_strm1d()
  {
    return strm1d;
  }

model<double,vecn<double,2>,std::vector<double>,std::string>& get_2dmodel_by_name(const char* name)
  {
    std::map<std::string,model<double,vecn<double,2>,std::vector<double>,std::string>* >::iterator iter;
    iter=model2d_map.find(name);
    if(iter==model2d_map.end()||iter->second==0)
      {
	throw opt_exception("model does not exist");
      }
    return *(iter->second);
  }

  int get_n_1dmodels()
  {
    return model_map.size();
  }

  int get_n_2dmodels()
  {
    return model2d_map.size();
  }

  class model_map_keeper_class
  {
  private:
    void init_model_map()
    {

      //#define DECL_POLY(n) model_map["poly1d##n"]=new poly1d<double,n>;


      model_map["lin1d"]=new lin1d<double>;
      model_map["pl1d"]=new pl1d<double>;
      model_map["bl1d"]=new bl1d<double>;
      model_map["bpl1d"]=new bpl1d<double>;
      model_map["beta1d"]=new beta1d<double>;  
      model_map["bremss"]=new bremss<double>;
      model_map["nbeta1d"]=new nbeta1d<double>;  
      model_map["2beta1d"]=new dbeta1d<double>;
      model_map["nfw"]=new nfw1d<double>;
      model_map["gauss1d"]=new gauss1d<double>;  
      model_map["poly1d2"]=new poly1d<double,2>;
      model_map["poly1d3"]=new poly1d<double,3>;
      model_map["poly1d4"]=new poly1d<double,4>;
      model_map["poly1d5"]=new poly1d<double,5>;
#ifdef __linux__
      model_map["dlmodel"]=new dl_model<double>;
#endif
      //DECL_POLY(7)
    }
    
    void release_model_map()
    {
      for(std::map<std::string,model<double,double,std::vector<double>,std::string>* >::iterator i=model_map.begin();
	  i!=model_map.end();++i)
	{
	  delete i->second;
	}
    }
  public:
    model_map_keeper_class()
    {
      init_model_map();
	  std::cerr<<"1d models Initialized"<<std::endl;
    }
    
    ~model_map_keeper_class()
    {
      release_model_map();
	  std::cerr<<"1d models Released"<<std::endl;
    }

  }model_map_keeper;

  class model2d_map_keeper_class
  {
  private:
    void init_model_map()
    {
      model2d_map["beta2d"]=new beta2d<double>;
      model2d_map["beta2d2"]=new beta2d2<double>;
      model2d_map["dbeta2d"]=new dbeta2d<double>;
      model2d_map["dbeta2d2"]=new dbeta2d2<double>;
      model2d_map["dbeta2d3"]=new dbeta2d3<double>;  
    }
    
    void release_model_map()
    {
      for(std::map<std::string,model<double,vecn<double,2>,std::vector<double>,std::string>* >::iterator i=model2d_map.begin();
	  i!=model2d_map.end();++i)
	{
	  delete i->second;
	}
    }
  public:
    model2d_map_keeper_class()
    {
      init_model_map();
      std::cerr<<"2d models Initialized"<<std::endl;
    }
    
    ~model2d_map_keeper_class()
    {
      release_model_map();
      std::cerr<<"2d models Released"<<std::endl;
    }

  }model2d_map_keeper;


}