This commit is contained in:
2025-05-12 20:05:54 +08:00
parent aa7f5cc6a3
commit 5f4d6267b6
196 changed files with 6707 additions and 583841 deletions

30
src/mesh/CMakeLists.txt Normal file
View File

@@ -0,0 +1,30 @@
# 设置可执行文件的输出地址
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
macro(add_example name switch)
if(${switch})
# 添加可执行程序名称
add_executable(${name} ${name}.cpp)
# 设置安装后的动态库调用地址
set_target_properties(${name} PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
set_target_properties(${name} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
# 链接动态库
target_link_libraries(${name} PRIVATE ${GCTL_LIB})
target_link_libraries(${name} PRIVATE gctl_mesh)
endif()
endmacro()
add_example(mesh_ex1 OFF)
add_example(mesh_ex2 OFF)
add_example(mesh_ex3 OFF)
add_example(mesh_ex4 OFF)
add_example(mesh_ex5 OFF)
add_example(mesh_ex6 OFF)
add_example(mesh_ex7 OFF)
add_example(mesh_ex8 OFF)
add_example(mesh_ex9 OFF)
add_example(mesh_ex10 OFF)
add_example(meshio_ex OFF)
add_example(tri2d_meshio_ex ON)

54
src/mesh/mesh_ex1.cpp Normal file
View File

@@ -0,0 +1,54 @@
/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
* ██║ ██║██║ ██║ ██║
* ╚██████╔╝╚██████╗ ██║ ███████╗
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
*
* GCTL is distributed under a dual licensing scheme. You can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 2
* of the License, or (at your option) any later version. You should have
* received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* If the terms and conditions of the LGPL v.2. would prevent you from using
* the GCTL, please consider the option to obtain a commercial license for a
* fee. These licenses are offered by the GCTL's original author. As a rule,
* licenses are provided "as-is", unlimited in time for a one time fee. Please
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
* to include some description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#include "../lib/mesh.h"
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);
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();
gctl::meshdata data2 = rgd.get_data("data-2");
std::cout << "data name: " << data2.name_ << std::endl;
data2.datval_.show();
gctl::meshdata data3 = rgd.get_data("data-3");
std::cout << "data name: " << data3.name_ << std::endl;
data3.datval_.show();
rgd.diff("data-4", "data-1", "data-3");
rgd.remove_data("data-1");
rgd.show_info();
rgd.save_gmsh_withdata("ex1_out", gctl::OverWrite, gctl::NotPacked);
return 0;
}

37
src/mesh/mesh_ex10.cpp Normal file
View File

@@ -0,0 +1,37 @@
/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
* ██║ ██║██║ ██║ ██║
* ╚██████╔╝╚██████╗ ██║ ███████╗
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
*
* GCTL is distributed under a dual licensing scheme. You can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 2
* of the License, or (at your option) any later version. You should have
* received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* If the terms and conditions of the LGPL v.2. would prevent you from using
* the GCTL, please consider the option to obtain a commercial license for a
* fee. These licenses are offered by the GCTL's original author. As a rule,
* licenses are provided "as-is", unlimited in time for a one time fee. Please
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
* to include some description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#include "../lib/mesh.h"
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(gctl::ElemData, gctl::Scalar, "data-1", 2.5);
rm_3ds.save_gmsh_withdata("mesh_sample10",gctl::OverWrite, gctl::NotPacked);
return 0;
}

62
src/mesh/mesh_ex2.cpp Normal file
View File

@@ -0,0 +1,62 @@
/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
* ██║ ██║██║ ██║ ██║
* ╚██████╔╝╚██████╗ ██║ ███████╗
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
*
* GCTL is distributed under a dual licensing scheme. You can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 2
* of the License, or (at your option) any later version. You should have
* received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* If the terms and conditions of the LGPL v.2. would prevent you from using
* the GCTL, please consider the option to obtain a commercial license for a
* fee. These licenses are offered by the GCTL's original author. As a rule,
* licenses are provided "as-is", unlimited in time for a one time fee. Please
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
* to include some description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#include "../lib/mesh.h"
int main(int argc, char *argv[])
{
std::string dname = "example";
std::string dname2= "another-example";
gctl::regular_grid rgd;
rgd.init("grid-1", "null", 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++)
{
for (int i = 0; i < rgd.get_xdim(); i++)
{
data.datval_[i + j*rgd.get_xdim()] = i;
}
}
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++)
{
data2.datval_[i + j*rgd.get_xdim()] = j;
}
}
// disable the output of data object named dname2
//data2.output_ok_ = false;
rgd.show_info();
rgd.save_netcdf_grid("sample2-out", gctl::NodeData);
return 0;
}

