diff --git a/backup/mesh.cpp b/backup/mesh.cpp
new file mode 100644
index 0000000..4b98173
--- /dev/null
+++ b/backup/mesh.cpp
@@ -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 .
+ *
+ * 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::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::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& 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::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::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* val_ptr = (array*) 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* val_ptr = (array*) 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* val_ptr = (array*) 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 &xsizes, const gctl::array &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 &xsizes, const gctl::array &ysizes,
+ const gctl::array &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 &in_nodes,
+ const gctl::array &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 &in_nodes,
+ const gctl::array &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 *data_ptr = (gctl::array*) 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 *data_ptr = (gctl::array*) 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 *data_ptr = (gctl::array*) 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 *data_ptr = (gctl::array*) 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 *data_ptr = (gctl::array*) 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 *data_ptr = (gctl::array*) 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 *data_ptr = (gctl::array*) curr_data->get_datval_ptr();
+ if (curr_data->get_dattype() == NodeData)
+ {
+ array 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 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 &in_posi, const array &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 &in_posi, const array &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 &in_posi, array &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 &in_posi, array &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 &out_posi, array &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 &out_posi, array &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;
+}
\ No newline at end of file
diff --git a/backup/mesh.h b/backup/mesh.h
new file mode 100644
index 0000000..2c10e8f
--- /dev/null
+++ b/backup/mesh.h
@@ -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 .
+ *
+ * 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 &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 &xsizes, const gctl::array &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 &xsizes, const gctl::array &ysizes,
+ const gctl::array &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 &in_nodes,
+ const gctl::array &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 &in_nodes,
+ const gctl::array &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 &in_posi, const array &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 &in_posi, const array &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 &in_posi, array &out_val);
+
+ /**
+ * @brief
+ *
+ * @param datname
+ * @param in_posi
+ * @param out_val
+ */
+ virtual void extract_points(std::string datname, const array &in_posi, array &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 &out_posi, array &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 &out_posi, array &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 saved_data;
+ std::list::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
\ No newline at end of file
diff --git a/backup/meshdata.cpp b/backup/meshdata.cpp
new file mode 100644
index 0000000..725f02a
--- /dev/null
+++ b/backup/meshdata.cpp
@@ -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 .
+ *
+ * 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;
+}
\ No newline at end of file
diff --git a/backup/meshdata.h b/backup/meshdata.h
new file mode 100644
index 0000000..217aea1
--- /dev/null
+++ b/backup/meshdata.h
@@ -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 .
+ *
+ * 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
\ No newline at end of file
diff --git a/lib/mesh/meshdata_scalar.cpp b/backup/meshdata_scalar.cpp
similarity index 100%
rename from lib/mesh/meshdata_scalar.cpp
rename to backup/meshdata_scalar.cpp
diff --git a/lib/mesh/meshdata_scalar.h b/backup/meshdata_scalar.h
similarity index 100%
rename from lib/mesh/meshdata_scalar.h
rename to backup/meshdata_scalar.h
diff --git a/lib/mesh/meshdata_tensor.cpp b/backup/meshdata_tensor.cpp
similarity index 100%
rename from lib/mesh/meshdata_tensor.cpp
rename to backup/meshdata_tensor.cpp
diff --git a/lib/mesh/meshdata_tensor.h b/backup/meshdata_tensor.h
similarity index 100%
rename from lib/mesh/meshdata_tensor.h
rename to backup/meshdata_tensor.h
diff --git a/lib/mesh/meshdata_vector.cpp b/backup/meshdata_vector.cpp
similarity index 100%
rename from lib/mesh/meshdata_vector.cpp
rename to backup/meshdata_vector.cpp
diff --git a/lib/mesh/meshdata_vector.h b/backup/meshdata_vector.h
similarity index 100%
rename from lib/mesh/meshdata_vector.h
rename to backup/meshdata_vector.h
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
index dc56351..63c8227 100644
--- a/example/CMakeLists.txt
+++ b/example/CMakeLists.txt
@@ -21,7 +21,7 @@ add_example(mesh_ex1 ON)
add_example(mesh_ex2 ON)
add_example(mesh_ex3 ON)
add_example(mesh_ex4 ON)
-add_example(mesh_ex5 ON)
+add_example(mesh_ex5 OFF)
add_example(mesh_ex6 ON)
add_example(mesh_ex7 ON)
add_example(mesh_ex8 ON)
diff --git a/example/mesh_ex1.cpp b/example/mesh_ex1.cpp
index 5129bff..3963ab5 100644
--- a/example/mesh_ex1.cpp
+++ b/example/mesh_ex1.cpp
@@ -32,26 +32,20 @@ int main(int argc, char *argv[])
gctl::regular_grid rgd;
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);
- gctl::meshdata *data2= rgd.add_data("data-2", gctl::ElemData, false, 1.2);
- gctl::meshdata *data3= rgd.add_data("data-3", gctl::NodeData, true, gctl::Scalar);
+ rgd.add_data(gctl::NodeData, gctl::Scalar, "data-1", 2.5);
+ rgd.add_data(gctl::ElemData, gctl::Scalar, "data-2", 1.2, false);
+ rgd.add_data(gctl::NodeData, gctl::Scalar, "data-3", 1.0);
+ rgd.show_info();
- std::cout << "data name: " << data2->get_datname() << std::endl;
- //gctl::array *data_ptr = (gctl::array*) rgd.get_datval(data2->get_name());
- gctl::array *data_ptr = (gctl::array*) data2->get_datval_ptr();
- for (int i = 0; i < data_ptr->size(); i++)
- {
- std::cout << data_ptr->at(i) << std::endl;
- }
+ gctl::meshdata data2 = rgd.get_data("data-2");
+ std::cout << "data name: " << data2.name_ << std::endl;
+ data2.datval_.show();
- std::cout << "data name: " << data3->get_datname() << std::endl;
- gctl::array *data_ptr2 = (gctl::array*) rgd.get_datval(data3->get_datname());
- for (int i = 0; i < data_ptr2->size(); i++)
- {
- std::cout << data_ptr2->at(i) << std::endl;
- }
+ gctl::meshdata data3 = rgd.get_data("data-3");
+ std::cout << "data name: " << data3.name_ << std::endl;
+ data3.datval_.show();
rgd.remove_data("data-1");
-
+ rgd.show_info();
return 0;
}
\ No newline at end of file
diff --git a/example/mesh_ex10.cpp b/example/mesh_ex10.cpp
index c02df14..cbf2dd2 100644
--- a/example/mesh_ex10.cpp
+++ b/example/mesh_ex10.cpp
@@ -31,7 +31,7 @@ int main(int argc, char *argv[])
{
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.add_data("data-1", gctl::ElemData, true, 2.5);
- rm_3ds.save_gmsh("data/out/mesh_sample10", gctl::ElemData, gctl::OverWrite, gctl::NotPacked);
+ rm_3ds.add_data(gctl::ElemData, gctl::Scalar, "data-1", 2.5);
+ rm_3ds.save_gmsh("mesh_sample10",gctl::OverWrite, gctl::NotPacked);
return 0;
}
\ No newline at end of file
diff --git a/example/mesh_ex2.cpp b/example/mesh_ex2.cpp
index e613611..3e05cb4 100644
--- a/example/mesh_ex2.cpp
+++ b/example/mesh_ex2.cpp
@@ -34,32 +34,29 @@ int main(int argc, char *argv[])
gctl::regular_grid rgd;
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 *data_ptr = (gctl::array*) 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 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);
- data_ptr = (gctl::array*) rgd.get_datval(dname2);
+ gctl::meshdata &data2 = rgd.add_data(gctl::NodeData, gctl::Scalar, dname2, 0.0);
for (int j = 0; j < rgd.get_ydim(); j++)
{
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
- gctl::meshdata *data2 = rgd.get_data(dname2);
- data2->set_output(false);
-
- rgd.save_netcdf_grid("data/out/sample2-out", gctl::NodeData);
+ //data2.output_ok_ = false;
+ rgd.show_info();
+ rgd.save_netcdf_grid("sample2-out", gctl::NodeData);
return 0;
}
\ No newline at end of file
diff --git a/example/mesh_ex3.cpp b/example/mesh_ex3.cpp
index 83c64ca..bac21f8 100644
--- a/example/mesh_ex3.cpp
+++ b/example/mesh_ex3.cpp
@@ -27,62 +27,56 @@
#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";
- 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 *data_ptr = (gctl::array*) rgd.get_datval(dname);
- for (int j = 0; j < rgd.get_ydim(); j++)
+ for (int i = 0; i < rgd.get_xdim(); i++)
{
- for (int i = 0; i < rgd.get_xdim(); i++)
- {
- data_ptr->at(i + j*rgd.get_xdim()) = i;
- }
+ data.datval_[i + j*rgd.get_xdim()] = i;
}
-
- rgd.add_data(dname2, gctl::ElemData, true, gctl::Scalar);
- data_ptr = (gctl::array*) 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*) 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*) 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;
+}
+catch(std::exception &e)
+{
+ GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}
\ No newline at end of file
diff --git a/example/mesh_ex4.cpp b/example/mesh_ex4.cpp
index c438760..834cc98 100644
--- a/example/mesh_ex4.cpp
+++ b/example/mesh_ex4.cpp
@@ -27,37 +27,34 @@
#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 init_data(rgd.get_ydim()*rgd.get_xdim());
+ for (int j = 0; j < rgd.get_ydim(); j++)
{
- 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);
- rgd.add_data(dname, gctl::NodeData, true, gctl::Vector);
-
- gctl::array *data_ptr = (gctl::array*) rgd.get_datval(dname);
- for (int j = 0; j < rgd.get_ydim(); j++)
+ for (int i = 0; i < rgd.get_xdim(); i++)
{
- for (int i = 0; i < rgd.get_xdim(); i++)
- {
- data_ptr->at(i + j*rgd.get_xdim()).x = i;
- data_ptr->at(i + j*rgd.get_xdim()).y = j;
- data_ptr->at(i + j*rgd.get_xdim()).z = i+j;
- }
+ init_data[i + j*rgd.get_xdim()].x = i;
+ init_data[i + j*rgd.get_xdim()].y = j;
+ init_data[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;
+}
+catch(std::exception &e)
+{
+ GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}
\ No newline at end of file
diff --git a/example/mesh_ex5.cpp b/example/mesh_ex5.cpp
index d4584e8..4f4d8b5 100644
--- a/example/mesh_ex5.cpp
+++ b/example/mesh_ex5.cpp
@@ -27,20 +27,17 @@
#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");
- }
- catch(std::exception &e)
- {
- GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
- }
+ rgd.save_netcdf_grid("data/out/sample5-out", "example");
return 0;
+}
+catch(std::exception &e)
+{
+ GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}
\ No newline at end of file
diff --git a/example/mesh_ex6.cpp b/example/mesh_ex6.cpp
index a3bf568..53f01b2 100644
--- a/example/mesh_ex6.cpp
+++ b/example/mesh_ex6.cpp
@@ -27,46 +27,40 @@
#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 init_data(ybnum*xbnum);
+ for (int j = 0; j < ybnum; j++)
{
- 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();
-
- rg_mesh.add_data("vector-data", gctl::ElemData, true, gctl::Vector);
- gctl::array *data_ptr = (gctl::array*) rg_mesh.get_datval("vector-data");
- for (int j = 0; j < ybnum; j++)
+ for (int i = 0; i < xbnum; i++)
{
- for (int i = 0; i < xbnum; i++)
- {
- data_ptr->at(i + j*xbnum).x = i;
- data_ptr->at(i + j*xbnum).y = j;
- data_ptr->at(i + j*xbnum).z = i+j;
- }
+ init_data[i + j*xbnum].x = i;
+ init_data[i + j*xbnum].y = j;
+ init_data[i + j*xbnum].z = i+j;
}
-
- rg_mesh.add_data("double-data", gctl::NodeData, true, gctl::Scalar);
- gctl::array *data_ptr2 = (gctl::array*) 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;
+}
+catch(std::exception &e)
+{
+ GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}
\ No newline at end of file
diff --git a/example/mesh_ex7.cpp b/example/mesh_ex7.cpp
index 095de7b..3750a5e 100644
--- a/example/mesh_ex7.cpp
+++ b/example/mesh_ex7.cpp
@@ -27,35 +27,31 @@
#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;
- 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 *data_ptr = (gctl::array*) rg_mesh.get_datval("double-data");
- for (int k = 0; k < zbnum+1; k++)
+ for (int j = 0; j < ybnum+1; j++)
{
- for (int j = 0; j < ybnum+1; j++)
+ for (int i = 0; i < xbnum+1; i++)
{
- for (int i = 0; i < xbnum+1; i++)
- {
- data_ptr->at(i + j*(xbnum+1) + k*(xbnum+1)*(ybnum+1)) = i+j+k;
- }
+ data.datval_[i + j*(xbnum+1) + k*(xbnum+1)*(ybnum+1)] = i+j+k;
}
}
+ }
- rg_mesh.save_gmsh("data/out/sample7-out", "double-data", gctl::OverWrite);
- }
- catch(std::exception &e)
- {
- GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
- }
+ rg_mesh.save_gmsh("sample7-out", "double-data", gctl::OverWrite);
return 0;
+}
+catch(std::exception &e)
+{
+ GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}
\ No newline at end of file
diff --git a/example/mesh_ex8.cpp b/example/mesh_ex8.cpp
index 6bcf468..46bcfac 100644
--- a/example/mesh_ex8.cpp
+++ b/example/mesh_ex8.cpp
@@ -27,24 +27,21 @@
#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("data/out/sample8", gctl::Packed);
- t_mesh.add_data("example", gctl::ElemData, gctl::Packed, 1.0);
+ gctl::triangle_mesh t_mesh;
+ t_mesh.load_triangle("sample8", gctl::Packed);
+ t_mesh.add_data(gctl::ElemData, gctl::Scalar, "example", 1.0);
- t_mesh.save_gmsh("data/out/sample8-out", "example", gctl::OverWrite, gctl::NotPacked);
- t_mesh.save_binary("data/out/sample8-out");
+ t_mesh.save_gmsh("sample8-out", "example", gctl::OverWrite, gctl::NotPacked);
+ t_mesh.save_binary("sample8-out");
- gctl::triangle_mesh t2_mesh;
- t2_mesh.load_binary("data/out/sample8-out");
- t2_mesh.show_info();
- }
- catch(std::exception &e)
- {
- GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
- }
+ gctl::triangle_mesh t2_mesh;
+ t2_mesh.load_binary("sample8-out");
+ t2_mesh.show_info();
return 0;
+}
+catch(std::exception &e)
+{
+ GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}
\ No newline at end of file
diff --git a/example/mesh_ex9.cpp b/example/mesh_ex9.cpp
index 5305301..611ecf0 100644
--- a/example/mesh_ex9.cpp
+++ b/example/mesh_ex9.cpp
@@ -27,43 +27,39 @@
#include "../lib/mesh.h"
-int main(int argc, char *argv[])
+int main(int argc, char *argv[]) try
{
- try
+ gctl::array xs(15);
+ for (int i = 0; i < 15; i++)
{
- gctl::array xs(15);
- for (int i = 0; i < 15; i++)
- {
- xs[i] = i+1;
- }
-
- gctl::array 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 *data_ptr2 = (gctl::array*) 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);
+ xs[i] = i+1;
}
- catch(std::exception &e)
+
+ gctl::array 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;
+}
+catch(std::exception &e)
+{
+ GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}
\ No newline at end of file
diff --git a/lib/mesh/linear_mesh_2d.cpp b/lib/mesh/linear_mesh_2d.cpp
index 4b18555..03e1294 100644
--- a/lib/mesh/linear_mesh_2d.cpp
+++ b/lib/mesh/linear_mesh_2d.cpp
@@ -30,11 +30,7 @@
void gctl::linear_mesh_2d::init(std::string in_name, std::string in_info, double xmin, double ymin,
const gctl::array &xsizes, const gctl::array &ysizes)
{
- if (initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is already initialized.");
- }
-
+ check_initiated(true); // 检查网格是否已经初始化
base_mesh::init(LINEAR_MESH, MESH_2D, in_name, in_info);
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_ysizes.resize(lm_ybnum);
- node_num = (lm_xbnum+1) * (lm_ybnum+1);
- ele_num = lm_xbnum * lm_ybnum;
+ node_num_ = (lm_xbnum+1) * (lm_ybnum+1);
+ ele_num_ = lm_xbnum * lm_ybnum;
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];
}
- nodes.resize(node_num);
- elements.resize(ele_num);
+ nodes.resize(node_num_);
+ elements.resize(ele_num_);
double x_p, y_p = lm_ymin - 0.5*lm_ysizes[0];
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;
}
void gctl::linear_mesh_2d::load_binary(std::string filename)
{
- if (initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is already initialized.");
- }
+ check_initiated(true); // 检查网格是否已经初始化
std::ifstream infile;
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_ysizes.resize(lm_ybnum);
- node_num = (lm_xbnum+1) * (lm_ybnum+1);
- ele_num = lm_xbnum * lm_ybnum;
+ node_num_ = (lm_xbnum+1) * (lm_ybnum+1);
+ ele_num_ = lm_xbnum * lm_ybnum;
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));
}
- nodes.resize(node_num);
- elements.resize(ele_num);
+ nodes.resize(node_num_);
+ elements.resize(ele_num_);
double x_p, y_p = lm_ymin - 0.5*lm_ysizes[0];
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);
@@ -168,10 +171,7 @@ void gctl::linear_mesh_2d::load_binary(std::string filename)
void gctl::linear_mesh_2d::save_binary(std::string filename)
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
- }
+ check_initiated(); // 检查网格是否已经初始化
std::ofstream outfile;
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
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
- }
-
+ check_initiated(); // 检查网格是否已经初始化
return lm_xbnum;
}
int gctl::linear_mesh_2d::get_ybnum() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
- }
-
+ check_initiated(); // 检查网格是否已经初始化
return lm_ybnum;
}
double gctl::linear_mesh_2d::get_xmin() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
- }
-
+ check_initiated(); // 检查网格是否已经初始化
return lm_xmin;
}
double gctl::linear_mesh_2d::get_ymin() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
- }
-
+ check_initiated(); // 检查网格是否已经初始化
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 *gctl::linear_mesh_2d::get_xsizes() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
- }
-
+ check_initiated(); // 检查网格是否已经初始化
return &lm_xsizes;
}
const gctl::array *gctl::linear_mesh_2d::get_ysizes() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
- }
-
+ check_initiated(); // 检查网格是否已经初始化
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;
}
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;
}
diff --git a/lib/mesh/linear_mesh_2d.h b/lib/mesh/linear_mesh_2d.h
index 90623e6..df505ef 100644
--- a/lib/mesh/linear_mesh_2d.h
+++ b/lib/mesh/linear_mesh_2d.h
@@ -43,6 +43,8 @@ namespace gctl
void init(std::string in_name, std::string in_info, double xmin, double ymin,
const array &xsizes, const array &ysizes);
+ void show_mesh_dimension(std::ostream &os) const;
+
void load_binary(std::string filename);
void save_binary(std::string filename);
@@ -59,11 +61,13 @@ namespace gctl
int get_ybnum() const;
double get_xmin() const;
double get_ymin() const;
+ double get_xmax() const;
+ double get_ymax() const;
const array *get_xsizes() const;
const array *get_ysizes() const;
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);
protected:
diff --git a/lib/mesh/linear_mesh_3d.cpp b/lib/mesh/linear_mesh_3d.cpp
index 0cabd92..c5df6d9 100644
--- a/lib/mesh/linear_mesh_3d.cpp
+++ b/lib/mesh/linear_mesh_3d.cpp
@@ -30,11 +30,7 @@
void gctl::linear_mesh_3d::init(std::string in_name, std::string in_info, double xmin, double ymin,
double zmin, const array &xsizes, const array &ysizes, const array &zsizes)
{
- if (initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is already initialized.");
- }
-
+ check_initiated(true); // 检查网格是否已经初始化
base_mesh::init(LINEAR_MESH, MESH_3D, in_name, in_info);
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_zsizes.resize(lm_zbnum);
- node_num = (lm_xbnum+1) * (lm_ybnum+1) * (lm_zbnum+1);
- ele_num = lm_xbnum * lm_ybnum * lm_zbnum;
+ node_num_ = (lm_xbnum+1) * (lm_ybnum+1) * (lm_zbnum+1);
+ ele_num_ = lm_xbnum * lm_ybnum * lm_zbnum;
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];
}
- nodes.resize(node_num);
- elements.resize(ele_num);
+ nodes.resize(node_num_);
+ elements.resize(ele_num_);
int tmp_index;
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;
}
void gctl::linear_mesh_3d::load_binary(std::string filename)
{
- if (initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is already initialized.");
- }
+ check_initiated(true); // 检查网格是否已经初始化
std::ifstream infile;
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_ysizes.resize(lm_ybnum);
lm_zsizes.resize(lm_zbnum);
- node_num = (lm_xbnum+1) * (lm_ybnum+1) * (lm_zbnum+1);
- ele_num = lm_xbnum * lm_ybnum * lm_zbnum;
+ node_num_ = (lm_xbnum+1) * (lm_ybnum+1) * (lm_zbnum+1);
+ ele_num_ = lm_xbnum * lm_ybnum * lm_zbnum;
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));
}
- nodes.resize(node_num);
- elements.resize(ele_num);
+ nodes.resize(node_num_);
+ elements.resize(ele_num_);
int tmp_index;
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);
@@ -217,10 +221,7 @@ void gctl::linear_mesh_3d::load_binary(std::string filename)
void gctl::linear_mesh_3d::save_binary(std::string filename)
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
- }
+ check_initiated(); // 检查网格是否已经初始化
std::ofstream outfile;
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
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
- }
-
+ check_initiated(); // 检查网格是否已经初始化
return lm_xbnum;
}
int gctl::linear_mesh_3d::get_ybnum() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
- }
-
+ check_initiated(); // 检查网格是否已经初始化
return lm_ybnum;
}
int gctl::linear_mesh_3d::get_zbnum() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
- }
-
+ check_initiated(); // 检查网格是否已经初始化
return lm_zbnum;
}
double gctl::linear_mesh_3d::get_xmin() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
- }
-
+ check_initiated(); // 检查网格是否已经初始化
return lm_xmin;
}
double gctl::linear_mesh_3d::get_ymin() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
- }
-
+ check_initiated(); // 检查网格是否已经初始化
return lm_ymin;
}
double gctl::linear_mesh_3d::get_zmin() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
- }
-
+ check_initiated(); // 检查网格是否已经初始化
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 *gctl::linear_mesh_3d::get_xsizes() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
- }
-
+ check_initiated(); // 检查网格是否已经初始化
return &lm_xsizes;
}
const gctl::array *gctl::linear_mesh_3d::get_ysizes() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
- }
-
+ check_initiated(); // 检查网格是否已经初始化
return &lm_ysizes;
}
const gctl::array *gctl::linear_mesh_3d::get_zsizes() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
- }
-
+ check_initiated(); // 检查网格是否已经初始化
return &lm_zsizes;
}
@@ -369,14 +373,14 @@ void gctl::linear_mesh_3d::save_gmsh(std::string filename, index_packed_e packed
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;
}
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;
}
diff --git a/lib/mesh/linear_mesh_3d.h b/lib/mesh/linear_mesh_3d.h
index 981581e..b27b537 100644
--- a/lib/mesh/linear_mesh_3d.h
+++ b/lib/mesh/linear_mesh_3d.h
@@ -44,6 +44,8 @@ namespace gctl
double zmin, const array &xsizes, const array &ysizes,
const array &zsizes);
+ void show_mesh_dimension(std::ostream &os) const;
+
void load_binary(std::string filename);
void save_binary(std::string filename);
@@ -63,12 +65,15 @@ namespace gctl
double get_xmin() const;
double get_ymin() const;
double get_zmin() const;
+ double get_xmax() const;
+ double get_ymax() const;
+ double get_zmax() const;
const array *get_xsizes() const;
const array *get_ysizes() const;
const array *get_zsizes() const;
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);
protected:
diff --git a/lib/mesh/mesh.cpp b/lib/mesh/mesh.cpp
index 4b98173..5ae0907 100644
--- a/lib/mesh/mesh.cpp
+++ b/lib/mesh/mesh.cpp
@@ -1,4 +1,4 @@
-/********************************************************
+/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
@@ -29,758 +29,485 @@
gctl::base_mesh::base_mesh()
{
- initialized = false;
- //std::clog << "A new mesh object is created." << std::endl;
+ meshtype_ = UNDEFINED;
+ meshdim_ = MESH_0D;
+ meshname_ = "Untitled";
+ meshinfo_ = "Undefined";
+ node_num_ = ele_num_ = 0;
+ initialized_ = false;
}
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;
+ meshtype_ = UNDEFINED;
+ meshdim_ = MESH_0D;
+ meshname_ = "Untitled";
+ meshinfo_ = "Undefined";
+ node_num_ = ele_num_ = 0;
+ initialized_ = false;
+ destroy_vector(datalist_);
return;
}
bool gctl::base_mesh::initiated() const
{
- return initialized;
+ return initialized_;
}
bool gctl::base_mesh::saved(std::string datname) const
{
- if (saved_data.empty())
- {
- return false;
- }
+ if (datalist_.empty()) return false;
else
{
- meshdata *data_ptr = nullptr;
- // 这里我们需要使用常量迭代器
- std::list::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;
- }
- }
+ for (size_t i = 0; i < datalist_.size(); i++)
+ {
+ if (datalist_[i].name_ == datname) return true;
+ }
+
return false;
}
}
-gctl::meshdata *gctl::base_mesh::get_data(std::string datname) const
+gctl::meshdata &gctl::base_mesh::get_data(std::string datname)
{
- if (saved_data.empty())
- {
- throw std::runtime_error("[gctl::base_mesh] No data saved.");
- }
-
- meshdata *curr_data = nullptr;
- std::list::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& 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::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();
+ return datalist_[data_index(datname)];
}
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;
- }
- }
+ int idx = data_index(datname);
+ datalist_.erase(datalist_.begin() + idx);
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 (meshtype_ == UNDEFINED) os << "Undefined | ";
+ if (meshtype_ == REGULAR_MESH) os << "Regular | ";
+ if (meshtype_ == LINEAR_MESH) os << "Linear | ";
+ if (meshtype_ == TRI_TET_MESH) os << "Unstructured | ";
+ if (meshtype_ == REGULAR_MESH_SPH) os << "Regular (spherical) | ";
+ if (meshtype_ == LINEAR_MESH_SPH) os << "Linear (spherical) | ";
+ if (meshtype_ == TRI_TET_MESH_SPH) os << "Unstructured (spherical) | ";
+ if (meshtype_ == REGULAR_GRID) os << "Grid | ";
- if (meshdim == MESH_2D) os << "2D" << std::endl;
- else if (meshdim == MESH_3D) os << "3D" << std::endl;
+ if (meshdim_ == MESH_0D) os << "Unknown" << std::endl;
+ else 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;
+ os << "Name: " << meshname_ << std::endl;
+ os << "Info: " << meshinfo_ << std::endl;
show_mesh_dimension(os);
- meshdata *curr_data;
- std::list::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);
+ for (size_t i = 0; i < datalist_.size(); i++)
+ {
+ datalist_[i].show_info(os);
+ }
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;
+ check_initiated();
+ 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;
+ check_initiated();
+ return meshdim_;
}
int gctl::base_mesh::get_nodenum() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
- }
-
- return node_num;
+ check_initiated();
+ 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;
+ check_initiated();
+ 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();
+ check_initiated();
+ return datalist_.size();
}
std::string gctl::base_mesh::get_meshname() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
- }
-
- return meshname;
+ check_initiated();
+ 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;
+ check_initiated();
+ 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;
+ check_initiated();
+ 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;
+ check_initiated();
+ 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)
+gctl::meshdata &gctl::base_mesh::add_data(mesh_data_type_e in_loctype, mesh_data_value_e in_valtype,
+ std::string name, double init_val, bool if_output, double nan_val)
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
- }
+ check_initiated();
+ meshdata new_data(in_loctype, in_valtype, 0, name, if_output, nan_val);
- 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);
- }
+ if (in_loctype == NodeData && in_valtype == Scalar) new_data.datval_.resize(node_num_, init_val);
+ else if (in_loctype == ElemData && in_valtype == Scalar) new_data.datval_.resize(ele_num_, init_val);
+ else if (in_loctype == NodeData && in_valtype == Vector) new_data.datval_.resize(3*node_num_, init_val);
+ else if (in_loctype == ElemData && in_valtype == Vector) new_data.datval_.resize(3*ele_num_, init_val);
+ else if (in_loctype == NodeData && in_valtype == Tensor) new_data.datval_.resize(9*node_num_, init_val);
+ else if (in_loctype == ElemData && in_valtype == Tensor) new_data.datval_.resize(9*ele_num_, init_val);
+ else throw std::runtime_error("[gctl::base_mesh] Fail to initialize the new data.");
- // 存在一个同名 同数据类型 同赋值类型的数据 则将其数据设置为初始值
- array* val_ptr = (array*) 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;
+ datalist_.push_back(new_data);
+ return datalist_.back();
}
-gctl::meshdata *gctl::base_mesh::add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, gctl::point3dc init_val)
+gctl::meshdata &gctl::base_mesh::add_data(mesh_data_type_e in_loctype, std::string name,
+ const array &init_arr, bool if_output, double nan_val)
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
- }
+ check_initiated();
+ meshdata new_data(in_loctype, Scalar, 0, name, if_output, nan_val);
- 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);
- }
+ if (in_loctype == NodeData)
+ {
+ if (init_arr.size() != node_num_) throw std::runtime_error("[gctl::base_mesh] Invalid input data size.");
+ new_data.datval_ = init_arr;
+ }
+ else if (in_loctype == ElemData)
+ {
+ if (init_arr.size() != ele_num_) throw std::runtime_error("[gctl::base_mesh] Invalid input data size.");
+ new_data.datval_ = init_arr;
+ }
+ else throw std::runtime_error("[gctl::base_mesh] Invalid input data location.");
- // 存在一个同名 同数据类型 同赋值类型的数据 则将其数据设置为初始值
- array* val_ptr = (array*) 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;
+ datalist_.push_back(new_data);
+ return datalist_.back();
}
-gctl::meshdata *gctl::base_mesh::add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, gctl::tensor init_val)
+gctl::meshdata &gctl::base_mesh::add_data(mesh_data_type_e in_loctype, std::string name,
+ const array &init_arr, bool if_output, double nan_val)
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
- }
+ check_initiated();
+ meshdata new_data(in_loctype, Vector, 0, name, if_output, nan_val);
- 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);
- }
+ if (in_loctype == NodeData)
+ {
+ if (init_arr.size() != node_num_) throw std::runtime_error("[gctl::base_mesh] Invalid input data size.");
- // 存在一个同名 同数据类型 同赋值类型的数据 则将其数据设置为初始值
- array* val_ptr = (array*) data_ptr->get_datval_ptr();
- val_ptr->assign_all(init_val);
- return data_ptr;
- }
+ new_data.datval_.resize(3*node_num_);
+ for (size_t i = 0; i < node_num_; i++)
+ {
+ new_data.datval_[3*i] = init_arr[i].x;
+ new_data.datval_[3*i+1] = init_arr[i].y;
+ new_data.datval_[3*i+2] = init_arr[i].z;
+ }
+ }
+ else if (in_loctype == ElemData)
+ {
+ if (init_arr.size() != ele_num_) throw std::runtime_error("[gctl::base_mesh] Invalid input data size.");
+
+ new_data.datval_.resize(3*ele_num_);
+ for (size_t i = 0; i < ele_num_; i++)
+ {
+ new_data.datval_[3*i] = init_arr[i].x;
+ new_data.datval_[3*i+1] = init_arr[i].y;
+ new_data.datval_[3*i+2] = init_arr[i].z;
+ }
+ }
+ else throw std::runtime_error("[gctl::base_mesh] Invalid input data location.");
- 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;
+ datalist_.push_back(new_data);
+ return datalist_.back();
}
-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)
+gctl::meshdata &gctl::base_mesh::add_data(mesh_data_type_e in_loctype, std::string name,
+ const array &init_arr, bool if_output, double nan_val)
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
- }
+ check_initiated();
+ meshdata new_data(in_loctype, Tensor, 0, name, if_output, nan_val);
- 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);
- }
+ if (in_loctype == NodeData)
+ {
+ if (init_arr.size() != node_num_) throw std::runtime_error("[gctl::base_mesh] Invalid input data size.");
- return data_ptr;
- }
+ new_data.datval_.resize(9*node_num_);
+ for (size_t i = 0; i < node_num_; i++)
+ {
+ new_data.datval_[9*i] = init_arr[i].val[0][0];
+ new_data.datval_[9*i+1] = init_arr[i].val[0][1];
+ new_data.datval_[9*i+2] = init_arr[i].val[0][2];
+ new_data.datval_[9*i+3] = init_arr[i].val[1][0];
+ new_data.datval_[9*i+4] = init_arr[i].val[1][1];
+ new_data.datval_[9*i+5] = init_arr[i].val[1][2];
+ new_data.datval_[9*i+6] = init_arr[i].val[2][0];
+ new_data.datval_[9*i+7] = init_arr[i].val[2][1];
+ new_data.datval_[9*i+8] = init_arr[i].val[2][2];
+ }
+ }
+ else if (in_loctype == ElemData)
+ {
+ if (init_arr.size() != ele_num_) throw std::runtime_error("[gctl::base_mesh] Invalid input data size.");
+
+ new_data.datval_.resize(9*ele_num_);
+ for (size_t i = 0; i < ele_num_; i++)
+ {
+ new_data.datval_[9*i] = init_arr[i].val[0][0];
+ new_data.datval_[9*i+1] = init_arr[i].val[0][1];
+ new_data.datval_[9*i+2] = init_arr[i].val[0][2];
+ new_data.datval_[9*i+3] = init_arr[i].val[1][0];
+ new_data.datval_[9*i+4] = init_arr[i].val[1][1];
+ new_data.datval_[9*i+5] = init_arr[i].val[1][2];
+ new_data.datval_[9*i+6] = init_arr[i].val[2][0];
+ new_data.datval_[9*i+7] = init_arr[i].val[2][1];
+ new_data.datval_[9*i+8] = init_arr[i].val[2][2];
+ }
+ }
+ else throw std::runtime_error("[gctl::base_mesh] Invalid input data location.");
- 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;
+ datalist_.push_back(new_data);
+ return datalist_.back();
}
-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 &xsizes, const gctl::array &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 &xsizes, const gctl::array &ysizes,
- const gctl::array &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 &in_nodes,
- const gctl::array &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 &in_nodes,
- const gctl::array &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)
+void gctl::base_mesh::save_gmsh_withdata(std::string filename, 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)
+ for (size_t i = 0; i < datalist_.size(); i++)
{
- curr_data = *iter;
- if (curr_data->get_dattype() == d_type && d_type == NodeData &&
- curr_data->get_valtype() == Scalar && curr_data->get_output())
+ if (datalist_[i].loctype_ == NodeData)
{
- gctl::array *data_ptr = (gctl::array*) curr_data->get_datval_ptr();
- gctl::save_gmsh_data(outfile, curr_data->get_datname(), *data_ptr, gctl::NodeData, packed);
+ if (datalist_[i].valtype_ == Scalar) gctl::save_gmsh_data(outfile, datalist_[i].name_, datalist_[i].datval_, gctl::NodeData, packed);
+ else if (datalist_[i].valtype_ == Vector)
+ {
+ array vec_data(node_num_);
+ for (size_t j = 0; j < node_num_; j++)
+ {
+ vec_data[j].x = datalist_[i].datval_[3*j];
+ vec_data[j].y = datalist_[i].datval_[3*j+1];
+ vec_data[j].z = datalist_[i].datval_[3*j+2];
+ }
+
+ gctl::save_gmsh_data(outfile, datalist_[i].name_, vec_data, gctl::NodeData, packed);
+ }
+ //else if (datalist_[i].valtype_ == Tensor)
+ //{
+ // array ten_data(node_num_);
+ // for (size_t j = 0; j < node_num_; j++)
+ // {
+ // ten_data[j].val[0][0] = datalist_[i].datval_[9*j];
+ // ten_data[j].val[0][1] = datalist_[i].datval_[9*j+1];
+ // ten_data[j].val[0][2] = datalist_[i].datval_[9*j+2];
+ // ten_data[j].val[1][0] = datalist_[i].datval_[9*j+3];
+ // ten_data[j].val[1][1] = datalist_[i].datval_[9*j+4];
+ // ten_data[j].val[1][2] = datalist_[i].datval_[9*j+5];
+ // ten_data[j].val[2][0] = datalist_[i].datval_[9*j+6];
+ // ten_data[j].val[2][1] = datalist_[i].datval_[9*j+7];
+ // ten_data[j].val[2][2] = datalist_[i].datval_[9*j+8];
+ // }
+ //
+ // gctl::save_gmsh_data(outfile, datalist_[i].name_, ten_data, gctl::NodeData, packed);
+ //}
+ else throw std::runtime_error("[gctl::base_mesh] Invalid input data value type.");
}
- else if (curr_data->get_dattype() == d_type && d_type == ElemData &&
- curr_data->get_valtype() == Scalar && curr_data->get_output())
+ else if (datalist_[i].loctype_ == ElemData)
{
- gctl::array *data_ptr = (gctl::array*) 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 *data_ptr = (gctl::array*) 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 *data_ptr = (gctl::array*) curr_data->get_datval_ptr();
- gctl::save_gmsh_data(outfile, curr_data->get_datname(), *data_ptr, gctl::ElemData, packed);
+ if (datalist_[i].valtype_ == Scalar) gctl::save_gmsh_data(outfile, datalist_[i].name_, datalist_[i].datval_, gctl::ElemData, packed);
+ else if (datalist_[i].valtype_ == Vector)
+ {
+ array vec_data(ele_num_);
+ for (size_t j = 0; j < ele_num_; j++)
+ {
+ vec_data[j].x = datalist_[i].datval_[3*j];
+ vec_data[j].y = datalist_[i].datval_[3*j+1];
+ vec_data[j].z = datalist_[i].datval_[3*j+2];
+ }
+
+ gctl::save_gmsh_data(outfile, datalist_[i].name_, vec_data, gctl::ElemData, packed);
+ }
+ //else if (datalist_[i].valtype_ == Tensor)
+ //{
+ // array ten_data(ele_num_);
+ // for (size_t j = 0; j < ele_num_; j++)
+ // {
+ // ten_data[j].val[0][0] = datalist_[i].datval_[9*j];
+ // ten_data[j].val[0][1] = datalist_[i].datval_[9*j+1];
+ // ten_data[j].val[0][2] = datalist_[i].datval_[9*j+2];
+ // ten_data[j].val[1][0] = datalist_[i].datval_[9*j+3];
+ // ten_data[j].val[1][1] = datalist_[i].datval_[9*j+4];
+ // ten_data[j].val[1][2] = datalist_[i].datval_[9*j+5];
+ // ten_data[j].val[2][0] = datalist_[i].datval_[9*j+6];
+ // ten_data[j].val[2][1] = datalist_[i].datval_[9*j+7];
+ // ten_data[j].val[2][2] = datalist_[i].datval_[9*j+8];
+ // }
+ //
+ // gctl::save_gmsh_data(outfile, datalist_[i].name_, ten_data, gctl::ElemData, packed);
+ //}
+ else throw std::runtime_error("[gctl::base_mesh] Invalid input data value type.");
}
+ else throw std::runtime_error("[gctl::base_mesh] Invalid input data location.");
}
outfile.close();
return;
}
-void gctl::base_mesh::save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed)
+void gctl::base_mesh::save_gmsh_withdata(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)
+ const meshdata &data = get_data(datname);
+ if (data.loctype_ == NodeData)
{
- gctl::array *data_ptr = (gctl::array*) curr_data->get_datval_ptr();
- if (curr_data->get_dattype() == NodeData)
+ if (data.valtype_ == Scalar) gctl::save_gmsh_data(outfile, data.name_, data.datval_, gctl::NodeData, packed);
+ else if (data.valtype_ == Vector)
{
- 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);
+ array vec_data(node_num_);
+ for (size_t j = 0; j < node_num_; j++)
+ {
+ vec_data[j].x = data.datval_[3*j];
+ vec_data[j].y = data.datval_[3*j+1];
+ vec_data[j].z = data.datval_[3*j+2];
+ }
+
+ gctl::save_gmsh_data(outfile, data.name_, vec_data, gctl::NodeData, packed);
}
+ //else if (data.valtype_ == Tensor)
+ //{
+ // array ten_data(node_num_);
+ // for (size_t j = 0; j < node_num_; j++)
+ // {
+ // ten_data[j].val[0][0] = data.datval_[9*j];
+ // ten_data[j].val[0][1] = data.datval_[9*j+1];
+ // ten_data[j].val[0][2] = data.datval_[9*j+2];
+ // ten_data[j].val[1][0] = data.datval_[9*j+3];
+ // ten_data[j].val[1][1] = data.datval_[9*j+4];
+ // ten_data[j].val[1][2] = data.datval_[9*j+5];
+ // ten_data[j].val[2][0] = data.datval_[9*j+6];
+ // ten_data[j].val[2][1] = data.datval_[9*j+7];
+ // ten_data[j].val[2][2] = data.datval_[9*j+8];
+ // }
+ //
+ // gctl::save_gmsh_data(outfile, data.name_, ten_data, gctl::NodeData, packed);
+ //}
+ else throw std::runtime_error("[gctl::base_mesh] Invalid input data value type.");
}
- else if (curr_data->get_valtype() == Vector)
+ else if (data.loctype_ == ElemData)
{
- gctl::array *data_ptr = (gctl::array*) curr_data->get_datval_ptr();
- if (curr_data->get_dattype() == NodeData)
+ if (data.valtype_ == Scalar) gctl::save_gmsh_data(outfile, data.name_, data.datval_, gctl::ElemData, packed);
+ else if (data.valtype_ == Vector)
{
- 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 *data_ptr = (gctl::array*) curr_data->get_datval_ptr();
- if (curr_data->get_dattype() == NodeData)
- {
- array 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 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);
+ array vec_data(ele_num_);
+ for (size_t j = 0; j < ele_num_; j++)
+ {
+ vec_data[j].x = data.datval_[3*j];
+ vec_data[j].y = data.datval_[3*j+1];
+ vec_data[j].z = data.datval_[3*j+2];
+ }
+
+ gctl::save_gmsh_data(outfile, data.name_, vec_data, gctl::ElemData, packed);
}
+ //else if (data.valtype_ == Tensor)
+ //{
+ // array ten_data(ele_num_);
+ // for (size_t j = 0; j < ele_num_; j++)
+ // {
+ // ten_data[j].val[0][0] = data.datval_[9*j];
+ // ten_data[j].val[0][1] = data.datval_[9*j+1];
+ // ten_data[j].val[0][2] = data.datval_[9*j+2];
+ // ten_data[j].val[1][0] = data.datval_[9*j+3];
+ // ten_data[j].val[1][1] = data.datval_[9*j+4];
+ // ten_data[j].val[1][2] = data.datval_[9*j+5];
+ // ten_data[j].val[2][0] = data.datval_[9*j+6];
+ // ten_data[j].val[2][1] = data.datval_[9*j+7];
+ // ten_data[j].val[2][2] = data.datval_[9*j+8];
+ // }
+ //
+ // gctl::save_gmsh_data(outfile, data.name_, ten_data, gctl::ElemData, packed);
+ //}
+ else throw std::runtime_error("[gctl::base_mesh] Invalid input data value type.");
}
+ else throw std::runtime_error("[gctl::base_mesh] Invalid input data location.");
outfile.close();
return;
}
-void gctl::base_mesh::load_data_cloud(const array &in_posi, const array &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 &in_posi, const array &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 &in_posi, array &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 &in_posi, array &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 &out_posi, array &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 &out_posi, array &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::check_initiated(bool inverse) const
+{
+ if (inverse == true)
+ {
+ if (initialized_) throw std::runtime_error("[gctl::base_mesh] Mesh already initialized.");
+ else return;
+ }
+
+ if (!initialized_) throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
+ else 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_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.");
- 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;
+ meshname_ = in_name;
+ meshinfo_ = in_info;
+ meshtype_ = in_type;
+ meshdim_ = in_dim;
return;
}
+int gctl::base_mesh::data_index(std::string datname) const
+{
+ if (datalist_.empty()) throw std::runtime_error("[gctl::base_mesh] No data saved.");
+
+ for (size_t i = 0; i < datalist_.size(); i++)
+ {
+ if (datalist_[i].name_ == datname) return i;
+ }
+
+ throw gctl::runtime_error("[gctl::base_mesh] No data found by the name: " + datname);
+}
+
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.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.");
@@ -788,36 +515,26 @@ void gctl::base_mesh::load_headinfo(std::ifstream &infile, mesh_type_e expected_
int info_size;
infile.read((char*)&info_size, sizeof(int));
- meshname.resize(info_size);
- infile.read((char*)meshname.c_str(), info_size);
+ 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);
+ 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;
+ int in_num;
+ meshdata new_data;
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);
+ new_data.clear();
+ new_data.load_binary(infile);
+ datalist_.push_back(new_data);
}
return;
}
@@ -825,39 +542,32 @@ void gctl::base_mesh::load_datablock(std::ifstream &infile)
void gctl::base_mesh::save_headinfo(std::ofstream &outfile)
{
// 首先输出网格的类型和维度
- outfile.write((char*)&meshtype, sizeof(int));
- outfile.write((char*)&meshdim, sizeof(int));
+ outfile.write((char*)&meshtype_, sizeof(int));
+ outfile.write((char*)&meshdim_, sizeof(int));
// 输出网格名称与信息
- int info_size = meshname.size();
+ 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*)meshname_.c_str(), info_size);
+ info_size = meshinfo_.size();
outfile.write((char*)&info_size, sizeof(int));
- outfile.write((char*)meshinfo.c_str(), info_size);
+ 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)
+{
+ int num = 0;
+ for (size_t i = 0; i < datalist_.size(); i++)
{
- curr_data = *iter;
- if (curr_data->get_output())
- {
- out_num++;
- }
+ if (datalist_[i].output_ok_) num++;
}
- outfile.write((char*)&out_num, sizeof(int));
- for (iter = saved_data.begin(); iter != saved_data.end(); ++iter)
+ outfile.write((char*) &num, sizeof(int));
+ for (size_t i = 0; i < datalist_.size(); i++)
{
- curr_data = *iter;
- if (curr_data->get_output())
+ if (datalist_[i].output_ok_)
{
- curr_data->save_binary(outfile);
+ datalist_[i].save_binary(outfile); // 输出数据块
}
}
return;
diff --git a/lib/mesh/mesh.h b/lib/mesh/mesh.h
index a6f6eb2..9347c74 100644
--- a/lib/mesh/mesh.h
+++ b/lib/mesh/mesh.h
@@ -1,4 +1,4 @@
-/********************************************************
+/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
@@ -28,13 +28,7 @@
#ifndef _GCTL_BASE_MESH_H
#define _GCTL_BASE_MESH_H
-#include "list"
-
#include "meshdata.h"
-#include "meshdata_scalar.h"
-#include "meshdata_vector.h"
-#include "meshdata_tensor.h"
-
#include "gctl/io.h"
#include "gctl/algorithm.h"
@@ -42,6 +36,7 @@ namespace gctl
{
enum mesh_type_e
{
+ UNDEFINED,
REGULAR_MESH,
LINEAR_MESH,
TRI_TET_MESH,
@@ -53,6 +48,7 @@ namespace gctl
enum mesh_dim_e
{
+ MESH_0D,
MESH_2D,
MESH_3D,
};
@@ -74,7 +70,6 @@ namespace gctl
/**
* @brief 检查网格是否已经初始化。
- *
*/
bool initiated() const;
@@ -85,36 +80,6 @@ namespace gctl
*/
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 &out_list) const;
-
- /**
- * @brief 返回对应名称的数据对象的数组指针。
- *
- * @param datname 数据名
- * @return 数组指针(注意需要转换为对应的数组指针类型)
- */
- void *get_datval(std::string datname) const;
-
- /**
- * @brief 删除对应名称的数据对象。
- *
- * @param datname 数据名
- */
- void remove_data(std::string datname);
-
/**
* @brief 显示网格与数据信息。
*
@@ -122,14 +87,6 @@ namespace gctl
*/
void show_info(std::ostream &os = std::clog) const;
- /**
- * @brief 重命名数据对象。
- *
- * @param oldname 旧名称
- * @param newname 新名称
- */
- void rename_data(std::string oldname, std::string newname);
-
/**
* @brief 返回网格类型
*
@@ -194,156 +151,109 @@ namespace gctl
void set_meshinfo(std::string in_info);
/**
- * @brief 添加标量网格数据对象并赋初始值,如果对象已经存在则赋初始值
+ * @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_loctype 网格数据类型(块体或顶点数据)
+ * @param in_valtype 网格数据值类型
+ * @param name 数据名称
+ * @param init_val 数据初始值
+ * @param if_output 数据是否可用于输出
+ * @param nan_val 数据无效值标记
*
- * @param in_name 数据对象名称
- * @param in_type 数据对象类型
- * @param if_output 数据对象是否可输出
- * @param init_val 初始值
- * @return 新建的数据对象指针
+ * @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);
+ 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_loctype 网格数据类型(块体或顶点数据)
+ * @param name 数据名称
+ * @param init_arr 数据初始值数组
+ * @param if_output 数据是否可用于输出
+ * @param nan_val 数据无效值标记
*
- * @param in_name 网格名称
- * @param in_info 网格说明信息
- * @param xnum 网格x轴数量
- * @param ynum 网格y轴数量
- * @param xmin 网格x轴最小值
- * @param ymin 网格y轴最小值
- * @param dx 网格x轴间隔
- * @param dy 网格y轴间隔
+ * @return 数据对象
*/
- virtual void init(std::string in_name, std::string in_info, int xnum, int ynum,
- double xmin, double ymin, double dx, double dy);
+ meshdata &add_data(mesh_data_type_e in_loctype, std::string name, const array &init_arr,
+ bool if_output = true, double nan_val = GCTL_BDL_MAX);
/**
- * @brief
+ * @brief 添加网格数据。
+ *
+ * @param in_loctype 网格数据类型(块体或顶点数据)
+ * @param name 数据名称
+ * @param init_arr 数据初始值数组
+ * @param if_output 数据是否可用于输出
+ * @param nan_val 数据无效值标记
*
- * @param in_name
- * @param in_info
- * @param xbnum
- * @param ybnum
- * @param zbnum
- * @param xmin
- * @param ymin
- * @param zmin
- * @param xsize
- * @param ysize
- * @param zsize
+ * @return 数据对象
*/
- 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);
+ meshdata &add_data(mesh_data_type_e in_loctype, std::string name, const array &init_arr,
+ bool if_output = true, double nan_val = GCTL_BDL_MAX);
+
+ /**
+ * @brief 添加网格数据。
+ *
+ * @param in_loctype 网格数据类型(块体或顶点数据)
+ * @param name 数据名称
+ * @param init_arr 数据初始值数组
+ * @param if_output 数据是否可用于输出
+ * @param nan_val 数据无效值标记
+ *
+ * @return 数据对象
+ */
+ meshdata &add_data(mesh_data_type_e in_loctype, std::string name, const array &init_arr,
+ bool if_output = true, double nan_val = GCTL_BDL_MAX);
+
+ /**
+ * @brief 返回对应名称的数据对象指针。
+ *
+ * @param datname 数据名
+ * @return 数据指针
+ */
+ meshdata &get_data(std::string datname);
+
+ /**
+ * @brief 删除对应名称的数据对象。
+ *
+ * @param datname 数据名
+ */
+ void remove_data(std::string datname);
/**
- * @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
+ * @brief 保存网格到Gmsh文件,并保存所有数据。
+ *
+ * @param filename 文件名
+ * @param out_mode 输出模式
+ * @param packed 索引是否为紧凑(从0开始)
*/
- 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);
+ void save_gmsh_withdata(std::string filename, output_type_e out_mode, index_packed_e packed = Packed);
/**
- * @brief
- *
- * @param in_name
- * @param in_info
- * @param xmin
- * @param ymin
- * @param xsizes
- * @param ysizes
+ * @brief 保存网格到Gmsh文件,并保存指定名称的数据。
+ *
+ * @param filename 文件名
+ * @param datname 数据名
+ * @param out_mode 输出模式
+ * @param packed 索引是否为紧凑(从0开始)
*/
- virtual void init(std::string in_name, std::string in_info, double xmin, double ymin,
- const gctl::array &xsizes, const gctl::array &ysizes);
-
+ void save_gmsh_withdata(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
+
/**
- * @brief
+ * @brief (基类虚函数)保存网格到Gmsh文件。
*
- * @param in_name
- * @param in_info
- * @param xmin
- * @param ymin
- * @param zmin
- * @param xsizes
- * @param ysizes
- * @param zsizes
+ * @param filename 文件名
+ * @param packed 索引是否为紧凑(从0开始)
*/
- virtual void init(std::string in_name, std::string in_info, double xmin, double ymin,
- double zmin, const gctl::array &xsizes, const gctl::array &ysizes,
- const gctl::array &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 &in_nodes,
- const gctl::array &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 &in_nodes,
- const gctl::array &in_tets);
+ virtual void save_gmsh(std::string filename, index_packed_e packed = Packed) = 0;
/**
* @brief 显示网格的维度信息
*
*/
- virtual void show_mesh_dimension(std::ostream &os) const;
+ virtual void show_mesh_dimension(std::ostream &os) const = 0;
/**
* @brief (基类纯虚函数)读入二进制网格文件
@@ -359,190 +269,44 @@ namespace gctl
*/
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 &in_posi, const array &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 &in_posi, const array &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 &in_posi, array &out_val);
-
- /**
- * @brief
- *
- * @param datname
- * @param in_posi
- * @param out_val
- */
- virtual void extract_points(std::string datname, const array &in_posi, array &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 &out_posi, array &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 &out_posi, array &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;
+ mesh_type_e meshtype_;
+ mesh_dim_e meshdim_;
+ std::string meshname_;
+ std::string meshinfo_;
- int node_num, ele_num;
- bool initialized;
+ int node_num_, ele_num_;
+ bool initialized_;
- std::list saved_data;
- std::list::iterator iter;
+ std::vector datalist_;
/**
* 以下为类的私有函数 只能被类的公共函数调用
*/
+
+ /**
+ * @brief 检查网格是否已经初始化。
+ *
+ */
+ void check_initiated(bool inverse = false) const;
/**
* @brief 初始化网格
- *
- * @param in_type
- * @param in_dim
- * @param in_name
- * @param in_info
+ *
+ * @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 datname 数据名
+ */
+ int data_index(std::string datname) const;
+
/**
* @brief 读入二进制网格头信息
*
diff --git a/lib/mesh/meshdata.cpp b/lib/mesh/meshdata.cpp
index 725f02a..4a7015d 100644
--- a/lib/mesh/meshdata.cpp
+++ b/lib/mesh/meshdata.cpp
@@ -1,4 +1,4 @@
-/********************************************************
+/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
@@ -26,69 +26,226 @@
******************************************************/
#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 == "")
- {
- throw std::runtime_error("[gctl::meshdata] The input name is empty.");
- }
-
- datname = in_name;
- dattype = in_type;
- output_ok = if_output;
+ name_ = "untitled";
+ loctype_ = NodeData;
+ valtype_ = Scalar;
+ output_ok_ = true;
+ nan_val_ = GCTL_BDL_MAX;
}
-gctl::meshdata::~meshdata(){}
-
-void gctl::meshdata::set_datname(std::string in_name)
+gctl::meshdata::meshdata(mesh_data_type_e in_loctype,
+ mesh_data_value_e in_valtype, size_t size,
+ std::string name, bool if_output, double nan_val)
{
- if (in_name == "")
- {
- throw std::runtime_error("[gctl::meshdata] The input name is empty.");
- }
+ create(in_loctype, in_valtype, size, name, if_output, nan_val);
+}
- 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::meshdata::export_vector() const
+{
+ if (valtype_ != Vector) throw std::runtime_error("[gctl::meshdata::export_vector] Invalid data type.");
+
+ size_t n = 0;
+ array 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::meshdata::export_tensor() const
+{
+ if (valtype_ != Tensor) throw std::runtime_error("[gctl::meshdata::export_tensor] Invalid data type.");
+
+ size_t n = 0;
+ array 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;
}
-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()
-{
- return dattype;
-}
+ array tmp_x(vn), tmp_y(vn), tmp_z(vn);
-gctl::mesh_data_value_e gctl::meshdata::get_valtype()
-{
- return valtype;
-}
+ vn = 0;
+ for (size_t i = 0; i < datval_.size(); i += 3)
+ {
+ 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++;
+ }
+ }
+
+ os << "mean = (" << tmp_x.mean() << ", " << tmp_y.mean() << ", " << tmp_z.mean() << ")\n"
+ << "std = (" << tmp_x.std() << ", " << tmp_y.std() << ", " << tmp_z.std() << ")\n"
+ << "rms = (" << tmp_x.rms() << ", " << tmp_y.rms() << ", " << tmp_z.rms() << ")\n";
+ }
+ else if (valtype_ == Tensor)
+ {
+ for (size_t i = 0; i < datval_.size(); i += 9)
+ {
+ if (fabs(datval_[9*i] - nan_val_) > 1e-10) vn++;
+ }
-void gctl::meshdata::set_output(bool if_output)
-{
- output_ok = if_output;
+ array tmp_xx(vn), tmp_xy(vn), tmp_xz(vn);
+ array tmp_yx(vn), tmp_yy(vn), tmp_yz(vn);
+ array 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 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;
}
-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 << " | ";
- 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;
+ int name_size = name_.size();
+ outfile.write((char*) &name_size, sizeof(int));
+ outfile.write((char*) name_.c_str(), name_size);
+ outfile.write((char*) &loctype_, sizeof(int));
+ outfile.write((char*) &valtype_, sizeof(int));
+ outfile.write((char*) &output_ok_, sizeof(bool));
+
+ int n = datval_.size();
+ outfile.write((char*) &n, sizeof(int));
+ outfile.write((char*) datval_.get(), sizeof(double)*datval_.size());
+ outfile.write((char*) &nan_val_, sizeof(double));
+ return;
}
\ No newline at end of file
diff --git a/lib/mesh/meshdata.h b/lib/mesh/meshdata.h
index 217aea1..46b0e7f 100644
--- a/lib/mesh/meshdata.h
+++ b/lib/mesh/meshdata.h
@@ -1,4 +1,4 @@
-/********************************************************
+/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
@@ -30,11 +30,12 @@
#include "gctl_mesh_config.h"
#include "gctl/core.h"
-#include "gctl/geometry.h"
+#include "gctl/geometry/point3c.h"
+#include "gctl/geometry/tensor.h"
namespace gctl
{
- /**
+ /**
* @brief 网格数据的数值类型
*/
enum mesh_data_value_e
@@ -44,93 +45,90 @@ namespace gctl
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 网格文件中的数据对象,可储存标量、矢量和张量数据。
+ *
+ */
+ struct meshdata
+ {
+ std::string name_; // 数据的名称
+ mesh_data_type_e loctype_; // 数据的赋值位置属性 顶点或是元素
+ mesh_data_value_e valtype_; // 数据的类型
+ bool output_ok_; // 是否可输出数据
+ array datval_; // 数据值 注意目前我们只支持浮点数据存储
+ double nan_val_; // 无效数据的标记值
/**
- * @brief 设置数据名称
- *
- * @param[in] in_name 名称字符串
+ * @brief 构造函数
*/
- void set_datname(std::string in_name);
+ meshdata();
/**
- * @brief 返回数据的名称
- *
- * @return 名称字符串
+ * @brief 创建数据对象
+ *
+ * @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 返回数据的赋值类型
- *
- * @return 数据赋值类型的枚举
+ * @brief 析构函数
*/
- mesh_data_type_e get_dattype();
+ virtual ~meshdata();
/**
- * @brief 返回数据值的类型
- *
- * @return 数据值类型的枚举
+ * @brief 清空数据对象
*/
- mesh_data_value_e get_valtype();
+ void clear();
/**
- * @brief 设置数据对象输出状态的设置情况
- *
- * @param[in] if_output 是否可输出此对象
+ * @brief 创建数据对象
+ *
+ * @param in_loctype 数据的赋值位置属性 顶点或是元素
+ * @param in_valtype 数据的类型
+ * @param size 数据的大小
+ * @param name 数据的名称
+ * @param if_output 是否可输出数据
+ * @param nan_val 无效数据的标记值
*/
- void set_output(bool if_output);
+ 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 返回数据对象输出状态的设置情况
- *
- * @return 是否可输出此对象
+ * @brief 返回适量数据。
*/
- bool get_output();
+ array export_vector() const;
/**
+ * @brief 返回张量数据。
+ */
+ array export_tensor() const;
+
+ /**
* @brief 显示数据对象的头信息
*/
- void show_info(std::ostream &os = std::clog);
+ void show_info(std::ostream &os = std::clog) const;
- /**
+ /**
* @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 载入二进制文件
*
* @warning 不要直接调用此函数,应该在网格类型的相应函数中调用
*
* @param infile 输入文件的流(以二进制方式打开)
*/
- virtual void load_binary(std::ifstream &infile) = 0;
+ void load_binary(std::ifstream &infile);
/**
* @brief 保存二进制文件
@@ -139,20 +137,8 @@ namespace gctl
*
* @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;
- }
- };
+ void save_binary(std::ofstream &outfile);
+ };
}
-#endif //_GCTL_MESHDATA_H
\ No newline at end of file
+#endif // _GCTL_MESHDATA_H
\ No newline at end of file
diff --git a/lib/mesh/regular_grid.cpp b/lib/mesh/regular_grid.cpp
index 28bc240..0e1e5d8 100644
--- a/lib/mesh/regular_grid.cpp
+++ b/lib/mesh/regular_grid.cpp
@@ -35,22 +35,18 @@
void gctl::regular_grid::init(std::string in_name, std::string in_info, int xnum, int ynum,
double xmin, double ymin, double dx, double dy)
{
- if (initialized)
- {
- throw std::runtime_error("[gctl::regular_grid] The mesh is already initialized.");
- }
-
+ check_initiated(true); // check to see if the mesh is already initiated
base_mesh::init(REGULAR_GRID, MESH_2D, in_name, in_info);
rg_xnum = xnum; rg_ynum = ynum;
rg_xmin = xmin; rg_ymin = ymin;
rg_dx = dx; rg_dy = dy;
- node_num = rg_xnum * rg_ynum;
- ele_num = (rg_xnum-1) * (rg_ynum-1);
+ node_num_ = rg_xnum * rg_ynum;
+ ele_num_ = (rg_xnum-1) * (rg_ynum-1);
- nodes.resize(node_num);
- elements.resize(ele_num);
+ nodes.resize(node_num_);
+ elements.resize(ele_num_);
for (int j = 0; j < rg_ynum; j++)
{
@@ -76,24 +72,24 @@ void gctl::regular_grid::init(std::string in_name, std::string in_info, int xnum
}
}
- initialized = true;
+ initialized_ = true;
return;
}
void gctl::regular_grid::show_mesh_dimension(std::ostream &os) const
{
- os << "Range X: " << rg_xmin << " -> " << rg_xmin + (rg_xnum - 1)*rg_dx << "\n";
- os << "Range Y: " << rg_ymin << " -> " << rg_ymin + (rg_ynum - 1)*rg_dy << "\n";
- os << "Interval: " << rg_dx << ", " << rg_dy << "\n";
+ os << "node num: " << node_num_ << std::endl;
+ os << "elem num: " << ele_num_ << std::endl;
+ os << "x-range: " << rg_xmin << " -> " << rg_xmin + (rg_xnum - 1)*rg_dx << "\n";
+ os << "y-range: " << rg_ymin << " -> " << rg_ymin + (rg_ynum - 1)*rg_dy << "\n";
+ os << "interval: " << rg_dx << ", " << rg_dy << "\n";
+ os << "dimension: " << rg_xnum << ", " << rg_ynum << "\n";
return;
}
void gctl::regular_grid::load_binary(std::string filename)
{
- if (initialized)
- {
- throw std::runtime_error("[gctl::regular_grid] The mesh is already initialized.");
- }
+ check_initiated(true); // check to see if the mesh is already initiated
std::ifstream infile;
gctl::open_infile(infile, filename, ".2m", std::ios::in|std::ios::binary);
@@ -109,11 +105,11 @@ void gctl::regular_grid::load_binary(std::string filename)
infile.read((char*)&rg_dx, sizeof(double));
infile.read((char*)&rg_dy, sizeof(double));
- node_num = rg_xnum * rg_ynum;
- ele_num = (rg_xnum-1) * (rg_ynum-1);
+ node_num_ = rg_xnum * rg_ynum;
+ ele_num_ = (rg_xnum-1) * (rg_ynum-1);
- nodes.resize(node_num);
- elements.resize(ele_num);
+ nodes.resize(node_num_);
+ elements.resize(ele_num_);
for (int j = 0; j < rg_ynum; j++)
{
@@ -139,7 +135,7 @@ void gctl::regular_grid::load_binary(std::string filename)
}
}
- initialized = true;
+ initialized_ = true;
// 读入模型数据单元
load_datablock(infile);
@@ -149,10 +145,7 @@ void gctl::regular_grid::load_binary(std::string filename)
void gctl::regular_grid::save_binary(std::string filename)
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::regular_grid] The mesh is not initialized.");
- }
+ check_initiated(); // check to see if the mesh is not initiated
std::ofstream outfile;
gctl::open_outfile(outfile, filename, ".2m", std::ios::out|std::ios::binary);
@@ -197,11 +190,11 @@ void gctl::regular_grid::clear_regular_grid()
int gctl::regular_grid::view(std::string datname)
{
- array *datval_ptr = (array*) get_datval(datname);
+ meshdata data = get_data(datname);
plt.range(rg_xmin, rg_xmin + (rg_xnum - 1)*rg_dx, rg_ymin, rg_ymin + (rg_ynum - 1)*rg_dy);
plt.demension(rg_xnum, rg_ynum);
- plt.add_dens(*datval_ptr, datname);
+ plt.add_dens(data.datval_, datname);
return plt.plot();
}
@@ -218,10 +211,10 @@ int gctl::regular_grid::view(std::string datname)
void gctl::regular_grid::plot(std::string datname)
{
- array *datval_ptr = (array*) get_datval(datname);
+ meshdata data = get_data(datname);
pic.set_command("psconvert", "-A -TG -E300");
- pic.plot(datname, *datval_ptr,
+ pic.plot(datname, data.datval_,
rg_xmin, rg_xmin + (rg_xnum - 1)*rg_dx,
rg_ymin, rg_ymin + (rg_ynum - 1)*rg_dy,
rg_xnum, rg_ynum);
@@ -239,61 +232,37 @@ void gctl::regular_grid::plot(std::string datname)
int gctl::regular_grid::get_xdim() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::regular_grid] The mesh is not initialized.");
- }
-
+ check_initiated(); // check to see if the mesh is not initiated
return rg_xnum;
}
int gctl::regular_grid::get_ydim() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::regular_grid] The mesh is not initialized.");
- }
-
+ check_initiated(); // check to see if the mesh is not initiated
return rg_ynum;
}
double gctl::regular_grid::get_xmin() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::regular_grid] The mesh is not initialized.");
- }
-
+ check_initiated(); // check to see if the mesh is not initiated
return rg_xmin;
}
double gctl::regular_grid::get_ymin() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::regular_grid] The mesh is not initialized.");
- }
-
+ check_initiated(); // check to see if the mesh is not initiated
return rg_ymin;
}
double gctl::regular_grid::get_dx() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::regular_grid] The mesh is not initialized.");
- }
-
+ check_initiated(); // check to see if the mesh is not initiated
return rg_dx;
}
double gctl::regular_grid::get_dy() const
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::regular_grid] The mesh is not initialized.");
- }
-
+ check_initiated(); // check to see if the mesh is not initiated
return rg_dy;
}
@@ -309,7 +278,7 @@ void gctl::regular_grid::load_netcdf_grid(std::string filename, mesh_data_type_e
gctl::array in_arr_single;
// 如果未初始化 则初始化
- if (!initialized)
+ if (!initialized_)
{
// read a data array
read_netcdf_axis(filename, in_x, xname);
@@ -348,7 +317,7 @@ void gctl::regular_grid::load_netcdf_grid(std::string filename, mesh_data_type_e
double dx = (xmax - xmin)/(xnum - 1);
double dy = (ymax - ymin)/(ynum - 1);
- meshdata *data_ptr;
+ meshdata new_data;
if (d_type == NodeData)
{
init(filename, "Imported from a .nc file.", xnum, ynum, xmin, ymin, dx, dy);
@@ -356,8 +325,14 @@ void gctl::regular_grid::load_netcdf_grid(std::string filename, mesh_data_type_e
{
if (!saved(in_name[i]))
{
- data_ptr = meshdata_scalar::create(in_name[i], NodeData, xnum*ynum, true, 0.0);
- saved_data.push_back(data_ptr);
+ new_data.clear();
+ new_data.create(NodeData, Scalar, node_num_, in_name[i], true, GCTL_BDL_MAX);
+ for (size_t j = 0; j < node_num_; j++)
+ {
+ new_data.datval_[i] = in_arr[i][j];
+ }
+
+ datalist_.push_back(new_data);
}
else throw std::runtime_error("[gctl::regular_grid] Duplicated data names.");
}
@@ -369,25 +344,20 @@ void gctl::regular_grid::load_netcdf_grid(std::string filename, mesh_data_type_e
{
if (!saved(in_name[i]))
{
- data_ptr = meshdata_scalar::create(in_name[i], ElemData, xnum*ynum, true, 0.0);
- saved_data.push_back(data_ptr);
+ new_data.clear();
+ new_data.create(ElemData, Scalar, ele_num_, in_name[i], true, GCTL_BDL_MAX);
+ for (size_t j = 0; j < ele_num_; j++)
+ {
+ new_data.datval_[i] = in_arr[i][j];
+ }
+
+ datalist_.push_back(new_data);
}
else throw std::runtime_error("[gctl::regular_grid] Duplicated data names.");
}
}
- // get data pointer
- gctl::array *val_ptr;
- for (size_t r = 0; r < in_arr.row_size(); r++)
- {
- val_ptr = (gctl::array*) get_datval(in_name[r]);
- for (int i = 0; i < val_ptr->size(); i++)
- {
- val_ptr->at(i) = in_arr[r][i];
- }
- }
-
- initialized = true;
+ initialized_ = true;
}
else
{
@@ -405,52 +375,43 @@ void gctl::regular_grid::load_netcdf_grid(std::string filename, mesh_data_type_e
}
}
- meshdata *data_ptr;
+ meshdata new_data;
if (d_type == NodeData)
{
- if (in_arr.col_size() != rg_xnum*rg_ynum)
- {
- throw std::runtime_error("[gctl::regular_grid] Incompatible input data size.");
- }
-
for (int i = 0; i < in_name.size(); i++)
{
if (!saved(in_name[i]))
{
- data_ptr = meshdata_scalar::create(in_name[i], d_type, rg_xnum*rg_ynum, true, 0.0);
- saved_data.push_back(data_ptr);
+ new_data.clear();
+ new_data.create(NodeData, Scalar, node_num_, in_name[i], true, GCTL_BDL_MAX);
+ for (size_t j = 0; j < node_num_; j++)
+ {
+ new_data.datval_[i] = in_arr[i][j];
+ }
+
+ datalist_.push_back(new_data);
}
else throw std::runtime_error("[gctl::regular_grid] Duplicated data names.");
}
}
else if (d_type == ElemData)
{
- if (in_arr.col_size() != (rg_xnum-1)*(rg_ynum-1))
- {
- throw std::runtime_error("[gctl::regular_grid] Incompatible input data size.");
- }
-
for (int i = 0; i < in_name.size(); i++)
{
if (!saved(in_name[i]))
{
- data_ptr = meshdata_scalar::create(in_name[i], d_type, (rg_xnum-1)*(rg_ynum-1), true, 0.0);
- saved_data.push_back(data_ptr);
+ new_data.clear();
+ new_data.create(ElemData, Scalar, ele_num_, in_name[i], true, GCTL_BDL_MAX);
+ for (size_t j = 0; j < ele_num_; j++)
+ {
+ new_data.datval_[i] = in_arr[i][j];
+ }
+
+ datalist_.push_back(new_data);
}
else throw std::runtime_error("[gctl::regular_grid] Duplicated data names.");
}
}
-
- // get data pointer
- gctl::array *val_ptr;
- for (size_t r = 0; r < in_arr.row_size(); r++)
- {
- val_ptr = (gctl::array*) get_datval(in_name[r]);
- for (int i = 0; i < val_ptr->size(); i++)
- {
- val_ptr->at(i) = in_arr[r][i];
- }
- }
}
return;
}
@@ -458,82 +419,70 @@ void gctl::regular_grid::load_netcdf_grid(std::string filename, mesh_data_type_e
void gctl::regular_grid::save_netcdf_grid(std::string filename, mesh_data_type_e d_type,
std::string xname, std::string yname)
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::regular_grid] The mesh is not initialized.");
- }
-
- meshdata *curr_data = nullptr;
+ check_initiated(); // check to see if the mesh is not initiated
bool if_append = false;
- for (iter = saved_data.begin(); iter != saved_data.end(); ++iter)
+ meshdata curr_data;
+ for (size_t i = 0; i < datalist_.size(); i++)
{
- curr_data = *iter;
- if (curr_data->get_dattype() == d_type && d_type == NodeData &&
- curr_data->get_valtype() == Scalar && curr_data->get_output())
+ curr_data = datalist_[i];
+ if (curr_data.loctype_ == d_type && d_type == NodeData &&
+ curr_data.valtype_ == Scalar && curr_data.output_ok_)
{
- array* data_ptr = (array*)curr_data->get_datval_ptr();
-
if (!if_append)
{
- gctl::save_netcdf_grid(filename, *data_ptr, rg_xnum, rg_ynum, rg_xmin,
- rg_dx, rg_ymin, rg_dy, xname, yname, curr_data->get_datname());
+ gctl::save_netcdf_grid(filename, curr_data.datval_, rg_xnum, rg_ynum, rg_xmin,
+ rg_dx, rg_ymin, rg_dy, xname, yname, curr_data.name_);
if_append = true;
}
else
{
- gctl::append_netcdf_grid(filename, *data_ptr, xname, yname, curr_data->get_datname());
+ gctl::append_netcdf_grid(filename, curr_data.datval_, xname, yname, curr_data.name_);
}
}
- else if (curr_data->get_dattype() == d_type && d_type == ElemData &&
- curr_data->get_valtype() == Scalar && curr_data->get_output())
+ else if (curr_data.loctype_ == d_type && d_type == ElemData &&
+ curr_data.valtype_ == Scalar && curr_data.output_ok_)
{
- array* data_ptr = (array*)curr_data->get_datval_ptr();
-
if (!if_append)
{
- gctl::save_netcdf_grid(filename, *data_ptr, rg_xnum-1, rg_ynum-1, rg_xmin+0.5*rg_dx,
- rg_dx, rg_ymin+0.5*rg_dy, rg_dy, xname, yname, curr_data->get_datname());
+ gctl::save_netcdf_grid(filename, curr_data.datval_, rg_xnum-1, rg_ynum-1, rg_xmin+0.5*rg_dx,
+ rg_dx, rg_ymin+0.5*rg_dy, rg_dy, xname, yname, curr_data.name_);
if_append = true;
}
else
{
- gctl::append_netcdf_grid(filename, *data_ptr, xname, yname, curr_data->get_datname());
+ gctl::append_netcdf_grid(filename, curr_data.datval_, xname, yname, curr_data.name_);
}
}
}
-
return;
}
void gctl::regular_grid::save_netcdf_grid(std::string filename, std::string datname,
std::string xname, std::string yname)
{
- meshdata *curr_data = get_data(datname);
+ meshdata curr_data = get_data(datname);
- if (!curr_data->get_output())
+ if (!curr_data.output_ok_)
{
throw std::runtime_error("[gctl::regular_grid] Output of the data is disabled.");
}
- if (curr_data->get_valtype() != Scalar)
+ if (curr_data.valtype_ != Scalar)
{
throw std::runtime_error("[gctl::regular_grid] The output data type can't be saved to a netCDF file.");
}
- if (curr_data->get_valtype() == Scalar && curr_data->get_dattype() == NodeData)
+ if (curr_data.valtype_ == Scalar && curr_data.loctype_ == NodeData)
{
- array* data_ptr = (array*)curr_data->get_datval_ptr();
- gctl::save_netcdf_grid(filename, *data_ptr, rg_xnum, rg_ynum, rg_xmin,
- rg_dx, rg_ymin, rg_dy, xname, yname, curr_data->get_datname());
+ gctl::save_netcdf_grid(filename, curr_data.datval_, rg_xnum, rg_ynum, rg_xmin,
+ rg_dx, rg_ymin, rg_dy, xname, yname, curr_data.name_);
}
- else if (curr_data->get_valtype() == Scalar && curr_data->get_dattype() == ElemData)
+ else if (curr_data.valtype_ == Scalar && curr_data.loctype_ == ElemData)
{
- array* data_ptr = (array*)curr_data->get_datval_ptr();
- gctl::save_netcdf_grid(filename, *data_ptr, rg_xnum-1, rg_ynum-1, rg_xmin+0.5*rg_dx,
- rg_dx, rg_ymin+0.5*rg_dy, rg_dy, xname, yname, curr_data->get_datname());
+ gctl::save_netcdf_grid(filename, curr_data.datval_, rg_xnum-1, rg_ynum-1, rg_xmin+0.5*rg_dx,
+ rg_dx, rg_ymin+0.5*rg_dy, rg_dy, xname, yname, curr_data.name_);
}
-
return;
}
@@ -541,13 +490,12 @@ void gctl::regular_grid::save_netcdf_grid(std::string filename, std::string datn
void gctl::regular_grid::load_surfer_grid(std::string filename, std::string datname, mesh_data_type_e d_type, surfer_file_type_e grid_type)
{
- gctl::array in_arr;
-
int xnum, ynum;
double xmin, xmax, ymin, ymax, zmin, zmax, dx, dy, blank_val;
+ gctl::array in_arr;
// 如果微初始化 则初始化
- if (!initialized)
+ if (!initialized_)
{
if (grid_type == Surfer6Text)
{
@@ -570,28 +518,28 @@ void gctl::regular_grid::load_surfer_grid(std::string filename, std::string datn
gctl::read_surfer7_grid(filename, in_arr, xnum, ynum, xmin, ymin, dx, dy, zmin, zmax, blank_val);
}
- meshdata *data_ptr;
+ meshdata curr_data;
if (d_type == NodeData)
{
init(filename, "Imported from a surfer grid.", xnum, ynum, xmin, ymin, dx, dy);
- data_ptr = meshdata_scalar::create(datname, NodeData, xnum*ynum, true, 0.0);
+ curr_data.create(NodeData, Scalar, node_num_, datname, true, GCTL_BDL_MAX);
+ for (size_t i = 0; i < node_num_; i++)
+ {
+ curr_data.datval_[i] = in_arr[i];
+ }
}
else if (d_type == ElemData)
{
init(filename, "Imported from a surfer grid.", xnum+1, ynum+1, xmin-0.5*dx, ymin-0.5*dy, dx, dy);
- data_ptr = meshdata_scalar::create(datname, ElemData, xnum*ynum, true, 0.0);
+ curr_data.create(ElemData, Scalar, ele_num_, datname, true, GCTL_BDL_MAX);
+ for (size_t i = 0; i < ele_num_; i++)
+ {
+ curr_data.datval_[i] = in_arr[i];
+ }
}
- saved_data.push_back(data_ptr);
-
- // get data pointer
- gctl::array *val_ptr = (gctl::array*) data_ptr->get_datval_ptr();
- for (int i = 0; i < val_ptr->size(); i++)
- {
- val_ptr->at(i) = in_arr[i];
- }
-
- initialized = true;
+ datalist_.push_back(curr_data);
+ initialized_ = true;
}
else
{
@@ -610,7 +558,7 @@ void gctl::regular_grid::load_surfer_grid(std::string filename, std::string datn
gctl::read_surfer7_grid(filename, in_arr, xnum, ynum, xmin, ymin, dx, dy, zmin, zmax, blank_val);
}
- meshdata *data_ptr;
+ meshdata curr_data;
if (d_type == NodeData)
{
if (in_arr.size() != rg_xnum*rg_ynum)
@@ -618,7 +566,11 @@ void gctl::regular_grid::load_surfer_grid(std::string filename, std::string datn
throw std::runtime_error("[gctl::regular_grid] Incompatible input data size.");
}
- data_ptr = meshdata_scalar::create(datname, d_type, rg_xnum*rg_ynum, true, 0.0);
+ curr_data.create(NodeData, Scalar, node_num_, datname, true, GCTL_BDL_MAX);
+ for (size_t i = 0; i < node_num_; i++)
+ {
+ curr_data.datval_[i] = in_arr[i];
+ }
}
else if (d_type == ElemData)
{
@@ -627,79 +579,74 @@ void gctl::regular_grid::load_surfer_grid(std::string filename, std::string datn
throw std::runtime_error("[gctl::regular_grid] Incompatible input data size.");
}
- data_ptr = meshdata_scalar::create(datname, d_type, (rg_xnum-1)*(rg_ynum-1), true, 0.0);
+ curr_data.create(ElemData, Scalar, ele_num_, datname, true, GCTL_BDL_MAX);
+ for (size_t i = 0; i < ele_num_; i++)
+ {
+ curr_data.datval_[i] = in_arr[i];
+ }
}
- saved_data.push_back(data_ptr);
-
- // get data pointer
- gctl::array *val_ptr = (gctl::array*) data_ptr->get_datval_ptr();
- for (int i = 0; i < val_ptr->size(); i++)
- {
- val_ptr->at(i) = in_arr[i];
- }
+ datalist_.push_back(curr_data);
}
return;
}
void gctl::regular_grid::save_surfer_grid(std::string filename, std::string datname, surfer_file_type_e grid_type)
{
- meshdata *curr_data = curr_data = get_data(datname);
+ meshdata curr_data = get_data(datname);
- if (!curr_data->get_output())
+ if (!curr_data.output_ok_)
{
throw std::runtime_error("[gctl::regular_grid] Output of the data is disabled.");
}
- if (curr_data->get_valtype() != Scalar)
+ if (curr_data.valtype_ != Scalar)
{
throw std::runtime_error("[gctl::regular_grid] The output data type can't be saved to a Surfer file.");
}
- gctl::array *data_ptr = (gctl::array*) curr_data->get_datval_ptr();
- if (curr_data->get_dattype() == NodeData)
+ if (curr_data.loctype_ == NodeData)
{
if (grid_type == Surfer6Text)
{
- gctl::save_surfer6_grid(filename, *data_ptr, rg_xnum, rg_ynum,
+ gctl::save_surfer6_grid(filename, curr_data.datval_, rg_xnum, rg_ynum,
rg_xmin, rg_xmin+(rg_xnum-1)*rg_dx, rg_ymin, rg_ymin+(rg_ynum-1)*rg_dy,
NAN, NAN, gctl::Surfer6Text);
}
else if (grid_type == Surfer6Binary)
{
- gctl::save_surfer6_grid(filename, *data_ptr, rg_xnum, rg_ynum,
+ gctl::save_surfer6_grid(filename, curr_data.datval_, rg_xnum, rg_ynum,
rg_xmin, rg_xmin+(rg_xnum-1)*rg_dx, rg_ymin, rg_ymin+(rg_ynum-1)*rg_dy,
NAN, NAN, gctl::Surfer6Binary);
}
else if (grid_type == Surfer7Grid)
{
- gctl::save_surfer6_grid(filename, *data_ptr, rg_xnum, rg_ynum,
+ gctl::save_surfer6_grid(filename, curr_data.datval_, rg_xnum, rg_ynum,
rg_xmin, rg_ymin, rg_dx, rg_dy);
}
}
- else if (curr_data->get_dattype() == ElemData)
+ else if (curr_data.loctype_ == ElemData)
{
if (grid_type == Surfer6Text)
{
- gctl::save_surfer6_grid(filename, *data_ptr, rg_xnum-1, rg_ynum-1,
+ gctl::save_surfer6_grid(filename, curr_data.datval_, rg_xnum-1, rg_ynum-1,
rg_xmin+0.5*rg_dx, rg_xmin+0.5*rg_dx+(rg_xnum-2)*rg_dx,
rg_ymin+0.5*rg_dy, rg_ymin+0.5*rg_dy+(rg_ynum-2)*rg_dy,
NAN, NAN, gctl::Surfer6Text);
}
else if (grid_type == Surfer6Binary)
{
- gctl::save_surfer6_grid(filename, *data_ptr, rg_xnum-1, rg_ynum-1,
+ gctl::save_surfer6_grid(filename, curr_data.datval_, rg_xnum-1, rg_ynum-1,
rg_xmin+0.5*rg_dx, rg_xmin+0.5*rg_dx+(rg_xnum-2)*rg_dx,
rg_ymin+0.5*rg_dy, rg_ymin+0.5*rg_dy+(rg_ynum-2)*rg_dy,
NAN, NAN, gctl::Surfer6Binary);
}
else if (grid_type == Surfer7Grid)
{
- gctl::save_surfer6_grid(filename, *data_ptr, rg_xnum-1, rg_ynum-1,
+ gctl::save_surfer6_grid(filename, curr_data.datval_, rg_xnum-1, rg_ynum-1,
rg_xmin+0.5*rg_dx, rg_ymin+0.5*rg_dy, rg_dx, rg_dy);
}
}
-
return;
}
@@ -712,40 +659,32 @@ void gctl::regular_grid::save_gmsh(std::string filename, index_packed_e packed)
return;
}
-void gctl::regular_grid::save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed)
+void gctl::regular_grid::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;
}
void gctl::regular_grid::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;
}
void gctl::regular_grid::save_text(std::string filename, const array &datname)
{
mesh_data_type_e d_type;
- meshdata *dat_ptr = nullptr;
-
- dat_ptr = get_data(datname[0]);
- d_type = dat_ptr->get_dattype();
+ meshdata curr_data = get_data(datname[0]);
+ d_type = curr_data.loctype_;
for (size_t i = 1; i < datname.size(); i++)
{
- dat_ptr = get_data(datname[i]);
- if (d_type != dat_ptr->get_dattype())
+ curr_data = get_data(datname[i]);
+ if (d_type != curr_data.loctype_)
{
- throw std::runtime_error("[gctl::regular_grid] multiple data location types occured.");
+ throw std::runtime_error("[gctl::regular_grid] multiple data location types found.");
}
}
- array*> datval_ptr(datname.size(), nullptr);
- for (size_t i = 0; i < datname.size(); i++)
- {
- datval_ptr[i] = (array*) get_datval(datname[i]);
- }
-
std::ofstream ofile;
open_outfile(ofile, filename, ".txt");
@@ -756,26 +695,28 @@ void gctl::regular_grid::save_text(std::string filename, const arrayget_dattype() == NodeData)
+ if (curr_data.loctype_ == NodeData)
{
- for (size_t i = 0; i < node_num; i++)
+ for (size_t i = 0; i < node_num_; i++)
{
ofile << nodes[i].x << " " << nodes[i].y;
for (size_t n = 0; n < datname.size(); n++)
{
- ofile << " " << datval_ptr[n]->at(i);
+ curr_data = get_data(datname[n]);
+ ofile << " " << curr_data.datval_[i];
}
ofile << "\n";
}
}
else
{
- for (size_t i = 0; i < ele_num; i++)
+ for (size_t i = 0; i < ele_num_; i++)
{
ofile << 0.5*(elements[i].dl->x + elements[i].ur->x) << " " << 0.5*(elements[i].dl->y + elements[i].ur->y);
for (size_t n = 0; n < datname.size(); n++)
{
- ofile << " " << datval_ptr[n]->at(i);
+ curr_data = get_data(datname[n]);
+ ofile << " " << curr_data.datval_[i];
}
ofile << "\n";
}
@@ -788,21 +729,15 @@ void gctl::regular_grid::save_text(std::string filename, const array &in_posi, const array &in_val,
double search_xlen, double search_ylen, double search_deg, std::string datname, mesh_data_type_e d_type)
{
- if (!initialized)
- {
- throw std::runtime_error("[gctl::regular_grid] The mesh is not initialized.");
- }
-
- gctl::array grid_points;
+ check_initiated(); // 检查网格是否已经初始化
if (in_posi.size() != in_val.size())
{
throw std::runtime_error("[gctl::regular_grid] Invalid sizes of the input data cloud.");
}
- // create a new data object
- meshdata *data_ptr = add_data(datname, d_type, true, Scalar);
array *inte_data = nullptr;
+ gctl::array