Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
S src
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 62
    • Issues 62
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 4
    • Merge requests 4
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI/CD
    • Code Review
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OPAL
  • src
  • Issues
  • #558

Closed
Open
Created Jul 02, 2020 by albajacas_a@albajacas_aDeveloper

Particles get wrong charge if input file has different number of particles

Summary

When inserting a distribution FROMFILE, if NPART is different from the number of lines in the input file, the total charge is wrongly modified.

This is because the charge-per-particle is set as totalCharge / NPART in Beam.cpp separately from Distribution.cpp, which simply gives an error:

    if (numberOfDistParticles != numberOfParticles) {
        *gmsg << "\n--------------------------------------------------" << endl
              << "Warning!! The number of particles in the initial" << endl
              << "distribution is " << numberOfDistParticles << "." << endl << endl
              << "This is different from the number of particles" << endl
              << "defined by the BEAM command: " << numberOfParticles << endl << endl
              << "This is often happens when using a FROMFILE type" << endl
              << "distribution and not matching the number of" << endl
              << "particles in the particles file(s) with the number" << endl
              << "given in the BEAM command." << endl << endl
              << "The number of particles in the initial distribution" << endl
              << "(" << numberOfDistParticles << ") "
              << "will take precedence." << endl
              << "---------------------------------------------------\n" << endl;

The simulation then continues, but you have more or less particles than NPART, and hence the charge-per-particle is too high or too low, and the total charge is different that what the user specified

Steps to reproduce

For example if initialDistro.in has 5e5 particles, and you use

// INITIAL DISTRIBUTION

Dist: DISTRIBUTION, TYPE = FROMFILE, FNAME = "initialDistro.in",
      EMITTED = FALSE;
// Electron Beam Definition

REAL beam_bunch_charge = 2e-9;
BEAM1:  BEAM, PARTICLE = ELECTRON, GAMMA = gamma, NPART = 1e6,
	BFREQ = rf_freq, BCURRENT = beam_bunch_charge * rf_freq * 1e6  , CHARGE = -1;

then you will get a warning, and the simulation will continue with a total charge of 1 nC instead of the 2 nC that the user specified.

Possible fixes

I think the best solution is to simply output an error message and quit the simulation if NPART != particles_in_file. The user can either correct NPART to be as in the file, or modify the file himself.

Assignee
Assign to
OPAL 2.4.0
Milestone
OPAL 2.4.0 (Past due)
Assign milestone
Time tracking