-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExperiment.cpp
More file actions
81 lines (72 loc) · 2.26 KB
/
Copy pathExperiment.cpp
File metadata and controls
81 lines (72 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "Experiment.h"
Experiment::Experiment(const Field& field, std::list<Coil> coils, std::list<double> I) : field(field), field_is_calculated(false)
{
if (coils.size() == I.size())
{
this->Is = I;
this->coils = coils;
}
}
Experiment::Experiment(const Field& field, const Coil& coil, const double& I) : field(field), field_is_calculated(false), coils({ coil }), Is({ I }) {}
void Experiment::setCoils(std::list<Coil> new_coils, std::list<double> new_I)
{
if (new_coils.size() == new_I.size())
{
coils = new_coils;
Is = new_I;
}
}
void Experiment::addCoil(Coil additional_coil, double I)
{
coils.push_back(additional_coil);
Is.push_back(I);
}
void Experiment::addCoils(std::list<Coil> additional_coils, std::list<double> Is)
{
if (Is.size() == additional_coils.size())
{
std::list<double>::iterator I = Is.begin();
for (auto additional_coil : additional_coils)
{
this->addCoil(additional_coil, *(I++));
}
}
else
{
//there must be an exception
}
}
void Experiment::setField(Field new_field)
{
//Possibly there could be implemented some copy from old field to keep old calculated data
field = new_field;
}
Field Experiment::getField()
{
if (!field_is_calculated)
{
constexpr double C = 1e-7 / std::numbers::pi;
std::list<double>::iterator I = Is.begin();
for (auto& current_coil : coils)
{
for (auto field_point = field.field.begin(); field_point < field.field.end(); ++field_point)
{
bool coil_ended = false;
current_coil.resetSegmentIterator();
while (!coil_ended)
{
Segment current_segment = current_coil.getCurrentSegment(coil_ended);
Vector segment_field_orth((*field_point).point,
current_segment.start.y * current_segment.end.z - current_segment.start.z * current_segment.end.y,
current_segment.start.x * current_segment.end.z - current_segment.start.z * current_segment.end.x,
current_segment.start.x * current_segment.end.y - current_segment.start.y * current_segment.end.x);
segment_field_orth.toOrth();
(*field_point) += segment_field_orth * C * (*I) * (cos_angle_line_to_line((*field_point).point, current_segment)
+ cos_angle_line_to_line(current_segment.end, (*field_point).point, current_segment.start));
}
}
I++;
}
}
return field;
}