redesigned meshdata and mesh

This commit is contained in:
张壹 2025-01-12 23:39:36 +08:00
parent 1145d8a3eb
commit bad10fb6f4
42 changed files with 3204 additions and 2123 deletions

864
backup/mesh.cpp Normal file
View 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
View 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
View 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
View 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

View File

@ -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)

View File

@ -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;
} }

View File

@ -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;
} }

View File

@ -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;
} }

View File

@ -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 dname2= "another-example";
gctl::regular_grid rgd;
rgd.init("grid-1", "this is a test message.", 15, 10, 0.0, 0.0, 1.0, 1.0);
gctl::meshdata &data = rgd.add_data(gctl::NodeData, gctl::Scalar, dname, 0.0);
for (int j = 0; j < rgd.get_ydim(); j++)
{ {
std::string dname = "example"; for (int i = 0; i < rgd.get_xdim(); i++)
std::string dname2= "another-example";
gctl::regular_grid rgd;
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);
for (int j = 0; j < rgd.get_ydim(); j++)
{ {
for (int i = 0; i < rgd.get_xdim(); i++) data.datval_[i + j*rgd.get_xdim()] = i;
{
data_ptr->at(i + j*rgd.get_xdim()) = i;
}
} }
rgd.add_data(dname2, gctl::ElemData, true, gctl::Scalar);
data_ptr = (gctl::array<double>*) rgd.get_datval(dname2);
for (int j = 0; j < rgd.get_ydim()-1; j++)
{
for (int i = 0; i < rgd.get_xdim()-1; i++)
{
data_ptr->at(i + j*(rgd.get_xdim()-1)) = j;
}
}
rgd.save_binary("data/out/sample3-out");
rgd.save_netcdf_grid("data/out/sample3-out1", dname);
rgd.save_netcdf_grid("data/out/sample3-out2", dname2);
gctl::regular_grid rgd2;
rgd2.load_binary("data/out/sample3-out");
rgd2.show_info();
data_ptr = (gctl::array<double>*) rgd2.get_datval(dname);
for (int i = 0; i < data_ptr->size(); i++)
{
std::cout << data_ptr->at(i) << " ";
}
std::cout << std::endl;
data_ptr = (gctl::array<double>*) rgd2.get_datval(dname2);
for (int i = 0; i < data_ptr->size(); i++)
{
std::cout << data_ptr->at(i) << " ";
}
std::cout << std::endl;
} }
catch(std::exception &e)
gctl::meshdata &data2 = rgd.add_data(gctl::ElemData, gctl::Scalar, dname2, 0.0);
for (int j = 0; j < rgd.get_ydim()-1; j++)
{ {
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0); for (int i = 0; i < rgd.get_xdim()-1; i++)
{
data2.datval_[i + j*(rgd.get_xdim()-1)] = j;
}
} }
rgd.save_binary("sample3-out");
rgd.save_netcdf_grid("sample3-out1", dname);
rgd.save_netcdf_grid("sample3-out2", dname2);
gctl::regular_grid rgd2;
rgd2.load_binary("sample3-out");
rgd2.show_info();
gctl::meshdata &data3 = rgd2.get_data(dname);
for (int i = 0; i < data3.datval_.size(); i++)
{
std::cout << data3.datval_[i] << " ";
}
std::cout << std::endl;
gctl::meshdata &data4 = rgd2.get_data(dname2);
for (int i = 0; i < data4.datval_.size(); i++)
{
std::cout << data4.datval_[i] << " ";
}
std::cout << std::endl;
return 0; return 0;
} }
catch(std::exception &e)
{
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}

View File

