RooParticle
Particle scattering simulator with ROOT
Loading...
Searching...
No Matches
asymptoteN.hpp
Go to the documentation of this file.
1#ifndef H_ASYMPTOTEN
2#define H_ASYMPTOTEN 1
3
4#include "vector"
5
6#include "TROOT.h"
7#include "TString.h"
8#include "TVector3.h"
9
10class event;
11
13//
14// asymptoteN : asymptotic (t -> +-infinity) velocities of an N-body event,
15// with an error estimate
16//
17// A run stops at a finite distance, where the interaction is not negligible.
18// For two bodies with a pure 1/r potential the class asymptote is exact. For
19// N bodies there is no closed form, so asymptoteN returns, for every moving
20// particle, the asymptotic velocity v_inf AND an estimate of its error, for
21// any number of bodies and any of the pair forces of force.hpp. The caller's
22// event is never modified (the integrating methods work on a private copy).
23//
24// What "asymptotic state" means here : VELOCITIES ONLY. With 1/r forces the
25// positions never settle on straight lines (r = v t + (kappa/mu v^2) ln t + ...,
26// a logarithmic phase), while the velocities converge like 1/t. Two bodies
27// that leave bound to each other have no individual asymptotic velocity : they
28// are reported as a cluster with its centre-of-mass velocity (see Clusters).
29//
30// Methods (Compute(ev, method, direction))
31// kBorn First order (straight-line impulse). Every particle moves on a
32// straight line x + v t; the impulse of each pair force is
33// integrated to t = infinity : closed form for unsoftened Coulomb
34// and gravity, I = kappa/(w R) [ b_vec/(R + s) + w_hat ]
35// (R = |r|, s = r.w_hat, b_vec = r - s w_hat, w = |v1 - v2|),
36// adaptive Gauss-Legendre quadrature of force::Evaluate() along
37// the line for the other forces. O(N^2) and cheap : this is the
38// residual / termination criterion. Works in the relativistic
39// mode (it integrates dp/dt along the lab-frame straight lines).
40// Error : O(eta^2) per pair, eta ~ |U|/(mu w^2) ~ 1/R ; the
41// measured order of the velocity error in 1/R is 2.0.
42// kPairwise (default) Every pair is solved as an isolated two-body problem
43// EXACTLY, and the velocity changes of all pairs are added :
44// pure 1/r pairs with the class asymptote, any other central
45// potential (Coulomb + Woods-Saxon, Yukawa, softened forces) with
46// the orbit integral dphi = int h / (r^2 sqrt(2(E-U)/mu - h^2/r^2)) dr
47// (adaptive quadrature, turning point included, so an approaching
48// pair, even one passing through a nucleus, is fine too).
49// Exact for two bodies (1e-16 closed form, 1e-15 quadrature);
50// for N >= 3 the error is the three-body cross term (pair ik
51// perturbed by the future kicks of the others), also O(1/R^2),
52// with a 10 - 60 times smaller coefficient than kBorn in the tests.
53// Momentum is conserved exactly ; the energy defect at infinity
54// is O(cross term) (GetEnergyInf() - GetEnergyNow()).
55// A receding pair whose non-1/r forces are below 1e-17 of its
56// potential and force (outside a nuclear range) is solved in closed form.
57// kAuto kPairwise on a private copy of the event that is continued with
58// the adaptive RK45 in doubling time blocks until the estimated
59// error is below SetAutoTolerance(). 1 - 11 blocks in the tests ;
60// at the default 1e-9 it costs about as much as kBrute, it pays
61// off for looser tolerances.
62// kBrute Reference : a private copy is continued with RK45 in doubling
63// time blocks t_k ; the velocities are extrapolated with the 1/t
64// law (Richardson, v_inf = (t2 v2 - t1 v1)/(t2 - t1)) until two
65// successive extrapolations agree within SetBruteTolerance().
66// Its residual error is O(ln t / t^2). Independent of the
67// analytic methods (it never uses them), slow compared to them.
68//
69// Direction
70// kOutgoing t -> +infinity (default).
71// kIncoming t -> -infinity : computed by time reversal (all velocities of
72// a copy flipped, outgoing asymptote, flipped back). Valid for
73// velocity-independent forces, which all forces of force.hpp are.
74// It gives the TRUE incoming velocities (and so the effective
75// impact parameters) of a run started at a finite distance.
76//
77// Error estimate (GetError(i), in c ; a 1-sigma-like magnitude, not a strict bound)
78// kPairwise err_a = C sum_b (mu_ab/m_a) eta_ab |dw_ab^ext| (cross term)
79// + quadrature error (two orders compared)
80// + multipole error of clusters (members vs point composite)
81// eta_ab = max(|U|, r |F_r|) / (2 E_ab) at r = current distance
82// (at the closest approach still ahead for an approaching pair),
83// dw_ab^ext = change of the relative velocity of a,b caused by the
84// OTHER bodies (from the same pairwise solution), C = SetCrossFactor()
85// (default 2 : one eta from the displaced relative orbit, one from
86// the shifted relative velocity it is solved with). Zero for two
87// bodies, where only the quadrature and round-off (4e-15 of the
88// largest velocity) terms remain.
89// kBorn the kPairwise estimate + |dv_Born - dv_Pairwise| (second-order
90// size of the pair terms : for two bodies it IS the error).
91// kAuto the kPairwise estimate at the last block + integration error.
92// kBrute |difference of the last two extrapolations| + integration error.
93// Integration error of a private copy : (rel |v| + abs) sqrt(n substeps) with
94// the RK45 tolerances of SetIntegrationTolerance().
95// Measured by main_asymptoteN_check.cpp, actual error / estimate, 3 and 4
96// bodies (fixed and free targets, Coulomb and Coulomb + Woods-Saxon, stops
97// from 15 fm to 23000 fm, outgoing and incoming) : kPairwise and kAuto
98// <= 0.23 (the estimate is 4 - 9 times too large), kBorn <= 0.99 (tight :
99// it is dominated by the exactly known pair term), kBrute <= 0.34.
100//
101// Residual and termination criterion
102// GetResidual(i) = v_inf - v_now, GetDeflection(i) = remaining deflection
103// angle (rad) of particle i, GetMaxDeflection() over the moving particles.
104// RemainingDeflection(ev) is the cheap static form (kBorn, no estimate) for
105// a stop condition : "stop when every particle will still turn by < X rad"
106// (use together with IsSeparating() : all interacting pairs receding).
107//
108// Clusters (bound subsystems)
109// Bodies are merged while some pair of bodies has a negative pair energy
110// E_ab = mu_ab |V_a - V_b|^2 / 2 + sum U_ij (members) in its own CM frame.
111// A cluster is then treated as ONE body (total mass and charge at its centre
112// of mass) and every member gets the cluster velocity, with flag kInCluster.
113// Its multipole interaction (e.g. the dipole of a neutral bound pair) is not
114// in v_inf : it enters the error estimate as |first-order impulse of the
115// members, moving rigidly - that of the point composite|.
116// GetClusterEnergy(c) = internal energy (kinetic in the CM frame + internal
117// potential), GetClusterIsolation(c) = |tidal / multipole coupling to the
118// other bodies| / |internal energy|; above SetIsolation() (default 1e-2) :
119// kNotIsolated, the binding may still be broken (or made) later.
120// Bound to an invincible particle : kBoundToFixed, v_inf = 0 for its members.
121//
122// Flags (per particle GetFlags(i), OR of all GetFlags())
123// kApproaching an interacting pair of it is still approaching : handled,
124// but the cross-term estimate is less certain.
125// kStrong some pair has C eta > 0.5 and is perturbed by other bodies :
126// the perturbative estimate is NOT trustworthy (stop later,
127// or use kAuto / kBrute).
128// kInCluster member of a bound cluster : v_inf is the cluster CM velocity.
129// kNotIsolated that cluster is not isolated (see above).
130// kBoundToFixed bound to an invincible particle : no asymptote, v_inf = 0.
131// kRelativistic relativistic event : kBorn (first order) is used instead of
132// kPairwise, which is non-relativistic.
133// kNoPairwise a force is not central or the event is not pair symmetric :
134// first order (kBorn) used.
135// kMarginal a pair with E ~ 0 (v_inf ~ 0) : slow convergence, unreliable.
136// kSingular radial fall into an attractive singular centre, or a
137// first-order impulse that diverges (head-on approach).
138// kNotConverged kAuto / kBrute reached SetMaxBlocks() before the tolerance.
139// kInvalid no event, no moving particle, zero mass ...
140// IsReliable() : none of kStrong, kNotIsolated, kMarginal, kSingular,
141// kNotConverged, kInvalid.
142//
143// Validity and failure modes
144// * Forces must be pairwise, velocity independent and vanish at infinity.
145// kPairwise needs them central (all forces of force.hpp are); a
146// non-central force falls back to kBorn (flag kNoPairwise).
147// * Particles are evaluated through stand-ins carrying mass, charge and
148// position (EMparticle) : a force reading other particle data is not
149// supported (the event copy constructor makes the same assumption).
150// * Not trustworthy while particles still approach each other strongly,
151// for slow relative motion (eta not small) and for clusters that are not
152// isolated : the flags say so. kAuto handles the first two by integrating on.
153// * Relativistic mode : first order (kBorn) only, error O(eta^2) estimated
154// from the non-relativistic second-order size; kBrute integrates the
155// relativistic copy and is exact up to its tolerance. Retardation is
156// ignored (as in the event).
157// * oddevent (sequential update) is not modelled : the copies are event.
158// * Invincible particles are fixed (their stored velocity is ignored, as the
159// event never moves them) and are excluded from momentum and energy sums.
160//
161// Cost (2 - 4 bodies, measured by main_asymptoteN_check, one core)
162// kBorn / kPairwise, Coulomb 4 - 15 microseconds
163// kBorn / kPairwise, inside a nuclear range (quadrature) 0.2 - 0.4 ms
164// kBrute, unbound 100 - 500 RK45 substeps, 0.3 - 1.3 ms
165// (to t ~ 1e9 fm/c ; tolerance 1e-13)
166// kBrute with a bound pair its orbit is integrated : ~ 1e5 substeps
167// kAuto 0.3 - 3.5 ms at the default tolerance
168// The residual of the fixed-target three-body run : 8 microseconds per call.
169//
170// Example
171// asymptoteN asy(ev); // kPairwise, outgoing
172// for(Int_t i=0; i<ev->getNParticle(); i++){
173// TVector3 vout = asy.GetVInf(i); // asymptotic velocity
174// Double_t dv = asy.GetError(i); // its error estimate (c)
175// }
176// if(!asy.IsReliable()) asy.Compute(ev, asymptoteN::kAuto);
177// asymptoteN in(ev, asymptoteN::kPairwise, asymptoteN::kIncoming);
178// // stop condition inside a loop :
179// Bool_t sep; if(asymptoteN::RemainingDeflection(ev, &sep) < 1e-6 && sep) break;
180//
183public:
186 enum flagBit {
188 kStrong = 1<<1,
194 kMarginal = 1<<7,
195 kSingular = 1<<8,
197 kInvalid = 1<<10
198 };
200
203
204 // Compute from the present state of ev (ev is not changed). Returns kFALSE
205 // when there is no result at all (kInvalid); check IsReliable() as well.
206 Bool_t Compute(event* ev, method m = kPairwise, direction d = kOutgoing);
207
208 // --- settings (keep their values across Compute calls)
209 void SetAutoTolerance(Double_t tol){autoTol = tol;} // kAuto : target of GetMaxRelError() (default 1e-9)
210 void SetBruteTolerance(Double_t tol){bruteTol = tol;} // kBrute : relative agreement of two extrapolations (1e-11)
211 void SetIntegrationTolerance(Double_t rel, Double_t abs){rkRel = rel; rkAbs = abs;} // RK45 of the copies (1e-13, 1e-15)
212 void SetMaxBlocks(Int_t n){maxBlocks = n;} // kAuto / kBrute : doubling blocks (default 60)
213 void SetQuadratureOrder(Int_t n){nquad = (n<4) ? 4 : n;} // Gauss points per panel (default 12)
214 void SetIsolation(Double_t eps){isoThr = eps;} // cluster isolation threshold (default 1e-2)
215 void SetCrossFactor(Double_t c){crossC = c;} // C of the cross-term estimate (default 2)
216 void SetAnalytic(Bool_t on = kTRUE){analytic = on;} // closed forms for pure 1/r pairs (off : quadrature everywhere)
217 void SetErrorEstimate(Bool_t on = kTRUE){estimate = on;} // kBorn : also solve the pairs for the estimate
218
219 // --- results per particle (index of the event; invincible : v_inf = 0, error 0)
220 Int_t GetNParticle() const {return (Int_t) vInf.size();}
221 TVector3 GetV(Int_t i) const {return vNow.at(i);} // velocity of the given state (0 if fixed)
222 TVector3 GetVBody(Int_t i) const {return vBody.at(i);} // GetV, or the cluster CM velocity for members
223 TVector3 GetVInf(Int_t i) const {return vInf.at(i);} // asymptotic velocity (cluster CM velocity for members)
224 Double_t GetError(Int_t i) const {return err.at(i);} // error estimate of GetVInf (c)
225 TVector3 GetResidual(Int_t i) const {return vInf.at(i) - vBody.at(i);} // velocity change still to come (or since t = -inf)
226 Double_t GetDeflection(Int_t i) const; // angle between GetVBody and GetVInf (rad)
227 Double_t GetAngularError(Int_t i) const; // GetError / |GetVInf| (rad)
228 UInt_t GetFlags(Int_t i) const {return flags.at(i);}
229 Int_t GetCluster(Int_t i) const {return cluster.at(i);} // -1 : not in a cluster
230 Bool_t IsFixed(Int_t i) const {return fixed.at(i);}
231
232 // --- results, whole event
233 method GetMethod() const {return meth;}
234 direction GetDirection() const {return dir;}
235 UInt_t GetFlags() const {return allFlags;}
236 TString GetFlagNames(UInt_t f) const;
237 Bool_t IsValid() const {return !(allFlags & kInvalid);}
238 Bool_t IsReliable() const {return !(allFlags & kUnreliable);}
239 Bool_t IsSeparating() const {return separating;} // every interacting pair receding (or bound in a cluster)
240 Double_t GetMaxDeflection() const {return maxDefl;} // largest remaining deflection (rad)
241 Double_t GetMaxError() const {return maxErr;} // largest GetError (c)
242 Double_t GetVelocityScale() const {return vScale;} // largest |v_inf| (c)
243 Double_t GetMaxRelError() const {return (vScale>0.) ? maxErr/vScale : 0.;}
244 Double_t GetMaxEta() const {return maxEta;} // largest pair strength eta = max(|U|, r|F|)/(2E)
245 // Total energy now (moving particles' KE + all pair PE but fixed-fixed), and
246 // the asymptotic one : sum of KE of the bodies at infinity + internal cluster
247 // energies. Their difference measures the non-conservation of the method
248 // (zero for two bodies). Non-relativistic kinetic energies.
249 Double_t GetEnergyNow() const {return eNow;}
250 Double_t GetEnergyInf() const {return eInf;}
251 TVector3 GetMomentumInf() const; // sum m v_inf over the moving particles
252
253 // --- clusters
254 Int_t GetNClusters() const {return (Int_t) clMembers.size();}
255 std::vector<Int_t> GetClusterMembers(Int_t c) const {return clMembers.at(c);}
256 Double_t GetClusterEnergy(Int_t c) const {return clEnergy.at(c);}
257 Double_t GetClusterIsolation(Int_t c) const {return clIso.at(c);}
258 TVector3 GetClusterVInf(Int_t c) const {return clVInf.at(c);}
259
260 // --- cost of the last Compute
261 Double_t GetRunTime() const {return runTime;} // wall-clock seconds
262 Double_t GetIntegratedTime() const {return tInt;} // fm/c continued by kAuto / kBrute
263 Int_t GetNBlocks() const {return nBlocks;}
264 Long_t GetNSubsteps() const {return nSub;} // RK45 substeps (accepted + rejected)
265 Long_t GetNForceSweeps() const {return 6*nSub + nBlocks;} // full force evaluations of the event
266
267 TString Print(Bool_t mute = kFALSE) const;
268
269 // Cheap termination criterion : largest remaining deflection (rad) of a
270 // moving particle (or cluster), first order, no error estimate.
271 // separating (if given) : every interacting pair is receding.
272 static Double_t RemainingDeflection(event* ev, Bool_t* separating = nullptr);
273 // Same, largest |v_inf - v| / |v_inf| (relative velocity change still to come).
274 static Double_t RemainingChange(event* ev, Bool_t* separating = nullptr);
275
276 // the internal analysis (public for the implementation helpers only)
277 struct pstate { Double_t m, q; TVector3 x, v; Bool_t fixed; };
278
279private:
280 void Reset(Int_t n);
281 void Analyze(event* ev, const std::vector<pstate> & ps, method m, Bool_t clusterOnly = kFALSE);
282 void RunIntegrating(event* ev, method m);
283 void Finish(event* ev);
284
285 // settings
286 Double_t autoTol = 1e-9;
287 Double_t bruteTol = 1e-11;
288 Double_t rkRel = 1e-13;
289 Double_t rkAbs = 1e-15;
290 Int_t maxBlocks = 60;
291 Int_t nquad = 12;
292 Double_t isoThr = 1e-2;
293 Double_t crossC = 2.;
294 Bool_t analytic = kTRUE;
295 Bool_t estimate = kTRUE;
296
297 // results
300 std::vector<TVector3> vNow, vBody, vInf;
301 std::vector<Double_t> err, mass;
302 std::vector<UInt_t> flags;
303 std::vector<Int_t> cluster;
304 std::vector<Bool_t> fixed;
305 std::vector<std::vector<Int_t> > clMembers;
306 std::vector<Double_t> clEnergy, clIso;
307 std::vector<TVector3> clVInf;
309 Bool_t separating = kFALSE;
310 Double_t maxDefl = 0., maxErr = 0., vScale = 0., maxEta = 0., etaApp = 0.;
311 Double_t eNow = 0., eInf = 0.;
312 Double_t runTime = 0., tInt = 0.;
313 Int_t nBlocks = 0;
314 Long_t nSub = 0;
315};
316
317#endif
void SetQuadratureOrder(Int_t n)
std::vector< Double_t > mass
UInt_t GetFlags() const
Double_t isoThr
Double_t crossC
direction dir
Double_t GetClusterIsolation(Int_t c) const
std::vector< TVector3 > vNow
void SetBruteTolerance(Double_t tol)
std::vector< TVector3 > vInf
Double_t rkRel
std::vector< TVector3 > clVInf
Bool_t IsSeparating() const
Double_t bruteTol
void SetIntegrationTolerance(Double_t rel, Double_t abs)
Int_t GetNBlocks() const
static const UInt_t kUnreliable
TVector3 GetClusterVInf(Int_t c) const
Double_t GetEnergyInf() const
TVector3 GetV(Int_t i) const
Bool_t estimate
std::vector< Bool_t > fixed
Double_t etaApp
Double_t GetMaxError() const
Double_t vScale
direction GetDirection() const
std::vector< Double_t > clEnergy
std::vector< Double_t > err
Double_t eInf
void SetIsolation(Double_t eps)
std::vector< TVector3 > vBody
void SetAnalytic(Bool_t on=kTRUE)
Int_t maxBlocks
std::vector< std::vector< Int_t > > clMembers
Double_t GetMaxRelError() const
Double_t GetEnergyNow() const
Int_t GetNClusters() const
Bool_t IsValid() const
static Double_t RemainingChange(event *ev, Bool_t *separating=nullptr)
UInt_t allFlags
method GetMethod() const
void SetMaxBlocks(Int_t n)
Bool_t IsReliable() const
Int_t GetCluster(Int_t i) const
Double_t runTime
void RunIntegrating(event *ev, method m)
Double_t maxEta
TVector3 GetVBody(Int_t i) const
Long_t GetNSubsteps() const
static Double_t RemainingDeflection(event *ev, Bool_t *separating=nullptr)
TVector3 GetVInf(Int_t i) const
TString Print(Bool_t mute=kFALSE) const
Bool_t separating
Double_t GetIntegratedTime() const
std::vector< Double_t > clIso
Double_t GetRunTime() const
Long_t GetNForceSweeps() const
std::vector< UInt_t > flags
std::vector< Int_t > GetClusterMembers(Int_t c) const
Double_t GetClusterEnergy(Int_t c) const
Double_t rkAbs
Double_t GetMaxEta() const
void Reset(Int_t n)
void SetCrossFactor(Double_t c)
void Finish(event *ev)
void Analyze(event *ev, const std::vector< pstate > &ps, method m, Bool_t clusterOnly=kFALSE)
Double_t GetError(Int_t i) const
UInt_t GetFlags(Int_t i) const
Double_t tInt
Double_t autoTol
Double_t eNow
Bool_t analytic
Double_t GetDeflection(Int_t i) const
std::vector< Int_t > cluster
Double_t maxErr
TVector3 GetResidual(Int_t i) const
asymptoteN(event *ev, method m=kPairwise, direction d=kOutgoing)
Int_t GetNParticle() const
void SetAutoTolerance(Double_t tol)
TString GetFlagNames(UInt_t f) const
Double_t maxDefl
TVector3 GetMomentumInf() const
Double_t GetVelocityScale() const
Double_t GetAngularError(Int_t i) const
Double_t GetMaxDeflection() const
Bool_t IsFixed(Int_t i) const
Bool_t Compute(event *ev, method m=kPairwise, direction d=kOutgoing)
void SetErrorEstimate(Bool_t on=kTRUE)
One simulated system: particles, pairwise forces, inspectors and the time integration.
Definition event.hpp:93