本文整理汇总了C++中Particles::charge方法的典型用法代码示例。如果您正苦于以下问题:C++ Particles::charge方法的具体用法?C++ Particles::charge怎么用?C++ Particles::charge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Particles
的用法示例。
在下文中一共展示了Particles::charge方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ny
// ---------------------------------------------------------------------------------------------------------------------
//! Project local densities only (Frozen species)
// ---------------------------------------------------------------------------------------------------------------------
void Projector3D4Order::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
// -------------------------------------
// Variable declaration & initialization
// -------------------------------------
int iloc, jloc;
int ny( nprimy ), nz( nprimz ), nyz;
// (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 );
nz ++;
}
}
nyz = ny*nz;
// variable declaration
double xpn, ypn, zpn;
double delta, delta2, delta3, delta4;
double Sx1[7], Sy1[7], Sz1[7]; // arrays used for the Esirkepov projection method
// Initialize all current-related arrays to zero
for( unsigned int i=0; i<7; i++ ) {
Sx1[i] = 0.;
Sy1[i] = 0.;
Sz1[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 ) );
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;
zpn = particles.position( 2, ipart ) * dz_inv_;
int kp = round( zpn+ 0.5*( type==3 ) );
delta = zpn - ( double )kp;
delta2 = delta*delta;
delta3 = delta2*delta;
delta4 = delta3*delta;
Sz1[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;
Sz1[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;
Sz1[3] = dble_115_ov_192 - dble_5_ov_8 * delta2 + dble_1_ov_4 * delta4;
Sz1[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;
Sz1[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 charge
// ---------------------------
ip -= i_domain_begin + 3;
jp -= j_domain_begin + 3;
kp -= k_domain_begin + 3;
for( unsigned int i=0 ; i<7 ; i++ ) {
iloc = ( i+ip )*nyz;
for( unsigned int j=0 ; j<7 ; j++ ) {
//.........这里部分代码省略.........
示例2: round
// ---------------------------------------------------------------------------------------------------------------------
//! Project local current densities (sort)
// ---------------------------------------------------------------------------------------------------------------------
void Projector3D4Order::currentsAndDensity( double *Jx, double *Jy, double *Jz, double *rho, Particles &particles, unsigned int ipart, double invgf, int *iold, double *deltaold )
{
int nparts = particles.size();
// -------------------------------------
// Variable declaration & initialization
// -------------------------------------
// (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*dz_ov_dt;
// variable declaration
double xpn, ypn, zpn;
double delta, delta2, delta3, delta4;
// arrays used for the Esirkepov projection method
double Sx0[7], Sx1[7], Sy0[7], Sy1[7], Sz0[7], Sz1[7], DSx[7], DSy[7], DSz[7];
double tmpJx[7][7], tmpJy[7][7], tmpJz[7][7];
for( unsigned int i=0; i<7; i++ ) {
Sx1[i] = 0.;
Sy1[i] = 0.;
Sz1[i] = 0.;
}
for( unsigned int j=0; j<7; j++ )
for( unsigned int k=0; k<7; k++ ) {
tmpJx[j][k] = 0.;
}
for( unsigned int i=0; i<7; i++ )
for( unsigned int k=0; k<7; k++ ) {
tmpJy[i][k] = 0.;
}
for( unsigned int i=0; i<7; i++ )
for( unsigned int j=0; j<7; j++ ) {
tmpJz[i][j] = 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[0] = 0.;
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;
Sx0[6] = 0.;
delta = deltaold[1*nparts];
delta2 = delta*delta;
delta3 = delta2*delta;
delta4 = delta3*delta;
Sy0[0] = 0.;
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;
Sy0[6] = 0.;
delta = deltaold[2*nparts];
delta2 = delta*delta;
delta3 = delta2*delta;
delta4 = delta3*delta;
Sz0[0] = 0.;
Sz0[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;
Sz0[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;
Sz0[3] = dble_115_ov_192 - dble_5_ov_8 * delta2 + dble_1_ov_4 * delta4;
Sz0[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;
Sz0[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;
Sz0[6] = 0.;
// 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 );
//.........这里部分代码省略.........