@ -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";
gctl::regular_grid rgd;
rgd.init("grid-example", "this grid can store vectors. Yeah!", 15, 10, 0.0, 0.0, 1.0, 1.0);
gctl::array<gctl::point3dc> init_data(rgd.get_ydim()*rgd.get_xdim());
for (int j = 0; j < rgd.get_ydim(); j++)
{ {
std::string dname = "vector-data"; for (int i = 0; i < rgd.get_xdim(); i++)
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.add_data(dname, gctl::NodeData, true, gctl::Vector);
gctl::array<gctl::point3dc> *data_ptr = (gctl::array<gctl::point3dc>*) rgd.get_datval(dname);
for (int j = 0; j < rgd.get_ydim(); j++)
{ {
for (int i = 0; i < rgd.get_xdim(); i++) init_data[i + j*rgd.get_xdim()].x = i;
{ init_data[i + j*rgd.get_xdim()].y = j;
data_ptr->at(i + j*rgd.get_xdim()).x = i; init_data[i + j*rgd.get_xdim()].z = i+j;
data_ptr->at(i + j*rgd.get_xdim()).y = j;
data_ptr->at(i + j*rgd.get_xdim()).z = i+j;
}
} }
rgd.save_binary("data/out/sample4-out");
gctl::regular_grid rgd2;
rgd2.load_binary("data/out/sample4-out");
rgd2.show_info();
}
catch(std::exception &e)
{
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
} }
gctl::meshdata data = rgd.add_data(gctl::NodeData, dname, init_data);
rgd.save_binary("sample4-out");
gctl::regular_grid rgd2;
rgd2.load_binary("sample4-out");
rgd2.show_info();
return 0; return 0;
} }
catch(std::exception &e)
{
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}

View File

@ -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;
{ rgd.load_netcdf_grid("data/out/sample3-out1", gctl::ElemData, "x", "y");
gctl::regular_grid rgd;
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);
}

View File

@ -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;
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 xbnum = rg_mesh.get_xbnum();
gctl::array<gctl::point3dc> init_data(ybnum*xbnum);
for (int j = 0; j < ybnum; j++)
{ {
gctl::regular_mesh_2d rg_mesh; for (int i = 0; i < xbnum; i++)
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 xbnum = rg_mesh.get_xbnum();
rg_mesh.add_data("vector-data", gctl::ElemData, true, gctl::Vector);
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 i = 0; i < xbnum; i++) init_data[i + j*xbnum].x = i;
{ init_data[i + j*xbnum].y = j;
data_ptr->at(i + j*xbnum).x = i; init_data[i + j*xbnum].z = i+j;
data_ptr->at(i + j*xbnum).y = j;
data_ptr->at(i + j*xbnum).z = i+j;
}
} }
rg_mesh.add_data("double-data", gctl::NodeData, true, gctl::Scalar);
gctl::array<double> *data_ptr2 = (gctl::array<double>*) rg_mesh.get_datval("double-data");
for (int j = 0; j < ybnum+1; j++)
{
for (int i = 0; i < xbnum+1; i++)
{
data_ptr2->at(i + j*(xbnum+1)) = i+j;
}
}
//rg_mesh.save_gmsh("data/sample6-out", "vector-data");
//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)
rg_mesh.add_data(gctl::ElemData, "vector-data", init_data);
gctl::meshdata &data2= rg_mesh.add_data(gctl::NodeData, gctl::Scalar, "double-data", 0.0);
for (int j = 0; j < ybnum+1; j++)
{ {
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0); for (int i = 0; i < xbnum+1; i++)
{
data2.datval_[i + j*(xbnum+1)] = i+j;
}
} }
rg_mesh.save_gmsh("sample6-out", gctl::OverWrite);
return 0; return 0;
} }
catch(std::exception &e)
{
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}

View File

