/********************************************************
 *  ██████╗  ██████╗████████╗██╗
 * ██╔════╝ ██╔════╝╚══██╔══╝██║
 * ██║  ███╗██║        ██║   ██║
 * ██║   ██║██║        ██║   ██║
 * ╚██████╔╝╚██████╗   ██║   ███████╗
 *  ╚═════╝  ╚═════╝   ╚═╝   ╚══════╝
 * Geophysical Computational Tools & Library (GCTL)
 *
 * Copyright (c) 2022  Yi Zhang (yizhang-geo@zju.edu.cn)
 *
 * GCTL is distributed under a dual licensing scheme. You can redistribute 
 * it and/or modify it under the terms of the GNU Lesser General Public 
 * License as published by the Free Software Foundation, either version 2 
 * of the License, or (at your option) any later version. You should have 
 * received a copy of the GNU Lesser General Public License along with this 
 * program. If not, see <http://www.gnu.org/licenses/>.
 * 
 * If the terms and conditions of the LGPL v.2. would prevent you from using 
 * the GCTL, please consider the option to obtain a commercial license for a 
 * fee. These licenses are offered by the GCTL's original author. As a rule, 
 * licenses are provided "as-is", unlimited in time for a one time fee. Please 
 * send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget 
 * to include some description of your company and the realm of its activities. 
 * Also add information on how to contact you by electronic and paper mail.
 ******************************************************/

#ifndef _GCTL_MAG_KERNEL_DIPOLE_H
#define _GCTL_MAG_KERNEL_DIPOLE_H

#include "gm_data.h"
#include "gctl/poly/vertex.h"
#include "gctl/utility/progress_bar.h"

namespace gctl
{
    /**
     * @brief Calculate magnetic parameters of an axial magnetic dipolar (north pointing)
     * 
     * @note Thébault, E., & Vervelidou, F. (2015). A statistical spatial power spectrum of the Earth's lithospheric magnetic field. Geophysical Journal International, 201(2), 605–620.
     * 
     * @param M magnetization strength
     * @param I Inclination angle
     * @param r Radius of the calculating point
     * @param lat_deg Latitude of the calculating point
     * @param sus Magnetic susceptibility
     * @param ref_r Reference earth radius
     * @param abs_g0 Gauss coefficient of degree 1 order 0 of the internal inducing field
     */
    void mag_axial_dipole_parameters(double &M, double &I, double r, double lat_deg, double sus = 1.0, double ref_r = GCTL_Earth_Radius, double abs_g0 = 29442.0);

    /**
     * @brief Magnetic dipole
     * 
     */
    struct mag_dipole
    {
        double M; // Magnetic moment scale value
        point3dc n; // Magnetic direction
    };

    /**
     * @brief 
     * 
     * @param a_dipole 
     * @param a_op 
     * @return point3dc 
     */
    point3dc magkernel_single(const mag_dipole &a_dipole, const point3dc &a_op);

    /**
     * @brief 
     * 
     * @param a_dipole 
     * @param a_op 
     * @param R_ptr 
     * @return point3dc 
     */
    point3dc magkernel_single(const mag_dipole &a_dipole, const point3ds &a_op, tensor *R_ptr = nullptr);

    /**
     * @brief 
     * 
     * @param out_obs 
     * @param dipoles 
     * @param obsp 
     * @param verbose 
     */
    void magobser(array<point3dc> &out_obs, const array<mag_dipole> &dipoles, 
        const array<point3dc> &obsp, verbose_type_e verbose = FullMsg);

    /**
     * @brief 
     * 
     * @param out_obs 
     * @param dipoles 
     * @param obsp 
     * @param verbose 
     */
    void magobser(array<point3dc> &out_obs, const array<mag_dipole> &dipoles, 
        const array<point3ds> &obsp, verbose_type_e verbose = FullMsg);
};

#endif // _GCTL_MAG_KERNEL_DIPOLE_H