Blame view

src/ExternLib/InternalField/InternalFields.hh 7.49 KB
55904ce1   Erdogan Furkan   Some corrections ...
1
2
3
4
5
6
/*
 * File:   InternalFields_.hh
 * Author: Furkan - AKKA I&S
 *
 * Created on July 11, 2022, 4:14 PM
 */
09b5a8e4   Erdogan Furkan   10038
7
8
9
10
#ifndef INTERNALFIELDS_HH
#define INTERNALFIELDS_HH

#include "libinternalfield.h"
6593ba1b   Erdogan Furkan   Last modification...
11
#include "libcon2020/libcon2020.h"
09b5a8e4   Erdogan Furkan   10038
12
13
14
15
16
17
18
19
20
21
22
23
24

#include "Parameter.hh"
#include "ParamData.hh"
#include "DataTypeMath.hh"
#include "Operation.hh"
#include <vector>

using namespace std;

namespace AMDA
{
    namespace Parameters
    {
9a4854f9   Erdogan Furkan   Implémentation de...
25
26
27
28
        template <typename DataType, class TOutputParamData>
        class InternalFields : public Operation
        {
        public:
e634d5f9   Erdogan Furkan   Some changes
29
            InternalFields(Process &pProcess, ParamDataSpec<vector<DataType>> &paramInput, const std::string &modelname, string outputCoord, const unsigned int addCon2020)
9a4854f9   Erdogan Furkan   Implémentation de...
30
                : Operation(pProcess), _paramInput(paramInput),
e634d5f9   Erdogan Furkan   Some changes
31
                  _paramOutput(new TOutputParamData()), _modelname(modelname), _outputCoord(outputCoord), _addCon2020(addCon2020)
9a4854f9   Erdogan Furkan   Implémentation de...
32
33
34
35
36
37
            {
                _paramDataOutput = _paramOutput;
            }