82
src/mesh/mesh_ex3.cpp Normal file
View File

@@ -0,0 +1,82 @@
/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
* ██║ ██║██║ ██║ ██║
* ╚██████╔╝╚██████╗ ██║ ███████╗
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
*
* GCTL is distributed under a dual licensing scheme. You can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 2
* of the License, or (at your option) any later version. You should have
* received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* If the terms and conditions of the LGPL v.2. would prevent you from using
* the GCTL, please consider the option to obtain a commercial license for a
* fee. These licenses are offered by the GCTL's original author. As a rule,
* licenses are provided "as-is", unlimited in time for a one time fee. Please
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
* to include some description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#include "../lib/mesh.h"
int main(int argc, char *argv[]) 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++)
{
for (int i = 0; i < rgd.get_xdim(); i++)
{
data.datval_[i + j*rgd.get_xdim()] = i;
}
}
gctl::meshdata &data2 = rgd.add_data(gctl::ElemData, gctl::Scalar, dname2, 0.0);
for (int j = 0; j < rgd.get_ydim()-1; j++)
{
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);
}

60
src/mesh/mesh_ex4.cpp Normal file
View File

@@ -0,0 +1,60 @@
/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
* ██║ ██║██║ ██║ ██║
* ╚██████╔╝╚██████╗ ██║ ███████╗
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
*
* GCTL is distributed under a dual licensing scheme. You can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 2
* of the License, or (at your option) any later version. You should have
* received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* If the terms and conditions of the LGPL v.2. would prevent you from using
* the GCTL, please consider the option to obtain a commercial license for a
* fee. These licenses are offered by the GCTL's original author. As a rule,
* licenses are provided "as-is", unlimited in time for a one time fee. Please
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
* to include some description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#include "../lib/mesh.h"
int main(int argc, char *argv[]) try
{
std::string dname = "vector-data";
gctl::regular_grid rgd;
rgd.init("grid-example", "this grid can store vectors. Yeah!", 15, 10, 0.0, 0.0, 1.0, 1.0);
gctl::array<gctl::point3dc> init_data(rgd.get_ydim()*rgd.get_xdim());
for (int j = 0; j < rgd.get_ydim(); j++)
{
for (int i = 0; i < rgd.get_xdim(); i++)
{
init_data[i + j*rgd.get_xdim()].x = i;
init_data[i + j*rgd.get_xdim()].y = j;
init_data[i + j*rgd.get_xdim()].z = i+j;
}
}
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);
}

43
src/mesh/mesh_ex5.cpp Normal file
View File

@@ -0,0 +1,43 @@
/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
* ██║ ██║██║ ██║ ██║
* ╚██████╔╝╚██████╗ ██║ ███████╗
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
*
* GCTL is distributed under a dual licensing scheme. You can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 2
* of the License, or (at your option) any later version. You should have
* received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* If the terms and conditions of the LGPL v.2. would prevent you from using
* the GCTL, please consider the option to obtain a commercial license for a
* fee. These licenses are offered by the GCTL's original author. As a rule,
* licenses are provided "as-is", unlimited in time for a one time fee. Please
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
* to include some description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#include "../lib/mesh.h"
int main(int argc, char *argv[]) try
{
gctl::regular_grid rgd;
rgd.load_netcdf_grid("data/out/sample3-out1", gctl::ElemData, "x", "y");
rgd.show_info();
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);
}

66
src/mesh/mesh_ex6.cpp Normal file
View File

