gfields
Loading...
Searching...
No Matches
test_gfield_dipole.cc
Go to the documentation of this file.
1// gfields
2#include "gfield_options.h"
3#include "gmagneto.h"
4
5// c++
6#include <iostream>
7
8using namespace std;
9
10int main(int argc, char* argv[]) {
11
12 // Initialize GOptions (parsed from YAML or another source)
13 auto gopts = std::make_shared<GOptions>(argc, argv, gfields::defineOptions());
14
15 // Create a GMagneto instance to manage fields
16 auto magneto = std::make_shared<GMagneto>(gopts);
17
18 string field_name = "dipole";
19
20 // Check if a specific field exists
21 if (magneto->isField(field_name)) {
22 auto dipole_field = magneto->getField(field_name);
23 auto dipole_field_manager = magneto->getFieldMgr(field_name);
24
25 // pos is a double[3] representing x,y,z
26 // iterate through 100 pos that span random positions between 0 and 100 in each coordinate
27 for (int i = 0; i < 100; i++) {
28 double x = rand() % 100;
29 double y = rand() % 100;
30 double z = rand() % 100;
31
32 double pos[3] = {x, y, z};
33 double bfield[3];
34 dipole_field->GetFieldValue(pos, bfield);
35
36 }
37
38
39 } else {
40 cout << "Field " << field_name << " was not found." << endl;
41 }
42
43 return EXIT_SUCCESS;
44}
GOptions defineOptions()
int main(int argc, char *argv[])