10 #ifdef HARD_CHECK_ENERGY
12 PS::F64 de_change_binary_interrupt;
13 PS::F64 de_change_modify_single;
22 PS::F64 de_sd_change_binary_interrupt;
23 PS::F64 de_sd_change_modify_single;
38 #ifdef HARD_CHECK_ENERGY
39 de_change_cum = de_change_binary_interrupt = de_change_modify_single = 0.0;
40 error_hard_cum = error_hard_cum_pre = 0.0;
41 error_sd_cum_pre = ekin_sd = epot_sd = etot_sd_ref = de_sd_change_cum = de_sd_change_binary_interrupt = de_sd_change_modify_single = 0.0;
42 error_hard_sd_cum = error_hard_sd_cum_pre = 0.0;
52 void print(std::ostream & _fout=std::cout,
const PS::S32 _width=16) {
54 <<std::setw(_width)<<
"Error/Total"
55 <<std::setw(_width)<<
"Error"
56 <<std::setw(_width)<<
"Error_cum"
57 <<std::setw(_width)<<
"Total"
58 <<std::setw(_width)<<
"Kinetic"
59 <<std::setw(_width)<<
"Potential"
60 #ifdef HARD_CHECK_ENERGY
61 <<std::setw(_width)<<
"Modify"
62 <<std::setw(_width)<<
"Modify_group"
63 <<std::setw(_width)<<
"Modify_single"
64 <<std::setw(_width)<<
"Error_PP"
65 <<std::setw(_width)<<
"Error_PP_cum"
73 <<std::setw(_width)<<
ekin
74 <<std::setw(_width)<<
epot
75 #ifdef HARD_CHECK_ENERGY
76 <<std::setw(_width)<<de_change_cum
77 <<std::setw(_width)<<de_change_binary_interrupt
78 <<std::setw(_width)<<de_change_modify_single
79 <<std::setw(_width)<<error_hard_cum - error_hard_cum_pre
80 <<std::setw(_width)<<error_hard_cum
83 #ifdef HARD_CHECK_ENERGY
85 <<std::setw(_width)<<(getEnergyErrorSlowDown() - error_sd_cum_pre)/(ekin_sd+epot_sd)
86 <<std::setw(_width)<<getEnergyErrorSlowDown() - error_sd_cum_pre
87 <<std::setw(_width)<<getEnergyErrorSlowDown()
88 <<std::setw(_width)<<ekin_sd + epot_sd
89 <<std::setw(_width)<<ekin_sd
90 <<std::setw(_width)<<epot_sd
91 <<std::setw(_width)<<de_sd_change_cum
92 <<std::setw(_width)<<de_sd_change_binary_interrupt
93 <<std::setw(_width)<<de_sd_change_modify_single
94 <<std::setw(_width)<<error_hard_sd_cum - error_hard_sd_cum_pre
95 <<std::setw(_width)<<error_hard_sd_cum
98 _fout<<
"Angular Momemtum:"
112 _fout<<std::setw(_width)<<
"Error"
113 <<std::setw(_width)<<
"Error_cum"
114 <<std::setw(_width)<<
"Ekin"
115 <<std::setw(_width)<<
"Epot"
116 <<std::setw(_width)<<
"Etot"
117 #ifdef HARD_CHECK_ENERGY
118 <<std::setw(_width)<<
"dE_modify"
119 <<std::setw(_width)<<
"dE_interrupt"
120 <<std::setw(_width)<<
"Error_hard"
121 <<std::setw(_width)<<
"Error_hard_cum"
122 <<std::setw(_width)<<
"Error_SD"
123 <<std::setw(_width)<<
"Error_SD_cum"
124 <<std::setw(_width)<<
"Ekin_SD"
125 <<std::setw(_width)<<
"Epot_SD"
126 <<std::setw(_width)<<
"Etot_SD"
127 <<std::setw(_width)<<
"dE_modify_SD"
128 <<std::setw(_width)<<
"dE_interrupt_SD"
129 <<std::setw(_width)<<
"Error_hard_SD"
130 <<std::setw(_width)<<
"Error_hard_SD_cum"
132 <<std::setw(_width)<<
"|L|error"
133 <<std::setw(_width)<<
"|L|error_cum"
134 <<std::setw(_width)<<
"Lx"
135 <<std::setw(_width)<<
"Ly"
136 <<std::setw(_width)<<
"Lz"
137 <<std::setw(_width)<<
"|L|";
148 <<std::setw(_width)<<
ekin
149 <<std::setw(_width)<<
epot
151 #ifdef HARD_CHECK_ENERGY
152 <<std::setw(_width)<<de_change_cum
153 <<std::setw(_width)<<de_change_binary_interrupt
154 <<std::setw(_width)<<error_hard_cum - error_hard_cum_pre
155 <<std::setw(_width)<<error_hard_cum
156 <<std::setw(_width)<<getEnergyErrorSlowDown() - error_sd_cum_pre
157 <<std::setw(_width)<<getEnergyErrorSlowDown()
158 <<std::setw(_width)<<ekin_sd
159 <<std::setw(_width)<<epot_sd
160 <<std::setw(_width)<<ekin_sd+epot_sd
161 <<std::setw(_width)<<de_sd_change_cum
162 <<std::setw(_width)<<de_sd_change_binary_interrupt
163 <<std::setw(_width)<<error_hard_sd_cum - error_hard_sd_cum_pre
164 <<std::setw(_width)<<error_hard_sd_cum
168 <<std::setw(_width)<<
L.x
169 <<std::setw(_width)<<
L.y
170 <<std::setw(_width)<<
L.z
171 <<std::setw(_width)<<
Lt;
174 #ifdef HARD_CHECK_ENERGY
176 fprintf(_fout,
"%26.17e %26.17e %26.17e %26.17e %26.17e %26.17e %26.17e %26.17e %26.17e %26.17e %26.17e %26.17e %26.17e %26.17e %26.17e %26.17e %26.17e %26.17e %26.17e %26.17e ",
178 error_sd_cum_pre, ekin_sd, epot_sd, etot_sd_ref, de_sd_change_cum, de_sd_change_binary_interrupt,
184 fprintf(_fout,
"%26.17e %26.17e %26.17e %26.17e %26.17e %26.17e %26.17e %26.17e %26.17e %26.17e %26.17e %26.17e ",
202 template<
class Tptcl>
203 void calc(
const Tptcl* _particles,
205 const bool _init_flag=
false,
const PS::F64vec* _pos_offset=NULL,
const PS::F64vec* _vel_offset=NULL) {
211 for(
PS::S32 i=0; i<_n_particle; i++){
212 PS::F64 mi = _particles[i].mass;
213 auto pi_artificial = _particles[i].group_data.artificial;
214 if(pi_artificial.isMember()) mi = pi_artificial.getMassBackup();
216 assert(_particles[i].
id>0&&(pi_artificial.isMember()||pi_artificial.isSingle()));
221 if (_pos_offset!=NULL) pi += *_pos_offset;
224 if (_vel_offset!=NULL) vi += *_vel_offset;
226 #ifdef EXTERNAL_POT_IN_PTCL
227 epot += 0.5 * mi * (_particles[i].pot_tot + _particles[i].pot_ext);
229 epot += 0.5 * mi * _particles[i].pot_tot;
231 ekin += 0.5 * mi * vi * vi;
237 #ifdef HARD_CHECK_ENERGY
251 template<
class Tptcl>
252 void calc(
const Tptcl* _particles,
253 const PS::S32* _particle_index,
255 const bool _init_flag=
false) {
260 for(
PS::S32 k=0; k<_n_particle; k++){
261 PS::S32 i = _particle_index[k];
262 PS::F64 mi = _particles[i].mass;
264 #ifdef EXTERNAL_POT_IN_PTCL
265 epot += 0.5 * mi * (_particles[i].pot_tot + _particles[i].pot_ext);
267 epot += 0.5 * mi * _particles[i].pot_tot;
269 ekin += 0.5 * mi * vi * vi;
270 L += _particles[i].pos ^ (mi*vi);
275 #ifdef HARD_CHECK_ENERGY
289 L = PS::Comm::getSum(
L);
293 #ifdef HARD_CHECK_ENERGY
303 #ifdef HARD_CHECK_ENERGY
304 error_sd_cum_pre = getEnergyErrorSlowDown();
305 error_hard_cum_pre = error_hard_cum;
306 error_hard_sd_cum_pre = error_hard_sd_cum;
316 #ifdef HARD_CHECK_ENERGY
317 PS::F64 getEnergyErrorSlowDown()
const {
319 return ekin_sd + epot_sd - etot_sd_ref;
326 return std::sqrt(dL*dL);