@@ -0,0 +1,66 @@
/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
* ██║ ██║██║ ██║ ██║
* ╚██████╔╝╚██████╗ ██║ ███████╗
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
*
* GCTL is distributed under a dual licensing scheme. You can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 2
* of the License, or (at your option) any later version. You should have
* received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* If the terms and conditions of the LGPL v.2. would prevent you from using
* the GCTL, please consider the option to obtain a commercial license for a
* fee. These licenses are offered by the GCTL's original author. As a rule,
* licenses are provided "as-is", unlimited in time for a one time fee. Please
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
* to include some description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#include "../lib/mesh.h"
int main(int argc, char *argv[]) try
{
gctl::regular_mesh_2d rg_mesh;
rg_mesh.init("mesh-example", "this mesh can store vectors. Yeah!", 15, 10, 0.5, 0.5, 1.0, 1.0);
int ybnum = rg_mesh.get_ybnum();
int xbnum = rg_mesh.get_xbnum();
gctl::array<gctl::point3dc> init_data(ybnum*xbnum);
for (int j = 0; j < ybnum; j++)
{
for (int i = 0; i < xbnum; i++)
{
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(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++)
{
for (int i = 0; i < xbnum+1; i++)
{
data2.datval_[i + j*(xbnum+1)] = i+j;
}
}
rg_mesh.save_gmsh_withdata("sample6-out", gctl::OverWrite);
return 0;
}
catch(std::exception &e)
{
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}

57
src/mesh/mesh_ex7.cpp Normal file
View File

@@ -0,0 +1,57 @@
/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
* ██║ ██║██║ ██║ ██║
* ╚██████╔╝╚██████╗ ██║ ███████╗
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
*
* GCTL is distributed under a dual licensing scheme. You can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 2
* of the License, or (at your option) any later version. You should have
* received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* If the terms and conditions of the LGPL v.2. would prevent you from using
* the GCTL, please consider the option to obtain a commercial license for a
* fee. These licenses are offered by the GCTL's original author. As a rule,
* licenses are provided "as-is", unlimited in time for a one time fee. Please
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
* to include some description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#include "../lib/mesh.h"
int main(int argc, char *argv[]) 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++)
{
for (int j = 0; j < ybnum+1; j++)
{
for (int i = 0; i < xbnum+1; i++)
{
data.datval_[i + j*(xbnum+1) + k*(xbnum+1)*(ybnum+1)] = i+j+k;
}
}
}
rg_mesh.save_gmsh_withdata("sample7-out", "double-data", gctl::OverWrite);
return 0;
}
catch(std::exception &e)
{
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}

47
src/mesh/mesh_ex8.cpp Normal file
View File

@@ -0,0 +1,47 @@
/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
* ██║ ██║██║ ██║ ██║
* ╚██████╔╝╚██████╗ ██║ ███████╗
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
*
* GCTL is distributed under a dual licensing scheme. You can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 2
* of the License, or (at your option) any later version. You should have
* received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* If the terms and conditions of the LGPL v.2. would prevent you from using
* the GCTL, please consider the option to obtain a commercial license for a
* fee. These licenses are offered by the GCTL's original author. As a rule,
* licenses are provided "as-is", unlimited in time for a one time fee. Please
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
* to include some description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#include "../lib/mesh.h"
int main(int argc, char *argv[]) try
{
gctl::triangle2d_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_withdata("sample8-out", "example", gctl::OverWrite, gctl::NotPacked);
t_mesh.save_binary("sample8-out");
gctl::triangle2d_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);
}

65
src/mesh/mesh_ex9.cpp Normal file
View File

@@ -0,0 +1,65 @@
/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
* ██║ ██║██║ ██║ ██║
* ╚██████╔╝╚██████╗ ██║ ███████╗
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
*
* GCTL is distributed under a dual licensing scheme. You can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 2
* of the License, or (at your option) any later version. You should have
* received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* If the terms and conditions of the LGPL v.2. would prevent you from using
* the GCTL, please consider the option to obtain a commercial license for a
* fee. These licenses are offered by the GCTL's original author. As a rule,
* licenses are provided "as-is", unlimited in time for a one time fee. Please
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
* to include some description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#include "../lib/mesh.h"
int main(int argc, char *argv[]) try
{
gctl::array<double> xs(15);
for (int i = 0; i < 15; i++)
{
xs[i] = i+1;
}
gctl::array<double> ys(10);
for (int i = 0; i < 10; i++)
{
ys[i] = i+1;
}
gctl::linear_mesh_2d l2d_mesh;
l2d_mesh.init("mesh-example", "This is a linear mesh", 0.5, 0.5, xs, ys);
int ybnum = l2d_mesh.get_ybnum();
int xbnum = l2d_mesh.get_xbnum();
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_withdata("sample9-out", gctl::OverWrite, gctl::NotPacked);
return 0;
}
catch(std::exception &e)
{
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}

109
src/mesh/meshio_ex.cpp Normal file
View File

