diff --git a/lib/geometry/point2c.h b/lib/geometry/point2c.h index a58b291..341461e 100644 --- a/lib/geometry/point2c.h +++ b/lib/geometry/point2c.h @@ -531,25 +531,20 @@ namespace gctl * @brief 生成一维网格节点数组,其中每一个点都是一个二维坐标点。 * * @param out_ps 返回网格节点数组 - * @param[in] xmin x最小值 - * @param[in] xmax x最大值 + * @param[in] x_st x起始值 + * @param[in] x_ed x终止值 * @param[in] dx x间隔 * @param[in] ele 高程值 */ template - void grid_points_1d(array> &out_ps, T xmin, T xmax, T dx, T ele) + void grid_points_1d(array> &out_ps, T x_st, T x_ed, T dx, T ele) { - if (xmin >= xmax || xmin + dx > xmax || dx <= 0) - { - throw std::invalid_argument("[gctl::grid_points_1d] Invalid parameters."); - } - - int xnum = round((xmax - xmin)/dx) + 1; + int xnum = round(std::abs((x_ed - x_st)/dx)) + 1; out_ps.resize(xnum); for (int i = 0; i < xnum; i++) { - out_ps[i].x = xmin + dx*i; + out_ps[i].x = x_st + dx*i; out_ps[i].y = ele; } return; diff --git a/lib/geometry/point2p.h b/lib/geometry/point2p.h index 064aef2..9664244 100644 --- a/lib/geometry/point2p.h +++ b/lib/geometry/point2p.h @@ -375,6 +375,20 @@ namespace gctl } return false; } + + template + void grid_points_1d(array> &obsp, T deg_st, T deg_ed, T ddeg, T rad) + { + int m = round(std::abs((deg_st - deg_ed)/ddeg)) + 1; + + obsp.resize(m); + for (size_t i = 0; i < m; i++) + { + obsp[i].arc = arc(deg_st + i*ddeg); + obsp[i].rad = rad; + } + return; + } } #endif // _GCTL_POINT2P_H \ No newline at end of file diff --git a/lib/io/dsv_io.cpp b/lib/io/dsv_io.cpp index f587243..4bd91d2 100644 --- a/lib/io/dsv_io.cpp +++ b/lib/io/dsv_io.cpp @@ -963,6 +963,29 @@ void gctl::geodsv_io::fill_column_point2dc(const array &data, std::str return; } +void gctl::geodsv_io::fill_column_point2dp(const array &data, int rid, int cid, int p) +{ + if (rid > col_num_ || cid > col_num_ || rid == cid || rid <= 0 || cid <= 0) + { + throw std::runtime_error("[gctl::geodsv_io] Invalid column index."); + } + + std::stringstream ss; + std::string s; + for (size_t i = 1; i <= std::min(row_num_, (int) data.size()); i++) + { + table_[i][rid].value(data[i - 1].rad, p); + table_[i][cid].value(data[i - 1].arc, p); + } + return; +} + +void gctl::geodsv_io::fill_column_point2dp(const array &data, std::string rname, std::string cname, int p) +{ + fill_column_point2dp(data, name_index(rname, false), name_index(cname, false), p); + return; +} + void gctl::geodsv_io::fill_column_point3dc(const array &data, int xid, int yid, int zid, int p) { if (xid > col_num_ || yid > col_num_ || zid > col_num_ || xid == yid || yid == zid || xid == zid @@ -1035,6 +1058,28 @@ void gctl::geodsv_io::get_column_point2dc(array &data, std::string xna return; } +void gctl::geodsv_io::get_column_point2dp(array &data, int rid, int cid) +{ + if (rid > col_num_ || cid > col_num_ || rid == cid || rid <= 0 || cid <= 0) + { + throw std::runtime_error("[gctl::geodsv_io] Invalid column index."); + } + + data.resize(row_num_); + for (size_t i = 1; i <= row_num_; i++) + { + data[i - 1].rad = table_[i][rid].value(); + data[i - 1].arc = table_[i][cid].value(); + } + return; +} + +void gctl::geodsv_io::get_column_point2dp(array &data, std::string rname, std::string cname) +{ + get_column_point2dp(data, name_index(rname, false), name_index(cname, false)); + return; +} + void gctl::geodsv_io::get_column_point3dc(array &data, int xid, int yid, int zid) { if (xid > col_num_ || yid > col_num_ || zid > col_num_ || xid == yid || yid == zid || xid == zid diff --git a/lib/io/dsv_io.h b/lib/io/dsv_io.h index c6f2fba..f8c8d7e 100644 --- a/lib/io/dsv_io.h +++ b/lib/io/dsv_io.h @@ -828,6 +828,26 @@ namespace gctl */ void fill_column_point2dc(const array &data, std::string xname, std::string yname, int p = 6); + /** + * @brief 填充二维坐标列 + * + * @param rid rad坐标列索引 从1开始 + * @param cid arc坐标列索引 从1开始 + * @param data 返回的二维坐标数据 + * @param p 填入的浮点数据有效位数(精度) + */ + void fill_column_point2dp(const array &data, int rid, int cid, int p = 6); + + /** + * @brief 填充二维坐标列 + * + * @param rname rad坐标列名称 + * @param cname arc坐标列名称 + * @param data 返回的二维坐标数据 + * @param p 填入的浮点数据有效位数(精度) + */ + void fill_column_point2dp(const array &data, std::string rname, std::string cname, int p = 6); + /** * @brief 填充三维坐标列 * @@ -890,6 +910,24 @@ namespace gctl */ void get_column_point2dc(array &data, std::string xname, std::string yname); + /** + * @brief 读取二维坐标列 + * + * @param rid rad坐标列索引 从1开始 + * @param cid arc坐标列索引 从1开始 + * @param data 返回的二维坐标数据 + */ + void get_column_point2dp(array &data, int rid, int cid); + + /** + * @brief 读取二维坐标列 + * + * @param rname rad坐标列名称 + * @param cname arc坐标列名称 + * @param data 返回的二维坐标数据 + */ + void get_column_point2dp(array &data, std::string rname, std::string cname); + /** * @brief 读取三维坐标列 * diff --git a/lib/io/gmsh_io.cpp b/lib/io/gmsh_io.cpp index e1b7d7b..fefd4fb 100644 --- a/lib/io/gmsh_io.cpp +++ b/lib/io/gmsh_io.cpp @@ -152,4 +152,15 @@ void gctl::gmshio::save_physical_groups(const array &phy_gr } gmsh_out << "$EndPhysicalNames\n"; return; +} + +int gctl::gmshio::physical_name2tag(const array &phy_groups, std::string name) +{ + for (size_t i = 0; i < phy_groups.size(); i++) + { + if (phy_groups[i].name == name) return phy_groups[i].phys_tag; + } + + throw std::runtime_error("[gctl::gmshio::physical_name2tag] Physical group name not found."); + return -1; } \ No newline at end of file diff --git a/lib/io/gmsh_io.h b/lib/io/gmsh_io.h index 41ba2a7..cb4c7d0 100644 --- a/lib/io/gmsh_io.h +++ b/lib/io/gmsh_io.h @@ -61,6 +61,7 @@ namespace gctl void read_physical_groups(array &phy_groups); void save_physical_groups(const array &phy_groups); + int physical_name2tag(const array &phy_groups, std::string name); template void read_node(array> &out_nodes); template void read_node(array> &out_nodes); diff --git a/lib/maths/mathfunc_t.h b/lib/maths/mathfunc_t.h index c6baae5..040402d 100644 --- a/lib/maths/mathfunc_t.h +++ b/lib/maths/mathfunc_t.h @@ -48,6 +48,12 @@ namespace gctl return deg*GCTL_Pi/180.0; } + template + inline T deg(T arc) + { + return arc*180.0/GCTL_Pi; + } + template inline T sind(T deg) {