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) 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 "BDSAcceleratorModel.hh"
19#include "BDSBeamPipe.hh"
20#include "BDSBeamPipeFactory.hh"
21#include "BDSBeamPipeInfo.hh"
22#include "BDSGasCapillary.hh"
23#include "BDSColours.hh"
24#include "BDSDebug.hh"
25#include "BDSException.hh"
26#include "BDSGlobalConstants.hh"
27#include "BDSMaterials.hh"
28#include "BDSSDType.hh"
29#include "BDSUtilities.hh"
30#include "BDSWarning.hh"
31
32#include "globals.hh"
33#include "G4Box.hh"
34#include "G4LogicalVolume.hh"
35#include "G4PVPlacement.hh"
36#include "G4SubtractionSolid.hh"
37#include "G4IntersectionSolid.hh"
38#include "G4Tubs.hh"
39#include "G4UserLimits.hh"
40#include "G4VisAttributes.hh"
41
42#include <map>
43
44BDSGasCapillary::BDSGasCapillary(const G4String& nameIn,
45 G4double lengthIn,
46 BDSBeamPipeInfo* beamPipeInfoIn,
47 G4double horizontalWidthIn,
48 G4Material* capillaryOuterMaterialIn,
49 G4Material* capillaryGasMaterialIn,
50 G4Material* electrodesMaterialIn,
51 G4double capillaryGasDiameterIn,
52 G4double electrodeThicknessIn,
53 G4bool circularOuterIn):
54 BDSAcceleratorComponent(nameIn, lengthIn, 0, "gascap", beamPipeInfoIn),
55 horizontalWidth(horizontalWidthIn),
56 capillaryGasDiameter(capillaryGasDiameterIn),
57 electrodeThickness(electrodeThicknessIn),
58 circularOuter(circularOuterIn),
59
60 capillaryOuterSolid(nullptr),
61 capillaryGasSolid(nullptr),
62 electrodeSolid(nullptr),
63
64 capillaryOuterUncutSolid(nullptr),
65 electrodeUncutSolid(nullptr),
66
67 capillaryHoleSolid(nullptr),
68 electrodeHoleSolid(nullptr),
69
70 capillaryOuterMaterial(capillaryOuterMaterialIn),
71 capillaryGasMaterial(capillaryGasMaterialIn),
72 electrodeMaterial(electrodesMaterialIn)
73{;}
74
75BDSGasCapillary::~BDSGasCapillary()
76{;}
77
79{
81 {
82 G4cerr << __METHOD_NAME__ << "aperture bigger than width!" << G4endl;
83 G4cerr << "Full horizontal width is " << horizontalWidth << " mm for component named: \""
84 << name << "\"" << G4endl;
85 G4cerr << "gas aperture " << capillaryGasDiameter << " mm" << G4endl;
86 throw BDSException(__METHOD_NAME__, "Error in gas capillary");
87 }
89 {
90 G4cerr << __METHOD_NAME__ << "element need a non null aperture!" << G4endl;
91 throw BDSException(__METHOD_NAME__, "Error in gas capillary");
92 }
93}
94
96{
98 {return capillaryOuterMaterial->GetName();}
99 else
100 {return "none";}
101}
102
104{
106 {return capillaryGasMaterial->GetName();}
107 else
108 {return "none";}
109}
110
112{
114 {return electrodeMaterial->GetName();}
115 else
116 {return "none";}
117}
118
119
121{
123 BDSBeamPipe* pipe = factory->CreateBeamPipe(name + "_beampipe",
126 RegisterDaughter(pipe);
127
128 // make the beam pipe container, this object's container
129 containerLogicalVolume = pipe->GetContainerLogicalVolume();
130 containerSolid = pipe->GetContainerSolid();
131
132 // register vacuum volume (for biasing)
134
135 // update extents
136 InheritExtents(pipe);
137
138 // update faces
141}
142
143void BDSGasCapillary::BuildUncutSolid() {
144 if (circularOuter)
145 {
146 capillaryOuterUncutSolid = new G4Tubs(name + "_capillaryOuterUncut_solid",
147 0, horizontalWidth * 0.5 - lengthSafety, // rMin rMax
148 chordLength * 0.5 - lengthSafety, // length
149 0, CLHEP::twopi); // phiMin phiMax
150 }
151 else {
152 capillaryOuterUncutSolid = new G4Box(name + "_capillaryOuterUncut_solid",
153 horizontalWidth * 0.5 - lengthSafety, // pX
154 horizontalWidth * 0.5 - lengthSafety, // pY
155 chordLength * 0.5 - lengthSafety); // pZ
156 }
157
158 electrodeUncutSolid = new G4Box(name + "_electrodeUncut_solid",
159 horizontalWidth * 0.5 - lengthSafety, // pX
160 horizontalWidth * 0.5 - lengthSafety, // pY
161 electrodeThickness * 0.5 - lengthSafety); // pZ
162
163 capillaryGasSolid = new G4Tubs(name + "_capillaryGas_solid",
164 0, capillaryGasDiameter * 0.5 - lengthSafety, // rMin rMax
165 chordLength * 0.5 - lengthSafety, // length
166 0, CLHEP::twopi); // phiMin phiMax
167
171}
172
173void BDSGasCapillary::BuildHolesSolid() {
174
175 electrodeHoleSolid = new G4Box(name + "_electrodeHole_solid",
176 horizontalWidth * 0.5 + lengthSafetyLarge * 5, // pZ
177 horizontalWidth * 0.5 + lengthSafetyLarge * 5, // pZ
178 electrodeThickness * 0.5 + lengthSafetyLarge * 5); // pZ
179
180 capillaryHoleSolid = new G4Tubs(name + "_capillaryHole_solid",
181 0, capillaryGasDiameter * 0.5 + lengthSafetyLarge * 5, // rMin rMax
182 chordLength * 0.5 + lengthSafetyLarge * 5, // length
183 0, CLHEP::twopi); // phiMin phiMax
184
187}
188
189void BDSGasCapillary::BuildCutSolid()
190{
191 G4ThreeVector TransFront(0, 0, -chordLength * 0.5 + electrodeThickness * 0.5);
192 G4ThreeVector TransBack(0, 0, chordLength * 0.5 - electrodeThickness * 0.5);
193 G4RotationMatrix* Rot = new G4RotationMatrix;
194
195 G4VSolid* capillaryOuterCut1Solid = new G4SubtractionSolid(name + "_capillaryOuterCut1_solid",
197
198 G4VSolid* capillaryOuterCut2Solid = new G4SubtractionSolid(name + "_capillaryOuterCut2_solid",
199 capillaryOuterCut1Solid, electrodeHoleSolid,
200 Rot, TransFront);
201
202 capillaryOuterSolid = new G4SubtractionSolid(name + "_capillaryOuterSolid_solid",
203 capillaryOuterCut2Solid, electrodeHoleSolid,
204 Rot, TransBack);
205
206 electrodeSolid = new G4IntersectionSolid(name + "_electrode_solid",
208
211}
212
214{
216 BDSAcceleratorComponent::Build(); // calls BuildContainer and sets limits and vis for container
217
218 G4ThreeVector TransFront(0, 0, -chordLength * 0.5 + electrodeThickness * 0.5);
219 G4ThreeVector TransBack(0, 0, chordLength * 0.5 - electrodeThickness * 0.5);
220 G4RotationMatrix* Rotate= new G4RotationMatrix;
221
222 BuildUncutSolid();
223 BuildHolesSolid();
224 BuildCutSolid();
225
226 G4LogicalVolume* capillaryOuterLV = new G4LogicalVolume(capillaryOuterSolid, capillaryOuterMaterial,
227 name + "_capillaryOuter_lv");
228 G4LogicalVolume* capillaryGasLV = new G4LogicalVolume(capillaryGasSolid, capillaryGasMaterial,
229 name + "_capillaryGas_lv");
230 G4LogicalVolume* electrodeLV = new G4LogicalVolume(electrodeSolid, electrodeMaterial,
231 name + "_electrode_lv");
232
233 // color, user limits, register
234 SetupLV(capillaryOuterLV, BDSColours::Instance()->GetColour("capillaryouter"));
235 SetupLV(capillaryGasLV, BDSColours::Instance()->GetColour("capillarygas"));
236 SetupLV(electrodeLV, BDSColours::Instance()->GetColour("electrode"));
237
238 G4LogicalVolume* vac = *(GetAcceleratorVacuumLogicalVolumes().begin()); // take the first one
239
240 G4PVPlacement* capillaryOuterPV = new G4PVPlacement(Rotate, // rotation
241 G4ThreeVector(0, 0, 0), // position
242 capillaryOuterLV, // its logical volume
243 name + "_capillaryOuter_pv", // its name
244 vac, // its mother volume
245 false, // no boolean operation
246 0, // copy number
248
249 G4PVPlacement* capillaryGasPV = new G4PVPlacement(Rotate, // rotation
250 G4ThreeVector(0,0,0), // position
251 capillaryGasLV, // its logical volume
252 name + "_capillaryGas_pv", // its name
253 vac, // its mother volume
254 false, // no boolean operation
255 0, // copy number
257
258 G4PVPlacement* electrodeFrontPV = new G4PVPlacement(Rotate, // rotation
259 TransFront, // position
260 electrodeLV, // its logical volume
261 name + "_electrodeFront_pv", // its name
262 vac, // its mother volume
263 false, // no boolean operation
264 0, // copy number
266
267 G4PVPlacement* electrodeBackPV = new G4PVPlacement(Rotate, // rotation
268 TransBack, // position
269 electrodeLV, // its logical volume
270 name + "_electrodeBack_pv", // its name
271 vac, // its mother volume
272 false, // no boolean operation
273 0, // copy number
275
276 RegisterPhysicalVolume(capillaryOuterPV);
277 RegisterPhysicalVolume(capillaryGasPV);
278 RegisterPhysicalVolume(electrodeFrontPV);
279 RegisterPhysicalVolume(electrodeBackPV);
280}
281
282void BDSGasCapillary::SetupLV(G4LogicalVolume* lv, G4Colour* colour)
283{
284 // color attribute
285 G4VisAttributes* gasVisAttr = new G4VisAttributes(*colour);
286 lv->SetVisAttributes(gasVisAttr);
287 RegisterVisAttributes(gasVisAttr);
288
289 // user limits - provided by BDSAcceleratorComponent
290 lv->SetUserLimits(userLimits);
291
292 // register with base class (BDSGeometryComponent)
294}
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:32
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())