@ -27,35 +27,31 @@
#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;
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);
int ybnum = rg_mesh.get_ybnum();
int xbnum = rg_mesh.get_xbnum();
int zbnum = rg_mesh.get_zbnum();
gctl::meshdata &data = rg_mesh.add_data(gctl::NodeData, gctl::Scalar, "double-data", 0.0);
for (int k = 0; k < zbnum+1; k++)
{ {
gctl::regular_mesh_3d rg_mesh; for (int j = 0; j < ybnum+1; j++)
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);
int ybnum = rg_mesh.get_ybnum();
int xbnum = rg_mesh.get_xbnum();
int zbnum = rg_mesh.get_zbnum();
rg_mesh.add_data("double-data", gctl::NodeData, gctl::Packed, gctl::Scalar);
gctl::array<double> *data_ptr = (gctl::array<double>*) rg_mesh.get_datval("double-data");
for (int k = 0; k < zbnum+1; k++)
{ {
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.datval_[i + j*(xbnum+1) + k*(xbnum+1)*(ybnum+1)] = i+j+k;
{
data_ptr->at(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);
}

View File

@ -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;
{ t_mesh.load_triangle("sample8", gctl::Packed);
gctl::triangle_mesh t_mesh; t_mesh.add_data(gctl::ElemData, gctl::Scalar, "example", 1.0);
t_mesh.load_triangle("data/out/sample8", gctl::Packed);
t_mesh.add_data("example", gctl::ElemData, gctl::Packed, 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);
}

View File

@ -27,43 +27,39 @@
#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);
for (int i = 0; i < 15; i++)
{ {
gctl::array<double> xs(15); xs[i] = i+1;
for (int i = 0; i < 15; i++)
{
xs[i] = i+1;
}
gctl::array<double> ys(10);
for (int i = 0; i < 10; i++)
{
ys[i] = i+1;
}
gctl::linear_mesh_2d l2d_mesh;
l2d_mesh.init("mesh-example", "This is a linear mesh", 0.5, 0.5, xs, ys);
int ybnum = l2d_mesh.get_ybnum();
int xbnum = l2d_mesh.get_xbnum();
l2d_mesh.add_data("double-data", gctl::ElemData, gctl::Packed, gctl::Scalar);
gctl::array<double> *data_ptr2 = (gctl::array<double>*) l2d_mesh.get_datval("double-data");
for (int j = 0; j < ybnum; j++)
{
for (int i = 0; i < xbnum; i++)
{
data_ptr2->at(i + j*xbnum) = i+j;
}
}
l2d_mesh.save_gmsh("data/out/sample9-out", gctl::ElemData, gctl::OverWrite, gctl::NotPacked);
} }
catch(std::exception &e)
gctl::array<double> ys(10);
for (int i = 0; i < 10; i++)
{ {
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0); ys[i] = i+1;
} }
gctl::linear_mesh_2d l2d_mesh;
l2d_mesh.init("mesh-example", "This is a linear mesh", 0.5, 0.5, xs, ys);
int ybnum = l2d_mesh.get_ybnum();
int xbnum = l2d_mesh.get_xbnum();
gctl::meshdata &data = l2d_mesh.add_data(gctl::ElemData, gctl::Scalar, "double-data", 0.0);
for (int j = 0; j < ybnum; j++)
{
for (int i = 0; i < xbnum; i++)
{
data.datval_[i + j*xbnum] = i+j;
}
}
l2d_mesh.save_gmsh("sample9-out", gctl::OverWrite, gctl::NotPacked);
return 0; return 0;
} }
catch(std::exception &e)
{
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}

View File

@ -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;
} }

View File

@ -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:

View File

@ -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;
} }

View File

@ -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

View File

@ -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
* *

View File

