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 string field_name = "dipole";
62
63 // Check if a specific field exists
64 if (magneto->isField(field_name)) {
65 auto dipole_field = magneto->getField(field_name);
66 auto dipole_field_manager = magneto->getFieldMgr(field_name);
67
68 // Non-Doxygen summary:
69 // Demonstrate repeated evaluation of the field; this intentionally does not attach the field manager
70 // to any volume, as the goal is only to show the API surface.
71
72 // pos is a double[3] representing x,y,z
73 // iterate through 100 pos that span random positions between 0 and 100 in each coordinate
74 for (int i = 0; i < 100; i++) {
75 double x = rand() % 100;
76 double y = rand() % 100;
77 double z = rand() % 100;
78
79 double pos[3] = {x, y, z};
80 double bfield[3];
81 dipole_field->GetFieldValue(pos, bfield);
82 }
83 } else {
84 cout << "Field " << field_name << " was not found." << endl;
85 }
86
87 return EXIT_SUCCESS;
88}
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[])