Garfield++ 3.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
parallel_plate.cc
Go to the documentation of this file.
1/**
2 * parallel_plate.cc
3 * General program flow based on example code from the Garfield++ website.
4 *
5 * Demonstrates the importing of a parallel-plate capacitor field map
6 * from Gmsh/Elmer into Garfield++.
7 *
8*/
9#include <iostream>
10#include <cmath>
11#include <cstring>
12#include <fstream>
13#include <TCanvas.h>
14#include <TApplication.h>
15
18#include "Garfield/Sensor.hh"
19#include "Garfield/ViewField.hh"
20#include "Garfield/Plotting.hh"
22
23using namespace Garfield;
24
25int main(int argc, char * argv[]) {
26
27 TApplication app("app", &argc, argv);
28
29 // Set relevant geometric parameters.
30 const double ext_x = 1.0; // external box x-width
31 const double ext_y = 1.0; // external box y-width
32 const double ext_z = 1.0; // external box z-width
33
34 // Create a main canvas.
35 TCanvas * c1 = new TCanvas();
36
37 // Define the medium.
38 MediumMagboltz* gas = new MediumMagboltz();
39 gas->SetTemperature(293.15); // Set the temperature [K]
40 gas->SetPressure(740.); // Set the pressure [Torr]
41 gas->EnableDrift(); // Allow for drifting in this medium
42 gas->SetComposition("ar", 70., "co2", 30.); // Specify the gas mixture (Ar/CO2 70:30)
43
44 // Import an Elmer-created parallel plate field map.
45 ComponentElmer * elm = new ComponentElmer("parallel_plate/mesh.header","parallel_plate/mesh.elements","parallel_plate/mesh.nodes",
46 "parallel_plate/dielectrics.dat","parallel_plate/parallel_plate.result","cm");
47 elm->SetMedium(0,gas);
48
49 // Set up a sensor object.
50 Sensor* sensor = new Sensor();
51 sensor->AddComponent(elm);
52 sensor->SetArea(-1*ext_x,-1*ext_y,-1*ext_z,ext_x,ext_y,ext_z);
53
54 // Set up the object for field visualization.
55 ViewField * vf = new ViewField();
56 vf->SetSensor(sensor);
57 vf->SetCanvas(c1);
58 vf->SetArea(-1*ext_x,-1*ext_y,ext_x,ext_y);
59 vf->SetNumberOfContours(20);
60 vf->SetNumberOfSamples2d(30,30);
61 vf->SetPlane(0,-1,0,0,0,0);
62
63 // Set up the object for FE mesh visualization.
64 ViewFEMesh * vFE = new ViewFEMesh();
65 vFE->SetCanvas(c1);
66 vFE->SetComponent(elm);
67 vFE->SetPlane(0,0,-1,0,0,0);
68 vFE->SetFillMesh(true);
69 vFE->SetColor(1,kBlue);
70
71 // Create plots.
72 vFE->SetArea(-1*ext_x,-1*ext_z,-1*ext_z,ext_x,ext_z,ext_z);
73 vf->PlotContour("v");
74 //vFE->Plot();
75
76 app.Run(kTRUE);
77
78 return 0;
79}
Component for importing field maps computed by Elmer.
void SetMedium(const unsigned int imat, Medium *medium)
Associate a field map material with a Medium class.
bool SetComposition(const std::string &gas1, const double f1=1., const std::string &gas2="", const double f2=0., const std::string &gas3="", const double f3=0., const std::string &gas4="", const double f4=0., const std::string &gas5="", const double f5=0., const std::string &gas6="", const double f6=0.)
Set the gas mixture.
Definition: MediumGas.cc:134
void SetTemperature(const double t)
Set the temperature [K].
Definition: Medium.cc:71
virtual void EnableDrift(const bool on=true)
Switch electron/ion/hole on/off.
Definition: Medium.hh:67
void SetPressure(const double p)
Definition: Medium.cc:81
bool SetArea()
Set the user area to the default.
Definition: Sensor.cc:189
void AddComponent(ComponentBase *comp)
Add a component.
Definition: Sensor.cc:301
void SetCanvas(TCanvas *c)
Set the canvas to be painted on.
Definition: ViewBase.cc:20
Draw the mesh of a field-map component.
Definition: ViewFEMesh.hh:26
void SetComponent(ComponentFieldMap *comp)
Set the component from which to retrieve the mesh and field.
Definition: ViewFEMesh.cc:40
void SetPlane(double fx, double fy, double fz, double x0, double y0, double z0)
Set the projection plane.
Definition: ViewFEMesh.cc:120
void SetArea()
Set area to be plotted to the default.
Definition: ViewFEMesh.cc:67
void SetColor(int matID, int colorID)
Definition: ViewFEMesh.hh:70
void SetFillMesh(const bool f)
Element fill switch; 2D only, set false for wireframe mesh.
Definition: ViewFEMesh.hh:62
Visualize the potential or electric field of a component or sensor.
Definition: ViewField.hh:16
void SetPlane(const double fx, const double fy, const double fz, const double x0, const double y0, const double z0)
Definition: ViewField.cc:612
void SetNumberOfSamples2d(const unsigned int nx, const unsigned int ny)
Set the number of points used for drawing 2D functions.
Definition: ViewField.cc:134
void PlotContour(const std::string &option="v")
Definition: ViewField.cc:155
void SetNumberOfContours(const unsigned int n)
Set the number of contour levels (at most 50).
Definition: ViewField.cc:112
void SetArea(const double xmin, const double ymin, const double xmax, const double ymax)
Set the viewing area (in local coordinates of the current viewing plane).
Definition: ViewField.cc:78
void SetSensor(Sensor *s)
Set the sensor from which to retrieve the field.
Definition: ViewField.cc:58
int main(int argc, char *argv[])