gfields
Loading...
Searching...
No Matches
gfield.cc
Go to the documentation of this file.
1// geant4
2#include "G4Mag_UsualEqRhs.hh"
3#include "G4DormandPrince745.hh"
4#include "G4ClassicalRK4.hh"
5#include "G4HelixSimpleRunge.hh"
6#include "G4HelixExplicitEuler.hh"
7#include "G4HelixImplicitEuler.hh"
8#include "G4CashKarpRKF45.hh"
9#include "G4RKG3_Stepper.hh"
10#include "G4SimpleHeum.hh"
11#include "G4NystromRK4.hh"
12#include "G4ImplicitEuler.hh"
13#include "G4ExplicitEuler.hh"
14#include "G4ChordFinder.hh"
15
16// gfield
17#include "gfield.h"
18#include "gfieldConventions.h"
19#include "gfield_options.h"
20
21
22// Create a Geant4 field manager and chord finder for this field (non-Doxygen summary).
23// Notice: we are always using G4Mag_UsualEqRhs here.
24G4FieldManager* GField::create_FieldManager() {
25
26 std::string integration_stepper = gfield_definitions.integration_stepper;
27 double minimum_step = gfield_definitions.minimum_step;
28
29 // Equation of motion for magnetic field integration.
30 G4Mag_UsualEqRhs* iEquation = new G4Mag_UsualEqRhs(this);
31
32 // Validate the requested stepper name and fall back to the default if unsupported.
33 if (std::find(SUPPORTED_STEPPERS.begin(), SUPPORTED_STEPPERS.end(), integration_stepper) == SUPPORTED_STEPPERS.end()) {
34 log->info(
35 0, "Integration Stepper %1 not supported. Using default: %2", integration_stepper,
38 }
39
40 G4MagIntegratorStepper* mag_int_stepper = nullptr;
41
42 // Select the stepper implementation by name.
43 // (This is intentionally explicit rather than reflective/automatic.)
44 if (integration_stepper == "G4DormandPrince745") {
45 mag_int_stepper = new G4DormandPrince745(iEquation);
46 } else if (integration_stepper == "G4ClassicalRK4") {
47 mag_int_stepper = new G4ClassicalRK4(iEquation);
48 } else if (integration_stepper == "G4SimpleRunge") {
49 mag_int_stepper = new G4HelixSimpleRunge(iEquation);
50 } else if (integration_stepper == "G4HelixExplicitEuler") {
51 mag_int_stepper = new G4HelixExplicitEuler(iEquation);
52 } else if (integration_stepper == "G4HelixImplicitEuler") {
53 mag_int_stepper = new G4HelixImplicitEuler(iEquation);
54 } else if (integration_stepper == "G4CashKarpRKF45") {
55 mag_int_stepper = new G4CashKarpRKF45(iEquation);
56 } else if (integration_stepper == "G4RKG3_Stepper") {
57 mag_int_stepper = new G4RKG3_Stepper(iEquation);
58 } else if (integration_stepper == "G4SimpleHeum") {
59 mag_int_stepper = new G4SimpleHeum(iEquation);
60 } else if (integration_stepper == "G4NystromRK4") {
61 mag_int_stepper = new G4NystromRK4(iEquation);
62 } else if (integration_stepper == "G4ImplicitEuler") {
63 mag_int_stepper = new G4ImplicitEuler(iEquation);
64 } else if (integration_stepper == "G4ExplicitEuler") {
65 mag_int_stepper = new G4ExplicitEuler(iEquation);
66 } else {
67 // If we got here, the name was expected to be valid but no branch matched.
68 log->error(
69 gfields::ERR_STEPPER_NOT_FOUND, "Integration Stepper %1 not found. Exiting.", integration_stepper);
70 }
71
72 // Build the chord finder (controls step subdivision and interpolation along curved trajectories).
73 G4ChordFinder* fChordFinder = new G4ChordFinder(this, minimum_step, mag_int_stepper);
74
75 // Field manager owns the chord finder and ties the field into Geant4 transportation.
76 return new G4FieldManager(this, fChordFinder);
77}
std::shared_ptr< GLogger > log
GFieldDefinition gfield_definitions
Stored field definition used for configuration and logging.
Definition gfield.h:191
G4FieldManager * create_FieldManager()
Create a G4FieldManager configured for this field.
Definition gfield.cc:24
constexpr char GFIELD_DEFAULT_INTEGRATION_STEPPER[]
Default integration stepper name used when the requested stepper is unsupported.
constexpr int ERR_STEPPER_NOT_FOUND