Skip to content

Commit 804d665

Browse files
author
Martin D. Weinberg
committed
Fix round off boundary and never ignore nout
1 parent c96ebc5 commit 804d665

3 files changed

Lines changed: 26 additions & 14 deletions

File tree

expui/BiorthBasis.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ namespace BasisClasses
11891189
std::tuple<Eigen::VectorXd, Eigen::Tensor<float, 3>>
11901190
IntegrateOrbits (double tinit, double tfinal, double h,
11911191
Eigen::MatrixXd ps, std::vector<BasisCoef> bfe,
1192-
AccelFunctor F, int nout=std::numeric_limits<int>::max());
1192+
AccelFunctor F, int nout=0);
11931193

11941194
using BiorthBasisPtr = std::shared_ptr<BiorthBasis>;
11951195
}

expui/BiorthBasis.cc

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3914,23 +3914,33 @@ namespace BasisClasses
39143914

39153915
// Number of steps
39163916
//
3917-
int numT = std::ceil( (tfinal - tinit)/h );
3917+
int numT = std::ceil( (tfinal - tinit)/h + 0.5);
39183918

39193919
// Want both end points in the output at minimum
39203920
//
39213921
numT = std::max(2, numT);
3922-
nout = std::max(2, nout);
39233922

3924-
// Number of output steps. Compute a stride>1 if nout<numT.
3923+
// Number of output steps
39253924
//
3926-
int stride = std::ceil(static_cast<double>(numT)/static_cast<double>(nout));
3927-
if (stride>1) numT = (nout-1) * stride + 1;
3928-
else nout = numT;
3925+
int stride = 1; // Default stride
3926+
if (nout>0) { // User has specified output count...
3927+
nout = std::max(2, nout);
3928+
stride = std::ceil(static_cast<double>(numT)/static_cast<double>(nout));
3929+
numT = (nout-1) * stride + 1;
3930+
} else { // Otherwise, use the default output number
3931+
nout = numT; // with the default stride
3932+
}
39293933

39303934
// Compute the interval-matching step
39313935
//
39323936
h = (tfinal - tinit)/(numT-1);
39333937

3938+
// DEBUG
3939+
if (false)
3940+
std::cout << "BasisClasses::IntegrateOrbits: choosing nout=" << nout
3941+
<< " numT=" << numT << " h=" << h << " stride=" << stride
3942+
<< std::endl;
3943+
39343944
// Return data
39353945
//
39363946
Eigen::Tensor<float, 3> ret;

pyEXP/BasisWrappers.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,11 +2194,13 @@ void BasisFactoryClasses(py::module &m)
21942194
R"(
21952195
Compute particle orbits in gravitational field from the bases
21962196
2197-
Integrate a list of initial conditions from tinit to tfinal with a
2198-
step size of h using the list of basis and coefficient pairs. Every
2199-
step will be included in return unless you provide an explicit
2200-
value for 'nout', the number of desired output steps. This will
2201-
choose the 'nout' points closest to the desired time.
2197+
Integrate a list of initial conditions from 'tinit' to 'tfinal' with
2198+
a step size of 'h' using the list of basis and coefficient pairs. The
2199+
step size will be adjusted to provide uniform sampling. Every
2200+
step will be returned unless you provide an explicit value for 'nout',
2201+
the number of desired output steps. In this case, the code will
2202+
choose new set step size equal or smaller to the supplied step size
2203+
with a stride to provide exactly 'nout' output times.
22022204
22032205
Parameters
22042206
----------
@@ -2216,7 +2218,7 @@ void BasisFactoryClasses(py::module &m)
22162218
func : AccelFunctor
22172219
the force function
22182220
nout : int
2219-
the number of output intervals if (tfinal - tinit) / h > nout
2221+
the number of output points, if specified
22202222
22212223
Returns
22222224
-------
@@ -2225,5 +2227,5 @@ void BasisFactoryClasses(py::module &m)
22252227
)",
22262228
py::arg("tinit"), py::arg("tfinal"), py::arg("h"),
22272229
py::arg("ps"), py::arg("basiscoef"), py::arg("func"),
2228-
py::arg("nout")=std::numeric_limits<int>::max());
2230+
py::arg("nout")=0);
22292231
}

0 commit comments

Comments
 (0)