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 if (gfields::runFieldQueries(gopts)) { return EXIT_SUCCESS; }
57
58 // Create a GMagneto instance to manage fields
59 auto magneto = std::make_shared<GMagneto>(gopts);
60
61 // Probe whichever fields the YAML configured (e.g. "dipole", "solenoid", "torus"), instead of a
62 // hardcoded name, so the example works for every field definition.
63 const auto field_names = magneto->getFieldNames();
64 if (field_names.empty()) {
65 cout << "No fields were configured." << endl;
66 return EXIT_SUCCESS;
67 }
68
69 for (const auto& field_name : field_names) {
70 auto field = magneto->getField(field_name);
71 auto field_manager = magneto->getFieldMgr(field_name);
72
73 // Non-Doxygen summary:
74 // Demonstrate repeated evaluation of the field; this intentionally does not attach the field manager
75 // to any volume, as the goal is only to show the API surface.
76
77 // pos is a double[3] representing x,y,z
78 // iterate through 100 pos that span random positions between 0 and 100 in each coordinate
79 for (int i = 0; i < 100; i++) {
80 double x = rand() % 100;
81 double y = rand() % 100;
82 double z = rand() % 100;
83
84 double pos[3] = {x, y, z};
85 double bfield[3];
86 field->GetFieldValue(pos, bfield);
87 }
88 }
89
90 return EXIT_SUCCESS;
91}
bool runFieldQueries(const std::shared_ptr< GOptions > &gopts)
Evaluate configured fields from fieldAt and fieldMapPoints options, if requested.
GOptions defineOptions()
Define all options used by the GField module and its built-in field factories.
int main(int argc, char *argv[])