/********************************************************
 *  ██████╗  ██████╗████████╗██╗
 * ██╔════╝ ██╔════╝╚══██╔══╝██║
 * ██║  ███╗██║        ██║   ██║
 * ██║   ██║██║        ██║   ██║
 * ╚██████╔╝╚██████╗   ██║   ███████╗
 *  ╚═════╝  ╚═════╝   ╚═╝   ╚══════╝
 * 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 _GM_REGULAR_GRID_H
#define _GM_REGULAR_GRID_H

#include "gctl/mesh/regular_grid.h"
#include "gm_data.h"
#include "gctl/math/extrapolate.h"
#include "gctl/math/space_filter.h"

namespace gctl
{
	/**
	 * @brief      位场数据规则网格类型
	 * 
	 * 此类型由规则网络类型继承而来。负责规则网格中的位场数据处理，可完成的处理类型包括求取不同阶次的
	 * 方向导数、线性特征提取、磁异常化极、区域场-剩余场分离、延拓等。
	 */
	class gm_regular_grid : public regular_grid
	{
	public:
		gm_regular_grid(); ///< 构造函数
		virtual ~gm_regular_grid(); ///< 析构函数
		
		/**
		 * @brief      构造函数重载
		 *
		 * @param[in]  in_name  网格的名称
		 * @param[in]  in_info  与网格有关的信息
		 * @param[in]  xnum     x方向的节点数量
		 * @param[in]  ynum     y方向的节点数量
		 * @param[in]  xmin     x方向的最小值
		 * @param[in]  ymin     y方向的最小值
		 * @param[in]  dx       x方向的网格间隔
		 * @param[in]  dy       y方向的网格间隔
		 */
		gm_regular_grid(std::string in_name, std::string in_info, int xnum, int ynum, 
			double xmin, double ymin, double dx, double dy);

/**
 * The following functions require the FFTW library. Turn off the macro GCTL_FFTW to disable these functions
 */
#ifdef GCTL_POTENTIAL_FFTW3

		/**
		 * @brief      计算重磁异常的方向导数
		 *
		 * @param[in]  datname   待计算的数据名称
		 * @param[in]  gradname  计算结果的保存名称
		 * @param[in]  c_type    需计算的方向导数类型。必须为Tzx，Tzy或Tzz其中之一
		 * @param[in]  order     求导的阶次
		 */
		void gradient(std::string datname, std::string gradname, gravitational_field_type_e c_type = Tzz, int order = 1);
		
		/**
		 * @brief      计算化极磁异常
		 *
		 * @param[in]  datname  待计算的数据名称
		 * @param[in]  rtpname  计算结果的保存名称
		 * @param[in]  inc      磁化倾角（度）
		 * @param[in]  dec      磁化偏角（度）
		 */
		void rtp(std::string datname, std::string rtpname, double inc, double dec);
		
		/**
		 * @brief      计算变磁化角度的化极磁异常
		 *
		 * @param[in]  datname   待计算的数据名称
		 * @param[in]  incname   磁化倾角数据名称
		 * @param[in]  decname   磁化偏角数据名称
		 * @param[in]  drtpname  计算结果的保存名称
		 * @param[in]  order     变磁化角度计算中的泰勒展开阶数
		 */
		void drtp(std::string datname, std::string incname, std::string decname, std::string drtpname, int order = 1);
		
		/**
		 * @brief      位场延拓
		 *
		 * @param[in]  datname  待计算的数据名称
		 * @param[in]  retname  计算结果的保存名称
		 * @param[in]  height   延拓的距离（向上为负，向下为正）
		 */
		void conti(std::string datname, std::string retname, double height);

#endif //GCTL_POTENTIAL_FFTW3

		/**
		 * @brief 趋势场分离
		 * 
		 * @param datname 待计算的数据名称
		 * @param regname 计算的区域场数据名称
		 * @param resname 计算的局部场数据名称
		 * @param wx_size 东向窗口大小
		 * @param wy_size 北向窗口大小
		 * @param x_order 东向趋势场阶数
		 * @param y_order 北向趋势场阶数
		 */
		void trend(std::string datname, std::string regname, std::string resname, int wx_size, int wy_size, int x_order, int y_order);
	};
};

#endif //_GM_REGULAR_GRID_H