BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSFieldFactory.hh
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2022.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef BDSFIELDFACTORY_H
20#define BDSFIELDFACTORY_H
21
22#include "BDSFieldType.hh"
23#include "BDSInterpolatorType.hh"
24#include "BDSMagnetType.hh"
25
26#include "globals.hh"
27
28#include <map>
29#include <vector>
30
31namespace GMAD
32{
33 class Field;
34}
35
36class BDSFieldE;
37class BDSFieldInfo;
38class BDSFieldMag;
39class BDSFieldObjects;
43
44class G4EquationOfMotion;
45class G4MagIntegratorStepper;
46class G4Mag_EqRhs;
47
70{
71public:
73 static BDSFieldFactory* Instance();
74
76 static void SetDesignParticle(const BDSParticleDefinition* designParticleIn)
77 {designParticle = designParticleIn;}
80
82
85 const BDSMagnetStrength* scalingStrength = nullptr,
86 const G4String& scalingKey = "none");
87
90 BDSFieldInfo* GetDefinition(const G4String& name) const;
91
93 static BDSInterpolatorType DefaultInterpolatorType(G4int numberOfDimensions);
94
95private:
98 const BDSMagnetStrength* scalingStrength = nullptr,
99 const G4String& scalingKey = "none");
100
103
106
109
112 const BDSMagnetStrength* scalingStrength = nullptr,
113 const G4String& scalingKey = "none");
114
117
120 G4MagIntegratorStepper* CreateIntegratorMag(const BDSFieldInfo& info,
121 G4Mag_EqRhs* eqOfM,
122 const BDSMagnetStrength* strength);
123
126 G4MagIntegratorStepper* CreateIntegratorEM(const BDSFieldInfo& info,
127 G4EquationOfMotion* eqOfM);
128
132 G4MagIntegratorStepper* CreateIntegratorE(const BDSFieldInfo& info,
133 G4EquationOfMotion* eqOfM);
134
138
141
144
148
150 G4double GetOuterScaling(const BDSMagnetStrength* st) const;
151
154
157
159 void PrepareFieldDefinitions(const std::vector<GMAD::Field>& definitions,
160 G4double defaultBRho);
161
163 G4double ConvertToDoubleWithException(const G4String& value,
164 const G4String& parameterNameForError) const;
165
169 const G4String& fieldParameters,
170 G4double& poleTipRadius) const;
171
173 std::map<G4String, BDSFieldInfo*> parserDefinitions;
174
177
180
181 G4bool useOldMultipoleOuterFields;
182};
183#endif
Interface for BDSIM electric fields that may or may not be local.
Definition: BDSFieldE.hh:37
Factory that produces fields and their associated objects.
G4double GetOuterScaling(const BDSMagnetStrength *st) const
Return the parameter "outerScaling" from strength st, but default to 1.
static void SetDesignParticle(const BDSParticleDefinition *designParticleIn)
Update the internal cache of the rigidity.
void PrepareFieldDefinitions(const std::vector< GMAD::Field > &definitions, G4double defaultBRho)
Prepare all required definitions that can be used dynamically.
static void SetPrimaryGeneratorAction(BDSPrimaryGeneratorAction *pgaIn)
Update the internal cache of the primary generator action.
BDSFieldObjects * CreateFieldE(const BDSFieldInfo &info)
Create an electric field.
BDSFieldObjects * CreateFieldIrregular(const BDSFieldInfo &info)
Create an irregular (special) field.
BDSFieldObjects * CreateRMatrix(const BDSFieldInfo &info)
Create special rmatrix 'field' that applies an rmatrix.
void PrepareFieldStrengthFromParameters(BDSMagnetStrength *st, const G4String &fieldParameters, G4double &poleTipRadius) const
static BDSPrimaryGeneratorAction * primaryGeneratorAction
Cache of primary generator action.
BDSFieldE * CreateFieldERaw(const BDSFieldInfo &info)
Creat just the electric field object.
G4double ConvertToDoubleWithException(const G4String &value, const G4String &parameterNameForError) const
Convert the string 'value' to a double. Throw an exception including the parameterNameForError if it ...
static BDSFieldFactory * Instance()
Public accessor method for singleton pattern.
BDSFieldObjects * CreateField(const BDSFieldInfo &info, const BDSMagnetStrength *scalingStrength=nullptr, const G4String &scalingKey="none")
Main interface to field factory.
BDSFieldObjects * CreateParallelTransport(const BDSFieldInfo &info)
static BDSFieldFactory * instance
Instance - singleton pattern.
BDSFieldInfo * GetDefinition(const G4String &name) const
BDSFieldObjects * CreateCavityFringe(const BDSFieldInfo &info)
Create special rf cavity fringe 'field' that applies an rmatrix.
std::map< G4String, BDSFieldInfo * > parserDefinitions
BDSFieldInfo definitions prepare from parser vector of definitions.
G4MagIntegratorStepper * CreateIntegratorMag(const BDSFieldInfo &info, G4Mag_EqRhs *eqOfM, const BDSMagnetStrength *strength)
G4MagIntegratorStepper * CreateIntegratorE(const BDSFieldInfo &info, G4EquationOfMotion *eqOfM)
BDSFieldObjects * CreateFieldMag(const BDSFieldInfo &info, const BDSMagnetStrength *scalingStrength=nullptr, const G4String &scalingKey="none")
Create a purely magnetic field.
static BDSInterpolatorType DefaultInterpolatorType(G4int numberOfDimensions)
Suggest a default interpolator.
BDSFieldObjects * CreateFieldEM(const BDSFieldInfo &info)
Create a general EM field.
BDSFieldMag * CreateFieldMagRaw(const BDSFieldInfo &info, const BDSMagnetStrength *scalingStrength=nullptr, const G4String &scalingKey="none")
Creat just the magnetic field object.
BDSFieldFactory()
Private default constructor as singleton class.
BDSFieldObjects * CreateTeleporter(const BDSFieldInfo &info)
G4MagIntegratorStepper * CreateIntegratorEM(const BDSFieldInfo &info, G4EquationOfMotion *eqOfM)
static const BDSParticleDefinition * designParticle
Cache of design particle for fields.
All info required to build complete field of any type.
Definition: BDSFieldInfo.hh:65
Interface for static magnetic fields that may or may not be local.
Definition: BDSFieldMag.hh:37
A holder for all the Geant4 field related objects.
Efficient storage of magnet strengths.
Wrapper for particle definition.
Generates primary particle vertices using BDSBunch.
Parser namespace for GMAD language. Combination of Geant4 and MAD.