@ -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;
throw std::runtime_error("[gctl::meshdata] The input name is empty."); valtype_ = Scalar;
} output_ok_ = true;
nan_val_ = GCTL_BDL_MAX;
datname = in_name;
dattype = in_type;
output_ok = if_output;
} }
gctl::meshdata::~meshdata(){} gctl::meshdata::meshdata(mesh_data_type_e in_loctype,
mesh_data_value_e in_valtype, size_t size,
void gctl::meshdata::set_datname(std::string in_name) std::string name, bool if_output, double nan_val)
{ {
if (in_name == "") create(in_loctype, in_valtype, size, name, if_output, nan_val);
{ }
throw std::runtime_error("[gctl::meshdata] The input name is empty.");
}
datname = in_name; 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)
{
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; return;
} }
std::string gctl::meshdata::get_datname() void gctl::meshdata::show_stats(std::ostream &os) const
{ {
return datname; 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++;
}
gctl::mesh_data_type_e gctl::meshdata::get_dattype() array<double> tmp_x(vn), tmp_y(vn), tmp_z(vn);
{
return dattype;
}
gctl::mesh_data_value_e gctl::meshdata::get_valtype() vn = 0;
{ for (size_t i = 0; i < datval_.size(); i += 3)
return valtype; {
} 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++;
}
}
void gctl::meshdata::set_output(bool if_output) os << "mean = (" << tmp_x.mean() << ", " << tmp_y.mean() << ", " << tmp_z.mean() << ")\n"
{ << "std = (" << tmp_x.std() << ", " << tmp_y.std() << ", " << tmp_z.std() << ")\n"
output_ok = if_output; << "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;
} }
bool gctl::meshdata::get_output() void gctl::meshdata::load_binary(std::ifstream &infile)
{ {
return output_ok; int name_size;
infile.read((char*) &name_size, sizeof(int));
name_.resize(name_size);
infile.read((char*) name_.c_str(), name_size);
infile.read((char*) &loctype_, sizeof(int));
infile.read((char*) &valtype_, sizeof(int));
infile.read((char*) &output_ok_, sizeof(bool));
int n;
infile.read((char*) &n, sizeof(int));
datval_.resize(n);
infile.read((char*) datval_.get(), sizeof(double)*datval_.size());
infile.read((char*) &nan_val_, sizeof(double));
return;
} }
void gctl::meshdata::show_info(std::ostream &os) void gctl::meshdata::save_binary(std::ofstream &outfile)
{ {
os << "Data: " << datname << " | "; int name_size = name_.size();
if (dattype == NodeData) os << "Type: Node data | "; outfile.write((char*) &name_size, sizeof(int));
if (dattype == ElemData) os << "Type: Element data | "; outfile.write((char*) name_.c_str(), name_size);
if (dattype == ElemData2D) os << "Type: 2D element data | "; outfile.write((char*) &loctype_, sizeof(int));
if (dattype == ElemData3D) os << "Type: 3D element data | "; outfile.write((char*) &valtype_, sizeof(int));
if (valtype == Scalar) os << "Value: Scalar | "; outfile.write((char*) &output_ok_, sizeof(bool));
if (valtype == Vector) os << "Value: Vector | ";
if (valtype == Tensor) os << "Value: Tensor | "; int n = datval_.size();
if (output_ok) os << "Output: Yes" << std::endl; outfile.write((char*) &n, sizeof(int));
else os<< "Output: No" << std::endl; outfile.write((char*) datval_.get(), sizeof(double)*datval_.size());
return; outfile.write((char*) &nan_val_, sizeof(double));
return;
} }

View File

@ -1,4 +1,4 @@
/******************************************************** /********************************************************
* *
* *
* *
@ -30,11 +30,12 @@
#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
{ {
/** /**
* @brief * @brief
*/ */
enum mesh_data_value_e enum mesh_data_value_e
@ -44,93 +45,90 @@ namespace gctl
Tensor, ///< 张量数据 Tensor, ///< 张量数据
}; };
/** /**
* @brief * @brief
*/ *
class meshdata */
{ struct meshdata
protected: {
std::string datname; // 数据的名称 std::string name_; // 数据的名称
mesh_data_type_e dattype; // 数据的赋值属性 顶点或是元素(设置后不可更改) mesh_data_type_e loctype_; // 数据的赋值位置属性 顶点或是元素
mesh_data_value_e valtype; // 数据的类型(设置后不可更改) mesh_data_value_e valtype_; // 数据的类型
bool output_ok; // 是否可输出数据 bool output_ok_; // 是否可输出数据
array<double> datval_; // 数据值 注意目前我们只支持浮点数据存储
public: double nan_val_; // 无效数据的标记值
// 构造函数
meshdata(std::string in_name, mesh_data_type_e in_type, bool if_output);
// 析构函数
virtual ~meshdata();
/** /**
* @brief * @brief
*
* @param[in] in_name
*/ */
void set_datname(std::string in_name); meshdata();
/** /**
* @brief * @brief
* *
* @return * @param in_loctype
* @param in_valtype
* @param size
* @param name
* @param if_output
* @param nan_val
*/ */
std::string get_datname(); 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 * @brief
*/
virtual ~meshdata();
/**
* @brief
*/
void clear();
/**
* @brief
* *
* @return * @param in_loctype
* @param in_valtype
* @param size
* @param name
* @param if_output
* @param nan_val
*/ */
mesh_data_type_e get_dattype(); 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_value_e get_valtype(); array<point3dc> export_vector() const;
/** /**
* @brief * @brief
*
* @param[in] if_output
*/ */
void set_output(bool if_output); array<tensor> export_tensor() const;
/** /**
* @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
* *
* @warning * @warning
* *
* @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

View File

@ -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);

View File

@ -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;
} }

View File

@ -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:

View File

@ -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;
} }

View File

@ -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);

View File

@ -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;
} }

View File

@ -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:

View File

@ -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;
} }

View File

@ -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:

View File

@ -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;
} }

View File

@ -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:

View File

@ -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;
} }