KT17.hh 4.97 KB
/*
 * File:   KT17.hh
 * Author: Furkan - AKKA I&S
 *
 * Created on January 19, 2022, 4:14 PM
 */
#ifndef KT17_HH
#define KT17_HH

#include "libkt.h" // If we name it this way

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

using namespace std;

namespace AMDA
{
    namespace Parameters
    {
        template <typename DataType, class TOutputParamData>
        class KT17 : public Operation
        {
        public:
            KT17(Process &pProcess, ParamDataSpec<vector<DataType>> &paramInput, string coordRef, double rSun, double distIndex)
                : Operation(pProcess), _paramInput(paramInput),  _coordRef(coordRef), _rSun(rSun), _distIndex(distIndex),
                  _paramOutput(new TOutputParamData())
            {
                _paramDataOutput = _paramOutput;
            }

            virtual ~KT17()
            {
            }
            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);
                    vector<DataType> outputBxyz;
                    outputBxyz.resize(3);
                    DataType outputBm;

                    /* Creation of the output vectors */
                    GetModelField(in,outputBxyz);

                    outputBm = sqrt(outputBxyz[0] * outputBxyz[0] + outputBxyz[1] * outputBxyz[1] + outputBxyz[2] * outputBxyz[2]);

                    _paramOutput->pushTime(crtTime);
                    pushResult(outputBxyz, outputBm);
                }
            }
            int GetModelField(vector<DataType> &input, vector<DataType> &output){
                double Bx, By, Bz;
                double x,y,z;
                double* params=new double[2];
                double dz = 0.196;


                // Coeffs for the model
                if (!std::isnan(_rSun) && !std::isnan(_distIndex)){
                    params[0] = _rSun;
                    params[1] = _distIndex;
                }
                else{
                    params[0] = 0.427;
                    params[1] = 50.0;
                }
               
                x =  double(input[0]);
                y = double(input[1]);
                
                if(_coordRef == "MSO")
                    z = double(input[2])-dz;
                else if (_coordRef == "MSM")
                    z = double(input[2]);

                // Call to the lib to compute
                ModelField(1,&x,&y,&z,1,2,&params,&Bx, &By,&Bz);
        
                output[0] = Bx;
                output[1] = By;
                output[2] = Bz;

                free(params);

                return true;
            }

        protected:
            virtual void
            pushResult(vector<DataType> field_cart, DataType magnitude_) = 0;
            ParamDataSpec<std::vector<DataType>> &_paramInput;
            std::string _coordRef;
            double _rSun;
            double _distIndex;
            TOutputParamData *_paramOutput;
            
        };

        template <typename DataType>
        class KT17Cart : public KT17<DataType, ParamDataSpec<vector<DataType>>>
        {
        public:
            /**
             * @brief Constructor.
             * @details Create the ParamData type of the input ParamData.
             */
            KT17Cart(Process &pProcess, ParamDataSpec<vector<DataType>> &paramInput, string coordRef, double rSun, double distIndex) : 
                    KT17<DataType, ParamDataSpec<vector<DataType>>>(pProcess, paramInput, coordRef, rSun, distIndex){}
            virtual ~KT17Cart(){}
        protected:
            virtual void pushResult(vector<DataType> _fieldCart, DataType /*magnitude_*/){
                KT17<DataType, ParamDataSpec<vector<DataType>>>::_paramOutput->getDataList().push_back(_fieldCart);
            }
        };


        template <typename DataType>
        class KT17Mag : public KT17<DataType, ParamDataSpec<DataType>>
        {
        public:
            /**
             * @brief Constructor.
             * @details Create the ParamData type of the input ParamData.
             */
            KT17Mag(Process &pProcess, ParamDataSpec<vector<DataType>> &paramInput, string coordRef, double rSun, double distIndex) : 
                    KT17<DataType, ParamDataSpec<DataType>>(pProcess, paramInput, coordRef, rSun, distIndex){}
            virtual ~KT17Mag(){}
        protected:
            virtual void pushResult(vector<DataType> /*_fieldCart*/, DataType magnitude_){
                KT17<DataType, ParamDataSpec<DataType>>::_paramOutput->getDataList().push_back(magnitude_); 
            }
        };

    }
}
#endif /* KT17.hh */