/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
* ██║ ██║██║ ██║ ██║
* ╚██████╔╝╚██████╗ ██║ ███████╗
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2023 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 .
*
* 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_ALGORITHM_FUNC_H
#define _GCTL_ALGORITHM_FUNC_H
#include "../core/array.h"
#include "../core/matrix.h"
#include "../maths/mathfunc.h"
namespace gctl
{
/**
* @brief 按距离反比加权计算均值
*
* @param dis_vec 距离向量
* @param val_vec 数值向量
* @param[in] order 距离加权的阶次 默认为1
*
* @return 加权平均值
*/
double dist_inverse_weight(std::vector *dis_vec, std::vector *val_vec, int order = 1);
/**
* @brief 查找一个数在已排序的数组中的位置,即找到包含该数的最小区间
*
* @param[in] in_array 输入数组
* @param[in] array_size 数组大小
* @param[in] in_val 查找值
* @param index 返回的索引值
*
* @return 成功0失败-1
*/
int find_index(const double *in_array, int array_size, double in_val, int &index);
/**
* @brief 查找一个数在已排序的数组中的位置,即找到包含该数的最小区间
*
* @param in_array 输入数组
* @param[in] in_val 查找值
* @param index 返回的索引值
*
* @return 成功0失败-1
*/
int find_index(array *in_array, double in_val, int &index);
/**
* @brief 计算一维分形模型
*
* @param out_arr 输出数组
* @param[in] l_val 分形计算的左端点值
* @param[in] r_val 分形计算的右端点值
* @param[in] maxi_range 最大变化值
* @param[in] smoothness 变化光滑度
*/
void fractal_model_1d(array &out_arr, int out_size, double l_val,
double r_val, double maxi_range, double smoothness);
/**
* @brief 计算二维分形模型
*
* @param out_arr 输出数组
* @param[in] dl_val 分形计算的左下角端点值
* @param[in] dr_val 分形计算的右下角端点值
* @param[in] ul_val 分形计算的左上角端点值
* @param[in] ur_val 分形计算的右上角端点值
* @param[in] maxi_range 最大变化值
* @param[in] smoothness 变化光滑度
*/
void fractal_model_2d(_2d_matrix &out_arr, int r_size, int c_size, double dl_val,
double dr_val, double ul_val, double ur_val, double maxi_range, double smoothness, unsigned int seed = 0);
/**
* @brief 一维数组差分(使用二阶差分公式)
*
* 计算一个一维数组中相邻元素间的差分结果(求导)。
*
* @param[in] in 输入数组
* @param diff 输出的差分结果
* @param[in] spacing 相邻元素的距离
* @param[in] order 求导的次数。最小为1(默认),最大为4。两边的数据将分别使用对应的向前或向后差分公式
*/
void difference_1d(const array &in, array &diff, double spacing, int order = 1);
/**
* @brief 二维数组差分(使用二阶差分公式)
*
* 计算一个二维数组中相邻元素间的差分结果(求导)。
*
* @param[in] in 输入数组
* @param diff 输出的差分结果
* @param[in] spacing 相邻元素对应方向的距离
* @param[in] d_type 求导的类型
* @param[in] order 求导的次数。最小为1(默认),最大为4。边缘的数据将分别使用对应的向前或向后差分公式
*/
void difference_2d(const _2d_matrix &in, _2d_matrix &diff, double spacing, gradient_type_e d_type, int order = 1);
/**
* @brief 二维数组差分(使用二阶差分公式)
*
* 计算一个二维数组中相邻元素间的差分结果(求导)。数组以列优先的方式储存为一个一维数组
*
* @param[in] in 输入数组
* @param diff 输出的差分结果
* @param[in] row_size 数组二维排列的行数
* @param[in] col_size 数组二维排列的列数
* @param[in] spacing 相邻元素对应方向的距离
* @param[in] d_type 求导的类型
* @param[in] order 求导的次数。最小为1(默认),最大为4。边缘的数据将分别使用对应的向前或向后差分公式
*/
void difference_2d(const array &in, array &diff, int row_size, int col_size,
double spacing, gradient_type_e d_type, int order = 1);
};
#endif // _GCTL_ALGORITHM_FUNC_H