gfields
Loading...
Searching...
No Matches
gfield_asciimap.h
Go to the documentation of this file.
1#pragma once
2
3// gemc gfield framework
4#include "gfield.h"
5
6// c++
7#include <array>
8#include <optional>
9#include <string>
10#include <vector>
11
30
79
80public:
81 explicit GField_AsciiMapFactory(const std::shared_ptr<GOptions>& gopt) : GField(gopt) {}
82
84 void GetFieldValue(const double pos[3], G4double* bfield) const override;
85
88
89private:
91 enum class Symmetry {
92 dipole_x, dipole_y, dipole_z,
93 cyl_x, cyl_y, cyl_z,
94 phi_segmented,
95 cartesian_3d, cartesian_3d_quadrant
96 };
97
98 Symmetry symmetry = Symmetry::dipole_z;
99 int ndim = 2;
100 int ncomp = 1;
101 bool linear = true;
102
103 // Grid geometry in canonical per-symmetry axis order (see class documentation).
104 std::array<unsigned, 3> np = {0, 0, 0};
105 std::array<double, 3> startMap = {0.0, 0.0, 0.0};
106 std::array<double, 3> endMap = {0.0, 0.0, 0.0};
107 std::array<double, 3> cellSize = {1.0, 1.0, 1.0};
108
109 // One map-file column per grid coordinate, in file-column order (coordinate1, coordinate2, ...).
110 struct Column {
111 int axis = 0;
112 double unitFactor = 1.0;
113 };
114 std::vector<Column> columns;
115
116 // Field buffers (contiguous). B2/B3 stay empty for symmetries that do not use them.
117 std::vector<float> B1;
118 std::vector<float> B2;
119 std::vector<float> B3;
120
121 // Overall placement (lab frame). Origin in Geant4 length units, rotation in radians.
122 double mapOrigin[3] = {0.0, 0.0, 0.0};
123 double mapRotation[3] = {0.0, 0.0, 0.0};
124 double sinAlpha = 0.0, cosAlpha = 1.0; // about X
125 double sinBeta = 0.0, cosBeta = 1.0; // about Y
126 double sinGamma = 0.0, cosGamma = 1.0; // about Z
127
128 // Flat indexing helpers (canonical axis order).
129 inline std::size_t idx2(unsigned i0, unsigned i1) const { return static_cast<std::size_t>(i0) * np[1] + i1; }
130 inline std::size_t idx3(unsigned i0, unsigned i1, unsigned i2) const {
131 return (static_cast<std::size_t>(i0) * np[1] + i1) * np[2] + i2;
132 }
133
134 // Per-symmetry field evaluation (point already shifted by mapOrigin).
135 void value_dipole(const double x[3], double* bfield) const;
136 void value_cylindrical(const double x[3], double* bfield) const;
137 void value_phi_segmented(const double x[3], double* bfield) const;
138 void value_cartesian3d(const double x[3], double* bfield) const;
139
140 // Rotate the field vector (not the point): each rotation is the inverse of the point rotation.
141 void rotate_field(double* bfield) const;
142
143 // Configuration helpers (the generic node only guarantees name/type).
144 std::string param_string(const std::string& key, const std::string& dflt) const;
145 double param_g4number(const std::string& key, const std::string& dflt) const;
146
147 // Map the canonical axis of a coordinate name for the current symmetry, or return nullopt if invalid.
148 std::optional<unsigned> axis_of_coordinate(const std::string& name) const;
149
150 // Parse one "name, npoints, min, max" coordinate string into the grid arrays and a Column.
151 void load_coordinate(const std::string& key);
152
153 // Read the map file and fill the field buffers.
154 void load_map_file();
155
156 // Default field-map directory: <plugin_dir>/../fields (the `meson install` layout). No env var.
157 std::string field_maps_directory() const;
158};
GField_AsciiMapFactory(const std::shared_ptr< GOptions > &gopt)
void load_field_definitions(GFieldDefinition gfd) override
Parse the YAML definition, build the grid and read the map file.
void GetFieldValue(const double pos[3], G4double *bfield) const override
Compute the field at the lab-frame point pos, writing {Bx,By,Bz} (Geant4 units) into bfield.
GField(const std::shared_ptr< GOptions > &gopt)
Construct the field base with the provided options (for logging and configuration access).
Definition gfield.h:112
Lightweight configuration carrier used to load and configure a GField plugin.
Definition gfield.h:27