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.
|
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
|
|
#include "regular_mesh_2d.h"
|
|
|
|
|
|
|
|
|
|
void gctl::regular_mesh_2d::init(std::string in_name, std::string in_info, int xbnum, int ybnum,
|
|
|
|
|
double xmin, double ymin, double xsize, double ysize)
|
|
|
|
|
{
|
2025-01-12 23:39:36 +08:00
|
|
|
|
check_initiated(true); // 检查网格是否已经初始化
|
2024-09-10 20:02:00 +08:00
|
|
|
|
base_mesh::init(REGULAR_MESH, MESH_2D, in_name, in_info);
|
|
|
|
|
|
|
|
|
|
rm_xbnum = xbnum; rm_ybnum = ybnum;
|
|
|
|
|
rm_xmin = xmin; rm_ymin = ymin;
|
|
|
|
|
rm_xsize = xsize; rm_ysize = ysize;
|
|
|
|
|
|
2025-01-12 23:39:36 +08:00
|
|
|
|
node_num_ = (rm_xbnum+1) * (rm_ybnum+1);
|
|
|
|
|
ele_num_ = rm_xbnum * rm_ybnum;
|
2024-09-10 20:02:00 +08:00
|
|
|
|
|
2025-01-12 23:39:36 +08:00
|
|
|
|
nodes.resize(node_num_);
|
|
|
|
|
elements.resize(ele_num_);
|
2024-09-10 20:02:00 +08:00
|
|
|
|
|
|
|
|
|
for (int j = 0; j < rm_ybnum+1; j++)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < rm_xbnum+1; i++)
|
|
|
|
|
{
|
|
|
|
|
nodes[i+j*(rm_xbnum+1)].id = i+j*(rm_xbnum+1);
|
|
|
|
|
nodes[i+j*(rm_xbnum+1)].x = rm_xmin+(i-0.5)*rm_xsize;
|
|
|
|
|
nodes[i+j*(rm_xbnum+1)].y = rm_ymin+(j-0.5)*rm_ysize;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < rm_ybnum; j++)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < rm_xbnum; i++)
|
|
|
|
|
{
|
|
|
|
|
elements[i+j*rm_xbnum].id = i+j*rm_xbnum;
|
|
|
|
|
elements[i+j*rm_xbnum].vert[0] = nodes.get(i+j*(rm_xbnum+1));
|
|
|
|
|
elements[i+j*rm_xbnum].vert[1] = nodes.get(i+1+j*(rm_xbnum+1));
|
|
|
|
|
elements[i+j*rm_xbnum].vert[2] = nodes.get(i+1+(j+1)*(rm_xbnum+1));
|
|
|
|
|
elements[i+j*rm_xbnum].vert[3] = nodes.get(i+(j+1)*(rm_xbnum+1));
|
|
|
|
|
elements[i+j*rm_xbnum].dl = nodes.get(i+j*(rm_xbnum+1));
|
|
|
|
|
elements[i+j*rm_xbnum].ur = nodes.get(i+1+(j+1)*(rm_xbnum+1));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-12 23:39:36 +08:00
|
|
|
|
initialized_ = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gctl::regular_mesh_2d::show_mesh_dimension(std::ostream &os) const
|
|
|
|
|
{
|
|
|
|
|
os << "node num: " << node_num_ << std::endl;
|
|
|
|
|
os << "elem num: " << ele_num_ << std::endl;
|
|
|
|
|
os << "x-range: " << rm_xmin << " -> " << rm_xmin + (rm_xbnum - 1)*rm_xsize << "\n";
|
|
|
|
|
os << "y-range: " << rm_ymin << " -> " << rm_ymin + (rm_ybnum - 1)*rm_ysize << "\n";
|
|
|
|
|
os << "block-size: " << rm_xsize << ", " << rm_ysize << "\n";
|
|
|
|
|
os << "dimension: " << rm_xbnum << ", " << rm_ybnum << "\n";
|
2024-09-10 20:02:00 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gctl::regular_mesh_2d::load_binary(std::string filename)
|
|
|
|
|
{
|
2025-01-12 23:39:36 +08:00
|
|
|
|
check_initiated(true); // 检查网格是否已经初始化(如果已经初始化,那么就会抛出异常)
|
2024-09-10 20:02:00 +08:00
|
|
|
|
|
|
|
|
|
std::ifstream infile;
|
|
|
|
|
gctl::open_infile(infile, filename, ".2m",
|
|
|
|
|
std::ios::in|std::ios::binary);
|
|
|
|
|
|
|
|
|
|
// 读入网格头信息
|
|
|
|
|
load_headinfo(infile, REGULAR_MESH, MESH_2D);
|
|
|
|
|
|
|
|
|
|
// 读入网格信息
|
|
|
|
|
infile.read((char*)&rm_xbnum, sizeof(int));
|
|
|
|
|
infile.read((char*)&rm_ybnum, sizeof(int));
|
|
|
|
|
infile.read((char*)&rm_xmin, sizeof(double));
|
|
|
|
|
infile.read((char*)&rm_ymin, sizeof(double));
|
|
|
|
|
infile.read((char*)&rm_xsize, sizeof(double));
|
|
|
|
|
infile.read((char*)&rm_ysize, sizeof(double));
|
|
|
|
|
|
2025-01-12 23:39:36 +08:00
|
|
|
|
node_num_ = (rm_xbnum+1) * (rm_ybnum+1);
|
|
|
|
|
ele_num_ = rm_xbnum * rm_ybnum;
|
2024-09-10 20:02:00 +08:00
|
|
|
|
|
2025-01-12 23:39:36 +08:00
|
|
|
|
nodes.resize(node_num_);
|
|
|
|
|
elements.resize(ele_num_);
|
2024-09-10 20:02:00 +08:00
|
|
|
|
|
|
|
|
|
for (int j = 0; j < rm_ybnum+1; j++)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < rm_xbnum+1; i++)
|
|
|
|
|
{
|
|
|
|
|
nodes[i+j*(rm_xbnum+1)].id = i+j*(rm_xbnum+1);
|
|
|
|
|
nodes[i+j*(rm_xbnum+1)].x = rm_xmin+(i-0.5)*rm_xsize;
|
|
|
|
|
nodes[i+j*(rm_xbnum+1)].y = rm_ymin+(j-0.5)*rm_ysize;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < rm_ybnum; j++)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < rm_xbnum; i++)
|
|
|
|
|
{
|
|
|
|
|
elements[i+j*rm_xbnum].id = i+j*rm_xbnum;
|
|
|
|
|
elements[i+j*rm_xbnum].vert[0] = nodes.get(i+j*(rm_xbnum+1));
|
|
|
|
|
elements[i+j*rm_xbnum].vert[1] = nodes.get(i+1+j*(rm_xbnum+1));
|
|
|
|
|
elements[i+j*rm_xbnum].vert[2] = nodes.get(i+1+(j+1)*(rm_xbnum+1));
|
|
|
|
|
elements[i+j*rm_xbnum].vert[3] = nodes.get(i+(j+1)*(rm_xbnum+1));
|
|
|
|
|
elements[i+j*rm_xbnum].dl = nodes.get(i+j*(rm_xbnum+1));
|
|
|
|
|
elements[i+j*rm_xbnum].ur = nodes.get(i+1+(j+1)*(rm_xbnum+1));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 读入模型数据单元
|
|
|
|
|
load_datablock(infile);
|
|
|
|
|
|
|
|
|
|
infile.close();
|
2025-01-12 23:39:36 +08:00
|
|
|
|
initialized_ = true;
|
2024-09-10 20:02:00 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gctl::regular_mesh_2d::save_binary(std::string filename)
|
|
|
|
|
{
|
2025-01-12 23:39:36 +08:00
|
|
|
|
check_initiated(); // 检查网格是否已经初始化
|
2024-09-10 20:02:00 +08:00
|
|
|
|
|
|
|
|
|
std::ofstream outfile;
|
|
|
|
|
gctl::open_outfile(outfile, filename, ".2m",
|
|
|
|
|
std::ios::out|std::ios::binary);
|
|
|
|
|
|
|
|
|
|
// 首先输出网格的头信息
|
|
|
|
|
save_headinfo(outfile);
|
|
|
|
|
|
|
|
|
|
// 输出网格信息
|
|
|
|
|
outfile.write((char*)&rm_xbnum, sizeof(int));
|
|
|
|
|
outfile.write((char*)&rm_ybnum, sizeof(int));
|
|
|
|
|
outfile.write((char*)&rm_xmin, sizeof(double));
|
|
|
|
|
outfile.write((char*)&rm_ymin, sizeof(double));
|
|
|
|
|
outfile.write((char*)&rm_xsize, sizeof(double));
|
|
|
|
|
outfile.write((char*)&rm_ysize, sizeof(double));
|
|
|
|
|
|
|
|
|
|
// 输出的模型数据单元
|
|
|
|
|
save_datablock(outfile);
|
|
|
|
|
|
|
|
|
|
outfile.close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gctl::regular_mesh_2d::regular_mesh_2d() : base_mesh::base_mesh(){}
|
|
|
|
|
|
|
|
|
|
gctl::regular_mesh_2d::regular_mesh_2d(std::string in_name, std::string in_info, int xbnum, int ybnum,
|
|
|
|
|
double xmin, double ymin, double xsize, double ysize)
|
|
|
|
|
{
|
|
|
|
|
init(in_name, in_info, xbnum, ybnum, xmin, ymin, xsize, ysize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gctl::regular_mesh_2d::~regular_mesh_2d(){}
|
|
|
|
|
|
|
|
|
|
int gctl::regular_mesh_2d::get_xbnum() const
|
|
|
|
|
{
|
2025-01-12 23:39:36 +08:00
|
|
|
|
check_initiated(); // 检查网格是否已经初始化
|
2024-09-10 20:02:00 +08:00
|
|
|
|
return rm_xbnum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int gctl::regular_mesh_2d::get_ybnum() const
|
|
|
|
|
{
|
2025-01-12 23:39:36 +08:00
|
|
|
|
check_initiated(); // 检查网格是否已经初始化
|
2024-09-10 20:02:00 +08:00
|
|
|
|
return rm_ybnum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double gctl::regular_mesh_2d::get_xmin() const
|
|
|
|
|
{
|
2025-01-12 23:39:36 +08:00
|
|
|
|
check_initiated(); // 检查网格是否已经初始化
|
2024-09-10 20:02:00 +08:00
|
|
|
|
return rm_xmin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double gctl::regular_mesh_2d::get_ymin() const
|
|
|
|
|
{
|
2025-01-12 23:39:36 +08:00
|
|
|
|
check_initiated(); // 检查网格是否已经初始化
|
2024-09-10 20:02:00 +08:00
|
|
|
|
return rm_ymin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double gctl::regular_mesh_2d::get_xsize() const
|
|
|
|
|
{
|
2025-01-12 23:39:36 +08:00
|
|
|
|
check_initiated(); // 检查网格是否已经初始化
|
2024-09-10 20:02:00 +08:00
|
|
|
|
return rm_xsize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double gctl::regular_mesh_2d::get_ysize() const
|
|
|
|
|
{
|
2025-01-12 23:39:36 +08:00
|
|
|
|
check_initiated(); // 检查网格是否已经初始化
|
2024-09-10 20:02:00 +08:00
|
|
|
|
return rm_ysize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gctl::regular_mesh_2d::save_gmsh(std::string filename, index_packed_e packed)
|
|
|
|
|
{
|
|
|
|
|
std::ofstream outfile;
|
|
|
|
|
gctl::open_outfile(outfile, filename, ".msh");
|
|
|
|
|
gctl::save2gmsh(outfile, elements, nodes, packed);
|
|
|
|
|
outfile.close();
|
|
|
|
|
return;
|
2025-01-17 16:34:58 +08:00
|
|
|
|
}
|