BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSArray1DCoordsTransformed.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 "BDSArray1DCoordsTransformed.hh"
19#include "BDSArrayOperatorIndex.hh"
20#include "BDSArrayOperatorValue.hh"
21#include "BDSFieldValue.hh"
22
23#include "globals.hh"
24
25#include <array>
26#include <cmath>
27#include <ostream>
28
30 BDSArrayOperatorIndex* indexOperatorIn,
31 BDSArrayOperatorValue* valueOperatorIn):
32 BDSArray1DCoords(*arrayIn),
33 indexOperator(indexOperatorIn),
34 valueOperator(valueOperatorIn),
35 returnValue(BDSFieldValue())
36{;}
37
38BDSArray1DCoordsTransformed::~BDSArray1DCoordsTransformed()
39{
40 delete indexOperator;
41 delete valueOperator;
42}
43
45 BDSFieldValue (&localData)[2],
46 G4double& xFrac) const
47{
48 G4double xArrayCoords = ArrayCoordsFromX(x);
49
50 auto x1 = (G4int)std::floor(xArrayCoords);
51
52 xFrac = xArrayCoords - x1;
53 std::array<G4int, 2> indexArr = {x1, x1+1};
54 G4int indexOriginal, indexTransformed;
55 for (G4int i = 0; i < 2; i++)
56 {
57 indexOriginal = indexArr[i];
58 indexTransformed = indexOriginal;
59 indexOperator->Apply(indexTransformed);
60 BDSFieldValue v = GetConst(indexTransformed);
61 localData[i] = valueOperator->Apply(v, indexOriginal);
62 }
63}
64
66 BDSFieldValue (&localData)[4],
67 G4double& xFrac) const
68{
69 G4double xArrayCoords = ArrayCoordsFromX(x);
70 auto x1 = (G4int)std::floor(xArrayCoords);
71 xFrac = xArrayCoords - x1;
72
73 std::array<G4int, 4> indexArr = {x1-1, x1, x1+1, x1+2};
74 G4int indexOriginal, indexTransformed;
75 for (G4int i = 0; i < 4; i++)
76 {
77 indexOriginal = indexArr[i];
78 indexTransformed = indexOriginal;
79 indexOperator->Apply(indexTransformed);
80 BDSFieldValue v = GetConst(indexTransformed);
81 localData[i] = valueOperator->Apply(v, indexOriginal);
82 }
83}
84
86 G4double /*y*/,
87 G4double /*z*/,
88 G4double /*t*/) const
89{
90 G4int indexOriginal = NearestX(x);
91 G4int indexTransformed = indexOriginal;
92 indexOperator->Apply(indexTransformed);
93 BDSFieldValue v = GetConst(indexTransformed);
94 v = valueOperator->Apply(v, indexOriginal);
95 return v;
96}
97
98std::ostream& BDSArray1DCoordsTransformed::Print(std::ostream& out) const
99{
100 out << "Spatial limits are the original ones" << G4endl;
101 out << "Array index operator: " << indexOperator->Name() << G4endl;
102 out << "Array value operator: " << valueOperator->Name() << G4endl;
103 return BDSArray1DCoords::Print(out);
104}
105
106std::ostream& operator<< (std::ostream& out, BDSArray1DCoordsTransformed const &a)
107{
108 return a.Print(out);
109}
Wrapped BDSArray1DCoords with possible transformation to extend field.
virtual std::ostream & Print(std::ostream &out) const
virtual void ExtractSection2(G4double x, BDSFieldValue(&localData)[2], G4double &xFrac) const
virtual void ExtractSection4(G4double x, BDSFieldValue(&localData)[4], G4double &xFrac) const
virtual BDSFieldValue ExtractNearest(G4double x, G4double y=0, G4double z=0, G4double t=0) const
Extract nearest field value from array. y,z,t ignored but required for overload.
BDSArray1DCoordsTransformed()=delete
No default constructor.
1D array with spatial mapping derived from BDSArray4DCoords.
virtual G4double ArrayCoordsFromX(G4double x) const
Not much point in being both virtual and inline (in our use case) but has to be virtual.
virtual G4int NearestX(G4double x) const
Not much point in being both virtual and inline (in our use case) but has to be virtual.
virtual const BDSFieldValue & GetConst(G4int x, G4int y=0, G4int z=0, G4int t=0) const
Definition BDSArray4D.cc:45
virtual std::ostream & Print(std::ostream &out) const
Definition BDSArray4D.cc:90
Interface for modifying by reference array indices.
virtual G4String Name() const
Supply a name of this operator for feedback to the user in print out.
virtual void Apply(G4int &, G4int &, G4int &, G4int &) const
Interface for modifying field values.
virtual BDSFieldValue Apply(BDSFieldValue v, G4int, G4int=0, G4int=0, G4int=0) const
virtual G4String Name() const
Return a name of the operator for feedback to the user in print out.