            virtual ~InternalFields()
            {
9a4854f9   Erdogan Furkan   Implémentation de...
38
39
40
41
42
43
44
45
46
47
48
49
            }
            void write(ParamDataIndexInfo &pParamDataIndexInfo)
            {
                for (unsigned int _index = pParamDataIndexInfo._startIndex;
                     _index < pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess;
                     ++_index)
                {
                    vector<DataType> in = _paramInput.getDataList()[_index];
                    if (in[0] == 0)
                        in[0] = 1e-31;

                    double crtTime = _paramInput.getTime(_index);
b1e1296b   Erdogan Furkan   Last changes
50
51
52
                    vector<DataType> outputBxyz, outputBrtp;
                    outputBxyz.resize(3);
                    outputBrtp.resize(3);
9a4854f9   Erdogan Furkan   Implémentation de...
53
                    DataType outputBm;
e634d5f9   Erdogan Furkan   Some changes
54
55
56
                    /* Creation of the output vectors */
                    if (_outputCoord == "cart")
                    {
b1e1296b   Erdogan Furkan   Last changes
57
                        GetJupiterField(in, true, outputBxyz);
e634d5f9   Erdogan Furkan   Some changes
58
59
60
                    }
                    else if (_outputCoord == "pol" || _outputCoord == "mag")
                    {
b1e1296b   Erdogan Furkan   Last changes
61
                        GetJupiterField(in, false, outputBrtp);
e634d5f9   Erdogan Furkan   Some changes
62
                    }
9a4854f9   Erdogan Furkan   Implémentation de...
63

b1e1296b   Erdogan Furkan   Last changes
64
                    outputBm = sqrt(outputBrtp[0] * outputBrtp[0] + outputBrtp[1] * outputBrtp[1] + outputBrtp[2] * outputBrtp[2]);
9a4854f9   Erdogan Furkan   Implémentation de...
65

9a4854f9   Erdogan Furkan   Implémentation de...
66
                    _paramOutput->pushTime(crtTime);
b1e1296b   Erdogan Furkan   Last changes
67
                    pushResult(outputBrtp, outputBm, outputBxyz);
9a4854f9   Erdogan Furkan   Implémentation de...
68
69
                }
            }
6b9283bc   Erdogan Furkan   Ajout de Con2020,...
70
            int GetJupiterField(vector<DataType> &inputCartCoord, bool SetCartOut, vector<DataType> &outputB)
9a4854f9   Erdogan Furkan   Implémentation de...
71
            {
b1e1296b   Erdogan Furkan   Last changes
72
                /* set the model */
6b9283bc   Erdogan Furkan   Ajout de Con2020,...
73
                _internalModel.SetModel(_modelname.c_str());
9a4854f9   Erdogan Furkan   Implémentation de...
74

e634d5f9   Erdogan Furkan   Some changes
75
                /* set intput and output coordinates */
9a4854f9   Erdogan Furkan   Implémentation de...
76
77
78
79
80
                _internalModel.SetCartIn(true);
                _internalModel.SetCartOut(SetCartOut);

                /* output field */
                double Br, Bt, Bp;
6b9283bc   Erdogan Furkan   Ajout de Con2020,...
81
                _internalModel.Field(inputCartCoord[0], inputCartCoord[1], inputCartCoord[2], &Br, &Bt, &Bp);
9a4854f9   Erdogan Furkan   Implémentation de...
82

55904ce1   Erdogan Furkan   Some corrections ...
83
                /* Con2020 calculation to add if necessary */
6b9283bc   Erdogan Furkan   Ajout de Con2020,...
84
                double Be0, Be1, Be2;
e634d5f9   Erdogan Furkan   Some changes
85
                if (_addCon2020 > 0)
6b9283bc   Erdogan Furkan   Ajout de Con2020,...
86
87
88
                {
                    _con2020.SetCartIn(true);
                    _con2020.SetCartOut(SetCartOut);
e634d5f9   Erdogan Furkan   Some changes
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
                    switch (_addCon2020)
                    {
                    case 1:
                        _con2020.SetEqType("analytic");  // Fast
                        break;
                    case 2:
                        _con2020.SetEqType("integral");  // Slow
                        break;
                    case 3:
                        _con2020.SetEqType("hybrid");    // In between
                        break;

                    default:
                        _con2020.SetEqType("analytic");
                        break;
                    }
6b9283bc   Erdogan Furkan   Ajout de Con2020,...
105
106
107
108
109
110
111
112
113
114
115
116
                    _con2020.Field(inputCartCoord[0], inputCartCoord[1], inputCartCoord[2], &Be0, &Be1, &Be2);
                }
                else
                {
                    Be0 = 0.0;
                    Be1 = 0.0;
                    Be2 = 0.0;
                }

                outputB[0] = Br + Be0;
                outputB[1] = Bt + Be1;
                outputB[2] = Bp + Be2;
9a4854f9   Erdogan Furkan   Implémentation de...
117
118
119
120
121
122

                return true;
            }

