87 : fParameters(parameters), fG4Field(field), fLogicalVolume(lv)
94 if (fLogicalVolume ==
nullptr) {
101 G4bool overwriteDaughtersField =
true;
103 fLogicalVolume->SetFieldManager(fFieldManager, overwriteDaughtersField);
121G4Field* G4FieldSetup::CreateCachedField(
130 if (magField ==
nullptr) {
132 "G4FieldSetup::CreateCachedField:",
"GeomFieldParameters0001",
148 G4MagneticField* magField =
nullptr;
150 magField =
dynamic_cast<G4MagneticField*
>(fG4Field);
151 if (magField ==
nullptr) {
153 "G4FieldSetup::CreateEquation:",
"GeomFieldParameters0001",
155 "The field type must be set explicitly for other than magnetic field.");
161 G4ElectroMagneticField* elMagField =
nullptr;
163 elMagField =
dynamic_cast<G4ElectroMagneticField*
>(fG4Field);
164 if (elMagField ==
nullptr) {
166 "G4FieldSetup::CreateEquation:",
"GeomFieldParameters0001",
168 "The field type must be set explicitly for other than magnetic field.");
176 return new G4Mag_UsualEqRhs(magField);
180 return new G4Mag_SpinEqRhs(magField);
184 return new G4EqMagElectricField(elMagField);
188 return new G4EqEMFieldWithSpin(elMagField);
192 return new G4EqEMFieldWithEDM(elMagField);
201 "G4FieldSetup::CreateEquation:",
"GeomFieldParameters0001",
213 auto eqRhs =
dynamic_cast<G4Mag_EqRhs*
>(equation);
216 "G4FieldSetup::CreateStepper:",
"GeomFieldParameters0001",
218 "The stepper type requires equation of motion of G4Mag_EqRhs type.");
224 return new G4BogackiShampine23(equation);
228 return new G4BogackiShampine45(equation);
232 return new G4CashKarpRKF45(equation);
236 return new G4ClassicalRK4(equation);
240 return new G4DormandPrince745(equation);
244 return new G4DormandPrinceRK56(equation);
248 return new G4DormandPrinceRK78(equation);
252 return new G4ExplicitEuler(equation);
256 return new G4ImplicitEuler(equation);
260 return new G4SimpleHeum(equation);
264 return new G4SimpleRunge(equation);
268 return new G4TsitourasRK45(equation);
272 return new G4ConstRK4(eqRhs);
276 return new G4ExactHelixStepper(eqRhs);
280 return new G4HelixExplicitEuler(eqRhs);
284 return new G4HelixHeum(eqRhs);
288 return new G4HelixImplicitEuler(eqRhs);
292 return new G4HelixMixedStepper(eqRhs);
296 return new G4HelixSimpleRunge(eqRhs);
300 return new G4NystromRK4(eqRhs);
304 return new G4RKG3_Stepper(eqRhs);
312 "G4FieldSetup::CreateStepper:",
"GeomFieldParameters0001",
324 switch (stepperType) {
326 return new G4FSALIntegrationDriver<G4RK547FEq1>(
327 minStep,
new G4RK547FEq1(equation));
330 return new G4FSALIntegrationDriver<G4RK547FEq2>(
331 minStep,
new G4RK547FEq2(equation));
334 return new G4FSALIntegrationDriver<G4RK547FEq3>(
335 minStep,
new G4RK547FEq3(equation));
339 "G4FieldSetup::CreateFSALStepperAndDriver",
"GeomFieldParameters0001",
346void G4FieldSetup::CreateCachedField()
349 fG4Field = CreateCachedField(fParameters, fG4Field);
353void G4FieldSetup::CreateStepper()
357 fEquation = fParameters.GetUserEquationOfMotion();
363 fEquation = CreateEquation(fParameters.GetEquationType());
366 fEquation->SetFieldObj(fG4Field);
371 fStepper = fParameters.GetUserStepper();
374 else if (fParameters.GetStepperType() >=
kRK547FEq1) {
380 fDriver = CreateFSALStepperAndDriver(
381 fEquation, fParameters.GetStepperType(), fParameters.GetMinimumStep());
384 fStepper = fDriver->GetStepper();
392 fStepper = CreateStepper(fEquation, fParameters.GetStepperType());
398void G4FieldSetup::CreateChordFinder()
401 if (fParameters.GetFieldType() ==
kMagnetic) {
403 fChordFinder =
new G4ChordFinder(fDriver);
408 fChordFinder =
new G4ChordFinder(
static_cast<G4MagneticField*
>(fG4Field),
409 fParameters.GetMinimumStep(), fStepper);
413 fChordFinder->SetDeltaChord(fParameters.GetDeltaChord());
417 G4MagInt_Driver* intDriver =
new G4MagInt_Driver(
418 fParameters.GetMinimumStep(), fStepper, fStepper->GetNumberOfVariables());
422 fChordFinder =
new G4ChordFinder(intDriver);
429void G4FieldSetup::UpdateFieldManager()
431 fFieldManager->SetChordFinder(fChordFinder);
432 fFieldManager->SetDetectorField(fG4Field);
439 fFieldManager->SetMinimumEpsilonStep(fParameters.GetMinimumEpsilonStep());
440 fFieldManager->SetMaximumEpsilonStep(fParameters.GetMaximumEpsilonStep());
441 fFieldManager->SetDeltaOneStep(fParameters.GetDeltaOneStep());
442 fFieldManager->SetDeltaIntersection(fParameters.GetDeltaIntersection());
454 fChordFinder =
nullptr;
456 if (fG4Field ==
nullptr) {
465 fChordFinder =
nullptr;
466 fFieldManager->SetChordFinder(fChordFinder);
467 fFieldManager->SetDetectorField(fG4Field);
477 if (fG4Field ==
nullptr) {
485 UpdateFieldManager();
491 if (verboseLevel == 0)
return;
494 auto isCachedMagneticField = (fParameters.GetConstDistance() > 0.);
495 if (fLogicalVolume ==
nullptr) {
496 fieldType =
"Global";
499 fieldType =
"Local (in ";
500 fieldType.append(fLogicalVolume->GetName());
501 fieldType.append(
")");
503 if (isCachedMagneticField) {
504 fieldType.append(
" cached");
507 G4cout << fieldType <<
" field " << about <<
" with stepper ";
509 fParameters.GetStepperType())
512 if (verboseLevel > 1) {
513 fParameters.PrintParameters();
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
@ kUserEquation
User defined equation of motion.
@ kElectroMagnetic
electromagnetic field
@ kMagnetic
magnetic field
@ kRKG3Stepper
G4RKG3_Stepper.
@ kHelixSimpleRunge
G4HelixSimpleRunge.
@ kNystromRK4
G4NystromRK4.
@ kDormandPrince745
G4DormandPrince745.
@ kCashKarpRKF45
G4CashKarpRKF45.
@ kDormandPrinceRK78
G4DormandPrinceRK78.
@ kSimpleRunge
G4SimpleRunge.
@ kHelixImplicitEuler
G4HelixImplicitEuler.
@ kUserStepper
User defined stepper.
@ kSimpleHeum
G4SimpleHeum.
@ kHelixExplicitEuler
G4HelixExplicitEuler.
@ kDormandPrinceRK56
G4DormandPrinceRK56.
@ kTsitourasRK45
G4TsitourasRK45.
@ kImplicitEuler
G4ImplicitEuler.
@ kExactHelixStepper
G4ExactHelixStepper.
@ kHelixMixedStepper
G4HelixMixedStepper.
@ kBogackiShampine45
G4BogackiShampine45.
@ kExplicitEuler
G4ExplicitEuler.
@ kBogackiShampine23
G4BogackiShampine23.
@ kClassicalRK4
G4ClassicalRK4.
G4GLOB_DLL std::ostream G4cout
static G4FieldManager * GetGlobalFieldManager()
The magnetic field parameters.
G4double GetConstDistance() const
Get the distance within which the field is considered constant.
static G4String StepperTypeName(G4StepperType stepper)
Return the stepper type as a string.
static G4String FieldTypeName(G4FieldType field)
Return the field type as a string.
Messenger class that defines commands for G4FieldSetup.
G4FieldSetup(const G4FieldParameters ¶meters, G4Field *field, G4LogicalVolume *lv=nullptr)
Standard constructor.
void Clear()
Clear previously created setup.
~G4FieldSetup()
Destructor.
void PrintInfo(G4int verboseLevel, const G4String about="created")
Print information.
void Update()
Update field setup with new field parameters.