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) 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 "BDSDebug.hh"
19#include "BDSBeamPipeFactoryOctagonal.hh"
20#include "BDSBeamPipeFactoryPoints.hh"
21
22#include "globals.hh" // geant4 globals / types
23#include "G4TwoVector.hh"
24
25#include <cmath>
26
27BDSBeamPipeFactoryOctagonal::BDSBeamPipeFactoryOctagonal()
28{;}
29
30void BDSBeamPipeFactoryOctagonal::GenerateOctagonal(std::vector<G4TwoVector>& vec,
31 G4double x1,
32 G4double y1,
33 G4double x2,
34 G4double y2)
35{
36 AppendPoint(vec, x1, y2 );
37 AppendPoint(vec, x1, -y2);
38 AppendPoint(vec, x2, -y1);
39 AppendPoint(vec, -x2, -y1);
40 AppendPoint(vec, -x1, -y2);
41 AppendPoint(vec, -x1, y2 );
42 AppendPoint(vec, -x2, y1 );
43 AppendPoint(vec, x2, y1 );
44}
45
47 G4double aper2,
48 G4double aper3,
49 G4double aper4,
50 G4double distance)
51{
52 // All calculations done in top right quadrant
53 G4TwoVector p1 = G4TwoVector(aper3, aper2);
54 G4TwoVector p1Unit = p1.unit();
55 G4TwoVector p1New = distance*p1Unit;
56
57 G4TwoVector p2 = G4TwoVector(aper1, aper4);
58 G4TwoVector p2Unit = p2.unit();
59 G4TwoVector p2New = distance*p2Unit;
60
61 G4double a1 = aper1 + distance;
62 G4double a2 = aper2 + distance;
63 G4double a3 = aper3 + p1New.x();
64 G4double a4 = aper4 + p2New.y();
65
66 BDS::FourPoints result = {a1,a2,a3,a4};
67 return result;
68}
69
71 G4double aper2,
72 G4double aper3,
73 G4double aper4,
74 G4double beamPipeThickness,
75 G4int /*pointsPerTwoPi*/)
76{
77 GenerateOctagonal(vacuumEdge, aper1, aper2, aper3, aper4);
78 BDS::FourPoints ai = ExpandOctagon(aper1, aper2, aper3, aper4, lengthSafetyLarge);
79 GenerateOctagonal(beamPipeInnerEdge, ai.aper1, ai.aper2, ai.aper3, ai.aper4);
80 BDS::FourPoints ao = ExpandOctagon(aper1, aper2, aper3, aper4, lengthSafetyLarge + beamPipeThickness);
81 GenerateOctagonal(beamPipeOuterEdge, ao.aper1, ao.aper2, ao.aper3, ao.aper4);
82 BDS::FourPoints ac = ExpandOctagon(aper1, aper2, aper3, aper4, beamPipeThickness + 2*lengthSafetyLarge);
83 GenerateOctagonal(containerEdge, ac.aper1, ac.aper2, ac.aper3, ac.aper4);
84 BDS::FourPoints acs = ExpandOctagon(aper1, aper2, aper3, aper4, beamPipeThickness + 3*lengthSafetyLarge);
85 GenerateOctagonal(containerSubtractionEdge, acs.aper1, acs.aper2, acs.aper3, acs.aper4);
86
87 extentX = acs.aper1;
88 extentY = acs.aper2;
89}
90
92 G4double aper2,
93 G4double aper3,
94 G4double aper4,
95 G4double beamPipeThickness)
96{
97 // We calculate the expanded aper1234 parameters corresponding to the outermost octagon
98 // this has to be the same as the last ExpandOctagon in GeneratePoints()
99 BDS::FourPoints acs = ExpandOctagon(aper1, aper2, aper3, aper4, beamPipeThickness + 2*lengthSafetyLarge);
100
101 // depending on the user supplied parameters, choose the largest radius from the origin,
102 // and add the beam pipe thickness plus some margin
103 G4double maxXY = std::max(acs.aper1, acs.aper2);
104 G4double r1 = std::hypot(acs.aper1, acs.aper4);
105 G4double r2 = std::hypot(acs.aper2,acs.aper3);
106 G4double result = std::max({maxXY, r1,r2});
107 result += lengthSafetyLarge;
108 return result;
109}
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.