60G4FieldBuilder::G4FieldBuilder()
77 for (
auto parameters : fFieldParameters) {
81 for (
auto setup : GetFieldSetups()) {
102 for (
auto fieldParameters : fFieldParameters) {
103 if (fieldParameters->GetVolumeName() == volumeName) {
105 return fieldParameters;
111 auto fieldParameters =
new G4FieldParameters(volumeName);
112 fFieldParameters.push_back(fieldParameters);
113 return fieldParameters;
122 for (
auto fieldSetup : GetFieldSetups()) {
123 if (fieldSetup->GetLogicalVolume() == lv) {
132void G4FieldBuilder::CreateFieldSetup(
G4Field* field,
137 auto fieldSetup =
new G4FieldSetup(*fieldParameters, field, lv);
138 fieldSetup->PrintInfo(fVerboseLevel);
140 if (fFieldSetups.Get() ==
nullptr) {
141 auto fieldSetups =
new std::vector<G4FieldSetup*>();
142 fFieldSetups.Put(fieldSetups);
145 GetFieldSetups().push_back(fieldSetup);
149void G4FieldBuilder::ConstructGlobalField()
153 if (fVerboseLevel > 1) {
154 G4cout <<
"G4FieldBuilder::ConstructGlobalField " <<
G4endl;
157 CreateFieldSetup(fGlobalField, fFieldParameters[0],
nullptr);
161void G4FieldBuilder::ConstructLocalFields()
165 if (fLocalFields.Get() ==
nullptr)
return;
167 if (fVerboseLevel > 1) {
168 G4cout <<
"G4FieldBuilder::ConstructLocalFields()" <<
G4endl;
172 for (
auto [lv, field] : GetLocalFields()) {
175 const auto& volumeName = lv->
GetName();
178 G4FieldParameters* fieldParameters =
179 GetOrCreateFieldParameters(volumeName);
181 if (fVerboseLevel > 1) {
182 G4cout <<
"Construct local field in volume: " << volumeName <<
G4endl;
186 CreateFieldSetup(field, fieldParameters, lv);
191void G4FieldBuilder::UpdateFieldSetups()
195 if (fVerboseLevel > 1) {
196 G4cout <<
"G4FieldBuilder::UpdateFieldSetups " <<
G4endl;
199 for (
auto fieldSetup : GetFieldSetups()) {
200 fieldSetup->Update();
202 if (fVerboseLevel > 1) {
203 fieldSetup->PrintInfo(fVerboseLevel,
"updated");
222 fFieldParameters.push_back(fieldParameters);
224 return fieldParameters;
232 if (fVerboseLevel > 1) {
236 if (fIsConstructed) {
238 "G4FieldBuilder::ConstructField:",
"GeomFieldParameters0001",
243 ConstructGlobalField();
244 ConstructLocalFields();
248 fIsConstructed =
true;
258 if (fFieldSetups.Get() ==
nullptr) {
260 "G4FieldBuilder::UpdateField",
"GeomFieldParameters0001",
265 if (fVerboseLevel > 1) {
279 if (fVerboseLevel > 1) {
285 fGlobalField =
nullptr;
288 if (fLocalFields.Get() !=
nullptr) {
289 for (
auto vectorElement : GetLocalFields()) {
290 delete vectorElement.second;
293 GetLocalFields().clear();
297 if (fFieldSetups.Get() !=
nullptr) {
298 for (
auto fieldSetup : GetFieldSetups()) {
299 fieldSetup->SetG4Field(
nullptr);
304 fIsConstructed =
false;
306 if (fVerboseLevel > 1) {
307 G4cout <<
"End of G4FieldBuilder::Reinitialize" <<
G4endl;
318 if (fIsConstructed) {
320 "G4FieldBuilder::SetFieldType:",
"GeomFieldParameters0001",
325 fFieldParameters[0]->SetFieldType(fieldType);
341 if (fGlobalField !=
nullptr && warn) {
343 "G4FieldBuilder::SetGlobalField:",
"GeomFieldParameters0001",
344 JustWarning,
"The global field already exists, it will be deleted.");
347 fGlobalField = field;
349 if (fIsConstructed) {
351 GetFieldSetups()[0]->SetG4Field(field);
352 GetFieldSetups()[0]->Update();
365 G4cerr <<
"Cannot register local field without Logical volume." <<
G4endl;
369 if (fLocalFields.Get() ==
nullptr) {
370 auto localFields =
new std::vector<std::pair<G4LogicalVolume*, G4Field*>>();
371 fLocalFields.Put(localFields);
374 auto it = GetLocalFields().begin();
375 for (it = GetLocalFields().begin(); it != GetLocalFields().end(); ++it) {
376 if (it->first == lv)
break;
379 if (it != GetLocalFields().end()) {
383 descr <<
"Logical volume " << lv->
GetName() <<
" has already field."
384 " It will be deleted.";
386 "G4FieldBuilder::SetLocalField:",
"GeomFieldParameters0001",
394 GetLocalFields().push_back(std::pair(lv,field));
397 if (fIsConstructed) {
399 auto fieldSetup = GetFieldSetup(lv);
400 if (fieldSetup ==
nullptr) {
402 "G4FieldBuilder::SetLocalField:",
"GeomFieldParameters0001",
403 JustWarning,
"Cannot get field setup for a local field.");
406 fieldSetup->SetG4Field(field);
407 fieldSetup->Update();
417 if (!volumeName.size()) {
419 fFieldParameters[0]->SetUserEquationOfMotion(equation);
425 GetOrCreateFieldParameters(volumeName);
436 if (!volumeName.size()) {
438 fFieldParameters[0]->SetUserStepper(stepper);
444 GetOrCreateFieldParameters(volumeName);
457 for (
auto fieldParameters : fFieldParameters) {
460 return fieldParameters;
465 "G4FieldBuilder::GetFieldParameters:",
"GeomFieldParameters0001",
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
Definition of the G4FieldParameters class.
G4FieldType
The available fields in Geant4.
@ kElectroMagnetic
electromagnetic field
@ kClassicalRK4
G4ClassicalRK4.
G4TemplateRNGHelper< G4long > * G4TemplateRNGHelper< G4long >::instance
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
Messenger class that defines commands for G4FieldBuilder.
G4FieldParameters * CreateFieldParameters(const G4String &fieldVolName)
void SetUserStepper(G4MagIntegratorStepper *stepper, G4String volumeName="")
Set user stepper.
void ConstructFieldSetup()
Construct setups for all registered fields.
G4FieldParameters * GetFieldParameters(const G4String &volumeName="") const
void SetLocalField(G4Field *field, G4LogicalVolume *lv, G4bool warn=false)
static G4FieldBuilder * Instance()
~G4FieldBuilder()
Destructor.
void SetFieldType(G4FieldType fieldType)
void SetGlobalField(G4Field *field, G4bool warn=false)
void SetUserEquationOfMotion(G4EquationOfMotion *equation, G4String volumeName="")
Set user equation of motion.
The magnetic field parameters.
G4String GetVolumeName() const
void SetUserStepper(G4MagIntegratorStepper *stepper)
Set user defined integrator of particle's equation of motion.
void SetUserEquationOfMotion(G4EquationOfMotion *equation)
Set user defined equation of motion.
The class for constructing magnetic, electromagnetic and gravity fields which strength is defined via...
const G4String & GetName() const