BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSFieldQueryForVis.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include "BDSFieldQueryForVis.hh"
19#include "BDSFieldQueryInfo.hh"
20
21#include "G4ThreeVector.hh"
22#include "G4Types.hh"
23
24#include <algorithm>
25#include <array>
26#include <cmath>
27#include <limits>
28#include <vector>
29
30
31BDSFieldQueryForVis::BDSFieldQueryForVis():
32 maxFieldB(0),
33 maxFieldE(0),
34 drawZeroValuePoints(false)
35{;}
36
37BDSFieldQueryForVis::~BDSFieldQueryForVis()
38{;}
39
41{
43 values.clear();
44 maxFieldB = -std::numeric_limits<G4double>::max();
45 maxFieldE = -std::numeric_limits<G4double>::max();
46}
47
49{
50 G4int totalNPoints = query->xInfo.n * query->yInfo.n * query->zInfo.n * query->tInfo.n;
51 values.reserve(totalNPoints);
52 drawZeroValuePoints = query->drawZeroValuePoints;
54}
55
56void BDSFieldQueryForVis::GetFieldValue(const G4ThreeVector& globalXYZ,
57 const G4ThreeVector& globalDirection,
58 G4double tGlobal,
59 G4double fieldValue[6])
60{
61 BDSFieldQuery::GetFieldValue(globalXYZ, globalDirection, tGlobal, fieldValue);
62 G4double bFieldMag = SimpleMag(fieldValue[0], fieldValue[1], fieldValue[2]);
63 G4double eFieldMag = SimpleMag(fieldValue[3], fieldValue[4], fieldValue[5]);
64 maxFieldB = std::max(maxFieldB, bFieldMag);
65 maxFieldE = std::max(maxFieldE, eFieldMag);
66 if ( (bFieldMag == 0) && (eFieldMag == 0) && !drawZeroValuePoints)
67 {return;} // don't store 0 field points - we don't need to retain the structure or complete array shape
68 values.emplace_back( std::array<G4double, 9>({globalXYZ.x(), globalXYZ.y(), globalXYZ.z(),
69 fieldValue[0], fieldValue[1], fieldValue[2],
70 fieldValue[3], fieldValue[4], fieldValue[5]}) );
71}
72
73G4double BDSFieldQueryForVis::SimpleMag(G4double x, G4double y, G4double z)
74{
75 return std::sqrt(x*x + y*y + z*z);
76}
virtual void GetFieldValue(const G4ThreeVector &globalXYZ, const G4ThreeVector &globalDirection, G4double tGlobal, G4double fieldValue[6])
Call base class method but make a copy of the global position and fields in this class.
virtual void QueryField(const BDSFieldQueryInfo *query)
Reserve the vector size we need first, then proceed as normal. Avoids big copies.
virtual void CleanUp()
Call the base class method and also clear the vector of values in this class.
static G4double SimpleMag(G4double x, G4double y, G4double z)
Calculate magnitude of 3-vector without having to construct one.
Holder class for all information required for a field query.
virtual void CleanUp()
Reset any member variables used during a query. Closes any files if open.
virtual void QueryField(const BDSFieldQueryInfo *query)
Query the field in the Geant4 model according to information in query.
virtual void GetFieldValue(const G4ThreeVector &globalXYZ, const G4ThreeVector &globalDirection, G4double tGlobal, G4double fieldValue[6])