CmPA / iPic3D

Particle-in-Cell code using the implicit moment method
72 stars 55 forks source link

written moments should live at same time as fields and particles #70

Open alecjohnson opened 10 years ago

alecjohnson commented 10 years ago

Currently, at the end of each cycle, we output the field and particle data at time tn, but we output the moment data for time step tn-1. Instead, at the end of each output cycle, all quantities saved should live at time step tn.

The current algorithm cycle looks like this:

  for (int i = KCode.FirstCycle(); i < KCode.LastCycle(); i++) 
  {
      // computes moments M at t^(n-1) and implicit moments IM at t^n
      KCode.CalculateMoments();
      KCode.CalculateField(); // computes E at t^n
      KCode.ParticlesMover(); // computes pcls P at t^n
      KCode.CalculateB(); // computes B at t^n
      KCode.WriteOutput(i); // writes M, E, B, and P
  }   

To fix this problem, we can change the algorithm cycle to look like this:

  // computes moments M at t^0 and implicit moments IM at t^1
  KCode.CalculateMoments();
  for (int i = KCode.FirstCycle(); i < KCode.LastCycle(); i++) 
  {
      KCode.CalculateField(); // computes E at t^n
      KCode.ParticlesMover(); // computes pcls P at t^n
      KCode.CalculateB(); // computes B at t^n
      // computes moments M at t^n and implicit moments IM at t^(n+1)
      KCode.CalculateMoments();
      KCode.WriteOutput(i);  // writes M, E, B, and P
  }