Skip to content

Commit 84bef8f

Browse files
author
Martin D. Weinberg
committed
Merge branch 'Toomre' of github.com:EXP-code/EXP into Toomre
2 parents 22b6493 + 9c2f36f commit 84bef8f

7 files changed

Lines changed: 31 additions & 20 deletions

File tree

expui/BiorthBasis.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ namespace BasisClasses
11981198
{"python", DiskType::python}
11991199
};
12001200

1201-
// Dprojection model for cylindrical basis construction
1201+
// Deprojection model for cylindrical basis construction
12021202
const std::map<std::string, Cylindrical::DeprojType> Cylindrical::dplookup =
12031203
{ {"mn", DeprojType::mn},
12041204
{"exponential", DeprojType::exponential},
@@ -1503,7 +1503,7 @@ namespace BasisClasses
15031503
if (conf["cmapz" ]) cmapZ = conf["cmapz" ].as<int>();
15041504
if (conf["ignore" ]) Ignore = conf["ignore" ].as<bool>();
15051505
if (conf["deproject" ]) deproject = conf["deproject" ].as<bool>();
1506-
if (conf["dmodel" ]) dmodel = conf["dmodel" ].as<string>();
1506+
if (conf["dmodel" ]) dmodel = conf["dmodel" ].as<std::string>();
15071507

15081508
if (conf["aratio" ]) aratio = conf["aratio" ].as<double>();
15091509
if (conf["hratio" ]) hratio = conf["hratio" ].as<double>();
@@ -1711,6 +1711,10 @@ namespace BasisClasses
17111711
std::transform(dmodel.begin(), dmodel.end(), dmodel.begin(),
17121712
[](unsigned char c){ return std::tolower(c); });
17131713

1714+
// Map legacy/short model names to canonical keys expected by dplookup
1715+
if (dmodel == "exp") {
1716+
dmodel = "exponential";
1717+
}
17141718

17151719
// Check for map entry
17161720
try {
@@ -1724,7 +1728,7 @@ namespace BasisClasses
17241728
}
17251729
catch (const std::out_of_range& err) {
17261730
if (myid==0) {
1727-
std::cout << "DeprojType error in configuraton file" << std::endl;
1731+
std::cout << "DeprojType error in configuration file" << std::endl;
17281732
std::cout << "Valid options are: ";
17291733
for (auto v : dplookup) std::cout << v.first << " ";
17301734
std::cout << std::endl;
@@ -1735,7 +1739,7 @@ namespace BasisClasses
17351739
if (PTYPE == DeprojType::mn) // Miyamoto-Nagai
17361740
model = std::make_shared<MNdisk>(1.0, H);
17371741
else if (PTYPE == DeprojType::toomre) {
1738-
model = std::make_shared<Toomre>(1.0, H);
1742+
model = std::make_shared<Toomre>(1.0, H, 5.0);
17391743
} else if (PTYPE == DeprojType::python and
17401744
DTYPE == DiskType::python) {
17411745
model = std::make_shared<AxiSymPyModel>(pyname, acyl);

include/DiskModels.H

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,8 @@ public:
219219
double operator()(double R, double z, double phi=0.)
220220
{
221221
double sigma = norm * std::pow(1.0 + (R/a)*(R/a), -0.5*n);
222-
double Z = std::fabs(z);
223-
double Q = std::exp(-0.5*Z/h);
224-
double sech = 2.0*Q/(1.0 + Q*Q);
222+
double Q = std::exp(-0.5*std::fabs(z)/h);
223+
double sech = 2.0*Q/(1.0 + Q*Q); // Prevent overflow
225224
return sigma * sech*sech;
226225
}
227226
};

utils/Test/Deprojector.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ namespace Deproject
4646
for (size_t i=0;i<pairs.size();++i) { R[i] = pairs[i].first; S[i] = pairs[i].second; }
4747

4848
// ensure positive radii and strictly increasing
49+
double eps = 1e-12;
4950
if (R.front() <= 0.0) {
50-
double eps = 1e-12;
51-
if (R.front() <= 0.0) R[0] = eps;
52-
for (size_t i=1;i<R.size();++i) if (R[i] <= R[i-1]) R[i] = R[i-1] + eps;
51+
R[0] = eps;
52+
}
53+
for (size_t i=1;i<R.size();++i) {
54+
if (R[i] <= R[i-1]) {
55+
R[i] = R[i-1] + eps;
56+
}
5357
}
5458

5559
spline_.set_data(R, S);

utils/Test/EmpDeproj.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,20 @@ EmpDeproj::EmpDeproj(double H, double RMIN, double RMAX, int NUMR, int NINT,
104104

105105
// Debug
106106
//
107-
if (true) {
107+
#ifdef EMPDEPROJ_DEBUG
108+
{
108109
std::string fname("deproject_sl.txt");
109110
std::ofstream out(fname);
110111
if (out) {
111112
for (int i=0; i<NUMR; i++)
112-
out << std::setw(18) << rl[i]
113-
<< std::setw(18) << rr[i]
114-
<< std::setw(18) << rho[i]
115-
<< std::setw(18) << mass[i]
116-
<< std::endl;
113+
out << std::setw(18) << rl[i]
114+
<< std::setw(18) << rr[i]
115+
<< std::setw(18) << rho[i]
116+
<< std::setw(18) << mass[i]
117+
<< std::endl;
117118
}
118119
}
120+
#endif
119121

120122
// Finalize
121123
//

utils/Test/testDeprojPlummer.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@ int main()
6464
auto rho = D.rho(r_eval);
6565

6666
std::ofstream ofs("rho_test.txt");
67-
for (size_t i = 0; i < r_eval.size(); ++i)
67+
for (size_t i = 0; i < r_eval.size(); ++i) {
6868
ofs << std::setw(16) << r_eval[i]
6969
<< std::setw(16) << rho[i]
7070
<< std::setw(16) << RhoFunc(r_eval[i])
7171
<< std::endl;
72-
ofs.close();
72+
}
73+
ofs.close();
7374
std::cout << "Wrote rho_test.txt\n";
7475

7576
return 0;

utils/Test/testDeproject.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ int main()
1818
double t = (double)i / (Ndata - 1);
1919
double r = Rmin + t * (Rmax - Rmin);
2020
Rdata.push_back(r);
21-
Sigma.push_back(1.0 / std::pow(1.0 + r*r, -1.5));
21+
Sigma.push_back(std::pow(1.0 + r*r, -1.5));
2222
}
2323

2424
Deprojector D(Rdata, Sigma, /*R_max_extend=*/50.0, /*tail_power=*/-4.0, /*Ngrid=*/6000);
@@ -39,7 +39,7 @@ int main()
3939

4040
// Example B: construct from analytic functor + analytic derivative
4141
{
42-
auto SigmaFunc = [](double R)->double { return 1.0 / std::pow(1.0 + R*R, -1.5); };
42+
auto SigmaFunc = [](double R)->double { return std::pow(1.0 + R*R, -1.5); };
4343
auto dSigmaFunc = [](double R)->double { return -3.0 * R / std::pow(1.0 + R*R, -2.5); }; // analytic derivative
4444

4545
Deprojector D(SigmaFunc, dSigmaFunc, /*R_data_min=*/0.01, /*R_data_max=*/10.0,

utils/Test/testEmp.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <fstream>
44
#include <vector>
55
#include <cmath>
6+
#include <stdexcept>
67

78
#include "Deprojector.H"
89
#include "EmpDeproj.H"

0 commit comments

Comments
 (0)