BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSBeamPipeFactoryOctagonal.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 "BDSDebug.hh"
20#include "BDSBeamPipeFactoryOctagonal.hh"
21#include "BDSBeamPipeFactoryPoints.hh"
22
23#include "globals.hh" // geant4 globals / types
24#include "G4TwoVector.hh"
25
26#include <cmath>
27
28BDSBeamPipeFactoryOctagonal::BDSBeamPipeFactoryOctagonal()
29{;}
30
31void BDSBeamPipeFactoryOctagonal::GenerateOctagonal(std::vector<G4TwoVector>& vec,
32 G4double x1,
33 G4double y1,
34 G4double x2,
35 G4double y2)
36{
37 AppendPoint(vec, x1, y2 );
38 AppendPoint(vec, x1, -y2);
39 AppendPoint(vec, x2, -y1);
40 AppendPoint(vec, -x2, -y1);
41 AppendPoint(vec, -x1, -y2);
42 AppendPoint(vec, -x1, y2 );
43 AppendPoint(vec, -x2, y1 );
44 AppendPoint(vec, x2, y1 );
45}
46
48 G4double aper2,
49 G4double aper3,
50 G4double aper4,
51 G4double distance)
52{
53 // All calculations done in top right quadrant
54 G4TwoVector p1 = G4TwoVector(aper3, aper2);
55 G4TwoVector p1Unit = p1.unit();
56 G4TwoVector p1New = distance*p1Unit;
57
58 G4TwoVector p2 = G4TwoVector(aper1, aper4);
59 G4TwoVector p2Unit = p2.unit();
60 G4TwoVector p2New = distance*p2Unit;
61
62 G4double a1 = aper1 + distance;
63 G4double a2 = aper2 + distance;
64 G4double a3 = aper3 + p1New.x();
65 G4double a4 = aper4 + p2New.y();
66
67 BDS::FourPoints result = {a1,a2,a3,a4};
68 return result;
69}
70
72 G4double aper2,
73 G4double aper3,
74 G4double aper4,
75 G4double beamPipeThickness,
76 G4int /*pointsPerTwoPi*/)
77{
78 GenerateOctagonal(vacuumEdge, aper1, aper2, aper3, aper4);
79 BDS::FourPoints ai = ExpandOctagon(aper1, aper2, aper3, aper4, lengthSafetyLarge);
80 GenerateOctagonal(beamPipeInnerEdge, ai.aper1, ai.aper2, ai.aper3, ai.aper4);
81 BDS::FourPoints ao = ExpandOctagon(aper1, aper2, aper3, aper4, lengthSafetyLarge + beamPipeThickness);
82 GenerateOctagonal(beamPipeOuterEdge, ao.aper1, ao.aper2, ao.aper3, ao.aper4);
83 BDS::FourPoints ac = ExpandOctagon(aper1, aper2, aper3, aper4, beamPipeThickness + 2*lengthSafetyLarge);
84 GenerateOctagonal(containerEdge, ac.aper1, ac.aper2, ac.aper3, ac.aper4);
85 BDS::FourPoints acs = ExpandOctagon(aper1, aper2, aper3, aper4, beamPipeThickness + 3*lengthSafetyLarge);
86 GenerateOctagonal(containerSubtractionEdge, acs.aper1, acs.aper2, acs.aper3, acs.aper4);
87
88 extentX = acs.aper1;
89 extentY = acs.aper2;
90}
91
93 G4double aper2,
94 G4double aper3,
95 G4double aper4,
96 G4double beamPipeThickness)
97{
98 // We calculate the expanded aper1234 parameters corresponding to the outermost octagon
99 // this has to be the same as the last ExpandOctagon in GeneratePoints()
100 BDS::FourPoints acs = ExpandOctagon(aper1, aper2, aper3, aper4, beamPipeThickness + 2*lengthSafetyLarge);
101
102 // depending on the user supplied parameters, choose the largest radius from the origin,
103 // and add the beam pipe thickness plus some margin
104 G4double maxXY = std::max(acs.aper1, acs.aper2);
105 G4double r1 = std::hypot(acs.aper1, acs.aper4);
106 G4double r2 = std::hypot(acs.aper2,acs.aper3);
107 G4double result = std::max({maxXY, r1,r2});
108 result += lengthSafetyLarge;
109 return result;
110}
virtual void GeneratePoints(G4double aper1, G4double aper2, G4double aper3, G4double aper4, G4double beamPipeThickness, G4int pointsPerTwoPi=40)
virtual G4double CalculateIntersectionRadius(G4double aper1, G4double aper2, G4double aper3, G4double aper4, G4double beamPipeThickness)
Calculate the radius of the solid used for intersection for angled faces.
void GenerateOctagonal(std::vector< G4TwoVector > &vec, G4double x1, G4double y1, G4double x2, G4double y2)
Append 2D points on an octagon in a clockwise direction into the vector argument.
BDS::FourPoints ExpandOctagon(G4double aper1, G4double aper2, G4double aper3, G4double aper4, G4double distance)
std::vector< G4TwoVector > containerSubtractionEdge
Vector of x,y coordinates for the container subtraction volume.
std::vector< G4TwoVector > beamPipeInnerEdge
Vector of x,y coordinates for beam pipe inner edge.
G4double extentY
Extents prepared by GeneratePoints function as only it knows the extents.
G4double extentX
Extents prepared by GeneratePoints function as only it knows the extents.
std::vector< G4TwoVector > vacuumEdge
Vector of x,y coordinates for vacuum extruded solid edge.
std::vector< G4TwoVector > containerEdge
Vector of x,y coordinates for the container volume.
std::vector< G4TwoVector > beamPipeOuterEdge
Vector of x,y coordinates for beam pipe outer edge.
G4double lengthSafetyLarge
Cache of global constants variable.