BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSGasCapillary.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2024.
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 "BDSAcceleratorModel.hh"
20#include "BDSBeamPipe.hh"
21#include "BDSBeamPipeFactory.hh"
22#include "BDSBeamPipeInfo.hh"
23#include "BDSGasCapillary.hh"
24#include "BDSColours.hh"
25#include "BDSDebug.hh"
26#include "BDSException.hh"
27#include "BDSGlobalConstants.hh"
28#include "BDSMaterials.hh"
29#include "BDSSDType.hh"
30#include "BDSUtilities.hh"
31#include "BDSWarning.hh"
32
33#include "globals.hh"
34#include "G4Box.hh"
35#include "G4LogicalVolume.hh"
36#include "G4PVPlacement.hh"
37#include "G4SubtractionSolid.hh"
38#include "G4IntersectionSolid.hh"
39#include "G4Tubs.hh"
40#include "G4UserLimits.hh"
41#include "G4VisAttributes.hh"
42
43#include <map>
44
45BDSGasCapillary::BDSGasCapillary(const G4String& nameIn,
46 G4double lengthIn,
47 BDSBeamPipeInfo* beamPipeInfoIn,
48 G4double horizontalWidthIn,
49 G4Material* capillaryOuterMaterialIn,
50 G4Material* capillaryGasMaterialIn,
51 G4Material* electrodesMaterialIn,
52 G4double capillaryGasDiameterIn,
53 G4double electrodeThicknessIn,
54 G4bool circularOuterIn):
55 BDSAcceleratorComponent(nameIn, lengthIn, 0, "gascap", beamPipeInfoIn),
56 horizontalWidth(horizontalWidthIn),
57 capillaryGasDiameter(capillaryGasDiameterIn),
58 electrodeThickness(electrodeThicknessIn),
59 circularOuter(circularOuterIn),
60
61 capillaryOuterSolid(nullptr),
62 capillaryGasSolid(nullptr),
63 electrodeSolid(nullptr),
64
65 capillaryOuterUncutSolid(nullptr),
66 electrodeUncutSolid(nullptr),
67
68 capillaryHoleSolid(nullptr),
69 electrodeHoleSolid(nullptr),
70
71 capillaryOuterMaterial(capillaryOuterMaterialIn),
72 capillaryGasMaterial(capillaryGasMaterialIn),
73 electrodeMaterial(electrodesMaterialIn)
74{;}
75
76BDSGasCapillary::~BDSGasCapillary()
77{;}
78
80{
82 {
83 G4cerr << __METHOD_NAME__ << "aperture bigger than width!" << G4endl;
84 G4cerr << "Full horizontal width is " << horizontalWidth << " mm for component named: \""
85 << name << "\"" << G4endl;
86 G4cerr << "gas aperture " << capillaryGasDiameter << " mm" << G4endl;
87 throw BDSException(__METHOD_NAME__, "Error in gas capillary");
88 }
90 {
91 G4cerr << __METHOD_NAME__ << "element need a non null aperture!" << G4endl;
92 throw BDSException(__METHOD_NAME__, "Error in gas capillary");
93 }
94}
95
97{
99 {return capillaryOuterMaterial->GetName();}
100 else
101 {return "none";}
102}
103
105{
107 {return capillaryGasMaterial->GetName();}
108 else
109 {return "none";}
110}
111
113{
115 {return electrodeMaterial->GetName();}
116 else
117 {return "none";}
118}
119
120
122{
124 BDSBeamPipe* pipe = factory->CreateBeamPipe(name + "_beampipe",
127 RegisterDaughter(pipe);
128
129 // make the beam pipe container, this object's container
130 containerLogicalVolume = pipe->GetContainerLogicalVolume();
131 containerSolid = pipe->GetContainerSolid();
132
133 // register vacuum volume (for biasing)
135
136 // update extents
137 InheritExtents(pipe);
138
139 // update faces
142}
143
144void BDSGasCapillary::BuildUncutSolid() {
145 if (circularOuter)
146 {
147 capillaryOuterUncutSolid = new G4Tubs(name + "_capillaryOuterUncut_solid",
148 0, horizontalWidth * 0.5 - lengthSafety, // rMin rMax
149 chordLength * 0.5 - lengthSafety, // length
150 0, CLHEP::twopi); // phiMin phiMax
151 }
152 else {
153 capillaryOuterUncutSolid = new G4Box(name + "_capillaryOuterUncut_solid",
154 horizontalWidth * 0.5 - lengthSafety, // pX
155 horizontalWidth * 0.5 - lengthSafety, // pY
156 chordLength * 0.5 - lengthSafety); // pZ
157 }
158
159 electrodeUncutSolid = new G4Box(name + "_electrodeUncut_solid",
160 horizontalWidth * 0.5 - lengthSafety, // pX
161 horizontalWidth * 0.5 - lengthSafety, // pY
162 electrodeThickness * 0.5 - lengthSafety); // pZ
163
164 capillaryGasSolid = new G4Tubs(name + "_capillaryGas_solid",
165 0, capillaryGasDiameter * 0.5 - lengthSafety, // rMin rMax
166 chordLength * 0.5 - lengthSafety, // length
167 0, CLHEP::twopi); // phiMin phiMax
168
172}
173
174void BDSGasCapillary::BuildHolesSolid() {
175
176 electrodeHoleSolid = new G4Box(name + "_electrodeHole_solid",
177 horizontalWidth * 0.5 + lengthSafetyLarge * 5, // pZ
178 horizontalWidth * 0.5 + lengthSafetyLarge * 5, // pZ
179 electrodeThickness * 0.5 + lengthSafetyLarge * 5); // pZ
180
181 capillaryHoleSolid = new G4Tubs(name + "_capillaryHole_solid",
182 0, capillaryGasDiameter * 0.5 + lengthSafetyLarge * 5, // rMin rMax
183 chordLength * 0.5 + lengthSafetyLarge * 5, // length
184 0, CLHEP::twopi); // phiMin phiMax
185
188}
189
190void BDSGasCapillary::BuildCutSolid()
191{
192 G4ThreeVector TransFront(0, 0, -chordLength * 0.5 + electrodeThickness * 0.5);
193 G4ThreeVector TransBack(0, 0, chordLength * 0.5 - electrodeThickness * 0.5);
194 G4RotationMatrix* Rot = new G4RotationMatrix;
195
196 G4VSolid* capillaryOuterCut1Solid = new G4SubtractionSolid(name + "_capillaryOuterCut1_solid",
198
199 G4VSolid* capillaryOuterCut2Solid = new G4SubtractionSolid(name + "_capillaryOuterCut2_solid",
200 capillaryOuterCut1Solid, electrodeHoleSolid,
201 Rot, TransFront);
202
203 capillaryOuterSolid = new G4SubtractionSolid(name + "_capillaryOuterSolid_solid",
204 capillaryOuterCut2Solid, electrodeHoleSolid,
205 Rot, TransBack);
206
207 electrodeSolid = new G4IntersectionSolid(name + "_electrode_solid",
209
212}
213
215{
217 BDSAcceleratorComponent::Build(); // calls BuildContainer and sets limits and vis for container
218
219 G4ThreeVector TransFront(0, 0, -chordLength * 0.5 + electrodeThickness * 0.5);
220 G4ThreeVector TransBack(0, 0, chordLength * 0.5 - electrodeThickness * 0.5);
221 G4RotationMatrix* Rotate= new G4RotationMatrix;
222
223 BuildUncutSolid();
224 BuildHolesSolid();
225 BuildCutSolid();
226
227 G4LogicalVolume* capillaryOuterLV = new G4LogicalVolume(capillaryOuterSolid, capillaryOuterMaterial,
228 name + "_capillaryOuter_lv");
229 G4LogicalVolume* capillaryGasLV = new G4LogicalVolume(capillaryGasSolid, capillaryGasMaterial,
230 name + "_capillaryGas_lv");
231 G4LogicalVolume* electrodeLV = new G4LogicalVolume(electrodeSolid, electrodeMaterial,
232 name + "_electrode_lv");
233
234 // color, user limits, register
235 SetupLV(capillaryOuterLV, BDSColours::Instance()->GetColour("capillaryouter"));
236 SetupLV(capillaryGasLV, BDSColours::Instance()->GetColour("capillarygas"));
237 SetupLV(electrodeLV, BDSColours::Instance()->GetColour("electrode"));
238
239 G4LogicalVolume* vac = *(GetAcceleratorVacuumLogicalVolumes().begin()); // take the first one
240
241 G4PVPlacement* capillaryOuterPV = new G4PVPlacement(Rotate, // rotation
242 G4ThreeVector(0, 0, 0), // position
243 capillaryOuterLV, // its logical volume
244 name + "_capillaryOuter_pv", // its name
245 vac, // its mother volume
246 false, // no boolean operation
247 0, // copy number
249
250 G4PVPlacement* capillaryGasPV = new G4PVPlacement(Rotate, // rotation
251 G4ThreeVector(0,0,0), // position
252 capillaryGasLV, // its logical volume
253 name + "_capillaryGas_pv", // its name
254 vac, // its mother volume
255 false, // no boolean operation
256 0, // copy number
258
259 G4PVPlacement* electrodeFrontPV = new G4PVPlacement(Rotate, // rotation
260 TransFront, // position
261 electrodeLV, // its logical volume
262 name + "_electrodeFront_pv", // its name
263 vac, // its mother volume
264 false, // no boolean operation
265 0, // copy number
267
268 G4PVPlacement* electrodeBackPV = new G4PVPlacement(Rotate, // rotation
269 TransBack, // position
270 electrodeLV, // its logical volume
271 name + "_electrodeBack_pv", // its name
272 vac, // its mother volume
273 false, // no boolean operation
274 0, // copy number
276
277 RegisterPhysicalVolume(capillaryOuterPV);
278 RegisterPhysicalVolume(capillaryGasPV);
279 RegisterPhysicalVolume(electrodeFrontPV);
280 RegisterPhysicalVolume(electrodeBackPV);
281}
282
283void BDSGasCapillary::SetupLV(G4LogicalVolume* lv, G4Colour* colour)
284{
285 // color attribute
286 G4VisAttributes* gasVisAttr = new G4VisAttributes(*colour);
287 lv->SetVisAttributes(gasVisAttr);
288 RegisterVisAttributes(gasVisAttr);
289
290 // user limits - provided by BDSAcceleratorComponent
291 lv->SetUserLimits(userLimits);
292
293 // register with base class (BDSGeometryComponent)
295}
Abstract class that represents a component of an accelerator.
G4UserLimits * userLimits
Cache of user limits.
void SetAcceleratorVacuumLogicalVolume(G4LogicalVolume *accVacLVIn)
const G4String name
Const protected member variable that may not be changed by derived classes.
virtual void SetOutputFaceNormal(const G4ThreeVector &output)
Allow updating of face normals. Virtual so derived class may apply it to daughters.
static G4double lengthSafety
Useful variable often used in construction.
static G4bool checkOverlaps
Useful variable often used in construction.
virtual std::set< G4LogicalVolume * > GetAcceleratorVacuumLogicalVolumes() const
Access the 'vacuum' volume(s) in this component if any. Default is empty set.
virtual void SetInputFaceNormal(const G4ThreeVector &input)
Allow updating of face normals. Virtual so derived class may apply it to daughters.
G4double chordLength
Protected member variable that can be modified by derived classes.
BDSBeamPipeInfo * beamPipeInfo
Optional beam pipe recipe that is written out to the survey if it exists.
The main interface for using the beam pipe factories.
static BDSBeamPipeFactory * Instance()
Singleton accessor.
Holder class for all information required to describe a beam pipe model.
A holder class for a piece of beam pipe geometry.
G4LogicalVolume * GetVacuumLogicalVolume() const
Access the vacuum volume to set fields and limits.
G4ThreeVector InputFaceNormal() const
Accessor.
G4ThreeVector OutputFaceNormal() const
Accessor.
static BDSColours * Instance()
singleton pattern
Definition BDSColours.cc:33
General exception with possible name of object and message.
G4double horizontalWidth
Horizontal width.
G4Material * capillaryOuterMaterial
Materials:
virtual G4String ElectrodeMaterial() const
Accessor.
G4VSolid * electrodeHoleSolid
Solids:
G4Material * electrodeMaterial
Materials:
BDSGasCapillary()=delete
Private default constructor to force the use of the supplied one.
G4Material * capillaryGasMaterial
Materials:
G4VSolid * capillaryGasSolid
Solids:
virtual void CheckParameters()
G4bool circularOuter
Aperture type of the outer wall.
virtual void BuildContainerLogicalVolume()
G4VSolid * capillaryOuterSolid
Solids:
virtual G4String CapillaryOuterMaterial() const
Accessor.
G4VSolid * electrodeSolid
Solids:
virtual void Build()
G4VSolid * electrodeUncutSolid
Solids:
G4double capillaryGasDiameter
Aperture diameter of the gas.
G4VSolid * capillaryOuterUncutSolid
Solids:
virtual G4String CapillaryGasMaterial() const
Accessor.
G4VSolid * capillaryHoleSolid
Solids:
G4double electrodeThickness
Thickness of the two electrodes.
G4LogicalVolume * GetContainerLogicalVolume() const
Accessor - see member for more info.
void InheritExtents(BDSGeometryComponent const *const anotherComponent)
Update the extents of this object with those of another object.
void RegisterDaughter(BDSGeometryComponent *anotherComponent)
void RegisterLogicalVolume(G4LogicalVolume *logicalVolume)
void RegisterPhysicalVolume(G4VPhysicalVolume *physicalVolume)
G4VSolid * GetContainerSolid() const
Accessor - see member for more info.
void RegisterVisAttributes(G4VisAttributes *visAttribute)
void RegisterSolid(G4VSolid *solid)
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())