BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSFieldFactory.hh
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef BDSFIELDFACTORY_H
19#define BDSFIELDFACTORY_H
20
21#include "BDSFieldType.hh"
22#include "BDSInterpolatorType.hh"
23#include "BDSMagnetType.hh"
24
25#include "globals.hh"
26
27#include <map>
28#include <vector>
29
30namespace GMAD
31{
32 class Field;
33 class Modulator;
34}
35
36class BDSFieldE;
37class BDSFieldEM;
38class BDSFieldInfo;
39class BDSFieldMag;
40class BDSFieldObjects;
42class BDSModulator;
46
47class G4EquationOfMotion;
48class G4MagIntegratorStepper;
49class G4Mag_EqRhs;
50
77{
78public:
80 static BDSFieldFactory* Instance();
81
83 static void SetDesignParticle(const BDSParticleDefinition* designParticleIn)
84 {designParticle = designParticleIn;}
87
89
92 const BDSMagnetStrength* scalingStrength = nullptr,
93 const G4String& scalingKey = "none");
94
98 BDSFieldInfo* GetDefinition(const G4String& name) const;
99
103 BDSModulatorInfo* GetModulatorDefinition(const G4String& modulatorName) const;
104
106 static BDSInterpolatorType DefaultInterpolatorType(G4int numberOfDimensions);
107
108private:
111 const BDSMagnetStrength* scalingStrength = nullptr,
112 const G4String& scalingKey = "none");
113
116
119
122
125 const BDSMagnetStrength* scalingStrength = nullptr,
126 const G4String& scalingKey = "none");
127
130
133 G4MagIntegratorStepper* CreateIntegratorMag(const BDSFieldInfo& info,
134 G4Mag_EqRhs* eqOfM,
135 const BDSMagnetStrength* strength);
136
139 G4MagIntegratorStepper* CreateIntegratorEM(const BDSFieldInfo& info,
140 G4EquationOfMotion* eqOfM);
141
145 G4MagIntegratorStepper* CreateIntegratorE(const BDSFieldInfo& info,
146 G4EquationOfMotion* eqOfM);
147
151
154
157
161
163 G4double GetOuterScaling(const BDSMagnetStrength* st) const;
164
166 BDSModulator* CreateModulator(const BDSModulatorInfo* modulatorRecipe,
167 const BDSFieldInfo& info) const;
168
171 G4double brho) const;
172
175
178
180 void PrepareFieldDefinitions(const std::vector<GMAD::Field>& definitions,
181 G4double defaultBRho);
182
184 void PrepareModulatorDefinitions(const std::vector<GMAD::Modulator>& definitions);
185
187 G4double ConvertToDoubleWithException(const G4String& value,
188 const G4String& parameterNameForError) const;
189
193 const G4String& fieldParameters,
194 G4double& poleTipRadius) const;
195
197 std::map<G4String, BDSFieldInfo*> parserDefinitions;
198 std::map<G4String, BDSModulatorInfo*> parserModulatorDefinitions;
199
202
205
206 G4bool useOldMultipoleOuterFields;
207};
208#endif
Interface for BDSIM electro-magnetic fields that may or may not be local.
Definition BDSFieldEM.hh:40
Interface for BDSIM electric fields that may or may not be local.
Definition BDSFieldE.hh:38
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.
void PrepareModulatorDefinitions(const std::vector< GMAD::Modulator > &definitions)
Prepare all required modulator 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.
BDSModulator * CreateModulator(const BDSModulatorInfo *modulatorRecipe, const BDSFieldInfo &info) const
Create the necessary modulator.
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)
BDSFieldEM * CreateMuonCoolerField(const BDSFieldInfo &info, G4double brho) const
Create a composite muon cooler field EM field.
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.
BDSModulatorInfo * GetModulatorDefinition(const G4String &modulatorName) const
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.
Interface for static magnetic fields that may or may not be local.
A holder for all the Geant4 field related objects.
Efficient storage of magnet strengths.
Holder class for all information required to describe a modulator.
Base class for a modulator.
Wrapper for particle definition.
Generates primary particle vertices using BDSBunch.
Parser namespace for GMAD language. Combination of Geant4 and MAD.