本文整理汇总了C++中Particles::momentum方法的典型用法代码示例。如果您正苦于以下问题:C++ Particles::momentum方法的具体用法?C++ Particles::momentum怎么用?C++ Particles::momentum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Particles
的用法示例。
在下文中一共展示了Particles::momentum方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operator
void PusherBoris::operator() (Particles &particles, SmileiMPI* smpi, int istart, int iend, int ithread)
{
std::vector<LocalFields> *Epart = &(smpi->dynamics_Epart[ithread]);
std::vector<LocalFields> *Bpart = &(smpi->dynamics_Bpart[ithread]);
std::vector<double> *gf = &(smpi->dynamics_gf[ithread]);
double charge_over_mass_ ;
double umx, umy, umz, upx, upy, upz;
double alpha, inv_det_T, Tx, Ty, Tz, Tx2, Ty2, Tz2;
double TxTy, TyTz, TzTx;
double pxsm, pysm, pzsm;
for (int ipart=istart ; ipart<iend; ipart++ ) {
charge_over_mass_ = static_cast<double>(particles.charge(ipart))*one_over_mass_;
//(*this)(particles, ipart, (*Epart)[ipart], (*Bpart)[ipart] , (*gf)[ipart]);
umx = particles.momentum(0, ipart) + charge_over_mass_*(*Epart)[ipart].x*dts2;
umy = particles.momentum(1, ipart) + charge_over_mass_*(*Epart)[ipart].y*dts2;
umz = particles.momentum(2, ipart) + charge_over_mass_*(*Epart)[ipart].z*dts2;
(*gf)[ipart] = sqrt( 1.0 + umx*umx + umy*umy + umz*umz );
// Rotation in the magnetic field
alpha = charge_over_mass_*dts2/(*gf)[ipart];
Tx = alpha * (*Bpart)[ipart].x;
Ty = alpha * (*Bpart)[ipart].y;
Tz = alpha * (*Bpart)[ipart].z;
Tx2 = Tx*Tx;
Ty2 = Ty*Ty;
Tz2 = Tz*Tz;
TxTy = Tx*Ty;
TyTz = Ty*Tz;
TzTx = Tz*Tx;
inv_det_T = 1.0/(1.0+Tx2+Ty2+Tz2);
upx = ( (1.0+Tx2-Ty2-Tz2)* umx + 2.0*(TxTy+Tz)* umy + 2.0*(TzTx-Ty)* umz )*inv_det_T;
upy = ( 2.0*(TxTy-Tz)* umx + (1.0-Tx2+Ty2-Tz2)* umy + 2.0*(TyTz+Tx)* umz )*inv_det_T;
upz = ( 2.0*(TzTx+Ty)* umx + 2.0*(TyTz-Tx)* umy + (1.0-Tx2-Ty2+Tz2)* umz )*inv_det_T;
// Half-acceleration in the electric field
pxsm = upx + charge_over_mass_*(*Epart)[ipart].x*dts2;
pysm = upy + charge_over_mass_*(*Epart)[ipart].y*dts2;
pzsm = upz + charge_over_mass_*(*Epart)[ipart].z*dts2;
(*gf)[ipart] = sqrt( 1.0 + pxsm*pxsm + pysm*pysm + pzsm*pzsm );
particles.momentum(0, ipart) = pxsm;
particles.momentum(1, ipart) = pysm;
particles.momentum(2, ipart) = pzsm;
// Move the particle
for ( int i = 0 ; i<nDim_ ; i++ )
particles.position(i, ipart) += dt*particles.momentum(i, ipart)/(*gf)[ipart];
}
}
示例2: operator
void PusherPonderomotivePositionBorisV::operator()( Particles &particles, SmileiMPI *smpi, int istart, int iend, int ithread, int ipart_ref )
{
/////////// not vectorized
std::vector<double> *Phi_mpart = &( smpi->dynamics_PHI_mpart[ithread] );
std::vector<double> *GradPhi_mpart = &( smpi->dynamics_GradPHI_mpart[ithread] );
double charge_sq_over_mass_dts4, charge_over_mass_sq;
double gamma0, gamma0_sq, gamma_ponderomotive;
double pxsm, pysm, pzsm;
//int* cell_keys;
double *momentum[3];
for( int i = 0 ; i<3 ; i++ ) {
momentum[i] = &( particles.momentum( i, 0 ) );
}
double *position[3];
for( int i = 0 ; i<nDim_ ; i++ ) {
position[i] = &( particles.position( i, 0 ) );
}
#ifdef __DEBUG
double *position_old[3];
for( int i = 0 ; i<nDim_ ; i++ ) {
position_old[i] = &( particles.position_old( i, 0 ) );
}
#endif
short *charge = &( particles.charge( 0 ) );
int nparts = GradPhi_mpart->size()/3;
double *Phi_m = &( ( *Phi_mpart )[0*nparts] );
double *GradPhi_mx = &( ( *GradPhi_mpart )[0*nparts] );
double *GradPhi_my = &( ( *GradPhi_mpart )[1*nparts] );
double *GradPhi_mz = &( ( *GradPhi_mpart )[2*nparts] );
//particles.cell_keys.resize(nparts);
//cell_keys = &( particles.cell_keys[0]);
#pragma omp simd
for( int ipart=istart ; ipart<iend; ipart++ ) { // begin loop on particles
// ! ponderomotive force is proportional to charge squared and the field is divided by 4 instead of 2
charge_sq_over_mass_dts4 = ( double )( charge[ipart] )*( double )( charge[ipart] )*one_over_mass_*dts4;
// (charge over mass)^2
charge_over_mass_sq = ( double )( charge[ipart] )*one_over_mass_*( charge[ipart] )*one_over_mass_;
// compute initial ponderomotive gamma
gamma0_sq = 1. + momentum[0][ipart]*momentum[0][ipart] + momentum[1][ipart]*momentum[1][ipart] + momentum[2][ipart]*momentum[2][ipart] + ( *( Phi_m+ipart-ipart_ref ) )*charge_over_mass_sq;
gamma0 = sqrt( gamma0_sq ) ;
// ponderomotive force for ponderomotive gamma advance (Grad Phi is interpolated in time, hence the division by 2)
pxsm = charge_sq_over_mass_dts4 * ( *( GradPhi_mx+ipart-ipart_ref ) ) / gamma0_sq ;
pysm = charge_sq_over_mass_dts4 * ( *( GradPhi_my+ipart-ipart_ref ) ) / gamma0_sq ;
pzsm = charge_sq_over_mass_dts4 * ( *( GradPhi_mz+ipart-ipart_ref ) ) / gamma0_sq ;
// update of gamma ponderomotive
gamma_ponderomotive = gamma0 + ( pxsm*momentum[0][ipart]+pysm*momentum[1][ipart]+pzsm*momentum[2][ipart] ) ;
// Move the particle
#ifdef __DEBUG
for( int i = 0 ; i<nDim_ ; i++ ) {
position_old[i][ipart] = position[i][ipart];
}
#endif
for( int i = 0 ; i<nDim_ ; i++ ) {
position[i][ipart] += dt*momentum[i][ipart]/gamma_ponderomotive;
}
} // end loop on particles
//#pragma omp simd
//for (int ipart=0 ; ipart<nparts; ipart++ ) {
//
// for ( int i = 0 ; i<nDim_ ; i++ ){
// cell_keys[ipart] *= nspace[i];
// cell_keys[ipart] += round( (position[i][ipart]-min_loc_vec[i]) * dx_inv_[i] );
// }
//
//} // end loop on particles
}
示例3: round
// ---------------------------------------------------------------------------------------------------------------------
//! Project current densities : main projector
// ---------------------------------------------------------------------------------------------------------------------
void Projector2D4Order::currents( double *Jx, double *Jy, double *Jz, Particles &particles, unsigned int ipart, double invgf, int *iold, double *deltaold )
{
int nparts = particles.size();
// -------------------------------------
// Variable declaration & initialization
// -------------------------------------
int iloc;
// (x,y,z) components of the current density for the macro-particle
double charge_weight = inv_cell_volume * ( double )( particles.charge( ipart ) )*particles.weight( ipart );
double crx_p = charge_weight*dx_ov_dt;
double cry_p = charge_weight*dy_ov_dt;
double crz_p = charge_weight*one_third*particles.momentum( 2, ipart )*invgf;
// variable declaration
double xpn, ypn;
double delta, delta2, delta3, delta4;
// arrays used for the Esirkepov projection method
double Sx0[7], Sx1[7], Sy0[7], Sy1[7], DSx[7], DSy[7], tmpJx[7];
for( unsigned int i=0; i<7; i++ ) {
Sx1[i] = 0.;
Sy1[i] = 0.;
tmpJx[i] = 0.;
}
Sx0[0] = 0.;
Sx0[6] = 0.;
Sy0[0] = 0.;
Sy0[6] = 0.;
// --------------------------------------------------------
// Locate particles & Calculate Esirkepov coef. S, DS and W
// --------------------------------------------------------
// locate the particle on the primal grid at former time-step & calculate coeff. S0
delta = deltaold[0*nparts];
delta2 = delta*delta;
delta3 = delta2*delta;
delta4 = delta3*delta;
Sx0[1] = dble_1_ov_384 - dble_1_ov_48 * delta + dble_1_ov_16 * delta2 - dble_1_ov_12 * delta3 + dble_1_ov_24 * delta4;
Sx0[2] = dble_19_ov_96 - dble_11_ov_24 * delta + dble_1_ov_4 * delta2 + dble_1_ov_6 * delta3 - dble_1_ov_6 * delta4;
Sx0[3] = dble_115_ov_192 - dble_5_ov_8 * delta2 + dble_1_ov_4 * delta4;
Sx0[4] = dble_19_ov_96 + dble_11_ov_24 * delta + dble_1_ov_4 * delta2 - dble_1_ov_6 * delta3 - dble_1_ov_6 * delta4;
Sx0[5] = dble_1_ov_384 + dble_1_ov_48 * delta + dble_1_ov_16 * delta2 + dble_1_ov_12 * delta3 + dble_1_ov_24 * delta4;
delta = deltaold[1*nparts];
delta2 = delta*delta;
delta3 = delta2*delta;
delta4 = delta3*delta;
Sy0[1] = dble_1_ov_384 - dble_1_ov_48 * delta + dble_1_ov_16 * delta2 - dble_1_ov_12 * delta3 + dble_1_ov_24 * delta4;
Sy0[2] = dble_19_ov_96 - dble_11_ov_24 * delta + dble_1_ov_4 * delta2 + dble_1_ov_6 * delta3 - dble_1_ov_6 * delta4;
Sy0[3] = dble_115_ov_192 - dble_5_ov_8 * delta2 + dble_1_ov_4 * delta4;
Sy0[4] = dble_19_ov_96 + dble_11_ov_24 * delta + dble_1_ov_4 * delta2 - dble_1_ov_6 * delta3 - dble_1_ov_6 * delta4;
Sy0[5] = dble_1_ov_384 + dble_1_ov_48 * delta + dble_1_ov_16 * delta2 + dble_1_ov_12 * delta3 + dble_1_ov_24 * delta4;
// locate the particle on the primal grid at current time-step & calculate coeff. S1
xpn = particles.position( 0, ipart ) * dx_inv_;
int ip = round( xpn );
int ipo = iold[0*nparts];
int ip_m_ipo = ip-ipo-i_domain_begin;
delta = xpn - ( double )ip;
delta2 = delta*delta;
delta3 = delta2*delta;
delta4 = delta3*delta;
Sx1[ip_m_ipo+1] = dble_1_ov_384 - dble_1_ov_48 * delta + dble_1_ov_16 * delta2 - dble_1_ov_12 * delta3 + dble_1_ov_24 * delta4;
Sx1[ip_m_ipo+2] = dble_19_ov_96 - dble_11_ov_24 * delta + dble_1_ov_4 * delta2 + dble_1_ov_6 * delta3 - dble_1_ov_6 * delta4;
Sx1[ip_m_ipo+3] = dble_115_ov_192 - dble_5_ov_8 * delta2 + dble_1_ov_4 * delta4;
Sx1[ip_m_ipo+4] = dble_19_ov_96 + dble_11_ov_24 * delta + dble_1_ov_4 * delta2 - dble_1_ov_6 * delta3 - dble_1_ov_6 * delta4;
Sx1[ip_m_ipo+5] = dble_1_ov_384 + dble_1_ov_48 * delta + dble_1_ov_16 * delta2 + dble_1_ov_12 * delta3 + dble_1_ov_24 * delta4;
ypn = particles.position( 1, ipart ) * dy_inv_;
int jp = round( ypn );
int jpo = iold[1*nparts];
int jp_m_jpo = jp-jpo-j_domain_begin;
delta = ypn - ( double )jp;
delta2 = delta*delta;
delta3 = delta2*delta;
delta4 = delta3*delta;
Sy1[jp_m_jpo+1] = dble_1_ov_384 - dble_1_ov_48 * delta + dble_1_ov_16 * delta2 - dble_1_ov_12 * delta3 + dble_1_ov_24 * delta4;
Sy1[jp_m_jpo+2] = dble_19_ov_96 - dble_11_ov_24 * delta + dble_1_ov_4 * delta2 + dble_1_ov_6 * delta3 - dble_1_ov_6 * delta4;
Sy1[jp_m_jpo+3] = dble_115_ov_192 - dble_5_ov_8 * delta2 + dble_1_ov_4 * delta4;
Sy1[jp_m_jpo+4] = dble_19_ov_96 + dble_11_ov_24 * delta + dble_1_ov_4 * delta2 - dble_1_ov_6 * delta3 - dble_1_ov_6 * delta4;
Sy1[jp_m_jpo+5] = dble_1_ov_384 + dble_1_ov_48 * delta + dble_1_ov_16 * delta2 + dble_1_ov_12 * delta3 + dble_1_ov_24 * delta4;
for( unsigned int i=0; i < 7; i++ ) {
DSx[i] = Sx1[i] - Sx0[i];
DSy[i] = Sy1[i] - Sy0[i];
}
// calculate Esirkepov coeff. Wx, Wy, Wz when used
double tmp, tmp2, tmp3, tmpY;
//.........这里部分代码省略.........
示例4: ny
// ---------------------------------------------------------------------------------------------------------------------
//! Project charge : frozen & diagFields timstep
// ---------------------------------------------------------------------------------------------------------------------
void Projector2D4Order::basic( double *rhoj, Particles &particles, unsigned int ipart, unsigned int type )
{
//Warning : this function is used for frozen species or initialization only and doesn't use the standard scheme.
//rho type = 0
//Jx type = 1
//Jy type = 2
//Jz type = 3
int iloc;
int ny( nprimy );
// (x,y,z) components of the current density for the macro-particle
double charge_weight = inv_cell_volume * ( double )( particles.charge( ipart ) )*particles.weight( ipart );
if( type > 0 ) {
charge_weight *= 1./sqrt( 1.0 + particles.momentum( 0, ipart )*particles.momentum( 0, ipart )
+ particles.momentum( 1, ipart )*particles.momentum( 1, ipart )
+ particles.momentum( 2, ipart )*particles.momentum( 2, ipart ) );
if( type == 1 ) {
charge_weight *= particles.momentum( 0, ipart );
} else if( type == 2 ) {
charge_weight *= particles.momentum( 1, ipart );
ny ++;
} else {
charge_weight *= particles.momentum( 2, ipart );
}
}
// variable declaration
double xpn, ypn;
double delta, delta2, delta3, delta4;
// arrays used for the Esirkepov projection method
double Sx1[7], Sy1[7];
for( unsigned int i=0; i<7; i++ ) {
Sx1[i] = 0.;
Sy1[i] = 0.;
}
// --------------------------------------------------------
// Locate particles & Calculate Esirkepov coef. S, DS and W
// --------------------------------------------------------
// locate the particle on the primal grid at current time-step & calculate coeff. S1
xpn = particles.position( 0, ipart ) * dx_inv_;
int ip = round( xpn + 0.5 * ( type==1 ) ); // index of the central node
delta = xpn - ( double )ip;
delta2 = delta*delta;
delta3 = delta2*delta;
delta4 = delta3*delta;
Sx1[1] = dble_1_ov_384 - dble_1_ov_48 * delta + dble_1_ov_16 * delta2 - dble_1_ov_12 * delta3 + dble_1_ov_24 * delta4;
Sx1[2] = dble_19_ov_96 - dble_11_ov_24 * delta + dble_1_ov_4 * delta2 + dble_1_ov_6 * delta3 - dble_1_ov_6 * delta4;
Sx1[3] = dble_115_ov_192 - dble_5_ov_8 * delta2 + dble_1_ov_4 * delta4;
Sx1[4] = dble_19_ov_96 + dble_11_ov_24 * delta + dble_1_ov_4 * delta2 - dble_1_ov_6 * delta3 - dble_1_ov_6 * delta4;
Sx1[5] = dble_1_ov_384 + dble_1_ov_48 * delta + dble_1_ov_16 * delta2 + dble_1_ov_12 * delta3 + dble_1_ov_24 * delta4;
ypn = particles.position( 1, ipart ) * dy_inv_;
int jp = round( ypn + 0.5*( type==2 ) );
delta = ypn - ( double )jp;
delta2 = delta*delta;
delta3 = delta2*delta;
delta4 = delta3*delta;
Sy1[1] = dble_1_ov_384 - dble_1_ov_48 * delta + dble_1_ov_16 * delta2 - dble_1_ov_12 * delta3 + dble_1_ov_24 * delta4;
Sy1[2] = dble_19_ov_96 - dble_11_ov_24 * delta + dble_1_ov_4 * delta2 + dble_1_ov_6 * delta3 - dble_1_ov_6 * delta4;
Sy1[3] = dble_115_ov_192 - dble_5_ov_8 * delta2 + dble_1_ov_4 * delta4;
Sy1[4] = dble_19_ov_96 + dble_11_ov_24 * delta + dble_1_ov_4 * delta2 - dble_1_ov_6 * delta3 - dble_1_ov_6 * delta4;
Sy1[5] = dble_1_ov_384 + dble_1_ov_48 * delta + dble_1_ov_16 * delta2 + dble_1_ov_12 * delta3 + dble_1_ov_24 * delta4;
// ---------------------------
// Calculate the total current
// ---------------------------
ip -= i_domain_begin + 3;
jp -= j_domain_begin + 3;
for( unsigned int i=0 ; i<7 ; i++ ) {
iloc = ( i+ip )*ny+jp;
for( unsigned int j=0 ; j<7 ; j++ ) {
rhoj[iloc+j] += charge_weight * Sx1[i]*Sy1[j];
}
}//i
}
示例5: round
// ---------------------------------------------------------------------------------------------------------------------
//! Project current densities : main projector
// ---------------------------------------------------------------------------------------------------------------------
void Projector1D4Order::currents( double *Jx, double *Jy, double *Jz, Particles &particles, unsigned int ipart, double invgf, int *iold, double *delta )
{
// Declare local variables
int ipo, ip;
int ip_m_ipo;
double charge_weight = inv_cell_volume * ( double )( particles.charge( ipart ) )*particles.weight( ipart );
double xjn, xj_m_xipo, xj_m_xipo2, xj_m_xipo3, xj_m_xipo4, xj_m_xip, xj_m_xip2, xj_m_xip3, xj_m_xip4;
double crx_p = charge_weight*dx_ov_dt; // current density for particle moving in the x-direction
double cry_p = charge_weight*particles.momentum( 1, ipart )*invgf; // current density in the y-direction of the macroparticle
double crz_p = charge_weight*particles.momentum( 2, ipart )*invgf; // current density allow the y-direction of the macroparticle
double S0[7], S1[7], Wl[7], Wt[7], Jx_p[7]; // arrays used for the Esirkepov projection method
// Initialize variables
for( unsigned int i=0; i<7; i++ ) {
S0[i]=0.;
S1[i]=0.;
Wl[i]=0.;
Wt[i]=0.;
Jx_p[i]=0.;
}//i
// Locate particle old position on the primal grid
xj_m_xipo = *delta; // normalized distance to the nearest grid point
xj_m_xipo2 = xj_m_xipo * xj_m_xipo; // square of the normalized distance to the nearest grid point
xj_m_xipo3 = xj_m_xipo2 * xj_m_xipo; // cube of the normalized distance to the nearest grid point
xj_m_xipo4 = xj_m_xipo3 * xj_m_xipo; // 4th power of the normalized distance to the nearest grid point
// Locate particle new position on the primal grid
xjn = particles.position( 0, ipart ) * dx_inv_;
ip = round( xjn ); // index of the central node
xj_m_xip = xjn - ( double )ip; // normalized distance to the nearest grid point
xj_m_xip2 = xj_m_xip * xj_m_xip; // square of the normalized distance to the nearest grid point
xj_m_xip3 = xj_m_xip2 * xj_m_xip; // cube of the normalized distance to the nearest grid point
xj_m_xip4 = xj_m_xip3 * xj_m_xip; // 4th power of the normalized distance to the nearest grid point
// coefficients 4th order interpolation on 5 nodes
S0[1] = dble_1_ov_384 - dble_1_ov_48 * xj_m_xipo + dble_1_ov_16 * xj_m_xipo2 - dble_1_ov_12 * xj_m_xipo3 + dble_1_ov_24 * xj_m_xipo4;
S0[2] = dble_19_ov_96 - dble_11_ov_24 * xj_m_xipo + dble_1_ov_4 * xj_m_xipo2 + dble_1_ov_6 * xj_m_xipo3 - dble_1_ov_6 * xj_m_xipo4;
S0[3] = dble_115_ov_192 - dble_5_ov_8 * xj_m_xipo2 + dble_1_ov_4 * xj_m_xipo4;
S0[4] = dble_19_ov_96 + dble_11_ov_24 * xj_m_xipo + dble_1_ov_4 * xj_m_xipo2 - dble_1_ov_6 * xj_m_xipo3 - dble_1_ov_6 * xj_m_xipo4;
S0[5] = dble_1_ov_384 + dble_1_ov_48 * xj_m_xipo + dble_1_ov_16 * xj_m_xipo2 + dble_1_ov_12 * xj_m_xipo3 + dble_1_ov_24 * xj_m_xipo4;
// coefficients 2nd order interpolation on 5 nodes
ipo = *iold; // index of the central node
ip_m_ipo = ip-ipo-index_domain_begin;
S1[ip_m_ipo+1] = dble_1_ov_384 - dble_1_ov_48 * xj_m_xip + dble_1_ov_16 * xj_m_xip2 - dble_1_ov_12 * xj_m_xip3 + dble_1_ov_24 * xj_m_xip4;
S1[ip_m_ipo+2] = dble_19_ov_96 - dble_11_ov_24 * xj_m_xip + dble_1_ov_4 * xj_m_xip2 + dble_1_ov_6 * xj_m_xip3 - dble_1_ov_6 * xj_m_xip4;
S1[ip_m_ipo+3] = dble_115_ov_192 - dble_5_ov_8 * xj_m_xip2 + dble_1_ov_4 * xj_m_xip4;
S1[ip_m_ipo+4] = dble_19_ov_96 + dble_11_ov_24 * xj_m_xip + dble_1_ov_4 * xj_m_xip2 - dble_1_ov_6 * xj_m_xip3 - dble_1_ov_6 * xj_m_xip4;
S1[ip_m_ipo+5] = dble_1_ov_384 + dble_1_ov_48 * xj_m_xip + dble_1_ov_16 * xj_m_xip2 + dble_1_ov_12 * xj_m_xip3 + dble_1_ov_24 * xj_m_xip4;
// coefficients used in the Esirkepov method
for( unsigned int i=0; i<7; i++ ) {
Wl[i] = S0[i] - S1[i]; // for longitudinal current (x)
Wt[i] = 0.5 * ( S0[i] + S1[i] ); // for transverse currents (y,z)
}//i
// local current created by the particle
// calculate using the charge conservation equation
for( unsigned int i=1; i<7; i++ ) {
Jx_p[i] = Jx_p[i-1] + crx_p * Wl[i-1];
}
ipo -= 3 ;
// 4th order projection for the total currents & charge density
// At the 4th order, oversize = 3.
for( unsigned int i=0; i<7; i++ ) {
Jx[i + ipo] += Jx_p[i];
Jy[i + ipo] += cry_p * Wt[i];
Jz[i + ipo] += crz_p * Wt[i];
}//i
}
示例6: if
// ---------------------------------------------------------------------------------------------------------------------
//! Project charge : frozen & diagFields timstep
// ---------------------------------------------------------------------------------------------------------------------
void Projector1D4Order::basic( double *rhoj, Particles &particles, unsigned int ipart, unsigned int type )
{
//Warning : this function is used for frozen species or initialization only and doesn't use the standard scheme.
//rho type = 0
//Jx type = 1
//Jy type = 2
//Jz type = 3
// Declare local variables
//int ipo, ip, iloc;
int ip;
//int ip_m_ipo;
double charge_weight = inv_cell_volume * ( double )( particles.charge( ipart ) )*particles.weight( ipart );
double xjn, xj_m_xip, xj_m_xip2, xj_m_xip3, xj_m_xip4;
double S1[7]; // arrays used for the Esirkepov projection method
// Initialize variables
for( unsigned int i=0; i<7; i++ ) {
S1[i]=0.;
}//i
if( type > 0 ) {
charge_weight *= 1./sqrt( 1.0 + particles.momentum( 0, ipart )*particles.momentum( 0, ipart )
+ particles.momentum( 1, ipart )*particles.momentum( 1, ipart )
+ particles.momentum( 2, ipart )*particles.momentum( 2, ipart ) );
if( type == 1 ) {
charge_weight *= particles.momentum( 0, ipart );
} else if( type == 2 ) {
charge_weight *= particles.momentum( 1, ipart );
} else {
charge_weight *= particles.momentum( 2, ipart );
}
}
// Locate particle new position on the primal grid
xjn = particles.position( 0, ipart ) * dx_inv_;
ip = round( xjn + 0.5 * ( type==1 ) ); // index of the central node
xj_m_xip = xjn - ( double )ip; // normalized distance to the nearest grid point
xj_m_xip2 = xj_m_xip * xj_m_xip; // square of the normalized distance to the nearest grid point
xj_m_xip3 = xj_m_xip2 * xj_m_xip; // cube of the normalized distance to the nearest grid point
xj_m_xip4 = xj_m_xip3 * xj_m_xip; // 4th power of the normalized distance to the nearest grid point
// coefficients 2nd order interpolation on 5 nodes
//ip_m_ipo = ip-ipo;
S1[1] = dble_1_ov_384 - dble_1_ov_48 * xj_m_xip + dble_1_ov_16 * xj_m_xip2 - dble_1_ov_12 * xj_m_xip3 + dble_1_ov_24 * xj_m_xip4;
S1[2] = dble_19_ov_96 - dble_11_ov_24 * xj_m_xip + dble_1_ov_4 * xj_m_xip2 + dble_1_ov_6 * xj_m_xip3 - dble_1_ov_6 * xj_m_xip4;
S1[3] = dble_115_ov_192 - dble_5_ov_8 * xj_m_xip2 + dble_1_ov_4 * xj_m_xip4;
S1[4] = dble_19_ov_96 + dble_11_ov_24 * xj_m_xip + dble_1_ov_4 * xj_m_xip2 - dble_1_ov_6 * xj_m_xip3 - dble_1_ov_6 * xj_m_xip4;
S1[5] = dble_1_ov_384 + dble_1_ov_48 * xj_m_xip + dble_1_ov_16 * xj_m_xip2 + dble_1_ov_12 * xj_m_xip3 + dble_1_ov_24 * xj_m_xip4;
ip -= index_domain_begin + 3 ;
// 4th order projection for the charge density
// At the 4th order, oversize = 3.
for( unsigned int i=0; i<7; i++ ) {
//iloc = i + ipo - 3;
rhoj[i + ip ] += charge_weight * S1[i];
}//i
}
示例7: operator
void PusherPonderomotiveBorisV::operator()( Particles &particles, SmileiMPI *smpi, int istart, int iend, int ithread, int ipart_ref )
{
std::vector<double> *Epart = &( smpi->dynamics_Epart[ithread] );
std::vector<double> *Bpart = &( smpi->dynamics_Bpart[ithread] );
std::vector<double> *GradPhipart = &( smpi->dynamics_GradPHIpart[ithread] );
std::vector<double> *dynamics_inv_gamma_ponderomotive = &( smpi->dynamics_inv_gamma_ponderomotive[ithread] );
double charge_over_mass_dts2, charge_sq_over_mass_sq_dts4;
double alpha, inv_det_T, Tx, Ty, Tz, Tx2, Ty2, Tz2;
double TxTy, TyTz, TzTx;
double one_ov_gamma_ponderomotive;
double *momentum[3];
for( int i = 0 ; i<3 ; i++ ) {
momentum[i] = &( particles.momentum( i, 0 ) );
}
short *charge = &( particles.charge( 0 ) );
int nparts = Epart->size()/3;
double *Ex = &( ( *Epart )[0*nparts] );
double *Ey = &( ( *Epart )[1*nparts] );
double *Ez = &( ( *Epart )[2*nparts] );
double *Bx = &( ( *Bpart )[0*nparts] );
double *By = &( ( *Bpart )[1*nparts] );
double *Bz = &( ( *Bpart )[2*nparts] );
double *GradPhix = &( ( *GradPhipart )[0*nparts] );
double *GradPhiy = &( ( *GradPhipart )[1*nparts] );
double *GradPhiz = &( ( *GradPhipart )[2*nparts] );
double *inv_gamma_ponderomotive = &( ( *dynamics_inv_gamma_ponderomotive )[0*nparts] );
double dcharge[nparts];
#pragma omp simd
for( int ipart=istart ; ipart<iend; ipart++ ) {
dcharge[ipart] = ( double )( charge[ipart] );
}
#pragma omp simd
for( int ipart=istart ; ipart<iend; ipart++ ) {
double psm[3], um[3];
charge_over_mass_dts2 = dcharge[ipart]*one_over_mass_*dts2;
// ! ponderomotive force is proportional to charge squared and the field is divided by 4 instead of 2
charge_sq_over_mass_sq_dts4 = ( double )( charge[ipart] )*( double )( charge[ipart] )*one_over_mass_*one_over_mass_*dts4;
// ponderomotive gamma buffered from susceptibility
one_ov_gamma_ponderomotive = ( *( inv_gamma_ponderomotive+ipart ) );
// init Half-acceleration in the electric field and ponderomotive force
psm[0] = charge_over_mass_dts2 * ( *( Ex+ipart-ipart_ref ) ) - charge_sq_over_mass_sq_dts4 * ( *( GradPhix+ipart-ipart_ref ) ) * one_ov_gamma_ponderomotive;
psm[1] = charge_over_mass_dts2 * ( *( Ey+ipart-ipart_ref ) ) - charge_sq_over_mass_sq_dts4 * ( *( GradPhiy+ipart-ipart_ref ) ) * one_ov_gamma_ponderomotive;
psm[2] = charge_over_mass_dts2 * ( *( Ez+ipart-ipart_ref ) ) - charge_sq_over_mass_sq_dts4 * ( *( GradPhiz+ipart-ipart_ref ) ) * one_ov_gamma_ponderomotive;
um[0] = momentum[0][ipart] + psm[0];
um[1] = momentum[1][ipart] + psm[1];
um[2] = momentum[2][ipart] + psm[2];
// Rotation in the magnetic field, using updated gamma ponderomotive
alpha = charge_over_mass_dts2 * one_ov_gamma_ponderomotive;
Tx = alpha * ( *( Bx+ipart-ipart_ref ) );
Ty = alpha * ( *( By+ipart-ipart_ref ) );
Tz = alpha * ( *( Bz+ipart-ipart_ref ) );
Tx2 = Tx*Tx;
Ty2 = Ty*Ty;
Tz2 = Tz*Tz;
TxTy = Tx*Ty;
TyTz = Ty*Tz;
TzTx = Tz*Tx;
inv_det_T = 1.0/( 1.0+Tx2+Ty2+Tz2 );
psm[0] += ( ( 1.0+Tx2-Ty2-Tz2 )* um[0] + 2.0*( TxTy+Tz )* um[1] + 2.0*( TzTx-Ty )* um[2] )*inv_det_T;
psm[1] += ( 2.0*( TxTy-Tz )* um[0] + ( 1.0-Tx2+Ty2-Tz2 )* um[1] + 2.0*( TyTz+Tx )* um[2] )*inv_det_T;
psm[2] += ( 2.0*( TzTx+Ty )* um[0] + 2.0*( TyTz-Tx )* um[1] + ( 1.0-Tx2-Ty2+Tz2 )* um[2] )*inv_det_T;
momentum[0][ipart] = psm[0];
momentum[1][ipart] = psm[1];
momentum[2][ipart] = psm[2];
}
}
示例8: operator
void PusherBorisV::operator()( Particles &particles, SmileiMPI *smpi, int istart, int iend, int ithread, int ipart_ref )
{
std::vector<double> *Epart = &( smpi->dynamics_Epart[ithread] );
std::vector<double> *Bpart = &( smpi->dynamics_Bpart[ithread] );
double *invgf = &( smpi->dynamics_invgf[ithread][0] );
double charge_over_mass_dts2;
double inv_det_T, Tx, Ty, Tz;
double local_invgf;
//int IX;
//int* cell_keys;
double *momentum[3];
for( int i = 0 ; i<3 ; i++ ) {
momentum[i] = &( particles.momentum( i, 0 ) );
}
double *position[3];
for( int i = 0 ; i<nDim_ ; i++ ) {
position[i] = &( particles.position( i, 0 ) );
}
#ifdef __DEBUG
double *position_old[3];
for( int i = 0 ; i<nDim_ ; i++ ) {
position_old[i] = &( particles.position_old( i, 0 ) );
}
#endif
short *charge = &( particles.charge( 0 ) );
int nparts = Epart->size()/3;
double *Ex = &( ( *Epart )[0*nparts] );
double *Ey = &( ( *Epart )[1*nparts] );
double *Ez = &( ( *Epart )[2*nparts] );
double *Bx = &( ( *Bpart )[0*nparts] );
double *By = &( ( *Bpart )[1*nparts] );
double *Bz = &( ( *Bpart )[2*nparts] );
//particles.cell_keys.resize(nparts);
//cell_keys = &( particles.cell_keys[0]);
double dcharge[nparts];
#pragma omp simd
for( int ipart=istart ; ipart<iend; ipart++ ) {
dcharge[ipart] = ( double )( charge[ipart] );
}
#pragma omp simd
for( int ipart=istart ; ipart<iend; ipart++ ) {
double psm[3], um[3];
charge_over_mass_dts2 = dcharge[ipart]*one_over_mass_*dts2;
// init Half-acceleration in the electric field
psm[0] = charge_over_mass_dts2*( *( Ex+ipart-ipart_ref ) );
psm[1] = charge_over_mass_dts2*( *( Ey+ipart-ipart_ref ) );
psm[2] = charge_over_mass_dts2*( *( Ez+ipart-ipart_ref ) );
//(*this)(particles, ipart, (*Epart)[ipart], (*Bpart)[ipart] , (*invgf)[ipart]);
um[0] = momentum[0][ipart] + psm[0];
um[1] = momentum[1][ipart] + psm[1];
um[2] = momentum[2][ipart] + psm[2];
// Rotation in the magnetic field
local_invgf = charge_over_mass_dts2 / sqrt( 1.0 + um[0]*um[0] + um[1]*um[1] + um[2]*um[2] );
Tx = local_invgf * ( *( Bx+ipart-ipart_ref ) );
Ty = local_invgf * ( *( By+ipart-ipart_ref ) );
Tz = local_invgf * ( *( Bz+ipart-ipart_ref ) );
inv_det_T = 1.0/( 1.0+Tx*Tx+Ty*Ty+Tz*Tz );
psm[0] += ( ( 1.0+Tx*Tx-Ty*Ty-Tz*Tz )* um[0] + 2.0*( Tx*Ty+Tz )* um[1] + 2.0*( Tz*Tx-Ty )* um[2] )*inv_det_T;
psm[1] += ( 2.0*( Tx*Ty-Tz )* um[0] + ( 1.0-Tx*Tx+Ty*Ty-Tz*Tz )* um[1] + 2.0*( Ty*Tz+Tx )* um[2] )*inv_det_T;
psm[2] += ( 2.0*( Tz*Tx+Ty )* um[0] + 2.0*( Ty*Tz-Tx )* um[1] + ( 1.0-Tx*Tx-Ty*Ty+Tz*Tz )* um[2] )*inv_det_T;
// finalize Half-acceleration in the electric field
local_invgf = 1. / sqrt( 1.0 + psm[0]*psm[0] + psm[1]*psm[1] + psm[2]*psm[2] );
invgf[ipart-ipart_ref] = local_invgf;
momentum[0][ipart] = psm[0];
momentum[1][ipart] = psm[1];
momentum[2][ipart] = psm[2];
// Move the particle
#ifdef __DEBUG
for( int i = 0 ; i<nDim_ ; i++ ) {
position_old[i][ipart] = position[i][ipart];
}
#endif
local_invgf *= dt;
for( int i = 0 ; i<nDim_ ; i++ ) {
position[i][ipart] += psm[i]*local_invgf;
}
}
// This is temporarily moved to SpeciesV.cpp
//#pragma omp simd
//for (int ipart=istart ; ipart<iend; ipart++ ) {
//
// for ( int i = 0 ; i<nDim_ ; i++ ){
// cell_keys[ipart] *= nspace[i];
//.........这里部分代码省略.........