gfields
Loading...
Searching...
No Matches
test_gfield_dipole.cc
Go to the documentation of this file.
1
28// gfields
29#include "gfield_options.h"
30#include "gmagneto.h"
31
32// c++
33#include <iostream>
34
35using namespace std;
36
51int main(int argc, char* argv[]) {
52
53 // Initialize GOptions (parsed from YAML or another source)
54 auto gopts = std::make_shared<GOptions>(argc, argv, gfields::defineOptions());
55
56 // Create a GMagneto instance to manage fields
57 auto magneto = std::make_shared<GMagneto>(gopts);
58
59 string field_name = "dipole";
60
61 // Check if a specific field exists
62 if (magneto->isField(field_name)) {
63 auto dipole_field = magneto->getField(field_name);
64 auto dipole_field_manager = magneto->getFieldMgr(field_name);
65
66 // Non-Doxygen summary:
67 // Demonstrate repeated evaluation of the field; this intentionally does not attach the field manager
68 // to any volume, as the goal is only to show the API surface.
69
70 // pos is a double[3] representing x,y,z
71 // iterate through 100 pos that span random positions between 0 and 100 in each coordinate
72 for (int i = 0; i < 100; i++) {
73 double x = rand() % 100;
74 double y = rand() % 100;
75 double z = rand() % 100;
76
77 double pos[3] = {x, y, z};
78 double bfield[3];
79 dipole_field->GetFieldValue(pos, bfield);
80 }
81 } else {
82 cout << "Field " << field_name << " was not found." << endl;
83 }
84
85 return EXIT_SUCCESS;
86}
GOptions defineOptions()
Define all options used by the GField module and its built-in field factories.
int main(int argc, char *argv[])