SlowDown Algorithmic Regularization (SDAR)
Algorithmic Regularization with slowdown method for integrating few-body motions
ar_information.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Common/Float.h"
4 #include "Common/list.h"
5 #include "Common/binary_tree.h"
7 #include "AR/information.h"
8 
9 namespace H4{
11 
12  template <class Tparticle>
13  class ARInformation: public AR::Information<Tparticle, ParticleH4<Tparticle>> {
14  private:
16 
18  static void addOneParticleAndReLinkPointer(COMM::ParticleGroup<Tparticle, ParticleH4<Tparticle>>& _particles, Tparticle*& _ptcl) {
19  _particles.addMember(*_ptcl);
20  _ptcl = &_particles.getLastMember();
21  }
22 
24  struct ParticleIndexAdr{
25  int n_particle;
26  Tparticle* first_particle_index_local_address; // the local particle data first address to calculate local index
27  int* particle_index_origin_output; // to store the particle index
28  const int* particle_index_origin_all; // to obtain the original index from local index
29 
30  ParticleIndexAdr(Tparticle* _first_adr, int* _index_output, const int* _index_org): n_particle(0), first_particle_index_local_address(_first_adr), particle_index_origin_output(_index_output), particle_index_origin_all(_index_org) {}
31  };
32 
34  static void calcParticleIndex(ParticleIndexAdr& _index, Tparticle*& _ptcl) {
35  _index.particle_index_origin_output[_index.n_particle++] = _index.particle_index_origin_all[int(_ptcl - _index.first_particle_index_local_address)];
36  }
37 
38  public:
40  COMM::List<int> particle_index; // particle index in original array (Hermite particles)
41  Float vcm_record[3]; // record the last group c.m. velocity before the energy correction after interruption. This is used to get correct kinetic energy corretion for perturbation in hermite_manager.calcEnergy
42 
44 
46 
48  bool checkParams() {
49  return true;
50  }
51 
53 
57  void printColumnTitle(std::ostream & _fout, const int _width=20) {
58  ARInfoBase::printColumnTitle(_fout, _width);
59  _fout<<std::setw(_width)<<"dt_limit";
60  }
61 
63 
67  void printColumn(std::ostream & _fout, const int _width=20){
68  ARInfoBase::printColumn(_fout, _width);
69  _fout<<std::setw(_width)<<dt_limit;
70  }
71 
72 
74  void reserveMem(const int _nmax) {
78  }
79 
80  void clear() {
84  vcm_record[0] = vcm_record[1] =vcm_record[2] = 0.0;
85  }
86 
87 
89 
95  int n_members = _bin.getMemberN();
96  // copy KeplerTree first
97  ARInfoBase::binarytree.resizeNoInitialize(n_members-1);
98  _bin.getherBinaryTreeIter(ARInfoBase::binarytree.getDataAddress());
99  // add particle and relink the address in bin_ leaf
100  auto& bin_root=ARInfoBase::getBinaryTreeRoot();
101  ASSERT(bin_root.getMemberN() == n_members);
102  bin_root.processLeafIter(_particles, addOneParticleAndReLinkPointer);
103  }
104 
106 
111  int getTwoBranchParticleIndexOriginFromBinaryTree(int* _particle_index_origin_output, Tparticle* _first_particle_address) {
112  ParticleIndexAdr p_index(_first_particle_address, _particle_index_origin_output, particle_index.getDataAddress());
113  auto& bin_root = ARInfoBase::binarytree.getLastMember();
114  bin_root.processLeafIter(p_index, calcParticleIndex);
115  if (bin_root.getMemberN()==2) return 1;
116  else {
117  if (bin_root.isMemberTree(0)) return bin_root.getLeftMemberAsTree()->getMemberN();
118  else return 1;
119  }
120  }
121 
123 
129  void getDrDv(Float& _dr2, Float& _drdv, Tparticle& _p1, Tparticle& _p2) {
130  Float dx[3],dv[3];
131  const Float* pos1 = _p1.getPos();
132  const Float* pos2 = _p2.getPos();
133  const Float* vel1 = _p1.getVel();
134  const Float* vel2 = _p2.getVel();
135  dx[0] = pos1[0] - pos2[0];
136  dx[1] = pos1[1] - pos2[1];
137  dx[2] = pos1[2] - pos2[2];
138 
139  dv[0] = vel1[0] - vel2[0];
140  dv[1] = vel1[1] - vel2[1];
141  dv[2] = vel1[2] - vel2[2];
142 
143  _dr2 = dx[0]*dx[0] + dx[1]*dx[1] + dx[2]*dx[2];
144  _drdv= dx[0]*dv[0] + dx[1]*dv[1] + dx[2]*dv[2];
145  }
146  };
147 }
H4::ARInformation::dt_limit
Float dt_limit
Definition: ar_information.h:39
COMM::List::getDataAddress
Ttype * getDataAddress() const
return member data array address
Definition: list.h:170
H4::ARInformation::getTwoBranchParticleIndexOriginFromBinaryTree
int getTwoBranchParticleIndexOriginFromBinaryTree(int *_particle_index_origin_output, Tparticle *_first_particle_address)
get two branch particle index
Definition: ar_information.h:111
H4::ARInformation::checkParams
bool checkParams()
check whether parameters values are correct
Definition: ar_information.h:48
H4::ARInformation
contain group information
Definition: ar_information.h:13
AR::Information< Tparticle, ParticleH4< Tparticle > >::printColumnTitle
void printColumnTitle(std::ostream &_fout, const int _width=20)
print titles of class members using column style
Definition: information.h:347
H4::ARInformation::vcm_record
Float vcm_record[3]
Definition: ar_information.h:41
AR::Information
A class contains information (e.g. parameters, binary tree, indices) about the particle group.
Definition: information.h:90
Float.h
COMM::List::clear
void clear()
Clear function.
Definition: list.h:76
NUMERIC_FLOAT_MAX
const Float NUMERIC_FLOAT_MAX
Definition: Float.h:29
H4::ARInformation::printColumnTitle
void printColumnTitle(std::ostream &_fout, const int _width=20)
print titles of class members using column style
Definition: ar_information.h:57
binary_tree.h
H4::ARInformation::getDrDv
void getDrDv(Float &_dr2, Float &_drdv, Tparticle &_p1, Tparticle &_p2)
get dr * dv for two particles
Definition: ar_information.h:129
COMM::BinaryTree::getherBinaryTreeIter
void getherBinaryTreeIter(BinaryTreeLocal _bin[])
collect BinaryTree data iteratively and save to a BinaryTree array
Definition: binary_tree.h:744
AR::Information< Tparticle, ParticleH4< Tparticle > >::binarytree
COMM::List< BinaryTree< Tparticle > > binarytree
fix step option for integration
Definition: information.h:96
H4::ARInformation::clear
void clear()
Definition: ar_information.h:80
AR::Information< Tparticle, ParticleH4< Tparticle > >::printColumn
void printColumn(std::ostream &_fout, const int _width=20)
print data of class members using column style
Definition: information.h:358
information.h
H4::ParticleH4
particle type for AR integrator, not necessary anymore
Definition: hermite_particle.h:6
COMM::ParticleGroup
Particle group class to store and manage a group of particle.
Definition: particle_group.h:13
COMM::BinaryTree::getMemberN
int getMemberN() const
get total number of members
Definition: binary_tree.h:801
H4::ARInformation::reserveMem
void reserveMem(const int _nmax)
reserve memory
Definition: ar_information.h:74
Float
double Float
Definition: Float.h:25
H4::ARInformation::addParticlesAndCopyBinaryTree
void addParticlesAndCopyBinaryTree(COMM::ParticleGroup< Tparticle, ParticleH4< Tparticle >> &_particles, AR::BinaryTree< Tparticle > &_bin)
Initialize group of particles from a binarytree.
Definition: ar_information.h:94
hermite_particle.h
H4::ARInformation::ARInformation
ARInformation()
Definition: ar_information.h:43
COMM::List< int >
COMM::BinaryTree
Binary tree cell.
Definition: binary_tree.h:492
AR::Information< Tparticle, ParticleH4< Tparticle > >::clear
void clear()
clear function
Definition: information.h:331
H4
Definition: ar_information.h:9
COMM::ListMode::local
@ local
H4::ARInformation::particle_index
COMM::List< int > particle_index
hermite time step limit for this group
Definition: ar_information.h:40
AR::Information< Tparticle, ParticleH4< Tparticle > >::getBinaryTreeRoot
BinaryTree< Tparticle > & getBinaryTreeRoot() const
get the root of binary tree
Definition: information.h:124
COMM::List::setMode
void setMode(const ListMode _mode)
set mode
Definition: list.h:39
list.h
AR::Information< Tparticle, ParticleH4< Tparticle > >::reserveMem
void reserveMem(const int _nmax)
reserve memory of binarytree list
Definition: information.h:118
COMM::List::reserveMem
void reserveMem(const int _nmax)
Memory allocation for storing members.
Definition: list.h:48
H4::ARInformation::printColumn
void printColumn(std::ostream &_fout, const int _width=20)
print data of class members using column style
Definition: ar_information.h:67