Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
NeBemInterface.cpp
Go to the documentation of this file.
1#include <stdio.h>
2
3#include "neBEMInterface.h"
4#include "NR.h"
5#include "Vector.h"
6#include "neBEM.h"
7
9
10namespace neBEM {
11
12/// Assign default values to some of the important global variables.
14
15 neBEMState = 0;
16
17 NbVolumes = 2;
18 VolMax = 2;
19
20 NbPrimitives = 1;
21 MaxNbVertices = 4;
22
23 NbSurfs = 1;
24 NbWires = 0;
25
28 ElementLengthRqstd = 100.0e-6;
29
30 NewModel = 1;
31 NewMesh = 1;
32 NewBC = 1;
33 NewPP = 1;
34 ModelCntr = 1;
35 MeshCntr = 1;
36 BCCntr = 1;
37 PPCntr = 1;
38
39 DebugLevel = 0;
40
41 LengthScale = 1.0;
42
43 TimeStep = 1;
44
45 strcpy(DeviceOutDir, "Outputs");
46
47 OptDeviceFile = 0;
48 strcpy(DeviceInputFile, "");
49
53
54 OptGnuplot = 1;
59
60 // Same directory can be used over and over again - BEWARE!
61 OptReuseDir = 1;
62
63 // Matrix inversion procedure => 0: LU, 1: SVD, 2:GSL
64 OptInvMatProc = 0;
65
75
77
78 return 0;
79} // neBEMSetDefaults ends
80
81int ReadInitFile(char filename[]) {
82 FILE* finit = fopen(filename, "r");
83 if (finit == NULL) {
84 neBEMMessage("ReadInitFile - fail to open init file");
85 return -1;
86 }
87
88 fscanf(finit, "MinNbElementsOnLength: %d\n", &MinNbElementsOnLength);
89 fscanf(finit, "MaxNbElementsOnLength: %d\n", &MaxNbElementsOnLength);
90 fscanf(finit, "ElementLengthRqstd: %le\n", &ElementLengthRqstd);
91 fscanf(finit, "LengthScale: %le\n", &LengthScale);
92
93 fscanf(finit, "DebugLevel: %d\n", &DebugLevel);
94
95 fscanf(finit, "NewModel: %d\n", &NewModel);
96 fscanf(finit, "NewMesh: %d\n", &NewMesh);
97 fscanf(finit, "NewBC: %d\n", &NewBC);
98 fscanf(finit, "NewPP: %d\n", &NewPP);
99 fscanf(finit, "ModelCntr: %d\n", &ModelCntr);
100 fscanf(finit, "MeshCntr: %d\n", &MeshCntr);
101 fscanf(finit, "BCCntr: %d\n", &BCCntr);
102 fscanf(finit, "PPCntr: %d\n", &PPCntr);
103
104 fscanf(finit, "DeviceOutDir: %255s\n", DeviceOutDir);
105
106 fscanf(finit, "OptDeviceFile: %d\n", &OptDeviceFile);
107 fscanf(finit, "DeviceInputFile: %255s\n", DeviceInputFile);
108
109 fscanf(finit, "OptPrintPrimaryDetails: %d\n", &OptPrintPrimaryDetails);
110 fscanf(finit, "OptPrintVolumeDetails: %d\n", &OptPrintVolumeDetails);
111 fscanf(finit, "OptPrintVertexAndNormal: %d\n", &OptPrintVertexAndNormal);
112
113 fscanf(finit, "OptGnuplot: %d\n", &OptGnuplot);
114 fscanf(finit, "OptGnuplotPrimitives: %d\n", &OptGnuplotPrimitives);
115 fscanf(finit, "OptGnuplotElements: %d\n", &OptGnuplotElements);
116
117 fscanf(finit, "OptPrimitiveFiles: %d\n", &OptPrimitiveFiles);
118 fscanf(finit, "OptElementFiles: %d\n", &OptElementFiles);
119
120 fscanf(finit, "OptReuseDir: %d\n", &OptReuseDir);
121
122 fscanf(finit, "OptInvMatProc: %d\n", &OptInvMatProc);
123
124 fscanf(finit, "OptValidateSolution: %d\n", &OptValidateSolution);
125 fscanf(finit, "OptForceValidation: %d\n", &OptForceValidation);
126 fscanf(finit, "OptStorePrimitives: %d\n", &OptStorePrimitives);
127 fscanf(finit, "OptStoreElements: %d\n", &OptStoreElements);
128 fscanf(finit, "OptStoreInflMatrix: %d\n", &OptStoreInflMatrix);
129 fscanf(finit, "OptStoreInvMatrix: %d\n", &OptStoreInvMatrix);
130 fscanf(finit, "OptFormattedFile: %d\n", &OptFormattedFile);
131 fscanf(finit, "OptUnformattedFile: %d\n", &OptUnformattedFile);
132 fscanf(finit, "OptRepeatLHMatrix: %d\n", &OptRepeatLHMatrix);
133
134 fscanf(finit, "OptSystemChargeZero: %d\n", &OptSystemChargeZero);
135
136 fscanf(finit, "PrimAfter: %d\n", &PrimAfter);
137
138 fclose(finit);
139
140 fprintf(stdout, "MinNbElementsOnLength: %d\n", MinNbElementsOnLength);
141 fprintf(stdout, "MaxNbElementsOnLength: %d\n", MaxNbElementsOnLength);
142 fprintf(stdout, "ElementLengthRqstd: %le\n", ElementLengthRqstd);
143 fprintf(stdout, "LengthScale: %le\n", LengthScale);
144
145 fprintf(stdout, "NewModel: %d\n", NewModel);
146 fprintf(stdout, "NewMesh: %d\n", NewMesh);
147 fprintf(stdout, "NewBC: %d\n", NewBC);
148 fprintf(stdout, "NewPP: %d\n", NewPP);
149 fprintf(stdout, "ModelCntr: %d\n", ModelCntr);
150 fprintf(stdout, "MeshCntr: %d\n", MeshCntr);
151 fprintf(stdout, "BCCntr: %d\n", BCCntr);
152 fprintf(stdout, "PPCntr: %d\n", PPCntr);
153
154 fprintf(stdout, "DeviceOutDir: %s\n", DeviceOutDir);
155
156 fprintf(stdout, "OptDeviceFile: %d\n", OptDeviceFile);
157 fprintf(stdout, "DeviceInputFile: %s\n", DeviceInputFile);
158
159 fprintf(stdout, "OptPrintPrimaryDetails: %d\n", OptPrintPrimaryDetails);
160 fprintf(stdout, "OptPrintVolumeDetails: %d\n", OptPrintVolumeDetails);
161 fprintf(stdout, "OptPrintVertexAndNormal: %d\n", OptPrintVertexAndNormal);
162
163 fprintf(stdout, "OptGnuplot: %d\n", OptGnuplot);
164 fprintf(stdout, "OptGnuplotPrimitives: %d\n", OptGnuplotPrimitives);
165 fprintf(stdout, "OptGnuplotElements: %d\n", OptGnuplotElements);
166
167 fprintf(stdout, "OptPrimitiveFiles: %d\n", OptPrimitiveFiles);
168 fprintf(stdout, "OptElementFiles: %d\n", OptElementFiles);
169
170 fprintf(stdout, "OptReuseDir: %d\n", OptReuseDir);
171
172 fprintf(stdout, "OptValidateSolution: %d\n", OptValidateSolution);
173 fprintf(stdout, "OptStorePrimitives: %d\n", OptStorePrimitives);
174 fprintf(stdout, "OptStoreElements: %d\n", OptStoreElements);
175 fprintf(stdout, "OptStoreInflMatrix: %d\n", OptStoreInflMatrix);
176 fprintf(stdout, "OptStoreInvMatrix: %d\n", OptStoreInvMatrix);
177 fprintf(stdout, "OptFormattedFile: %d\n", OptFormattedFile);
178 fprintf(stdout, "OptUnformattedFile: %d\n", OptUnformattedFile);
179 fprintf(stdout, "OptRepeatLHMatrix: %d\n", OptRepeatLHMatrix);
180
181 fprintf(stdout, "OptSystemChargeZero: %d\n", OptSystemChargeZero);
182
183 fprintf(stdout, "PrimAfter: %d\n", PrimAfter);
184
185 return 0;
186}
187
188/// Do-nothing function (no file inputs).
189int neBEMGetInputsFromFiles(void) { return 0; }
190
191/// Return the number of primitives.
193 if (!Garfield::gComponentNeBem3d) return 0;
195}
196
197/// Return one primitive at a time.
198int neBEMGetPrimitive(int prim, int* nvertex, double xvert[], double yvert[],
199 double zvert[], double* xnorm, double* ynorm,
200 double* znorm, int* volref1, int* volref2) {
201
202 if (!Garfield::gComponentNeBem3d) return -1;
203 if (prim < 1) return -1;
204 double a = 0., b = 0., c = 0.;
205 std::vector<double> xv;
206 std::vector<double> yv;
207 std::vector<double> zv;
208 int vol1 = 0, vol2 = 0;
209 if (!Garfield::gComponentNeBem3d->GetPrimitive(prim - 1, a, b, c,
210 xv, yv, zv, vol1, vol2)) {
211 return -1;
212 }
213 const size_t nv = xv.size();
214 *nvertex = nv;
215 for (size_t i = 0; i < nv; ++i) {
216 // Convert from cm to m.
217 xvert[i] = 0.01 * xv[i];
218 yvert[i] = 0.01 * yv[i];
219 zvert[i] = 0.01 * zv[i];
220 }
221 *xnorm = a;
222 *ynorm = b;
223 *znorm = c;
224 if (nv == 2) *xnorm *= 0.01;
225 *volref1 = vol1;
226 *volref2 = vol2;
227 return 0;
228}
229
230/// Return information about periodicities.
231/// ix: 0 = no periodicity in x,
232/// 1 = simple periodicity of length sx,
233/// 2 = mirror periodicity of length sx,
234/// 3 = axial periodicity around x with sector angle sx,
235/// 4 = rotational symmetry around x
236/// jx: number of periodic copies internally in neBEM
237int neBEMGetPeriodicities(int /*prim*/, int* ix, int* jx, double* sx, int* iy,
238 int* jy, double* sy, int* iz, int* jz, double* sz) {
239 if (!Garfield::gComponentNeBem3d) return -1;
240 *ix = 0;
241 *iy = 0;
242 *iz = 0;
243 bool perx = false, pery = false, perz = false;
244 Garfield::gComponentNeBem3d->IsPeriodic(perx, pery, perz);
245 if (perx) *ix = 1;
246 if (pery) *iy = 1;
247 if (perz) *iz = 1;
249 if (perx) *ix = 2;
250 if (pery) *iy = 2;
251 if (perz) *iz = 2;
252 *sx = 0.;
253 *sy = 0.;
254 *sz = 0.;
258 // Convert from cm to m.
259 *sx *= 0.01;
260 *sy *= 0.01;
261 *sz *= 0.01;
262 *jx = 0;
263 *jy = 0;
264 *jz = 0;
265 if (*ix > 0 || *iy > 0 || *iz > 0) {
266 unsigned int nx = 0, ny = 0, nz = 0;
268 *jx = nx;
269 *jy = ny;
270 *jz = nz;
271 }
272 return 0;
273}
274
275/// Return information about mirror periodicity.
276/// ix: 0 = no mirror in x,
277/// 1 = producing charge density of opposite sign (infinite cond plane)
278/// 2 = producing charge density of same sign
279/// jx: not used at present
280/// sx: x distance of the mirror from origin
281int neBEMGetMirror(int /*prim*/, int* ix, int* jx, double* sx, int* iy, int* jy,
282 double* sy, int* iz, int* jz, double* sz) {
283
284 if (!Garfield::gComponentNeBem3d) return -1;
285 *jx = *jy = *jz = 0;
286 bool perx = false, pery = false, perz = false;
288 // Only one reflection is allowed at present.
289 *ix = *iy = *iz = 0;
290 if (perx) {
291 *ix = 2;
292 } else if (pery) {
293 *iy = 2;
294 } else if (perz) {
295 *iz = 2;
296 }
297 // Mirror assumed to be passing through the origin.
298 *sx = *sy = *sz = 0.;
299 return 0;
300}
301
302/// Return infinite (bounding) conductors if any.
303/// ixmin=0: lower x-plane does not exist
304/// ixmin=1: lower x-plane does exist
305/// cxmin: coordinate of lower x-plane
306/// vxmin: potential of lower x-plane
307/// Similar for ixmax, iymin, iymax, izmin, izmax
308int neBEMGetBoundingPlanes(int* ixmin, double* cxmin, double* vxmin, int* ixmax,
309 double* cxmax, double* vxmax, int* iymin,
310 double* cymin, double* vymin, int* iymax,
311 double* cymax, double* vymax, int* izmin,
312 double* czmin, double* vzmin, int* izmax,
313 double* czmax, double* vzmax) {
314 if (!Garfield::gComponentNeBem3d) return -1;
315 *ixmin = *ixmax = 0;
316 *vxmin = *vxmax = 0.;
317 *cxmin = *cxmax = 0.;
318 const unsigned int nx = Garfield::gComponentNeBem3d->GetNumberOfPlanesX();
319 for (unsigned int i = 0; i < nx; ++i) {
320 double x = 0., v = 0.;
322 if (i == 0) {
323 *ixmin = 1;
324 *vxmin = v;
325 *cxmin = x;
326 } else {
327 *ixmax = 1;
328 *vxmax = v;
329 *cxmax = x;
330 }
331 }
332 *iymin = *iymax = 0;
333 *vymin = *vymax = 0.;
334 *cymin = *cymax = 0.;
335 const unsigned int ny = Garfield::gComponentNeBem3d->GetNumberOfPlanesY();
336 for (unsigned int i = 0; i < ny; ++i) {
337 double y = 0., v = 0.;
339 if (i == 0) {
340 *iymin = 1;
341 *vymin = v;
342 *cymin = y;
343 } else {
344 *iymax = 1;
345 *vymax = v;
346 *cymax = y;
347 }
348 }
349 *izmin = *izmax = 0;
350 *vzmin = *vzmax = 0.;
351 *czmin = *czmax = 0.;
352 const unsigned int nz = Garfield::gComponentNeBem3d->GetNumberOfPlanesZ();
353 for (unsigned int i = 0; i < nz; ++i) {
354 double z = 0., v = 0.;
356 if (i == 0) {
357 *izmin = 1;
358 *vzmin = v;
359 *czmin = z;
360 } else {
361 *izmax = 1;
362 *vzmax = v;
363 *czmax = z;
364 }
365 }
366 // Convert from cm to m.
367 *cxmin *= 0.01;
368 *cxmax *= 0.01;
369 *cymin *= 0.01;
370 *cymax *= 0.01;
371 *czmin *= 0.01;
372 *czmax *= 0.01;
373
374 return 0;
375}
376
377/// Return information about a volume.
378int neBEMVolumeDescription(int vol, int* shape, int* material,
379 double* epsilon, double* potential, double* charge,
380 int* boundarytype) {
381
382 if (!Garfield::gComponentNeBem3d) return -1;
383 if (!Garfield::gComponentNeBem3d->GetVolume(vol, *shape, *material,
384 *epsilon, *potential, *charge,
385 *boundarytype)) {
386 return false;
387 }
388 return true;
389}
390
391/// Return the volume in which a point is located.
392int neBEMVolumePoint(double x, double y, double z) {
393
394 if (!Garfield::gComponentNeBem3d) return -1;
395 return Garfield::gComponentNeBem3d->GetVolume(100. * x, 100. * y, 100. * z);
396}
397
398/// Return the primitives for a volume.
399/// TODO! Do we need this?
400void neBEMVolumePrimitives(int /*vol*/, int* /*nprim*/, int /*primlist*/[]) {
401
402}
403
404}
bool GetPlaneZ(const unsigned int i, double &z, double &v) const
Retrieve the parameters of a plane at constant z.
bool GetPlaneY(const unsigned int i, double &y, double &v) const
Retrieve the parameters of a plane at constant y.
bool GetPeriodicityX(double &s) const
Get the periodic length in the x-direction.
unsigned int GetNumberOfPrimitives() const
bool GetPeriodicityZ(double &s) const
Get the periodic length in the z-direction.
unsigned int GetNumberOfPlanesY() const
Get the number of equipotential planes at constant y.
bool GetPeriodicityY(double &s) const
Get the periodic length in the y-direction.
unsigned int GetNumberOfPlanesZ() const
Get the number of equipotential planes at constant z.
bool GetVolume(const unsigned int vol, int &shape, int &material, double &eps, double &potential, double &charge, int &bc)
unsigned int GetNumberOfPlanesX() const
Get the number of equipotential planes at constant x.
bool GetPlaneX(const unsigned int i, double &x, double &v) const
Retrieve the parameters of a plane at constant x.
void GetPeriodicCopies(unsigned int &nx, unsigned int &ny, unsigned int &nz) const
Retrieve the number of periodic copies used by neBEM.
void IsMirrorPeriodic(bool &perx, bool &pery, bool &perz)
Return mirror periodicity flags.
Definition: Component.hh:230
void IsPeriodic(bool &perx, bool &pery, bool &perz)
Return periodicity flags.
Definition: Component.hh:208
ComponentNeBem3d * gComponentNeBem3d
int neBEMVolumeDescription(int vol, int *shape, int *material, double *epsilon, double *potential, double *charge, int *boundarytype)
Return information about a volume.
int neBEMGetInputsFromFiles(void)
Do-nothing function (no file inputs).
int neBEMSetDefaults(void)
Assign default values to some of the important global variables.
int ReadInitFile(char filename[])
int neBEMVolumePoint(double x, double y, double z)
Return the volume in which a point is located.
int neBEMGetMirror(int, int *ix, int *jx, double *sx, int *iy, int *jy, double *sy, int *iz, int *jz, double *sz)
void neBEMVolumePrimitives(int, int *, int[])
int neBEMGetNbPrimitives()
Return the number of primitives.
int neBEMGetBoundingPlanes(int *ixmin, double *cxmin, double *vxmin, int *ixmax, double *cxmax, double *vxmax, int *iymin, double *cymin, double *vymin, int *iymax, double *cymax, double *vymax, int *izmin, double *czmin, double *vzmin, int *izmax, double *czmax, double *vzmax)
int neBEMGetPrimitive(int prim, int *nvertex, double xvert[], double yvert[], double zvert[], double *xnorm, double *ynorm, double *znorm, int *volref1, int *volref2)
Return one primitive at a time.
int neBEMGetPeriodicities(int, int *ix, int *jx, double *sx, int *iy, int *jy, double *sy, int *iz, int *jz, double *sz)
int neBEMMessage(const char *message)
INTFACEGLOBAL int OptPrimitiveFiles
INTFACEGLOBAL int neBEMState
INTFACEGLOBAL int OptPrintVolumeDetails
INTFACEGLOBAL char DeviceInputFile[256]
INTFACEGLOBAL int OptGnuplotPrimitives
INTFACEGLOBAL int OptDeviceFile
INTFACEGLOBAL int OptPrintPrimaryDetails
INTFACEGLOBAL int OptPrintVertexAndNormal
INTFACEGLOBAL int OptElementFiles
INTFACEGLOBAL int OptGnuplot
INTFACEGLOBAL int OptGnuplotElements
INTFACEGLOBAL int OptReuseDir
neBEMGLOBAL int DebugLevel
Definition: neBEM.h:235
neBEMGLOBAL int NbVolumes
Definition: neBEM.h:56
neBEMGLOBAL int MeshCntr
Definition: neBEM.h:224
neBEMGLOBAL int PPCntr
Definition: neBEM.h:224
neBEMGLOBAL int OptInvMatProc
Definition: neBEM.h:41
neBEMGLOBAL int OptRepeatLHMatrix
Definition: neBEM.h:51
neBEMGLOBAL int OptStorePrimitives
Definition: neBEM.h:45
neBEMGLOBAL int MaxNbVertices
Definition: neBEM.h:59
neBEMGLOBAL double ElementLengthRqstd
Definition: neBEM.h:107
neBEMGLOBAL int NewModel
Definition: neBEM.h:220
neBEMGLOBAL int OptFormattedFile
Definition: neBEM.h:49
neBEMGLOBAL int NewMesh
Definition: neBEM.h:220
neBEMGLOBAL int NbPrimitives
Definition: neBEM.h:57
neBEMGLOBAL int NbWires
Definition: neBEM.h:97
neBEMGLOBAL int PrimAfter
Definition: neBEM.h:351
neBEMGLOBAL int OptSystemChargeZero
Definition: neBEM.h:118
neBEMGLOBAL int NewPP
Definition: neBEM.h:220
neBEMGLOBAL int NbSurfs
Definition: neBEM.h:97
neBEMGLOBAL int BCCntr
Definition: neBEM.h:224
neBEMGLOBAL int TimeStep
Definition: neBEM.h:241
neBEMGLOBAL int OptStoreInflMatrix
Definition: neBEM.h:47
neBEMGLOBAL int OptForceValidation
Definition: neBEM.h:43
neBEMGLOBAL int OptUnformattedFile
Definition: neBEM.h:50
neBEMGLOBAL double LengthScale
Definition: neBEM.h:238
neBEMGLOBAL int MaxNbElementsOnLength
Definition: neBEM.h:105
neBEMGLOBAL int ModelCntr
Definition: neBEM.h:224
neBEMGLOBAL int OptValidateSolution
Definition: neBEM.h:42
neBEMGLOBAL char DeviceOutDir[256]
Definition: neBEM.h:262
neBEMGLOBAL int OptStoreElements
Definition: neBEM.h:46
neBEMGLOBAL int VolMax
Definition: neBEM.h:77
neBEMGLOBAL int OptStoreInvMatrix
Definition: neBEM.h:48
neBEMGLOBAL int NewBC
Definition: neBEM.h:220
neBEMGLOBAL int MinNbElementsOnLength
Definition: neBEM.h:103