        protected:
            virtual void
b1e1296b   Erdogan Furkan   Last changes
123
            pushResult(vector<DataType> field_pol, DataType magnitude_, vector<DataType> field_cart) = 0;
9a4854f9   Erdogan Furkan   Implémentation de...
124
125
            ParamDataSpec<std::vector<DataType>> &_paramInput;
            TOutputParamData *_paramOutput;
6b9283bc   Erdogan Furkan   Ajout de Con2020,...
126
            Con2020 _con2020;
9a4854f9   Erdogan Furkan   Implémentation de...
127
            InternalModel _internalModel;
6b9283bc   Erdogan Furkan   Ajout de Con2020,...
128
            std::string _modelname;
9a4854f9   Erdogan Furkan   Implémentation de...
129
            string _outputCoord;
b1e1296b   Erdogan Furkan   Last changes
130
            unsigned int _addCon2020;
9a4854f9   Erdogan Furkan   Implémentation de...
131
        };
09b5a8e4   Erdogan Furkan   10038
132

9a4854f9   Erdogan Furkan   Implémentation de...
133
134
        template <typename DataType>
        class InternalFieldCart : public InternalFields<DataType, ParamDataSpec<vector<DataType>>>
09b5a8e4   Erdogan Furkan   10038
135
136
        {
        public:
9a4854f9   Erdogan Furkan   Implémentation de...
137
138
139
140
            /**
             * @brief Constructor.
             * @details Create the ParamData type of the input ParamData.
             */
e634d5f9   Erdogan Furkan   Some changes
141
            InternalFieldCart(Process &pProcess, ParamDataSpec<vector<DataType>> &paramInput, const std::string &modelname, const unsigned int addCon2020) : InternalFields<DataType, ParamDataSpec<vector<DataType>>>(pProcess, paramInput, modelname, "cart", addCon2020)
9a4854f9   Erdogan Furkan   Implémentation de...
142
143
            {
            }
09b5a8e4   Erdogan Furkan   10038
144

9a4854f9   Erdogan Furkan   Implémentation de...
145
146
147
            virtual ~InternalFieldCart()
            {
            }
09b5a8e4   Erdogan Furkan   10038
148

9a4854f9   Erdogan Furkan   Implémentation de...
149
        protected:
b1e1296b   Erdogan Furkan   Last changes
150
            virtual void pushResult(vector<DataType> /*_fieldPol*/, DataType /*magnitude_*/, vector<DataType> _fieldCart)
9a4854f9   Erdogan Furkan   Implémentation de...
151
152
153
            {
                InternalFields<DataType, ParamDataSpec<vector<DataType>>>::_paramOutput->getDataList().push_back(_fieldCart);
            }
9a4854f9   Erdogan Furkan   Implémentation de...
154
155
156
157
158
159
160
161
162
163
        };

        template <typename DataType>
        class InternalFieldMag : public InternalFields<DataType, ParamDataSpec<DataType>>
        {
        public:
            /**
             * @brief Constructor.
             * @details Create the ParamData type of the input ParamData.
             */
e634d5f9   Erdogan Furkan   Some changes
164
            InternalFieldMag(Process &pProcess, ParamDataSpec<vector<DataType>> &paramInput, const std::string &modelname, const unsigned int addCon2020) : InternalFields<DataType, ParamDataSpec<DataType>>(pProcess, paramInput, modelname, "mag", addCon2020)
9a4854f9   Erdogan Furkan   Implémentation de...
165
166
167
168
169
170
171
            {
            }

            virtual ~InternalFieldMag()
            {
            }

09b5a8e4   Erdogan Furkan   10038
172
        protected:
b1e1296b   Erdogan Furkan   Last changes
173
            virtual void pushResult(vector<DataType> /*_fieldPol*/, DataType _magnetude, vector<DataType> /*_fieldCart*/)
9a4854f9   Erdogan Furkan   Implémentation de...
174
175
176
177
178
179
180
181
182
183
184
185
186
            {
                InternalFields<DataType, ParamDataSpec<DataType>>::_paramOutput->getDataList().push_back(_magnetude);
            }
        };

        template <typename DataType>
        class InternalFieldPol : public InternalFields<DataType, ParamDataSpec<vector<DataType>>>
        {
        public:
            /**
             * @brief Constructor.
             * @details Create the ParamData type of the input ParamData.
             */
e634d5f9   Erdogan Furkan   Some changes
187
            InternalFieldPol(Process &pProcess, ParamDataSpec<vector<DataType>> &paramInput, const std::string &modelname, const unsigned int addCon2020) : InternalFields<DataType, ParamDataSpec<vector<DataType>>>(pProcess, paramInput, modelname, "pol", addCon2020)
9a4854f9   Erdogan Furkan   Implémentation de...
188
189
190
191
192
193
194
195
            {
            }

            virtual ~InternalFieldPol()
            {
            }

        protected:
b1e1296b   Erdogan Furkan   Last changes
196
            virtual void pushResult(vector<DataType> _fieldPol, DataType /* _magnetude*/, vector<DataType> /*_fieldCart*/)
9a4854f9   Erdogan Furkan   Implémentation de...
197
198
199
            {
                InternalFields<DataType, ParamDataSpec<vector<DataType>>>::_paramOutput->getDataList().push_back(_fieldPol);
            }
09b5a8e4   Erdogan Furkan   10038
200
201
202
203
        };
    }
}
#endif /* InternalFields.hh */