redesigned meshdata and mesh
This commit is contained in:
parent
1145d8a3eb
commit
bad10fb6f4
864
backup/mesh.cpp
Normal file
864
backup/mesh.cpp
Normal file
@ -0,0 +1,864 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* 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 "mesh.h"
|
||||||
|
|
||||||
|
gctl::base_mesh::base_mesh()
|
||||||
|
{
|
||||||
|
initialized = false;
|
||||||
|
//std::clog << "A new mesh object is created." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::base_mesh::~base_mesh()
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
//std::clog << "A mesh object is destroyed." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::clear()
|
||||||
|
{
|
||||||
|
meshdata *data_ptr;
|
||||||
|
if (!saved_data.empty())
|
||||||
|
{
|
||||||
|
for (iter = saved_data.begin(); iter != saved_data.end(); ++iter)
|
||||||
|
{
|
||||||
|
data_ptr = *iter;
|
||||||
|
meshdata::destroy(data_ptr);
|
||||||
|
}
|
||||||
|
saved_data.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
initialized = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool gctl::base_mesh::initiated() const
|
||||||
|
{
|
||||||
|
return initialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool gctl::base_mesh::saved(std::string datname) const
|
||||||
|
{
|
||||||
|
if (saved_data.empty())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
meshdata *data_ptr = nullptr;
|
||||||
|
// 这里我们需要使用常量迭代器
|
||||||
|
std::list<meshdata*>::const_iterator c_iter;
|
||||||
|
for (c_iter = saved_data.begin(); c_iter != saved_data.end(); ++c_iter)
|
||||||
|
{
|
||||||
|
data_ptr = *c_iter;
|
||||||
|
if (data_ptr->get_datname() == datname)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::meshdata *gctl::base_mesh::get_data(std::string datname) const
|
||||||
|
{
|
||||||
|
if (saved_data.empty())
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] No data saved.");
|
||||||
|
}
|
||||||
|
|
||||||
|
meshdata *curr_data = nullptr;
|
||||||
|
std::list<meshdata*>::const_iterator c_iter;
|
||||||
|
for (c_iter = saved_data.begin(); c_iter != saved_data.end(); ++c_iter)
|
||||||
|
{
|
||||||
|
curr_data = *c_iter;
|
||||||
|
if (curr_data->get_datname() == datname)
|
||||||
|
{
|
||||||
|
return curr_data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw gctl::runtime_error("[gctl::base_mesh] No data found by the name: " + datname);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::get_all_data(array<meshdata*>& out_list) const
|
||||||
|
{
|
||||||
|
if (saved_data.empty())
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] No data saved.");
|
||||||
|
}
|
||||||
|
|
||||||
|
int c_count = 0;
|
||||||
|
out_list.resize(saved_data.size());
|
||||||
|
|
||||||
|
meshdata *curr_data = nullptr;
|
||||||
|
std::list<meshdata*>::const_iterator c_iter;
|
||||||
|
for (c_iter = saved_data.begin(); c_iter != saved_data.end(); ++c_iter)
|
||||||
|
{
|
||||||
|
curr_data = *c_iter;
|
||||||
|
out_list[c_count] = curr_data;
|
||||||
|
c_count++;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *gctl::base_mesh::get_datval(std::string datname) const
|
||||||
|
{
|
||||||
|
meshdata *curr_data = get_data(datname);
|
||||||
|
return curr_data->get_datval_ptr();
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::remove_data(std::string datname)
|
||||||
|
{
|
||||||
|
if (saved_data.empty())
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] No data saved.");
|
||||||
|
}
|
||||||
|
|
||||||
|
meshdata *curr_data;
|
||||||
|
for (iter = saved_data.begin(); iter != saved_data.end(); ++iter)
|
||||||
|
{
|
||||||
|
curr_data = *iter;
|
||||||
|
if (curr_data->get_datname() == datname)
|
||||||
|
{
|
||||||
|
meshdata::destroy(curr_data);
|
||||||
|
iter = saved_data.erase(iter);
|
||||||
|
//std::clog << "Meshdata: " << datname << " is destroyed." << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::show_info(std::ostream &os) const
|
||||||
|
{
|
||||||
|
if (meshtype == REGULAR_MESH) os << "Mesh: Regular | ";
|
||||||
|
if (meshtype == LINEAR_MESH) os << "Mesh: Linear | ";
|
||||||
|
if (meshtype == TRI_TET_MESH) os << "Mesh: Unstructured | ";
|
||||||
|
if (meshtype == REGULAR_MESH_SPH) os << "Mesh: Regular (spherical) | ";
|
||||||
|
if (meshtype == LINEAR_MESH_SPH) os << "Mesh: Linear (spherical) | ";
|
||||||
|
if (meshtype == TRI_TET_MESH_SPH) os << "Mesh: Unstructured (spherical) | ";
|
||||||
|
if (meshtype == REGULAR_GRID) os << "Mesh: Grid | ";
|
||||||
|
|
||||||
|
if (meshdim == MESH_2D) os << "2D" << std::endl;
|
||||||
|
else if (meshdim == MESH_3D) os << "3D" << std::endl;
|
||||||
|
|
||||||
|
os << "Name: " << meshname << std::endl;
|
||||||
|
os << "Info: " << meshinfo << std::endl;
|
||||||
|
|
||||||
|
show_mesh_dimension(os);
|
||||||
|
|
||||||
|
meshdata *curr_data;
|
||||||
|
std::list<meshdata*>::const_iterator c_iter;
|
||||||
|
for (c_iter = saved_data.begin(); c_iter != saved_data.end(); ++c_iter)
|
||||||
|
{
|
||||||
|
curr_data = *c_iter;
|
||||||
|
curr_data->show_info();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::rename_data(std::string oldname, std::string newname)
|
||||||
|
{
|
||||||
|
meshdata *curr_data = get_data(oldname);
|
||||||
|
curr_data->set_datname(newname);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::mesh_type_e gctl::base_mesh::get_meshtype() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return meshtype;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::mesh_dim_e gctl::base_mesh::get_meshdim() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return meshdim;
|
||||||
|
}
|
||||||
|
|
||||||
|
int gctl::base_mesh::get_nodenum() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return node_num;
|
||||||
|
}
|
||||||
|
|
||||||
|
int gctl::base_mesh::get_elenum() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ele_num;
|
||||||
|
}
|
||||||
|
|
||||||
|
int gctl::base_mesh::get_datanum() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return saved_data.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string gctl::base_mesh::get_meshname() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return meshname;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::set_meshname(std::string in_name)
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_name.empty())
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] The input name is empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
meshname = in_name;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string gctl::base_mesh::get_meshinfo() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return meshinfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::set_meshinfo(std::string in_info)
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_info == "")
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] The input info. is empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
meshinfo = in_info;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::meshdata *gctl::base_mesh::add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, double init_val)
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
meshdata *data_ptr;
|
||||||
|
if(saved(in_name))
|
||||||
|
{
|
||||||
|
data_ptr = get_data(in_name);
|
||||||
|
if (data_ptr->get_valtype() != Scalar || data_ptr->get_dattype() != in_type)
|
||||||
|
{
|
||||||
|
throw gctl::runtime_error("[gctl::base_mesh] A data object is already created with a different data or value type by the name:" + in_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 存在一个同名 同数据类型 同赋值类型的数据 则将其数据设置为初始值
|
||||||
|
array<double>* val_ptr = (array<double>*) data_ptr->get_datval_ptr();
|
||||||
|
val_ptr->assign_all(init_val);
|
||||||
|
return data_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_type == NodeData)
|
||||||
|
{
|
||||||
|
data_ptr = meshdata_scalar::create(in_name, in_type, node_num, if_output, init_val);
|
||||||
|
}
|
||||||
|
else if (in_type == ElemData || in_type == ElemData2D || in_type == ElemData3D)
|
||||||
|
{
|
||||||
|
data_ptr = meshdata_scalar::create(in_name, in_type, ele_num, if_output, init_val);
|
||||||
|
}
|
||||||
|
|
||||||
|
saved_data.push_back(data_ptr);
|
||||||
|
return data_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::meshdata *gctl::base_mesh::add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, gctl::point3dc init_val)
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
meshdata *data_ptr;
|
||||||
|
if(saved(in_name))
|
||||||
|
{
|
||||||
|
data_ptr = get_data(in_name);
|
||||||
|
if (data_ptr->get_valtype() != Scalar || data_ptr->get_dattype() != in_type)
|
||||||
|
{
|
||||||
|
throw gctl::runtime_error("[gctl::base_mesh] A data object is already created with a different data or value type by the name:" + in_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 存在一个同名 同数据类型 同赋值类型的数据 则将其数据设置为初始值
|
||||||
|
array<point3dc>* val_ptr = (array<point3dc>*) data_ptr->get_datval_ptr();
|
||||||
|
val_ptr->assign_all(init_val);
|
||||||
|
return data_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_type == NodeData)
|
||||||
|
{
|
||||||
|
data_ptr = meshdata_vector::create(in_name, in_type, node_num, if_output, init_val);
|
||||||
|
}
|
||||||
|
else if (in_type == ElemData || in_type == ElemData2D || in_type == ElemData3D)
|
||||||
|
{
|
||||||
|
data_ptr = meshdata_vector::create(in_name, in_type, ele_num, if_output, init_val);
|
||||||
|
}
|
||||||
|
|
||||||
|
saved_data.push_back(data_ptr);
|
||||||
|
return data_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::meshdata *gctl::base_mesh::add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, gctl::tensor init_val)
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
meshdata *data_ptr;
|
||||||
|
if(saved(in_name))
|
||||||
|
{
|
||||||
|
data_ptr = get_data(in_name);
|
||||||
|
if (data_ptr->get_valtype() != Scalar || data_ptr->get_dattype() != in_type)
|
||||||
|
{
|
||||||
|
throw gctl::runtime_error("[gctl::base_mesh] A data object is already created with a different data or value type by the name:" + in_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 存在一个同名 同数据类型 同赋值类型的数据 则将其数据设置为初始值
|
||||||
|
array<tensor>* val_ptr = (array<tensor>*) data_ptr->get_datval_ptr();
|
||||||
|
val_ptr->assign_all(init_val);
|
||||||
|
return data_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_type == NodeData)
|
||||||
|
{
|
||||||
|
data_ptr = meshdata_tensor::create(in_name, in_type, node_num, if_output, init_val);
|
||||||
|
}
|
||||||
|
else if (in_type == ElemData || in_type == ElemData2D || in_type == ElemData3D)
|
||||||
|
{
|
||||||
|
data_ptr = meshdata_tensor::create(in_name, in_type, ele_num, if_output, init_val);
|
||||||
|
}
|
||||||
|
|
||||||
|
saved_data.push_back(data_ptr);
|
||||||
|
return data_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::meshdata *gctl::base_mesh::add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, mesh_data_value_e val_type)
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
meshdata *data_ptr;
|
||||||
|
if(saved(in_name))
|
||||||
|
{
|
||||||
|
data_ptr = get_data(in_name);
|
||||||
|
if (data_ptr->get_valtype() != Scalar || data_ptr->get_dattype() != in_type)
|
||||||
|
{
|
||||||
|
throw gctl::runtime_error("[gctl::base_mesh] A data object is already created with a different data or value type by the name:" + in_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return data_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (val_type == Scalar && in_type == NodeData)
|
||||||
|
{
|
||||||
|
data_ptr = meshdata_scalar::create(in_name, in_type, node_num, if_output, 0.0);
|
||||||
|
}
|
||||||
|
else if (val_type == Scalar && in_type == ElemData)
|
||||||
|
{
|
||||||
|
data_ptr = meshdata_scalar::create(in_name, in_type, ele_num, if_output, 0.0);
|
||||||
|
}
|
||||||
|
else if (val_type == Vector && in_type == NodeData)
|
||||||
|
{
|
||||||
|
point3dc init_val = {0.0, 0.0, 0.0};
|
||||||
|
data_ptr = meshdata_vector::create(in_name, in_type, node_num, if_output, init_val);
|
||||||
|
}
|
||||||
|
else if (val_type == Vector && in_type == ElemData)
|
||||||
|
{
|
||||||
|
point3dc init_val = {0.0, 0.0, 0.0};
|
||||||
|
data_ptr = meshdata_vector::create(in_name, in_type, ele_num, if_output, init_val);
|
||||||
|
}
|
||||||
|
else if (val_type == Tensor && in_type == NodeData)
|
||||||
|
{
|
||||||
|
tensor init_val = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
|
||||||
|
data_ptr = meshdata_tensor::create(in_name, in_type, node_num, if_output, init_val);
|
||||||
|
}
|
||||||
|
else if (val_type == Tensor && in_type == ElemData)
|
||||||
|
{
|
||||||
|
tensor init_val = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
|
||||||
|
data_ptr = meshdata_tensor::create(in_name, in_type, ele_num, if_output, init_val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
saved_data.push_back(data_ptr);
|
||||||
|
return data_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::init(std::string in_name, std::string in_info, int xnum, int ynum,
|
||||||
|
double xmin, double ymin, double dx, double dy)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::init(std::string in_name, std::string in_info, int xbnum, int ybnum, int zbnum,
|
||||||
|
double xmin, double ymin, double zmin, double xsize, double ysize, double zsize)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::init(std::string in_name, std::string in_info, double lon_min, double lat_min,
|
||||||
|
double rad_min, double lon_size, double lat_size, double rad_size, int lon_bnum, int lat_bnum, int rad_bnum)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::init(std::string in_name, std::string in_info, double xmin, double ymin,
|
||||||
|
const gctl::array<double> &xsizes, const gctl::array<double> &ysizes)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::init(std::string in_name, std::string in_info, double xmin, double ymin,
|
||||||
|
double zmin, const gctl::array<double> &xsizes, const gctl::array<double> &ysizes,
|
||||||
|
const gctl::array<double> &zsizes)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::init(std::string in_name, std::string in_info, const gctl::array<gctl::vertex2dc> &in_nodes,
|
||||||
|
const gctl::array<gctl::triangle2d> &in_triangles)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::init(std::string in_name, std::string in_info, const gctl::array<gctl::vertex3dc> &in_nodes,
|
||||||
|
const gctl::array<gctl::tetrahedron> &in_tets)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::show_mesh_dimension(std::ostream &os) const
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::save_gmsh(std::string filename, index_packed_e packed)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed)
|
||||||
|
{
|
||||||
|
if (out_mode == OverWrite) save_gmsh(filename, packed);
|
||||||
|
|
||||||
|
std::ofstream outfile;
|
||||||
|
gctl::open_outfile(outfile, filename, ".msh", std::ios::out|std::ios::app);
|
||||||
|
|
||||||
|
meshdata *curr_data;
|
||||||
|
for (iter = saved_data.begin(); iter != saved_data.end(); ++iter)
|
||||||
|
{
|
||||||
|
curr_data = *iter;
|
||||||
|
if (curr_data->get_dattype() == d_type && d_type == NodeData &&
|
||||||
|
curr_data->get_valtype() == Scalar && curr_data->get_output())
|
||||||
|
{
|
||||||
|
gctl::array<double> *data_ptr = (gctl::array<double>*) curr_data->get_datval_ptr();
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname(), *data_ptr, gctl::NodeData, packed);
|
||||||
|
}
|
||||||
|
else if (curr_data->get_dattype() == d_type && d_type == ElemData &&
|
||||||
|
curr_data->get_valtype() == Scalar && curr_data->get_output())
|
||||||
|
{
|
||||||
|
gctl::array<double> *data_ptr = (gctl::array<double>*) curr_data->get_datval_ptr();
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname(), *data_ptr, gctl::ElemData, packed);
|
||||||
|
}
|
||||||
|
else if (curr_data->get_dattype() == d_type && d_type == NodeData &&
|
||||||
|
curr_data->get_valtype() == Vector && curr_data->get_output())
|
||||||
|
{
|
||||||
|
gctl::array<gctl::point3dc> *data_ptr = (gctl::array<gctl::point3dc>*) curr_data->get_datval_ptr();
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname(), *data_ptr, gctl::NodeData, packed);
|
||||||
|
}
|
||||||
|
else if (curr_data->get_dattype() == d_type && d_type == ElemData &&
|
||||||
|
curr_data->get_valtype() == Vector && curr_data->get_output())
|
||||||
|
{
|
||||||
|
gctl::array<gctl::point3dc> *data_ptr = (gctl::array<gctl::point3dc>*) curr_data->get_datval_ptr();
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname(), *data_ptr, gctl::ElemData, packed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
outfile.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed)
|
||||||
|
{
|
||||||
|
meshdata *curr_data = get_data(datname);
|
||||||
|
|
||||||
|
if (!curr_data->get_output())
|
||||||
|
{
|
||||||
|
throw gctl::runtime_error("[gctl::base_mesh] Output is disabled for the data:" + datname);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (out_mode == OverWrite) save_gmsh(filename, packed);
|
||||||
|
|
||||||
|
std::ofstream outfile;
|
||||||
|
gctl::open_outfile(outfile, filename, ".msh", std::ios::out|std::ios::app);
|
||||||
|
|
||||||
|
if (curr_data->get_valtype() == Scalar)
|
||||||
|
{
|
||||||
|
gctl::array<double> *data_ptr = (gctl::array<double>*) curr_data->get_datval_ptr();
|
||||||
|
if (curr_data->get_dattype() == NodeData)
|
||||||
|
{
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname(), *data_ptr, gctl::NodeData, packed);
|
||||||
|
}
|
||||||
|
else if (curr_data->get_dattype() == ElemData)
|
||||||
|
{
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname(), *data_ptr, gctl::ElemData, packed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (curr_data->get_valtype() == Vector)
|
||||||
|
{
|
||||||
|
gctl::array<gctl::point3dc> *data_ptr = (gctl::array<gctl::point3dc>*) curr_data->get_datval_ptr();
|
||||||
|
if (curr_data->get_dattype() == NodeData)
|
||||||
|
{
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname(), *data_ptr, gctl::NodeData, packed);
|
||||||
|
}
|
||||||
|
else if (curr_data->get_dattype() == ElemData)
|
||||||
|
{
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname(), *data_ptr, gctl::ElemData, packed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (curr_data->get_valtype() == Tensor)
|
||||||
|
{
|
||||||
|
gctl::array<gctl::tensor> *data_ptr = (gctl::array<gctl::tensor>*) curr_data->get_datval_ptr();
|
||||||
|
if (curr_data->get_dattype() == NodeData)
|
||||||
|
{
|
||||||
|
array<double> v(data_ptr->size());
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[0][0];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Txx", v, gctl::NodeData, packed);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[0][1];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Txy", v, gctl::NodeData, packed);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[0][2];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Txz", v, gctl::NodeData, packed);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[1][1];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Tyy", v, gctl::NodeData, packed);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[1][2];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Tyz", v, gctl::NodeData, packed);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[2][2];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Tzz", v, gctl::NodeData, packed);
|
||||||
|
}
|
||||||
|
else if (curr_data->get_dattype() == ElemData)
|
||||||
|
{
|
||||||
|
array<double> v(data_ptr->size());
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[0][0];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Txx", v, gctl::ElemData, packed);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[0][1];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Txy", v, gctl::ElemData, packed);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[0][2];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Txz", v, gctl::ElemData, packed);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[1][1];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Tyy", v, gctl::ElemData, packed);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[1][2];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Tyz", v, gctl::ElemData, packed);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[2][2];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Tzz", v, gctl::ElemData, packed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
outfile.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::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)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::load_data_cloud(const array<point3dc> &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)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::extract_points(std::string datname, const array<point2dc> &in_posi, array<double> &out_val)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::extract_points(std::string datname, const array<point3dc> &in_posi, array<double> &out_val)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::extract_profile(std::string datname, const point2dc &start_p, const point2dc &end_p, int size_p,
|
||||||
|
array<point2dc> &out_posi, array<double> &out_val)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::extract_profile(std::string datname, const point3dc &start_p, const point3dc &end_p, int size_p,
|
||||||
|
double dh, array<point3dc> &out_posi, array<double> &out_val)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::edit_data(std::string datname, physical_type_e p_type, value_operator_e v_type, std::string para_str, double in_val)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::edit_data(std::string datname, physical_type_e p_type, value_operator_e v_type, std::string para_str, point3dc in_val)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::edit_data(std::string datname, physical_type_e p_type, value_operator_e v_type, std::string para_str, tensor in_val)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::purge_data(std::string datname, double in_val)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::purge_data(std::string datname, point3dc in_val)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::purge_data(std::string datname, tensor in_val)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以下是类的私有函数,可以简单一些
|
||||||
|
*/
|
||||||
|
|
||||||
|
void gctl::base_mesh::init(mesh_type_e in_type, mesh_dim_e in_dim, std::string in_name, std::string in_info)
|
||||||
|
{
|
||||||
|
if (in_name == "")
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] The input name is empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_info == "")
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] The input info. is empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
meshname = in_name;
|
||||||
|
meshinfo = in_info;
|
||||||
|
meshtype = in_type;
|
||||||
|
meshdim = in_dim;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::load_headinfo(std::ifstream &infile, mesh_type_e expected_type, mesh_dim_e expected_dim)
|
||||||
|
{
|
||||||
|
// 读入网格头信息
|
||||||
|
infile.read((char*)&meshtype, sizeof(int));
|
||||||
|
infile.read((char*)&meshdim, sizeof(int));
|
||||||
|
if (meshdim != expected_dim || meshtype != expected_type)
|
||||||
|
{
|
||||||
|
infile.close();
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Invalid input mesh type.");
|
||||||
|
}
|
||||||
|
|
||||||
|
int info_size;
|
||||||
|
infile.read((char*)&info_size, sizeof(int));
|
||||||
|
meshname.resize(info_size);
|
||||||
|
infile.read((char*)meshname.c_str(), info_size);
|
||||||
|
|
||||||
|
infile.read((char*)&info_size, sizeof(int));
|
||||||
|
meshinfo.resize(info_size);
|
||||||
|
infile.read((char*)meshinfo.c_str(), info_size);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::load_datablock(std::ifstream &infile)
|
||||||
|
{
|
||||||
|
meshdata *new_data;
|
||||||
|
int in_num, info_size;
|
||||||
|
mesh_data_type_e in_dattype;
|
||||||
|
mesh_data_value_e in_valtype;
|
||||||
|
std::string in_name;
|
||||||
|
|
||||||
|
infile.read((char*)&in_num, sizeof(int));
|
||||||
|
for (int i = 0; i < in_num; i++)
|
||||||
|
{
|
||||||
|
// 首先读入三个整形和数据名称
|
||||||
|
infile.read((char*)&in_dattype, sizeof(int));
|
||||||
|
infile.read((char*)&in_valtype, sizeof(int));
|
||||||
|
infile.read((char*)&info_size, sizeof(int));
|
||||||
|
|
||||||
|
in_name.resize(info_size);
|
||||||
|
infile.read((char*)in_name.c_str(), info_size);
|
||||||
|
|
||||||
|
new_data = add_data(in_name, in_dattype, true, in_valtype);
|
||||||
|
new_data->load_binary(infile);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::save_headinfo(std::ofstream &outfile)
|
||||||
|
{
|
||||||
|
// 首先输出网格的类型和维度
|
||||||
|
outfile.write((char*)&meshtype, sizeof(int));
|
||||||
|
outfile.write((char*)&meshdim, sizeof(int));
|
||||||
|
// 输出网格名称与信息
|
||||||
|
int info_size = meshname.size();
|
||||||
|
outfile.write((char*)&info_size, sizeof(int));
|
||||||
|
outfile.write((char*)meshname.c_str(), info_size);
|
||||||
|
info_size = meshinfo.size();
|
||||||
|
outfile.write((char*)&info_size, sizeof(int));
|
||||||
|
outfile.write((char*)meshinfo.c_str(), info_size);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::save_datablock(std::ofstream &outfile)
|
||||||
|
{
|
||||||
|
// 统计输出的模型数量
|
||||||
|
int out_num = 0;
|
||||||
|
meshdata *curr_data = nullptr;
|
||||||
|
for (iter = saved_data.begin(); iter != saved_data.end(); ++iter)
|
||||||
|
{
|
||||||
|
curr_data = *iter;
|
||||||
|
if (curr_data->get_output())
|
||||||
|
{
|
||||||
|
out_num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outfile.write((char*)&out_num, sizeof(int));
|
||||||
|
|
||||||
|
for (iter = saved_data.begin(); iter != saved_data.end(); ++iter)
|
||||||
|
{
|
||||||
|
curr_data = *iter;
|
||||||
|
if (curr_data->get_output())
|
||||||
|
{
|
||||||
|
curr_data->save_binary(outfile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
579
backup/mesh.h
Normal file
579
backup/mesh.h
Normal file
@ -0,0 +1,579 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* 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_BASE_MESH_H
|
||||||
|
#define _GCTL_BASE_MESH_H
|
||||||
|
|
||||||
|
#include "list"
|
||||||
|
|
||||||
|
#include "new_meshdata.h"
|
||||||
|
//#include "meshdata.h"
|
||||||
|
//#include "meshdata_scalar.h"
|
||||||
|
//#include "meshdata_vector.h"
|
||||||
|
//#include "meshdata_tensor.h"
|
||||||
|
|
||||||
|
#include "gctl/io.h"
|
||||||
|
#include "gctl/algorithm.h"
|
||||||
|
|
||||||
|
namespace gctl
|
||||||
|
{
|
||||||
|
enum mesh_type_e
|
||||||
|
{
|
||||||
|
REGULAR_MESH,
|
||||||
|
LINEAR_MESH,
|
||||||
|
TRI_TET_MESH,
|
||||||
|
REGULAR_MESH_SPH,
|
||||||
|
LINEAR_MESH_SPH,
|
||||||
|
TRI_TET_MESH_SPH,
|
||||||
|
REGULAR_GRID,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum mesh_dim_e
|
||||||
|
{
|
||||||
|
MESH_2D,
|
||||||
|
MESH_3D,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 网格对象(纯虚类)。此类为所有具体网格类型的基类
|
||||||
|
*/
|
||||||
|
class base_mesh
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
base_mesh();
|
||||||
|
virtual ~base_mesh();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 清除所有网格数据。
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 检查网格是否已经初始化。
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool initiated() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 检查是否存在对应名称的数据。
|
||||||
|
*
|
||||||
|
* @param datname 数据名
|
||||||
|
*/
|
||||||
|
bool saved(std::string datname) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回对应名称的数据对象指针。
|
||||||
|
*
|
||||||
|
* @param datname 数据名
|
||||||
|
* @return 数据指针
|
||||||
|
*/
|
||||||
|
meshdata *get_data(std::string datname) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回所有数据指针。
|
||||||
|
*
|
||||||
|
* @param out_list 数据指针列表
|
||||||
|
*/
|
||||||
|
void get_all_data(array<meshdata*> &out_list) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回对应名称的数据对象的数组指针。
|
||||||
|
*
|
||||||
|
* @param datname 数据名
|
||||||
|
* @return 数组指针(注意需要转换为对应的数组指针类型)
|
||||||
|
*/
|
||||||
|
void *get_datval(std::string datname) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 删除对应名称的数据对象。
|
||||||
|
*
|
||||||
|
* @param datname 数据名
|
||||||
|
*/
|
||||||
|
void remove_data(std::string datname);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 显示网格与数据信息。
|
||||||
|
*
|
||||||
|
* @param os 输出流
|
||||||
|
*/
|
||||||
|
void show_info(std::ostream &os = std::clog) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 重命名数据对象。
|
||||||
|
*
|
||||||
|
* @param oldname 旧名称
|
||||||
|
* @param newname 新名称
|
||||||
|
*/
|
||||||
|
void rename_data(std::string oldname, std::string newname);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回网格类型
|
||||||
|
*
|
||||||
|
* @return 网格类型
|
||||||
|
*/
|
||||||
|
mesh_type_e get_meshtype() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回网格维度类型
|
||||||
|
*
|
||||||
|
* @return 网格维度
|
||||||
|
*/
|
||||||
|
mesh_dim_e get_meshdim() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回顶点数量
|
||||||
|
*
|
||||||
|
* @return 顶点数量
|
||||||
|
*/
|
||||||
|
int get_nodenum() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回网格单元数量
|
||||||
|
*
|
||||||
|
* @return 单元数量
|
||||||
|
*/
|
||||||
|
int get_elenum() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回数据对象数量
|
||||||
|
*
|
||||||
|
* @return 数据对象数量
|
||||||
|
*/
|
||||||
|
int get_datanum() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回网格名称
|
||||||
|
*
|
||||||
|
* @return 网格名称
|
||||||
|
*/
|
||||||
|
std::string get_meshname() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置网格名称
|
||||||
|
*
|
||||||
|
* @param in_name 网格名称
|
||||||
|
*/
|
||||||
|
void set_meshname(std::string in_name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回网格说明信息
|
||||||
|
*
|
||||||
|
* @return 说明信息
|
||||||
|
*/
|
||||||
|
std::string get_meshinfo() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置网格说明信息
|
||||||
|
*
|
||||||
|
* @param in_info 说明信息
|
||||||
|
*/
|
||||||
|
void set_meshinfo(std::string in_info);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 添加标量网格数据对象并赋初始值,如果对象已经存在则赋初始值
|
||||||
|
*
|
||||||
|
* @param in_name 数据对象名称
|
||||||
|
* @param in_type 数据对象类型
|
||||||
|
* @param if_output 数据对象是否可输出
|
||||||
|
* @param init_val 初始值
|
||||||
|
* @return 新建的数据对象指针
|
||||||
|
*/
|
||||||
|
meshdata *add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, double init_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 添加适量网格数据对象并赋初始值,如果对象已经存在则赋初始值
|
||||||
|
*
|
||||||
|
* @param in_name 数据对象名称
|
||||||
|
* @param in_type 数据对象类型
|
||||||
|
* @param if_output 数据对象是否可输出
|
||||||
|
* @param init_val 初始值
|
||||||
|
* @return 新建的数据对象指针
|
||||||
|
*/
|
||||||
|
meshdata *add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, gctl::point3dc init_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 添加张量网格数据对象并赋初始值,如果对象已经存在则赋初始值
|
||||||
|
*
|
||||||
|
* @param in_name 数据对象名称
|
||||||
|
* @param in_type 数据对象类型
|
||||||
|
* @param if_output 数据对象是否可输出
|
||||||
|
* @param init_val 初始值
|
||||||
|
* @return 新建的数据对象指针
|
||||||
|
*/
|
||||||
|
meshdata *add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, gctl::tensor init_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 添加张量网格数据对象并初始为0值
|
||||||
|
*
|
||||||
|
* @param in_name 数据对象名称
|
||||||
|
* @param in_type 数据对象类型
|
||||||
|
* @param if_output 数据对象是否可输出
|
||||||
|
* @param init_val 初始值
|
||||||
|
* @return 新建的数据对象指针
|
||||||
|
*/
|
||||||
|
meshdata *add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, mesh_data_value_e val_type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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轴间隔
|
||||||
|
*/
|
||||||
|
virtual void init(std::string in_name, std::string in_info, int xnum, int ynum,
|
||||||
|
double xmin, double ymin, double dx, double dy);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param in_name
|
||||||
|
* @param in_info
|
||||||
|
* @param xbnum
|
||||||
|
* @param ybnum
|
||||||
|
* @param zbnum
|
||||||
|
* @param xmin
|
||||||
|
* @param ymin
|
||||||
|
* @param zmin
|
||||||
|
* @param xsize
|
||||||
|
* @param ysize
|
||||||
|
* @param zsize
|
||||||
|
*/
|
||||||
|
virtual void init(std::string in_name, std::string in_info, int xbnum, int ybnum, int zbnum,
|
||||||
|
double xmin, double ymin, double zmin, double xsize, double ysize, double zsize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param in_name
|
||||||
|
* @param in_info
|
||||||
|
* @param lon_min
|
||||||
|
* @param lat_min
|
||||||
|
* @param rad_min
|
||||||
|
* @param lon_size
|
||||||
|
* @param lat_size
|
||||||
|
* @param rad_size
|
||||||
|
* @param lon_bnum
|
||||||
|
* @param lat_bnum
|
||||||
|
* @param rad_bnum
|
||||||
|
*/
|
||||||
|
virtual void init(std::string in_name, std::string in_info, double lon_min, double lat_min,
|
||||||
|
double rad_min, double lon_size, double lat_size, double rad_size, int lon_bnum, int lat_bnum, int rad_bnum);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param in_name
|
||||||
|
* @param in_info
|
||||||
|
* @param xmin
|
||||||
|
* @param ymin
|
||||||
|
* @param xsizes
|
||||||
|
* @param ysizes
|
||||||
|
*/
|
||||||
|
virtual void init(std::string in_name, std::string in_info, double xmin, double ymin,
|
||||||
|
const gctl::array<double> &xsizes, const gctl::array<double> &ysizes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param in_name
|
||||||
|
* @param in_info
|
||||||
|
* @param xmin
|
||||||
|
* @param ymin
|
||||||
|
* @param zmin
|
||||||
|
* @param xsizes
|
||||||
|
* @param ysizes
|
||||||
|
* @param zsizes
|
||||||
|
*/
|
||||||
|
virtual void init(std::string in_name, std::string in_info, double xmin, double ymin,
|
||||||
|
double zmin, const gctl::array<double> &xsizes, const gctl::array<double> &ysizes,
|
||||||
|
const gctl::array<double> &zsizes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param in_name
|
||||||
|
* @param in_info
|
||||||
|
* @param in_nodes
|
||||||
|
* @param in_triangles
|
||||||
|
*/
|
||||||
|
virtual void init(std::string in_name, std::string in_info, const gctl::array<gctl::vertex2dc> &in_nodes,
|
||||||
|
const gctl::array<gctl::triangle2d> &in_triangles);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param in_name
|
||||||
|
* @param in_info
|
||||||
|
* @param in_nodes
|
||||||
|
* @param in_tets
|
||||||
|
*/
|
||||||
|
virtual void init(std::string in_name, std::string in_info, const gctl::array<gctl::vertex3dc> &in_nodes,
|
||||||
|
const gctl::array<gctl::tetrahedron> &in_tets);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 显示网格的维度信息
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
virtual void show_mesh_dimension(std::ostream &os) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief (基类纯虚函数)读入二进制网格文件
|
||||||
|
*
|
||||||
|
* @param filename 文件名
|
||||||
|
*/
|
||||||
|
virtual void load_binary(std::string filename) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief (基类纯虚函数)写入二进制网格文件
|
||||||
|
*
|
||||||
|
* @param filename 文件名
|
||||||
|
*/
|
||||||
|
virtual void save_binary(std::string filename) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief (基类虚函数)保存网格到Gmsh文件。
|
||||||
|
*
|
||||||
|
* @param filename 文件名
|
||||||
|
* @param packed 索引是否为紧凑(从0开始)
|
||||||
|
*/
|
||||||
|
virtual void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param filename
|
||||||
|
* @param d_type
|
||||||
|
* @param out_mode
|
||||||
|
* @param packed
|
||||||
|
*/
|
||||||
|
void save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param filename
|
||||||
|
* @param datname
|
||||||
|
* @param out_mode
|
||||||
|
* @param packed
|
||||||
|
*/
|
||||||
|
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 将输入的自由点位上的浮点数据插值为规则网络的顶点或者块体数据
|
||||||
|
*
|
||||||
|
* @param in_posi 输入的自由点位的坐标
|
||||||
|
* @param in_val 输入的自由点位的数值
|
||||||
|
* @param[in] search_xlen 插值搜索区域的x半径
|
||||||
|
* @param[in] search_ylen 插值搜索区域的y半径
|
||||||
|
* @param[in] search_deg 插值搜索区域的x半径绕x轴正方向逆时针旋转的角度(弧度)
|
||||||
|
* @param[in] datname 网格后的数据名称
|
||||||
|
* @param[in] d_type 网格后的数据类型
|
||||||
|
*/
|
||||||
|
virtual 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);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param in_posi
|
||||||
|
* @param in_val
|
||||||
|
* @param search_xlen
|
||||||
|
* @param search_ylen
|
||||||
|
* @param search_deg
|
||||||
|
* @param datname
|
||||||
|
* @param d_type
|
||||||
|
*/
|
||||||
|
virtual void load_data_cloud(const array<point3dc> &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);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param datname
|
||||||
|
* @param in_posi
|
||||||
|
* @param out_val
|
||||||
|
*/
|
||||||
|
virtual void extract_points(std::string datname, const array<point2dc> &in_posi, array<double> &out_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param datname
|
||||||
|
* @param in_posi
|
||||||
|
* @param out_val
|
||||||
|
*/
|
||||||
|
virtual void extract_points(std::string datname, const array<point3dc> &in_posi, array<double> &out_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param datname
|
||||||
|
* @param start_p
|
||||||
|
* @param end_p
|
||||||
|
* @param size_p
|
||||||
|
* @param out_posi
|
||||||
|
* @param out_val
|
||||||
|
*/
|
||||||
|
virtual 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);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param datname
|
||||||
|
* @param start_p
|
||||||
|
* @param end_p
|
||||||
|
* @param size_p
|
||||||
|
* @param dh
|
||||||
|
* @param out_posi
|
||||||
|
* @param out_val
|
||||||
|
*/
|
||||||
|
virtual void extract_profile(std::string datname, const point3dc &start_p, const point3dc &end_p, int size_p,
|
||||||
|
double dh, array<point3dc> &out_posi, array<double> &out_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param datname
|
||||||
|
* @param p_type
|
||||||
|
* @param v_type
|
||||||
|
* @param para_str
|
||||||
|
* @param in_val
|
||||||
|
*/
|
||||||
|
virtual void edit_data(std::string datname, physical_type_e p_type, value_operator_e v_type, std::string para_str, double in_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param datname
|
||||||
|
* @param p_type
|
||||||
|
* @param v_type
|
||||||
|
* @param para_str
|
||||||
|
* @param in_val
|
||||||
|
*/
|
||||||
|
virtual void edit_data(std::string datname, physical_type_e p_type, value_operator_e v_type, std::string para_str, point3dc in_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param datname
|
||||||
|
* @param p_type
|
||||||
|
* @param v_type
|
||||||
|
* @param para_str
|
||||||
|
* @param in_val
|
||||||
|
*/
|
||||||
|
virtual void edit_data(std::string datname, physical_type_e p_type, value_operator_e v_type, std::string para_str, tensor in_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param datname
|
||||||
|
* @param in_val
|
||||||
|
*/
|
||||||
|
virtual void purge_data(std::string datname, double in_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param datname
|
||||||
|
* @param in_val
|
||||||
|
*/
|
||||||
|
virtual void purge_data(std::string datname, point3dc in_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param datname
|
||||||
|
* @param in_val
|
||||||
|
*/
|
||||||
|
virtual void purge_data(std::string datname, tensor in_val);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
mesh_type_e meshtype;
|
||||||
|
mesh_dim_e meshdim;
|
||||||
|
std::string meshname;
|
||||||
|
std::string meshinfo;
|
||||||
|
|
||||||
|
int node_num, ele_num;
|
||||||
|
bool initialized;
|
||||||
|
|
||||||
|
std::list<meshdata*> saved_data;
|
||||||
|
std::list<meshdata*>::iterator iter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以下为类的私有函数 只能被类的公共函数调用
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 初始化网格
|
||||||
|
*
|
||||||
|
* @param in_type
|
||||||
|
* @param in_dim
|
||||||
|
* @param in_name
|
||||||
|
* @param in_info
|
||||||
|
*/
|
||||||
|
void init(mesh_type_e in_type, mesh_dim_e in_dim, std::string in_name, std::string in_info);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 读入二进制网格头信息
|
||||||
|
*
|
||||||
|
* @param infile 输入流
|
||||||
|
* @param expected_type 预期获取的网格类型
|
||||||
|
* @param expected_dim 预期获得的网格维度类型
|
||||||
|
*/
|
||||||
|
void load_headinfo(std::ifstream &infile, mesh_type_e expected_type, mesh_dim_e expected_dim);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 读入二进制数据块
|
||||||
|
*
|
||||||
|
* @param infile 输入流
|
||||||
|
*/
|
||||||
|
void load_datablock(std::ifstream &infile);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 写入二进制网格头信息
|
||||||
|
*
|
||||||
|
* @param outfile 输出流
|
||||||
|
*/
|
||||||
|
void save_headinfo(std::ofstream &outfile);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 写入二进制数据块
|
||||||
|
*
|
||||||
|
* @param outfile 输出流
|
||||||
|
*/
|
||||||
|
void save_datablock(std::ofstream &outfile);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //_GCTL_BASE_MESH_H
|
94
backup/meshdata.cpp
Normal file
94
backup/meshdata.cpp
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* 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 "meshdata.h"
|
||||||
|
|
||||||
|
gctl::meshdata::meshdata(std::string in_name, mesh_data_type_e in_type, bool if_output)
|
||||||
|
{
|
||||||
|
if (in_name == "")
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::meshdata] The input name is empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
datname = in_name;
|
||||||
|
dattype = in_type;
|
||||||
|
output_ok = if_output;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::meshdata::~meshdata(){}
|
||||||
|
|
||||||
|
void gctl::meshdata::set_datname(std::string in_name)
|
||||||
|
{
|
||||||
|
if (in_name == "")
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::meshdata] The input name is empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
datname = in_name;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string gctl::meshdata::get_datname()
|
||||||
|
{
|
||||||
|
return datname;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::mesh_data_type_e gctl::meshdata::get_dattype()
|
||||||
|
{
|
||||||
|
return dattype;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::mesh_data_value_e gctl::meshdata::get_valtype()
|
||||||
|
{
|
||||||
|
return valtype;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::meshdata::set_output(bool if_output)
|
||||||
|
{
|
||||||
|
output_ok = if_output;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool gctl::meshdata::get_output()
|
||||||
|
{
|
||||||
|
return output_ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::meshdata::show_info(std::ostream &os)
|
||||||
|
{
|
||||||
|
os << "Data: " << datname << " | ";
|
||||||
|
if (dattype == NodeData) os << "Type: Node data | ";
|
||||||
|
if (dattype == ElemData) os << "Type: Element data | ";
|
||||||
|
if (dattype == ElemData2D) os << "Type: 2D element data | ";
|
||||||
|
if (dattype == ElemData3D) os << "Type: 3D element data | ";
|
||||||
|
if (valtype == Scalar) os << "Value: Scalar | ";
|
||||||
|
if (valtype == Vector) os << "Value: Vector | ";
|
||||||
|
if (valtype == Tensor) os << "Value: Tensor | ";
|
||||||
|
if (output_ok) os << "Output: Yes" << std::endl;
|
||||||
|
else os<< "Output: No" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
158
backup/meshdata.h
Normal file
158
backup/meshdata.h
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* 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_MESHDATA_H
|
||||||
|
#define _GCTL_MESHDATA_H
|
||||||
|
|
||||||
|
#include "gctl_mesh_config.h"
|
||||||
|
#include "gctl/core.h"
|
||||||
|
#include "gctl/geometry.h"
|
||||||
|
|
||||||
|
namespace gctl
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @brief 网格数据的数值类型
|
||||||
|
*/
|
||||||
|
enum mesh_data_value_e
|
||||||
|
{
|
||||||
|
Scalar, ///< 标量数据
|
||||||
|
Vector, ///< 矢量数据
|
||||||
|
Tensor, ///< 张量数据
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 网格文件中的数据对象(纯虚类)。此类为具体类型的数据对象的基类
|
||||||
|
*/
|
||||||
|
class meshdata
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
std::string datname; // 数据的名称
|
||||||
|
mesh_data_type_e dattype; // 数据的赋值属性 顶点或是元素(设置后不可更改)
|
||||||
|
mesh_data_value_e valtype; // 数据的类型(设置后不可更改)
|
||||||
|
bool output_ok; // 是否可输出数据
|
||||||
|
|
||||||
|
public:
|
||||||
|
// 构造函数
|
||||||
|
meshdata(std::string in_name, mesh_data_type_e in_type, bool if_output);
|
||||||
|
|
||||||
|
// 析构函数
|
||||||
|
virtual ~meshdata();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置数据名称
|
||||||
|
*
|
||||||
|
* @param[in] in_name 名称字符串
|
||||||
|
*/
|
||||||
|
void set_datname(std::string in_name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回数据的名称
|
||||||
|
*
|
||||||
|
* @return 名称字符串
|
||||||
|
*/
|
||||||
|
std::string get_datname();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回数据的赋值类型
|
||||||
|
*
|
||||||
|
* @return 数据赋值类型的枚举
|
||||||
|
*/
|
||||||
|
mesh_data_type_e get_dattype();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回数据值的类型
|
||||||
|
*
|
||||||
|
* @return 数据值类型的枚举
|
||||||
|
*/
|
||||||
|
mesh_data_value_e get_valtype();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置数据对象输出状态的设置情况
|
||||||
|
*
|
||||||
|
* @param[in] if_output 是否可输出此对象
|
||||||
|
*/
|
||||||
|
void set_output(bool if_output);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回数据对象输出状态的设置情况
|
||||||
|
*
|
||||||
|
* @return 是否可输出此对象
|
||||||
|
*/
|
||||||
|
bool get_output();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 显示数据对象的头信息
|
||||||
|
*/
|
||||||
|
void show_info(std::ostream &os = std::clog);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 显示数据统计参数
|
||||||
|
*/
|
||||||
|
virtual void show_stats(std::ostream &os = std::clog) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回数据块的指针 所有子类的数据块均为gctl::array类型,这是一个通用的接口。
|
||||||
|
*
|
||||||
|
* @note 注意因为具体的返回类型未知 因此需在调用后按实际数据类型转换指针
|
||||||
|
*
|
||||||
|
* @return 数据块的指针
|
||||||
|
*/
|
||||||
|
virtual void *get_datval_ptr() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 载入二进制文件
|
||||||
|
*
|
||||||
|
* @warning 不要直接调用此函数,应该在网格类型的相应函数中调用
|
||||||
|
*
|
||||||
|
* @param infile 输入文件的流(以二进制方式打开)
|
||||||
|
*/
|
||||||
|
virtual void load_binary(std::ifstream &infile) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 保存二进制文件
|
||||||
|
*
|
||||||
|
* @warning 不要直接调用此函数,应该在网格类型的相应函数中调用
|
||||||
|
*
|
||||||
|
* @param outfile 输出的文件流(以二进制方式打开)
|
||||||
|
*/
|
||||||
|
virtual void save_binary(std::ofstream &outfile) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 销毁指针的对象 可销毁此基类或子类指针指向的对象
|
||||||
|
*
|
||||||
|
* @param obj_ptr 网格数据指针
|
||||||
|
*/
|
||||||
|
static void destroy(meshdata *obj_ptr)
|
||||||
|
{
|
||||||
|
delete obj_ptr;
|
||||||
|
obj_ptr = nullptr;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //_GCTL_MESHDATA_H
|
@ -21,7 +21,7 @@ add_example(mesh_ex1 ON)
|
|||||||
add_example(mesh_ex2 ON)
|
add_example(mesh_ex2 ON)
|
||||||
add_example(mesh_ex3 ON)
|
add_example(mesh_ex3 ON)
|
||||||
add_example(mesh_ex4 ON)
|
add_example(mesh_ex4 ON)
|
||||||
add_example(mesh_ex5 ON)
|
add_example(mesh_ex5 OFF)
|
||||||
add_example(mesh_ex6 ON)
|
add_example(mesh_ex6 ON)
|
||||||
add_example(mesh_ex7 ON)
|
add_example(mesh_ex7 ON)
|
||||||
add_example(mesh_ex8 ON)
|
add_example(mesh_ex8 ON)
|
||||||
|
@ -32,26 +32,20 @@ int main(int argc, char *argv[])
|
|||||||
gctl::regular_grid rgd;
|
gctl::regular_grid rgd;
|
||||||
rgd.init("grid-1", "null", 4, 4, 0.0, 0.0, 1.0, 1.0);
|
rgd.init("grid-1", "null", 4, 4, 0.0, 0.0, 1.0, 1.0);
|
||||||
|
|
||||||
gctl::meshdata *data = rgd.add_data("data-1", gctl::NodeData, true, 2.5);
|
rgd.add_data(gctl::NodeData, gctl::Scalar, "data-1", 2.5);
|
||||||
gctl::meshdata *data2= rgd.add_data("data-2", gctl::ElemData, false, 1.2);
|
rgd.add_data(gctl::ElemData, gctl::Scalar, "data-2", 1.2, false);
|
||||||
gctl::meshdata *data3= rgd.add_data("data-3", gctl::NodeData, true, gctl::Scalar);
|
rgd.add_data(gctl::NodeData, gctl::Scalar, "data-3", 1.0);
|
||||||
|
rgd.show_info();
|
||||||
|
|
||||||
std::cout << "data name: " << data2->get_datname() << std::endl;
|
gctl::meshdata data2 = rgd.get_data("data-2");
|
||||||
//gctl::array<double> *data_ptr = (gctl::array<double>*) rgd.get_datval(data2->get_name());
|
std::cout << "data name: " << data2.name_ << std::endl;
|
||||||
gctl::array<double> *data_ptr = (gctl::array<double>*) data2->get_datval_ptr();
|
data2.datval_.show();
|
||||||
for (int i = 0; i < data_ptr->size(); i++)
|
|
||||||
{
|
|
||||||
std::cout << data_ptr->at(i) << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "data name: " << data3->get_datname() << std::endl;
|
gctl::meshdata data3 = rgd.get_data("data-3");
|
||||||
gctl::array<int> *data_ptr2 = (gctl::array<int>*) rgd.get_datval(data3->get_datname());
|
std::cout << "data name: " << data3.name_ << std::endl;
|
||||||
for (int i = 0; i < data_ptr2->size(); i++)
|
data3.datval_.show();
|
||||||
{
|
|
||||||
std::cout << data_ptr2->at(i) << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
rgd.remove_data("data-1");
|
rgd.remove_data("data-1");
|
||||||
|
rgd.show_info();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -31,7 +31,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
gctl::regular_mesh_sph_3d rm_3ds;
|
gctl::regular_mesh_sph_3d rm_3ds;
|
||||||
rm_3ds.init("mesh-1", "null", 30.25, 30.25, 2005, 0.5, 0.5, 10, 40, 40, 50);
|
rm_3ds.init("mesh-1", "null", 30.25, 30.25, 2005, 0.5, 0.5, 10, 40, 40, 50);
|
||||||
rm_3ds.add_data("data-1", gctl::ElemData, true, 2.5);
|
rm_3ds.add_data(gctl::ElemData, gctl::Scalar, "data-1", 2.5);
|
||||||
rm_3ds.save_gmsh("data/out/mesh_sample10", gctl::ElemData, gctl::OverWrite, gctl::NotPacked);
|
rm_3ds.save_gmsh("mesh_sample10",gctl::OverWrite, gctl::NotPacked);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -34,32 +34,29 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
gctl::regular_grid rgd;
|
gctl::regular_grid rgd;
|
||||||
rgd.init("grid-1", "null", 15, 10, 0.0, 0.0, 1.0, 1.0);
|
rgd.init("grid-1", "null", 15, 10, 0.0, 0.0, 1.0, 1.0);
|
||||||
rgd.add_data(dname, gctl::NodeData, true, gctl::Scalar);
|
|
||||||
|
|
||||||
gctl::array<double> *data_ptr = (gctl::array<double>*) rgd.get_datval(dname);
|
gctl::meshdata &data = rgd.add_data(gctl::NodeData, gctl::Scalar, dname, 0.0);
|
||||||
for (int j = 0; j < rgd.get_ydim(); j++)
|
for (int j = 0; j < rgd.get_ydim(); j++)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < rgd.get_xdim(); i++)
|
for (int i = 0; i < rgd.get_xdim(); i++)
|
||||||
{
|
{
|
||||||
data_ptr->at(i + j*rgd.get_xdim()) = i;
|
data.datval_[i + j*rgd.get_xdim()] = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rgd.add_data(dname2, gctl::NodeData, true, gctl::Scalar);
|
gctl::meshdata &data2 = rgd.add_data(gctl::NodeData, gctl::Scalar, dname2, 0.0);
|
||||||
data_ptr = (gctl::array<double>*) rgd.get_datval(dname2);
|
|
||||||
for (int j = 0; j < rgd.get_ydim(); j++)
|
for (int j = 0; j < rgd.get_ydim(); j++)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < rgd.get_xdim(); i++)
|
for (int i = 0; i < rgd.get_xdim(); i++)
|
||||||
{
|
{
|
||||||
data_ptr->at(i + j*rgd.get_xdim()) = j;
|
data2.datval_[i + j*rgd.get_xdim()] = j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// disable the output of data object named dname2
|
// disable the output of data object named dname2
|
||||||
gctl::meshdata *data2 = rgd.get_data(dname2);
|
//data2.output_ok_ = false;
|
||||||
data2->set_output(false);
|
|
||||||
|
|
||||||
rgd.save_netcdf_grid("data/out/sample2-out", gctl::NodeData);
|
|
||||||
|
|
||||||
|
rgd.show_info();
|
||||||
|
rgd.save_netcdf_grid("sample2-out", gctl::NodeData);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -27,62 +27,56 @@
|
|||||||
|
|
||||||
#include "../lib/mesh.h"
|
#include "../lib/mesh.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[]) try
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
std::string dname = "example";
|
std::string dname = "example";
|
||||||
std::string dname2= "another-example";
|
std::string dname2= "another-example";
|
||||||
|
|
||||||
gctl::regular_grid rgd;
|
gctl::regular_grid rgd;
|
||||||
rgd.init("grid-1", "this is a test message.", 15, 10, 0.0, 0.0, 1.0, 1.0);
|
rgd.init("grid-1", "this is a test message.", 15, 10, 0.0, 0.0, 1.0, 1.0);
|
||||||
rgd.add_data(dname, gctl::NodeData, true, gctl::Scalar);
|
|
||||||
|
|
||||||
gctl::array<double> *data_ptr = (gctl::array<double>*) rgd.get_datval(dname);
|
gctl::meshdata &data = rgd.add_data(gctl::NodeData, gctl::Scalar, dname, 0.0);
|
||||||
for (int j = 0; j < rgd.get_ydim(); j++)
|
for (int j = 0; j < rgd.get_ydim(); j++)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < rgd.get_xdim(); i++)
|
for (int i = 0; i < rgd.get_xdim(); i++)
|
||||||
{
|
{
|
||||||
data_ptr->at(i + j*rgd.get_xdim()) = i;
|
data.datval_[i + j*rgd.get_xdim()] = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rgd.add_data(dname2, gctl::ElemData, true, gctl::Scalar);
|
gctl::meshdata &data2 = rgd.add_data(gctl::ElemData, gctl::Scalar, dname2, 0.0);
|
||||||
data_ptr = (gctl::array<double>*) rgd.get_datval(dname2);
|
|
||||||
for (int j = 0; j < rgd.get_ydim()-1; j++)
|
for (int j = 0; j < rgd.get_ydim()-1; j++)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < rgd.get_xdim()-1; i++)
|
for (int i = 0; i < rgd.get_xdim()-1; i++)
|
||||||
{
|
{
|
||||||
data_ptr->at(i + j*(rgd.get_xdim()-1)) = j;
|
data2.datval_[i + j*(rgd.get_xdim()-1)] = j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rgd.save_binary("data/out/sample3-out");
|
rgd.save_binary("sample3-out");
|
||||||
rgd.save_netcdf_grid("data/out/sample3-out1", dname);
|
rgd.save_netcdf_grid("sample3-out1", dname);
|
||||||
rgd.save_netcdf_grid("data/out/sample3-out2", dname2);
|
rgd.save_netcdf_grid("sample3-out2", dname2);
|
||||||
|
|
||||||
gctl::regular_grid rgd2;
|
gctl::regular_grid rgd2;
|
||||||
rgd2.load_binary("data/out/sample3-out");
|
rgd2.load_binary("sample3-out");
|
||||||
|
|
||||||
rgd2.show_info();
|
rgd2.show_info();
|
||||||
|
|
||||||
data_ptr = (gctl::array<double>*) rgd2.get_datval(dname);
|
gctl::meshdata &data3 = rgd2.get_data(dname);
|
||||||
for (int i = 0; i < data_ptr->size(); i++)
|
for (int i = 0; i < data3.datval_.size(); i++)
|
||||||
{
|
{
|
||||||
std::cout << data_ptr->at(i) << " ";
|
std::cout << data3.datval_[i] << " ";
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
data_ptr = (gctl::array<double>*) rgd2.get_datval(dname2);
|
gctl::meshdata &data4 = rgd2.get_data(dname2);
|
||||||
for (int i = 0; i < data_ptr->size(); i++)
|
for (int i = 0; i < data4.datval_.size(); i++)
|
||||||
{
|
{
|
||||||
std::cout << data_ptr->at(i) << " ";
|
std::cout << data4.datval_[i] << " ";
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
|
||||||
catch(std::exception &e)
|
|
||||||
{
|
|
||||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
catch(std::exception &e)
|
||||||
|
{
|
||||||
|
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||||
|
}
|
@ -27,37 +27,34 @@
|
|||||||
|
|
||||||
#include "../lib/mesh.h"
|
#include "../lib/mesh.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[]) try
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
std::string dname = "vector-data";
|
std::string dname = "vector-data";
|
||||||
|
|
||||||
gctl::regular_grid rgd;
|
gctl::regular_grid rgd;
|
||||||
rgd.init("grid-example", "this grid can store vectors. Yeah!", 15, 10, 0.0, 0.0, 1.0, 1.0);
|
rgd.init("grid-example", "this grid can store vectors. Yeah!", 15, 10, 0.0, 0.0, 1.0, 1.0);
|
||||||
rgd.add_data(dname, gctl::NodeData, true, gctl::Vector);
|
|
||||||
|
|
||||||
gctl::array<gctl::point3dc> *data_ptr = (gctl::array<gctl::point3dc>*) rgd.get_datval(dname);
|
gctl::array<gctl::point3dc> init_data(rgd.get_ydim()*rgd.get_xdim());
|
||||||
for (int j = 0; j < rgd.get_ydim(); j++)
|
for (int j = 0; j < rgd.get_ydim(); j++)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < rgd.get_xdim(); i++)
|
for (int i = 0; i < rgd.get_xdim(); i++)
|
||||||
{
|
{
|
||||||
data_ptr->at(i + j*rgd.get_xdim()).x = i;
|
init_data[i + j*rgd.get_xdim()].x = i;
|
||||||
data_ptr->at(i + j*rgd.get_xdim()).y = j;
|
init_data[i + j*rgd.get_xdim()].y = j;
|
||||||
data_ptr->at(i + j*rgd.get_xdim()).z = i+j;
|
init_data[i + j*rgd.get_xdim()].z = i+j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rgd.save_binary("data/out/sample4-out");
|
gctl::meshdata data = rgd.add_data(gctl::NodeData, dname, init_data);
|
||||||
|
|
||||||
|
rgd.save_binary("sample4-out");
|
||||||
|
|
||||||
gctl::regular_grid rgd2;
|
gctl::regular_grid rgd2;
|
||||||
rgd2.load_binary("data/out/sample4-out");
|
rgd2.load_binary("sample4-out");
|
||||||
|
|
||||||
rgd2.show_info();
|
rgd2.show_info();
|
||||||
}
|
|
||||||
catch(std::exception &e)
|
|
||||||
{
|
|
||||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
catch(std::exception &e)
|
||||||
|
{
|
||||||
|
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||||
|
}
|
@ -27,20 +27,17 @@
|
|||||||
|
|
||||||
#include "../lib/mesh.h"
|
#include "../lib/mesh.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[]) try
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
gctl::regular_grid rgd;
|
gctl::regular_grid rgd;
|
||||||
rgd.load_netcdf_grid("data/out/sample3-out1", gctl::ElemData, "x", "y");
|
rgd.load_netcdf_grid("data/out/sample3-out1", gctl::ElemData, "x", "y");
|
||||||
|
|
||||||
rgd.show_info();
|
rgd.show_info();
|
||||||
|
|
||||||
rgd.save_netcdf_grid("data/out/sample5-out", "example");
|
rgd.save_netcdf_grid("data/out/sample5-out", "example");
|
||||||
}
|
|
||||||
catch(std::exception &e)
|
|
||||||
{
|
|
||||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
catch(std::exception &e)
|
||||||
|
{
|
||||||
|
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||||
|
}
|
@ -27,46 +27,40 @@
|
|||||||
|
|
||||||
#include "../lib/mesh.h"
|
#include "../lib/mesh.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[]) try
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
gctl::regular_mesh_2d rg_mesh;
|
gctl::regular_mesh_2d rg_mesh;
|
||||||
rg_mesh.init("mesh-example", "this mesh can store vectors. Yeah!", 15, 10, 0.5, 0.5, 1.0, 1.0);
|
rg_mesh.init("mesh-example", "this mesh can store vectors. Yeah!", 15, 10, 0.5, 0.5, 1.0, 1.0);
|
||||||
|
|
||||||
int ybnum = rg_mesh.get_ybnum();
|
int ybnum = rg_mesh.get_ybnum();
|
||||||
int xbnum = rg_mesh.get_xbnum();
|
int xbnum = rg_mesh.get_xbnum();
|
||||||
|
|
||||||
rg_mesh.add_data("vector-data", gctl::ElemData, true, gctl::Vector);
|
gctl::array<gctl::point3dc> init_data(ybnum*xbnum);
|
||||||
gctl::array<gctl::point3dc> *data_ptr = (gctl::array<gctl::point3dc>*) rg_mesh.get_datval("vector-data");
|
|
||||||
for (int j = 0; j < ybnum; j++)
|
for (int j = 0; j < ybnum; j++)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < xbnum; i++)
|
for (int i = 0; i < xbnum; i++)
|
||||||
{
|
{
|
||||||
data_ptr->at(i + j*xbnum).x = i;
|
init_data[i + j*xbnum].x = i;
|
||||||
data_ptr->at(i + j*xbnum).y = j;
|
init_data[i + j*xbnum].y = j;
|
||||||
data_ptr->at(i + j*xbnum).z = i+j;
|
init_data[i + j*xbnum].z = i+j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rg_mesh.add_data("double-data", gctl::NodeData, true, gctl::Scalar);
|
rg_mesh.add_data(gctl::ElemData, "vector-data", init_data);
|
||||||
gctl::array<double> *data_ptr2 = (gctl::array<double>*) rg_mesh.get_datval("double-data");
|
|
||||||
|
gctl::meshdata &data2= rg_mesh.add_data(gctl::NodeData, gctl::Scalar, "double-data", 0.0);
|
||||||
for (int j = 0; j < ybnum+1; j++)
|
for (int j = 0; j < ybnum+1; j++)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < xbnum+1; i++)
|
for (int i = 0; i < xbnum+1; i++)
|
||||||
{
|
{
|
||||||
data_ptr2->at(i + j*(xbnum+1)) = i+j;
|
data2.datval_[i + j*(xbnum+1)] = i+j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//rg_mesh.save_gmsh("data/sample6-out", "vector-data");
|
rg_mesh.save_gmsh("sample6-out", gctl::OverWrite);
|
||||||
//rg_mesh.save_gmsh("data/sample6-out", "double-data", Append);
|
|
||||||
|
|
||||||
rg_mesh.save_gmsh("data/out/sample6-out", gctl::ElemData, gctl::OverWrite);
|
|
||||||
}
|
|
||||||
catch(std::exception &e)
|
|
||||||
{
|
|
||||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
catch(std::exception &e)
|
||||||
|
{
|
||||||
|
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||||
|
}
|
@ -27,10 +27,8 @@
|
|||||||
|
|
||||||
#include "../lib/mesh.h"
|
#include "../lib/mesh.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[]) try
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
gctl::regular_mesh_3d rg_mesh;
|
gctl::regular_mesh_3d rg_mesh;
|
||||||
rg_mesh.init("mesh-example", "this mesh can store vectors. Yeah!", 15, 10, 10, 0.5, 0.5, 0.5, 1.0, 1.0, 1.0);
|
rg_mesh.init("mesh-example", "this mesh can store vectors. Yeah!", 15, 10, 10, 0.5, 0.5, 0.5, 1.0, 1.0, 1.0);
|
||||||
|
|
||||||
@ -38,24 +36,22 @@ int main(int argc, char *argv[])
|
|||||||
int xbnum = rg_mesh.get_xbnum();
|
int xbnum = rg_mesh.get_xbnum();
|
||||||
int zbnum = rg_mesh.get_zbnum();
|
int zbnum = rg_mesh.get_zbnum();
|
||||||
|
|
||||||
rg_mesh.add_data("double-data", gctl::NodeData, gctl::Packed, gctl::Scalar);
|
gctl::meshdata &data = rg_mesh.add_data(gctl::NodeData, gctl::Scalar, "double-data", 0.0);
|
||||||
gctl::array<double> *data_ptr = (gctl::array<double>*) rg_mesh.get_datval("double-data");
|
|
||||||
for (int k = 0; k < zbnum+1; k++)
|
for (int k = 0; k < zbnum+1; k++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < ybnum+1; j++)
|
for (int j = 0; j < ybnum+1; j++)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < xbnum+1; i++)
|
for (int i = 0; i < xbnum+1; i++)
|
||||||
{
|
{
|
||||||
data_ptr->at(i + j*(xbnum+1) + k*(xbnum+1)*(ybnum+1)) = i+j+k;
|
data.datval_[i + j*(xbnum+1) + k*(xbnum+1)*(ybnum+1)] = i+j+k;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rg_mesh.save_gmsh("data/out/sample7-out", "double-data", gctl::OverWrite);
|
rg_mesh.save_gmsh("sample7-out", "double-data", gctl::OverWrite);
|
||||||
}
|
|
||||||
catch(std::exception &e)
|
|
||||||
{
|
|
||||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
catch(std::exception &e)
|
||||||
|
{
|
||||||
|
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||||
|
}
|
@ -27,24 +27,21 @@
|
|||||||
|
|
||||||
#include "../lib/mesh.h"
|
#include "../lib/mesh.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[]) try
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
gctl::triangle_mesh t_mesh;
|
gctl::triangle_mesh t_mesh;
|
||||||
t_mesh.load_triangle("data/out/sample8", gctl::Packed);
|
t_mesh.load_triangle("sample8", gctl::Packed);
|
||||||
t_mesh.add_data("example", gctl::ElemData, gctl::Packed, 1.0);
|
t_mesh.add_data(gctl::ElemData, gctl::Scalar, "example", 1.0);
|
||||||
|
|
||||||
t_mesh.save_gmsh("data/out/sample8-out", "example", gctl::OverWrite, gctl::NotPacked);
|
t_mesh.save_gmsh("sample8-out", "example", gctl::OverWrite, gctl::NotPacked);
|
||||||
t_mesh.save_binary("data/out/sample8-out");
|
t_mesh.save_binary("sample8-out");
|
||||||
|
|
||||||
gctl::triangle_mesh t2_mesh;
|
gctl::triangle_mesh t2_mesh;
|
||||||
t2_mesh.load_binary("data/out/sample8-out");
|
t2_mesh.load_binary("sample8-out");
|
||||||
t2_mesh.show_info();
|
t2_mesh.show_info();
|
||||||
}
|
|
||||||
catch(std::exception &e)
|
|
||||||
{
|
|
||||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
catch(std::exception &e)
|
||||||
|
{
|
||||||
|
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||||
|
}
|
@ -27,10 +27,8 @@
|
|||||||
|
|
||||||
#include "../lib/mesh.h"
|
#include "../lib/mesh.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[]) try
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
gctl::array<double> xs(15);
|
gctl::array<double> xs(15);
|
||||||
for (int i = 0; i < 15; i++)
|
for (int i = 0; i < 15; i++)
|
||||||
{
|
{
|
||||||
@ -49,21 +47,19 @@ int main(int argc, char *argv[])
|
|||||||
int ybnum = l2d_mesh.get_ybnum();
|
int ybnum = l2d_mesh.get_ybnum();
|
||||||
int xbnum = l2d_mesh.get_xbnum();
|
int xbnum = l2d_mesh.get_xbnum();
|
||||||
|
|
||||||
l2d_mesh.add_data("double-data", gctl::ElemData, gctl::Packed, gctl::Scalar);
|
gctl::meshdata &data = l2d_mesh.add_data(gctl::ElemData, gctl::Scalar, "double-data", 0.0);
|
||||||
gctl::array<double> *data_ptr2 = (gctl::array<double>*) l2d_mesh.get_datval("double-data");
|
|
||||||
for (int j = 0; j < ybnum; j++)
|
for (int j = 0; j < ybnum; j++)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < xbnum; i++)
|
for (int i = 0; i < xbnum; i++)
|
||||||
{
|
{
|
||||||
data_ptr2->at(i + j*xbnum) = i+j;
|
data.datval_[i + j*xbnum] = i+j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
l2d_mesh.save_gmsh("data/out/sample9-out", gctl::ElemData, gctl::OverWrite, gctl::NotPacked);
|
l2d_mesh.save_gmsh("sample9-out", gctl::OverWrite, gctl::NotPacked);
|
||||||
}
|
|
||||||
catch(std::exception &e)
|
|
||||||
{
|
|
||||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
catch(std::exception &e)
|
||||||
|
{
|
||||||
|
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||||
|
}
|
@ -30,11 +30,7 @@
|
|||||||
void gctl::linear_mesh_2d::init(std::string in_name, std::string in_info, double xmin, double ymin,
|
void gctl::linear_mesh_2d::init(std::string in_name, std::string in_info, double xmin, double ymin,
|
||||||
const gctl::array<double> &xsizes, const gctl::array<double> &ysizes)
|
const gctl::array<double> &xsizes, const gctl::array<double> &ysizes)
|
||||||
{
|
{
|
||||||
if (initialized)
|
check_initiated(true); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is already initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
base_mesh::init(LINEAR_MESH, MESH_2D, in_name, in_info);
|
base_mesh::init(LINEAR_MESH, MESH_2D, in_name, in_info);
|
||||||
|
|
||||||
lm_xmin = xmin;
|
lm_xmin = xmin;
|
||||||
@ -44,8 +40,8 @@ void gctl::linear_mesh_2d::init(std::string in_name, std::string in_info, double
|
|||||||
lm_xsizes.resize(lm_xbnum);
|
lm_xsizes.resize(lm_xbnum);
|
||||||
lm_ysizes.resize(lm_ybnum);
|
lm_ysizes.resize(lm_ybnum);
|
||||||
|
|
||||||
node_num = (lm_xbnum+1) * (lm_ybnum+1);
|
node_num_ = (lm_xbnum+1) * (lm_ybnum+1);
|
||||||
ele_num = lm_xbnum * lm_ybnum;
|
ele_num_ = lm_xbnum * lm_ybnum;
|
||||||
|
|
||||||
for (int i = 0; i < lm_xbnum; i++)
|
for (int i = 0; i < lm_xbnum; i++)
|
||||||
{
|
{
|
||||||
@ -57,8 +53,8 @@ void gctl::linear_mesh_2d::init(std::string in_name, std::string in_info, double
|
|||||||
lm_ysizes[i] = ysizes[i];
|
lm_ysizes[i] = ysizes[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes.resize(node_num);
|
nodes.resize(node_num_);
|
||||||
elements.resize(ele_num);
|
elements.resize(ele_num_);
|
||||||
|
|
||||||
double x_p, y_p = lm_ymin - 0.5*lm_ysizes[0];
|
double x_p, y_p = lm_ymin - 0.5*lm_ysizes[0];
|
||||||
for (int j = 0; j < lm_ybnum+1; j++)
|
for (int j = 0; j < lm_ybnum+1; j++)
|
||||||
@ -88,16 +84,23 @@ void gctl::linear_mesh_2d::init(std::string in_name, std::string in_info, double
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initialized = true;
|
initialized_ = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::linear_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: " << get_xmin() << " -> " << get_xmax() << "\n";
|
||||||
|
os << "y-range: " << get_ymin() << " -> " << get_ymax() << "\n";
|
||||||
|
os << "dimension: " << lm_xbnum << ", " << lm_ybnum << "\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::linear_mesh_2d::load_binary(std::string filename)
|
void gctl::linear_mesh_2d::load_binary(std::string filename)
|
||||||
{
|
{
|
||||||
if (initialized)
|
check_initiated(true); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is already initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ifstream infile;
|
std::ifstream infile;
|
||||||
gctl::open_infile(infile, filename, ".2m", std::ios::in|std::ios::binary);
|
gctl::open_infile(infile, filename, ".2m", std::ios::in|std::ios::binary);
|
||||||
@ -113,8 +116,8 @@ void gctl::linear_mesh_2d::load_binary(std::string filename)
|
|||||||
|
|
||||||
lm_xsizes.resize(lm_xbnum);
|
lm_xsizes.resize(lm_xbnum);
|
||||||
lm_ysizes.resize(lm_ybnum);
|
lm_ysizes.resize(lm_ybnum);
|
||||||
node_num = (lm_xbnum+1) * (lm_ybnum+1);
|
node_num_ = (lm_xbnum+1) * (lm_ybnum+1);
|
||||||
ele_num = lm_xbnum * lm_ybnum;
|
ele_num_ = lm_xbnum * lm_ybnum;
|
||||||
|
|
||||||
for (int i = 0; i < lm_xbnum; i++)
|
for (int i = 0; i < lm_xbnum; i++)
|
||||||
{
|
{
|
||||||
@ -126,8 +129,8 @@ void gctl::linear_mesh_2d::load_binary(std::string filename)
|
|||||||
infile.read((char*)lm_ysizes.get(i), sizeof(double));
|
infile.read((char*)lm_ysizes.get(i), sizeof(double));
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes.resize(node_num);
|
nodes.resize(node_num_);
|
||||||
elements.resize(ele_num);
|
elements.resize(ele_num_);
|
||||||
|
|
||||||
double x_p, y_p = lm_ymin - 0.5*lm_ysizes[0];
|
double x_p, y_p = lm_ymin - 0.5*lm_ysizes[0];
|
||||||
for (int j = 0; j < lm_ybnum+1; j++)
|
for (int j = 0; j < lm_ybnum+1; j++)
|
||||||
@ -157,7 +160,7 @@ void gctl::linear_mesh_2d::load_binary(std::string filename)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initialized = true;
|
initialized_ = true;
|
||||||
|
|
||||||
// 读入模型数据单元
|
// 读入模型数据单元
|
||||||
load_datablock(infile);
|
load_datablock(infile);
|
||||||
@ -168,10 +171,7 @@ void gctl::linear_mesh_2d::load_binary(std::string filename)
|
|||||||
|
|
||||||
void gctl::linear_mesh_2d::save_binary(std::string filename)
|
void gctl::linear_mesh_2d::save_binary(std::string filename)
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ofstream outfile;
|
std::ofstream outfile;
|
||||||
gctl::open_outfile(outfile, filename, ".2m", std::ios::out|std::ios::binary);
|
gctl::open_outfile(outfile, filename, ".2m", std::ios::out|std::ios::binary);
|
||||||
@ -214,61 +214,63 @@ gctl::linear_mesh_2d::~linear_mesh_2d(){}
|
|||||||
|
|
||||||
int gctl::linear_mesh_2d::get_xbnum() const
|
int gctl::linear_mesh_2d::get_xbnum() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return lm_xbnum;
|
return lm_xbnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gctl::linear_mesh_2d::get_ybnum() const
|
int gctl::linear_mesh_2d::get_ybnum() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return lm_ybnum;
|
return lm_ybnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::linear_mesh_2d::get_xmin() const
|
double gctl::linear_mesh_2d::get_xmin() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return lm_xmin;
|
return lm_xmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::linear_mesh_2d::get_ymin() const
|
double gctl::linear_mesh_2d::get_ymin() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return lm_ymin;
|
return lm_ymin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double gctl::linear_mesh_2d::get_xmax() const
|
||||||
|
{
|
||||||
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
|
|
||||||
|
double xmax = lm_xmin - 0.5*lm_xsizes[0];
|
||||||
|
for (size_t i = 0; i < lm_xsizes.size(); i++)
|
||||||
|
{
|
||||||
|
xmax += lm_xsizes[i];
|
||||||
|
}
|
||||||
|
xmax -= 0.5*lm_xsizes.back();
|
||||||
|
return xmax;
|
||||||
|
}
|
||||||
|
|
||||||
|
double gctl::linear_mesh_2d::get_ymax() const
|
||||||
|
{
|
||||||
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
|
|
||||||
|
double ymax = lm_ymin - 0.5*lm_ysizes[0];
|
||||||
|
for (size_t i = 0; i < lm_ysizes.size(); i++)
|
||||||
|
{
|
||||||
|
ymax += lm_ysizes[i];
|
||||||
|
}
|
||||||
|
ymax -= 0.5*lm_ysizes.back();
|
||||||
|
return ymax;
|
||||||
|
}
|
||||||
|
|
||||||
const gctl::array<double> *gctl::linear_mesh_2d::get_xsizes() const
|
const gctl::array<double> *gctl::linear_mesh_2d::get_xsizes() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return &lm_xsizes;
|
return &lm_xsizes;
|
||||||
}
|
}
|
||||||
|
|
||||||
const gctl::array<double> *gctl::linear_mesh_2d::get_ysizes() const
|
const gctl::array<double> *gctl::linear_mesh_2d::get_ysizes() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return &lm_ysizes;
|
return &lm_ysizes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,14 +284,14 @@ void gctl::linear_mesh_2d::save_gmsh(std::string filename, index_packed_e packed
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void gctl::linear_mesh_2d::save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed)
|
void gctl::linear_mesh_2d::save_gmsh(std::string filename, output_type_e out_mode, index_packed_e packed)
|
||||||
{
|
{
|
||||||
base_mesh::save_gmsh(filename, d_type, out_mode, packed);
|
base_mesh::save_gmsh_withdata(filename, out_mode, packed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::linear_mesh_2d::save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed)
|
void gctl::linear_mesh_2d::save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed)
|
||||||
{
|
{
|
||||||
base_mesh::save_gmsh(filename, datname, out_mode, packed);
|
base_mesh::save_gmsh_withdata(filename, datname, out_mode, packed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,8 @@ namespace gctl
|
|||||||
void init(std::string in_name, std::string in_info, double xmin, double ymin,
|
void init(std::string in_name, std::string in_info, double xmin, double ymin,
|
||||||
const array<double> &xsizes, const array<double> &ysizes);
|
const array<double> &xsizes, const array<double> &ysizes);
|
||||||
|
|
||||||
|
void show_mesh_dimension(std::ostream &os) const;
|
||||||
|
|
||||||
void load_binary(std::string filename);
|
void load_binary(std::string filename);
|
||||||
void save_binary(std::string filename);
|
void save_binary(std::string filename);
|
||||||
|
|
||||||
@ -59,11 +61,13 @@ namespace gctl
|
|||||||
int get_ybnum() const;
|
int get_ybnum() const;
|
||||||
double get_xmin() const;
|
double get_xmin() const;
|
||||||
double get_ymin() const;
|
double get_ymin() const;
|
||||||
|
double get_xmax() const;
|
||||||
|
double get_ymax() const;
|
||||||
const array<double> *get_xsizes() const;
|
const array<double> *get_xsizes() const;
|
||||||
const array<double> *get_ysizes() const;
|
const array<double> *get_ysizes() const;
|
||||||
|
|
||||||
void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
||||||
void save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -30,11 +30,7 @@
|
|||||||
void gctl::linear_mesh_3d::init(std::string in_name, std::string in_info, double xmin, double ymin,
|
void gctl::linear_mesh_3d::init(std::string in_name, std::string in_info, double xmin, double ymin,
|
||||||
double zmin, const array<double> &xsizes, const array<double> &ysizes, const array<double> &zsizes)
|
double zmin, const array<double> &xsizes, const array<double> &ysizes, const array<double> &zsizes)
|
||||||
{
|
{
|
||||||
if (initialized)
|
check_initiated(true); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is already initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
base_mesh::init(LINEAR_MESH, MESH_3D, in_name, in_info);
|
base_mesh::init(LINEAR_MESH, MESH_3D, in_name, in_info);
|
||||||
|
|
||||||
lm_xmin = xmin;
|
lm_xmin = xmin;
|
||||||
@ -47,8 +43,8 @@ void gctl::linear_mesh_3d::init(std::string in_name, std::string in_info, double
|
|||||||
lm_ysizes.resize(lm_ybnum);
|
lm_ysizes.resize(lm_ybnum);
|
||||||
lm_zsizes.resize(lm_zbnum);
|
lm_zsizes.resize(lm_zbnum);
|
||||||
|
|
||||||
node_num = (lm_xbnum+1) * (lm_ybnum+1) * (lm_zbnum+1);
|
node_num_ = (lm_xbnum+1) * (lm_ybnum+1) * (lm_zbnum+1);
|
||||||
ele_num = lm_xbnum * lm_ybnum * lm_zbnum;
|
ele_num_ = lm_xbnum * lm_ybnum * lm_zbnum;
|
||||||
|
|
||||||
for (int i = 0; i < lm_xbnum; i++)
|
for (int i = 0; i < lm_xbnum; i++)
|
||||||
{
|
{
|
||||||
@ -65,8 +61,8 @@ void gctl::linear_mesh_3d::init(std::string in_name, std::string in_info, double
|
|||||||
lm_zsizes[i] = zsizes[i];
|
lm_zsizes[i] = zsizes[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes.resize(node_num);
|
nodes.resize(node_num_);
|
||||||
elements.resize(ele_num);
|
elements.resize(ele_num_);
|
||||||
|
|
||||||
int tmp_index;
|
int tmp_index;
|
||||||
double x_p, y_p, z_p = lm_zmin - 0.5*lm_zsizes[0];
|
double x_p, y_p, z_p = lm_zmin - 0.5*lm_zsizes[0];
|
||||||
@ -112,16 +108,24 @@ void gctl::linear_mesh_3d::init(std::string in_name, std::string in_info, double
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initialized = true;
|
initialized_ = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::linear_mesh_3d::show_mesh_dimension(std::ostream &os) const
|
||||||
|
{
|
||||||
|
os << "node num: " << node_num_ << std::endl;
|
||||||
|
os << "elem num: " << ele_num_ << std::endl;
|
||||||
|
os << "x-range: " << get_xmin() << " -> " << get_xmax() << "\n";
|
||||||
|
os << "y-range: " << get_ymin() << " -> " << get_ymax() << "\n";
|
||||||
|
os << "z-range: " << get_zmin() << " -> " << get_zmax() << "\n";
|
||||||
|
os << "dimension: " << lm_xbnum << ", " << lm_ybnum << ", " << lm_zbnum << "\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::linear_mesh_3d::load_binary(std::string filename)
|
void gctl::linear_mesh_3d::load_binary(std::string filename)
|
||||||
{
|
{
|
||||||
if (initialized)
|
check_initiated(true); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is already initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ifstream infile;
|
std::ifstream infile;
|
||||||
gctl::open_infile(infile, filename, ".2m",
|
gctl::open_infile(infile, filename, ".2m",
|
||||||
@ -141,8 +145,8 @@ void gctl::linear_mesh_3d::load_binary(std::string filename)
|
|||||||
lm_xsizes.resize(lm_xbnum);
|
lm_xsizes.resize(lm_xbnum);
|
||||||
lm_ysizes.resize(lm_ybnum);
|
lm_ysizes.resize(lm_ybnum);
|
||||||
lm_zsizes.resize(lm_zbnum);
|
lm_zsizes.resize(lm_zbnum);
|
||||||
node_num = (lm_xbnum+1) * (lm_ybnum+1) * (lm_zbnum+1);
|
node_num_ = (lm_xbnum+1) * (lm_ybnum+1) * (lm_zbnum+1);
|
||||||
ele_num = lm_xbnum * lm_ybnum * lm_zbnum;
|
ele_num_ = lm_xbnum * lm_ybnum * lm_zbnum;
|
||||||
|
|
||||||
for (int i = 0; i < lm_xbnum; i++)
|
for (int i = 0; i < lm_xbnum; i++)
|
||||||
{
|
{
|
||||||
@ -159,8 +163,8 @@ void gctl::linear_mesh_3d::load_binary(std::string filename)
|
|||||||
infile.read((char*)lm_zsizes.get(i), sizeof(double));
|
infile.read((char*)lm_zsizes.get(i), sizeof(double));
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes.resize(node_num);
|
nodes.resize(node_num_);
|
||||||
elements.resize(ele_num);
|
elements.resize(ele_num_);
|
||||||
|
|
||||||
int tmp_index;
|
int tmp_index;
|
||||||
double x_p, y_p, z_p = lm_zmin - 0.5*lm_zsizes[0];
|
double x_p, y_p, z_p = lm_zmin - 0.5*lm_zsizes[0];
|
||||||
@ -206,7 +210,7 @@ void gctl::linear_mesh_3d::load_binary(std::string filename)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initialized = true;
|
initialized_ = true;
|
||||||
|
|
||||||
// 读入模型数据单元
|
// 读入模型数据单元
|
||||||
load_datablock(infile);
|
load_datablock(infile);
|
||||||
@ -217,10 +221,7 @@ void gctl::linear_mesh_3d::load_binary(std::string filename)
|
|||||||
|
|
||||||
void gctl::linear_mesh_3d::save_binary(std::string filename)
|
void gctl::linear_mesh_3d::save_binary(std::string filename)
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ofstream outfile;
|
std::ofstream outfile;
|
||||||
gctl::open_outfile(outfile, filename, ".2m",
|
gctl::open_outfile(outfile, filename, ".2m",
|
||||||
@ -272,91 +273,94 @@ gctl::linear_mesh_3d::~linear_mesh_3d(){}
|
|||||||
|
|
||||||
int gctl::linear_mesh_3d::get_xbnum() const
|
int gctl::linear_mesh_3d::get_xbnum() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return lm_xbnum;
|
return lm_xbnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gctl::linear_mesh_3d::get_ybnum() const
|
int gctl::linear_mesh_3d::get_ybnum() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return lm_ybnum;
|
return lm_ybnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gctl::linear_mesh_3d::get_zbnum() const
|
int gctl::linear_mesh_3d::get_zbnum() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return lm_zbnum;
|
return lm_zbnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::linear_mesh_3d::get_xmin() const
|
double gctl::linear_mesh_3d::get_xmin() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return lm_xmin;
|
return lm_xmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::linear_mesh_3d::get_ymin() const
|
double gctl::linear_mesh_3d::get_ymin() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return lm_ymin;
|
return lm_ymin;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::linear_mesh_3d::get_zmin() const
|
double gctl::linear_mesh_3d::get_zmin() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return lm_zmin;
|
return lm_zmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double gctl::linear_mesh_3d::get_xmax() const
|
||||||
|
{
|
||||||
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
|
|
||||||
|
double xmax = lm_xmin - 0.5*lm_xsizes[0];
|
||||||
|
for (size_t i = 0; i < lm_xsizes.size(); i++)
|
||||||
|
{
|
||||||
|
xmax += lm_xsizes[i];
|
||||||
|
}
|
||||||
|
xmax -= 0.5*lm_xsizes.back();
|
||||||
|
return xmax;
|
||||||
|
}
|
||||||
|
|
||||||
|
double gctl::linear_mesh_3d::get_ymax() const
|
||||||
|
{
|
||||||
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
|
|
||||||
|
double ymax = lm_ymin - 0.5*lm_ysizes[0];
|
||||||
|
for (size_t i = 0; i < lm_ysizes.size(); i++)
|
||||||
|
{
|
||||||
|
ymax += lm_ysizes[i];
|
||||||
|
}
|
||||||
|
ymax -= 0.5*lm_ysizes.back();
|
||||||
|
return ymax;
|
||||||
|
}
|
||||||
|
|
||||||
|
double gctl::linear_mesh_3d::get_zmax() const
|
||||||
|
{
|
||||||
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
|
|
||||||
|
double zmax = lm_zmin - 0.5*lm_zsizes[0];
|
||||||
|
for (size_t i = 0; i < lm_zsizes.size(); i++)
|
||||||
|
{
|
||||||
|
zmax += lm_zsizes[i];
|
||||||
|
}
|
||||||
|
zmax -= 0.5*lm_zsizes.back();
|
||||||
|
return zmax;
|
||||||
|
}
|
||||||
|
|
||||||
const gctl::array<double> *gctl::linear_mesh_3d::get_xsizes() const
|
const gctl::array<double> *gctl::linear_mesh_3d::get_xsizes() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return &lm_xsizes;
|
return &lm_xsizes;
|
||||||
}
|
}
|
||||||
|
|
||||||
const gctl::array<double> *gctl::linear_mesh_3d::get_ysizes() const
|
const gctl::array<double> *gctl::linear_mesh_3d::get_ysizes() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return &lm_ysizes;
|
return &lm_ysizes;
|
||||||
}
|
}
|
||||||
|
|
||||||
const gctl::array<double> *gctl::linear_mesh_3d::get_zsizes() const
|
const gctl::array<double> *gctl::linear_mesh_3d::get_zsizes() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return &lm_zsizes;
|
return &lm_zsizes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,14 +373,14 @@ void gctl::linear_mesh_3d::save_gmsh(std::string filename, index_packed_e packed
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::linear_mesh_3d::save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed)
|
void gctl::linear_mesh_3d::save_gmsh(std::string filename, output_type_e out_mode, index_packed_e packed)
|
||||||
{
|
{
|
||||||
base_mesh::save_gmsh(filename, d_type, out_mode, packed);
|
base_mesh::save_gmsh_withdata(filename, out_mode, packed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::linear_mesh_3d::save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed)
|
void gctl::linear_mesh_3d::save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed)
|
||||||
{
|
{
|
||||||
base_mesh::save_gmsh(filename, datname, out_mode, packed);
|
base_mesh::save_gmsh_withdata(filename, datname, out_mode, packed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,8 @@ namespace gctl
|
|||||||
double zmin, const array<double> &xsizes, const array<double> &ysizes,
|
double zmin, const array<double> &xsizes, const array<double> &ysizes,
|
||||||
const array<double> &zsizes);
|
const array<double> &zsizes);
|
||||||
|
|
||||||
|
void show_mesh_dimension(std::ostream &os) const;
|
||||||
|
|
||||||
void load_binary(std::string filename);
|
void load_binary(std::string filename);
|
||||||
void save_binary(std::string filename);
|
void save_binary(std::string filename);
|
||||||
|
|
||||||
@ -63,12 +65,15 @@ namespace gctl
|
|||||||
double get_xmin() const;
|
double get_xmin() const;
|
||||||
double get_ymin() const;
|
double get_ymin() const;
|
||||||
double get_zmin() const;
|
double get_zmin() const;
|
||||||
|
double get_xmax() const;
|
||||||
|
double get_ymax() const;
|
||||||
|
double get_zmax() const;
|
||||||
const array<double> *get_xsizes() const;
|
const array<double> *get_xsizes() const;
|
||||||
const array<double> *get_ysizes() const;
|
const array<double> *get_ysizes() const;
|
||||||
const array<double> *get_zsizes() const;
|
const array<double> *get_zsizes() const;
|
||||||
|
|
||||||
void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
||||||
void save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
File diff suppressed because it is too large
Load Diff
418
lib/mesh/mesh.h
418
lib/mesh/mesh.h
@ -1,4 +1,4 @@
|
|||||||
/********************************************************
|
/********************************************************
|
||||||
* ██████╗ ██████╗████████╗██╗
|
* ██████╗ ██████╗████████╗██╗
|
||||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
* ██║ ███╗██║ ██║ ██║
|
* ██║ ███╗██║ ██║ ██║
|
||||||
@ -28,13 +28,7 @@
|
|||||||
#ifndef _GCTL_BASE_MESH_H
|
#ifndef _GCTL_BASE_MESH_H
|
||||||
#define _GCTL_BASE_MESH_H
|
#define _GCTL_BASE_MESH_H
|
||||||
|
|
||||||
#include "list"
|
|
||||||
|
|
||||||
#include "meshdata.h"
|
#include "meshdata.h"
|
||||||
#include "meshdata_scalar.h"
|
|
||||||
#include "meshdata_vector.h"
|
|
||||||
#include "meshdata_tensor.h"
|
|
||||||
|
|
||||||
#include "gctl/io.h"
|
#include "gctl/io.h"
|
||||||
#include "gctl/algorithm.h"
|
#include "gctl/algorithm.h"
|
||||||
|
|
||||||
@ -42,6 +36,7 @@ namespace gctl
|
|||||||
{
|
{
|
||||||
enum mesh_type_e
|
enum mesh_type_e
|
||||||
{
|
{
|
||||||
|
UNDEFINED,
|
||||||
REGULAR_MESH,
|
REGULAR_MESH,
|
||||||
LINEAR_MESH,
|
LINEAR_MESH,
|
||||||
TRI_TET_MESH,
|
TRI_TET_MESH,
|
||||||
@ -53,6 +48,7 @@ namespace gctl
|
|||||||
|
|
||||||
enum mesh_dim_e
|
enum mesh_dim_e
|
||||||
{
|
{
|
||||||
|
MESH_0D,
|
||||||
MESH_2D,
|
MESH_2D,
|
||||||
MESH_3D,
|
MESH_3D,
|
||||||
};
|
};
|
||||||
@ -74,7 +70,6 @@ namespace gctl
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 检查网格是否已经初始化。
|
* @brief 检查网格是否已经初始化。
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
bool initiated() const;
|
bool initiated() const;
|
||||||
|
|
||||||
@ -85,36 +80,6 @@ namespace gctl
|
|||||||
*/
|
*/
|
||||||
bool saved(std::string datname) const;
|
bool saved(std::string datname) const;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 返回对应名称的数据对象指针。
|
|
||||||
*
|
|
||||||
* @param datname 数据名
|
|
||||||
* @return 数据指针
|
|
||||||
*/
|
|
||||||
meshdata *get_data(std::string datname) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 返回所有数据指针。
|
|
||||||
*
|
|
||||||
* @param out_list 数据指针列表
|
|
||||||
*/
|
|
||||||
void get_all_data(array<meshdata*> &out_list) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 返回对应名称的数据对象的数组指针。
|
|
||||||
*
|
|
||||||
* @param datname 数据名
|
|
||||||
* @return 数组指针(注意需要转换为对应的数组指针类型)
|
|
||||||
*/
|
|
||||||
void *get_datval(std::string datname) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 删除对应名称的数据对象。
|
|
||||||
*
|
|
||||||
* @param datname 数据名
|
|
||||||
*/
|
|
||||||
void remove_data(std::string datname);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 显示网格与数据信息。
|
* @brief 显示网格与数据信息。
|
||||||
*
|
*
|
||||||
@ -122,14 +87,6 @@ namespace gctl
|
|||||||
*/
|
*/
|
||||||
void show_info(std::ostream &os = std::clog) const;
|
void show_info(std::ostream &os = std::clog) const;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 重命名数据对象。
|
|
||||||
*
|
|
||||||
* @param oldname 旧名称
|
|
||||||
* @param newname 新名称
|
|
||||||
*/
|
|
||||||
void rename_data(std::string oldname, std::string newname);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 返回网格类型
|
* @brief 返回网格类型
|
||||||
*
|
*
|
||||||
@ -194,156 +151,109 @@ namespace gctl
|
|||||||
void set_meshinfo(std::string in_info);
|
void set_meshinfo(std::string in_info);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 添加标量网格数据对象并赋初始值,如果对象已经存在则赋初始值
|
* @brief 添加网格数据。
|
||||||
*
|
*
|
||||||
* @param in_name 数据对象名称
|
* @param in_loctype 网格数据类型(块体或顶点数据)
|
||||||
* @param in_type 数据对象类型
|
* @param in_valtype 网格数据值类型
|
||||||
* @param if_output 数据对象是否可输出
|
* @param name 数据名称
|
||||||
* @param init_val 初始值
|
* @param init_val 数据初始值
|
||||||
* @return 新建的数据对象指针
|
* @param if_output 数据是否可用于输出
|
||||||
|
* @param nan_val 数据无效值标记
|
||||||
|
*
|
||||||
|
* @return 数据对象
|
||||||
*/
|
*/
|
||||||
meshdata *add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, double init_val);
|
meshdata &add_data(mesh_data_type_e in_loctype, mesh_data_value_e in_valtype, std::string name,
|
||||||
|
double init_val, bool if_output = true, double nan_val = GCTL_BDL_MAX);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 添加适量网格数据对象并赋初始值,如果对象已经存在则赋初始值
|
* @brief 添加网格数据。
|
||||||
*
|
*
|
||||||
* @param in_name 数据对象名称
|
* @param in_loctype 网格数据类型(块体或顶点数据)
|
||||||
* @param in_type 数据对象类型
|
* @param name 数据名称
|
||||||
* @param if_output 数据对象是否可输出
|
* @param init_arr 数据初始值数组
|
||||||
* @param init_val 初始值
|
* @param if_output 数据是否可用于输出
|
||||||
* @return 新建的数据对象指针
|
* @param nan_val 数据无效值标记
|
||||||
|
*
|
||||||
|
* @return 数据对象
|
||||||
*/
|
*/
|
||||||
meshdata *add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, gctl::point3dc init_val);
|
meshdata &add_data(mesh_data_type_e in_loctype, std::string name, const array<double> &init_arr,
|
||||||
|
bool if_output = true, double nan_val = GCTL_BDL_MAX);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 添加张量网格数据对象并赋初始值,如果对象已经存在则赋初始值
|
* @brief 添加网格数据。
|
||||||
*
|
*
|
||||||
* @param in_name 数据对象名称
|
* @param in_loctype 网格数据类型(块体或顶点数据)
|
||||||
* @param in_type 数据对象类型
|
* @param name 数据名称
|
||||||
* @param if_output 数据对象是否可输出
|
* @param init_arr 数据初始值数组
|
||||||
* @param init_val 初始值
|
* @param if_output 数据是否可用于输出
|
||||||
* @return 新建的数据对象指针
|
* @param nan_val 数据无效值标记
|
||||||
|
*
|
||||||
|
* @return 数据对象
|
||||||
*/
|
*/
|
||||||
meshdata *add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, gctl::tensor init_val);
|
meshdata &add_data(mesh_data_type_e in_loctype, std::string name, const array<point3dc> &init_arr,
|
||||||
|
bool if_output = true, double nan_val = GCTL_BDL_MAX);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 添加张量网格数据对象并初始为0值
|
* @brief 添加网格数据。
|
||||||
*
|
*
|
||||||
* @param in_name 数据对象名称
|
* @param in_loctype 网格数据类型(块体或顶点数据)
|
||||||
* @param in_type 数据对象类型
|
* @param name 数据名称
|
||||||
* @param if_output 数据对象是否可输出
|
* @param init_arr 数据初始值数组
|
||||||
* @param init_val 初始值
|
* @param if_output 数据是否可用于输出
|
||||||
* @return 新建的数据对象指针
|
* @param nan_val 数据无效值标记
|
||||||
|
*
|
||||||
|
* @return 数据对象
|
||||||
*/
|
*/
|
||||||
meshdata *add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, mesh_data_value_e val_type);
|
meshdata &add_data(mesh_data_type_e in_loctype, std::string name, const array<tensor> &init_arr,
|
||||||
|
bool if_output = true, double nan_val = GCTL_BDL_MAX);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief (基类虚函数)初始化规则网格
|
* @brief 返回对应名称的数据对象指针。
|
||||||
*
|
*
|
||||||
* @param in_name 网格名称
|
* @param datname 数据名
|
||||||
* @param in_info 网格说明信息
|
* @return 数据指针
|
||||||
* @param xnum 网格x轴数量
|
|
||||||
* @param ynum 网格y轴数量
|
|
||||||
* @param xmin 网格x轴最小值
|
|
||||||
* @param ymin 网格y轴最小值
|
|
||||||
* @param dx 网格x轴间隔
|
|
||||||
* @param dy 网格y轴间隔
|
|
||||||
*/
|
*/
|
||||||
virtual void init(std::string in_name, std::string in_info, int xnum, int ynum,
|
meshdata &get_data(std::string datname);
|
||||||
double xmin, double ymin, double dx, double dy);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief 删除对应名称的数据对象。
|
||||||
*
|
*
|
||||||
* @param in_name
|
* @param datname 数据名
|
||||||
* @param in_info
|
|
||||||
* @param xbnum
|
|
||||||
* @param ybnum
|
|
||||||
* @param zbnum
|
|
||||||
* @param xmin
|
|
||||||
* @param ymin
|
|
||||||
* @param zmin
|
|
||||||
* @param xsize
|
|
||||||
* @param ysize
|
|
||||||
* @param zsize
|
|
||||||
*/
|
*/
|
||||||
virtual void init(std::string in_name, std::string in_info, int xbnum, int ybnum, int zbnum,
|
void remove_data(std::string datname);
|
||||||
double xmin, double ymin, double zmin, double xsize, double ysize, double zsize);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief 保存网格到Gmsh文件,并保存所有数据。
|
||||||
*
|
*
|
||||||
* @param in_name
|
* @param filename 文件名
|
||||||
* @param in_info
|
* @param out_mode 输出模式
|
||||||
* @param lon_min
|
* @param packed 索引是否为紧凑(从0开始)
|
||||||
* @param lat_min
|
|
||||||
* @param rad_min
|
|
||||||
* @param lon_size
|
|
||||||
* @param lat_size
|
|
||||||
* @param rad_size
|
|
||||||
* @param lon_bnum
|
|
||||||
* @param lat_bnum
|
|
||||||
* @param rad_bnum
|
|
||||||
*/
|
*/
|
||||||
virtual void init(std::string in_name, std::string in_info, double lon_min, double lat_min,
|
void save_gmsh_withdata(std::string filename, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
double rad_min, double lon_size, double lat_size, double rad_size, int lon_bnum, int lat_bnum, int rad_bnum);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief 保存网格到Gmsh文件,并保存指定名称的数据。
|
||||||
*
|
*
|
||||||
* @param in_name
|
* @param filename 文件名
|
||||||
* @param in_info
|
* @param datname 数据名
|
||||||
* @param xmin
|
* @param out_mode 输出模式
|
||||||
* @param ymin
|
* @param packed 索引是否为紧凑(从0开始)
|
||||||
* @param xsizes
|
|
||||||
* @param ysizes
|
|
||||||
*/
|
*/
|
||||||
virtual void init(std::string in_name, std::string in_info, double xmin, double ymin,
|
void save_gmsh_withdata(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
const gctl::array<double> &xsizes, const gctl::array<double> &ysizes);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief (基类虚函数)保存网格到Gmsh文件。
|
||||||
*
|
*
|
||||||
* @param in_name
|
* @param filename 文件名
|
||||||
* @param in_info
|
* @param packed 索引是否为紧凑(从0开始)
|
||||||
* @param xmin
|
|
||||||
* @param ymin
|
|
||||||
* @param zmin
|
|
||||||
* @param xsizes
|
|
||||||
* @param ysizes
|
|
||||||
* @param zsizes
|
|
||||||
*/
|
*/
|
||||||
virtual void init(std::string in_name, std::string in_info, double xmin, double ymin,
|
virtual void save_gmsh(std::string filename, index_packed_e packed = Packed) = 0;
|
||||||
double zmin, const gctl::array<double> &xsizes, const gctl::array<double> &ysizes,
|
|
||||||
const gctl::array<double> &zsizes);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @param in_name
|
|
||||||
* @param in_info
|
|
||||||
* @param in_nodes
|
|
||||||
* @param in_triangles
|
|
||||||
*/
|
|
||||||
virtual void init(std::string in_name, std::string in_info, const gctl::array<gctl::vertex2dc> &in_nodes,
|
|
||||||
const gctl::array<gctl::triangle2d> &in_triangles);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @param in_name
|
|
||||||
* @param in_info
|
|
||||||
* @param in_nodes
|
|
||||||
* @param in_tets
|
|
||||||
*/
|
|
||||||
virtual void init(std::string in_name, std::string in_info, const gctl::array<gctl::vertex3dc> &in_nodes,
|
|
||||||
const gctl::array<gctl::tetrahedron> &in_tets);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 显示网格的维度信息
|
* @brief 显示网格的维度信息
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
virtual void show_mesh_dimension(std::ostream &os) const;
|
virtual void show_mesh_dimension(std::ostream &os) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief (基类纯虚函数)读入二进制网格文件
|
* @brief (基类纯虚函数)读入二进制网格文件
|
||||||
@ -359,190 +269,44 @@ namespace gctl
|
|||||||
*/
|
*/
|
||||||
virtual void save_binary(std::string filename) = 0;
|
virtual void save_binary(std::string filename) = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief (基类虚函数)保存网格到Gmsh文件。
|
|
||||||
*
|
|
||||||
* @param filename 文件名
|
|
||||||
* @param packed 索引是否为紧凑(从0开始)
|
|
||||||
*/
|
|
||||||
virtual void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @param filename
|
|
||||||
* @param d_type
|
|
||||||
* @param out_mode
|
|
||||||
* @param packed
|
|
||||||
*/
|
|
||||||
void save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed = Packed);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @param filename
|
|
||||||
* @param datname
|
|
||||||
* @param out_mode
|
|
||||||
* @param packed
|
|
||||||
*/
|
|
||||||
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 将输入的自由点位上的浮点数据插值为规则网络的顶点或者块体数据
|
|
||||||
*
|
|
||||||
* @param in_posi 输入的自由点位的坐标
|
|
||||||
* @param in_val 输入的自由点位的数值
|
|
||||||
* @param[in] search_xlen 插值搜索区域的x半径
|
|
||||||
* @param[in] search_ylen 插值搜索区域的y半径
|
|
||||||
* @param[in] search_deg 插值搜索区域的x半径绕x轴正方向逆时针旋转的角度(弧度)
|
|
||||||
* @param[in] datname 网格后的数据名称
|
|
||||||
* @param[in] d_type 网格后的数据类型
|
|
||||||
*/
|
|
||||||
virtual 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);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @param in_posi
|
|
||||||
* @param in_val
|
|
||||||
* @param search_xlen
|
|
||||||
* @param search_ylen
|
|
||||||
* @param search_deg
|
|
||||||
* @param datname
|
|
||||||
* @param d_type
|
|
||||||
*/
|
|
||||||
virtual void load_data_cloud(const array<point3dc> &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);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @param datname
|
|
||||||
* @param in_posi
|
|
||||||
* @param out_val
|
|
||||||
*/
|
|
||||||
virtual void extract_points(std::string datname, const array<point2dc> &in_posi, array<double> &out_val);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @param datname
|
|
||||||
* @param in_posi
|
|
||||||
* @param out_val
|
|
||||||
*/
|
|
||||||
virtual void extract_points(std::string datname, const array<point3dc> &in_posi, array<double> &out_val);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @param datname
|
|
||||||
* @param start_p
|
|
||||||
* @param end_p
|
|
||||||
* @param size_p
|
|
||||||
* @param out_posi
|
|
||||||
* @param out_val
|
|
||||||
*/
|
|
||||||
virtual 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);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @param datname
|
|
||||||
* @param start_p
|
|
||||||
* @param end_p
|
|
||||||
* @param size_p
|
|
||||||
* @param dh
|
|
||||||
* @param out_posi
|
|
||||||
* @param out_val
|
|
||||||
*/
|
|
||||||
virtual void extract_profile(std::string datname, const point3dc &start_p, const point3dc &end_p, int size_p,
|
|
||||||
double dh, array<point3dc> &out_posi, array<double> &out_val);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @param datname
|
|
||||||
* @param p_type
|
|
||||||
* @param v_type
|
|
||||||
* @param para_str
|
|
||||||
* @param in_val
|
|
||||||
*/
|
|
||||||
virtual void edit_data(std::string datname, physical_type_e p_type, value_operator_e v_type, std::string para_str, double in_val);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @param datname
|
|
||||||
* @param p_type
|
|
||||||
* @param v_type
|
|
||||||
* @param para_str
|
|
||||||
* @param in_val
|
|
||||||
*/
|
|
||||||
virtual void edit_data(std::string datname, physical_type_e p_type, value_operator_e v_type, std::string para_str, point3dc in_val);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @param datname
|
|
||||||
* @param p_type
|
|
||||||
* @param v_type
|
|
||||||
* @param para_str
|
|
||||||
* @param in_val
|
|
||||||
*/
|
|
||||||
virtual void edit_data(std::string datname, physical_type_e p_type, value_operator_e v_type, std::string para_str, tensor in_val);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @param datname
|
|
||||||
* @param in_val
|
|
||||||
*/
|
|
||||||
virtual void purge_data(std::string datname, double in_val);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @param datname
|
|
||||||
* @param in_val
|
|
||||||
*/
|
|
||||||
virtual void purge_data(std::string datname, point3dc in_val);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @param datname
|
|
||||||
* @param in_val
|
|
||||||
*/
|
|
||||||
virtual void purge_data(std::string datname, tensor in_val);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
mesh_type_e meshtype;
|
mesh_type_e meshtype_;
|
||||||
mesh_dim_e meshdim;
|
mesh_dim_e meshdim_;
|
||||||
std::string meshname;
|
std::string meshname_;
|
||||||
std::string meshinfo;
|
std::string meshinfo_;
|
||||||
|
|
||||||
int node_num, ele_num;
|
int node_num_, ele_num_;
|
||||||
bool initialized;
|
bool initialized_;
|
||||||
|
|
||||||
std::list<meshdata*> saved_data;
|
std::vector<meshdata> datalist_;
|
||||||
std::list<meshdata*>::iterator iter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 以下为类的私有函数 只能被类的公共函数调用
|
* 以下为类的私有函数 只能被类的公共函数调用
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 检查网格是否已经初始化。
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void check_initiated(bool inverse = false) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 初始化网格
|
* @brief 初始化网格
|
||||||
*
|
*
|
||||||
* @param in_type
|
* @param in_type 网格类型
|
||||||
* @param in_dim
|
* @param in_dim 网格维度
|
||||||
* @param in_name
|
* @param in_name 网格名称
|
||||||
* @param in_info
|
* @param in_info 网格说明
|
||||||
*/
|
*/
|
||||||
void init(mesh_type_e in_type, mesh_dim_e in_dim, std::string in_name, std::string in_info);
|
void init(mesh_type_e in_type, mesh_dim_e in_dim, std::string in_name, std::string in_info);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回数据索引并检查数据对象是否存在
|
||||||
|
*
|
||||||
|
* @param datname 数据名
|
||||||
|
*/
|
||||||
|
int data_index(std::string datname) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 读入二进制网格头信息
|
* @brief 读入二进制网格头信息
|
||||||
*
|
*
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/********************************************************
|
/********************************************************
|
||||||
* ██████╗ ██████╗████████╗██╗
|
* ██████╗ ██████╗████████╗██╗
|
||||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
* ██║ ███╗██║ ██║ ██║
|
* ██║ ███╗██║ ██║ ██║
|
||||||
@ -26,69 +26,226 @@
|
|||||||
******************************************************/
|
******************************************************/
|
||||||
|
|
||||||
#include "meshdata.h"
|
#include "meshdata.h"
|
||||||
|
#include "fstream"
|
||||||
|
|
||||||
gctl::meshdata::meshdata(std::string in_name, mesh_data_type_e in_type, bool if_output)
|
gctl::meshdata::meshdata()
|
||||||
{
|
{
|
||||||
if (in_name == "")
|
name_ = "untitled";
|
||||||
|
loctype_ = NodeData;
|
||||||
|
valtype_ = Scalar;
|
||||||
|
output_ok_ = true;
|
||||||
|
nan_val_ = GCTL_BDL_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::meshdata::meshdata(mesh_data_type_e in_loctype,
|
||||||
|
mesh_data_value_e in_valtype, size_t size,
|
||||||
|
std::string name, bool if_output, double nan_val)
|
||||||
|
{
|
||||||
|
create(in_loctype, in_valtype, size, name, if_output, nan_val);
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::meshdata::~meshdata()
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::meshdata::clear()
|
||||||
|
{
|
||||||
|
name_ = "untitled";
|
||||||
|
loctype_ = NodeData;
|
||||||
|
valtype_ = Scalar;
|
||||||
|
output_ok_ = true;
|
||||||
|
nan_val_ = GCTL_BDL_MAX;
|
||||||
|
datval_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::meshdata::create(mesh_data_type_e in_loctype,
|
||||||
|
mesh_data_value_e in_valtype, size_t size,
|
||||||
|
std::string name, bool if_output, double nan_val)
|
||||||
|
{
|
||||||
|
name_ = name;
|
||||||
|
loctype_ = in_loctype;
|
||||||
|
valtype_ = in_valtype;
|
||||||
|
output_ok_ = if_output;
|
||||||
|
nan_val_ = nan_val;
|
||||||
|
if (size != 0) datval_.resize(size, 0.0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::array<gctl::point3dc> gctl::meshdata::export_vector() const
|
||||||
|
{
|
||||||
|
if (valtype_ != Vector) throw std::runtime_error("[gctl::meshdata::export_vector] Invalid data type.");
|
||||||
|
|
||||||
|
size_t n = 0;
|
||||||
|
array<point3dc> tmp(datval_.size()/3);
|
||||||
|
for (size_t i = 0; i < datval_.size(); i += 3)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("[gctl::meshdata] The input name is empty.");
|
tmp[n] = point3dc(datval_[3*i], datval_[3*i + 1], datval_[3*i + 2]);
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::array<gctl::tensor> gctl::meshdata::export_tensor() const
|
||||||
|
{
|
||||||
|
if (valtype_ != Tensor) throw std::runtime_error("[gctl::meshdata::export_tensor] Invalid data type.");
|
||||||
|
|
||||||
|
size_t n = 0;
|
||||||
|
array<tensor> tmp(datval_.size()/9);
|
||||||
|
for (size_t i = 0; i < datval_.size(); i += 9)
|
||||||
|
{
|
||||||
|
tmp[n] = tensor(datval_[9*i], datval_[9*i + 1], datval_[9*i + 2],
|
||||||
|
datval_[9*i + 3], datval_[9*i + 4], datval_[9*i + 5],
|
||||||
|
datval_[9*i + 6], datval_[9*i + 7], datval_[9*i + 8]);
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::meshdata::show_info(std::ostream &os) const
|
||||||
|
{
|
||||||
|
os << "Data: " << name_ << " | ";
|
||||||
|
if (loctype_ == NodeData) os << "node data | ";
|
||||||
|
if (loctype_ == ElemData) os << "element data | ";
|
||||||
|
if (loctype_ == ElemData2D) os << "2D element data | ";
|
||||||
|
if (loctype_ == ElemData3D) os << "3D element data | ";
|
||||||
|
if (valtype_ == Scalar) os << "scalar | ";
|
||||||
|
if (valtype_ == Vector) os << "vector | ";
|
||||||
|
if (valtype_ == Tensor) os << "tensor | ";
|
||||||
|
if (output_ok_) os << "output" << std::endl;
|
||||||
|
else os<< "no-output" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::meshdata::show_stats(std::ostream &os) const
|
||||||
|
{
|
||||||
|
int vn = 0;
|
||||||
|
if (valtype_ == Vector)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < datval_.size(); i += 3)
|
||||||
|
{
|
||||||
|
if (fabs(datval_[3*i] - nan_val_) > 1e-10) vn++;
|
||||||
}
|
}
|
||||||
|
|
||||||
datname = in_name;
|
array<double> tmp_x(vn), tmp_y(vn), tmp_z(vn);
|
||||||
dattype = in_type;
|
|
||||||
output_ok = if_output;
|
|
||||||
}
|
|
||||||
|
|
||||||
gctl::meshdata::~meshdata(){}
|
vn = 0;
|
||||||
|
for (size_t i = 0; i < datval_.size(); i += 3)
|
||||||
void gctl::meshdata::set_datname(std::string in_name)
|
|
||||||
{
|
|
||||||
if (in_name == "")
|
|
||||||
{
|
{
|
||||||
throw std::runtime_error("[gctl::meshdata] The input name is empty.");
|
if (fabs(datval_[3*i] - nan_val_) > 1e-10)
|
||||||
|
{
|
||||||
|
tmp_x[vn] = datval_[3*i];
|
||||||
|
tmp_y[vn] = datval_[3*i + 1];
|
||||||
|
tmp_z[vn] = datval_[3*i + 2];
|
||||||
|
vn++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
datname = in_name;
|
os << "mean = (" << tmp_x.mean() << ", " << tmp_y.mean() << ", " << tmp_z.mean() << ")\n"
|
||||||
|
<< "std = (" << tmp_x.std() << ", " << tmp_y.std() << ", " << tmp_z.std() << ")\n"
|
||||||
|
<< "rms = (" << tmp_x.rms() << ", " << tmp_y.rms() << ", " << tmp_z.rms() << ")\n";
|
||||||
|
}
|
||||||
|
else if (valtype_ == Tensor)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < datval_.size(); i += 9)
|
||||||
|
{
|
||||||
|
if (fabs(datval_[9*i] - nan_val_) > 1e-10) vn++;
|
||||||
|
}
|
||||||
|
|
||||||
|
array<double> tmp_xx(vn), tmp_xy(vn), tmp_xz(vn);
|
||||||
|
array<double> tmp_yx(vn), tmp_yy(vn), tmp_yz(vn);
|
||||||
|
array<double> tmp_zx(vn), tmp_zy(vn), tmp_zz(vn);
|
||||||
|
|
||||||
|
vn = 0;
|
||||||
|
for (size_t i = 0; i < datval_.size(); i += 9)
|
||||||
|
{
|
||||||
|
if (fabs(datval_[9*i] - nan_val_) > 1e-10)
|
||||||
|
{
|
||||||
|
tmp_xx[vn] = datval_[9*i];
|
||||||
|
tmp_xy[vn] = datval_[9*i + 1];
|
||||||
|
tmp_xz[vn] = datval_[9*i + 2];
|
||||||
|
tmp_yx[vn] = datval_[9*i + 3];
|
||||||
|
tmp_yy[vn] = datval_[9*i + 4];
|
||||||
|
tmp_yz[vn] = datval_[9*i + 5];
|
||||||
|
tmp_zx[vn] = datval_[9*i + 6];
|
||||||
|
tmp_zy[vn] = datval_[9*i + 7];
|
||||||
|
tmp_zz[vn] = datval_[9*i + 8];
|
||||||
|
vn++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
os << "mean = \n"
|
||||||
|
<< tmp_xx.mean() << ", " << tmp_xy.mean() << ", " << tmp_xz.mean() << "\n"
|
||||||
|
<< tmp_yx.mean() << ", " << tmp_yy.mean() << ", " << tmp_yz.mean() << "\n"
|
||||||
|
<< tmp_zx.mean() << ", " << tmp_zy.mean() << ", " << tmp_zz.mean() << "\n";
|
||||||
|
|
||||||
|
os << "std = \n"
|
||||||
|
<< tmp_xx.std() << ", " << tmp_xy.std() << ", " << tmp_xz.std() << "\n"
|
||||||
|
<< tmp_yx.std() << ", " << tmp_yy.std() << ", " << tmp_yz.std() << "\n"
|
||||||
|
<< tmp_zx.std() << ", " << tmp_zy.std() << ", " << tmp_zz.std() << "\n";
|
||||||
|
|
||||||
|
os << "rms = \n"
|
||||||
|
<< tmp_xx.rms() << ", " << tmp_xy.rms() << ", " << tmp_xz.rms() << "\n"
|
||||||
|
<< tmp_yx.rms() << ", " << tmp_yy.rms() << ", " << tmp_yz.rms() << "\n"
|
||||||
|
<< tmp_zx.rms() << ", " << tmp_zy.rms() << ", " << tmp_zz.rms() << "\n";
|
||||||
|
}
|
||||||
|
else // Scalar
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < datval_.size(); i++)
|
||||||
|
{
|
||||||
|
if (fabs(datval_[i] - nan_val_) > 1e-10) vn++;
|
||||||
|
}
|
||||||
|
|
||||||
|
array<double> tmp(vn);
|
||||||
|
|
||||||
|
vn = 0;
|
||||||
|
for (size_t i = 0; i < datval_.size(); i++)
|
||||||
|
{
|
||||||
|
if (fabs(datval_[i] - nan_val_) > 1e-10)
|
||||||
|
{
|
||||||
|
tmp[vn] = datval_[i];
|
||||||
|
vn++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
os << "mean = " << tmp.mean() << ", std = " << tmp.std() << ", rms = " << tmp.rms() << std::endl;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string gctl::meshdata::get_datname()
|
void gctl::meshdata::load_binary(std::ifstream &infile)
|
||||||
{
|
{
|
||||||
return datname;
|
int name_size;
|
||||||
}
|
infile.read((char*) &name_size, sizeof(int));
|
||||||
|
|
||||||
gctl::mesh_data_type_e gctl::meshdata::get_dattype()
|
name_.resize(name_size);
|
||||||
{
|
infile.read((char*) name_.c_str(), name_size);
|
||||||
return dattype;
|
|
||||||
}
|
|
||||||
|
|
||||||
gctl::mesh_data_value_e gctl::meshdata::get_valtype()
|
infile.read((char*) &loctype_, sizeof(int));
|
||||||
{
|
infile.read((char*) &valtype_, sizeof(int));
|
||||||
return valtype;
|
infile.read((char*) &output_ok_, sizeof(bool));
|
||||||
}
|
|
||||||
|
|
||||||
void gctl::meshdata::set_output(bool if_output)
|
int n;
|
||||||
{
|
infile.read((char*) &n, sizeof(int));
|
||||||
output_ok = if_output;
|
datval_.resize(n);
|
||||||
|
|
||||||
|
infile.read((char*) datval_.get(), sizeof(double)*datval_.size());
|
||||||
|
infile.read((char*) &nan_val_, sizeof(double));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gctl::meshdata::get_output()
|
void gctl::meshdata::save_binary(std::ofstream &outfile)
|
||||||
{
|
{
|
||||||
return output_ok;
|
int name_size = name_.size();
|
||||||
}
|
outfile.write((char*) &name_size, sizeof(int));
|
||||||
|
outfile.write((char*) name_.c_str(), name_size);
|
||||||
|
outfile.write((char*) &loctype_, sizeof(int));
|
||||||
|
outfile.write((char*) &valtype_, sizeof(int));
|
||||||
|
outfile.write((char*) &output_ok_, sizeof(bool));
|
||||||
|
|
||||||
void gctl::meshdata::show_info(std::ostream &os)
|
int n = datval_.size();
|
||||||
{
|
outfile.write((char*) &n, sizeof(int));
|
||||||
os << "Data: " << datname << " | ";
|
outfile.write((char*) datval_.get(), sizeof(double)*datval_.size());
|
||||||
if (dattype == NodeData) os << "Type: Node data | ";
|
outfile.write((char*) &nan_val_, sizeof(double));
|
||||||
if (dattype == ElemData) os << "Type: Element data | ";
|
|
||||||
if (dattype == ElemData2D) os << "Type: 2D element data | ";
|
|
||||||
if (dattype == ElemData3D) os << "Type: 3D element data | ";
|
|
||||||
if (valtype == Scalar) os << "Value: Scalar | ";
|
|
||||||
if (valtype == Vector) os << "Value: Vector | ";
|
|
||||||
if (valtype == Tensor) os << "Value: Tensor | ";
|
|
||||||
if (output_ok) os << "Output: Yes" << std::endl;
|
|
||||||
else os<< "Output: No" << std::endl;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
/********************************************************
|
/********************************************************
|
||||||
* ██████╗ ██████╗████████╗██╗
|
* ██████╗ ██████╗████████╗██╗
|
||||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
* ██║ ███╗██║ ██║ ██║
|
* ██║ ███╗██║ ██║ ██║
|
||||||
@ -30,7 +30,8 @@
|
|||||||
|
|
||||||
#include "gctl_mesh_config.h"
|
#include "gctl_mesh_config.h"
|
||||||
#include "gctl/core.h"
|
#include "gctl/core.h"
|
||||||
#include "gctl/geometry.h"
|
#include "gctl/geometry/point3c.h"
|
||||||
|
#include "gctl/geometry/tensor.h"
|
||||||
|
|
||||||
namespace gctl
|
namespace gctl
|
||||||
{
|
{
|
||||||
@ -45,83 +46,80 @@ namespace gctl
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 网格文件中的数据对象(纯虚类)。此类为具体类型的数据对象的基类
|
* @brief 网格文件中的数据对象,可储存标量、矢量和张量数据。
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
class meshdata
|
struct meshdata
|
||||||
{
|
{
|
||||||
protected:
|
std::string name_; // 数据的名称
|
||||||
std::string datname; // 数据的名称
|
mesh_data_type_e loctype_; // 数据的赋值位置属性 顶点或是元素
|
||||||
mesh_data_type_e dattype; // 数据的赋值属性 顶点或是元素(设置后不可更改)
|
mesh_data_value_e valtype_; // 数据的类型
|
||||||
mesh_data_value_e valtype; // 数据的类型(设置后不可更改)
|
bool output_ok_; // 是否可输出数据
|
||||||
bool output_ok; // 是否可输出数据
|
array<double> datval_; // 数据值 注意目前我们只支持浮点数据存储
|
||||||
|
double nan_val_; // 无效数据的标记值
|
||||||
|
|
||||||
public:
|
/**
|
||||||
// 构造函数
|
* @brief 构造函数
|
||||||
meshdata(std::string in_name, mesh_data_type_e in_type, bool if_output);
|
*/
|
||||||
|
meshdata();
|
||||||
|
|
||||||
// 析构函数
|
/**
|
||||||
|
* @brief 创建数据对象
|
||||||
|
*
|
||||||
|
* @param in_loctype 数据的赋值位置属性 顶点或是元素
|
||||||
|
* @param in_valtype 数据的类型
|
||||||
|
* @param size 数据的大小
|
||||||
|
* @param name 数据的名称
|
||||||
|
* @param if_output 是否可输出数据
|
||||||
|
* @param nan_val 无效数据的标记值
|
||||||
|
*/
|
||||||
|
meshdata(mesh_data_type_e in_loctype, mesh_data_value_e in_valtype,
|
||||||
|
size_t size, std::string name = "untitled",
|
||||||
|
bool if_output = true, double nan_val = GCTL_BDL_MAX);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 析构函数
|
||||||
|
*/
|
||||||
virtual ~meshdata();
|
virtual ~meshdata();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 设置数据名称
|
* @brief 清空数据对象
|
||||||
*
|
|
||||||
* @param[in] in_name 名称字符串
|
|
||||||
*/
|
*/
|
||||||
void set_datname(std::string in_name);
|
void clear();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 返回数据的名称
|
* @brief 创建数据对象
|
||||||
*
|
*
|
||||||
* @return 名称字符串
|
* @param in_loctype 数据的赋值位置属性 顶点或是元素
|
||||||
|
* @param in_valtype 数据的类型
|
||||||
|
* @param size 数据的大小
|
||||||
|
* @param name 数据的名称
|
||||||
|
* @param if_output 是否可输出数据
|
||||||
|
* @param nan_val 无效数据的标记值
|
||||||
*/
|
*/
|
||||||
std::string get_datname();
|
void create(mesh_data_type_e in_loctype, mesh_data_value_e in_valtype,
|
||||||
|
size_t size, std::string name = "untitled",
|
||||||
|
bool if_output = true, double nan_val = GCTL_BDL_MAX);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 返回数据的赋值类型
|
* @brief 返回适量数据。
|
||||||
*
|
|
||||||
* @return 数据赋值类型的枚举
|
|
||||||
*/
|
*/
|
||||||
mesh_data_type_e get_dattype();
|
array<point3dc> export_vector() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 返回数据值的类型
|
* @brief 返回张量数据。
|
||||||
*
|
|
||||||
* @return 数据值类型的枚举
|
|
||||||
*/
|
*/
|
||||||
mesh_data_value_e get_valtype();
|
array<tensor> export_tensor() const;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 设置数据对象输出状态的设置情况
|
|
||||||
*
|
|
||||||
* @param[in] if_output 是否可输出此对象
|
|
||||||
*/
|
|
||||||
void set_output(bool if_output);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 返回数据对象输出状态的设置情况
|
|
||||||
*
|
|
||||||
* @return 是否可输出此对象
|
|
||||||
*/
|
|
||||||
bool get_output();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 显示数据对象的头信息
|
* @brief 显示数据对象的头信息
|
||||||
*/
|
*/
|
||||||
void show_info(std::ostream &os = std::clog);
|
void show_info(std::ostream &os = std::clog) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 显示数据统计参数
|
* @brief 显示数据统计参数
|
||||||
*/
|
*/
|
||||||
virtual void show_stats(std::ostream &os = std::clog) = 0;
|
void show_stats(std::ostream &os = std::clog) const;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 返回数据块的指针 所有子类的数据块均为gctl::array类型,这是一个通用的接口。
|
|
||||||
*
|
|
||||||
* @note 注意因为具体的返回类型未知 因此需在调用后按实际数据类型转换指针
|
|
||||||
*
|
|
||||||
* @return 数据块的指针
|
|
||||||
*/
|
|
||||||
virtual void *get_datval_ptr() = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 载入二进制文件
|
* @brief 载入二进制文件
|
||||||
@ -130,7 +128,7 @@ namespace gctl
|
|||||||
*
|
*
|
||||||
* @param infile 输入文件的流(以二进制方式打开)
|
* @param infile 输入文件的流(以二进制方式打开)
|
||||||
*/
|
*/
|
||||||
virtual void load_binary(std::ifstream &infile) = 0;
|
void load_binary(std::ifstream &infile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 保存二进制文件
|
* @brief 保存二进制文件
|
||||||
@ -139,20 +137,8 @@ namespace gctl
|
|||||||
*
|
*
|
||||||
* @param outfile 输出的文件流(以二进制方式打开)
|
* @param outfile 输出的文件流(以二进制方式打开)
|
||||||
*/
|
*/
|
||||||
virtual void save_binary(std::ofstream &outfile) = 0;
|
void save_binary(std::ofstream &outfile);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 销毁指针的对象 可销毁此基类或子类指针指向的对象
|
|
||||||
*
|
|
||||||
* @param obj_ptr 网格数据指针
|
|
||||||
*/
|
|
||||||
static void destroy(meshdata *obj_ptr)
|
|
||||||
{
|
|
||||||
delete obj_ptr;
|
|
||||||
obj_ptr = nullptr;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //_GCTL_MESHDATA_H
|
#endif // _GCTL_MESHDATA_H
|
File diff suppressed because it is too large
Load Diff
@ -92,7 +92,7 @@ namespace gctl
|
|||||||
void save_surfer_grid(std::string filename, std::string datname, surfer_file_type_e grid_type = Surfer7Grid);
|
void save_surfer_grid(std::string filename, std::string datname, surfer_file_type_e grid_type = Surfer7Grid);
|
||||||
|
|
||||||
void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
||||||
void save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
|
|
||||||
void save_text(std::string filename, const array<std::string> &datname);
|
void save_text(std::string filename, const array<std::string> &datname);
|
||||||
|
@ -30,22 +30,18 @@
|
|||||||
void gctl::regular_mesh_2d::init(std::string in_name, std::string in_info, int xbnum, int ybnum,
|
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)
|
double xmin, double ymin, double xsize, double ysize)
|
||||||
{
|
{
|
||||||
if (initialized)
|
check_initiated(true); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_2d] The mesh is already initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
base_mesh::init(REGULAR_MESH, MESH_2D, in_name, in_info);
|
base_mesh::init(REGULAR_MESH, MESH_2D, in_name, in_info);
|
||||||
|
|
||||||
rm_xbnum = xbnum; rm_ybnum = ybnum;
|
rm_xbnum = xbnum; rm_ybnum = ybnum;
|
||||||
rm_xmin = xmin; rm_ymin = ymin;
|
rm_xmin = xmin; rm_ymin = ymin;
|
||||||
rm_xsize = xsize; rm_ysize = ysize;
|
rm_xsize = xsize; rm_ysize = ysize;
|
||||||
|
|
||||||
node_num = (rm_xbnum+1) * (rm_ybnum+1);
|
node_num_ = (rm_xbnum+1) * (rm_ybnum+1);
|
||||||
ele_num = rm_xbnum * rm_ybnum;
|
ele_num_ = rm_xbnum * rm_ybnum;
|
||||||
|
|
||||||
nodes.resize(node_num);
|
nodes.resize(node_num_);
|
||||||
elements.resize(ele_num);
|
elements.resize(ele_num_);
|
||||||
|
|
||||||
for (int j = 0; j < rm_ybnum+1; j++)
|
for (int j = 0; j < rm_ybnum+1; j++)
|
||||||
{
|
{
|
||||||
@ -71,16 +67,24 @@ void gctl::regular_mesh_2d::init(std::string in_name, std::string in_info, int x
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initialized = true;
|
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";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::regular_mesh_2d::load_binary(std::string filename)
|
void gctl::regular_mesh_2d::load_binary(std::string filename)
|
||||||
{
|
{
|
||||||
if (initialized)
|
check_initiated(true); // 检查网格是否已经初始化(如果已经初始化,那么就会抛出异常)
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_2d] The mesh is already initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ifstream infile;
|
std::ifstream infile;
|
||||||
gctl::open_infile(infile, filename, ".2m",
|
gctl::open_infile(infile, filename, ".2m",
|
||||||
@ -97,11 +101,11 @@ void gctl::regular_mesh_2d::load_binary(std::string filename)
|
|||||||
infile.read((char*)&rm_xsize, sizeof(double));
|
infile.read((char*)&rm_xsize, sizeof(double));
|
||||||
infile.read((char*)&rm_ysize, sizeof(double));
|
infile.read((char*)&rm_ysize, sizeof(double));
|
||||||
|
|
||||||
node_num = (rm_xbnum+1) * (rm_ybnum+1);
|
node_num_ = (rm_xbnum+1) * (rm_ybnum+1);
|
||||||
ele_num = rm_xbnum * rm_ybnum;
|
ele_num_ = rm_xbnum * rm_ybnum;
|
||||||
|
|
||||||
nodes.resize(node_num);
|
nodes.resize(node_num_);
|
||||||
elements.resize(ele_num);
|
elements.resize(ele_num_);
|
||||||
|
|
||||||
for (int j = 0; j < rm_ybnum+1; j++)
|
for (int j = 0; j < rm_ybnum+1; j++)
|
||||||
{
|
{
|
||||||
@ -127,21 +131,17 @@ void gctl::regular_mesh_2d::load_binary(std::string filename)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initialized = true;
|
|
||||||
|
|
||||||
// 读入模型数据单元
|
// 读入模型数据单元
|
||||||
load_datablock(infile);
|
load_datablock(infile);
|
||||||
|
|
||||||
infile.close();
|
infile.close();
|
||||||
|
initialized_ = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::regular_mesh_2d::save_binary(std::string filename)
|
void gctl::regular_mesh_2d::save_binary(std::string filename)
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_2d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ofstream outfile;
|
std::ofstream outfile;
|
||||||
gctl::open_outfile(outfile, filename, ".2m",
|
gctl::open_outfile(outfile, filename, ".2m",
|
||||||
@ -177,61 +177,37 @@ gctl::regular_mesh_2d::~regular_mesh_2d(){}
|
|||||||
|
|
||||||
int gctl::regular_mesh_2d::get_xbnum() const
|
int gctl::regular_mesh_2d::get_xbnum() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_2d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_xbnum;
|
return rm_xbnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gctl::regular_mesh_2d::get_ybnum() const
|
int gctl::regular_mesh_2d::get_ybnum() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_2d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_ybnum;
|
return rm_ybnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::regular_mesh_2d::get_xmin() const
|
double gctl::regular_mesh_2d::get_xmin() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_2d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_xmin;
|
return rm_xmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::regular_mesh_2d::get_ymin() const
|
double gctl::regular_mesh_2d::get_ymin() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_2d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_ymin;
|
return rm_ymin;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::regular_mesh_2d::get_xsize() const
|
double gctl::regular_mesh_2d::get_xsize() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_2d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_xsize;
|
return rm_xsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::regular_mesh_2d::get_ysize() const
|
double gctl::regular_mesh_2d::get_ysize() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_2d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_ysize;
|
return rm_ysize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,14 +220,14 @@ void gctl::regular_mesh_2d::save_gmsh(std::string filename, index_packed_e packe
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::regular_mesh_2d::save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed)
|
void gctl::regular_mesh_2d::save_gmsh(std::string filename, output_type_e out_mode, index_packed_e packed)
|
||||||
{
|
{
|
||||||
base_mesh::save_gmsh(filename, d_type, out_mode, packed);
|
base_mesh::save_gmsh_withdata(filename, out_mode, packed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::regular_mesh_2d::save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed)
|
void gctl::regular_mesh_2d::save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed)
|
||||||
{
|
{
|
||||||
base_mesh::save_gmsh(filename, datname, out_mode, packed);
|
base_mesh::save_gmsh_withdata(filename, datname, out_mode, packed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,8 @@ namespace gctl
|
|||||||
void init(std::string in_name, std::string in_info, int xbnum, int ybnum,
|
void init(std::string in_name, std::string in_info, int xbnum, int ybnum,
|
||||||
double xmin, double ymin, double xsize, double ysize);
|
double xmin, double ymin, double xsize, double ysize);
|
||||||
|
|
||||||
|
void show_mesh_dimension(std::ostream &os) const;
|
||||||
|
|
||||||
void load_binary(std::string filename);
|
void load_binary(std::string filename);
|
||||||
void save_binary(std::string filename);
|
void save_binary(std::string filename);
|
||||||
|
|
||||||
@ -63,7 +65,7 @@ namespace gctl
|
|||||||
double get_ysize() const;
|
double get_ysize() const;
|
||||||
|
|
||||||
void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
||||||
void save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -30,22 +30,18 @@
|
|||||||
void gctl::regular_mesh_3d::init(std::string in_name, std::string in_info, int xbnum, int ybnum, int zbnum,
|
void gctl::regular_mesh_3d::init(std::string in_name, std::string in_info, int xbnum, int ybnum, int zbnum,
|
||||||
double xmin, double ymin, double zmin, double xsize, double ysize, double zsize)
|
double xmin, double ymin, double zmin, double xsize, double ysize, double zsize)
|
||||||
{
|
{
|
||||||
if (initialized)
|
check_initiated(true); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_3d] The mesh is already initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
base_mesh::init(REGULAR_MESH, MESH_3D, in_name, in_info);
|
base_mesh::init(REGULAR_MESH, MESH_3D, in_name, in_info);
|
||||||
|
|
||||||
rm_xbnum = xbnum; rm_ybnum = ybnum; rm_zbnum = zbnum;
|
rm_xbnum = xbnum; rm_ybnum = ybnum; rm_zbnum = zbnum;
|
||||||
rm_xmin = xmin; rm_ymin = ymin; rm_zmin = zmin;
|
rm_xmin = xmin; rm_ymin = ymin; rm_zmin = zmin;
|
||||||
rm_xsize = xsize; rm_ysize = ysize; rm_zsize = zsize;
|
rm_xsize = xsize; rm_ysize = ysize; rm_zsize = zsize;
|
||||||
|
|
||||||
node_num = (rm_xbnum+1) * (rm_ybnum+1) *(rm_zbnum+1);
|
node_num_ = (rm_xbnum+1) * (rm_ybnum+1) *(rm_zbnum+1);
|
||||||
ele_num = rm_xbnum * rm_ybnum * rm_zbnum;
|
ele_num_ = rm_xbnum * rm_ybnum * rm_zbnum;
|
||||||
|
|
||||||
nodes.resize(node_num);
|
nodes.resize(node_num_);
|
||||||
elements.resize(ele_num);
|
elements.resize(ele_num_);
|
||||||
|
|
||||||
for (int k = 0; k < rm_zbnum+1; k++)
|
for (int k = 0; k < rm_zbnum+1; k++)
|
||||||
{
|
{
|
||||||
@ -82,16 +78,25 @@ void gctl::regular_mesh_3d::init(std::string in_name, std::string in_info, int x
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initialized = true;
|
initialized_ = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::regular_mesh_3d::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 << "z-range: " << rm_zmin << " -> " << rm_zmin + (rm_zbnum - 1)*rm_zsize << "\n";
|
||||||
|
os << "block-size: " << rm_xsize << ", " << rm_ysize << ", " << rm_zsize << "\n";
|
||||||
|
os << "dimension: " << rm_xbnum << ", " << rm_ybnum << ", " << rm_zbnum << "\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::regular_mesh_3d::load_binary(std::string filename)
|
void gctl::regular_mesh_3d::load_binary(std::string filename)
|
||||||
{
|
{
|
||||||
if (initialized)
|
check_initiated(true); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_3d] The mesh is already initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ifstream infile;
|
std::ifstream infile;
|
||||||
gctl::open_infile(infile, filename, ".2m",
|
gctl::open_infile(infile, filename, ".2m",
|
||||||
@ -111,11 +116,11 @@ void gctl::regular_mesh_3d::load_binary(std::string filename)
|
|||||||
infile.read((char*)&rm_ysize, sizeof(double));
|
infile.read((char*)&rm_ysize, sizeof(double));
|
||||||
infile.read((char*)&rm_zsize, sizeof(double));
|
infile.read((char*)&rm_zsize, sizeof(double));
|
||||||
|
|
||||||
node_num = (rm_xbnum+1) * (rm_ybnum+1) *(rm_zbnum+1);
|
node_num_ = (rm_xbnum+1) * (rm_ybnum+1) *(rm_zbnum+1);
|
||||||
ele_num = rm_xbnum * rm_ybnum * rm_zbnum;
|
ele_num_ = rm_xbnum * rm_ybnum * rm_zbnum;
|
||||||
|
|
||||||
nodes.resize(node_num);
|
nodes.resize(node_num_);
|
||||||
elements.resize(ele_num);
|
elements.resize(ele_num_);
|
||||||
|
|
||||||
for (int k = 0; k < rm_zbnum+1; k++)
|
for (int k = 0; k < rm_zbnum+1; k++)
|
||||||
{
|
{
|
||||||
@ -152,21 +157,17 @@ void gctl::regular_mesh_3d::load_binary(std::string filename)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initialized = true;
|
|
||||||
|
|
||||||
// 读入模型数据单元
|
// 读入模型数据单元
|
||||||
load_datablock(infile);
|
load_datablock(infile);
|
||||||
|
|
||||||
infile.close();
|
infile.close();
|
||||||
|
initialized_ = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::regular_mesh_3d::save_binary(std::string filename)
|
void gctl::regular_mesh_3d::save_binary(std::string filename)
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ofstream outfile;
|
std::ofstream outfile;
|
||||||
gctl::open_outfile(outfile, filename, ".2m",
|
gctl::open_outfile(outfile, filename, ".2m",
|
||||||
@ -205,91 +206,55 @@ gctl::regular_mesh_3d::~regular_mesh_3d(){}
|
|||||||
|
|
||||||
int gctl::regular_mesh_3d::get_xbnum() const
|
int gctl::regular_mesh_3d::get_xbnum() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_xbnum;
|
return rm_xbnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gctl::regular_mesh_3d::get_ybnum() const
|
int gctl::regular_mesh_3d::get_ybnum() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_ybnum;
|
return rm_ybnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gctl::regular_mesh_3d::get_zbnum() const
|
int gctl::regular_mesh_3d::get_zbnum() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_zbnum;
|
return rm_zbnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::regular_mesh_3d::get_xmin() const
|
double gctl::regular_mesh_3d::get_xmin() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_xmin;
|
return rm_xmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::regular_mesh_3d::get_ymin() const
|
double gctl::regular_mesh_3d::get_ymin() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_ymin;
|
return rm_ymin;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::regular_mesh_3d::get_zmin() const
|
double gctl::regular_mesh_3d::get_zmin() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_zmin;
|
return rm_zmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::regular_mesh_3d::get_xsize() const
|
double gctl::regular_mesh_3d::get_xsize() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_xsize;
|
return rm_xsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::regular_mesh_3d::get_ysize() const
|
double gctl::regular_mesh_3d::get_ysize() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_ysize;
|
return rm_ysize;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::regular_mesh_3d::get_zsize() const
|
double gctl::regular_mesh_3d::get_zsize() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_zsize;
|
return rm_zsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,15 +267,15 @@ void gctl::regular_mesh_3d::save_gmsh(std::string filename, index_packed_e packe
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::regular_mesh_3d::save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed)
|
void gctl::regular_mesh_3d::save_gmsh(std::string filename, output_type_e out_mode, index_packed_e packed)
|
||||||
{
|
{
|
||||||
base_mesh::save_gmsh(filename, d_type, out_mode, packed);
|
base_mesh::save_gmsh_withdata(filename, out_mode, packed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::regular_mesh_3d::save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed)
|
void gctl::regular_mesh_3d::save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed)
|
||||||
{
|
{
|
||||||
base_mesh::save_gmsh(filename, datname, out_mode, packed);
|
base_mesh::save_gmsh_withdata(filename, datname, out_mode, packed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,8 @@ namespace gctl
|
|||||||
void init(std::string in_name, std::string in_info, int xbnum, int ybnum, int zbnum,
|
void init(std::string in_name, std::string in_info, int xbnum, int ybnum, int zbnum,
|
||||||
double xmin, double ymin, double zmin, double xsize, double ysize, double zsize);
|
double xmin, double ymin, double zmin, double xsize, double ysize, double zsize);
|
||||||
|
|
||||||
|
void show_mesh_dimension(std::ostream &os) const;
|
||||||
|
|
||||||
void load_binary(std::string filename);
|
void load_binary(std::string filename);
|
||||||
void save_binary(std::string filename);
|
void save_binary(std::string filename);
|
||||||
|
|
||||||
@ -66,7 +68,7 @@ namespace gctl
|
|||||||
double get_zsize() const;
|
double get_zsize() const;
|
||||||
|
|
||||||
void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
||||||
void save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
|
|
||||||
//void edit_data(std::string datname, physical_type_e p_type, value_operator_e v_type, std::string para_str, double in_val);
|
//void edit_data(std::string datname, physical_type_e p_type, value_operator_e v_type, std::string para_str, double in_val);
|
||||||
|
@ -30,22 +30,18 @@
|
|||||||
void gctl::regular_mesh_sph_3d::init(std::string in_name, std::string in_info, double lon_min, double lat_min,
|
void gctl::regular_mesh_sph_3d::init(std::string in_name, std::string in_info, double lon_min, double lat_min,
|
||||||
double rad_min, double lon_size, double lat_size, double rad_size, int lon_bnum, int lat_bnum, int rad_bnum)
|
double rad_min, double lon_size, double lat_size, double rad_size, int lon_bnum, int lat_bnum, int rad_bnum)
|
||||||
{
|
{
|
||||||
if (initialized)
|
check_initiated(true); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_sph_3d] The mesh is already initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
base_mesh::init(REGULAR_MESH_SPH, MESH_3D, in_name, in_info);
|
base_mesh::init(REGULAR_MESH_SPH, MESH_3D, in_name, in_info);
|
||||||
|
|
||||||
rm_lon_bnum = lon_bnum; rm_lat_bnum = lat_bnum; rm_rad_bnum = rad_bnum;
|
rm_lon_bnum = lon_bnum; rm_lat_bnum = lat_bnum; rm_rad_bnum = rad_bnum;
|
||||||
rm_lon_min = lon_min; rm_lat_min = lat_min; rm_rad_min = rad_min;
|
rm_lon_min = lon_min; rm_lat_min = lat_min; rm_rad_min = rad_min;
|
||||||
rm_lon_size = lon_size; rm_lat_size = lat_size; rm_rad_size = rad_size;
|
rm_lon_size = lon_size; rm_lat_size = lat_size; rm_rad_size = rad_size;
|
||||||
|
|
||||||
node_num = (rm_lon_bnum+1) * (rm_lat_bnum+1) *(rm_rad_bnum+1);
|
node_num_ = (rm_lon_bnum+1) * (rm_lat_bnum+1) *(rm_rad_bnum+1);
|
||||||
ele_num = rm_lon_bnum * rm_lat_bnum * rm_rad_bnum;
|
ele_num_ = rm_lon_bnum * rm_lat_bnum * rm_rad_bnum;
|
||||||
|
|
||||||
nodes.resize(node_num);
|
nodes.resize(node_num_);
|
||||||
elements.resize(ele_num);
|
elements.resize(ele_num_);
|
||||||
|
|
||||||
int tmp_id;
|
int tmp_id;
|
||||||
for (int k = 0; k < rm_rad_bnum+1; k++)
|
for (int k = 0; k < rm_rad_bnum+1; k++)
|
||||||
@ -85,16 +81,25 @@ void gctl::regular_mesh_sph_3d::init(std::string in_name, std::string in_info, d
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initialized = true;
|
initialized_ = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::regular_mesh_sph_3d::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_lon_min << " -> " << rm_lon_min + (rm_lon_bnum - 1)*rm_lon_size << "\n";
|
||||||
|
os << "y-range: " << rm_lat_min << " -> " << rm_lat_min + (rm_lat_bnum - 1)*rm_lat_size << "\n";
|
||||||
|
os << "z-range: " << rm_rad_min << " -> " << rm_rad_min + (rm_rad_bnum - 1)*rm_rad_size << "\n";
|
||||||
|
os << "block-size: " << rm_lon_size << ", " << rm_lat_size << ", " << rm_rad_size << "\n";
|
||||||
|
os << "dimension: " << rm_lon_bnum << ", " << rm_lat_bnum << ", " << rm_rad_bnum << "\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::regular_mesh_sph_3d::load_binary(std::string filename)
|
void gctl::regular_mesh_sph_3d::load_binary(std::string filename)
|
||||||
{
|
{
|
||||||
if (initialized)
|
check_initiated(true); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_sph_3d] The mesh is already initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ifstream infile;
|
std::ifstream infile;
|
||||||
gctl::open_infile(infile, filename, ".2m",
|
gctl::open_infile(infile, filename, ".2m",
|
||||||
@ -114,11 +119,11 @@ void gctl::regular_mesh_sph_3d::load_binary(std::string filename)
|
|||||||
infile.read((char*)&rm_lat_size, sizeof(double));
|
infile.read((char*)&rm_lat_size, sizeof(double));
|
||||||
infile.read((char*)&rm_rad_size, sizeof(double));
|
infile.read((char*)&rm_rad_size, sizeof(double));
|
||||||
|
|
||||||
node_num = (rm_lon_bnum+1) * (rm_lat_bnum+1) *(rm_rad_bnum+1);
|
node_num_ = (rm_lon_bnum+1) * (rm_lat_bnum+1) *(rm_rad_bnum+1);
|
||||||
ele_num = rm_lon_bnum * rm_lat_bnum * rm_rad_bnum;
|
ele_num_ = rm_lon_bnum * rm_lat_bnum * rm_rad_bnum;
|
||||||
|
|
||||||
nodes.resize(node_num);
|
nodes.resize(node_num_);
|
||||||
elements.resize(ele_num);
|
elements.resize(ele_num_);
|
||||||
|
|
||||||
int tmp_id;
|
int tmp_id;
|
||||||
for (int k = 0; k < rm_rad_bnum+1; k++)
|
for (int k = 0; k < rm_rad_bnum+1; k++)
|
||||||
@ -158,7 +163,7 @@ void gctl::regular_mesh_sph_3d::load_binary(std::string filename)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initialized = true;
|
initialized_ = true;
|
||||||
|
|
||||||
// 读入模型数据单元
|
// 读入模型数据单元
|
||||||
load_datablock(infile);
|
load_datablock(infile);
|
||||||
@ -169,10 +174,7 @@ void gctl::regular_mesh_sph_3d::load_binary(std::string filename)
|
|||||||
|
|
||||||
void gctl::regular_mesh_sph_3d::save_binary(std::string filename)
|
void gctl::regular_mesh_sph_3d::save_binary(std::string filename)
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_sph_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ofstream outfile;
|
std::ofstream outfile;
|
||||||
gctl::open_outfile(outfile, filename, ".2m",
|
gctl::open_outfile(outfile, filename, ".2m",
|
||||||
@ -211,91 +213,55 @@ gctl::regular_mesh_sph_3d::~regular_mesh_sph_3d(){}
|
|||||||
|
|
||||||
int gctl::regular_mesh_sph_3d::get_lon_bnum() const
|
int gctl::regular_mesh_sph_3d::get_lon_bnum() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_sph_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_lon_bnum;
|
return rm_lon_bnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gctl::regular_mesh_sph_3d::get_lat_bnum() const
|
int gctl::regular_mesh_sph_3d::get_lat_bnum() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_sph_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_lat_bnum;
|
return rm_lat_bnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gctl::regular_mesh_sph_3d::get_rad_bnum() const
|
int gctl::regular_mesh_sph_3d::get_rad_bnum() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_sph_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_rad_bnum;
|
return rm_rad_bnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::regular_mesh_sph_3d::get_lon_min() const
|
double gctl::regular_mesh_sph_3d::get_lon_min() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_sph_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_lon_min;
|
return rm_lon_min;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::regular_mesh_sph_3d::get_lat_min() const
|
double gctl::regular_mesh_sph_3d::get_lat_min() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_sph_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_lat_min;
|
return rm_lat_min;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::regular_mesh_sph_3d::get_rad_min() const
|
double gctl::regular_mesh_sph_3d::get_rad_min() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_sph_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_rad_min;
|
return rm_rad_min;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::regular_mesh_sph_3d::get_lon_size() const
|
double gctl::regular_mesh_sph_3d::get_lon_size() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_sph_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_lon_size;
|
return rm_lon_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::regular_mesh_sph_3d::get_lat_size() const
|
double gctl::regular_mesh_sph_3d::get_lat_size() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_sph_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_lat_size;
|
return rm_lat_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
double gctl::regular_mesh_sph_3d::get_rad_size() const
|
double gctl::regular_mesh_sph_3d::get_rad_size() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::regular_mesh_sph_3d] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rm_rad_size;
|
return rm_rad_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,14 +285,14 @@ void gctl::regular_mesh_sph_3d::save_gmsh(std::string filename, index_packed_e p
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::regular_mesh_sph_3d::save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed)
|
void gctl::regular_mesh_sph_3d::save_gmsh(std::string filename, output_type_e out_mode, index_packed_e packed)
|
||||||
{
|
{
|
||||||
base_mesh::save_gmsh(filename, d_type, out_mode, packed);
|
base_mesh::save_gmsh_withdata(filename, out_mode, packed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::regular_mesh_sph_3d::save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed)
|
void gctl::regular_mesh_sph_3d::save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed)
|
||||||
{
|
{
|
||||||
base_mesh::save_gmsh(filename, datname, out_mode, packed);
|
base_mesh::save_gmsh_withdata(filename, datname, out_mode, packed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,8 @@ namespace gctl
|
|||||||
void init(std::string in_name, std::string in_info, double lon_min, double lat_min, double rad_min,
|
void init(std::string in_name, std::string in_info, double lon_min, double lat_min, double rad_min,
|
||||||
double lon_size, double lat_size, double rad_size, int lon_bnum, int lat_bnum, int rad_bnum);
|
double lon_size, double lat_size, double rad_size, int lon_bnum, int lat_bnum, int rad_bnum);
|
||||||
|
|
||||||
|
void show_mesh_dimension(std::ostream &os) const;
|
||||||
|
|
||||||
void load_binary(std::string filename);
|
void load_binary(std::string filename);
|
||||||
void save_binary(std::string filename);
|
void save_binary(std::string filename);
|
||||||
|
|
||||||
@ -64,7 +66,7 @@ namespace gctl
|
|||||||
double get_rad_size() const;
|
double get_rad_size() const;
|
||||||
|
|
||||||
void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
||||||
void save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -30,24 +30,20 @@
|
|||||||
void gctl::tetrahedron_mesh::init(std::string in_name, std::string in_info, const array<vertex3dc> &in_nodes,
|
void gctl::tetrahedron_mesh::init(std::string in_name, std::string in_info, const array<vertex3dc> &in_nodes,
|
||||||
const array<tetrahedron> &in_tets)
|
const array<tetrahedron> &in_tets)
|
||||||
{
|
{
|
||||||
if (initialized)
|
check_initiated(true); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::tetrahedron_mesh] The mesh is already initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
base_mesh::init(TRI_TET_MESH, MESH_3D, in_name, in_info);
|
base_mesh::init(TRI_TET_MESH, MESH_3D, in_name, in_info);
|
||||||
|
|
||||||
node_num = in_nodes.size();
|
node_num_ = in_nodes.size();
|
||||||
ele_num = in_tets.size();
|
ele_num_ = in_tets.size();
|
||||||
|
|
||||||
nodes.resize(node_num);
|
nodes.resize(node_num_);
|
||||||
for (int i = 0; i < node_num; i++)
|
for (int i = 0; i < node_num_; i++)
|
||||||
{
|
{
|
||||||
nodes[i] = in_nodes[i];
|
nodes[i] = in_nodes[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
elements.resize(ele_num);
|
elements.resize(ele_num_);
|
||||||
for (int i = 0; i < ele_num; i++)
|
for (int i = 0; i < ele_num_; i++)
|
||||||
{
|
{
|
||||||
elements[i].id = i;
|
elements[i].id = i;
|
||||||
for (int j = 0; j < 4; j++)
|
for (int j = 0; j < 4; j++)
|
||||||
@ -57,16 +53,20 @@ void gctl::tetrahedron_mesh::init(std::string in_name, std::string in_info, cons
|
|||||||
elements[i].deter_vert_order();
|
elements[i].deter_vert_order();
|
||||||
}
|
}
|
||||||
|
|
||||||
initialized = true;
|
initialized_ = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::tetrahedron_mesh::show_mesh_dimension(std::ostream &os) const
|
||||||
|
{
|
||||||
|
os << "node num: " << node_num_ << std::endl;
|
||||||
|
os << "elem num: " << ele_num_ << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::tetrahedron_mesh::load_binary(std::string filename)
|
void gctl::tetrahedron_mesh::load_binary(std::string filename)
|
||||||
{
|
{
|
||||||
if (initialized)
|
check_initiated(true); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::tetrahedron_mesh] The mesh is already initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ifstream infile;
|
std::ifstream infile;
|
||||||
gctl::open_infile(infile, filename, ".2m",
|
gctl::open_infile(infile, filename, ".2m",
|
||||||
@ -76,19 +76,19 @@ void gctl::tetrahedron_mesh::load_binary(std::string filename)
|
|||||||
load_headinfo(infile, TRI_TET_MESH, MESH_2D);
|
load_headinfo(infile, TRI_TET_MESH, MESH_2D);
|
||||||
|
|
||||||
// 读入网格信息
|
// 读入网格信息
|
||||||
infile.read((char*)&node_num, sizeof(int));
|
infile.read((char*)&node_num_, sizeof(int));
|
||||||
infile.read((char*)&ele_num, sizeof(int));
|
infile.read((char*)&ele_num_, sizeof(int));
|
||||||
|
|
||||||
nodes.resize(node_num);
|
nodes.resize(node_num_);
|
||||||
elements.resize(ele_num);
|
elements.resize(ele_num_);
|
||||||
|
|
||||||
for (int i = 0; i < node_num; i++)
|
for (int i = 0; i < node_num_; i++)
|
||||||
{
|
{
|
||||||
infile.read((char*)nodes.get(i), sizeof(gctl::vertex3dc));
|
infile.read((char*)nodes.get(i), sizeof(gctl::vertex3dc));
|
||||||
}
|
}
|
||||||
|
|
||||||
int in_index;
|
int in_index;
|
||||||
for (int i = 0; i < ele_num; i++)
|
for (int i = 0; i < ele_num_; i++)
|
||||||
{
|
{
|
||||||
elements[i].id = i;
|
elements[i].id = i;
|
||||||
for (int j = 0; j < 4; j++)
|
for (int j = 0; j < 4; j++)
|
||||||
@ -98,21 +98,18 @@ void gctl::tetrahedron_mesh::load_binary(std::string filename)
|
|||||||
}
|
}
|
||||||
elements[i].deter_vert_order();
|
elements[i].deter_vert_order();
|
||||||
}
|
}
|
||||||
initialized = true;
|
|
||||||
|
|
||||||
// 读入模型数据单元
|
// 读入模型数据单元
|
||||||
load_datablock(infile);
|
load_datablock(infile);
|
||||||
|
|
||||||
infile.close();
|
infile.close();
|
||||||
|
initialized_ = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::tetrahedron_mesh::save_binary(std::string filename)
|
void gctl::tetrahedron_mesh::save_binary(std::string filename)
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::tetrahedron_mesh] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ofstream outfile;
|
std::ofstream outfile;
|
||||||
gctl::open_outfile(outfile, filename, ".2m",
|
gctl::open_outfile(outfile, filename, ".2m",
|
||||||
@ -122,16 +119,16 @@ void gctl::tetrahedron_mesh::save_binary(std::string filename)
|
|||||||
save_headinfo(outfile);
|
save_headinfo(outfile);
|
||||||
|
|
||||||
// 输出网格信息
|
// 输出网格信息
|
||||||
outfile.write((char*)&node_num, sizeof(int));
|
outfile.write((char*)&node_num_, sizeof(int));
|
||||||
outfile.write((char*)&ele_num, sizeof(int));
|
outfile.write((char*)&ele_num_, sizeof(int));
|
||||||
|
|
||||||
for (int i = 0; i < node_num; i++)
|
for (int i = 0; i < node_num_; i++)
|
||||||
{
|
{
|
||||||
outfile.write((char*)nodes.get(i), sizeof(gctl::vertex3dc));
|
outfile.write((char*)nodes.get(i), sizeof(gctl::vertex3dc));
|
||||||
}
|
}
|
||||||
|
|
||||||
int in_index;
|
int in_index;
|
||||||
for (int i = 0; i < ele_num; i++)
|
for (int i = 0; i < ele_num_; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < 4; j++)
|
for (int j = 0; j < 4; j++)
|
||||||
{
|
{
|
||||||
@ -159,21 +156,13 @@ gctl::tetrahedron_mesh::~tetrahedron_mesh(){}
|
|||||||
|
|
||||||
const gctl::array<gctl::vertex3dc> &gctl::tetrahedron_mesh::get_nodes() const
|
const gctl::array<gctl::vertex3dc> &gctl::tetrahedron_mesh::get_nodes() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::tetrahedron_mesh] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
const gctl::array<gctl::tetrahedron> &gctl::tetrahedron_mesh::get_elements() const
|
const gctl::array<gctl::tetrahedron> &gctl::tetrahedron_mesh::get_elements() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查网格是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::tetrahedron_mesh] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return elements;
|
return elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,11 +172,10 @@ void gctl::tetrahedron_mesh::load_tetgen(std::string filename, index_packed_e pa
|
|||||||
gctl::read_Tetgen_element(filename, elements, nodes, packed);
|
gctl::read_Tetgen_element(filename, elements, nodes, packed);
|
||||||
|
|
||||||
// 设置名称与信息等
|
// 设置名称与信息等
|
||||||
node_num = nodes.size();
|
node_num_ = nodes.size();
|
||||||
ele_num = elements.size();
|
ele_num_ = elements.size();
|
||||||
base_mesh::init(TRI_TET_MESH, MESH_3D, filename, "Imported from a .node and .ele file.");
|
base_mesh::init(TRI_TET_MESH, MESH_3D, filename, "Imported from a .node and .ele file.");
|
||||||
initialized = true;
|
initialized_ = true;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,11 +188,10 @@ void gctl::tetrahedron_mesh::load_gmsh(std::string filename, index_packed_e pack
|
|||||||
infile.close();
|
infile.close();
|
||||||
|
|
||||||
// 设置名称与信息等
|
// 设置名称与信息等
|
||||||
node_num = nodes.size();
|
node_num_ = nodes.size();
|
||||||
ele_num = elements.size();
|
ele_num_ = elements.size();
|
||||||
base_mesh::init(TRI_TET_MESH, MESH_3D, filename, "Imported from a .msh file.");
|
base_mesh::init(TRI_TET_MESH, MESH_3D, filename, "Imported from a .msh file.");
|
||||||
initialized = true;
|
initialized_ = true;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,14 +204,14 @@ void gctl::tetrahedron_mesh::save_gmsh(std::string filename, index_packed_e pack
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::tetrahedron_mesh::save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed)
|
void gctl::tetrahedron_mesh::save_gmsh(std::string filename, output_type_e out_mode, index_packed_e packed)
|
||||||
{
|
{
|
||||||
base_mesh::save_gmsh(filename, d_type, out_mode, packed);
|
base_mesh::save_gmsh_withdata(filename, out_mode, packed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::tetrahedron_mesh::save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed)
|
void gctl::tetrahedron_mesh::save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed)
|
||||||
{
|
{
|
||||||
base_mesh::save_gmsh(filename, datname, out_mode, packed);
|
base_mesh::save_gmsh_withdata(filename, datname, out_mode, packed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,8 @@ namespace gctl
|
|||||||
void init(std::string in_name, std::string in_info, const array<vertex3dc> &in_nodes,
|
void init(std::string in_name, std::string in_info, const array<vertex3dc> &in_nodes,
|
||||||
const array<tetrahedron> &in_tets);
|
const array<tetrahedron> &in_tets);
|
||||||
|
|
||||||
|
void show_mesh_dimension(std::ostream &os) const;
|
||||||
|
|
||||||
void load_binary(std::string filename);
|
void load_binary(std::string filename);
|
||||||
void save_binary(std::string filename);
|
void save_binary(std::string filename);
|
||||||
|
|
||||||
@ -61,7 +63,7 @@ namespace gctl
|
|||||||
void load_tetgen(std::string filename, index_packed_e packed = Packed);
|
void load_tetgen(std::string filename, index_packed_e packed = Packed);
|
||||||
void load_gmsh(std::string filename, index_packed_e packed = Packed);
|
void load_gmsh(std::string filename, index_packed_e packed = Packed);
|
||||||
void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
||||||
void save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -30,24 +30,20 @@
|
|||||||
void gctl::triangle_mesh::init(std::string in_name, std::string in_info, const array<vertex2dc> &in_nodes,
|
void gctl::triangle_mesh::init(std::string in_name, std::string in_info, const array<vertex2dc> &in_nodes,
|
||||||
const array<triangle2d> &in_triangles)
|
const array<triangle2d> &in_triangles)
|
||||||
{
|
{
|
||||||
if (initialized)
|
check_initiated(true); // 检查是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::triangle_mesh] The mesh is already initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
base_mesh::init(TRI_TET_MESH, MESH_2D, in_name, in_info);
|
base_mesh::init(TRI_TET_MESH, MESH_2D, in_name, in_info);
|
||||||
|
|
||||||
node_num = in_nodes.size();
|
node_num_ = in_nodes.size();
|
||||||
ele_num = in_triangles.size();
|
ele_num_ = in_triangles.size();
|
||||||
|
|
||||||
nodes.resize(node_num);
|
nodes.resize(node_num_);
|
||||||
for (int i = 0; i < node_num; i++)
|
for (int i = 0; i < node_num_; i++)
|
||||||
{
|
{
|
||||||
nodes[i] = in_nodes[i];
|
nodes[i] = in_nodes[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
elements.resize(ele_num);
|
elements.resize(ele_num_);
|
||||||
for (int i = 0; i < ele_num; i++)
|
for (int i = 0; i < ele_num_; i++)
|
||||||
{
|
{
|
||||||
elements[i].id = i;
|
elements[i].id = i;
|
||||||
for (int j = 0; j < 3; j++)
|
for (int j = 0; j < 3; j++)
|
||||||
@ -55,16 +51,21 @@ void gctl::triangle_mesh::init(std::string in_name, std::string in_info, const a
|
|||||||
elements[i].vert[j] = nodes.get(in_triangles[i].vert[j]->id);
|
elements[i].vert[j] = nodes.get(in_triangles[i].vert[j]->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
initialized = true;
|
|
||||||
|
initialized_ = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::triangle_mesh::show_mesh_dimension(std::ostream &os) const
|
||||||
|
{
|
||||||
|
os << "node num: " << node_num_ << std::endl;
|
||||||
|
os << "elem num: " << ele_num_ << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::triangle_mesh::load_binary(std::string filename)
|
void gctl::triangle_mesh::load_binary(std::string filename)
|
||||||
{
|
{
|
||||||
if (initialized)
|
check_initiated(true); // 检查是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::triangle_mesh] The mesh is already initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ifstream infile;
|
std::ifstream infile;
|
||||||
gctl::open_infile(infile, filename, ".2m",
|
gctl::open_infile(infile, filename, ".2m",
|
||||||
@ -74,19 +75,19 @@ void gctl::triangle_mesh::load_binary(std::string filename)
|
|||||||
load_headinfo(infile, TRI_TET_MESH, MESH_2D);
|
load_headinfo(infile, TRI_TET_MESH, MESH_2D);
|
||||||
|
|
||||||
// 读入网格信息
|
// 读入网格信息
|
||||||
infile.read((char*)&node_num, sizeof(int));
|
infile.read((char*)&node_num_, sizeof(int));
|
||||||
infile.read((char*)&ele_num, sizeof(int));
|
infile.read((char*)&ele_num_, sizeof(int));
|
||||||
|
|
||||||
nodes.resize(node_num);
|
nodes.resize(node_num_);
|
||||||
elements.resize(ele_num);
|
elements.resize(ele_num_);
|
||||||
|
|
||||||
for (int i = 0; i < node_num; i++)
|
for (int i = 0; i < node_num_; i++)
|
||||||
{
|
{
|
||||||
infile.read((char*)nodes.get(i), sizeof(gctl::vertex2dc));
|
infile.read((char*)nodes.get(i), sizeof(gctl::vertex2dc));
|
||||||
}
|
}
|
||||||
|
|
||||||
int in_index;
|
int in_index;
|
||||||
for (int i = 0; i < ele_num; i++)
|
for (int i = 0; i < ele_num_; i++)
|
||||||
{
|
{
|
||||||
elements[i].id = i;
|
elements[i].id = i;
|
||||||
for (int j = 0; j < 3; j++)
|
for (int j = 0; j < 3; j++)
|
||||||
@ -95,21 +96,18 @@ void gctl::triangle_mesh::load_binary(std::string filename)
|
|||||||
elements[i].vert[j] = nodes.get(in_index);
|
elements[i].vert[j] = nodes.get(in_index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
initialized = true;
|
|
||||||
|
|
||||||
// 读入模型数据单元
|
// 读入模型数据单元
|
||||||
load_datablock(infile);
|
load_datablock(infile);
|
||||||
|
|
||||||
infile.close();
|
infile.close();
|
||||||
|
initialized_ = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::triangle_mesh::save_binary(std::string filename)
|
void gctl::triangle_mesh::save_binary(std::string filename)
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::triangle_mesh] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ofstream outfile;
|
std::ofstream outfile;
|
||||||
gctl::open_outfile(outfile, filename, ".2m",
|
gctl::open_outfile(outfile, filename, ".2m",
|
||||||
@ -119,16 +117,16 @@ void gctl::triangle_mesh::save_binary(std::string filename)
|
|||||||
save_headinfo(outfile);
|
save_headinfo(outfile);
|
||||||
|
|
||||||
// 输出网格信息
|
// 输出网格信息
|
||||||
outfile.write((char*)&node_num, sizeof(int));
|
outfile.write((char*)&node_num_, sizeof(int));
|
||||||
outfile.write((char*)&ele_num, sizeof(int));
|
outfile.write((char*)&ele_num_, sizeof(int));
|
||||||
|
|
||||||
for (int i = 0; i < node_num; i++)
|
for (int i = 0; i < node_num_; i++)
|
||||||
{
|
{
|
||||||
outfile.write((char*)nodes.get(i), sizeof(gctl::vertex2dc));
|
outfile.write((char*)nodes.get(i), sizeof(gctl::vertex2dc));
|
||||||
}
|
}
|
||||||
|
|
||||||
int in_index;
|
int in_index;
|
||||||
for (int i = 0; i < ele_num; i++)
|
for (int i = 0; i < ele_num_; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < 3; j++)
|
for (int j = 0; j < 3; j++)
|
||||||
{
|
{
|
||||||
@ -156,21 +154,13 @@ gctl::triangle_mesh::~triangle_mesh(){}
|
|||||||
|
|
||||||
const gctl::array<gctl::vertex2dc> &gctl::triangle_mesh::get_nodes() const
|
const gctl::array<gctl::vertex2dc> &gctl::triangle_mesh::get_nodes() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::triangle_mesh] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
const gctl::array<gctl::triangle2d> &gctl::triangle_mesh::get_elements() const
|
const gctl::array<gctl::triangle2d> &gctl::triangle_mesh::get_elements() const
|
||||||
{
|
{
|
||||||
if (!initialized)
|
check_initiated(); // 检查是否已经初始化
|
||||||
{
|
|
||||||
throw std::runtime_error("[gctl::triangle_mesh] The mesh is not initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return elements;
|
return elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,11 +170,10 @@ void gctl::triangle_mesh::load_triangle(std::string filename, index_packed_e pac
|
|||||||
gctl::read_Triangle_element(filename, elements, nodes, packed);
|
gctl::read_Triangle_element(filename, elements, nodes, packed);
|
||||||
|
|
||||||
// 设置名称与信息等
|
// 设置名称与信息等
|
||||||
node_num = nodes.size();
|
node_num_ = nodes.size();
|
||||||
ele_num = elements.size();
|
ele_num_ = elements.size();
|
||||||
base_mesh::init(TRI_TET_MESH, MESH_2D, filename, "Imported from a .node and .ele file.");
|
base_mesh::init(TRI_TET_MESH, MESH_2D, filename, "Imported from a .node and .ele file.");
|
||||||
initialized = true;
|
initialized_ = true;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,11 +186,10 @@ void gctl::triangle_mesh::load_gmsh(std::string filename, index_packed_e packed)
|
|||||||
infile.close();
|
infile.close();
|
||||||
|
|
||||||
// 设置名称与信息等
|
// 设置名称与信息等
|
||||||
node_num = nodes.size();
|
node_num_ = nodes.size();
|
||||||
ele_num = elements.size();
|
ele_num_ = elements.size();
|
||||||
base_mesh::init(TRI_TET_MESH, MESH_2D, filename, "Imported from a .msh file.");
|
base_mesh::init(TRI_TET_MESH, MESH_2D, filename, "Imported from a .msh file.");
|
||||||
initialized = true;
|
initialized_ = true;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,14 +202,14 @@ void gctl::triangle_mesh::save_gmsh(std::string filename, index_packed_e packed)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::triangle_mesh::save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed)
|
void gctl::triangle_mesh::save_gmsh(std::string filename, output_type_e out_mode, index_packed_e packed)
|
||||||
{
|
{
|
||||||
base_mesh::save_gmsh(filename, d_type, out_mode, packed);
|
base_mesh::save_gmsh_withdata(filename, out_mode, packed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gctl::triangle_mesh::save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed)
|
void gctl::triangle_mesh::save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed)
|
||||||
{
|
{
|
||||||
base_mesh::save_gmsh(filename, datname, out_mode, packed);
|
base_mesh::save_gmsh_withdata(filename, datname, out_mode, packed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,8 @@ namespace gctl
|
|||||||
void init(std::string in_name, std::string in_info, const array<vertex2dc> &in_nodes,
|
void init(std::string in_name, std::string in_info, const array<vertex2dc> &in_nodes,
|
||||||
const array<triangle2d> &in_triangles);
|
const array<triangle2d> &in_triangles);
|
||||||
|
|
||||||
|
void show_mesh_dimension(std::ostream &os) const;
|
||||||
|
|
||||||
void load_binary(std::string filename);
|
void load_binary(std::string filename);
|
||||||
void save_binary(std::string filename);
|
void save_binary(std::string filename);
|
||||||
|
|
||||||
@ -61,7 +63,7 @@ namespace gctl
|
|||||||
void load_triangle(std::string filename, index_packed_e packed = Packed);
|
void load_triangle(std::string filename, index_packed_e packed = Packed);
|
||||||
void load_gmsh(std::string filename, index_packed_e packed = Packed);
|
void load_gmsh(std::string filename, index_packed_e packed = Packed);
|
||||||
void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
||||||
void save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -377,8 +377,7 @@ void save_gmsh(const std::vector<std::string> &cmd_units)
|
|||||||
// save gmsh <file>
|
// save gmsh <file>
|
||||||
if (cmd_units.size() < 3) throw std::runtime_error("save: insufficient parameters.");
|
if (cmd_units.size() < 3) throw std::runtime_error("save: insufficient parameters.");
|
||||||
|
|
||||||
rg.save_gmsh(cmd_units[2], NodeData, OverWrite, NotPacked);
|
rg.save_gmsh(cmd_units[2], OverWrite, NotPacked);
|
||||||
rg.save_gmsh(cmd_units[2], ElemData, Append, NotPacked);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -477,7 +476,7 @@ void data_cloud(const std::vector<std::string> &cmd_units)
|
|||||||
array<point2dc> posi_arr(posix_vec.size());
|
array<point2dc> posi_arr(posix_vec.size());
|
||||||
array<double> posi_val;
|
array<double> posi_val;
|
||||||
|
|
||||||
posi_val.import_vector(data_vec);
|
posi_val.input(data_vec);
|
||||||
for (size_t i = 0; i < posi_arr.size(); i++)
|
for (size_t i = 0; i < posi_arr.size(); i++)
|
||||||
{
|
{
|
||||||
posi_arr[i].x = posix_vec[i];
|
posi_arr[i].x = posix_vec[i];
|
||||||
@ -622,21 +621,21 @@ void data_output(const std::vector<std::string> &cmd_units)
|
|||||||
copy_str[i - 1] = cmd_units[i];
|
copy_str[i - 1] = cmd_units[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
meshdata* data_ptr;
|
meshdata curr_data;
|
||||||
if (copy_str[0] == "enable")
|
if (copy_str[0] == "enable")
|
||||||
{
|
{
|
||||||
for (size_t i = 1; i < copy_str.size(); i++)
|
for (size_t i = 1; i < copy_str.size(); i++)
|
||||||
{
|
{
|
||||||
data_ptr = rg.get_data(copy_str[i]);
|
curr_data = rg.get_data(copy_str[i]);
|
||||||
data_ptr->set_output(true);
|
curr_data.output_ok_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (copy_str[0] == "disable")
|
else if (copy_str[0] == "disable")
|
||||||
{
|
{
|
||||||
for (size_t i = 1; i < copy_str.size(); i++)
|
for (size_t i = 1; i < copy_str.size(); i++)
|
||||||
{
|
{
|
||||||
data_ptr = rg.get_data(copy_str[i]);
|
curr_data = rg.get_data(copy_str[i]);
|
||||||
data_ptr->set_output(false);
|
curr_data.output_ok_ = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else throw std::runtime_error("data-output: invalid operation type.");
|
else throw std::runtime_error("data-output: invalid operation type.");
|
||||||
@ -654,7 +653,8 @@ void data_rename(const std::vector<std::string> &cmd_units)
|
|||||||
copy_str[i - 1] = cmd_units[i];
|
copy_str[i - 1] = cmd_units[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
rg.rename_data(copy_str[0], copy_str[1]);
|
meshdata curr_data = rg.get_data(copy_str[0]);
|
||||||
|
curr_data.name_ = copy_str[1];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -693,13 +693,13 @@ void get_stats(const std::vector<std::string> &cmd_units)
|
|||||||
copy_str[i - 1] = cmd_units[i];
|
copy_str[i - 1] = cmd_units[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
meshdata *data_ptr;
|
meshdata curr_data;
|
||||||
std::vector<double> stats;
|
std::vector<double> stats;
|
||||||
for (size_t i = 0; i < copy_str.size(); i++)
|
for (size_t i = 0; i < copy_str.size(); i++)
|
||||||
{
|
{
|
||||||
data_ptr = rg.get_data(copy_str[i]);
|
curr_data = rg.get_data(copy_str[i]);
|
||||||
data_ptr->show_info();
|
curr_data.show_info();
|
||||||
data_ptr->show_stats();
|
curr_data.show_stats();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user