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) Royal Holloway,
3University of London 2001 - 2023.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#include "BDSArray1DCoordsTransformed.hh"
20#include "BDSArrayOperatorIndex.hh"
21#include "BDSArrayOperatorValue.hh"
22#include "BDSFieldValue.hh"
23
24#include "globals.hh"
25
26#include <array>
27#include <cmath>
28#include <ostream>
29
31 BDSArrayOperatorIndex* indexOperatorIn,
32 BDSArrayOperatorValue* valueOperatorIn):
33 BDSArray1DCoords(*arrayIn),
34 indexOperator(indexOperatorIn),
35 valueOperator(valueOperatorIn),
36 returnValue(BDSFieldValue())
37{;}
38
39BDSArray1DCoordsTransformed::~BDSArray1DCoordsTransformed()
40{
41 delete indexOperator;
42 delete valueOperator;
43}
44
46 BDSFieldValue (&localData)[2],
47 G4double& xFrac) const
48{
49 G4double xArrayCoords = ArrayCoordsFromX(x);
50
51 auto x1 = (G4int)std::floor(xArrayCoords);
52
53 xFrac = xArrayCoords - x1;
54 std::array<G4int, 2> indexArr = {x1, x1+1};
55 G4int indexOriginal, indexTransformed;
56 for (G4int i = 0; i < 2; i++)
57 {
58 indexOriginal = indexArr[i];
59 indexTransformed = indexOriginal;
60 indexOperator->Apply(indexTransformed);
61 BDSFieldValue v = GetConst(indexTransformed);
62 localData[i] = valueOperator->Apply(v, indexOriginal);
63 }
64}
65
67 BDSFieldValue (&localData)[4],
68 G4double& xFrac) const
69{
70 G4double xArrayCoords = ArrayCoordsFromX(x);
71 auto x1 = (G4int)std::floor(xArrayCoords);
72 xFrac = xArrayCoords - x1;
73
74 std::array<G4int, 4> indexArr = {x1-1, x1, x1+1, x1+2};
75 G4int indexOriginal, indexTransformed;
76 for (G4int i = 0; i < 4; i++)
77 {
78 indexOriginal = indexArr[i];
79 indexTransformed = indexOriginal;
80 indexOperator->Apply(indexTransformed);
81 BDSFieldValue v = GetConst(indexTransformed);
82 localData[i] = valueOperator->Apply(v, indexOriginal);
83 }
84}
85
87 G4double /*y*/,
88 G4double /*z*/,
89 G4double /*t*/) const
90{
91 G4int indexOriginal = NearestX(x);
92 G4int indexTransformed = indexOriginal;
93 indexOperator->Apply(indexTransformed);
94 BDSFieldValue v = GetConst(indexTransformed);
95 v = valueOperator->Apply(v, indexOriginal);
96 return v;
97}
98
99std::ostream& BDSArray1DCoordsTransformed::Print(std::ostream& out) const
100{
101 out << "Spatial limits are the original ones" << G4endl;
102 out << "Array index operator: " << indexOperator->Name() << G4endl;
103 out << "Array value operator: " << valueOperator->Name() << G4endl;
104 return BDSArray1DCoords::Print(out);
105}
106
107std::ostream& operator<< (std::ostream& out, BDSArray1DCoordsTransformed const &a)
108{
109 return a.Print(out);
110}
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:46
virtual std::ostream & Print(std::ostream &out) const
Definition: BDSArray4D.cc:91
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.