initial upload
This commit is contained in:
103
examples/array_ex.cpp
Normal file
103
examples/array_ex.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/algorithm.h"
|
||||
#include "gctl/io.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
// create a new array and give initial values
|
||||
gctl::array<double> A;
|
||||
gctl::linespace(1.1, 2.9, 10, A);
|
||||
// show values
|
||||
std::cout << "A = " << std::endl;
|
||||
for (int i = 0; i < A.size(); i++)
|
||||
{
|
||||
std::cout << A[i] << std::endl;
|
||||
}
|
||||
|
||||
// copy A to a new array
|
||||
gctl::array<double> B = A;
|
||||
gctl::normalize(B);
|
||||
B.show();
|
||||
|
||||
gctl::array<double> S = A;
|
||||
std::cout << "B + A = " << std::endl;
|
||||
for (int i = 0; i < S.size(); i++)
|
||||
{
|
||||
S[i] += B[i];
|
||||
}
|
||||
S.show();
|
||||
gctl::normalize(S);
|
||||
S.show();
|
||||
|
||||
// create a new 2D array
|
||||
gctl::matrix<int> C(5, 5, 1);
|
||||
std::cout << "C = " << std::endl;
|
||||
for (int i = 0; i < C.row_size(); i++)
|
||||
{
|
||||
for (int j = 0; j < C.col_size(); j++)
|
||||
{
|
||||
C[i][j] += i*10 + j;
|
||||
std::cout << C.at(i,j) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// access row elements
|
||||
std::cout << "C[3][:] = " << std::endl;
|
||||
for (int i = 0; i < C.col_size(); i++)
|
||||
{
|
||||
std::cout << C.get(3)[i] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
// save array to a binary file
|
||||
gctl::save_matrix2binary("data/out/array_ex_out", C, "Int");
|
||||
|
||||
// import 2D array to a new object
|
||||
gctl::matrix<int> D;
|
||||
gctl::read_binary2matrix("data/out/array_ex_out", D);
|
||||
std::cout << "D = " << std::endl;
|
||||
for (int i = 0; i < D.row_size(); i++)
|
||||
{
|
||||
for (int j = 0; j < D.col_size(); j++)
|
||||
{
|
||||
std::cout << D[i][j] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
67
examples/basic_io_ex.cpp
Normal file
67
examples/basic_io_ex.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
|
||||
#include "cmath"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
typedef std::vector<std::vector<double> > _2d_vector;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
_2d_vector input_table2;
|
||||
try
|
||||
{
|
||||
gctl::text_descriptor desc;
|
||||
gctl::read_text2vector2d("data/point_height.txt", input_table2, desc);
|
||||
|
||||
for (int i = 0; i < input_table2.size(); i++)
|
||||
{
|
||||
for (int j = 0; j < input_table2.at(i).size(); j++)
|
||||
{
|
||||
if (std::isnan(input_table2.at(i).at(j)))
|
||||
{
|
||||
std::cout << input_table2.at(i).at(j) << " is nan";
|
||||
}
|
||||
else if (std::isinf(input_table2.at(i).at(j)))
|
||||
{
|
||||
std::cout << input_table2.at(i).at(j) << " is inf";
|
||||
}
|
||||
else std::cout << input_table2.at(i).at(j) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
catch (const char* err_str)
|
||||
{
|
||||
GCTL_ShowWhatError(err_str, GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
55
examples/cut_2d_tri_mesh_ex.cpp
Normal file
55
examples/cut_2d_tri_mesh_ex.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/geometry.h"
|
||||
#include "gctl/io.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
array<vertex2dc> nodes;
|
||||
array<triangle2d> eles;
|
||||
|
||||
gmshio fio;
|
||||
fio.init_file("data/sample", Input);
|
||||
fio.set_packed(NotPacked, Input);
|
||||
fio.read_mesh(eles, nodes);
|
||||
|
||||
// 使用一条直线进行切割 我们需要直线上的一个点和直线的方向向量 直线“左侧”的网络将被保留 右侧的网络将被删除
|
||||
point2dc p1(0.05, -1.0), p2(-0.65, 0.0);
|
||||
|
||||
array<vertex2dc> out_nodes;
|
||||
array<triangle2d> out_eles;
|
||||
geometry2d::cut_triangular_mesh_2d(eles, p1, p2, out_nodes, out_eles);
|
||||
|
||||
fio.init_file("data/out/sample_out", Output);
|
||||
fio.set_packed(NotPacked, Output);
|
||||
fio.save_mesh(out_eles, out_nodes);
|
||||
return 0;
|
||||
}
|
||||
52
examples/cut_3d_tri_mesh_ex.cpp
Normal file
52
examples/cut_3d_tri_mesh_ex.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/geometry.h"
|
||||
#include "gctl/io.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
array<vertex3dc> nodes;
|
||||
array<triangle> eles;
|
||||
|
||||
gmshio fio;
|
||||
fio.init_file("data/sample3d", Input);
|
||||
fio.read_mesh(eles, nodes);
|
||||
|
||||
array<vertex3dc> out_nodes;
|
||||
array<triangle> out_eles;
|
||||
point3dc nor(0, 0, -1), surf(254, 8240, 150);
|
||||
|
||||
geometry3d::cut_triangular_mesh(eles, nor, surf, out_nodes, out_eles);
|
||||
|
||||
fio.init_file("data/out/sample3d_out", Output);
|
||||
fio.save_mesh(out_eles, out_nodes);
|
||||
return 0;
|
||||
}
|
||||
52
examples/difference_1d_ex.cpp
Normal file
52
examples/difference_1d_ex.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/algorithm.h"
|
||||
#include "gctl/io.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::array<double> o1, o2, o3, o4;
|
||||
gctl::array<double> in(128, 0.0);
|
||||
for (int i = 0; i < in.size(); i++)
|
||||
{
|
||||
in[i] = sin(25.0*GCTL_Pi*i/360.0 + 0.2);
|
||||
}
|
||||
|
||||
gctl::difference_1d(in, o1, 1.0, 1);
|
||||
gctl::difference_1d(in, o2, 1.0, 2);
|
||||
gctl::difference_1d(in, o3, 1.0, 3);
|
||||
gctl::difference_1d(in, o4, 1.0, 4);
|
||||
|
||||
std::vector<std::string> head_info(1);
|
||||
head_info[0] = "ori o1 o2 o3 o4";
|
||||
gctl::save_arrays2text("data/out/difference_1d.txt", ' ', '#',
|
||||
&head_info, nullptr, in, o1, o2, o3, o4);
|
||||
|
||||
return 0;
|
||||
}
|
||||
84
examples/difference_2d_ex.cpp
Normal file
84
examples/difference_2d_ex.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/algorithm.h"
|
||||
#include "gctl/io.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::matrix<double> diff;
|
||||
gctl::matrix<double> in(128, 128, 0.0);
|
||||
|
||||
double dist;
|
||||
for (int i = 0; i < in.row_size(); i++)
|
||||
{
|
||||
for (int j = 0; j < in.col_size(); j++)
|
||||
{
|
||||
dist = sqrt((i-25.0)*(i-25.0) + (j-40.0)*(j-40.0));
|
||||
in[i][j] = cos(25.0*GCTL_Pi*dist/360.0);
|
||||
}
|
||||
}
|
||||
|
||||
gctl::array<double> out_data(in.row_size()*in.col_size());
|
||||
for (int i = 0; i < in.row_size(); i++)
|
||||
{
|
||||
for (int j = 0; j < in.col_size(); j++)
|
||||
{
|
||||
out_data[j + i*in.col_size()] = in[in.row_size()-1-i][j];
|
||||
}
|
||||
}
|
||||
|
||||
gctl::save_netcdf_grid("data/out/difference_2d", out_data, in.col_size(), in.row_size(), 0, 1, 0, 1, "x", "y", "z");
|
||||
|
||||
for (int d = 0; d < 4; d++)
|
||||
{
|
||||
gctl::difference_2d(in, diff, 1.0, gctl::Dx, d+1);
|
||||
for (int i = 0; i < in.row_size(); i++)
|
||||
{
|
||||
for (int j = 0; j < in.col_size(); j++)
|
||||
{
|
||||
out_data[j + i*in.col_size()] = diff[in.row_size()-1-i][j];
|
||||
}
|
||||
}
|
||||
gctl::append_netcdf_grid("data/out/difference_2d", out_data, "x", "y", "dx_"+std::to_string(d+1));
|
||||
}
|
||||
|
||||
for (int d = 0; d < 4; d++)
|
||||
{
|
||||
gctl::difference_2d(in, diff, 1.0, gctl::Dy, d+1);
|
||||
for (int i = 0; i < in.row_size(); i++)
|
||||
{
|
||||
for (int j = 0; j < in.col_size(); j++)
|
||||
{
|
||||
out_data[j + i*in.col_size()] = diff[in.row_size()-1-i][j];
|
||||
}
|
||||
}
|
||||
gctl::append_netcdf_grid("data/out/difference_2d", out_data, "x", "y", "dy_"+std::to_string(d+1));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
49
examples/drtp_ex.cpp
Normal file
49
examples/drtp_ex.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/potential.h"
|
||||
#include "iostream"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
gctl::gm_regular_grid mag_rg;
|
||||
mag_rg.load_netcdf_grid("../data/emag2_cut", gctl::NodeData,
|
||||
"longitude", "latitude");
|
||||
|
||||
mag_rg.drtp("delta_t", "inclination", "declination", "drtp", 3);
|
||||
mag_rg.save_netcdf_grid("../data/emag2_DRTP", gctl::NodeData);
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
81
examples/dynamic_stddev_ex.cpp
Normal file
81
examples/dynamic_stddev_ex.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/algorithm.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::array<double> all_data(1000);
|
||||
gctl::random(all_data, 0.0, 2.0);
|
||||
|
||||
// 计算均值和方差
|
||||
double mean = 0, stddev = 0;
|
||||
for (int i = 0; i < all_data.size(); i++)
|
||||
{
|
||||
mean += all_data[i];
|
||||
}
|
||||
mean /= all_data.size();
|
||||
|
||||
for (int i = 0; i < all_data.size(); i++)
|
||||
{
|
||||
stddev += pow(all_data[i] - mean, 2.0);
|
||||
}
|
||||
stddev = sqrt(stddev/all_data.size());
|
||||
|
||||
std::cout << "mean = " << mean << ", stddev = " << stddev << std::endl;
|
||||
|
||||
// 计算前900个的均值和方差 然后动态计算最后100次
|
||||
mean = 0;
|
||||
stddev = 0;
|
||||
for (int i = 0; i < 900; i++)
|
||||
{
|
||||
mean += all_data[i];
|
||||
}
|
||||
mean /= 900;
|
||||
|
||||
for (int i = 0; i < 900; i++)
|
||||
{
|
||||
stddev += pow(all_data[i] - mean, 2.0);
|
||||
}
|
||||
stddev = sqrt(stddev/900);
|
||||
|
||||
std::cout << "mean = " << mean << ", stddev = " << stddev << std::endl;
|
||||
|
||||
double new_mean;
|
||||
int count = 900;
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
stddev = gctl::dynamic_stddev(stddev, count, mean, all_data[900 + i], new_mean);
|
||||
mean = new_mean;
|
||||
std::cout << i << " mean = " << mean << ", stddev = " << stddev << std::endl;
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
45
examples/ellipse_filter_ex.cpp
Normal file
45
examples/ellipse_filter_ex.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/algorithm.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::ellipse_filter_para self_para =
|
||||
{500, 500, 100, 0, 1, 0.5, 1.0, 0.1};
|
||||
|
||||
for (double i = 0; i <= 1000.0; i += 10.0)
|
||||
{
|
||||
for (double j = 0; j <= 1000.0; j += 10.0)
|
||||
{
|
||||
std::cout << i << " " << j << " "
|
||||
<< ellipse_filter(i, j, self_para) << std::endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
56
examples/entity_ex.cpp
Normal file
56
examples/entity_ex.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/geometry.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
array<vertex3dc> v(8);
|
||||
v[0].set(point3dc(0,0,0), 1);
|
||||
v[1].set(point3dc(10,0,0),2);
|
||||
v[2].set(point3dc(10,8,0),3);
|
||||
v[3].set(point3dc(0,8,0), 4);
|
||||
v[4].set(point3dc(0,0,6), 5);
|
||||
v[5].set(point3dc(10,0,6),6);
|
||||
v[6].set(point3dc(10,8,6),7);
|
||||
v[7].set(point3dc(0,8,6), 8);
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
std::cout << v[i] << std::endl;
|
||||
}
|
||||
|
||||
edge ee(v[1], v[0], 10);
|
||||
std::cout << ee << std::endl;
|
||||
|
||||
block bk(v, 0, 1, 2, 3, 4, 5, 6, 7, 100);
|
||||
std::cout << bk << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
57
examples/find_index_ex.cpp
Normal file
57
examples/find_index_ex.cpp
Normal 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 "gctl/core.h"
|
||||
#include "gctl/algorithm.h"
|
||||
#include "iostream"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
int a_size = 12;
|
||||
double *t_array = new double [a_size];
|
||||
for (int i = 0; i < a_size; i++)
|
||||
{
|
||||
t_array[i] = i*1.0;
|
||||
}
|
||||
for (int i = 0; i < a_size; i++)
|
||||
{
|
||||
std::cout << t_array[i] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
double target = 0.5;
|
||||
int l_index;
|
||||
if (gctl::find_index(t_array, a_size, target, l_index))
|
||||
{
|
||||
std::cout << "not found!" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "found " << target << " between " << l_index << " and " << l_index+1 << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
70
examples/flags_parser_ex.cpp
Normal file
70
examples/flags_parser_ex.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/utility.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
try{
|
||||
int on_screen = 0;
|
||||
// 配置命令行参数与相关信息
|
||||
gctl::flags_parser fp;
|
||||
fp.set_proname("Test_Pro");
|
||||
fp.set_proinfo("This is an example of the flags_parser class.");
|
||||
fp.add_opt('i', "infile", required_argument, NULL, "Input file name.", "<filename>", true);
|
||||
fp.add_opt('o', "outfile", required_argument, NULL, "Output file name.", "<filename>", true);
|
||||
fp.add_opt('r', "range", required_argument, NULL, "Griding range.", "<xmin>/<xmax>/<ymin>/<ymax>", false);
|
||||
fp.add_opt('f', "filter", optional_argument, NULL, "Applying filter. A name may attached to the option", "[filer-name]", false);
|
||||
fp.add_opt(1, "screen", no_argument, &on_screen, "Show screen.", 0, false); // 不需要特别去拾取 只要触发getopt_long就会自动被识别
|
||||
fp.add_opt('h', "help", no_argument, NULL, "Show help information.", 0, false);
|
||||
fp.configure(argc, argv);
|
||||
|
||||
if(argc == 1 || fp.set_opt("help"))
|
||||
{
|
||||
fp.show_help_page();
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string in_name, out_name, range, filter;
|
||||
fp.get_argv({'i', 'o', 'r', 'f'}, {&in_name, &out_name, &range, &filter});
|
||||
if (filter == "NO_ARG") filter = "Gaussian";
|
||||
|
||||
// 查看是否通过强制参数检查
|
||||
if (!fp.pass_mandatory()) return 0;
|
||||
|
||||
std::cout << in_name << std::endl;
|
||||
std::cout << out_name << std::endl;
|
||||
std::cout << range << std::endl;
|
||||
std::cout << filter << std::endl;
|
||||
if (on_screen) std::cout << "-s option is set." << std::endl;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
63
examples/frac_model_ex.cpp
Normal file
63
examples/frac_model_ex.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/algorithm.h"
|
||||
#include "gctl/io.h"
|
||||
#include "iostream"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
// test for 1D fractal model
|
||||
gctl::array<double> model_1d;
|
||||
gctl::fractal_model_1d(model_1d, 250, 0, 0, 200.0, 0.8);
|
||||
|
||||
std::ofstream outfile;
|
||||
gctl::open_outfile(outfile, "data/out/frac_1d", ".txt");
|
||||
for (int i = 0; i < model_1d.size(); i++)
|
||||
{
|
||||
outfile << i+1 << " " << model_1d[i] << std::endl;
|
||||
}
|
||||
outfile.close();
|
||||
|
||||
// test for 2D fractal model
|
||||
gctl::matrix<double> model_2d;
|
||||
gctl::fractal_model_2d(model_2d, 251, 251, 0, 0, 0, 0, 200.0, 0.5);
|
||||
|
||||
gctl::save_netcdf_grid("data/out/frac_2d", model_2d, 0.0, 5.0, 0.0, 5.0);
|
||||
|
||||
gctl::fractal_model_2d(model_2d, 251, 251, 0, 0, 0, 0, 100.0, 1.0);
|
||||
gctl::append_netcdf_grid("data/out/frac_2d", model_2d, "x", "y", "z2");
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
84
examples/gaussian_hill_ex.cpp
Normal file
84
examples/gaussian_hill_ex.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/algorithm.h"
|
||||
#include "gctl/utility.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::gaussian_para2d p, q;
|
||||
|
||||
p.mu_x = 50.0;
|
||||
p.mu_y = 40.0;
|
||||
p.sigma_x = 15.0;
|
||||
p.sigma_y = 10.0;
|
||||
p.rho = 0.2;
|
||||
|
||||
q.mu_x = 60.0;
|
||||
q.mu_y = 70.0;
|
||||
q.sigma_x = 10.0;
|
||||
q.sigma_y = 20.0;
|
||||
q.rho = 0.0;
|
||||
|
||||
int m = 101, n = 101;
|
||||
gctl::array<double> d(m*n, 0.0);
|
||||
gctl::array<double> dx(m*n, 0.0);
|
||||
gctl::array<double> dy(m*n, 0.0);
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
for (int j = 0; j < m; j++)
|
||||
{
|
||||
d[j + i*m] = gctl::gaussian_dist2d(1.0*j, 1.0*i, p);
|
||||
dx[j + i*m] = gctl::gaussian_dist2d(1.0*j, 1.0*i, p, gctl::Dx);
|
||||
dy[j + i*m] = gctl::gaussian_dist2d(1.0*j, 1.0*i, p, gctl::Dy);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
for (int j = 0; j < m; j++)
|
||||
{
|
||||
d[j + i*m] += gctl::gaussian_dist2d(1.0*j, 1.0*i, q);
|
||||
dx[j + i*m] += gctl::gaussian_dist2d(1.0*j, 1.0*i, q, gctl::Dx);
|
||||
dy[j + i*m] += gctl::gaussian_dist2d(1.0*j, 1.0*i, q, gctl::Dy);
|
||||
}
|
||||
}
|
||||
|
||||
std::ofstream outfile;
|
||||
gctl::open_outfile(outfile, "data/out/gauss_hill", ".txt");
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
for (int j = 0; j < m; j++)
|
||||
{
|
||||
outfile << j << " " << i << " " << -1.0e+4*d[j + i*m] << " " << -1.0e+4*dx[j + i*m] << " " << -1.0e+4*dy[j + i*m] << std::endl;
|
||||
}
|
||||
}
|
||||
outfile.close();
|
||||
return 0;
|
||||
}
|
||||
82
examples/geometry2d_ex.cpp
Normal file
82
examples/geometry2d_ex.cpp
Normal 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 "gctl/core.h"
|
||||
#include "gctl/geometry.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::point2dc a, b, c, d;
|
||||
a.set(0.0, 0.0);
|
||||
b.set(10.0, 0.0);
|
||||
c.set(5.0, 7.0);
|
||||
|
||||
d.set(5.0, 5.0);
|
||||
if (gctl::geometry2d::node_in_triangle(d, a, b, c))
|
||||
{
|
||||
std::cout << "d is in triangle" << std::endl;
|
||||
}
|
||||
else std::cout << "d is not in triangle" << std::endl;
|
||||
|
||||
d.set(5.0, 7.0);
|
||||
if (gctl::geometry2d::node_in_triangle(d, a, b, c, false))
|
||||
{
|
||||
std::cout << "d is in triangle" << std::endl;
|
||||
}
|
||||
else std::cout << "d is not in triangle" << std::endl;
|
||||
|
||||
d.set(5.0, 8.0);
|
||||
if (gctl::geometry2d::node_in_triangle(d, a, b, c))
|
||||
{
|
||||
std::cout << "d is in triangle" << std::endl;
|
||||
}
|
||||
else std::cout << "d is not in triangle" << std::endl;
|
||||
|
||||
std::cout << "---------------------" << std::endl;
|
||||
|
||||
gctl::point2dc *c2, *d2;
|
||||
c2 = new gctl::point2dc;
|
||||
d2 = new gctl::point2dc;
|
||||
|
||||
a.set(0.0, 0.0);
|
||||
b.set(10.0, 0.0);
|
||||
c2->set(5.0, 7.0);
|
||||
d2->set(5.0, 5.0);
|
||||
|
||||
gctl::point2dc nor = d2->normal();
|
||||
std::cout << "nor(d) = (" << nor.x << ", " << nor.y << ")" << std::endl;
|
||||
|
||||
gctl::point2dc e = a - b;
|
||||
std::cout << "a - b = (" << e.x << ", " << e.y << ")" << std::endl;
|
||||
|
||||
double dist = gctl::distance(*c2, *d2);
|
||||
std::cout << "dist(c, d) = " << dist << std::endl;
|
||||
|
||||
delete c2;
|
||||
delete d2;
|
||||
return 0;
|
||||
}
|
||||
79
examples/getoption_ex.cpp
Normal file
79
examples/getoption_ex.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/utility.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
getoption gopt;
|
||||
|
||||
gopt.add_options({"range", "interval", "weight", "model-file", "model-tag", "out-model", "save-model"},
|
||||
{true, true, true, true, true, true, false});
|
||||
|
||||
gopt.set_group(1, {"out-model", "save-model"});
|
||||
|
||||
gopt.read_options("option_sample");
|
||||
|
||||
gopt.check_mandatory();
|
||||
|
||||
gopt.check_group(1);
|
||||
|
||||
// 显示所有读入的键值与参数值
|
||||
gopt.show_options();
|
||||
// 通过键值获取参数值
|
||||
std::cout << gopt.get_value("model-file") << std::endl;
|
||||
// 查找不存在的命令 返回警告信息与默认值NULL
|
||||
std::cout << gopt.get_value("model-tag") << std::endl;
|
||||
|
||||
std::cout << "---------------------" << std::endl;
|
||||
|
||||
double weight;
|
||||
// 通过选项的标签值来获取参数值 需要匹配的字符串只需要包含标签值即可
|
||||
gctl::str2type(gopt.get_value("weight|Weight"), weight);
|
||||
std::cout << weight << std::endl;
|
||||
|
||||
double xmin, xmax, ymin, ymax;
|
||||
std::string cover_str;
|
||||
parse_string_to_value(gopt.get_value("range|Range"), '/', true, xmin, xmax, ymin, ymax, cover_str);
|
||||
std::cout << xmin << " " << xmax << " " << ymin << " " << ymax << " " << cover_str << std::endl;
|
||||
|
||||
std::vector<std::string> tags;
|
||||
parse_string_to_vector(gopt.get_value("model-tag"), ',', tags);
|
||||
for (int i = 0; i < tags.size(); i++)
|
||||
{
|
||||
std::cout << tags[i] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
56
examples/gmsh_io_ex.cpp
Normal file
56
examples/gmsh_io_ex.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/io.h"
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
gctl::array<gctl::vertex2dc> mesh_node;
|
||||
gctl::array<gctl::triangle2d> mesh_triangle;
|
||||
gctl::array<double> mesh_data;
|
||||
|
||||
gctl::gmshio mshio;
|
||||
mshio.init_file("data/fmm2d/sample_mesh.1", gctl::Input);
|
||||
mshio.init_file("data/fmm2d/sample_mesh.2", gctl::Output);
|
||||
mshio.read_data(mesh_data, "Elements' gradient");
|
||||
mshio.set_packed(gctl::NotPacked, gctl::Input);
|
||||
|
||||
|
||||
mshio.read_mesh(mesh_triangle, mesh_node);
|
||||
mshio.save_mesh(mesh_triangle, mesh_node);
|
||||
mshio.save_data("Test Data", mesh_data, gctl::ElemData);
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
49
examples/gmt_plot_grid_ex.cpp
Normal file
49
examples/gmt_plot_grid_ex.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/graphic.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::array<double> data(51*41);
|
||||
|
||||
double dist;
|
||||
for (int i = 0; i < 51; ++i)
|
||||
{
|
||||
for (int j = 0; j < 41; ++j)
|
||||
{
|
||||
dist = sqrt((j-20)*(j-20) + (i-25)*(i-25));
|
||||
data[j+i*41] = sin(dist/GCTL_Pi);
|
||||
}
|
||||
}
|
||||
|
||||
gctl::gmt_JX_single pic;
|
||||
pic.show_command();
|
||||
pic.set_command("psconvert", "-A -TG -E300");
|
||||
pic.plot("data/out/gmt_plot_ex", data, 0, 40, 0, 50, 41, 51);
|
||||
return 0;
|
||||
}
|
||||
63
examples/gobser_block_ex.cpp
Normal file
63
examples/gobser_block_ex.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// set up observation parameters and block parameters
|
||||
array<point3dc> obes;
|
||||
gridspace(point3dc(0, 0, 0), point3dc(100, 0, 0),
|
||||
point3dc(0, 0, 0), point3dc(0, 100, 0), 51, 51, obes);
|
||||
|
||||
array<block> model(2);
|
||||
model[0].set(20, 35, 20, 40, -40, -10);
|
||||
model[1].set(50, 60, 40, 70, -32, -5);
|
||||
|
||||
array<double> rho(2, 1.0);
|
||||
array<double> g, gx, gy, gz;
|
||||
gobser(g, model, obes, rho, Vz, ShortMsg);
|
||||
|
||||
#ifdef GCTL_NETCDF
|
||||
gobser(gx, model, obes, rho, Tzx, ShortMsg);
|
||||
gobser(gy, model, obes, rho, Tzy, ShortMsg);
|
||||
gobser(gz, model, obes, rho, Tzz, ShortMsg);
|
||||
|
||||
save_netcdf_grid("data/block_g", g, 51, 51, 0.0, 2.0, 0.0, 2.0, "x", "y", "g");
|
||||
append_netcdf_grid("data/block_g", gx, "x", "y", "gx");
|
||||
append_netcdf_grid("data/block_g", gy, "x", "y", "gy");
|
||||
append_netcdf_grid("data/block_g", gz, "x", "y", "gz");
|
||||
#else
|
||||
save_surfer6_grid("data/block_g", g, 51, 51, 0.0, 2.0*51, 0.0, 2.0*51);
|
||||
#endif // GCTL_NETCDF
|
||||
|
||||
return 0;
|
||||
}
|
||||
58
examples/gobser_polygon_ex.cpp
Normal file
58
examples/gobser_polygon_ex.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// set up observation parameters and polygon parameters
|
||||
array<point2dc> obes;
|
||||
linespace(point2dc(0.0, 0.0), point2dc(200.0, 0.0), 201, obes);
|
||||
|
||||
array<vertex2dc> polygon(5);
|
||||
polygon[0].set(point2dc(80, -50), 0);
|
||||
polygon[1].set(point2dc(120, -50), 1);
|
||||
polygon[2].set(point2dc(120, -10), 2);
|
||||
polygon[3].set(point2dc(100, -30), 3);
|
||||
polygon[4].set(point2dc(80, -10), 4);
|
||||
|
||||
array<double> g, gx, gz;
|
||||
gobser(g, polygon, obes, 1.0, Vz);
|
||||
gobser(gx, polygon, obes, 1.0, Tzx);
|
||||
gobser(gz, polygon, obes, 1.0, Tzz);
|
||||
|
||||
for (int i = 0; i < obes.size(); i++)
|
||||
{
|
||||
std::cout << obes[i].x << " " << obes[i].y << " " << g[i] << " " << gx[i] << " " << gz[i] << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
56
examples/gobser_rect2d_ex.cpp
Normal file
56
examples/gobser_rect2d_ex.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// set up observation parameters and block parameters
|
||||
array<point2dc> obes;
|
||||
linespace(point2dc(0.0, 0.0), point2dc(200.0, 0.0), 201, obes);
|
||||
|
||||
array<rectangle2d> model(2);
|
||||
model[0].set(60, 80, -30, -10);
|
||||
model[1].set(110, 120, -80, -20);
|
||||
|
||||
array<double> rho(2, 0.5);
|
||||
rho[1] = 0.6;
|
||||
|
||||
array<double> obs_val;
|
||||
gobser(obs_val, model, obes, rho, Vz, ShortMsg);
|
||||
|
||||
for (int i = 0; i < obes.size(); i++)
|
||||
{
|
||||
std::cout << obes[i].x << " " << obes[i].y << " " << obs_val[i] << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
89
examples/gobser_sphere_ex.cpp
Normal file
89
examples/gobser_sphere_ex.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/potential.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
// set up observation parameters and block parameters
|
||||
gctl::array<double> line_node, line_node2;
|
||||
gctl::linespace(0.0, 150.0, 61, line_node);
|
||||
gctl::linespace(0.0, 200.0, 101, line_node2);
|
||||
gctl::array<gctl::point3dc> obes(line_node.size() * line_node2.size());
|
||||
for (int i = 0; i < line_node2.size(); i++)
|
||||
{
|
||||
for (int j = 0; j < line_node.size(); j++)
|
||||
{
|
||||
obes[i*line_node.size()+j].x = line_node.at(j);
|
||||
obes[i*line_node.size()+j].y = line_node2.at(i);
|
||||
obes[i*line_node.size()+j].z = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
gctl::sphere a_body(gctl::point3dc(60, 120, -25), 15);
|
||||
double rho = 1.0;
|
||||
a_body.att = ρ
|
||||
|
||||
gctl::array<double> data_g, data_gx, data_gy, data_gz;
|
||||
|
||||
gobser_sphere(data_g, obes, a_body, gctl::Vz);
|
||||
gobser_sphere(data_gx, obes, a_body, gctl::Tzx);
|
||||
gobser_sphere(data_gy, obes, a_body, gctl::Tzy);
|
||||
gobser_sphere(data_gz, obes, a_body, gctl::Tzz);
|
||||
|
||||
gctl::sphere t_body(gctl::point3dc(80, 100, -25), 10);
|
||||
rho = 1.2;
|
||||
t_body.att = ρ
|
||||
|
||||
gobser_sphere(data_g, obes, t_body, gctl::Vz, gctl::AppendVal);
|
||||
gobser_sphere(data_gx, obes, t_body, gctl::Tzx, gctl::AppendVal);
|
||||
gobser_sphere(data_gy, obes, t_body, gctl::Tzy, gctl::AppendVal);
|
||||
gobser_sphere(data_gz, obes, t_body, gctl::Tzz, gctl::AppendVal);
|
||||
|
||||
#ifdef GCTL_NETCDF
|
||||
gctl::save_netcdf_grid("data/sphere_g", data_g, 61, 101, 0.0, 2.5, 0.0, 2.0, "x", "y", "g");
|
||||
gctl::append_netcdf_grid("data/sphere_g", data_gx, "x", "y", "gx");
|
||||
gctl::append_netcdf_grid("data/sphere_g", data_gy, "x", "y", "gy");
|
||||
gctl::append_netcdf_grid("data/sphere_g", data_gz, "x", "y", "gz");
|
||||
#else
|
||||
gctl::save_surfer6_grid("data/sphere_g", data_g, 61, 101, 0.0, 2.5*60, 0.0, 2.0*100, NAN, NAN, gctl::Surfer6Binary);
|
||||
gctl::save_surfer6_grid("data/sphere_gx", data_gx, 61, 101, 0.0, 2.5*60, 0.0, 2.0*100, NAN, NAN, gctl::Surfer6Binary);
|
||||
gctl::save_surfer6_grid("data/sphere_gy", data_gy, 61, 101, 0.0, 2.5*60, 0.0, 2.0*100, NAN, NAN, gctl::Surfer6Binary);
|
||||
gctl::save_surfer6_grid("data/sphere_gz", data_gz, 61, 101, 0.0, 2.5*60, 0.0, 2.0*100, NAN, NAN, gctl::Surfer6Binary);
|
||||
#endif // GCTL_NETCDF
|
||||
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
77
examples/gobser_tesseroid_ex.cpp
Normal file
77
examples/gobser_tesseroid_ex.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/potential.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
// set up observation parameters and block parameters
|
||||
gctl::array<double> line_node;
|
||||
gctl::linespace(-25.0, 25.0, 201, line_node);
|
||||
gctl::array<gctl::point3ds> obes(line_node.size() * line_node.size());
|
||||
for (int i = 0; i < line_node.size(); i++)
|
||||
{
|
||||
for (int j = 0; j < line_node.size(); j++)
|
||||
{
|
||||
obes[i*line_node.size()+j].lon = line_node.at(j);
|
||||
obes[i*line_node.size()+j].lat = line_node.at(i);
|
||||
obes[i*line_node.size()+j].rad = GCTL_Earth_Radius + 100000.0;
|
||||
}
|
||||
}
|
||||
|
||||
gctl::array<gctl::tesseroid> tesses(1);
|
||||
tesses[0].set(GCTL_Earth_Radius - 10000.0, GCTL_Earth_Radius - 1000.0, -2, 2, -2, 2);
|
||||
|
||||
gctl::array<double> rho(1, 1.0);
|
||||
|
||||
gctl::array<double> data;
|
||||
|
||||
#ifdef GCTL_NETCDF
|
||||
gctl::gobser(data, tesses, obes, rho, gctl::Vz, gctl::ShortMsg);
|
||||
gctl::save_netcdf_grid("data/tesseroid_gr", data, 201, 201, -25.0, 0.25, -25.0, 0.25, "x", "y", "Vr");
|
||||
|
||||
gctl::gobser(data, tesses, obes, rho, gctl::Tzx, gctl::ShortMsg);
|
||||
gctl::append_netcdf_grid("data/tesseroid_gr", data, "x", "y", "Vrp");
|
||||
|
||||
gctl::gobser(data, tesses, obes, rho, gctl::Tzy, gctl::ShortMsg);
|
||||
gctl::append_netcdf_grid("data/tesseroid_gr", data, "x", "y", "Vrt");
|
||||
#else
|
||||
gctl::gobser(data, tesses, obes, rho, gctl::Tr, gctl::ShortMsg);
|
||||
gctl::save_surfer6_grid("data/tesseroid_gr", data, 201, 201, -25.0, 25.0, -25.0, 25.0, NAN, NAN, gctl::Surfer6Binary);
|
||||
#endif // GCTL_NETCDF
|
||||
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
80
examples/gobser_tetra_ex.cpp
Normal file
80
examples/gobser_tetra_ex.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
// set up observation points
|
||||
array<point3dc> obes;
|
||||
gridspace(point3dc(0, 0, 0), point3dc(100, 0, 0), point3dc(0, 0, 0), point3dc(0, 100, 0), 41, 41, obes);
|
||||
// set up model element
|
||||
array<grav_tetrahedron> onetetra(1);
|
||||
array<gravtet_para> tet_gp;
|
||||
onetetra[0].set(point3dc(20, 50, -30), point3dc(80, 20, -10), point3dc(50, 80, -15), point3dc(50, 50, -50), 0);
|
||||
callink_gravity_para(onetetra, tet_gp);
|
||||
|
||||
array<double> rho(1, 1.0);
|
||||
|
||||
array<tensor> data_grad;
|
||||
gobser(data_grad, onetetra, obes, rho);
|
||||
|
||||
array<double> data(data_grad.size());
|
||||
for (int i = 0; i < data_grad.size(); ++i)
|
||||
{
|
||||
data[i] = data_grad[i].at(2,2) * 1e+4;
|
||||
}
|
||||
|
||||
#ifdef GCTL_NETCDF
|
||||
save_netcdf_grid("data/tetra_g", data, 41, 41, 0.0, 2.5, 0.0, 2.5);
|
||||
|
||||
gmshio fio;
|
||||
fio.init_file("data/tetra_g", Output);
|
||||
fio.set_packed(NotPacked, Output);
|
||||
fio.save_mesh(onetetra);
|
||||
#else
|
||||
save_surfer6_grid("data/tetra_g", data, 41, 41, 0.0, 2.5*41, 0.0, 2.5*41, NAN, NAN, Surfer6Binary);
|
||||
|
||||
gmshio fio;
|
||||
fio.init_file("data/tetra_g", Output);
|
||||
fio.set_packed(NotPacked, Output);
|
||||
fio.save_mesh(onetetra);
|
||||
#endif // GCTL_NETCDF
|
||||
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
58
examples/gobser_tetra_sph_ex.cpp
Normal file
58
examples/gobser_tetra_sph_ex.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// set up observation parameters and block parameters
|
||||
array<point3ds> obes;
|
||||
gridspace(point3ds(5e+3, 30, 0), point3ds(5e+3, 50, 0),
|
||||
point3ds(5e+3, 0, 20), point3ds(5e+3, 0, 40), 81, 81, obes);
|
||||
|
||||
array<grav_tetrahedron> onetetra(1);
|
||||
array<gravtet_para> tet_gp(1);
|
||||
onetetra[0].set(point3ds(9900.0, 35.0, 25.0), point3ds(9900.0, 45.0, 30.0),
|
||||
point3ds(9900.0, 40.0, 35.0), point3ds(9800.0, 40.0, 30.0));
|
||||
callink_gravity_para(onetetra, tet_gp);
|
||||
|
||||
// set up observation array
|
||||
array<double> rho(1, 1.0);
|
||||
array<point3dc> obsval;
|
||||
gobser(obsval, onetetra, obes, rho);
|
||||
|
||||
array<double> out_data(obsval.size());
|
||||
for (int i = 0; i < obsval.size(); ++i)
|
||||
{
|
||||
out_data[i] = obsval[i].x; // 球坐标下矢量第一个分量为径向分量
|
||||
}
|
||||
|
||||
save_netcdf_grid("data/tetra_gr_sph", out_data, 81, 81, 30.0, 0.25, 20.0, 0.25, "longitude", "latitude", "gr");
|
||||
return 0;
|
||||
}
|
||||
75
examples/gobser_tri2d_ex.cpp
Normal file
75
examples/gobser_tri2d_ex.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
int obs_num = 101;
|
||||
|
||||
// set up observation points
|
||||
array<point2dc> obs_loc;
|
||||
linespace(point2dc(0.0, 0.0), point2dc(200.0, 0.0), obs_num, obs_loc);
|
||||
|
||||
// set nodes locations
|
||||
array<vertex2dc> node_vert(3);
|
||||
node_vert[0].set(point2dc(80.0, -30.0));
|
||||
node_vert[1].set(point2dc(105.0, -60.0));
|
||||
node_vert[2].set(point2dc(106.0, -10.0));
|
||||
|
||||
// set triangular elements
|
||||
array<double> rho(2, 1.0);
|
||||
array<triangle2d> tri(2);
|
||||
// anti-clock wise
|
||||
tri[0].set(node_vert[0], node_vert[1], node_vert[2]); // set triangle's vertex from existing vertex
|
||||
tri[1].set(point2dc(135.0, -5.0), point2dc(141.0, -40.0), point2dc(145.0, -15.0)); // set triangle's vertex from parameters
|
||||
|
||||
// forward modeling
|
||||
array<double> g(obs_num);
|
||||
array<double> gx(obs_num);
|
||||
array<double> gz(obs_num);
|
||||
gobser(g, tri, obs_loc, rho, gctl::Vz);
|
||||
gobser(gx, tri, obs_loc, rho, gctl::Tzx);
|
||||
gobser(gz, tri, obs_loc, rho, gctl::Tzz);
|
||||
|
||||
for (int i = 0; i < obs_num; ++i)
|
||||
{
|
||||
std::cout << obs_loc[i] << " " << g[i] << " " << gx[i] << " " << gz[i] << std::endl;
|
||||
}
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
139
examples/gobser_tri_ex.cpp
Normal file
139
examples/gobser_tri_ex.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
// set up observation points
|
||||
array<point3dc> obes;
|
||||
gridspace(point3dc(0, 0, 0), point3dc(100, 0, 0), point3dc(0, 0, 0), point3dc(0, 100, 0), 41, 41, obes);
|
||||
|
||||
gmshio fio("data/cube/cube_sorted", Input);
|
||||
|
||||
array<vertex3dc> nodes;
|
||||
array<grav_triangle> eles;
|
||||
fio.read_mesh(eles, nodes);
|
||||
|
||||
array<gravtri_para> gpara(eles.size());
|
||||
callink_gravity_para(eles, gpara);
|
||||
|
||||
array<double> out_data;
|
||||
array<point3dc> out_grad;
|
||||
array<tensor> out_tens;
|
||||
|
||||
gobser(out_data, eles, obes, 1.0, ShortMsg);
|
||||
save_netcdf_grid("data/cube/cube_gravity", out_data, 41, 41, 0.0, 2.5, 0.0, 2.5, "easting", "northing", "potential");
|
||||
|
||||
|
||||
gobser(out_grad, eles, obes, 1.0, ShortMsg);
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_grad[i].x;
|
||||
}
|
||||
append_netcdf_grid("data/cube/cube_gravity", out_data, "easting", "northing", "gravity_x");
|
||||
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_grad[i].y;
|
||||
}
|
||||
append_netcdf_grid("data/cube/cube_gravity", out_data, "easting", "northing", "gravity_y");
|
||||
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_grad[i].z;
|
||||
}
|
||||
append_netcdf_grid("data/cube/cube_gravity", out_data, "easting", "northing", "gravity_z");
|
||||
|
||||
|
||||
gobser(out_tens, eles, obes, 1.0, ShortMsg);
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_tens[i].at(0, 0);
|
||||
}
|
||||
append_netcdf_grid("data/cube/cube_gravity", out_data, "easting", "northing", "tensor_xx");
|
||||
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_tens[i].at(0, 1);
|
||||
}
|
||||
append_netcdf_grid("data/cube/cube_gravity", out_data, "easting", "northing", "tensor_xy");
|
||||
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_tens[i].at(0, 2);
|
||||
}
|
||||
append_netcdf_grid("data/cube/cube_gravity", out_data, "easting", "northing", "tensor_xz");
|
||||
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_tens[i].at(1, 0);
|
||||
}
|
||||
append_netcdf_grid("data/cube/cube_gravity", out_data, "easting", "northing", "tensor_yx");
|
||||
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_tens[i].at(1, 1);
|
||||
}
|
||||
append_netcdf_grid("data/cube/cube_gravity", out_data, "easting", "northing", "tensor_yy");
|
||||
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_tens[i].at(1, 2);
|
||||
}
|
||||
append_netcdf_grid("data/cube/cube_gravity", out_data, "easting", "northing", "tensor_yz");
|
||||
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_tens[i].at(2, 0);
|
||||
}
|
||||
append_netcdf_grid("data/cube/cube_gravity", out_data, "easting", "northing", "tensor_zx");
|
||||
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_tens[i].at(2, 1);
|
||||
}
|
||||
append_netcdf_grid("data/cube/cube_gravity", out_data, "easting", "northing", "tensor_zy");
|
||||
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_tens[i].at(2, 2);
|
||||
}
|
||||
append_netcdf_grid("data/cube/cube_gravity", out_data, "easting", "northing", "tensor_zz");
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
140
examples/gobser_tri_sph_ex.cpp
Normal file
140
examples/gobser_tri_sph_ex.cpp
Normal file
@@ -0,0 +1,140 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
// set up observation points
|
||||
array<point3ds> obes;
|
||||
gridspace(point3ds(550, 20, 0), point3ds(550, 70, 0),
|
||||
point3ds(550, 0, 10), point3ds(550, 0, 60), 101, 101, obes);
|
||||
|
||||
gmshio fio("data/tess/tess_sorted", Input);
|
||||
|
||||
array<vertex3dc> nodes;
|
||||
array<grav_triangle> eles;
|
||||
fio.read_mesh(eles, nodes);
|
||||
|
||||
array<gravtri_para> gpara(eles.size());
|
||||
callink_gravity_para(eles, gpara);
|
||||
|
||||
array<double> out_data;
|
||||
array<point3dc> out_grad;
|
||||
array<tensor> out_tens;
|
||||
|
||||
gobser(out_data, eles, obes, 1.0, ShortMsg);
|
||||
save_netcdf_grid("data/tess/tess_gravity", out_data, 101, 101, 20.0, 0.5, 10.0, 0.5, "easting", "northing", "potential");
|
||||
|
||||
|
||||
gobser(out_grad, eles, obes, 1.0, ShortMsg);
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_grad[i].x;
|
||||
}
|
||||
append_netcdf_grid("data/tess/tess_gravity", out_data, "easting", "northing", "gravity_r");
|
||||
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_grad[i].y;
|
||||
}
|
||||
append_netcdf_grid("data/tess/tess_gravity", out_data, "easting", "northing", "gravity_t");
|
||||
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_grad[i].z;
|
||||
}
|
||||
append_netcdf_grid("data/tess/tess_gravity", out_data, "easting", "northing", "gravity_p");
|
||||
|
||||
|
||||
gobser(out_tens, eles, obes, 1.0, ShortMsg);
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_tens[i].at(0, 0);
|
||||
}
|
||||
append_netcdf_grid("data/tess/tess_gravity", out_data, "easting", "northing", "tensor_rr");
|
||||
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_tens[i].at(0, 1);
|
||||
}
|
||||
append_netcdf_grid("data/tess/tess_gravity", out_data, "easting", "northing", "tensor_rt");
|
||||
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_tens[i].at(0, 2);
|
||||
}
|
||||
append_netcdf_grid("data/tess/tess_gravity", out_data, "easting", "northing", "tensor_rp");
|
||||
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_tens[i].at(1, 0);
|
||||
}
|
||||
append_netcdf_grid("data/tess/tess_gravity", out_data, "easting", "northing", "tensor_tr");
|
||||
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_tens[i].at(1, 1);
|
||||
}
|
||||
append_netcdf_grid("data/tess/tess_gravity", out_data, "easting", "northing", "tensor_tt");
|
||||
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_tens[i].at(1, 2);
|
||||
}
|
||||
append_netcdf_grid("data/tess/tess_gravity", out_data, "easting", "northing", "tensor_tp");
|
||||
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_tens[i].at(2, 0);
|
||||
}
|
||||
append_netcdf_grid("data/tess/tess_gravity", out_data, "easting", "northing", "tensor_pr");
|
||||
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_tens[i].at(2, 1);
|
||||
}
|
||||
append_netcdf_grid("data/tess/tess_gravity", out_data, "easting", "northing", "tensor_pt");
|
||||
|
||||
for (int i = 0; i < obes.size(); ++i)
|
||||
{
|
||||
out_data[i] = out_tens[i].at(2, 2);
|
||||
}
|
||||
append_netcdf_grid("data/tess/tess_gravity", out_data, "easting", "northing", "tensor_pp");
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
139
examples/gobser_tricone_ex.cpp
Normal file
139
examples/gobser_tricone_ex.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/potential.h"
|
||||
#include "iostream"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
gctl::array<gctl::vertex3dc> msh_vert;
|
||||
gctl::array<gctl::grav_tri_cone> msh_cone;
|
||||
gctl::array<gctl::gravcone_para> cone_para;
|
||||
|
||||
// read element from Gmsh file
|
||||
std::ifstream infile;
|
||||
gctl::open_infile(infile, "data/gobser_tricone/template", ".msh");
|
||||
gctl::read_gmsh_node(infile, msh_vert, gctl::Packed);
|
||||
gctl::read_gmsh_element(infile, msh_cone, msh_vert, gctl::Packed, nullptr);
|
||||
infile.close();
|
||||
|
||||
// set origin for the cone
|
||||
gctl::vertex3dc ori_vert(gctl::point3dc(0.0, 0.0, 0.0), msh_vert.size());
|
||||
// create grav_tri_cone
|
||||
for (int i = 0; i < msh_cone.size(); i++)
|
||||
{
|
||||
msh_cone[i].set_origin(ori_vert);
|
||||
}
|
||||
|
||||
//initialize the tensors
|
||||
gctl::callink_gravity_para(msh_cone, cone_para);
|
||||
|
||||
// read topography data
|
||||
gctl::_2d_vector txt_content;
|
||||
gctl::array<gctl::point3ds> topo_sph;
|
||||
gctl::text_descriptor desc;
|
||||
gctl::read_text2vector2d("data/gobser_tricone/topo.txt", txt_content, desc);
|
||||
|
||||
topo_sph.resize(txt_content.size());
|
||||
for (int i = 0; i < txt_content.size(); i++)
|
||||
{
|
||||
topo_sph[i].rad = 1e+5 + txt_content[i][2];
|
||||
topo_sph[i].lon = txt_content[i][0];
|
||||
topo_sph[i].lat = txt_content[i][1];
|
||||
}
|
||||
|
||||
// initiate observation points
|
||||
double xmin = 30, xmax = 50, dx = 0.25;
|
||||
double ymin = 30, ymax = 50, dy = 0.25;
|
||||
int xnum = round((xmax - xmin)/dx) + 1;
|
||||
int ynum = round((ymax - ymin)/dy) + 1;
|
||||
gctl::array<gctl::point3ds> obs_ps(xnum*ynum);
|
||||
for (int j = 0; j < ynum; j++)
|
||||
{
|
||||
for (int i = 0; i < xnum; i++)
|
||||
{
|
||||
obs_ps[i + j*xnum].rad = 1e+5 + 200.0;
|
||||
obs_ps[i + j*xnum].lon = xmin + i*dx;
|
||||
obs_ps[i + j*xnum].lat = ymin + j*dy;
|
||||
}
|
||||
}
|
||||
|
||||
// calculate base gravity
|
||||
gctl::array<double> out_obs;
|
||||
gctl::array<double> rho(msh_cone.size(), 1.0);
|
||||
gctl::gobser(out_obs, msh_cone, obs_ps, rho, gctl::Vz);
|
||||
|
||||
// interpolate topography
|
||||
int m, n;
|
||||
double colat1, colat2, lon1, lon2;
|
||||
gctl::point3ds tmp_p;
|
||||
gctl::point3dc tmp_c;
|
||||
|
||||
gctl::array<double> out_topo(msh_vert.size());
|
||||
for (int i = 0; i < msh_vert.size(); i++)
|
||||
{
|
||||
tmp_p = msh_vert[i].c2s();
|
||||
m = floor(tmp_p.lon - 28.0)/0.5;
|
||||
n = floor(tmp_p.lat - 28.0)/0.5;
|
||||
|
||||
colat1 = 90.0 - (28.0 + n*0.5);
|
||||
colat2 = 90.0 - (28.0 + (n+1)*0.5);
|
||||
lon1 = 28.0 + m*0.5;
|
||||
lon2 = 28.0 + (m+1)*0.5;
|
||||
|
||||
tmp_p.rad = gctl::sph_linear_interpolate_deg(colat1, colat2, lon1, lon2,
|
||||
90.0-tmp_p.lat, tmp_p.lon,
|
||||
topo_sph[m + 49*n].rad,
|
||||
topo_sph[m + 1 + 49*n].rad,
|
||||
topo_sph[m + 49*(n+1)].rad,
|
||||
topo_sph[m + 1 + 49*(n+1)].rad);
|
||||
|
||||
out_topo[i] = tmp_p.rad - 1e+5;
|
||||
|
||||
tmp_c = tmp_p.s2c();
|
||||
msh_vert[i].set(tmp_c);
|
||||
}
|
||||
|
||||
// recalculate tensors
|
||||
gctl::callink_gravity_para(msh_cone, cone_para);
|
||||
|
||||
gctl::array<double> out_obs2;
|
||||
gctl::gobser(out_obs2, msh_cone, obs_ps, rho, gctl::Vz);
|
||||
|
||||
for (int i = 0; i < out_obs.size(); i++)
|
||||
{
|
||||
out_obs2[i] -= out_obs[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < out_obs.size(); i++)
|
||||
{
|
||||
std::cout << obs_ps[i].lon << " " << obs_ps[i].lat << " " << out_obs2[i] << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
58
examples/grav_gradient_ex.cpp
Normal file
58
examples/grav_gradient_ex.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/potential.h"
|
||||
#include "iostream"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
gctl::gm_regular_grid grav_rg;
|
||||
#ifdef GCTL_NETCDF
|
||||
grav_rg.load_netcdf_grid("data/sphere_g", gctl::NodeData,
|
||||
"x", "y");
|
||||
|
||||
grav_rg.gradient("g", "gx2", gctl::Tzx, 1);
|
||||
grav_rg.gradient("g", "gy2", gctl::Tzy, 1);
|
||||
grav_rg.gradient("g", "gz2", gctl::Tzz, 1);
|
||||
grav_rg.conti("g", "g2", -50);
|
||||
grav_rg.save_netcdf_grid("data/sphere_g2", gctl::NodeData);
|
||||
#else
|
||||
grav_rg.load_surfer_grid("data/sphere_g", "g", gctl::NodeData, gctl::Surfer6Binary);
|
||||
grav_rg.gradient("g", "gx", gctl::Tzx, 1);
|
||||
grav_rg.save_surfer_grid("data/sphere_gx_out", "gx", gctl::Surfer6Binary);
|
||||
#endif // GCTL_NETCDF
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
82
examples/griding_ex.cpp
Normal file
82
examples/griding_ex.cpp
Normal 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/mesh.h"
|
||||
|
||||
#include "vector"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
// read topography data
|
||||
gctl::_2d_vector xyz_content;
|
||||
gctl::text_descriptor desc;
|
||||
gctl::read_text2vector2d("data/random_topo.xyz", xyz_content, desc);
|
||||
// convert to 2D points and values
|
||||
gctl::array<gctl::point2dc> topo_posi(xyz_content.size());
|
||||
gctl::array<double> topo_val(xyz_content.size());
|
||||
for (int i = 0; i < xyz_content.size(); i++)
|
||||
{
|
||||
topo_posi[i].x = xyz_content.at(i).at(0);
|
||||
topo_posi[i].y = xyz_content.at(i).at(1);
|
||||
topo_val[i] = xyz_content.at(i).at(2);
|
||||
}
|
||||
// destroy vector
|
||||
gctl::destroy_vector(xyz_content);
|
||||
|
||||
// griding
|
||||
double s_xlen = 15, s_ylen = 20;
|
||||
|
||||
gctl::regular_grid topo_grid("Topography", "null", 101, 101, 0, 0, 10, 10);
|
||||
topo_grid.load_data_cloud(topo_posi, topo_val, 15, 20, 0, "random_topo", gctl::ElemData);
|
||||
topo_grid.load_data_cloud(topo_posi, topo_val, 25, 25, 0, "random_topo_node", gctl::NodeData);
|
||||
topo_grid.gradient("random_topo", "random_topo_dx", gctl::Dx);
|
||||
topo_grid.gradient("random_topo", "random_topo_dx2", gctl::Dx, 2);
|
||||
topo_grid.gradient("random_topo_node", "random_topo_node_dx", gctl::Dx);
|
||||
topo_grid.gradient("random_topo_node", "random_topo_node_dy", gctl::Dy);
|
||||
|
||||
topo_grid.save_gmsh("../data/random_topo_out", gctl::ElemData, gctl::OverWrite, gctl::NotPacked);
|
||||
topo_grid.save_gmsh("../data/random_topo_out", gctl::NodeData, gctl::Append, gctl::NotPacked);
|
||||
|
||||
gctl::point2dc sp(20, 20), ep(980, 960);
|
||||
gctl::array<gctl::point2dc> profile_posi;
|
||||
gctl::array<double> profile_val;
|
||||
topo_grid.extract_profile("random_topo", sp, ep, 201, profile_posi, profile_val);
|
||||
|
||||
std::vector<std::string> head_info(1);
|
||||
head_info[0] = "x,y,data";
|
||||
gctl::save_arrays2text("../data/random_topo_profile.csv", ',', '#', &head_info, nullptr, profile_posi, profile_val);
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
85
examples/heap_sort_ex.cpp
Normal file
85
examples/heap_sort_ex.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/algorithm.h"
|
||||
#include "gctl/geometry.h"
|
||||
#include "gctl/utility.h"
|
||||
|
||||
#include "iostream"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// declare a sort operator for double
|
||||
gctl::heap_sort<double> double_sorter;
|
||||
|
||||
// test double_sorter
|
||||
int a_size = 10;
|
||||
double *A = new double [a_size];
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
A[i] = i + 1.0;
|
||||
std::cout << A[i] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
// sort as a descending array
|
||||
double_sorter.execute(A, a_size, [](double *a, int l_id, int r_id)->bool{
|
||||
if (a[l_id] > a[r_id]) return true;
|
||||
else return false;
|
||||
});
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
std::cout << A[i] << " ";
|
||||
std::cout << std::endl;
|
||||
|
||||
delete[] A;
|
||||
|
||||
// declare a sort operator for point3dc
|
||||
gctl::heap_sort<gctl::point3dc> p3d_sorter;
|
||||
|
||||
gctl::array<gctl::point3dc> line_ps;
|
||||
gctl::linespace(gctl::point3dc(10,11,12), gctl::point3dc(0,0,0), 11, line_ps);
|
||||
for (int i = 0; i < line_ps.size(); i++)
|
||||
{
|
||||
std::cout << line_ps.at(i).x << " " << line_ps.at(i).y << " " << line_ps.at(i).z << std::endl;
|
||||
}
|
||||
|
||||
// sort as an ascending array according y values
|
||||
p3d_sorter.execute(line_ps, [](gctl::array<gctl::point3dc> &a, int l_id, int r_id)->bool
|
||||
{
|
||||
if (a[l_id].y < a[r_id].y) return true;
|
||||
else return false;
|
||||
});
|
||||
|
||||
for (int i = 0; i < line_ps.size(); i++)
|
||||
{
|
||||
std::cout << line_ps.at(i).x << " " << line_ps.at(i).y << " " << line_ps.at(i).z << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
104
examples/mat_inverse_ex.cpp
Normal file
104
examples/mat_inverse_ex.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/algorithm.h"
|
||||
#include "iostream"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
int n_size = 5;
|
||||
gctl::matrix<double> B;
|
||||
// A=[10,1,2,0,1;
|
||||
//2,20,1,0,1;
|
||||
//1,3,30,2,0;
|
||||
//2,3,0,40,1;
|
||||
//5,6,1,0,50]
|
||||
/*
|
||||
gctl::array2d<double> A(n_size, n_size, 0.0);
|
||||
A[0][0] = 10.0; A[0][1] = 1.0; A[0][2] = 2.0; A[0][3] = 0.0; A[0][4] = 1.0;
|
||||
A[1][0] = 2.0; A[1][1] = 20.0; A[1][2] = 1.0; A[1][3] = 0.0; A[1][4] = 1.0;
|
||||
A[2][0] = 1.0; A[2][1] = 3.0; A[2][2] = 30.0; A[2][3] = 2.0; A[2][4] = 0.0;
|
||||
A[3][0] = 2.0; A[3][1] = 3.0; A[3][2] = 0.0; A[3][3] = 40.0; A[3][4] = 1.0;
|
||||
A[4][0] = 5.0; A[4][1] = 6.0; A[4][2] = 1.0; A[4][3] = 0.0; A[4][4] = 50.0;
|
||||
*/
|
||||
|
||||
gctl::spmat<double> A(n_size, n_size, 0.0);
|
||||
A.insert(0, 0, 10.0);
|
||||
A.insert(1, 1, 20.0);
|
||||
A.insert(2, 2, 30.0);
|
||||
A.insert(3, 3, 40.0);
|
||||
A.insert(4, 4, 10.0);
|
||||
A.insert(0, 3, 1.0);
|
||||
A.insert(1, 2, 2.0);
|
||||
A.insert(2, 4, 5.0);
|
||||
A.insert(3, 0, 3.0);
|
||||
A.insert(4, 1, 4.0);
|
||||
|
||||
std::cout << "epsilon = " << gctl::newton_inverse(A, B, 1e-12) << std::endl;
|
||||
|
||||
std::cout << "A = " << std::endl;
|
||||
A.show_matrix();
|
||||
|
||||
std::cout << "A^-1 = " << std::endl;
|
||||
for (int i = 0; i < n_size; i++)
|
||||
{
|
||||
for (int j = 0; j < n_size; j++)
|
||||
{
|
||||
std::cout << B[i][j] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
double ele;
|
||||
std::cout << "A * A^-1 = " << std::endl;
|
||||
|
||||
gctl::array<double> tmp_arr(n_size);
|
||||
for (int i = 0; i < n_size; i++)
|
||||
{
|
||||
for (int j = 0; j < n_size; j++)
|
||||
{
|
||||
//ele = 0.0;
|
||||
//for (int k = 0; k < n_size; k++)
|
||||
//{
|
||||
// ele += A[i][k] * B[k][j];
|
||||
//}
|
||||
for (int k = 0; k < n_size; k++)
|
||||
{
|
||||
tmp_arr[k] = B[k][j];
|
||||
}
|
||||
ele = A.multiply_vector(tmp_arr, i);
|
||||
|
||||
if (fabs(ele) < 1e-12)
|
||||
ele = 0.0;
|
||||
|
||||
std::cout << ele << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
68
examples/mobser_block_ex.cpp
Normal file
68
examples/mobser_block_ex.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// 设置块体模型
|
||||
array<mag_block> bk(1);
|
||||
bk[0].set(45, 55, 45, 55, 20, 40);
|
||||
// 设置块体的磁化率与磁化参数
|
||||
array<double> sus(1, 0.1);
|
||||
array<magblock_para> mag_para(1);
|
||||
mag_para[0].inclina_deg = 60;
|
||||
mag_para[0].declina_deg = 10;
|
||||
bk[0].att = &mag_para[0];
|
||||
// 设置观测点位
|
||||
array<point3dc> obsp;
|
||||
gridspace(point3dc(0, 0, 0), point3dc(100, 0, 0),
|
||||
point3dc(0, 0, 0), point3dc(0, 100, 0), 51, 51, obsp);
|
||||
// 正演计算
|
||||
array<double> obsval;
|
||||
magobser(obsval, bk, obsp, sus, Hax, ShortMsg);
|
||||
// 保存网格
|
||||
gctl::save_netcdf_grid("out", obsval, 51, 51, 0, 2, 0, 2, "x", "y", "Hax");
|
||||
|
||||
magobser(obsval, bk, obsp, sus, Hay, ShortMsg);
|
||||
// 保存网格
|
||||
gctl::append_netcdf_grid("out", obsval, "x", "y", "Hay");
|
||||
|
||||
magobser(obsval, bk, obsp, sus, Za, ShortMsg);
|
||||
// 保存网格
|
||||
gctl::append_netcdf_grid("out", obsval, "x", "y", "Za");
|
||||
|
||||
gridspace(point3dc(0, 0, -5), point3dc(100, 0, -5),
|
||||
point3dc(0, 0, -5), point3dc(0, 100, -5), 51, 51, obsp);
|
||||
|
||||
magobser(obsval, bk, obsp, sus, Za, ShortMsg);
|
||||
// 保存网格
|
||||
gctl::append_netcdf_grid("out", obsval, "x", "y", "Za-10");
|
||||
return 0;
|
||||
}
|
||||
82
examples/mobser_tesseroid_ex.cpp
Normal file
82
examples/mobser_tesseroid_ex.cpp
Normal 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/potential.h"
|
||||
#include "iostream"
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
// set up observation parameters and block parameters
|
||||
double lon, lat;
|
||||
gctl::array<gctl::point3ds> obes(201*201);
|
||||
for (int i = 0; i < 201; i++)
|
||||
{
|
||||
lat = 20.0 + 0.25*i;
|
||||
for (int j = 0; j < 201; j++)
|
||||
{
|
||||
lon = 65.0 + 0.25*j;
|
||||
obes[i*201+j].lon = lon;
|
||||
obes[i*201+j].lat = lat;
|
||||
obes[i*201+j].rad = GCTL_Earth_Radius + 40000.0;
|
||||
}
|
||||
}
|
||||
|
||||
gctl::array<gctl::mag_tesseroid> tesses(1);
|
||||
gctl::array<gctl::magtess_para> mtess(1);
|
||||
tesses[0].set(GCTL_Earth_Radius - 11650.0, GCTL_Earth_Radius - 1000.0, 89, 91, 44, 46);
|
||||
mtess[0].bx = 23458.6;
|
||||
mtess[0].by = 840.2;
|
||||
mtess[0].bz = 53040.0;
|
||||
gctl::link_entity_attribute(tesses, mtess);
|
||||
|
||||
gctl::array<double> rho(1, 1.0);
|
||||
gctl::array<double> sus(1, 1.0);
|
||||
|
||||
gctl::array<double> data;
|
||||
|
||||
#ifdef GCTL_NETCDF
|
||||
magobser(data, tesses, obes, rho, sus, gctl::Za, gctl::ShortMsg);
|
||||
gctl::save_netcdf_grid("data/tesseroid_mag", data, 201, 201, -25.0, 0.25, -25.0, 0.25, "x", "y", "Za");
|
||||
|
||||
magobser(data, tesses, obes, rho, sus, gctl::Hax, gctl::ShortMsg);
|
||||
gctl::append_netcdf_grid("data/tesseroid_mag", data, "x", "y", "Hax");
|
||||
|
||||
magobser(data, tesses, obes, rho, sus, gctl::Hay, gctl::ShortMsg);
|
||||
gctl::append_netcdf_grid("data/tesseroid_mag", data, "x", "y", "Hay");
|
||||
#else
|
||||
magobser(data, tesses, obes, rho, sus, gctl::Za, gctl::ShortMsg);
|
||||
gctl::save_surfer6_grid("data/tesseroid_mag", data, 201, 201, -25.0, 25.0, -25.0, 25.0, NAN, NAN, gctl::Surfer6Binary);
|
||||
#endif // GCTL_NETCDF
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
115
examples/mobser_tetra_ex.cpp
Normal file
115
examples/mobser_tetra_ex.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/io.h"
|
||||
#include "gctl/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
array<vertex3dc> node;
|
||||
array<mag_tetrahedron_ren17> ele;
|
||||
read_Tetgen_node("data/prism/prism.1", node);
|
||||
read_Tetgen_element("data/prism/prism.1", ele, node);
|
||||
|
||||
array<point3dc> magz(ele.size(), point3dc(0,0,200));
|
||||
array<magtet_para_ren17> mag_para;
|
||||
callink_magnetic_para_direct(ele, mag_para, magz);
|
||||
|
||||
// 设置观测点位
|
||||
array<point3dc> obsp;
|
||||
gridspace(point3dc(-30, 0, 5), point3dc(30, 0, 5),
|
||||
point3dc(0, -30, 5), point3dc(0, 30, 5), 81, 81, obsp);
|
||||
// 正演计算
|
||||
array<double> obsval;
|
||||
array<point3dc> obsgrad;
|
||||
array<tensor> obstensor;
|
||||
magobser(obsval, ele, obsp, ShortMsg);
|
||||
// 保存网格
|
||||
gctl::save_netcdf_grid("out", obsval, 81, 81, -30.0, 0.75, -30.0, 0.75, "x", "y", "Potential");
|
||||
|
||||
magobser(obsgrad, ele, obsp, ShortMsg);
|
||||
// 保存网格
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].x;
|
||||
}
|
||||
gctl::append_netcdf_grid("out", obsval, "x", "y", "Bx");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].y;
|
||||
}
|
||||
gctl::append_netcdf_grid("out", obsval, "x", "y", "By");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].z;
|
||||
}
|
||||
gctl::append_netcdf_grid("out", obsval, "x", "y", "Bz");
|
||||
|
||||
|
||||
magobser(obstensor, ele, obsp, ShortMsg);
|
||||
// 保存网格
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obstensor[i].at(0, 0);
|
||||
}
|
||||
gctl::append_netcdf_grid("out", obsval, "x", "y", "Txx");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obstensor[i].at(0, 1);
|
||||
}
|
||||
gctl::append_netcdf_grid("out", obsval, "x", "y", "Txy");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obstensor[i].at(0, 2);
|
||||
}
|
||||
gctl::append_netcdf_grid("out", obsval, "x", "y", "Txz");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obstensor[i].at(1, 1);
|
||||
}
|
||||
gctl::append_netcdf_grid("out", obsval, "x", "y", "Tyy");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obstensor[i].at(1, 2);
|
||||
}
|
||||
gctl::append_netcdf_grid("out", obsval, "x", "y", "Tyz");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obstensor[i].at(2, 2);
|
||||
}
|
||||
gctl::append_netcdf_grid("out", obsval, "x", "y", "Tzz");
|
||||
return 0;
|
||||
}
|
||||
46
examples/parse_string.cpp
Normal file
46
examples/parse_string.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/utility.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
std::string t = "2/3/4/6/ssd";
|
||||
int a[5];
|
||||
|
||||
int ret = gctl::parse_string_to_value(t, '/', false, a[0], a[1], a[2], a[3], a[4]);
|
||||
|
||||
std::cout << "num = " << ret << std::endl;
|
||||
for (size_t i = 0; i < 5; i++)
|
||||
{
|
||||
|
||||
std::cout << a[i] << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
48
examples/point2d_rotate_ex.cpp
Normal file
48
examples/point2d_rotate_ex.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/geometry.h"
|
||||
#include "iostream"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::point2dc a(1.0, 1.0);
|
||||
gctl::point2dc o1(2.0, 2.0);
|
||||
gctl::point2dc o2(1.0, 0.0);
|
||||
gctl::point2dc b = a.rotate(0.5*GCTL_Pi);
|
||||
gctl::point2dc c = a.rotate(-0.25*GCTL_Pi);
|
||||
gctl::point2dc d = a.rotate(0.5*GCTL_Pi, o1);
|
||||
gctl::point2dc e = a.rotate(-0.5*GCTL_Pi, o2);
|
||||
|
||||
std::cout << "a (" << a.x << ", " << a.y << ")" << std::endl;
|
||||
std::cout << "b (" << b.x << ", " << b.y << ")" << std::endl;
|
||||
std::cout << "c (" << c.x << ", " << c.y << ")" << std::endl;
|
||||
std::cout << "d (" << d.x << ", " << d.y << ")" << std::endl;
|
||||
std::cout << "e (" << e.x << ", " << e.y << ")" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
59
examples/point_ex.cpp
Normal file
59
examples/point_ex.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/geometry.h"
|
||||
#include "iostream"
|
||||
|
||||
using namespace gctl;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// 二维实点的测试
|
||||
point2dc p, q;
|
||||
p.set(4.3, 5.9);
|
||||
q.set(1.2, 3.0);
|
||||
cout << (p+q).x << endl;
|
||||
cout << (p-q).y << endl;
|
||||
cout << (5*p).x << endl;
|
||||
// 以下为三维实点的测试
|
||||
point3dc a, b;
|
||||
a.set(3,2,5);
|
||||
b.set(4,1,7);
|
||||
point3dc c = a + b;
|
||||
point3dc d = a - b;
|
||||
point3dc e = 0.5*a;
|
||||
cout << a.x << " " << a.y << " " << a.z << endl;
|
||||
cout << b.x << " " << b.y << " " << b.z << endl;
|
||||
cout << c.x << " " << c.y << " " << c.z << endl;
|
||||
cout << d.x << " " << d.y << " " << d.z << endl;
|
||||
cout << e.x << " " << e.y << " " << e.z << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
65
examples/progressbar_ex.cpp
Normal file
65
examples/progressbar_ex.cpp
Normal 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 "gctl/utility.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// declare a progress bar with the size of p_size
|
||||
int p_size = 10;
|
||||
gctl::progress_bar bar(p_size, "Sample");
|
||||
|
||||
// do something and show the progress
|
||||
for (int i = 0; i < p_size; ++i)
|
||||
{
|
||||
bar.progressed(i);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// reset the progress bar to the size of 2*p_size
|
||||
bar.reset(2*p_size, "Sample-2");
|
||||
// set customized styles for the progress bar
|
||||
bar.set_style(">", " ");
|
||||
|
||||
// do something and show the progress
|
||||
for (int i = 0; i < 2*p_size; ++i)
|
||||
{
|
||||
bar.progressed(i);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// reset the progress bar
|
||||
bar.reset(p_size, "Sample-3");
|
||||
|
||||
// do something and show the simple progress
|
||||
for (int i = 0; i < p_size; ++i)
|
||||
{
|
||||
bar.progressed_simple(i);
|
||||
sleep(1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
60
examples/read_netcdf_ex.cpp
Normal file
60
examples/read_netcdf_ex.cpp
Normal 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "iostream"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::array<int> xs, ys;
|
||||
gctl::array<double> data;
|
||||
|
||||
gctl::read_netcdf_axis("data/out/nc_example", xs, "x");
|
||||
gctl::read_netcdf_axis("data/out/nc_example", xs, "y");
|
||||
gctl::read_netcdf_grid("data/out/nc_example", data, "x", "y", "z");
|
||||
gctl::show_netcdf_info("data/out/nc_example");
|
||||
|
||||
for (int i = 0; i < xs.size(); ++i)
|
||||
{
|
||||
std::cout << xs[i] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
for (int i = 0; i < ys.size(); ++i)
|
||||
{
|
||||
std::cout << ys[i] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
std::cout << data[i] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
return 0;
|
||||
}
|
||||
17
examples/rtp_ex.cpp
Normal file
17
examples/rtp_ex.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/potential.h"
|
||||
#include "iostream"
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
gctl::gm_regular_grid mag_rg;
|
||||
mag_rg.load_netcdf_grid("data/sample_DeltaT", gctl::NodeData, "x", "y");
|
||||
mag_rg.rtp("z", "rtp", 50, 3);
|
||||
mag_rg.save_netcdf_grid("data/sample_RTP", gctl::NodeData);
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
49
examples/save_netcdf_ex.cpp
Normal file
49
examples/save_netcdf_ex.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "iostream"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
int xnum = 101, ynum = 91;
|
||||
int xmin = 100, ymin = 50;
|
||||
int dx = 5, dy = 5;
|
||||
gctl::array<double> data(xnum*ynum);
|
||||
|
||||
for (int j = 0; j < ynum; j++)
|
||||
{
|
||||
for (int i = 0; i < xnum; i++)
|
||||
{
|
||||
data[i + j*xnum] = 1.0*i + 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
gctl::save_netcdf_grid("data/out/nc_example", data, xnum, ynum, xmin, dx, ymin, dy);
|
||||
return 0;
|
||||
}
|
||||
43
examples/sparray2d_ex.cpp
Normal file
43
examples/sparray2d_ex.cpp
Normal 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 "gctl/core.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::sparray2d<double> M(10, 10, 0.0);
|
||||
|
||||
M.at(4)->set(4, 5);
|
||||
M.at(2)->set(3, 8);
|
||||
M.at(6)->set(8, 2);
|
||||
|
||||
for (int i = 0; i < M.size(); i++)
|
||||
{
|
||||
M.at(i)->show_full();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
109
examples/sparray_ex.cpp
Normal file
109
examples/sparray_ex.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/algorithm.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
srand(time(0));
|
||||
gctl::sparray<double> M(50, 0.0);
|
||||
|
||||
int tmp_id[13] = {4, 2, 6, 7, 8, 12, 23, 43, 33, 47, 38, 15, 1};
|
||||
int tmp_size = 13;
|
||||
for (int i = 0; i < tmp_size; i++)
|
||||
{
|
||||
M.set(tmp_id[i], gctl::random(10.0, 20.0));
|
||||
}
|
||||
|
||||
M.show_list();
|
||||
|
||||
M.set(18, 100);
|
||||
M.set(38, 100);
|
||||
M.remove(12);
|
||||
|
||||
std::cout << "************" << std::endl;
|
||||
M.show_list();
|
||||
|
||||
gctl::array<double> C(50, -1.0);
|
||||
M.export_dense(C, 1.0, gctl::AppendVal);
|
||||
for (int i = 0; i < C.size(); i++)
|
||||
{
|
||||
std::cout << C.at(i) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
gctl::sparray<double> N(C, -1, 1e-10);
|
||||
N.show_list();
|
||||
|
||||
std::cout << "Test 2" << std::endl;
|
||||
|
||||
M.clear();
|
||||
M.malloc(20, 0.0);
|
||||
|
||||
M.set(5, 6.5);
|
||||
M.set(9, 9.1);
|
||||
M.set(3, 4.3);
|
||||
M.set(17, 1.4);
|
||||
M.set(10, 3.5);
|
||||
M.set(7, 7.4);
|
||||
|
||||
M.show_list();
|
||||
|
||||
M.remove(17);
|
||||
M.remove(9);
|
||||
|
||||
std::cout << "**********" << std::endl;
|
||||
M.show_list();
|
||||
|
||||
std::cout << "Test 3" << std::endl;
|
||||
|
||||
int test_size = 500000;
|
||||
|
||||
M.clear();
|
||||
M.malloc(test_size, 0.0);
|
||||
|
||||
clock_t start = clock();
|
||||
for (int i = 0; i < 300000; i++)
|
||||
{
|
||||
M.set(i, gctl::random(10.0, 20.0));
|
||||
}
|
||||
for (int i = 300001; i < test_size; i++)
|
||||
{
|
||||
M.set(i, gctl::random(10.0, 20.0));
|
||||
}
|
||||
M.set(300000, 15.8888);
|
||||
|
||||
clock_t end = clock();
|
||||
std::cout << "sparray set() time: " << 1000.0*(end - start)/(double)CLOCKS_PER_SEC << " ms" << std::endl;
|
||||
|
||||
std::cout << "M.at(300000) = " << M.value(300000) << std::endl;
|
||||
|
||||
M.show_list(299995, 300005);
|
||||
|
||||
return 0;
|
||||
}
|
||||
86
examples/spmat_ex.cpp
Normal file
86
examples/spmat_ex.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::spmat<double> M(10, 10, 0.0);
|
||||
|
||||
M.insert(3, 3, 1.3);
|
||||
M.insert(8, 1, 2.8);
|
||||
M.insert(2, 6, 4.2);
|
||||
M.insert(5, 6, 4.6);
|
||||
M.insert(2, 3, 7.2);
|
||||
M.insert(5, 9, 2.2);
|
||||
M.insert(2, 9, 5.4);
|
||||
M.insert(7, 4, 8.5);
|
||||
M.insert(0, 4, 0.0);
|
||||
M.insert(7, 6, 0.0);
|
||||
|
||||
M.show_matrix();
|
||||
M.show_list();
|
||||
|
||||
std::cout << "M.at(4, 4) = " << M.at(4, 4) << std::endl;
|
||||
std::cout << "M.at(5, 9) = " << M.at(5, 9) << std::endl;
|
||||
|
||||
gctl::spmat<double> N = M; // 等效语句 gctl::spmat<double> N(M);
|
||||
N.remove(2, 3);
|
||||
N.remove(3, 3);
|
||||
N.show_matrix();
|
||||
|
||||
for (int i = 0; i < N.row_size(); i++)
|
||||
{
|
||||
std::cout << "row size " << i << " = " << N.ele_size(i) << std::endl;
|
||||
}
|
||||
|
||||
for (int i = 0; i < N.col_size(); i++)
|
||||
{
|
||||
std::cout << "col size " << i << " = " << N.ele_size(i, gctl::ColMajor) << std::endl;
|
||||
}
|
||||
|
||||
N.minus_sparse_matrix(M);
|
||||
|
||||
N.show_matrix();
|
||||
for (int i = 0; i < N.row_size(); i++)
|
||||
{
|
||||
std::cout << "row size " << i << " = " << N.ele_size(i) << std::endl;
|
||||
}
|
||||
|
||||
for (int i = 0; i < N.col_size(); i++)
|
||||
{
|
||||
std::cout << "col size " << i << " = " << N.ele_size(i, gctl::ColMajor) << std::endl;
|
||||
}
|
||||
|
||||
//for (int i = 0; i < N.col_size(); i++)
|
||||
//{
|
||||
// std::cout << "col size " << i << " = " << N.ele_size(i, gctl::SpMatColMajor) << std::endl;
|
||||
//}
|
||||
|
||||
//N.show_full();
|
||||
return 0;
|
||||
}
|
||||
115
examples/spmat_ex2.cpp
Normal file
115
examples/spmat_ex2.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::spmat<double> M(6, 5, 0.0);
|
||||
|
||||
M.insert(3, 3, 0.1);
|
||||
M.insert(2, 3, 0.2);
|
||||
M.insert(2, 0, 0.3);
|
||||
M.insert(1, 4, 0.4);
|
||||
M.insert(0, 1, 0.5);
|
||||
M.insert(4, 2, 0.6);
|
||||
M.insert(5, 1, 0.7);
|
||||
|
||||
std::cout << "M = " << std::endl;
|
||||
M.show_matrix();
|
||||
|
||||
gctl::spmat<double> N(5, 6, 0.0);
|
||||
|
||||
N.insert(3, 3, 0.1);
|
||||
N.insert(3, 2, 0.2);
|
||||
N.insert(0, 2, 0.3);
|
||||
N.insert(4, 1, 0.4);
|
||||
N.insert(1, 0, 0.5);
|
||||
N.insert(2, 4, 0.6);
|
||||
N.insert(1, 5, 0.7);
|
||||
|
||||
std::cout << "N = " << std::endl;
|
||||
N.show_matrix();
|
||||
|
||||
gctl::spmat<double> Product;
|
||||
M.multiply_sparse_matrix(N, Product);
|
||||
std::cout << "M*N = " << std::endl;
|
||||
Product.show_matrix();
|
||||
std::cout << "N (list) = " << std::endl;
|
||||
Product.show_list();
|
||||
|
||||
gctl::array<double> V(6, 1.0);
|
||||
V[3] = 2.0;
|
||||
std::cout << "V = " << std::endl;
|
||||
for (int i = 0; i < V.size(); i++)
|
||||
{
|
||||
std::cout << V.at(i) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
gctl::array<double> MxV;
|
||||
M.multiply_vector(V, MxV, gctl::Trans);
|
||||
|
||||
std::cout << "M^T*V = " << std::endl;
|
||||
for (int i = 0; i < MxV.size(); i++)
|
||||
{
|
||||
std::cout << MxV.at(i) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
gctl::spmat<double> L;
|
||||
M.transpose(L);
|
||||
std::cout << "L = M^T = " << std::endl;
|
||||
L.show_matrix();
|
||||
|
||||
gctl::matrix<double> P(5, 6);
|
||||
std::cout << "P = " << std::endl;
|
||||
for (int i = 0; i < P.row_size(); i++)
|
||||
{
|
||||
for (int j = 0; j < P.col_size(); j++)
|
||||
{
|
||||
P.at(i, j) = i + 0.1*j;
|
||||
std::cout << P.at(i, j) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
gctl::matrix<double> Product2;
|
||||
M.multiply_matrix(P, Product2);
|
||||
|
||||
std::cout << "M*P = " << std::endl;
|
||||
for (int i = 0; i < Product2.row_size(); i++)
|
||||
{
|
||||
for (int j = 0; j < Product2.col_size(); j++)
|
||||
{
|
||||
std::cout << Product2.at(i, j) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
63
examples/spmat_ex3.cpp
Normal file
63
examples/spmat_ex3.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
gctl::spmat<double> M(6, 5, 0.0);
|
||||
|
||||
M.insert(3, 3, 0.5);
|
||||
M.insert(2, 3, 0.5);
|
||||
M.insert(2, 0, 0.5);
|
||||
M.insert(1, 4, 0.5);
|
||||
M.insert(0, 1, 0.5);
|
||||
M.insert(4, 2, 0.5);
|
||||
M.insert(5, 1, 0.5);
|
||||
M.insert(4, 4, 0.5);
|
||||
|
||||
std::cout << "M.ele_size() = " << M.ele_size() << std::endl;
|
||||
|
||||
std::cout << "M = " << std::endl;
|
||||
M.show_matrix();
|
||||
gctl::save_spmat2binary("data/out/spmat_M", M);
|
||||
|
||||
gctl::spmat<double> N;
|
||||
gctl::read_binary2spmat("data/out/spmat_M", N);
|
||||
|
||||
std::cout << "N = " << std::endl;
|
||||
N.show_matrix();
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
61
examples/spmat_ex4.cpp
Normal file
61
examples/spmat_ex4.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::spmat<double> M(10, 10, 0.0);
|
||||
|
||||
M.insert(3, 3, 1.3);
|
||||
M.insert(5, 6, 4.6);
|
||||
M.insert(8, 1, 2.8);
|
||||
M.insert(2, 3, 7.2);
|
||||
M.insert(5, 9, 2.2);
|
||||
M.insert(2, 9, 5.4);
|
||||
M.insert(7, 4, 8.5);
|
||||
|
||||
M.show_matrix();
|
||||
M.show_list();
|
||||
|
||||
M.map(5, 0, 2.0);
|
||||
M.map(2, 0, 1.0);
|
||||
M.map(3, 0, 1.0, gctl::ColMajor);
|
||||
|
||||
M.show_matrix();
|
||||
M.show_list();
|
||||
|
||||
gctl::array<double> in(10, 0.2), out(10);
|
||||
M.multiply_vector(0, in.get(), 10, out.get());
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
std::cout << out[i] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
return 0;
|
||||
}
|
||||
59
examples/spmat_ex5.cpp
Normal file
59
examples/spmat_ex5.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::_2d_vector A(10);
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
A[i].resize(10, 0.0);
|
||||
}
|
||||
|
||||
A[3][3] = 1.3;
|
||||
A[5][6] = 4.6;
|
||||
A[8][1] = 2.8;
|
||||
A[2][3] = 7.2;
|
||||
A[5][9] = 2.2;
|
||||
A[2][9] = 5.4;
|
||||
A[7][4] = 8.5;
|
||||
A[0][4] = 0.0;
|
||||
A[7][6] = 0.0;
|
||||
|
||||
gctl::spmat<double> M(10, 10, 0.0);
|
||||
M.set_2d_vector(A, 1e-20);
|
||||
|
||||
M.show_matrix();
|
||||
M.show_list();
|
||||
std::cout << "##########" << std::endl;
|
||||
M.show_list(gctl::ColMajor, ' ');
|
||||
|
||||
gctl::spmat<double> N(M);
|
||||
N.show_matrix();
|
||||
return 0;
|
||||
}
|
||||
101
examples/spmat_ex6.cpp
Normal file
101
examples/spmat_ex6.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
|
||||
gctl::spmat<double> A(10, 10, 0.0);
|
||||
|
||||
A.insert(3, 3, 1.3);
|
||||
A.insert(5, 6, 4.6);
|
||||
A.insert(8, 1, 2.8);
|
||||
A.insert(2, 3, 7.2);
|
||||
A.insert(5, 9, 2.2);
|
||||
A.insert(2, 9, 5.4);
|
||||
A.insert(7, 4, 8.5);
|
||||
A.insert(0, 1, 8.5);
|
||||
A.insert(0, 7, 5.3);
|
||||
A.insert(1, 2, 8.1);
|
||||
A.insert(1, 5, 1.2);
|
||||
A.insert(1, 6, 3.4);
|
||||
|
||||
gctl::spmat<double> B(A);
|
||||
|
||||
A.show_matrix();
|
||||
std::cout << "#########" << std::endl;
|
||||
|
||||
std::cout << A.sum() << std::endl;
|
||||
for (int i = 0; i < A.row_size(); i++)
|
||||
{
|
||||
std::cout << A.sum(i) << std::endl;
|
||||
}
|
||||
/*
|
||||
double sum;
|
||||
gctl::mat_node<double> *node_ptr;
|
||||
for (int i = 0; i < A.row_size(); i++)
|
||||
{
|
||||
sum = 0.0;
|
||||
|
||||
node_ptr = A.row_head(i);
|
||||
while (node_ptr != nullptr)
|
||||
{
|
||||
sum += node_ptr->value();
|
||||
node_ptr = A.next(node_ptr);
|
||||
}
|
||||
|
||||
node_ptr = A.row_head(i);
|
||||
while (node_ptr != nullptr)
|
||||
{
|
||||
node_ptr->value(node_ptr->value()/sum);
|
||||
node_ptr = A.next(node_ptr);
|
||||
}
|
||||
}
|
||||
*/
|
||||
std::cout << A.sum() << std::endl;
|
||||
for (int i = 0; i < A.row_size(); i++)
|
||||
{
|
||||
std::cout << A.sum(i) << std::endl;
|
||||
}
|
||||
|
||||
A.show_matrix();
|
||||
std::cout << "#########" << std::endl;
|
||||
|
||||
for (int i = 0; i < B.row_size(); i++)
|
||||
{
|
||||
B.normalize(i, 1.0);
|
||||
}
|
||||
B.show_matrix();
|
||||
|
||||
B.clear(1);
|
||||
B.clear(3, gctl::ColMajor);
|
||||
std::cout << "#########" << std::endl;
|
||||
B.show_matrix();
|
||||
B.show_list(gctl::ColMajor, ',');
|
||||
return 0;
|
||||
}
|
||||
65
examples/spmat_ex7.cpp
Normal file
65
examples/spmat_ex7.cpp
Normal 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 "gctl/core.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
|
||||
gctl::spmat<double> A(10, 10, 0.0), B;
|
||||
|
||||
A.insert(3, 3, 1.3);
|
||||
A.insert(5, 6, 4.6);
|
||||
A.insert(8, 1, 2.8);
|
||||
A.insert(2, 3, 7.2);
|
||||
A.insert(5, 9, 2.2);
|
||||
A.insert(2, 9, 5.4);
|
||||
A.insert(7, 4, 8.5);
|
||||
A.insert(0, 1, 8.5);
|
||||
A.insert(0, 7, 5.3);
|
||||
A.insert(1, 2, 8.1);
|
||||
A.insert(1, 5, 1.2);
|
||||
A.insert(1, 6, 3.4);
|
||||
|
||||
A.show_matrix();
|
||||
std::cout << "#########" << std::endl;
|
||||
|
||||
gctl::array<double> a(10);
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
a[i] = i+1.0;
|
||||
}
|
||||
|
||||
A.multiply_diagonal_matrix(a, B, false);
|
||||
B.show_matrix();
|
||||
std::cout << "#########" << std::endl;
|
||||
|
||||
A.multiply_diagonal_matrix(a, B);
|
||||
B.show_matrix();
|
||||
std::cout << "#########" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
160
examples/spmat_inversion_ex.cpp
Normal file
160
examples/spmat_inversion_ex.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/algorithm.h"
|
||||
#include "lcg/lcg.h"
|
||||
#include "ctime"
|
||||
|
||||
#define M 100
|
||||
#define N 80
|
||||
|
||||
// 普通二维数组做核矩阵
|
||||
gctl::matrix<double> kernel(M, N, 0.0);
|
||||
// 稀疏矩阵为核矩阵
|
||||
gctl::spmat<double> sp_kernel(M, N, 0.0);
|
||||
// 中间结果数组
|
||||
gctl::array<double> tmp_arr(M, 0.0);
|
||||
|
||||
// 计算核矩阵乘向量的乘积
|
||||
void CalAx(void* instance, const lcg_float* x, lcg_float* prod_Ax, const int n_s)
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
tmp_arr[i] = 0.0;
|
||||
for (int j = 0; j < n_s; j++)
|
||||
{
|
||||
tmp_arr[i] += kernel[i][j] * x[j];
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < n_s; j++)
|
||||
{
|
||||
prod_Ax[j] = 0.0;
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
prod_Ax[j] += kernel[i][j] * tmp_arr[i];
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算核矩阵乘向量的乘积
|
||||
void CalAx_Spmat(void* instance, const lcg_float* x, lcg_float* prod_Ax, const int n_s)
|
||||
{
|
||||
// 直接调用稀疏矩阵与向量的乘法
|
||||
// 注意第二次为向量乘矩阵 相当于矩阵的转置与向量相乘
|
||||
sp_kernel.multiply_vector(x, n_s, tmp_arr.get(), M);
|
||||
sp_kernel.multiply_vector(tmp_arr.get(), M, prod_Ax, n_s, gctl::Trans);
|
||||
return;
|
||||
}
|
||||
|
||||
//定义共轭梯度监控函数
|
||||
int Prog(void* instance, const lcg_float* m, const lcg_float converge, const lcg_para* param, const int n_s, const int k)
|
||||
{
|
||||
std::clog << "Iteration-times: " << k << "\tconvergence: " << converge << std::endl;
|
||||
if (converge > param->epsilon) std::clog << "\033[1A\033[K";
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
srand(time(0));
|
||||
// 添加一些大数
|
||||
int tmp_id, tmp_size;
|
||||
double tmp_val;
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
tmp_size = gctl::random(25, 35);
|
||||
for (int j = 0; j < tmp_size; j++)
|
||||
{
|
||||
tmp_id = gctl::random(0, N);
|
||||
tmp_val = gctl::random(-10.0, 10.0);
|
||||
|
||||
kernel[i][tmp_id] = tmp_val;
|
||||
sp_kernel.insert(i, tmp_id, tmp_val);
|
||||
}
|
||||
}
|
||||
|
||||
// 生成一组正演解
|
||||
gctl::array<double> fm(N);
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
fm[i] = gctl::random(1.0, 2.0);
|
||||
}
|
||||
|
||||
// 计算共轭梯度B项
|
||||
gctl::array<double> B(N);
|
||||
sp_kernel.multiply_vector(fm.get(), N, tmp_arr.get(), M);
|
||||
sp_kernel.multiply_vector(tmp_arr.get(), M, B.get(), N, gctl::Trans);
|
||||
/*
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
tmp_arr[i] = 0.0;
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
tmp_arr[i] += kernel[i][j]*fm[j];
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
B[j] = 0.0;
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
B[j] += kernel[i][j]*tmp_arr[i];
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/********************准备工作完成************************/
|
||||
lcg_para self_para = lcg_default_parameters();
|
||||
self_para.max_iterations = 1000;
|
||||
self_para.epsilon = 1e-10;
|
||||
|
||||
// 声明两组解
|
||||
gctl::array<double> m(N, 0.0);
|
||||
gctl::array<double> m_sp(N, 0.0);
|
||||
|
||||
clock_t start = clock();
|
||||
int ret = lcg_solver(CalAx, Prog, m.get(), B.get(), N, &self_para, NULL, LCG_CG);
|
||||
clock_t end = clock();
|
||||
if (ret < 0) lcg_error_str(ret);
|
||||
std::cout << "array2d's time: " << 1000.0*(end - start)/(double)CLOCKS_PER_SEC << " ms" << std::endl;
|
||||
|
||||
start = clock();
|
||||
ret = lcg_solver(CalAx_Spmat, Prog, m_sp.get(), B.get(), N, &self_para, NULL, LCG_CG);
|
||||
if (ret < 0) lcg_error_str(ret);
|
||||
end = clock();
|
||||
std::cout << "spmat's time: " << 1000.0*(end - start)/(double)CLOCKS_PER_SEC << " ms" << std::endl;
|
||||
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
std::cout << fm[i] << " " << m[i] << " " << m_sp[i] << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
47
examples/sptr_ex.cpp
Normal file
47
examples/sptr_ex.cpp
Normal 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 "gctl/core.h"
|
||||
|
||||
#include "iostream"
|
||||
#include "memory"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::smart_ptr<gctl::array<double>> a_ptr = new gctl::array<double>(10, 1.0);
|
||||
for (int i = 0; i < a_ptr->size(); ++i)
|
||||
{
|
||||
std::cout << a_ptr->at(i) << std::endl;
|
||||
}
|
||||
|
||||
std::unique_ptr<gctl::array<double>> b_ptr(new gctl::array<double>(10, 2.0));
|
||||
for (int i = 0; i < b_ptr->size(); ++i)
|
||||
{
|
||||
std::cout << b_ptr->at(i) << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
67
examples/stream_ex.cpp
Normal file
67
examples/stream_ex.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
|
||||
struct people
|
||||
{
|
||||
std::string name, gender;
|
||||
int age;
|
||||
double weight;
|
||||
|
||||
friend std::istream &operator >>(std::istream & os, people &p)
|
||||
{
|
||||
os >> p.name >> p.age >> p.gender >> p.weight;
|
||||
return os;
|
||||
}
|
||||
|
||||
friend std::ostream &operator <<(std::ostream & os, people &p)
|
||||
{
|
||||
os << p.name << p.age << p.gender << p.weight;
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
std::vector<people> group;
|
||||
gctl::read_text2vector("data/out/table_sample.txt", group);
|
||||
|
||||
for (int i = 0; i < group.size(); ++i)
|
||||
{
|
||||
std::cout << group[i] << std::endl;
|
||||
}
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
55
examples/stream_template_ex.cpp
Normal file
55
examples/stream_template_ex.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/utility.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
std::string in = "This is a test string.";
|
||||
std::string w;
|
||||
std::stringstream out;
|
||||
gctl::type2ss(in, out);
|
||||
while (out >> w)
|
||||
{
|
||||
std::cout << w << std::endl;
|
||||
}
|
||||
|
||||
in = "24.5";
|
||||
double out_d;
|
||||
gctl::str2type(in, out_d);
|
||||
std::cout << out_d << std::endl;
|
||||
|
||||
in = "This,is,a,test,string.";
|
||||
std::vector<std::string> word;
|
||||
gctl::parse_string_to_vector(in, ',', word);
|
||||
for (int i = 0; i < word.size(); i++)
|
||||
{
|
||||
std::cout << word[i] << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
83
examples/surfer_io_ex.cpp
Normal file
83
examples/surfer_io_ex.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// prepare data
|
||||
gctl::_2d_vector input_topo;
|
||||
gctl::text_descriptor desc;
|
||||
gctl::read_text2vector2d("data/topo.txt", input_topo, desc);
|
||||
|
||||
gctl::matrix<double> test_d(101, 101, 0.0);
|
||||
for (int i = 0; i < 101; i++)
|
||||
{
|
||||
for (int j = 0; j < 101; j++)
|
||||
{
|
||||
test_d[i][j] = input_topo[i*101+j][2];
|
||||
}
|
||||
}
|
||||
|
||||
// save grid
|
||||
gctl::save_surfer6_grid("data/out/sample_grid_surfer6", test_d, 0, 1000, 0, 1000, NAN, NAN, gctl::Surfer6Binary);
|
||||
|
||||
// read grid
|
||||
gctl::matrix<double> in_data;
|
||||
int xnum, ynum;
|
||||
double xmin, xmax, ymin, ymax, zmin, zmax;
|
||||
gctl::read_surfer6_grid("data/sample_grid_surfer6", in_data, xnum, ynum, xmin, xmax, ymin, ymax, zmin, zmax, gctl::Surfer6Binary);
|
||||
|
||||
// show info
|
||||
std::cout << xmin << " " << xmax << std::endl;
|
||||
std::cout << ymin << " " << ymax << std::endl;
|
||||
std::cout << zmin << " " << zmax << std::endl;
|
||||
for (int j = 0; j < in_data.col_size(); j++)
|
||||
{
|
||||
std::cout << in_data[in_data.row_size()-1][j] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
// save surfer7 grid
|
||||
gctl::save_surfer7_grid("data/sample_grid_surfer7", test_d, 100, 120, 10, 8);
|
||||
|
||||
// read surfer7 grid
|
||||
double dx, dy, null_val;
|
||||
gctl::read_surfer7_grid("data/sample_grid_surfer7", in_data, xmin, ymin, dx, dy, zmin, zmax, null_val);
|
||||
|
||||
// show info
|
||||
std::cout << xmin << " " << ymin << std::endl;
|
||||
std::cout << dx << " " << dy << std::endl;
|
||||
std::cout << zmin << " " << zmax << std::endl;
|
||||
for (int j = 0; j < in_data.col_size(); j++)
|
||||
{
|
||||
std::cout << in_data[in_data.row_size()-1][j] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
return 0;
|
||||
}
|
||||
110
examples/svd_ex.cpp
Normal file
110
examples/svd_ex.cpp
Normal file
@@ -0,0 +1,110 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/algorithm.h"
|
||||
#include "gctl/optimization.h"
|
||||
#include "iostream"
|
||||
#include "iomanip"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::setw;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::matrix<double> A(4, 3);
|
||||
for (int i = 0; i < A.row_size(); i++)
|
||||
{
|
||||
for (int j = 0; j < A.col_size(); j++)
|
||||
{
|
||||
A[i][j] = 3*(i+1) + j - 2;
|
||||
}
|
||||
}
|
||||
A[3][1] = 1;
|
||||
|
||||
cout<<"A(" << A.row_size() << ", " << A.col_size() << ") = " <<endl;
|
||||
for(int i=0;i<A.row_size();i++){
|
||||
for(int j=0;j<A.col_size();j++){
|
||||
cout<<setw(12)<<A[i][j]<<' ';
|
||||
}
|
||||
cout<<endl;
|
||||
}
|
||||
cout<<endl;
|
||||
|
||||
gctl::svd svdd;
|
||||
svdd.decompose(A);
|
||||
|
||||
cout<<"U(" << svdd.U.row_size() << ", " << svdd.U.col_size() << ") = " <<endl;
|
||||
for(int i=0;i<svdd.U.row_size();i++){
|
||||
for(int j=0;j<svdd.U.col_size();j++){
|
||||
cout<<setw(12)<<svdd.U[i][j]<<' ';
|
||||
}
|
||||
cout<<endl;
|
||||
}
|
||||
cout<<endl;
|
||||
|
||||
cout<<"S(" << svdd.S.size() << ") = " << endl;
|
||||
for(int i=0;i<svdd.S.size();i++){
|
||||
cout<<setw(7)<<svdd.S[i]<<' ';
|
||||
}
|
||||
cout<<endl;
|
||||
|
||||
cout<<"V(" << svdd.V.row_size() << ", " << svdd.V.col_size() << ") = " <<endl;
|
||||
for(int i=0;i<svdd.V.row_size();i++){
|
||||
for(int j=0;j<svdd.V.col_size();j++){
|
||||
cout<<setw(12)<<svdd.V[i][j]<<' ';
|
||||
}
|
||||
cout<<endl;
|
||||
}
|
||||
|
||||
int sig_num = svdd.get_singular_number();
|
||||
double tmp_d;
|
||||
gctl::array<double> tmp(sig_num);
|
||||
cout<<"U^T * S * V(" << A.row_size() << ", " << A.col_size() << ") = " <<endl;
|
||||
for(int i=0;i<A.row_size();i++)
|
||||
{
|
||||
for (int k = 0; k < sig_num; k++)
|
||||
{
|
||||
tmp[k] = svdd.U[k][i] * svdd.S[k];
|
||||
}
|
||||
|
||||
for(int j=0;j<A.col_size();j++)
|
||||
{
|
||||
tmp_d = 0.0;
|
||||
for (int k = 0; k < sig_num; k++)
|
||||
{
|
||||
tmp_d += tmp[k] * svdd.V[k][j];
|
||||
}
|
||||
cout<<setw(12)<<tmp_d<<' ';
|
||||
}
|
||||
cout<<endl;
|
||||
}
|
||||
cout<<endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
82
examples/tensor_ex.cpp
Normal file
82
examples/tensor_ex.cpp
Normal 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 "gctl/core.h"
|
||||
#include "gctl/geometry.h"
|
||||
|
||||
namespace {
|
||||
// show elements
|
||||
void show_tensor(const gctl::tensor &a, std::string t_name)
|
||||
{
|
||||
std::cout << t_name << " = " << std::endl;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
std::cout << a.at(i,j) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// declare two tensors
|
||||
gctl::tensor a, b;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
a[i][j] = j+1;
|
||||
b[i][j] = i+1;
|
||||
}
|
||||
}
|
||||
|
||||
show_tensor(a, "a");
|
||||
show_tensor(b, "b");
|
||||
|
||||
// test calculations
|
||||
gctl::tensor c = a + b;
|
||||
show_tensor(c, "a+b");
|
||||
|
||||
gctl::tensor d = a - b;
|
||||
show_tensor(d, "a-b");
|
||||
|
||||
gctl::tensor e = a * b;
|
||||
show_tensor(e, "a*b");
|
||||
|
||||
gctl::point3dc f(1.0, 2.0, 3.0);
|
||||
gctl::point3dc g = a * f;
|
||||
gctl::point3dc h = f * a;
|
||||
|
||||
std::cout << "a*f = " << g.x << " " << g.y << " " << g.z << std::endl;
|
||||
std::cout << "f*a = " << h.x << " " << h.y << " " << h.z << std::endl;
|
||||
return 0;
|
||||
}
|
||||
63
examples/tetra_neighbor_ex.cpp
Normal file
63
examples/tetra_neighbor_ex.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/geometry.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
array<vertex3dc> nodes;
|
||||
array<tetrahedron> eles;
|
||||
|
||||
gmshio fio;
|
||||
fio.init_file("data/sample_tet", Input);
|
||||
fio.set_packed(NotPacked, Input);
|
||||
fio.read_mesh(eles, nodes);
|
||||
|
||||
size_t n_num = nodes.size();
|
||||
geometry3d::sort_tet_neighbor(eles, &n_num);
|
||||
|
||||
for (size_t i = 0; i < eles.size(); i++)
|
||||
{
|
||||
std::clog << i << " ";
|
||||
for (size_t j = 0; j < 4; j++)
|
||||
{
|
||||
if (eles[i].neigh[j] != nullptr) std::clog << eles[i].neigh[j]->id << " ";
|
||||
else std::clog << "-1 ";
|
||||
}
|
||||
std::clog << "\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
77
examples/text_io_ex.cpp
Normal file
77
examples/text_io_ex.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Read space separated mixed table to a 2D string matrix, then save to a comma separated csv file
|
||||
gctl::_2s_vector table;
|
||||
gctl::text_descriptor desc;
|
||||
|
||||
gctl::read_text2vector2d("data/table_sample.txt", table, desc);
|
||||
gctl::save_vector2d2text("data/out/table_sample_out.csv", table, ',');
|
||||
|
||||
// Read different columns into individual vectors that are of different types
|
||||
std::vector<double> weights;
|
||||
std::vector<std::string> names;
|
||||
|
||||
gctl::read_text2vectors("data/out/table_sample_out.csv", "0,3", ',', '#', 0, names, weights);
|
||||
|
||||
for (int i = 0; i < names.size(); ++i)
|
||||
{
|
||||
std::cout << names[i] << " weights " << weights[i] << " kg." << std::endl;
|
||||
}
|
||||
|
||||
// Save vectors to a text file as individual columns
|
||||
gctl::save_vectors2text("data/table_sample_out.txt", ' ', '#', nullptr, nullptr,
|
||||
names, weights);
|
||||
|
||||
// Read a user-defined structure. One need to reload the >> operator for this to work
|
||||
// Check the function's instruction for more information
|
||||
std::vector<gctl::point3dc> pos;
|
||||
gctl::read_text2vectors("data/random_topo.xyz", "0", ' ', '#', 0, pos);
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
std::cout << pos[i] << std::endl;
|
||||
}
|
||||
std::cout << "Size: " << pos.size() << " ============" << std::endl;
|
||||
|
||||
//gctl::point3dc mean;
|
||||
//mean = gctl::average(pos, gctl::point3dc(0, 0, 0));
|
||||
//std::cout << mean << std::endl;
|
||||
|
||||
gctl::array<gctl::point3dc> pos2;
|
||||
gctl::read_text2array("data/random_topo.xyz", pos2);
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
std::cout << pos2[i] << std::endl;
|
||||
}
|
||||
std::cout << "Size: " << pos2.size() << " ============" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
74
examples/track_ellipse_ex.cpp
Normal file
74
examples/track_ellipse_ex.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "vector"
|
||||
|
||||
using namespace gctl;
|
||||
using namespace gctl::geometry3d;
|
||||
using std::endl;
|
||||
|
||||
typedef std::vector<point3dc> point3dc_array;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
//初始化两个球坐标点 比较容易设置参数
|
||||
point3ds as(1000, 30, 40), bs(800, 45, 60);
|
||||
//得到直角坐标点
|
||||
point3dc ac = as.s2c(), bc = bs.s2c();
|
||||
//等角间隔计算ac与bc之间的点的坐标
|
||||
point3dc_array mid_points;
|
||||
//把起点添加到数组
|
||||
mid_points.push_back(ac);
|
||||
//计算椭圆上点的坐标
|
||||
for (double ang = 0.001; ang < 2*GCTL_Pi; ang += 0.001)
|
||||
{
|
||||
mid_points.push_back(track_ellipse(ac,bc,ang));
|
||||
}
|
||||
//把终点添加到数组
|
||||
mid_points.push_back(bc);
|
||||
|
||||
//输出到文件
|
||||
std::ofstream ofile;
|
||||
char oname[1024] = "data/out/track_ellipse_output";
|
||||
try
|
||||
{
|
||||
open_outfile(ofile, oname, ".txt");
|
||||
}
|
||||
catch(std::string err_str)
|
||||
{
|
||||
GCTL_ShowWhatError(err_str, GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < mid_points.size(); i++)
|
||||
{
|
||||
ofile << mid_points[i].x << " " << mid_points[i].y << " " << mid_points[i].z << endl;
|
||||
}
|
||||
ofile.close();
|
||||
return 0;
|
||||
}
|
||||
140
examples/traveltime_tet3d_ex.cpp
Normal file
140
examples/traveltime_tet3d_ex.cpp
Normal file
@@ -0,0 +1,140 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/seismic.h"
|
||||
|
||||
#include "cmath"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string mesh_file = "../data/fmm3d/cube.1";
|
||||
|
||||
// read triangular mesh's vertice and elements
|
||||
array<vertex3dc> tetgen_node;
|
||||
array<tetrahedron> tetgen_tet;
|
||||
read_Tetgen_node(mesh_file, tetgen_node);
|
||||
read_Tetgen_element(mesh_file, tetgen_tet, tetgen_node);
|
||||
|
||||
array<fmm_vertex3dc> fmm_node;
|
||||
array<fmm_tetrahedron> fmm_ele;
|
||||
array<double> node_time(tetgen_node.size(), GCTL_BDL_MAX);
|
||||
|
||||
array<double> mesh_slow(fmm_ele.size(), 1.0);
|
||||
create_fmm_mesh(tetgen_node, tetgen_tet, node_time, mesh_slow, fmm_node, fmm_ele);
|
||||
|
||||
std::ofstream outfile;
|
||||
gctl::open_outfile(outfile, mesh_file, ".msh");
|
||||
save2gmsh(outfile, tetgen_tet, tetgen_node, gctl::NotPacked);
|
||||
|
||||
// declare a source point and calculate
|
||||
seis_point3d_tet source;
|
||||
source.set(point3dc(5.0, 250.0, 250.0), 1);
|
||||
source.find_host_element(fmm_ele.get(), fmm_ele.size());
|
||||
|
||||
// assign initial tags for elements
|
||||
source.host_ele->tag = 1;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
source.host_ele->vert[i]->tag = 2;
|
||||
*source.host_ele->vert[i]->time_ptr = *source.host_ele->slow_ptr *
|
||||
distance(*source.host_ele->vert[i], source);
|
||||
}
|
||||
|
||||
// declare a source point and calculate
|
||||
seis_point3d_tet receiver;
|
||||
receiver.set(point3dc(995.0, 250.0, 495.0), 1);
|
||||
receiver.find_host_element(fmm_ele.get(), fmm_ele.size());
|
||||
|
||||
std::vector<fmm_vertex3dc*> rece_node;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
rece_node.push_back(receiver.host_ele->vert[i]);
|
||||
}
|
||||
|
||||
array<double> jn_temp(fmm_ele.size());
|
||||
array<double> time_ele_grad(fmm_ele.size(), 0.0);
|
||||
sparray2d<double> jn(fmm_node.size(), fmm_ele.size(), 0.0);
|
||||
std::vector<fmm_vertex3dc*> wave_front;
|
||||
std::vector<fmm_vertex3dc*> march_record;
|
||||
|
||||
double temp_val;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
//初始化前四个梯度值
|
||||
//对元素的慢度求梯度即为源到顶点的距离
|
||||
temp_val= distance(*source.host_ele->vert[i], source);
|
||||
jn.at(source.host_ele->vert[i]->id)->set(source.host_ele->id, temp_val);
|
||||
}
|
||||
|
||||
// calculate
|
||||
clock_t start = clock();
|
||||
fmm3d_forward_tetrahedron(&fmm_node, &fmm_ele, &wave_front, &march_record, &rece_node, &jn, &jn_temp);
|
||||
clock_t end = clock();
|
||||
std::cout << "FMM's time: " << 1000.0*(end - start)/(double)CLOCKS_PER_SEC << " ms" << std::endl;
|
||||
|
||||
double r[4], w_sum;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
r[i] = distance(*receiver.host_ele->vert[i], receiver) + GCTL_ZERO;
|
||||
}
|
||||
w_sum = 1.0/r[0] + 1.0/r[1] + 1.0/r[2] + 1.0/r[3];
|
||||
|
||||
receiver.time = *receiver.host_ele->vert[0]->time_ptr/(r[0]*w_sum) +
|
||||
*receiver.host_ele->vert[1]->time_ptr/(r[1]*w_sum) +
|
||||
*receiver.host_ele->vert[2]->time_ptr/(r[2]*w_sum) +
|
||||
*receiver.host_ele->vert[3]->time_ptr/(r[3]*w_sum);
|
||||
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
jn.at(receiver.host_ele->vert[i]->id)->export_dense(time_ele_grad, 1.0/(r[i]*w_sum), gctl::AppendVal);
|
||||
}
|
||||
|
||||
for (int i = 0; i < node_time.size(); i++)
|
||||
{
|
||||
if (node_time[i] == GCTL_BDL_MAX)
|
||||
{
|
||||
node_time[i] = NAN;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Receiver's time = " << receiver.time << std::endl;
|
||||
save_gmsh_data(outfile, "Arrival time", node_time.get(), node_time.size(), NodeData, gctl::NotPacked);
|
||||
save_gmsh_data(outfile, "receiver's gradient", time_ele_grad.get(), time_ele_grad.size(), ElemData, gctl::NotPacked);
|
||||
outfile.close();
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
108
examples/traveltime_tet3d_ex2.cpp
Normal file
108
examples/traveltime_tet3d_ex2.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/seismic.h"
|
||||
|
||||
#include "cmath"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string mesh_file = "../data/fmm3d/cube.1";
|
||||
|
||||
// read triangular mesh's vertice and elements
|
||||
array<vertex3dc> tetgen_node;
|
||||
array<tetrahedron> tetgen_tet;
|
||||
read_Tetgen_node(mesh_file, tetgen_node);
|
||||
read_Tetgen_element(mesh_file, tetgen_tet, tetgen_node);
|
||||
|
||||
array<fmm_vertex3dc> fmm_node;
|
||||
array<fmm_tetrahedron> fmm_ele;
|
||||
array<double> node_time(tetgen_node.size(), GCTL_BDL_MAX);
|
||||
|
||||
array<double> mesh_slow(fmm_ele.size(), 1.0);
|
||||
create_fmm_mesh(tetgen_node, tetgen_tet, node_time, mesh_slow, fmm_node, fmm_ele);
|
||||
|
||||
std::ofstream outfile;
|
||||
gctl::open_outfile(outfile, mesh_file, ".msh");
|
||||
save2gmsh(outfile, tetgen_tet, tetgen_node, gctl::NotPacked);
|
||||
|
||||
point3dc cen;
|
||||
for (int i = 0; i < fmm_ele.size(); i++)
|
||||
{
|
||||
cen = 0.25*(*fmm_ele[i].vert[0] + *fmm_ele[i].vert[1] +
|
||||
*fmm_ele[i].vert[2] + *fmm_ele[i].vert[3]);
|
||||
if (cen.x > 400 && cen.x < 600 && cen.y > 300 && cen.y < 400 && cen.z > 300 && cen.z < 400)
|
||||
{
|
||||
mesh_slow[i] = 0.25;
|
||||
}
|
||||
}
|
||||
|
||||
// declare a source point and calculate
|
||||
seis_point3d_tet source;
|
||||
source.set(point3dc(5.0, 250.0, 250.0), 1);
|
||||
|
||||
// declare a source point and calculate
|
||||
seis_point3d_tet receiver;
|
||||
receiver.set(point3dc(995.0, 250.0, 495.0), 1);
|
||||
|
||||
// setup temporary arrays
|
||||
array<double> jn_temp(fmm_ele.size());
|
||||
array<double> time_ele_grad(fmm_ele.size(), 0.0);
|
||||
sparray2d<double> jn(fmm_node.size(), fmm_ele.size(), 0.0);
|
||||
std::vector<fmm_vertex3dc*> wave_front;
|
||||
std::vector<fmm_vertex3dc*> march_record;
|
||||
|
||||
// calculate
|
||||
clock_t start = clock();
|
||||
source2receiver_direct(&fmm_node, &fmm_ele, &source, &receiver, &time_ele_grad, &wave_front, &march_record, &jn, &jn_temp);
|
||||
clock_t end = clock();
|
||||
std::cout << "FMM's time: " << 1000.0*(end - start)/(double)CLOCKS_PER_SEC << " ms" << std::endl;
|
||||
|
||||
for (int i = 0; i < node_time.size(); i++)
|
||||
{
|
||||
if (node_time[i] == GCTL_BDL_MAX)
|
||||
{
|
||||
node_time[i] = NAN;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Receiver's time = " << receiver.time << std::endl;
|
||||
save_gmsh_data(outfile, "Arrival time", node_time.get(), node_time.size(), NodeData, gctl::NotPacked);
|
||||
save_gmsh_data(outfile, "receiver's gradient", time_ele_grad.get(), time_ele_grad.size(), ElemData, gctl::NotPacked);
|
||||
outfile.close();
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
94
examples/traveltime_tri2d_ex.cpp
Normal file
94
examples/traveltime_tri2d_ex.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/seismic.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string mesh_file = "../data/fmm2d/sample_mesh.1";
|
||||
std::string mod_file = "../data/fmm2d/sample_model.txt";
|
||||
|
||||
// read triangular mesh's vertice and elements
|
||||
array<vertex2dc> mesh_node;
|
||||
array<triangle2d> mesh_ele;
|
||||
read_Triangle_node(mesh_file, mesh_node);
|
||||
read_Triangle_element(mesh_file, mesh_ele, mesh_node);
|
||||
|
||||
array<fmm_vertex2dc> fmm_node;
|
||||
array<fmm_triangle2d> fmm_ele;
|
||||
array<double> node_time(mesh_node.size());
|
||||
|
||||
array<double> mesh_slow;
|
||||
text_descriptor desc;
|
||||
desc.head_num_ = 1;
|
||||
|
||||
get_data_column(mod_file, {&mesh_slow}, {1}, desc);
|
||||
create_fmm_mesh(mesh_node, mesh_ele, node_time, mesh_slow, fmm_node, fmm_ele);
|
||||
|
||||
// declare a source point and calculate
|
||||
seis_point2d_tri source_1;
|
||||
source_1.set(point2dc(5.0, 10.0), 1);
|
||||
|
||||
// declare a receiver point and a gradient array and calculate
|
||||
seis_point2d_tri receiver_1;
|
||||
receiver_1.set(point2dc(235.0, 90.0), 1);
|
||||
|
||||
array<double> time_ele_grad(fmm_ele.size());
|
||||
|
||||
// calculate
|
||||
source2receiver_direct(&fmm_node, &fmm_ele, &source_1, &receiver_1, &time_ele_grad);
|
||||
|
||||
for (int i = 0; i < node_time.size(); i++)
|
||||
{
|
||||
if (node_time[i] == GCTL_BDL_MAX)
|
||||
{
|
||||
node_time[i] = NAN;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "receiver's time = " << receiver_1.time << std::endl;
|
||||
|
||||
// save to gmsh file
|
||||
std::ofstream outfile;
|
||||
open_outfile(outfile, mesh_file, ".msh");
|
||||
save2gmsh(outfile, mesh_ele, mesh_node, gctl::NotPacked);
|
||||
save_gmsh_data(outfile, "First arrival time", node_time.get(), node_time.size(), NodeData, gctl::NotPacked);
|
||||
save_gmsh_data(outfile, "Elements' gradient", time_ele_grad.get(), time_ele_grad.size(), ElemData, gctl::NotPacked);
|
||||
outfile.close();
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
104
examples/traveltime_tri2d_ex2.cpp
Normal file
104
examples/traveltime_tri2d_ex2.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/seismic.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string mesh_file = "../data/fmm2d/sample_mesh.1";
|
||||
std::string mod_file = "../data/fmm2d/sample_model.txt";
|
||||
|
||||
// read triangular mesh's vertice and elements
|
||||
array<vertex2dc> mesh_node;
|
||||
array<triangle2d> mesh_ele;
|
||||
array<int> node_boundary;
|
||||
|
||||
read_Triangle_node(mesh_file, mesh_node, gctl::Packed, &node_boundary);
|
||||
read_Triangle_element(mesh_file, mesh_ele, mesh_node);
|
||||
|
||||
array<fmm_vertex2dc> fmm_node;
|
||||
array<fmm_triangle2d> fmm_ele;
|
||||
array<double> node_time(mesh_node.size(), GCTL_BDL_MAX);
|
||||
|
||||
// save to gmsh file
|
||||
std::ofstream outfile;
|
||||
open_outfile(outfile, mesh_file, ".msh");
|
||||
save2gmsh(outfile, mesh_ele, mesh_node, gctl::NotPacked);
|
||||
|
||||
array<double> mesh_slow;
|
||||
text_descriptor desc;
|
||||
desc.head_num_ = 1;
|
||||
|
||||
get_data_column(mod_file, {&mesh_slow}, {1}, desc);
|
||||
create_fmm_mesh(mesh_node, mesh_ele, node_time, mesh_slow, fmm_node, fmm_ele);
|
||||
|
||||
for (int i = 0; i < fmm_node.size(); i++)
|
||||
{
|
||||
if (node_boundary[i] && fabs(mesh_node[i].x) < 1e-6 )
|
||||
{
|
||||
*fmm_node.at(i).time_ptr = 0.0;
|
||||
fmm_node.at(i).tag = 2;
|
||||
}
|
||||
}
|
||||
|
||||
array<double> tmp_jn(fmm_ele.size());
|
||||
sparray2d<double> jn(fmm_node.size(), fmm_ele.size(), 0.0);
|
||||
std::vector<fmm_vertex2dc*> wave_front;
|
||||
std::vector<fmm_vertex2dc*> march_record;
|
||||
|
||||
clock_t start = clock();
|
||||
fmm2d_forward_triangle(&fmm_node, &fmm_ele, &wave_front, &march_record, nullptr, &jn, &tmp_jn);
|
||||
clock_t end = clock();
|
||||
std::cout << "FMM's time: " << 1000.0*(end - start)/(double)CLOCKS_PER_SEC << " ms" << std::endl;
|
||||
|
||||
for (int i = 0; i < node_time.size(); i++)
|
||||
{
|
||||
if (node_time[i] == GCTL_BDL_MAX)
|
||||
{
|
||||
node_time[i] = NAN;
|
||||
}
|
||||
}
|
||||
|
||||
array<double> node_grad(fmm_ele.size(), 0.0);
|
||||
jn.at(4451)->export_dense(node_grad);
|
||||
|
||||
save_gmsh_data(outfile, "Arrival time", node_time.get(), node_time.size(), NodeData, gctl::NotPacked);
|
||||
save_gmsh_data(outfile, "Model gradient", node_grad.get(), node_grad.size(), ElemData, gctl::NotPacked);
|
||||
outfile.close();
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
107
examples/traveltime_tri2d_ex3.cpp
Normal file
107
examples/traveltime_tri2d_ex3.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/seismic.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string mesh_file = "../data/fmm2d/sample_mesh.1";
|
||||
std::string mod_file = "../data/fmm2d/sample_model.txt";
|
||||
// read triangular mesh's vertice and elements
|
||||
array<vertex2dc> mesh_node;
|
||||
array<triangle2d> mesh_ele;
|
||||
array<int> node_boundary;
|
||||
read_Triangle_node(mesh_file, mesh_node, gctl::Packed, &node_boundary);
|
||||
read_Triangle_element(mesh_file, mesh_ele, mesh_node);
|
||||
|
||||
array<fmm_vertex2dc> fmm_node;
|
||||
array<fmm_triangle2d> fmm_ele;
|
||||
array<double> node_time(mesh_node.size());
|
||||
|
||||
array<double> mesh_slow;
|
||||
text_descriptor desc;
|
||||
desc.head_num_ = 1;
|
||||
|
||||
get_data_column(mod_file, {&mesh_slow}, {1}, desc);
|
||||
create_fmm_mesh(mesh_node, mesh_ele, node_time, mesh_slow, fmm_node, fmm_ele);
|
||||
|
||||
// 使用外部临时数组与向量
|
||||
array<bool> temp_index(fmm_node.size());
|
||||
array<double> jn_temp(fmm_ele.size());
|
||||
array<double> time_ele_grad(fmm_ele.size());
|
||||
sparray2d<double> jn(fmm_node.size(), fmm_ele.size(), 0.0);
|
||||
std::vector<fmm_vertex2dc*> wave_front;
|
||||
std::vector<fmm_vertex2dc*> march_record;
|
||||
|
||||
// save to gmsh file
|
||||
std::ofstream outfile;
|
||||
open_outfile(outfile, mesh_file, ".msh");
|
||||
save2gmsh(outfile, mesh_ele, mesh_node, gctl::NotPacked);
|
||||
|
||||
// declare a new seismic point
|
||||
seis_point2d_tri source_1;
|
||||
source_1.set(point2dc(40.0, 98.0), 0);
|
||||
|
||||
seis_point2d_tri receiver_1;
|
||||
// declare a receiver point and a gradient array and calculate
|
||||
receiver_1.set(point2dc(125.0, 98.0), 1);
|
||||
|
||||
std::vector<fmm_vertex2dc*> refl_nodes;
|
||||
for (int i = 0; i < fmm_node.size(); i++)
|
||||
{
|
||||
if (node_boundary[i] && fabs(fmm_node[i].y) < 1e-6)
|
||||
{
|
||||
refl_nodes.push_back(fmm_node.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
source2receiver_reflect(&fmm_node, &fmm_ele, &source_1, &receiver_1, &refl_nodes,
|
||||
&time_ele_grad, &wave_front, &march_record, &jn, &jn_temp, &temp_index);
|
||||
|
||||
std::cout << "receiver's time = " << receiver_1.time << std::endl;
|
||||
save_gmsh_data(outfile, "Elements' gradient", time_ele_grad.get(), time_ele_grad.size(), ElemData, gctl::NotPacked);
|
||||
|
||||
receiver_1.set(point2dc(235.0, 98.0), 1);
|
||||
source2receiver_reflect(&fmm_node, &fmm_ele, &source_1, &receiver_1, &refl_nodes,
|
||||
&time_ele_grad, &wave_front, &march_record, &jn, &jn_temp, &temp_index);
|
||||
|
||||
std::cout << "receiver's time = " << receiver_1.time << std::endl;
|
||||
save_gmsh_data(outfile, "Elements' gradient 2", time_ele_grad.get(), time_ele_grad.size(), ElemData, gctl::NotPacked);
|
||||
outfile.close();
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
80
examples/triangle_io_ex.cpp
Normal file
80
examples/triangle_io_ex.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::array<int> mesh_mark;
|
||||
gctl::array<gctl::vertex2dc> mesh_node;
|
||||
gctl::array<gctl::triangle2d> mesh_triangle;
|
||||
|
||||
try
|
||||
{
|
||||
gctl::read_Triangle_node("data/sample_mesh", mesh_node, gctl::Packed, &mesh_mark);
|
||||
gctl::read_Triangle_element("data/sample_mesh", mesh_triangle, mesh_node);
|
||||
|
||||
gctl::matrix<double> mesh_attri(mesh_node.size(), 3);
|
||||
for (int i = 0; i < mesh_node.size(); i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
mesh_attri[i][j] = -1.0 + j;
|
||||
}
|
||||
}
|
||||
|
||||
gctl::matrix<double> ele_attri(mesh_triangle.size(), 3);
|
||||
for (int i = 0; i < mesh_triangle.size(); i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
ele_attri[i][j] = -1.0 + j;
|
||||
}
|
||||
}
|
||||
|
||||
gctl::save_Triangle_node("data/out/sample_out", mesh_node, gctl::NotPacked, &mesh_mark, &mesh_attri);
|
||||
gctl::save_Triangle_element("data/out/sample_out", mesh_triangle, gctl::NotPacked, &ele_attri);
|
||||
|
||||
std::ofstream outfile;
|
||||
gctl::open_outfile(outfile, "data/1", ".msh");
|
||||
gctl::save2gmsh(outfile, mesh_triangle, mesh_node);
|
||||
outfile.close();
|
||||
|
||||
for (int i = 0; i < mesh_mark.size(); i++)
|
||||
{
|
||||
if (mesh_mark[i])
|
||||
std::cout << i << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
72
examples/vector_ex.cpp
Normal file
72
examples/vector_ex.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
|
||||
#include "vector"
|
||||
#include "iostream"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
unsigned int m = 8;
|
||||
unsigned int n = 10;
|
||||
|
||||
std::vector<double> A;
|
||||
A.resize(n);
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
A[i] = 1.21 * i;
|
||||
}
|
||||
|
||||
gctl::array<double> B;
|
||||
B.import_vector(A);
|
||||
|
||||
for (int i = 0; i < B.size(); i++)
|
||||
std::cout << B.at(i) << std::endl;
|
||||
|
||||
gctl::matrix<double> C(m, n);
|
||||
for (int i = 0; i < m; i++)
|
||||
{
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
C[i][j] = i*10 + j*1.1;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::vector<double> > D;
|
||||
C.copy_to(D);
|
||||
for (int i = 0; i < m; i++)
|
||||
{
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
std::cout << D.at(i).at(j) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
37
examples/wavelet_ex.cpp
Normal file
37
examples/wavelet_ex.cpp
Normal 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 "gctl/mesh.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
gctl::regular_grid rgd;
|
||||
rgd.load_netcdf_grid("data/wavelet_sample", gctl::NodeData, "x", "y");
|
||||
rgd.wavelet("z", "db2", 3, true);
|
||||
rgd.save_netcdf_grid("data/out/wavelet_sample_out", gctl::NodeData);
|
||||
return 0;
|
||||
}
|
||||
64
examples/xyz_io_ex.cpp
Normal file
64
examples/xyz_io_ex.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "gctl/core.h"
|
||||
#include "gctl/io.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
gctl::array<gctl::point3dc> in_point;
|
||||
gctl::text_descriptor desc;
|
||||
gctl::get_xyz_points("data/obs_topo", in_point, desc, ".xyz");
|
||||
|
||||
gctl::array<double> A, B, C;
|
||||
A.resize(in_point.size() - 100, 1.0);
|
||||
B.resize(in_point.size() - 200, -10.0);
|
||||
C.resize(in_point.size() - 500, 2.0);
|
||||
|
||||
std::vector<std::string> head_info(2);
|
||||
head_info[0] = "This is just an example output.";
|
||||
head_info[1] = "data1(mGal) data2(m) data3(nT)";
|
||||
gctl::save_arrays2text("data/obs_topo_out.csv", ',', '#', &head_info, nullptr, A, B, C);
|
||||
|
||||
gctl::_2d_vector in_table;
|
||||
gctl::array<gctl::point3dc> in_point2;
|
||||
gctl::array<double> D, E;
|
||||
|
||||
desc.delimiter_ = ',';
|
||||
gctl::read_text2vector2d("data/obs_topo_out.csv", in_table, desc);
|
||||
gctl::get_xyz_points(in_table, in_point2, "0,1,2");
|
||||
gctl::get_data_column(in_table, {&D, &E}, {4, 5});
|
||||
|
||||
gctl::destroy_vector(in_table);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
std::cout << in_point2[i].x << " " << in_point2[i].y << " "
|
||||
<< in_point2[i].z << " " << D[i] << " " << E[i] << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user