@@ -0,0 +1,109 @@
/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
* ██║ ██║██║ ██║ ██║
* ╚██████╔╝╚██████╗ ██║ ███████╗
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
*
* GCTL is distributed under a dual licensing scheme. You can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 2
* of the License, or (at your option) any later version. You should have
* received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* If the terms and conditions of the LGPL v.2. would prevent you from using
* the GCTL, please consider the option to obtain a commercial license for a
* fee. These licenses are offered by the GCTL's original author. As a rule,
* licenses are provided "as-is", unlimited in time for a one time fee. Please
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
* to include some description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#include "../lib/mesh/mesh_io.h"
using namespace gctl;
int main(int argc, char const *argv[]) try
{
mesh_io mshio;
mshio.read_gmsh_v2_ascii("tmp/test");
mshio.info();
array<vertex3dc> nodes;
array<triangle> tris;
mshio.select_elements("Bz (pT)", NodeData);
mshio.export_selected_to(tris, nodes);
//meshio_data &d = mshio.get_data("Bz (pT)", NodeData);
//array<double> dat = d.val;
array<double> dat1 = mshio.get_selected_data("Bx (pT)", NodeData);
array<double> dat2 = mshio.get_selected_data("By (pT)", NodeData);
array<double> dat3 = mshio.get_selected_data("Bz (pT)", NodeData);
mesh_io mshio2;
mshio2.import_from(tris, nodes);
mshio2.add_data("Bx (pT)", dat1, NodeData, OverWrite);
mshio2.add_data("By (pT)", dat2, NodeData, OverWrite);
mshio2.add_data("Bz (pT)", dat3, NodeData, OverWrite);
mshio2.save_gmsh_v2_ascii("tmp");
mshio2.info();
/*
mshio.read_tetgen_ascii("tmp/ex1.1");
mshio.edit_group(Disable, GeometryTag, 5);
mshio.edit_group(GeometryTag, 1, PhysicalTag, 1);
mshio.edit_group(GeometryTag, 2, PhysicalTag, 2);
mshio.edit_group(GeometryTag, 3, PhysicalTag, 3);
mshio.edit_group(GeometryTag, 4, PhysicalTag, 4);
mshio.edit_group(GeometryTag, 1, "Boundary");
mshio.edit_group(GeometryTag, 2, "Body1");
mshio.edit_group(GeometryTag, 3, "Body2");
mshio.edit_group(GeometryTag, 4, "Body3");
mshio.save_gmsh_v2_ascii("tmp/ex1.1");
*/
/*
mshio.read_gmsh_v2_ascii("tmp/ex1.1");
mshio.convert_tags_to_data(GeometryTag);
array<double> body_val(mshio.element_size("Body2"), 2.0);
mshio.add_element_data("BodyValue", "Body2", body_val);
array<double> body_val2(mshio.element_size("Body3"), 1.0);
mshio.add_element_data("BodyValue", "Body3", body_val2);
mshio.save_gmsh_v2_ascii("tmp/ex1.2");
//mshio.save_vtk_legacy_ascii("tmp/ex1.1");
mshio.info();
const array<vertex3dc> &nodes = mshio.get_nodes();
array<tetrahedron> body2_tets;
mshio.export_elements_to(body2_tets, "All");
gmshio gio;
gio.init_file("tmp.msh", Output);
gio.set_packed(NotPacked, Output);
gio.save_mesh(body2_tets, nodes);
*/
/*
mshio.read_gmsh_v2_ascii("tmp/wjb.1");
mshio.edit_group(Disable);
mshio.edit_group(Enable, GeometryTag, 3);
mshio.edit_group(Enable, GeometryTag, 8);
mshio.edit_group(Enable, GeometryTag, 9);
mshio.save_gmsh_v2_ascii("tmp/wjb.2");
*/
return 0;
}
catch(std::exception &e)
{
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}

View File

@@ -0,0 +1,55 @@
/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
* ██║ ██║██║ ██║ ██║
* ╚██████╔╝╚██████╗ ██║ ███████╗
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
*
* GCTL is distributed under a dual licensing scheme. You can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 2
* of the License, or (at your option) any later version. You should have
* received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* If the terms and conditions of the LGPL v.2. would prevent you from using
* the GCTL, please consider the option to obtain a commercial license for a
* fee. These licenses are offered by the GCTL's original author. As a rule,
* licenses are provided "as-is", unlimited in time for a one time fee. Please
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
* to include some description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#include "../lib/mesh/tri2d_mesh.h"
using namespace gctl;
int main(int argc, char const *argv[]) try
{
mesh_io mshio;
mshio.read_gmsh_v2_ascii("tmp/tri2d");
mshio.info();
array<vertex2dc> nodes;
array<triangle2d> tris;
mshio.select_elements(_3NodeTriangle);
mshio.export_selected_to(tris, nodes);
_1d_array data = mshio.get_selected_data("Model slowness (s/km)", ElemData);
triangle2d_mesh tri2dmesh;
tri2dmesh.init("Test", "This is a test.", nodes, tris);
tri2dmesh.add_data(ElemData, "Test Data", data);
tri2dmesh.show_info();
tri2dmesh.save_gmsh_withdata("tri2d_out", OverWrite);
return 0;
}
catch(std::exception &e)
{
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}