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, " not supported. Using default: ", GFIELD_DEFAULT_INTEGRATION_STEPPER);
35 integration_stepper = GFIELD_DEFAULT_INTEGRATION_STEPPER;
36 }
37
38 G4MagIntegratorStepper* mag_int_stepper = nullptr;
39
40 // Select the stepper implementation by name.
41 // (This is intentionally explicit rather than reflective/automatic.)
42 if (integration_stepper == "G4DormandPrince745") {
43 mag_int_stepper = new G4DormandPrince745(iEquation);
44 } else if (integration_stepper == "G4ClassicalRK4") {
45 mag_int_stepper = new G4ClassicalRK4(iEquation);
46 } else if (integration_stepper == "G4SimpleRunge") {
47 mag_int_stepper = new G4HelixSimpleRunge(iEquation);
48 } else if (integration_stepper == "G4HelixExplicitEuler") {
49 mag_int_stepper = new G4HelixExplicitEuler(iEquation);
50 } else if (integration_stepper == "G4HelixImplicitEuler") {
51 mag_int_stepper = new G4HelixImplicitEuler(iEquation);
52 } else if (integration_stepper == "G4CashKarpRKF45") {
53 mag_int_stepper = new G4CashKarpRKF45(iEquation);
54 } else if (integration_stepper == "G4RKG3_Stepper") {
55 mag_int_stepper = new G4RKG3_Stepper(iEquation);
56 } else if (integration_stepper == "G4SimpleHeum") {
57 mag_int_stepper = new G4SimpleHeum(iEquation);
58 } else if (integration_stepper == "G4NystromRK4") {
59 mag_int_stepper = new G4NystromRK4(iEquation);
60 } else if (integration_stepper == "G4ImplicitEuler") {
61 mag_int_stepper = new G4ImplicitEuler(iEquation);
62 } else if (integration_stepper == "G4ExplicitEuler") {
63 mag_int_stepper = new G4ExplicitEuler(iEquation);
64 } else {
65 // If we got here, the name was expected to be valid but no branch matched.
66 log->error(ERR_STEPPER_NOT_FOUND, "Integration Stepper ", integration_stepper, " not found. Exiting.");
67 }
68
69 // Build the chord finder (controls step subdivision and interpolation along curved trajectories).
70 G4ChordFinder* fChordFinder = new G4ChordFinder(this, minimum_step, mag_int_stepper);
71
72 // Field manager owns the chord finder and ties the field into Geant4 transportation.
73 return new G4FieldManager(this, fChordFinder);
74}
std::shared_ptr< GLogger > log
GFieldDefinition gfield_definitions
Stored field definition used for configuration and logging.
Definition gfield.h:185
G4FieldManager * create_FieldManager()
Create a G4FieldManager configured for this field.
Definition gfield.cc:24
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
#define GFIELD_DEFAULT_INTEGRATION_STEPPER
Default integration stepper name used when the requested stepper is unsupported.
#define ERR_STEPPER_NOT_FOUND
double minimum_step
Minimum step size used when constructing the G4ChordFinder (Geant4 length units).
Definition gfield.h:39
std::string integration_stepper
Integration stepper name (string) used when creating the G4ChordFinder.
Definition gfield.h:36