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(0, "Integration Stepper ", integration_stepper,
35 " not supported. Using default: ", gfields::GFIELD_DEFAULT_INTEGRATION_STEPPER);
37 }
38
39 G4MagIntegratorStepper* mag_int_stepper = nullptr;
40
41 // Select the stepper implementation by name.
42 // (This is intentionally explicit rather than reflective/automatic.)
43 if (integration_stepper == "G4DormandPrince745") {
44 mag_int_stepper = new G4DormandPrince745(iEquation);
45 } else if (integration_stepper == "G4ClassicalRK4") {
46 mag_int_stepper = new G4ClassicalRK4(iEquation);
47 } else if (integration_stepper == "G4SimpleRunge") {
48 mag_int_stepper = new G4HelixSimpleRunge(iEquation);
49 } else if (integration_stepper == "G4HelixExplicitEuler") {
50 mag_int_stepper = new G4HelixExplicitEuler(iEquation);
51 } else if (integration_stepper == "G4HelixImplicitEuler") {
52 mag_int_stepper = new G4HelixImplicitEuler(iEquation);
53 } else if (integration_stepper == "G4CashKarpRKF45") {
54 mag_int_stepper = new G4CashKarpRKF45(iEquation);
55 } else if (integration_stepper == "G4RKG3_Stepper") {
56 mag_int_stepper = new G4RKG3_Stepper(iEquation);
57 } else if (integration_stepper == "G4SimpleHeum") {
58 mag_int_stepper = new G4SimpleHeum(iEquation);
59 } else if (integration_stepper == "G4NystromRK4") {
60 mag_int_stepper = new G4NystromRK4(iEquation);
61 } else if (integration_stepper == "G4ImplicitEuler") {
62 mag_int_stepper = new G4ImplicitEuler(iEquation);
63 } else if (integration_stepper == "G4ExplicitEuler") {
64 mag_int_stepper = new G4ExplicitEuler(iEquation);
65 } else {
66 // If we got here, the name was expected to be valid but no branch matched.
67 log->error(gfields::ERR_STEPPER_NOT_FOUND, "Integration Stepper ", integration_stepper,
68 " not found. Exiting.");
69 }
70
71 // Build the chord finder (controls step subdivision and interpolation along curved trajectories).
72 G4ChordFinder* fChordFinder = new G4ChordFinder(this, minimum_step, mag_int_stepper);
73
74 // Field manager owns the chord finder and ties the field into Geant4 transportation.
75 return new G4FieldManager(this, fChordFinder);
76}
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