-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbstractSimulation.py
61 lines (52 loc) · 2.69 KB
/
AbstractSimulation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from abc import ABC, abstractmethod
import numpy as np
import pandas as pd
from copy import deepcopy
import scipy.constants as const
from ParticleBunchClass import ParticleBunch
from SumEMFields import EMFieldClass
from Particle import Particle
class AbstractSimulationClass(ABC):
""" Abstract base class for building a simulation or set of simulations
Class Attributes:
totalEMField (object: EMFieldClass): The combined collection of electromagnetic
fields that interact in the simulation.
particleBunch (object: ParticleBunch): The bunch of particles that are moved
throughout the simulation
duration (float): Duration of each simulation
largeTimeStep (float): The timestep that is used when on average, the bunch is
outside of the accelerating electric field
smallTimeStep (float): The shorter timestep that is used when on average, the
bunch is inside of the accelerating electric field.
"""
def __init__(self, totalEMField=EMFieldClass, particleBunch=ParticleBunch, duration=1.0, largeTimestep=1e-3
, smallTimestep=1e-8):
""" Constructor for any simulation child class.
Args:
totalEMField (object: EMFieldClass): The combined collection of electromagnetic
fields that interact in the simulation.
particleBunch (object: ParticleBunch): The bunch of particles that are moved
throughout the simulation
duration (float): Duration of each simulation
largeTimeStep (float): The timestep that is used when on average, the bunch is
outside of the accelerating electric field
smallTimeStep (float): The shorter timestep that is used when on average, the
bunch is inside of the accelerating electric field.
"""
self.totalEMField = totalEMField
self.particleBunch = particleBunch
self.duration = duration
self.largeTimestep = largeTimestep
self.smallTimestep = smallTimestep
@abstractmethod
def RunSimulation(self):
""" Abstract method for running the simulation or set of simulations.
Method is abstract as different simulations require very different
steps.
"""
@abstractmethod
def SaveSimulation(self, fileName:str):
""" Abstract method for saving data from the simulation or set of simulations.
Method is abtract since different simulations generate results in
different formats.
"""