gctl_mesh/lib/mesh/regular_grid.h

351 lines
11 KiB
C
Raw Normal View History

2024-09-10 20:02:00 +08:00
/********************************************************
*
*
*
*
*
*
* 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 <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_REGULAR_GRID_H
#define _GCTL_REGULAR_GRID_H
#include "gctl/graphic.h"
#include "mesh.h"
#ifdef GCTL_MESH_EXPRTK
#include "exprtk.hpp"
#endif // GCTL_MESH_EXPRTK
namespace gctl
{
/**
* @brief
*
*/
class regular_grid : public base_mesh
{
public:
/**
* mesh类型的虚函数实现
*/
2025-01-13 12:08:35 +08:00
/**
* @brief Gmsh文件
*
* @param filename
* @param packed 0
*/
void save_gmsh(std::string filename, index_packed_e packed = Packed);
2024-09-10 20:02:00 +08:00
2025-01-13 12:08:35 +08:00
/**
* @brief
*/
2024-09-10 20:02:00 +08:00
void show_mesh_dimension(std::ostream &os) const;
2025-01-13 12:08:35 +08:00
/**
* @brief
*
* @param filename
*/
2024-09-10 20:02:00 +08:00
void load_binary(std::string filename);
2025-01-13 12:08:35 +08:00
/**
* @brief
*
* @param filename
*/
2024-09-10 20:02:00 +08:00
void save_binary(std::string filename);
/**
* regular_grid的专有函数
*/
2025-01-13 12:08:35 +08:00
regular_grid(); ///< 构造函数
/**
* @brief
*
* @param in_name
* @param in_info
* @param xnum x方向单元数量
* @param ynum y方向单元数量
* @param xmin x方向最小值
* @param ymin y方向最小值
* @param dx x方向单元长度
* @param dy y方向单元长度
*/
2024-09-10 20:02:00 +08:00
regular_grid(std::string in_name, std::string in_info, int xnum, int ynum,
double xmin, double ymin, double dx, double dy);
2025-01-13 12:08:35 +08:00
virtual ~regular_grid(); ///< 析构函数
/**
* @brief
*
* @param in_name
* @param in_info
* @param xnum x方向单元数量
* @param ynum y方向单元数量
* @param xmin x方向最小值
* @param ymin y方向最小值
* @param dx x方向单元长度
* @param dy y方向单元长度
*/
void init(std::string in_name, std::string in_info, int xnum, int ynum,
double xmin, double ymin, double dx, double dy);
/**
* @brief
*/
2024-09-10 20:02:00 +08:00
void clear_regular_grid();
2025-01-13 12:08:35 +08:00
/**
* @brief 使mathgl显示规则网格
*
* @param datname
* @return
*/
2024-09-10 20:02:00 +08:00
int view(std::string datname);
2025-01-13 12:08:35 +08:00
/**
* @brief 使gmt绘制规则网格
*
* @param datname
*/
2024-09-10 20:02:00 +08:00
void plot(std::string datname);
2025-01-13 12:08:35 +08:00
int get_xdim() const; ///< 获取规则网格的x方向单元数量
int get_ydim() const; ///< 获取规则网格的y方向单元数量
double get_xmin() const; ///< 获取规则网格的x方向最小值
double get_ymin() const; ///< 获取规则网格的y方向最小值
double get_dx() const; ///< 获取规则网格的x方向单元长度
double get_dy() const; ///< 获取规则网格的y方向单元长度
2024-09-10 20:02:00 +08:00
#ifdef GCTL_NETCDF
2025-01-13 12:08:35 +08:00
/**
* @brief netcdf文件中读取规则网格数据
*
* @param filename
* @param d_type
* @param xname x坐标变量名
* @param yname y坐标变量名
* @param zname z坐标变量名
*/
2024-09-10 20:02:00 +08:00
void load_netcdf_grid(std::string filename, mesh_data_type_e d_type,
std::string xname = "x", std::string yname = "y", std::string zname = "null");
2025-01-13 12:08:35 +08:00
/**
* @brief netcdf文件中
*
* @param filename
* @param d_type
* @param xname x坐标变量名
* @param yname y坐标变量名
*/
2024-10-07 21:09:58 +08:00
void save_netcdf_grid(std::string filename, mesh_data_type_e d_type,
std::string xname = "x", std::string yname = "y");
2025-01-13 12:08:35 +08:00
/**
* @brief netcdf文件中
*
* @param filename
* @param datname
* @param xname x坐标变量名
* @param yname y坐标变量名
*/
2024-10-07 21:09:58 +08:00
void save_netcdf_grid(std::string filename, std::string datname,
std::string xname = "x", std::string yname = "y");
2024-09-10 20:02:00 +08:00
#endif // GCTL_NETCDF
2025-01-13 12:08:35 +08:00
/**
* @brief surfer文件中读取规则网格数据
*
* @param filename
* @param datname
* @param d_type
* @param grid_type
*/
2024-09-10 20:02:00 +08:00
void load_surfer_grid(std::string filename, std::string datname, mesh_data_type_e d_type, surfer_file_type_e grid_type = Surfer7Grid);
2025-01-13 12:08:35 +08:00
/**
* @brief surfer文件中
*
* @param filename
* @param datname
* @param grid_type
*/
2024-09-10 20:02:00 +08:00
void save_surfer_grid(std::string filename, std::string datname, surfer_file_type_e grid_type = Surfer7Grid);
2025-01-13 12:08:35 +08:00
/**
* @brief Gmsh文件中
*
* @param filename
* @param out_mode
* @param packed 0
*/
2025-01-12 23:39:36 +08:00
void save_gmsh(std::string filename, output_type_e out_mode, index_packed_e packed = Packed);
2025-01-13 12:08:35 +08:00
/**
* @brief Gmsh文件中
*
* @param filename
* @param datname
* @param out_mode
* @param packed 0
*/
2024-09-10 20:02:00 +08:00
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
2025-01-13 12:08:35 +08:00
/**
* @brief
*
* @param filename
* @param datname
*/
2024-09-10 20:02:00 +08:00
void save_text(std::string filename, const array<std::string> &datname);
2025-01-13 12:08:35 +08:00
/**
* @brief
*
* @param in_posi
* @param in_val
* @param search_xlen x方向长度
* @param search_ylen y方向长度
* @param search_deg
* @param datname
* @param d_type
*/
2024-09-10 20:02:00 +08:00
void load_data_cloud(const array<point2dc> &in_posi, const array<double> &in_val, double search_xlen,
double search_ylen, double search_deg, std::string datname, mesh_data_type_e d_type = NodeData);
2025-01-13 12:08:35 +08:00
/**
* @brief
*
* @param datname
* @param in_posi
* @param out_val
*/
2024-09-10 20:02:00 +08:00
void extract_points(std::string datname, const array<point2dc> &in_posi, array<double> &out_val);
2025-01-13 12:08:35 +08:00
/**
* @brief
*
* @param datname
* @param start_p
* @param end_p
* @param size_p
* @param out_posi
* @param out_val
*/
2024-09-10 20:02:00 +08:00
void extract_profile(std::string datname, const point2dc &start_p, const point2dc &end_p, int size_p,
array<point2dc> &out_posi, array<double> &out_val);
2025-01-13 12:08:35 +08:00
/**
* @brief
*
* @param datname
* @param gradname
* @param d_type
* @param order
*/
2024-09-10 20:02:00 +08:00
void gradient(std::string datname, std::string gradname, gradient_type_e d_type, int order = 1);
2025-01-13 12:08:35 +08:00
/**
* @brief
*
* @param newname
* @param datname
* @param datname2 2
*/
2024-09-10 20:02:00 +08:00
void sum(std::string newname, std::string datname, std::string datname2);
2025-01-13 12:08:35 +08:00
/**
* @brief
*
* @param newname
* @param datname
* @param datname2 2
*/
2024-09-10 20:02:00 +08:00
void diff(std::string newname, std::string datname, std::string datname2);
2025-01-13 12:08:35 +08:00
/**
* @brief
*
* @param newname
* @param datname
* @param maskname
* @param reverse
*/
2024-09-10 20:02:00 +08:00
void boolean(std::string newname, std::string datname, std::string maskname, bool reverse = false);
#ifdef GCTL_MESH_EXPRTK
2025-01-13 12:08:35 +08:00
/**
* @brief f为节点位置xy
*
* @param expression_str
* @param newname
* @param x_str x变量名称
* @param y_str y变量名称
* @param f_str f变量名称
*/
2024-09-10 20:02:00 +08:00
void function(std::string expression_str, std::string newname, std::string x_str = "x", std::string y_str = "y", std::string f_str = "f");
2025-01-13 12:08:35 +08:00
/**
* @brief
*
* @param expression_str
* @param var_list
* @param data_list
*/
2024-09-10 20:02:00 +08:00
void calculator(std::string expression_str, const array<std::string> &var_list, const array<std::string> &data_list);
2025-01-13 12:08:35 +08:00
2024-09-10 20:02:00 +08:00
#endif // GCTL_MESH_EXPRTK
#ifdef GCTL_MESH_WAVELIB
2025-01-13 12:08:35 +08:00
/**
* @brief
*
* @param datname
* @param wavename
* @param order
* @param summary
*/
2024-09-10 20:02:00 +08:00
void wavelet(std::string datname, std::string wavename, int order, bool summary = true);
2025-01-13 12:08:35 +08:00
2024-09-10 20:02:00 +08:00
#endif // GCTL_MESH_WAVELIB
protected:
2025-01-13 12:08:35 +08:00
int rg_xnum, rg_ynum; ///< 规则网格的x方向单元数量和y方向单元数量
double rg_xmin, rg_ymin; ///< 规则网格的x方向最小值和y方向最小值
double rg_dx, rg_dy; ///< 规则网格的x方向单元长度和y方向单元长度
2024-09-10 20:02:00 +08:00
2025-01-13 12:08:35 +08:00
array<vertex2dc> nodes; ///< 规则网格的节点数组
array<rectangle2d> elements; ///< 规则网格的单元数组
2024-09-10 20:02:00 +08:00
};
}
#endif //_GCTL_REGULAR_GRID_H