Particle transfer to continuation simulation
For long geometries the simulation can be chopped in to two pieces. The first simulation can be higher resolution where it is needed, a plasma extraction for example and a following beam tube can be done as a continuation simulation.
For taking the particles from a simulation and making a data file containing the particle data you can do the following:
// Write output file containing all particles
ofstream fileOut( "particles_out.txt" );
for( size_t k = 0; k < pdb.size(); k++ ) {
Particle3D &pp = pdb.particle( k );
// Skip electrons
if( pp.m() < 0.5*MASS_U )
continue;
// Skip ions not at the end
if( pp(PARTICLE_Z) < 29.0e-3 )
continue;
// Plot particle I, m, coordinates
// 3D has 7 coordinates
fileOut << setw(12) << pp.IQ() << " ";
fileOut << setw(12) << pp.m() << " ";
for( size_t j = 0; j < 7; j ++ )
fileOut << setw(12) << pp(j) << " ";
fileOut << "\n";
}
fileOut.close();
For defining a beam using the data file:
// Input particles
ReadAscii din( "particles_out", 9 );
cout << "Reading " << din.rows() << " particles\n";
// Go through all read particles
for( size_t i = 0; i < din.rows(); i++ ) {
double I = din[0][i];
double m = din[1][i];
double t = din[2][i];
double x = din[3][i];
double vx = din[4][i];
double y = din[5][i];
double vy = din[6][i];
double z = din[7][i];
double vz = din[8][i];
pdb.add_particle( I, 1.0, m/MASS_U, ParticleP3D(t,x,vx,y,vy,z,vz) );
}