add all
This commit is contained in:
13
src/ai/CMakeLists.txt
Normal file
13
src/ai/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -O3")
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin/examples)
|
||||
|
||||
macro(add_example name)
|
||||
add_executable(${name} ${name}.cpp)
|
||||
target_link_libraries(${name} PUBLIC gctl_ai)
|
||||
endmacro()
|
||||
|
||||
add_example(ex1)
|
||||
add_example(ex2)
|
||||
add_example(ex_mnist)
|
||||
add_example(ex_mnist2)
|
||||
add_example(ex_mnist3)
|
120
src/ai/ex1.cpp
Normal file
120
src/ai/ex1.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/dnn.h"
|
||||
using namespace gctl;
|
||||
|
||||
void data_generator(const matrix<double> &train_obs, matrix<double> &train_tar)
|
||||
{
|
||||
for (int j = 0; j < train_obs.col_size(); j++)
|
||||
{
|
||||
train_tar[0][j] = sqrt(train_obs[0][j]*train_obs[0][j] + train_obs[1][j]*train_obs[1][j]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
// Prepare the data. In this example, we try to learn the sin() function.
|
||||
matrix<double> train_obs(2, 1000), train_tar(1, 1000), pre_obs(2, 10), pre_tar(1, 10), predicts(1, 10);
|
||||
|
||||
unsigned int seed = 101;
|
||||
srand(seed);
|
||||
for (int j = 0; j < 1000; j++)
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
train_obs[i][j] = random(0.0, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < 10; j++)
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
pre_obs[i][j] = random(0.0, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
data_generator(train_obs, train_tar);
|
||||
data_generator(pre_obs, pre_tar);
|
||||
|
||||
dnn my_nn("Ex-1");
|
||||
my_nn.add_hind_layer(2, 100, FullyConnected, Identity);
|
||||
my_nn.add_hind_layer(100, 100, FullyConnected, PReLU);
|
||||
my_nn.add_hind_layer(100, 100, FullyConnected, PReLU);
|
||||
my_nn.add_hind_layer(100, 1, FullyConnected, Identity);
|
||||
my_nn.add_output_layer(RegressionMSE);
|
||||
my_nn.add_train_set(train_obs, train_tar, 200);
|
||||
|
||||
my_nn.show_network();
|
||||
my_nn.init_network(0.0, 0.1, seed);
|
||||
|
||||
sgd_para my_para = my_nn.default_sgd_para();
|
||||
my_nn.train_network(my_para, gctl::ADAM);
|
||||
//lgd_para my_para = my_nn.default_lgd_para();
|
||||
//my_para.flight_times = 5000;
|
||||
//my_para.lambda = 5e-5;
|
||||
//my_para.epsilon = 1e-5;
|
||||
//my_para.batch = 10;
|
||||
//my_nn.train_network(my_para, gctl::LGD);
|
||||
|
||||
my_nn.predict(pre_obs, predicts);
|
||||
|
||||
double diff = 0;
|
||||
for (int i = 0; i < 1; i++)
|
||||
{
|
||||
for (int j = 0; j < 10; j++)
|
||||
{
|
||||
diff = std::max(fabs(predicts[i][j] - pre_tar[i][j]), diff);
|
||||
}
|
||||
}
|
||||
std::clog << "Max difference = " << diff << "\n";
|
||||
/*
|
||||
my_nn.save_network("ex1");
|
||||
|
||||
dnn file_nn("File NN");
|
||||
file_nn.load_network("ex1");
|
||||
file_nn.show_network();
|
||||
file_nn.predict(pre_obs, predicts);
|
||||
|
||||
diff = 0;
|
||||
for (int i = 0; i < 1; i++)
|
||||
{
|
||||
for (int j = 0; j < 10; j++)
|
||||
{
|
||||
diff = std::max(fabs(predicts[i][j] - pre_tar[i][j]), diff);
|
||||
}
|
||||
}
|
||||
std::clog << "Max difference = " << diff << "\n";
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
66
src/ai/ex2.cpp
Normal file
66
src/ai/ex2.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/dnn.h"
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
convolution cnl_layer(0, 3, 10, 10, 3, 3, 2, 2, Valid, ReLU);
|
||||
std::clog << cnl_layer.layer_info() << std::endl;
|
||||
|
||||
matrix<double> t(100, 3);
|
||||
std::clog << "T = \n";
|
||||
for (size_t c = 0; c < 3; c++)
|
||||
{
|
||||
for (size_t i = 0; i < 10; i++)
|
||||
{
|
||||
for (size_t j = 0; j < 10; j++)
|
||||
{
|
||||
t[i*10+j][c] = i*10 + j + 1;
|
||||
std::clog << t[i*10+j][c] << " ";
|
||||
}
|
||||
std::clog << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
array<double> weights(28);
|
||||
for (size_t i = 0; i < 28; i++)
|
||||
{
|
||||
weights[i] = 1.0;
|
||||
}
|
||||
|
||||
cnl_layer.forward_propagation(weights, t);
|
||||
|
||||
const matrix<double> &d = cnl_layer.forward_propagation_data();
|
||||
d.show(std::clog);
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
116
src/ai/ex_mnist.cpp
Normal file
116
src/ai/ex_mnist.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "../data/MNIST/mnist_database.h"
|
||||
#include "../lib/dnn.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
mnist_database data("data/MNIST");
|
||||
|
||||
matrix<double> train_obs(784, 60000), train_lab(10, 60000, 0.0);
|
||||
matrix<double> test_obs(784, 10000), test_lab(10, 10000, 0.0), predicts(10, 10000);
|
||||
|
||||
const std::vector<std::vector<double> > &dt_obs = data.train_images();
|
||||
for (size_t i = 0; i < 60000; i++)
|
||||
{
|
||||
for (size_t j = 0; j < 784; j++)
|
||||
{
|
||||
train_obs[j][i] = dt_obs[i][j]/255.0;
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<std::vector<double> > &dt_obs2 = data.test_images();
|
||||
for (size_t i = 0; i < 10000; i++)
|
||||
{
|
||||
for (size_t j = 0; j < 784; j++)
|
||||
{
|
||||
test_obs[j][i] = dt_obs2[i][j]/255.0;
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<double> &dt_lab = data.train_labels();
|
||||
for (size_t i = 0; i < 60000; i++)
|
||||
{
|
||||
train_lab[dt_lab[i]][i] = 1.0;
|
||||
}
|
||||
|
||||
const std::vector<double> &dt_lab2 = data.test_labels();
|
||||
for (size_t i = 0; i < 10000; i++)
|
||||
{
|
||||
test_lab[dt_lab2[i]][i] = 1.0;
|
||||
}
|
||||
|
||||
dnn my_nn("Ex-MNIST");
|
||||
my_nn.add_hind_layer(784, 800, FullyConnected, PReLU);
|
||||
my_nn.add_hind_layer(800, 10, FullyConnected, SoftMax);
|
||||
my_nn.add_output_layer(MultiClassEntropy);
|
||||
my_nn.add_train_set(train_obs, train_lab, 1000);
|
||||
my_nn.init_network(0.0, 0.1);
|
||||
|
||||
//sgd_para my_para = my_nn.default_sgd_para();
|
||||
//my_para.alpha = 0.01;
|
||||
//my_para.epsilon = 1e-5;
|
||||
//my_nn.train_network(my_para, gctl::ADAM);
|
||||
lgd_para my_para = my_nn.default_lgd_para();
|
||||
my_para.flight_times = 1000;
|
||||
my_para.alpha = 0.08;
|
||||
my_para.beta = 1.8;
|
||||
my_nn.train_network(my_para);
|
||||
|
||||
my_nn.predict(test_obs, predicts);
|
||||
my_nn.save_network("data/saved_networks/mnist_m1");
|
||||
|
||||
int wrong_predicts = 0;
|
||||
int test_id, pre_id;
|
||||
double test_scr, pre_scr;
|
||||
for (size_t j = 0; j < 10000; j++)
|
||||
{
|
||||
test_id = pre_id = 0;
|
||||
test_scr = pre_scr = 0;
|
||||
for (size_t i = 0; i < 10; i++)
|
||||
{
|
||||
if (test_lab[i][j] > test_scr) {test_scr = test_lab[i][j]; test_id = i;}
|
||||
if (predicts[i][j] > pre_scr) {pre_scr = predicts[i][j]; pre_id = i;}
|
||||
}
|
||||
|
||||
if (test_id != pre_id)
|
||||
{
|
||||
wrong_predicts++;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Correct Rate = " << (10000 - wrong_predicts)/100.0 << "%\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
116
src/ai/ex_mnist2.cpp
Normal file
116
src/ai/ex_mnist2.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "../data/MNIST/mnist_database.h"
|
||||
#include "../lib/dnn.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
mnist_database data("data/MNIST");
|
||||
|
||||
matrix<double> train_obs(784, 60000), train_lab(10, 60000, 0.0);
|
||||
matrix<double> test_obs(784, 10000), test_lab(10, 10000, 0.0), predicts(10, 10000);
|
||||
|
||||
const std::vector<std::vector<double> > &dt_obs = data.train_images();
|
||||
for (size_t i = 0; i < 60000; i++)
|
||||
{
|
||||
for (size_t j = 0; j < 784; j++)
|
||||
{
|
||||
train_obs[j][i] = dt_obs[i][j]/255.0;
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<std::vector<double> > &dt_obs2 = data.test_images();
|
||||
for (size_t i = 0; i < 10000; i++)
|
||||
{
|
||||
for (size_t j = 0; j < 784; j++)
|
||||
{
|
||||
test_obs[j][i] = dt_obs2[i][j]/255.0;
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<double> &dt_lab = data.train_labels();
|
||||
for (size_t i = 0; i < 60000; i++)
|
||||
{
|
||||
train_lab[dt_lab[i]][i] = 1.0;
|
||||
}
|
||||
|
||||
const std::vector<double> &dt_lab2 = data.test_labels();
|
||||
for (size_t i = 0; i < 10000; i++)
|
||||
{
|
||||
test_lab[dt_lab2[i]][i] = 1.0;
|
||||
}
|
||||
|
||||
dnn my_nn("Ex-MNIST");
|
||||
my_nn.add_hind_layer(1, 28, 28, 4, 4, 2, 2, Convolution, Same, PReLU);
|
||||
my_nn.add_hind_layer(169, 256, FullyConnected, PReLU);
|
||||
my_nn.add_hind_layer(256, 10, FullyConnected, SoftMax);
|
||||
my_nn.add_output_layer(MultiClassEntropy);
|
||||
my_nn.add_train_set(train_obs, train_lab, 5000);
|
||||
my_nn.init_network(0.0, 0.1);
|
||||
|
||||
sgd_para my_para = my_nn.default_sgd_para();
|
||||
my_para.alpha = 0.01;
|
||||
my_para.epsilon = 1e-5;
|
||||
my_nn.train_network(my_para, gctl::ADAM);
|
||||
//lgd_para my_para = my_nn.default_lgd_para();
|
||||
//my_para.flight_times = 2000;
|
||||
//my_para.alpha = 0.1;
|
||||
//my_nn.train_network(my_para);
|
||||
|
||||
my_nn.predict(test_obs, predicts);
|
||||
my_nn.save_network("data/saved_networks/mnist_m2");
|
||||
|
||||
int wrong_predicts = 0;
|
||||
int test_id, pre_id;
|
||||
double test_scr, pre_scr;
|
||||
for (size_t j = 0; j < 10000; j++)
|
||||
{
|
||||
test_id = pre_id = 0;
|
||||
test_scr = pre_scr = 0;
|
||||
for (size_t i = 0; i < 10; i++)
|
||||
{
|
||||
if (test_lab[i][j] > test_scr) {test_scr = test_lab[i][j]; test_id = i;}
|
||||
if (predicts[i][j] > pre_scr) {pre_scr = predicts[i][j]; pre_id = i;}
|
||||
}
|
||||
|
||||
if (test_id != pre_id)
|
||||
{
|
||||
wrong_predicts++;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Correct Rate = " << (10000 - wrong_predicts)/100.0 << "%\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
87
src/ai/ex_mnist3.cpp
Normal file
87
src/ai/ex_mnist3.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "../data/MNIST/mnist_database.h"
|
||||
#include "../lib/dnn.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
mnist_database data("data/MNIST");
|
||||
dnn my_nn("Ex-MNIST");
|
||||
my_nn.load_network("data/saved_networks/mnist_m1.gctl.dnn");
|
||||
my_nn.show_network();
|
||||
my_nn.save_layer2text(0, "data/saved_networks/mnist_m1_layer1");
|
||||
my_nn.save_layer2text(1, "data/saved_networks/mnist_m1_layer2");
|
||||
/*
|
||||
matrix<double> test_obs(784, 10000), test_lab(10, 10000, 0.0), predicts(10, 10000);
|
||||
|
||||
const std::vector<std::vector<double> > &dt_obs2 = data.test_images();
|
||||
for (size_t i = 0; i < 10000; i++)
|
||||
{
|
||||
for (size_t j = 0; j < 784; j++)
|
||||
{
|
||||
test_obs[j][i] = dt_obs2[i][j]/255.0;
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<double> &dt_lab2 = data.test_labels();
|
||||
for (size_t i = 0; i < 10000; i++)
|
||||
{
|
||||
test_lab[dt_lab2[i]][i] = 1.0;
|
||||
}
|
||||
|
||||
my_nn.predict(test_obs, predicts);
|
||||
|
||||
int wrong_predicts = 0;
|
||||
int test_id, pre_id;
|
||||
double test_scr, pre_scr;
|
||||
for (size_t j = 0; j < 10000; j++)
|
||||
{
|
||||
test_id = pre_id = 0;
|
||||
test_scr = pre_scr = 0;
|
||||
for (size_t i = 0; i < 10; i++)
|
||||
{
|
||||
if (test_lab[i][j] > test_scr) {test_scr = test_lab[i][j]; test_id = i;}
|
||||
if (predicts[i][j] > pre_scr) {pre_scr = predicts[i][j]; pre_id = i;}
|
||||
}
|
||||
|
||||
if (test_id != pre_id)
|
||||
{
|
||||
wrong_predicts++;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Correct Rate = " << (10000 - wrong_predicts)/100.0 << "%\n";
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
41
src/core/CMakeLists.txt
Normal file
41
src/core/CMakeLists.txt
Normal file
@@ -0,0 +1,41 @@
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
|
||||
macro(add_example name switch)
|
||||
if(${switch})
|
||||
# 添加可执行程序名称
|
||||
add_executable(${name} ${name}.cpp)
|
||||
# 设置安装后的动态库调用地址
|
||||
set_target_properties(${name} PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
|
||||
set_target_properties(${name} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
|
||||
target_link_libraries(${name} PRIVATE gctl)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
add_example(spmat_ex OFF)
|
||||
add_example(eemd_ex OFF)
|
||||
add_example(ceemdan_ex OFF)
|
||||
add_example(fft_ex OFF)
|
||||
add_example(fft2d_ex OFF)
|
||||
add_example(fir_filter_ex OFF)
|
||||
add_example(fft_filter_ex OFF)
|
||||
add_example(windowfunc_ex OFF)
|
||||
add_example(legendre_ex OFF)
|
||||
add_example(refellipsoid_ex OFF)
|
||||
add_example(kde_ex OFF)
|
||||
add_example(meshio_ex OFF)
|
||||
add_example(autodiff_ex OFF)
|
||||
add_example(multinary_ex OFF)
|
||||
add_example(dsv_io_ex OFF)
|
||||
add_example(getoption_ex OFF)
|
||||
add_example(process_ex OFF)
|
||||
add_example(array_ex OFF)
|
||||
add_example(gmt_ex OFF)
|
||||
add_example(gnuplot_ex OFF)
|
||||
add_example(cliplot_ex OFF)
|
||||
add_example(stl_io_ex OFF)
|
||||
add_example(ply_io_ex OFF)
|
||||
add_example(sparray_ex OFF)
|
||||
add_example(sparray2d_ex OFF)
|
97
src/core/array_ex.cpp
Normal file
97
src/core/array_ex.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/core.h"
|
||||
#include "../lib/io.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
double get_x(const point3dc &p)
|
||||
{
|
||||
return p.x;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
// create a new array and give initial values
|
||||
array<double> A(10, 0.0, 1.0);
|
||||
A.memory_usage();
|
||||
|
||||
A.log2linear(2);
|
||||
A.show();
|
||||
|
||||
A.linear2log(2);
|
||||
A.show();
|
||||
|
||||
A.for_each([](double &a){a += 1;});
|
||||
A.show();
|
||||
|
||||
A.sequence(1.0, 0.5, 3, 4, 1);
|
||||
A.show();
|
||||
|
||||
// copy A to a new array
|
||||
array<double> B = A;
|
||||
B.normalize();
|
||||
B.show();
|
||||
|
||||
array<double> S = A + B;
|
||||
std::cout << "B + A = ";
|
||||
S.show();
|
||||
|
||||
S.normalize();
|
||||
S.show();
|
||||
|
||||
array<point3dc> P(5);
|
||||
P.sequence(point3dc(0, 0, 0), point3dc(2, 1, 0.5));
|
||||
P.show(std::cout, '\n');
|
||||
|
||||
//array<double> Px = P.extract<double>([](const point3dc &p)->double{return p.x;});
|
||||
array<double> Px = P.extract<double>(get_x);
|
||||
Px.show();
|
||||
|
||||
// create a new 2D array
|
||||
matrix<int> C(5, 5, 1);
|
||||
C.sequence(0, 1, 10);
|
||||
|
||||
std::cout << "C = \n";
|
||||
C.show();
|
||||
|
||||
// save array to a binary file
|
||||
save_matrix2binary("tmp/array_ex_out", C, "Int");
|
||||
|
||||
// import 2D array to a new object
|
||||
matrix<int> D;
|
||||
read_binary2matrix("tmp/array_ex_out", D);
|
||||
|
||||
std::cout << "D = \n";
|
||||
D.show();
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
54
src/core/autodiff_ex.cpp
Normal file
54
src/core/autodiff_ex.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/algorithm.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
affvar func(const affvar &x1, const affvar &x2)
|
||||
{
|
||||
// y(x1, x2) = x1*x2 + 2*cos(x1) - 3*sin(x2)
|
||||
// dy/dx1 = x2 - 2*sin(x1)
|
||||
// dy/dx2 = x1 - 3*cos(x2)
|
||||
affvar y = x1*x2 + 2.0*cos(x1) - 3.0*sin(x2);
|
||||
return y;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
affvar x1 = 2.0;
|
||||
affvar x2 = 3.0;
|
||||
affvar y;
|
||||
y.var({&x1, &x2}, x1);
|
||||
y = func(x1, x2);
|
||||
std::cout << y.val() << " " << y.der() << "\n";
|
||||
|
||||
y.var({&x1, &x2}, x2);
|
||||
y = func(x1, x2);
|
||||
std::cout << y.val() << " " << y.der() << "\n";
|
||||
return 0;
|
||||
}
|
94
src/core/ceemdan_ex.cpp
Normal file
94
src/core/ceemdan_ex.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
/* Copyright 2013 Perttu Luukko
|
||||
|
||||
* This file is part of libeemd.
|
||||
|
||||
* libeemd is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* libeemd is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with libeemd. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../lib/core.h"
|
||||
#include "../lib/io.h"
|
||||
#include "../lib/algorithm.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
const size_t ensemble_size = 500;
|
||||
const unsigned int S_number = 4;
|
||||
const unsigned int num_siftings = 50;
|
||||
const double noise_strength = 0.02;
|
||||
const unsigned long int rng_seed = 0;
|
||||
const std::string outfile = "ceemdan_example.out";
|
||||
|
||||
const size_t N = 512;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
libeemd_error_code err;
|
||||
// As an example decompose a Dirac signal as in the original CEEMDAN paper
|
||||
array<double> inp(N, 0.0);
|
||||
inp[N/2] = 1.0;
|
||||
|
||||
// Allocate memory for output data
|
||||
size_t M = emd_num_imfs(N); // This function is provided by the libeemd
|
||||
matrix<double> outp;
|
||||
|
||||
// Run CEEMDAN
|
||||
// This is just a warpper of the function ceemdan() from libeemd
|
||||
// IMFs are stored in rows of the output matrix in the shape of M*N
|
||||
ceemdan1d(inp, outp, M, ensemble_size, noise_strength, S_number, num_siftings, rng_seed);
|
||||
|
||||
std::ofstream ofile;
|
||||
open_outfile(ofile, outfile);
|
||||
|
||||
for (size_t j=0; j<N; j++)
|
||||
{
|
||||
ofile << inp[j];
|
||||
for (size_t i=0; i<M; i++)
|
||||
{
|
||||
ofile << " " << outp[i][j];
|
||||
}
|
||||
ofile << "\n";
|
||||
}
|
||||
ofile.close();
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
47
src/core/cliplot_ex.cpp
Normal file
47
src/core/cliplot_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 "../lib/graphic/cliplot.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
double xmin = -3;
|
||||
double xmax = 3;
|
||||
double ymin = -1;
|
||||
double ymax = 1;
|
||||
|
||||
gctl::cliplot c(81, 16, xmin, xmax, ymin, ymax);
|
||||
|
||||
//c.set_new_screen(true);
|
||||
c.set_axis(5, 5);
|
||||
c.set_digs(4);
|
||||
c.set_wname("Time (s)");
|
||||
c.set_hname("Value");
|
||||
c.plot_func([](double x)->double{return sin(x);}, '.', GCTL_BOLDRED);
|
||||
c.display();
|
||||
return 0;
|
||||
}
|
104
src/core/dsv_io_ex.cpp
Normal file
104
src/core/dsv_io_ex.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/io.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
|
||||
dsv_io tc;
|
||||
tc.delimeter('|');
|
||||
tc.head_number(1);
|
||||
tc.load_text("tmp/world_data", ".txt", ColHead|RowHead);
|
||||
tc.info(AttInfo|HeadInfo|TagInfo);
|
||||
|
||||
tc.filter("America", "Continent_s", ColHead);
|
||||
//tc.filter("America", "BLZ", RowHead);
|
||||
//tc.save_text("out");
|
||||
|
||||
if (tc.has_column("Continent_s")) std::cout << "Find Column\n";
|
||||
|
||||
dsv_io tc2 = tc.export_table();
|
||||
//tc2.head_records(tc.head_records());
|
||||
tc2.delimeter('|');
|
||||
tc2.save_text("out");
|
||||
|
||||
/*
|
||||
geodsv_io tc;
|
||||
tc.load_text("tmp/topo", ".txt", ColumnHead);
|
||||
tc.set_column_names({"x (m)", "y (m)", "elev (m)"});
|
||||
tc.set_column_type(Float, "x (m)");
|
||||
tc.set_column_type(Float, "y (m)");
|
||||
tc.set_column_type(Float, "elev (m)");
|
||||
|
||||
array<point3dc> topo;
|
||||
tc.get_column_point3dc(topo, 1, 2, 3);
|
||||
|
||||
std::clog << std::setprecision(11) << topo.front().z << "\n";
|
||||
std::clog << topo.back().x << "," << topo.back().y << "," << topo.back().z << "\n";
|
||||
display_vector(tc.get_tags(), std::clog, '\n');
|
||||
display_vector(tc.get_annotoations(), std::clog, '\n');
|
||||
display_vector(tc.get_head_records(), std::clog, '\n');
|
||||
|
||||
//tc.column_output("C3", Disable);
|
||||
|
||||
array<double> elev;
|
||||
tc.get_column(elev, "elev (m)");
|
||||
elev.for_each([](double &d, size_t i){d += 100.0;});
|
||||
|
||||
tc.add_column(2, "elev_plus");
|
||||
tc.fill_column(elev, "elev_plus");
|
||||
|
||||
tc.add_column(-1, "dist");
|
||||
tc.cal_column("dist := sqrt(C1*C1 + C3*C3)", {"dist", "C1", "C3"});
|
||||
|
||||
tc.add_row(3);
|
||||
tc.fill_row(array<double>{5.5, 4.4, 3.3, 2.2, 1.1}, 3);
|
||||
|
||||
geodsv_io out_table;
|
||||
tc.filt_column("dist > 1000", {"dist"}, {"x (m)", "y (m)", "elev (m)"}, out_table);
|
||||
out_table.save_text("out2");
|
||||
|
||||
_1s_vector s = tc.get_tags();
|
||||
s.push_back("Elev = 1000");
|
||||
tc.set_tags(s);
|
||||
tc.save_csv("out");
|
||||
|
||||
double c = 4.25242153654;
|
||||
tc.cell(c, 2, 1, 12);
|
||||
std::clog << std::setprecision(12) << tc.cell<double>(2, 1) << "\n";
|
||||
|
||||
tc.info();
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
100
src/core/eemd_ex.cpp
Normal file
100
src/core/eemd_ex.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
/* Copyright 2013 Perttu Luukko
|
||||
|
||||
* This file is part of libeemd.
|
||||
|
||||
* libeemd is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* libeemd is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with libeemd. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../lib/core.h"
|
||||
#include "../lib/io.h"
|
||||
#include "../lib/algorithms.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
const size_t ensemble_size = 250;
|
||||
const unsigned int S_number = 4;
|
||||
const unsigned int num_siftings = 50;
|
||||
const double noise_strength = 0.2;
|
||||
const unsigned long int rng_seed = 0;
|
||||
std::string outfile = "eemd_example.out";
|
||||
|
||||
// An example signal to decompose
|
||||
const size_t N = 1024;
|
||||
static inline double input_signal(double x) {
|
||||
const double omega = 2*GCTL_Pi/(N-1);
|
||||
return sin(17*omega*x)+0.5*(1.0-exp(-0.002*x))*sin(51*omega*x+1);
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
// Define input data
|
||||
array<double> inp(N);
|
||||
for (size_t i=0; i<N; i++)
|
||||
{
|
||||
inp[i] = input_signal((double)i);
|
||||
}
|
||||
|
||||
// Run eemd
|
||||
matrix<double> outp;
|
||||
// This is just a warpper of the function eemd() from libeemd
|
||||
// IMFs are stored in rows of the output matrix in the shape of M*N
|
||||
eemd1d(inp, outp, 0, ensemble_size, noise_strength, S_number, num_siftings, rng_seed);
|
||||
|
||||
std::ofstream ofile;
|
||||
open_outfile(ofile, outfile);
|
||||
|
||||
size_t M = outp.row_size();
|
||||
for (size_t j=0; j<N; j++)
|
||||
{
|
||||
ofile << inp[j];
|
||||
for (size_t i=0; i<M; i++)
|
||||
{
|
||||
ofile << " " << outp[i][j];
|
||||
}
|
||||
ofile << "\n";
|
||||
}
|
||||
ofile.close();
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
145
src/core/fft2d_ex.cpp
Normal file
145
src/core/fft2d_ex.cpp
Normal file
@@ -0,0 +1,145 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/core.h"
|
||||
#include "../lib/io.h"
|
||||
#include "../lib/algorithm.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
double module(std::complex<double> a)
|
||||
{
|
||||
return sqrt(a.real()*a.real() + a.imag()*a.imag());
|
||||
}
|
||||
|
||||
double sin_wave(double t, double f, double phi = 0, double A = 1.0)
|
||||
{
|
||||
return A*sin(2*GCTL_Pi*f*t + phi);
|
||||
}
|
||||
|
||||
void average_radian_spec(const array<double> &in_freq, const array<double> &in_power,
|
||||
const array<double> &out_freq, array<double> &out_power, array<double> &out_std)
|
||||
{
|
||||
int in_num = in_freq.size();
|
||||
int out_num = out_freq.size();
|
||||
out_power.resize(out_num, 0);
|
||||
out_std.resize(out_num, 0);
|
||||
|
||||
std::vector<double> bin;
|
||||
_1d_array bin_arr;
|
||||
for (size_t i = 0; i < out_num; i++)
|
||||
{
|
||||
bin.clear();
|
||||
for (size_t j = 0; j < in_num; j++)
|
||||
{
|
||||
if (in_freq[j] > out_freq[i] - 0.5 && in_freq[j] <= out_freq[i] + 0.5)
|
||||
{
|
||||
bin.push_back(in_power[j]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!bin.empty())
|
||||
{
|
||||
bin_arr.import_vector(bin);
|
||||
out_power[i] = bin_arr.mean();
|
||||
out_std[i] = bin_arr.std();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
double T = 2.0; // 采样时间
|
||||
double dT = 0.01; // 采样间隔
|
||||
double freq = 1.0/dT; // 采样频率
|
||||
|
||||
int M = round(T/dT) + 1, N = round(T/dT) + 1;
|
||||
|
||||
_2d_matrix sig(M, N);
|
||||
_1d_array X(N), Y(M);
|
||||
_1d_array U(N), V(M);
|
||||
X.sequence(-1.0, dT);
|
||||
Y.sequence(-1.0, dT);
|
||||
U.sequence(-1.0*freq, 2.0*freq/(N - 1));
|
||||
V.sequence(-1.0*freq, 2.0*freq/(M - 1));
|
||||
|
||||
double t;
|
||||
double f1 = 40.0;
|
||||
double f2 = 20.0;
|
||||
double f3 = 10.0;
|
||||
for (size_t i = 0; i < M; i++)
|
||||
{
|
||||
for (size_t j = 0; j < N; j++)
|
||||
{
|
||||
t = sqrt(X[j]*X[j] + Y[i]*Y[i]);
|
||||
sig[i][j] = pow(-1, i+j)*(sin_wave(t, f1) + sin_wave(t, f2) + sin_wave(t, f3));
|
||||
}
|
||||
}
|
||||
|
||||
_1cd_array spectrum;
|
||||
dft2d(sig, spectrum);
|
||||
|
||||
_1d_array spec_real(M*N), spec_imag(M*N), spec_power(M*N);
|
||||
for (size_t i = 0; i < M*N; i++)
|
||||
{
|
||||
spec_real[i] = spectrum[i].real();
|
||||
spec_imag[i] = spectrum[i].imag();
|
||||
spec_power[i] = module(spectrum[i]);
|
||||
}
|
||||
|
||||
save_netcdf_grid("fft2d_sig", sig, U, V, "u", "v");
|
||||
append_netcdf_grid("fft2d_sig", spec_real, "u", "v", "real");
|
||||
append_netcdf_grid("fft2d_sig", spec_imag, "u", "v", "imag");
|
||||
append_netcdf_grid("fft2d_sig", spec_power, "u", "v", "power");
|
||||
|
||||
_1d_array pro_freq(M*N), pro_spec(M*N);
|
||||
for (size_t i = 0; i < M; i++)
|
||||
{
|
||||
for (size_t j = 0; j < N; j++)
|
||||
{
|
||||
pro_freq[j + i*N] = sqrt(U[j]*U[j] + V[i]*V[i]);
|
||||
pro_spec[j + i*N] = spec_power[j + i*N];
|
||||
}
|
||||
}
|
||||
|
||||
_1d_array out_freq, out_power, out_std;
|
||||
out_freq.resize(150, 1.0, 1.0);
|
||||
average_radian_spec(pro_freq, pro_spec, out_freq, out_power, out_std);
|
||||
|
||||
std::ofstream ofile;
|
||||
open_outfile(ofile, "fft2d_radian_spec", ".txt");
|
||||
for (size_t i = 0; i < out_freq.size(); i++)
|
||||
{
|
||||
ofile << out_freq[i] << " " << out_power[i] << " " << out_std[i] << "\n";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
87
src/core/fft_ex.cpp
Normal file
87
src/core/fft_ex.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/core.h"
|
||||
#include "../lib/io.h"
|
||||
#include "../lib/algorithm.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
double module(std::complex<double> a)
|
||||
{
|
||||
return sqrt(a.real()*a.real() + a.imag()*a.imag());
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
int fs = 100;
|
||||
double T = 5;
|
||||
int n = round(fs*T);
|
||||
double t;
|
||||
|
||||
gctl::array<double> in(n), out;
|
||||
gctl::array<double> freq_index;
|
||||
gctl::_1cd_array spectrum;
|
||||
|
||||
for (size_t i = 0; i < n; i++)
|
||||
{
|
||||
t = 1.0*T*i/n;
|
||||
in[i] = 2.0*sin(2.0*GCTL_Pi*t*10) + 1.0*sin(2.0*GCTL_Pi*t*5) + 3.0*sin(2.0*GCTL_Pi*t*2);
|
||||
}
|
||||
|
||||
// Run the r2c transform
|
||||
gctl::dft_r2c_1d(in, spectrum, 1.0*fs, &freq_index);
|
||||
|
||||
std::ofstream ofile;
|
||||
open_outfile(ofile, "fft_example_spec.out");
|
||||
for (size_t i = 0; i < spectrum.size(); i++)
|
||||
{
|
||||
ofile << freq_index[i] << ' ' << module(spectrum[i]) << " ";
|
||||
|
||||
if (9.5 < freq_index[i] && freq_index[i] < 10.5) {spectrum[i].real(0.0); spectrum[i].imag(0.0);}
|
||||
//if (1.5 < freq_index[i] && freq_index[i] < 2.5) {spectrum[i].real(0.0); = spectrum[i].imag(0.0);}
|
||||
if (4.5 < freq_index[i] && freq_index[i] < 5.5) {spectrum[i].real(0.0); spectrum[i].imag(0.0);}
|
||||
|
||||
ofile << module(spectrum[i]) << "\n";
|
||||
}
|
||||
ofile.close();
|
||||
|
||||
// Run the c2r transform
|
||||
gctl::dft_c2r_1d(spectrum, out);
|
||||
|
||||
open_outfile(ofile, "fft_example_sig.out");
|
||||
for (size_t i = 0; i < n; i++)
|
||||
{
|
||||
t = 1.0*T*i/n;
|
||||
ofile << t << " " << in[i] << " " << out[i] << "\n";
|
||||
}
|
||||
ofile.close();
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
81
src/core/fft_filter_ex.cpp
Normal file
81
src/core/fft_filter_ex.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/core.h"
|
||||
#include "../lib/io.h"
|
||||
#include "../lib/algorithm.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
int fs = 200;
|
||||
double f1 = 4.0;
|
||||
double f2 = 10.0;
|
||||
|
||||
// Create filters
|
||||
fft_filter filter_lp(LowPass, Butterworth, 5, (double) fs, f1);
|
||||
fft_filter filter_hp(HighPass, Butterworth, 5, (double) fs, f2);
|
||||
fft_filter filter_bp(BandPass, Butterworth, 5, (double) fs, f1, f2);
|
||||
fft_filter filter_bs(BandStop, Butterworth, 5, (double) fs, f1, f2);
|
||||
|
||||
// Demo
|
||||
double f1_demo = 1.0; // Hz
|
||||
double f2_demo = 7.5;
|
||||
double f3_demo = 15.0;
|
||||
|
||||
// Create input signal
|
||||
int snum = int(10.13*fs);
|
||||
gctl::array<double> t(snum), signal(snum);
|
||||
t.sequence(0.0, 10.13/(snum - 1));
|
||||
|
||||
for (size_t i = 0; i < t.size(); i++)
|
||||
{
|
||||
signal[i] = 2.0*sin(2.0*GCTL_Pi*f1_demo*t[i]) + sin(2.0*GCTL_Pi*f2_demo*t[i]) + 0.5*sin(2.0*GCTL_Pi*f3_demo*t[i]);
|
||||
}
|
||||
|
||||
gctl::array<double> filtered_lp, filtered_hp, filtered_bp, filtered_bs;
|
||||
|
||||
// Run the filtersc。
|
||||
filter_lp.filter(signal, filtered_lp);
|
||||
filter_hp.filter(signal, filtered_hp);
|
||||
filter_bp.filter(signal, filtered_bp);
|
||||
filter_bs.filter(signal, filtered_bs);
|
||||
|
||||
std::ofstream ofile;
|
||||
open_outfile(ofile, "fft_filter_ex.out");
|
||||
for (size_t i = 0; i < filtered_lp.size(); i++)
|
||||
{
|
||||
ofile << t[i] << " " << signal[i] << " " << filtered_lp[i] << " " << filtered_hp[i] << " " << filtered_bp[i] << " " << filtered_bs[i] << "\n";
|
||||
}
|
||||
ofile.close();
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
88
src/core/fir_filter_ex.cpp
Normal file
88
src/core/fir_filter_ex.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/core.h"
|
||||
#include "../lib/io.h"
|
||||
#include "../lib/algorithm.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
int fs = 200;
|
||||
double f1 = 4.0;
|
||||
double f2 = 10.0;
|
||||
int m = 600;
|
||||
|
||||
// Create filters
|
||||
fir_filter filter_lp(LowPass, Hamming, m, (double) fs, f1);
|
||||
fir_filter filter_hp(HighPass, Hamming, m, (double) fs, f2);
|
||||
fir_filter filter_bp(BandPass, Hamming, m, (double) fs, f1, f2);
|
||||
fir_filter filter_sb(BandStop, Hamming, m, (double) fs, f1, f2);
|
||||
|
||||
// Get coefficient
|
||||
//array<double> h_lp = filter_lp.get_coefficients();
|
||||
//array<double> h_hp = filter_hp.get_coefficients();
|
||||
//array<double> h_bp = filter_bp.get_coefficients();
|
||||
//array<double> h_sb = filter_sb.get_coefficients();
|
||||
|
||||
// Demo
|
||||
double f1_demo = 1.0; // Hz
|
||||
double f2_demo = 7.5;
|
||||
double f3_demo = 15.0;
|
||||
|
||||
// Create input signal
|
||||
int snum = int(10.13*fs);
|
||||
gctl::array<double> t(snum), signal(snum);
|
||||
t.sequence(0.0, 10.13/(snum - 1));
|
||||
|
||||
for (size_t i = 0; i < t.size(); i++)
|
||||
{
|
||||
signal[i] = 2.0*sin(2.0*GCTL_Pi*f1_demo*t[i]) + sin(2.0*GCTL_Pi*f2_demo*t[i]) + 0.5*sin(2.0*GCTL_Pi*f3_demo*t[i]);
|
||||
}
|
||||
|
||||
gctl::array<double> filtered_lp, filtered_hp, filtered_bp, filtered_sb;
|
||||
|
||||
// Run the filters
|
||||
filter_lp.filter(signal, filtered_lp);
|
||||
filter_hp.filter(signal, filtered_hp);
|
||||
filter_bp.filter(signal, filtered_bp);
|
||||
filter_sb.filter(signal, filtered_sb);
|
||||
|
||||
std::ofstream ofile;
|
||||
open_outfile(ofile, "fir_filter_ex.out");
|
||||
for (size_t i = 0; i < filtered_lp.size(); i++)
|
||||
{
|
||||
ofile << t[i] << " " << signal[i] << " " << filtered_lp[i] << " " << filtered_hp[i] << " " << filtered_bp[i] << " " << filtered_sb[i] << "\n";
|
||||
}
|
||||
ofile.close();
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
84
src/core/getoption_ex.cpp
Normal file
84
src/core/getoption_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 "../lib/utility.h"
|
||||
#include "../lib/geometry.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("tmp/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;
|
||||
|
||||
// 通过选项的标签值来获取参数值 需要匹配的字符串只需要包含标签值即可
|
||||
_1d_vector weight = gopt.get_value_t<_1d_vector>("weight|Weight", '|', '/');
|
||||
std::cout << weight.size() << std::endl;
|
||||
std::cout << weight[2] << 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;
|
||||
|
||||
_1s_vector s;
|
||||
std::cin >> s;
|
||||
std::cout << s.size() << "\n";
|
||||
std::cout << s << "\n";
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
65
src/core/gmt_ex.cpp
Normal file
65
src/core/gmt_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 "../lib/graphic/gmt.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
gctl::gmt gt;
|
||||
/*
|
||||
gt.begin_session("line_plot", "eps,png");
|
||||
gt.call_module("basemap", "-R0/10/0/10 -JX5i/5i -Baf");
|
||||
gt.call_module("plot", "tmp/data.txt -R0/10/0/10 -JX5i/5i -W1p,blue");
|
||||
gt.end_session(false);
|
||||
gt.save_session("line_plot");
|
||||
*/
|
||||
|
||||
// example 2
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
gt.begin_session("image_plot", "eps");
|
||||
gt.call_module("set", "FONT_ANNOT_PRIMARY=10.5p,Times-Roman,black");
|
||||
|
||||
std::string gname = gt.create_grid(data, 41, 51, 0.0, 1.0, 0.0, 1.0);
|
||||
|
||||
gt.call_module("grd2cpt", gname + " -R0/40/0/50 -Crainbow -Z -D");
|
||||
gt.call_module("grdimage", gname + " -R0/40/0/50 -JX1.5i/1.5i -X0.5i -Y0.5i -Bxag+l\"x (m)\" -Byag+l\"y (m)\"");
|
||||
gt.call_module("psscale", "-Bxa -By+lm -Dx0.1i/-0.2i+w1.3i/0.05i+h");
|
||||
gt.end_session();
|
||||
gt.save_session("image_plot");
|
||||
return 0;
|
||||
}
|
97
src/core/gnuplot_ex.cpp
Normal file
97
src/core/gnuplot_ex.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/core/macro.h"
|
||||
#include "../lib/graphic/gnuplot.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
gctl::gnuplot gt;
|
||||
|
||||
//one line test
|
||||
//gt.send("set terminal dumb");
|
||||
//gt.send("plot [-pi/2:pi] cos(x),-(sin(x) > sin(x+1) ? sin(x) : sin(x+1))");
|
||||
|
||||
//buffer test (bessel animation)
|
||||
/*
|
||||
gt.to_buffer();
|
||||
gt.send("set terminal gif animate delay 10 size 600,400");
|
||||
gt.send("set output 'bessel.gif'");
|
||||
gt.send("set palette rgb 3,9,9");
|
||||
gt.send("unset key; unset colorbox; unset border; unset tics");
|
||||
gt.send("set lmargin at screen 0.03");
|
||||
gt.send("set bmargin at screen 0");
|
||||
gt.send("set rmargin at screen 0.97");
|
||||
gt.send("set tmargin at screen 1");
|
||||
gt.send("set parametric", true);
|
||||
gt.send("bessel(x,t) = besj0(x) * cos(2*pi*t)");
|
||||
gt.send("n = 6 # number of zeros");
|
||||
gt.send("k = (n*pi-1.0/4*pi)");
|
||||
gt.send("u_0 = k + 1/(8*k) - 31/(384*k)**3 + 3779/(15360*k)**5");
|
||||
gt.send("set urange [0:u_0]");
|
||||
gt.send("set vrange[0:1.5*pi]");
|
||||
gt.send("set cbrange [-1:1]");
|
||||
gt.send("set zrange[-1:1]");
|
||||
gt.send("set isosamples 200,100");
|
||||
gt.send("set pm3d depthorder");
|
||||
gt.send("set view 40,200");
|
||||
|
||||
std::string cmd;
|
||||
for (float t = 0.0f; t < 2.0f; t += 0.02f)
|
||||
{
|
||||
cmd = "splot u*sin(v),u*cos(v),bessel(u," + std::to_string(t) + ") w pm3d ls 1";
|
||||
gt.send(cmd);
|
||||
}
|
||||
gt.send("set output");
|
||||
|
||||
gt.save_buffer("bessel");
|
||||
gt.send_buffer();
|
||||
*/
|
||||
|
||||
//data test
|
||||
std::vector<double> x(101);
|
||||
std::vector<double> y1(101);
|
||||
std::vector<double> y2(101);
|
||||
for (size_t i = 0; i < 101; i++)
|
||||
{
|
||||
x[i] = -1.0*GCTL_Pi + 2.0*GCTL_Pi*i/100.0;
|
||||
y1[i] = sin(x[i]);
|
||||
y2[i] = cos(x[i]);
|
||||
}
|
||||
|
||||
std::vector<std::vector<double> > data;
|
||||
data.push_back(x);
|
||||
data.push_back(y1);
|
||||
data.push_back(y2);
|
||||
|
||||
gt.to_buffer();
|
||||
gt.send_data("$Data", data);
|
||||
gt.send("plot $Data using 1:2 with lines title 'y1', '' using 1:3 with lines title 'y2'");
|
||||
gt.save_buffer("sin_cos");
|
||||
gt.send_buffer();
|
||||
return 0;
|
||||
}
|
106
src/core/kde_ex.cpp
Normal file
106
src/core/kde_ex.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/core.h"
|
||||
#include "../lib/algorithm.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
/*
|
||||
array<double> x(201);
|
||||
x.sequence(-1.0, 0.01);
|
||||
kde k(0.02, x);
|
||||
|
||||
array<double> d;
|
||||
array<double> a(100000);
|
||||
a.random_float(0.2, 0.2, RdNormal, 0);
|
||||
k.get_distribution(a, d);
|
||||
|
||||
gaussian_para1d g1(0, 0.2);
|
||||
array<double> g(201);
|
||||
for (size_t i = 0; i < x.size(); i++)
|
||||
{
|
||||
g[i] = gaussian_dist1d(x[i], g1);
|
||||
}
|
||||
|
||||
array<double> dm(201);
|
||||
array<double> am(100000, 0.0);
|
||||
|
||||
for (size_t i = 0; i < am.size(); i++)
|
||||
{
|
||||
k.get_gradient_at(i, a, dm);
|
||||
|
||||
for (size_t j = 0; j < x.size(); j++)
|
||||
{
|
||||
am[i] += 2.0*(d[j] - g[j])*dm[j];
|
||||
}
|
||||
|
||||
std::cout << a[i] << " " << am[i] << "\n";
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < x.size(); i++)
|
||||
{
|
||||
std::cout << x[i] << " " << d[i] - g[i] << "\n";
|
||||
}
|
||||
*/
|
||||
|
||||
array<double> x(201), y(301);
|
||||
x.sequence(-1.0, 0.01);
|
||||
y.sequence(0.0, 0.01);
|
||||
kde2d k(0.1, 0.1, x, y);
|
||||
|
||||
array<double> a(10000), b(10000);
|
||||
a.random_float(0, 0.2, RdNormal, 0);
|
||||
b.random_float(1.5, 0.3, RdNormal, 0);
|
||||
|
||||
gaussian_para2d g1(0, 1.5, 0.2, 0.3, 0);
|
||||
|
||||
array<double> d(201*301);
|
||||
//k.get_distribution(a, b, d);
|
||||
|
||||
a[0] = 0;
|
||||
b[0] = 1.5;
|
||||
k.get_gradient_y_at(0, a, b, d);
|
||||
|
||||
double t, sum = 0;
|
||||
for (size_t i = 0; i < y.size(); i++)
|
||||
{
|
||||
for (size_t j = 0; j < x.size(); j++)
|
||||
{
|
||||
std::cout << x[j] << " " << y[i] << " "
|
||||
//<< gaussian_dist2d(x[j], y[i], g1) << " "
|
||||
<< d[201*i + j] << "\n";
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
53
src/core/legendre_ex.cpp
Normal file
53
src/core/legendre_ex.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/io.h"
|
||||
#include "../lib/algebra.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
std::ofstream ofile;
|
||||
open_outfile(ofile, "legendre_ex.out");
|
||||
for (size_t i = 0; i < 101; i++)
|
||||
{
|
||||
ofile << -1.0+2.0*i/100;
|
||||
for (size_t o = 0; o < 10; o++)
|
||||
{
|
||||
ofile << " " << legendre_polynomials(o, -1.0+2.0*i/100, false);
|
||||
ofile << " " << legendre_polynomials(o, -1.0+2.0*i/100, true);
|
||||
}
|
||||
ofile << "\n";
|
||||
}
|
||||
ofile.close();
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
53
src/core/multinary_ex.cpp
Normal file
53
src/core/multinary_ex.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/geometry.h"
|
||||
#include "../lib/algorithm.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
multinary ml;
|
||||
ml.init(0.1, 0.3, 0.008, 5);
|
||||
|
||||
//array<double> std(9, 0.05);
|
||||
//array<double> xs = {-2.2, -1.8, -1.5, -1.0, -0.7, -0.2, 0.9, 1.3, 1.9, 2.5};
|
||||
//ml.init(xs, std);
|
||||
|
||||
array<double> x(201);
|
||||
sequence(x, 0.1, 0.001);
|
||||
|
||||
for (size_t i = 0; i < x.size(); i++)
|
||||
{
|
||||
std::cout << x[i] << " " << ml.val(x[i]) << " " << ml.der(x[i]) << "\n";
|
||||
}
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
44
src/core/ply_io_ex.cpp
Normal file
44
src/core/ply_io_ex.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/core.h"
|
||||
#include "../lib/io.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
array<vertex3dc> nodes;
|
||||
array<triangle> tris;
|
||||
read_ply_binary("tmp_binary", nodes, tris);
|
||||
save_ply_ascii("tmp", nodes, tris);
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
63
src/core/process_ex.cpp
Normal file
63
src/core/process_ex.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/core.h"
|
||||
#include "../lib/utility.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
class process_ex : public process_monitor
|
||||
{
|
||||
public:
|
||||
process_ex(){}
|
||||
virtual ~process_ex(){}
|
||||
|
||||
void process()
|
||||
{
|
||||
for (size_t i = 0; i < 10; i++)
|
||||
{
|
||||
std::cout << "do something here...\n";
|
||||
|
||||
wait_for_kerboard();
|
||||
if (end_process()) break;
|
||||
}
|
||||
|
||||
set_end_process();
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
process_ex p;
|
||||
p.start_monitoring();
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
74
src/core/refellipsoid_ex.cpp
Normal file
74
src/core/refellipsoid_ex.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/geometry.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
refellipsoid ellip;
|
||||
ellip.set(WGS84);
|
||||
/*
|
||||
point3ds ps;
|
||||
ps.set_io_precision(17);
|
||||
ps.lon = -110;
|
||||
ellip.geodetic2spherical(-40, 0, ps.lat, ps.rad);
|
||||
std::cout << "Geocentric: " << ps << std::endl;
|
||||
|
||||
point3dc pc = ps.s2c();
|
||||
pc.set_io_precision(17);
|
||||
std::cout << "XYZ: " << pc << std::endl;
|
||||
|
||||
ellip.spherical2geodetic(ps, ps.lon, ps.lat, ps.rad);
|
||||
std::cout << "Geodetic: " << ps << std::endl;
|
||||
|
||||
ellip.xyz2geodetic(pc, ps.lon, ps.lat, ps.rad);
|
||||
std::cout << "Geodetic: " << ps << std::endl;
|
||||
*/
|
||||
|
||||
point3ds ps;
|
||||
ps.set_io_precision(17);
|
||||
// 大地坐标 (110,40,0)
|
||||
ps.lon = 110;
|
||||
ellip.geodetic2spherical(40.0, 0.0, ps.lat, ps.rad);
|
||||
// 球心坐标 (110,39.810615323061491,6369344.5441424493)
|
||||
std::cout << "Geocentric: " << ps << std::endl;
|
||||
// 转换为大地坐标
|
||||
point3ds pd;
|
||||
ellip.xyz2geodetic(ps.s2c(), pd.lon, pd.lat, pd.rad);
|
||||
std::cout << "Geodetic: " << pd << std::endl;
|
||||
// 400km高
|
||||
pd.rad = 400000.0;
|
||||
ellip.geodetic2spherical(pd.lat, pd.rad, pd.lat, pd.rad);
|
||||
std::cout << "Geocentric: " << pd << std::endl;
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
43
src/core/sparray2d_ex.cpp
Normal file
43
src/core/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;
|
||||
}
|
114
src/core/sparray_ex.cpp
Normal file
114
src/core/sparray_ex.cpp
Normal file
@@ -0,0 +1,114 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/core.h"
|
||||
#include "../lib/algorithms.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
srand(time(0));
|
||||
gctl::sparray<double> M(50, 0.0);
|
||||
gctl::sparray<double> L;
|
||||
|
||||
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();
|
||||
std::cout << "************" << std::endl;
|
||||
|
||||
M.copy_to(L, 2);
|
||||
L.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;
|
||||
}
|
77
src/core/spmat_ex.cpp
Normal file
77
src/core/spmat_ex.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/core.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
spmat<double> mat(5, 5, 0.0);
|
||||
|
||||
std::vector<mat_node<double> > triplts;
|
||||
triplts.push_back(mat_node(0, 1, 0.23));
|
||||
triplts.push_back(mat_node(1, 2, 0.52));
|
||||
triplts.push_back(mat_node(2, 3, 0.31));
|
||||
triplts.push_back(mat_node(2, 3, 0.19));
|
||||
triplts.push_back(mat_node(3, 2, 0.65));
|
||||
triplts.push_back(mat_node(3, 4, 0.8));
|
||||
triplts.push_back(mat_node(4, 3, 1.6));
|
||||
triplts.push_back(mat_node(4, 3, 0.4));
|
||||
|
||||
mat.set_triplts(triplts, ReplaceVal);
|
||||
mat.init_pattern();
|
||||
mat.show_matrix();
|
||||
std::cout << "=====\n";
|
||||
|
||||
// 调用clear会重置pattern
|
||||
mat.clear(3, RowMajor);
|
||||
|
||||
for (size_t i = 0; i < triplts.size(); i++)
|
||||
{
|
||||
triplts[i].val = 0.1*(i + 1);
|
||||
}
|
||||
|
||||
mat.set_triplts(triplts, ReplaceVal);
|
||||
mat.show_matrix();
|
||||
|
||||
for (size_t i = 0; i < mat.row_size(); i++)
|
||||
{
|
||||
std::cout << "module(" << i << ") = " << mat.module(i, ColMajor) << "\n";
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < mat.row_size(); i++)
|
||||
{
|
||||
mat.scale(2.0, i);
|
||||
}
|
||||
|
||||
mat.show_matrix();
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
45
src/core/stl_io_ex.cpp
Normal file
45
src/core/stl_io_ex.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/core.h"
|
||||
#include "../lib/io.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
array<vertex3dc> nodes;
|
||||
array<triangle> tris;
|
||||
read_stl_binary("tmp/Stanford_Bunny_Binary", nodes, tris);
|
||||
save_stl_ascii("tmp", tris, "Stanford_Bunny");
|
||||
save_stl_binary("tmp_binary", tris, "Stanford_Bunny");
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
55
src/core/windowfunc_ex.cpp
Normal file
55
src/core/windowfunc_ex.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/core.h"
|
||||
#include "../lib/algorithm.h"
|
||||
#include "../lib/io.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
int t = 100;
|
||||
_1d_array w1, w2, w3, w4;
|
||||
|
||||
window_hamming(t, w1);
|
||||
window_hanning(t, w2);
|
||||
window_triangle(t, w3);
|
||||
window_blackman(t, w4);
|
||||
|
||||
std::ofstream ofile;
|
||||
open_outfile(ofile, "windowfunc_ex.out");
|
||||
for (size_t i = 0; i < t; i++)
|
||||
{
|
||||
ofile << i << " " << w1[i] << " " << w2[i] << " " << w3[i] << " " << w4[i] << "\n";
|
||||
}
|
||||
ofile.close();
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
30
src/mesh/CMakeLists.txt
Normal file
30
src/mesh/CMakeLists.txt
Normal file
@@ -0,0 +1,30 @@
|
||||
# 设置可执行文件的输出地址
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
|
||||
macro(add_example name switch)
|
||||
if(${switch})
|
||||
# 添加可执行程序名称
|
||||
add_executable(${name} ${name}.cpp)
|
||||
|
||||
# 设置安装后的动态库调用地址
|
||||
set_target_properties(${name} PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
|
||||
set_target_properties(${name} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# 链接动态库
|
||||
target_link_libraries(${name} PRIVATE ${GCTL_LIB})
|
||||
target_link_libraries(${name} PRIVATE gctl_mesh)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
add_example(mesh_ex1 OFF)
|
||||
add_example(mesh_ex2 OFF)
|
||||
add_example(mesh_ex3 OFF)
|
||||
add_example(mesh_ex4 OFF)
|
||||
add_example(mesh_ex5 OFF)
|
||||
add_example(mesh_ex6 OFF)
|
||||
add_example(mesh_ex7 OFF)
|
||||
add_example(mesh_ex8 OFF)
|
||||
add_example(mesh_ex9 OFF)
|
||||
add_example(mesh_ex10 OFF)
|
||||
add_example(meshio_ex OFF)
|
||||
add_example(tri2d_meshio_ex ON)
|
54
src/mesh/mesh_ex1.cpp
Normal file
54
src/mesh/mesh_ex1.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/mesh.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
gctl::regular_grid rgd;
|
||||
rgd.init("grid-1", "null", 4, 4, 0.0, 0.0, 1.0, 1.0);
|
||||
|
||||
rgd.add_data(gctl::NodeData, gctl::Scalar, "data-1", 2.5);
|
||||
rgd.add_data(gctl::ElemData, gctl::Scalar, "data-2", 1.2, false);
|
||||
rgd.add_data(gctl::NodeData, gctl::Scalar, "data-3", 1.0);
|
||||
rgd.show_info();
|
||||
|
||||
gctl::meshdata data2 = rgd.get_data("data-2");
|
||||
std::cout << "data name: " << data2.name_ << std::endl;
|
||||
data2.datval_.show();
|
||||
|
||||
gctl::meshdata data3 = rgd.get_data("data-3");
|
||||
std::cout << "data name: " << data3.name_ << std::endl;
|
||||
data3.datval_.show();
|
||||
|
||||
rgd.diff("data-4", "data-1", "data-3");
|
||||
|
||||
rgd.remove_data("data-1");
|
||||
rgd.show_info();
|
||||
rgd.save_gmsh_withdata("ex1_out", gctl::OverWrite, gctl::NotPacked);
|
||||
return 0;
|
||||
}
|
37
src/mesh/mesh_ex10.cpp
Normal file
37
src/mesh/mesh_ex10.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 "../lib/mesh.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
gctl::regular_mesh_sph_3d rm_3ds;
|
||||
rm_3ds.init("mesh-1", "null", 30.25, 30.25, 2005, 0.5, 0.5, 10, 40, 40, 50);
|
||||
rm_3ds.add_data(gctl::ElemData, gctl::Scalar, "data-1", 2.5);
|
||||
rm_3ds.save_gmsh_withdata("mesh_sample10",gctl::OverWrite, gctl::NotPacked);
|
||||
return 0;
|
||||
}
|
62
src/mesh/mesh_ex2.cpp
Normal file
62
src/mesh/mesh_ex2.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/mesh.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
std::string dname = "example";
|
||||
std::string dname2= "another-example";
|
||||
|
||||
gctl::regular_grid rgd;
|
||||
rgd.init("grid-1", "null", 15, 10, 0.0, 0.0, 1.0, 1.0);
|
||||
|
||||
gctl::meshdata &data = rgd.add_data(gctl::NodeData, gctl::Scalar, dname, 0.0);
|
||||
for (int j = 0; j < rgd.get_ydim(); j++)
|
||||
{
|
||||
for (int i = 0; i < rgd.get_xdim(); i++)
|
||||
{
|
||||
data.datval_[i + j*rgd.get_xdim()] = i;
|
||||
}
|
||||
}
|
||||
|
||||
gctl::meshdata &data2 = rgd.add_data(gctl::NodeData, gctl::Scalar, dname2, 0.0);
|
||||
for (int j = 0; j < rgd.get_ydim(); j++)
|
||||
{
|
||||
for (int i = 0; i < rgd.get_xdim(); i++)
|
||||
{
|
||||
data2.datval_[i + j*rgd.get_xdim()] = j;
|
||||
}
|
||||
}
|
||||
|
||||
// disable the output of data object named dname2
|
||||
//data2.output_ok_ = false;
|
||||
|
||||
rgd.show_info();
|
||||
rgd.save_netcdf_grid("sample2-out", gctl::NodeData);
|
||||
return 0;
|
||||
}
|
82
src/mesh/mesh_ex3.cpp
Normal file
82
src/mesh/mesh_ex3.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 "../lib/mesh.h"
|
||||
|
||||
int main(int argc, char *argv[]) try
|
||||
{
|
||||
std::string dname = "example";
|
||||
std::string dname2= "another-example";
|
||||
|
||||
gctl::regular_grid rgd;
|
||||
rgd.init("grid-1", "this is a test message.", 15, 10, 0.0, 0.0, 1.0, 1.0);
|
||||
|
||||
gctl::meshdata &data = rgd.add_data(gctl::NodeData, gctl::Scalar, dname, 0.0);
|
||||
for (int j = 0; j < rgd.get_ydim(); j++)
|
||||
{
|
||||
for (int i = 0; i < rgd.get_xdim(); i++)
|
||||
{
|
||||
data.datval_[i + j*rgd.get_xdim()] = i;
|
||||
}
|
||||
}
|
||||
|
||||
gctl::meshdata &data2 = rgd.add_data(gctl::ElemData, gctl::Scalar, dname2, 0.0);
|
||||
for (int j = 0; j < rgd.get_ydim()-1; j++)
|
||||
{
|
||||
for (int i = 0; i < rgd.get_xdim()-1; i++)
|
||||
{
|
||||
data2.datval_[i + j*(rgd.get_xdim()-1)] = j;
|
||||
}
|
||||
}
|
||||
|
||||
rgd.save_binary("sample3-out");
|
||||
rgd.save_netcdf_grid("sample3-out1", dname);
|
||||
rgd.save_netcdf_grid("sample3-out2", dname2);
|
||||
|
||||
gctl::regular_grid rgd2;
|
||||
rgd2.load_binary("sample3-out");
|
||||
rgd2.show_info();
|
||||
|
||||
gctl::meshdata &data3 = rgd2.get_data(dname);
|
||||
for (int i = 0; i < data3.datval_.size(); i++)
|
||||
{
|
||||
std::cout << data3.datval_[i] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
gctl::meshdata &data4 = rgd2.get_data(dname2);
|
||||
for (int i = 0; i < data4.datval_.size(); i++)
|
||||
{
|
||||
std::cout << data4.datval_[i] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
60
src/mesh/mesh_ex4.cpp
Normal file
60
src/mesh/mesh_ex4.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 "../lib/mesh.h"
|
||||
|
||||
int main(int argc, char *argv[]) try
|
||||
{
|
||||
std::string dname = "vector-data";
|
||||
|
||||
gctl::regular_grid rgd;
|
||||
rgd.init("grid-example", "this grid can store vectors. Yeah!", 15, 10, 0.0, 0.0, 1.0, 1.0);
|
||||
|
||||
gctl::array<gctl::point3dc> init_data(rgd.get_ydim()*rgd.get_xdim());
|
||||
for (int j = 0; j < rgd.get_ydim(); j++)
|
||||
{
|
||||
for (int i = 0; i < rgd.get_xdim(); i++)
|
||||
{
|
||||
init_data[i + j*rgd.get_xdim()].x = i;
|
||||
init_data[i + j*rgd.get_xdim()].y = j;
|
||||
init_data[i + j*rgd.get_xdim()].z = i+j;
|
||||
}
|
||||
}
|
||||
|
||||
gctl::meshdata data = rgd.add_data(gctl::NodeData, dname, init_data);
|
||||
|
||||
rgd.save_binary("sample4-out");
|
||||
|
||||
gctl::regular_grid rgd2;
|
||||
rgd2.load_binary("sample4-out");
|
||||
rgd2.show_info();
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
43
src/mesh/mesh_ex5.cpp
Normal file
43
src/mesh/mesh_ex5.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 "../lib/mesh.h"
|
||||
|
||||
int main(int argc, char *argv[]) try
|
||||
{
|
||||
gctl::regular_grid rgd;
|
||||
rgd.load_netcdf_grid("data/out/sample3-out1", gctl::ElemData, "x", "y");
|
||||
|
||||
rgd.show_info();
|
||||
|
||||
rgd.save_netcdf_grid("data/out/sample5-out", "example");
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
66
src/mesh/mesh_ex6.cpp
Normal file
66
src/mesh/mesh_ex6.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/mesh.h"
|
||||
|
||||
int main(int argc, char *argv[]) try
|
||||
{
|
||||
gctl::regular_mesh_2d rg_mesh;
|
||||
rg_mesh.init("mesh-example", "this mesh can store vectors. Yeah!", 15, 10, 0.5, 0.5, 1.0, 1.0);
|
||||
|
||||
int ybnum = rg_mesh.get_ybnum();
|
||||
int xbnum = rg_mesh.get_xbnum();
|
||||
|
||||
gctl::array<gctl::point3dc> init_data(ybnum*xbnum);
|
||||
for (int j = 0; j < ybnum; j++)
|
||||
{
|
||||
for (int i = 0; i < xbnum; i++)
|
||||
{
|
||||
init_data[i + j*xbnum].x = i;
|
||||
init_data[i + j*xbnum].y = j;
|
||||
init_data[i + j*xbnum].z = i+j;
|
||||
}
|
||||
}
|
||||
|
||||
rg_mesh.add_data(gctl::ElemData, "vector-data", init_data);
|
||||
|
||||
gctl::meshdata &data2= rg_mesh.add_data(gctl::NodeData, gctl::Scalar, "double-data", 0.0);
|
||||
for (int j = 0; j < ybnum+1; j++)
|
||||
{
|
||||
for (int i = 0; i < xbnum+1; i++)
|
||||
{
|
||||
data2.datval_[i + j*(xbnum+1)] = i+j;
|
||||
}
|
||||
}
|
||||
|
||||
rg_mesh.save_gmsh_withdata("sample6-out", gctl::OverWrite);
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
57
src/mesh/mesh_ex7.cpp
Normal file
57
src/mesh/mesh_ex7.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 "../lib/mesh.h"
|
||||
|
||||
int main(int argc, char *argv[]) try
|
||||
{
|
||||
gctl::regular_mesh_3d rg_mesh;
|
||||
rg_mesh.init("mesh-example", "this mesh can store vectors. Yeah!", 15, 10, 10, 0.5, 0.5, 0.5, 1.0, 1.0, 1.0);
|
||||
|
||||
int ybnum = rg_mesh.get_ybnum();
|
||||
int xbnum = rg_mesh.get_xbnum();
|
||||
int zbnum = rg_mesh.get_zbnum();
|
||||
|
||||
gctl::meshdata &data = rg_mesh.add_data(gctl::NodeData, gctl::Scalar, "double-data", 0.0);
|
||||
for (int k = 0; k < zbnum+1; k++)
|
||||
{
|
||||
for (int j = 0; j < ybnum+1; j++)
|
||||
{
|
||||
for (int i = 0; i < xbnum+1; i++)
|
||||
{
|
||||
data.datval_[i + j*(xbnum+1) + k*(xbnum+1)*(ybnum+1)] = i+j+k;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rg_mesh.save_gmsh_withdata("sample7-out", "double-data", gctl::OverWrite);
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
47
src/mesh/mesh_ex8.cpp
Normal file
47
src/mesh/mesh_ex8.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 "../lib/mesh.h"
|
||||
|
||||
int main(int argc, char *argv[]) try
|
||||
{
|
||||
gctl::triangle2d_mesh t_mesh;
|
||||
t_mesh.load_triangle("sample8", gctl::Packed);
|
||||
t_mesh.add_data(gctl::ElemData, gctl::Scalar, "example", 1.0);
|
||||
|
||||
t_mesh.save_gmsh_withdata("sample8-out", "example", gctl::OverWrite, gctl::NotPacked);
|
||||
t_mesh.save_binary("sample8-out");
|
||||
|
||||
gctl::triangle2d_mesh t2_mesh;
|
||||
t2_mesh.load_binary("sample8-out");
|
||||
t2_mesh.show_info();
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
65
src/mesh/mesh_ex9.cpp
Normal file
65
src/mesh/mesh_ex9.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 "../lib/mesh.h"
|
||||
|
||||
int main(int argc, char *argv[]) try
|
||||
{
|
||||
gctl::array<double> xs(15);
|
||||
for (int i = 0; i < 15; i++)
|
||||
{
|
||||
xs[i] = i+1;
|
||||
}
|
||||
|
||||
gctl::array<double> ys(10);
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
ys[i] = i+1;
|
||||
}
|
||||
|
||||
gctl::linear_mesh_2d l2d_mesh;
|
||||
l2d_mesh.init("mesh-example", "This is a linear mesh", 0.5, 0.5, xs, ys);
|
||||
|
||||
int ybnum = l2d_mesh.get_ybnum();
|
||||
int xbnum = l2d_mesh.get_xbnum();
|
||||
|
||||
gctl::meshdata &data = l2d_mesh.add_data(gctl::ElemData, gctl::Scalar, "double-data", 0.0);
|
||||
for (int j = 0; j < ybnum; j++)
|
||||
{
|
||||
for (int i = 0; i < xbnum; i++)
|
||||
{
|
||||
data.datval_[i + j*xbnum] = i+j;
|
||||
}
|
||||
}
|
||||
|
||||
l2d_mesh.save_gmsh_withdata("sample9-out", gctl::OverWrite, gctl::NotPacked);
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
109
src/mesh/meshio_ex.cpp
Normal file
109
src/mesh/meshio_ex.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/mesh/mesh_io.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
mesh_io mshio;
|
||||
mshio.read_gmsh_v2_ascii("tmp/test");
|
||||
mshio.info();
|
||||
|
||||
array<vertex3dc> nodes;
|
||||
array<triangle> tris;
|
||||
|
||||
mshio.select_elements("Bz (pT)", NodeData);
|
||||
mshio.export_selected_to(tris, nodes);
|
||||
|
||||
//meshio_data &d = mshio.get_data("Bz (pT)", NodeData);
|
||||
//array<double> dat = d.val;
|
||||
array<double> dat1 = mshio.get_selected_data("Bx (pT)", NodeData);
|
||||
array<double> dat2 = mshio.get_selected_data("By (pT)", NodeData);
|
||||
array<double> dat3 = mshio.get_selected_data("Bz (pT)", NodeData);
|
||||
|
||||
mesh_io mshio2;
|
||||
mshio2.import_from(tris, nodes);
|
||||
mshio2.add_data("Bx (pT)", dat1, NodeData, OverWrite);
|
||||
mshio2.add_data("By (pT)", dat2, NodeData, OverWrite);
|
||||
mshio2.add_data("Bz (pT)", dat3, NodeData, OverWrite);
|
||||
mshio2.save_gmsh_v2_ascii("tmp");
|
||||
mshio2.info();
|
||||
|
||||
/*
|
||||
mshio.read_tetgen_ascii("tmp/ex1.1");
|
||||
mshio.edit_group(Disable, GeometryTag, 5);
|
||||
mshio.edit_group(GeometryTag, 1, PhysicalTag, 1);
|
||||
mshio.edit_group(GeometryTag, 2, PhysicalTag, 2);
|
||||
mshio.edit_group(GeometryTag, 3, PhysicalTag, 3);
|
||||
mshio.edit_group(GeometryTag, 4, PhysicalTag, 4);
|
||||
mshio.edit_group(GeometryTag, 1, "Boundary");
|
||||
mshio.edit_group(GeometryTag, 2, "Body1");
|
||||
mshio.edit_group(GeometryTag, 3, "Body2");
|
||||
mshio.edit_group(GeometryTag, 4, "Body3");
|
||||
mshio.save_gmsh_v2_ascii("tmp/ex1.1");
|
||||
*/
|
||||
/*
|
||||
mshio.read_gmsh_v2_ascii("tmp/ex1.1");
|
||||
mshio.convert_tags_to_data(GeometryTag);
|
||||
|
||||
array<double> body_val(mshio.element_size("Body2"), 2.0);
|
||||
mshio.add_element_data("BodyValue", "Body2", body_val);
|
||||
|
||||
array<double> body_val2(mshio.element_size("Body3"), 1.0);
|
||||
mshio.add_element_data("BodyValue", "Body3", body_val2);
|
||||
|
||||
mshio.save_gmsh_v2_ascii("tmp/ex1.2");
|
||||
//mshio.save_vtk_legacy_ascii("tmp/ex1.1");
|
||||
mshio.info();
|
||||
|
||||
const array<vertex3dc> &nodes = mshio.get_nodes();
|
||||
|
||||
array<tetrahedron> body2_tets;
|
||||
mshio.export_elements_to(body2_tets, "All");
|
||||
|
||||
gmshio gio;
|
||||
gio.init_file("tmp.msh", Output);
|
||||
gio.set_packed(NotPacked, Output);
|
||||
gio.save_mesh(body2_tets, nodes);
|
||||
*/
|
||||
/*
|
||||
mshio.read_gmsh_v2_ascii("tmp/wjb.1");
|
||||
mshio.edit_group(Disable);
|
||||
mshio.edit_group(Enable, GeometryTag, 3);
|
||||
mshio.edit_group(Enable, GeometryTag, 8);
|
||||
mshio.edit_group(Enable, GeometryTag, 9);
|
||||
|
||||
mshio.save_gmsh_v2_ascii("tmp/wjb.2");
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
55
src/mesh/tri2d_meshio_ex.cpp
Normal file
55
src/mesh/tri2d_meshio_ex.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/mesh/tri2d_mesh.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
mesh_io mshio;
|
||||
mshio.read_gmsh_v2_ascii("tmp/tri2d");
|
||||
mshio.info();
|
||||
|
||||
array<vertex2dc> nodes;
|
||||
array<triangle2d> tris;
|
||||
|
||||
mshio.select_elements(_3NodeTriangle);
|
||||
mshio.export_selected_to(tris, nodes);
|
||||
_1d_array data = mshio.get_selected_data("Model slowness (s/km)", ElemData);
|
||||
|
||||
triangle2d_mesh tri2dmesh;
|
||||
tri2dmesh.init("Test", "This is a test.", nodes, tris);
|
||||
tri2dmesh.add_data(ElemData, "Test Data", data);
|
||||
tri2dmesh.show_info();
|
||||
tri2dmesh.save_gmsh_withdata("tri2d_out", OverWrite);
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
23
src/optimization/CMakeLists.txt
Normal file
23
src/optimization/CMakeLists.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin/examples)
|
||||
|
||||
macro(add_example name switch)
|
||||
if(${switch})
|
||||
add_executable(${name} ${name}.cpp)
|
||||
set_target_properties(${name} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
|
||||
target_link_libraries(${name} PRIVATE ${GCTL_LIB})
|
||||
target_link_libraries(${name} PRIVATE gctl_optimization)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
add_example(ex1 OFF)
|
||||
add_example(ex2 OFF)
|
||||
add_example(ex3 OFF)
|
||||
add_example(ex4 OFF)
|
||||
add_example(ex5 OFF)
|
||||
add_example(ex6 OFF)
|
||||
add_example(ex7 OFF)
|
||||
add_example(ex8 OFF)
|
||||
add_example(ex9 OFF)
|
||||
add_example(ex10 OFF)
|
||||
add_example(cfg_ex ON)
|
147
src/optimization/cfg_ex.cpp
Normal file
147
src/optimization/cfg_ex.cpp
Normal file
@@ -0,0 +1,147 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/optimization.h"
|
||||
#include "gctl/math/gaussfunc.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
class cfg : public lgd_solver
|
||||
{
|
||||
private:
|
||||
std::vector<gaussian_para2d> gs1_, gs2_;
|
||||
array<double> g1_, g2_;
|
||||
|
||||
common_gradient cmg_;
|
||||
|
||||
array<double> x_;
|
||||
array<double> xm_;
|
||||
array<double> xs_;
|
||||
|
||||
public:
|
||||
cfg(/* args */){}
|
||||
~cfg(){}
|
||||
|
||||
virtual double LGD_Evaluate(const array<double> &x, array<double> &g);
|
||||
void read_gaussians(std::string file, std::vector<gaussian_para2d> &gs);
|
||||
void routine(int argc, char *argv[]);
|
||||
};
|
||||
|
||||
double cfg::LGD_Evaluate(const array<double> &x, array<double> &g)
|
||||
{
|
||||
double f, fx = 0.0;
|
||||
g1_.assign(0.0);
|
||||
g2_.assign(0.0);
|
||||
|
||||
f = 0.0;
|
||||
for (int i = 0; i < gs1_.size(); i++)
|
||||
{
|
||||
f += -1e+3*gctl::gaussian_dist2d(x[0], x[1], gs1_[i]);
|
||||
g1_[0] += -1e+3*gctl::gaussian_dist2d(x[0], x[1], gs1_[i], gctl::Dx);
|
||||
g1_[1] += -1e+3*gctl::gaussian_dist2d(x[0], x[1], gs1_[i], gctl::Dy);
|
||||
}
|
||||
|
||||
cmg_.fill_model_gradient(0, f, g1_);
|
||||
fx += f;
|
||||
|
||||
f = 0.0;
|
||||
for (int i = 0; i < gs2_.size(); i++)
|
||||
{
|
||||
f += -1e+3*gctl::gaussian_dist2d(x[0], x[1], gs2_[i]);
|
||||
g2_[0] += -1e+3*gctl::gaussian_dist2d(x[0], x[1], gs2_[i], gctl::Dx);
|
||||
g2_[1] += -1e+3*gctl::gaussian_dist2d(x[0], x[1], gs2_[i], gctl::Dy);
|
||||
}
|
||||
|
||||
cmg_.fill_model_gradient(1, f, g2_);
|
||||
fx += f;
|
||||
fx += 0.666027; // 目标值
|
||||
|
||||
g = cmg_.get_common_gradient();
|
||||
return fx;
|
||||
}
|
||||
|
||||
void cfg::read_gaussians(std::string file, std::vector<gaussian_para2d> &gs)
|
||||
{
|
||||
gaussian_para2d tmp_p;
|
||||
std::string tmp_str;
|
||||
std::stringstream tmp_ss;
|
||||
|
||||
std::ifstream infile;
|
||||
gctl::open_infile(infile, file, ".txt");
|
||||
|
||||
while(getline(infile, tmp_str))
|
||||
{
|
||||
if (tmp_str[0] == '#') continue;
|
||||
else
|
||||
{
|
||||
gctl::str2ss(tmp_str, tmp_ss);
|
||||
tmp_ss >> tmp_p.mu_x >> tmp_p.mu_y >> tmp_p.sigma_x >> tmp_p.sigma_y >> tmp_p.rho;
|
||||
gs.push_back(tmp_p);
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
return;
|
||||
}
|
||||
|
||||
void cfg::routine(int argc, char *argv[])
|
||||
{
|
||||
cmg_.init(2, 2);
|
||||
g1_.resize(2);
|
||||
g2_.resize(2);
|
||||
|
||||
read_gaussians("example/data/gauss_model", gs1_);
|
||||
read_gaussians("example/data/gauss_model2", gs2_);
|
||||
|
||||
x_.resize(2, 20.0);
|
||||
xm_.resize(2, 0.0);
|
||||
xs_.resize(2, 0.0);
|
||||
array<double> low(2, 0.0);
|
||||
array<double> high(2, 100.0);
|
||||
|
||||
lgd_para para = default_lgd_para();
|
||||
para.alpha = 0.01;
|
||||
para.flight_times = 1000;
|
||||
set_lgd_para(para);
|
||||
|
||||
set_lgd_record_trace();
|
||||
LGD_Minimize(x_, xm_, xs_, low, high);
|
||||
|
||||
save_lgd_trace("trace.txt");
|
||||
std::cout << "x = (" << x_[0] << ", " << x_[1] << ")\n";
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) try
|
||||
{
|
||||
cfg c;
|
||||
c.routine(argc, argv);
|
||||
return 0;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
174
src/optimization/ex1.cpp
Normal file
174
src/optimization/ex1.cpp
Normal file
@@ -0,0 +1,174 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/optimization/lcg.h"
|
||||
#include "gctl/graphic/gnuplot.h"
|
||||
|
||||
#define M 1000
|
||||
#define N 800
|
||||
|
||||
double max_diff(const gctl::array<double> &a, const gctl::array<double> &b)
|
||||
{
|
||||
double max = -1.0;
|
||||
for (size_t i = 0; i < a.size(); i++)
|
||||
{
|
||||
max = std::max(sqrt((a[i] - b[i])*(a[i] - b[i])), max);
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
class ex1 : public gctl::lcg_solver
|
||||
{
|
||||
public:
|
||||
ex1();
|
||||
virtual ~ex1();
|
||||
|
||||
// 计算共轭梯度的B项
|
||||
void cal_partb(const gctl::array<double> &x, gctl::array<double> &B);
|
||||
|
||||
//定义共轭梯度中Ax的算法
|
||||
virtual void LCG_Ax(const gctl::array<double> &x, gctl::array<double> &ax);
|
||||
virtual void LCG_Mx(const gctl::array<double> &x, gctl::array<double> &mx);
|
||||
|
||||
private:
|
||||
gctl::matrix<double> kernel; // 普通二维数组做核矩阵
|
||||
gctl::array<double> tmp_arr; // 中间结果数组
|
||||
gctl::array<double> p; // 预优矩阵
|
||||
};
|
||||
|
||||
ex1::ex1()
|
||||
{
|
||||
kernel.resize(M, N);
|
||||
kernel.random_float(-1.0, 1.0, gctl::RdUniform);
|
||||
|
||||
tmp_arr.resize(M);
|
||||
p.resize(N);
|
||||
for (size_t i = 0; i < N; i++)
|
||||
{
|
||||
p[i] = 1.0;
|
||||
}
|
||||
|
||||
double diag;
|
||||
for (size_t i = 0; i < N; i++)
|
||||
{
|
||||
diag = 0.0;
|
||||
for (size_t j = 0; j < M; j++)
|
||||
{
|
||||
diag += kernel[j][i]*kernel[j][i];
|
||||
}
|
||||
p[i] = 1.0/diag;
|
||||
}
|
||||
}
|
||||
|
||||
ex1::~ex1(){}
|
||||
|
||||
void ex1::cal_partb(const gctl::array<double> &x, gctl::array<double> &B)
|
||||
{
|
||||
LCG_Ax(x, B);
|
||||
return;
|
||||
}
|
||||
|
||||
void ex1::LCG_Ax(const gctl::array<double> &x, gctl::array<double> &ax)
|
||||
{
|
||||
matvec(tmp_arr, kernel, x);
|
||||
matvec(ax, kernel, tmp_arr, gctl::Trans);
|
||||
return;
|
||||
}
|
||||
|
||||
void ex1::LCG_Mx(const gctl::array<double> &x, gctl::array<double> &mx)
|
||||
{
|
||||
vecmul(mx, p, x);
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// 生成一组正演解
|
||||
gctl::array<double> fm(N);
|
||||
fm.random_float(1.0, 2.0, gctl::RdUniform);
|
||||
|
||||
ex1 test;
|
||||
|
||||
// 计算共轭梯度B项
|
||||
gctl::array<double> B(N);
|
||||
test.cal_partb(fm, B);
|
||||
|
||||
// 声明一组解
|
||||
gctl::array<double> m(N, 0.0);
|
||||
|
||||
test.set_lcg_message(gctl::LCG_SOLUTION);
|
||||
|
||||
std::ofstream ofile("log.txt");
|
||||
test.LCG_Minimize(m, B, gctl::LCG_CG, ofile);
|
||||
ofile << "maximal difference: " << max_diff(fm, m) << std::endl;
|
||||
|
||||
test.save_convergence("convergence");
|
||||
gctl::gnuplot gt;
|
||||
gt.to_buffer();
|
||||
gt.send("set terminal png size 800,600");
|
||||
gt.send("set output \"convergence.png\"");
|
||||
gt.send("plot \"convergence.txt\" using 1:2 with lines");
|
||||
gt.send("set output");
|
||||
gt.send_buffer();
|
||||
|
||||
m.assign(0.0);
|
||||
|
||||
test.LCG_Minimize(m, B, gctl::LCG_PCG, ofile);
|
||||
ofile << "maximal difference: " << max_diff(fm, m) << std::endl;
|
||||
|
||||
m.assign(0.0);
|
||||
|
||||
test.LCG_Minimize(m, B, gctl::LCG_CGS, ofile);
|
||||
ofile << "maximal difference: " << max_diff(fm, m) << std::endl;
|
||||
ofile.close();
|
||||
|
||||
test.set_lcg_message(gctl::LCG_SOLUTION);
|
||||
|
||||
m.assign(0.0);
|
||||
|
||||
test.LCG_Minimize(m, B, gctl::LCG_BICGSTAB);
|
||||
std::clog << "maximal difference: " << max_diff(fm, m) << std::endl;
|
||||
|
||||
m.assign(0.0);
|
||||
|
||||
test.LCG_Minimize(m, B, gctl::LCG_BICGSTAB2);
|
||||
std::clog << "maximal difference: " << max_diff(fm, m) << std::endl;
|
||||
|
||||
gctl::array<double> low(N, 1.0);
|
||||
gctl::array<double> hig(N, 2.0);
|
||||
|
||||
m.assign(0.0);
|
||||
|
||||
test.LCG_MinimizeConstrained(m, B, low, hig, gctl::LCG_PG);
|
||||
std::clog << "maximal difference: " << max_diff(fm, m) << std::endl;
|
||||
|
||||
m.assign(0.0);
|
||||
|
||||
test.LCG_MinimizeConstrained(m, B, low, hig, gctl::LCG_SPG);
|
||||
std::clog << "maximal difference: " << max_diff(fm, m) << std::endl;
|
||||
return 0;
|
||||
}
|
64
src/optimization/ex10.cpp
Normal file
64
src/optimization/ex10.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 <iostream>
|
||||
#include <iomanip>
|
||||
#include "../lib/optimization.h"
|
||||
#include "gctl/core.h"
|
||||
#include "gctl/algorithms.h"
|
||||
|
||||
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;
|
||||
|
||||
gctl::array<double> x(3), y(3), m(3);
|
||||
x.random_float(-1.0, 1.0, gctl::RdUniform, 452);
|
||||
gctl::matvec(y, A, x);
|
||||
|
||||
cout<<"A(" << A.row_size() << ", " << A.col_size() << ") = " <<endl;
|
||||
A.show();
|
||||
|
||||
gctl::svd svdd;
|
||||
svdd.decompose(A);
|
||||
svdd.solve(y, m);
|
||||
|
||||
cout << "x = "; x.show();
|
||||
cout << "m = "; m.show();
|
||||
return 0;
|
||||
}
|
179
src/optimization/ex2.cpp
Normal file
179
src/optimization/ex2.cpp
Normal file
@@ -0,0 +1,179 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/optimization.h"
|
||||
|
||||
#define M 90
|
||||
#define N 100
|
||||
|
||||
// get random floating points
|
||||
double random_double(double l, double t)
|
||||
{
|
||||
return (t-l)*rand()*1.0/RAND_MAX + l;
|
||||
}
|
||||
|
||||
// get random integral numbers
|
||||
int random_int(int small, int big)
|
||||
{
|
||||
return (rand() % (big - small)) + small;
|
||||
}
|
||||
|
||||
class ex2 : public gctl::lgd_solver
|
||||
{
|
||||
protected:
|
||||
gctl::matrix<double> kernel;
|
||||
gctl::array<double> obs, tmp;
|
||||
|
||||
protected:
|
||||
double LGD_Evaluate(const gctl::array<double> &x, gctl::array<double> &g);
|
||||
|
||||
public:
|
||||
ex2();
|
||||
virtual ~ex2(){}
|
||||
|
||||
void CalObs(const gctl::array<double> &x);
|
||||
};
|
||||
|
||||
ex2::ex2()
|
||||
{
|
||||
kernel.resize(M, N);
|
||||
tmp.resize(M);
|
||||
obs.resize(M);
|
||||
|
||||
srand(time(0));
|
||||
// 添加一些大数
|
||||
int tmp_id, tmp_size;
|
||||
double tmp_val;
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
tmp_size = random_int(25, 35);
|
||||
for (int j = 0; j < tmp_size; j++)
|
||||
{
|
||||
tmp_id = random_int(0, N);
|
||||
tmp_val = random_double(-10, 10);
|
||||
|
||||
kernel[i][tmp_id] = tmp_val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double ex2::LGD_Evaluate(const gctl::array<double> &x, gctl::array<double> &g)
|
||||
{
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
tmp[i] = 0.0;
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
tmp[i] += kernel[i][j] * x[j];
|
||||
}
|
||||
tmp[i] -= obs[i];
|
||||
//tmp[i] /= 1e-1;
|
||||
}
|
||||
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
g[j] = 0.0;
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
g[j] += kernel[i][j]*tmp[i];
|
||||
}
|
||||
g[j] *= 2.0/M;
|
||||
}
|
||||
|
||||
double sum = 0.0;
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
sum += tmp[i]*tmp[i];
|
||||
}
|
||||
return sum/M;
|
||||
}
|
||||
|
||||
void ex2::CalObs(const gctl::array<double> &x)
|
||||
{
|
||||
// 计算正演值
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
obs[i] = 0.0;
|
||||
for (int j = 0; j < N; j++)
|
||||
{
|
||||
obs[i] += kernel[i][j]*x[j];
|
||||
}
|
||||
// 添加噪声
|
||||
obs[i] += random_double(-1e-3, 1e-3);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::array<double> m(N, 0.0), mean_m(N, 0.0), stddev_m(N, 0.0), low(N), hig(N);
|
||||
|
||||
// 生成一组正演解 包含一些大值和一些小值
|
||||
gctl::array<double> fm(N);
|
||||
int N2 = (int) N/2;
|
||||
|
||||
srand(time(0));
|
||||
for (int i = 0; i < N2; i++)
|
||||
{
|
||||
fm[i] = random_double(5, 10);
|
||||
//fm[i] = 10.0;
|
||||
}
|
||||
|
||||
for (int i = N2; i < N; i++)
|
||||
{
|
||||
fm[i] = random_double(1, 2);
|
||||
//fm[i] = 1.0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < N2; i++)
|
||||
{
|
||||
low[i] = 4.0; // 对解的范围进行约束
|
||||
hig[i] = 11.0;
|
||||
}
|
||||
|
||||
for (int i = N2; i < N; i++)
|
||||
{
|
||||
low[i] = 0.0;
|
||||
hig[i] = 3.0;
|
||||
}
|
||||
|
||||
ex2 e;
|
||||
e.CalObs(fm);
|
||||
|
||||
gctl::lgd_para my_para = e.default_lgd_para();
|
||||
my_para.flight_times = 20000;
|
||||
my_para.batch = 100;
|
||||
my_para.fmt = 0.5;
|
||||
my_para.smt = 0.05;
|
||||
e.set_lgd_para(my_para);
|
||||
e.LGD_Minimize(m, mean_m, stddev_m, low, hig);
|
||||
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
std::cout << fm[i] << " " << m[i] << " " << mean_m[i] << " " << stddev_m[i] << " " << fabs(mean_m[i] - fm[i]) << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
69
src/optimization/ex3.cpp
Normal file
69
src/optimization/ex3.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "../lib/optimization.h"
|
||||
|
||||
class TEST_FUNC : public gctl::lbfgs_solver
|
||||
{
|
||||
public:
|
||||
TEST_FUNC();
|
||||
~TEST_FUNC();
|
||||
|
||||
virtual double LBFGS_Evaluate(const gctl::array<double> &x, gctl::array<double> &g);
|
||||
|
||||
void Routine();
|
||||
|
||||
private:
|
||||
gctl::array<double> m_x;
|
||||
};
|
||||
|
||||
TEST_FUNC::TEST_FUNC()
|
||||
{
|
||||
m_x.resize(3, 0.0);
|
||||
}
|
||||
|
||||
TEST_FUNC::~TEST_FUNC(){}
|
||||
|
||||
// test functions
|
||||
// 3 = 3*x1 + x2 + 2*x3*x3
|
||||
// 1 = -3*x1 + 5*x2*x2 + 2*x1*x3
|
||||
// -12 = 25*x1*x2 + 20*x3
|
||||
double TEST_FUNC::LBFGS_Evaluate(const gctl::array<double> &x, gctl::array<double> &g)
|
||||
{
|
||||
double f0,f1,f2,temp;
|
||||
f0 = 3*x[0] + x[1] + 2*x[2]*x[2] - 3.012; //这里添加一点噪声
|
||||
f1 = -3*x[0] + 5*x[1]*x[1] + 2*x[0]*x[2] - 1.04252;
|
||||
f2 = 25*x[0]*x[1] + 20*x[2] + 12.12479;
|
||||
temp = sqrt(f0*f0+f1*f1+f2*f2);
|
||||
|
||||
g[0] = 0.5*(6*f0+2*f1*(2*x[2]-3)+50*f2*x[1])/temp;
|
||||
g[1] = 0.5*(2*f0+20*f1*x[1]+50*f2*x[0])/temp;
|
||||
g[2] = 0.5*(8*f0*x[2]+4*f1*x[0]+40*f2)/temp;
|
||||
return temp;
|
||||
}
|
||||
|
||||
void TEST_FUNC::Routine()
|
||||
{
|
||||
gctl::lbfgs_para self_para = default_lbfgs_para();
|
||||
self_para.m = 10;
|
||||
self_para.past = 5;
|
||||
self_para.residual = 1e-10;
|
||||
//self_para.min_step = 1e-30;
|
||||
//self_para.max_linesearch = 40;
|
||||
//self_para.linesearch = gctl::LBFGS_LINESEARCH_BACKTRACKING_WOLFE;
|
||||
|
||||
set_lbfgs_para(self_para);
|
||||
|
||||
std::ofstream ofile("log.txt");
|
||||
show_lbfgs_para(ofile);
|
||||
|
||||
double fx = LBFGS_Minimize(m_x, ofile);
|
||||
ofile.close();
|
||||
|
||||
m_x.show();
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
TEST_FUNC test;
|
||||
test.Routine();
|
||||
return 0;
|
||||
}
|
91
src/optimization/ex4.cpp
Normal file
91
src/optimization/ex4.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 <iostream>
|
||||
#include <iomanip>
|
||||
#include "../lib/optimization.h"
|
||||
#include "gctl/core.h"
|
||||
#include "gctl/algorithms.h"
|
||||
|
||||
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;
|
||||
A.show();
|
||||
|
||||
gctl::svd svdd;
|
||||
svdd.decompose(A);
|
||||
|
||||
cout<<"U(" << svdd.U.row_size() << ", " << svdd.U.col_size() << ") = " <<endl;
|
||||
svdd.U.show();
|
||||
|
||||
cout<<"S(" << svdd.S.size() << ") = " << endl;
|
||||
svdd.S.show();
|
||||
|
||||
cout<<"V(" << svdd.V.row_size() << ", " << svdd.V.col_size() << ") = " <<endl;
|
||||
svdd.V.show();
|
||||
|
||||
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;
|
||||
}
|
78
src/optimization/ex5.cpp
Normal file
78
src/optimization/ex5.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/optimization.h"
|
||||
#include "gctl/core.h"
|
||||
#include "gctl/algorithms.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::matrix<double> A(5, 5);
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
for (int j = 0; j < 5; j++)
|
||||
{
|
||||
A[i][j] = 3*(i+1) + j - 2;
|
||||
}
|
||||
}
|
||||
// 注意A要满秩
|
||||
A[1][2] = 3.4;
|
||||
A[4][1] = 2.1;
|
||||
A[3][4] = 9.7;
|
||||
A[2][3] = 2.7;
|
||||
|
||||
std::cout<<"A(5, 5) = " <<std::endl;
|
||||
for(int i=0;i<5;i++){
|
||||
for(int j=0;j<5;j++){
|
||||
std::cout<<A[i][j]<<' ';
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
|
||||
gctl::array<double> m(5, 0.5), x(5, 0.0);
|
||||
gctl::array<double> B(5);
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
B[i] = 0.0;
|
||||
for (int j = 0; j < 5; j++)
|
||||
{
|
||||
B[i] += A[i][j] * m[j];
|
||||
}
|
||||
}
|
||||
|
||||
gctl::lu glu(A);
|
||||
glu.decompose();
|
||||
glu.solve(B, x);
|
||||
|
||||
for (size_t i = 0; i < 5; i++)
|
||||
{
|
||||
std::cout << m[i] << " " << x[i] << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
90
src/optimization/ex6.cpp
Normal file
90
src/optimization/ex6.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/optimization.h"
|
||||
#include "gctl/core.h"
|
||||
#include "gctl/algorithms.h"
|
||||
|
||||
// get random floating points
|
||||
double random_double(double l, double t)
|
||||
{
|
||||
return (t-l)*rand()*1.0/RAND_MAX + l;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
srand(time(0));
|
||||
|
||||
gctl::matrix<double> A(5, 5);
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
for (int j = i; j < 5; j++)
|
||||
{
|
||||
if (i == j) A[i][j] = random_double(1.0, 3.0);
|
||||
else A[i][j] = random_double(0.1, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
for (int j = i; j < 5; j++)
|
||||
{
|
||||
A[j][i] = A[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
std::cout<<"A(5, 5) = " <<std::endl;
|
||||
for(int i=0;i<5;i++){
|
||||
for(int j=0;j<5;j++){
|
||||
std::cout<<A[i][j]<<' ';
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
|
||||
gctl::array<double> m(5, 0.5), x(5, 0.0);
|
||||
gctl::array<double> B(5);
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
B[i] = 0.0;
|
||||
for (int j = 0; j < 5; j++)
|
||||
{
|
||||
B[i] += A[i][j] * m[j];
|
||||
}
|
||||
}
|
||||
|
||||
gctl::cholesky gck(A);
|
||||
gck.decompose();
|
||||
gck.solve(B, x);
|
||||
|
||||
for (size_t i = 0; i < 5; i++)
|
||||
{
|
||||
std::cout << m[i] << " " << x[i] << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
136
src/optimization/ex7.cpp
Normal file
136
src/optimization/ex7.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/optimization.h"
|
||||
#include "gctl/core.h"
|
||||
#include "gctl/algorithms.h"
|
||||
|
||||
typedef gctl::array<std::complex<double>> cd_array;
|
||||
|
||||
#define N 1000
|
||||
|
||||
double max_diff(const cd_array &a, const cd_array &b)
|
||||
{
|
||||
double max = -1;
|
||||
std::complex<double> t;
|
||||
for (size_t i = 0; i < a.size(); i++)
|
||||
{
|
||||
t = a[i] - b[i];
|
||||
max = std::max(std::norm(t), max);
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
class ex7 : public gctl::clcg_solver
|
||||
{
|
||||
public:
|
||||
ex7();
|
||||
virtual ~ex7();
|
||||
virtual void CLCG_Ax(const cd_array &x, cd_array &ax, gctl::matrix_layout_e layout, gctl::conjugate_type_e conj);
|
||||
|
||||
// 计算共轭梯度的B项
|
||||
void cal_partb(const cd_array &x, cd_array &B);
|
||||
|
||||
private:
|
||||
gctl::matrix<std::complex<double>> kernel; // 普通二维数组做核矩阵
|
||||
};
|
||||
|
||||
ex7::ex7()
|
||||
{
|
||||
gctl::array<double> tmp(round(0.5*(N+1)*N));
|
||||
tmp.random_float(1.0, 2.0, gctl::RdUniform);
|
||||
|
||||
size_t c = 0;
|
||||
kernel.resize(N, N);
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
for (int j = i; j < N; j++)
|
||||
{
|
||||
kernel[i][j] = tmp[c];
|
||||
kernel[j][i] = kernel[i][j];
|
||||
c++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ex7::~ex7(){}
|
||||
|
||||
void ex7::cal_partb(const cd_array &x, cd_array &B)
|
||||
{
|
||||
gctl::matvec(B, kernel, x);
|
||||
return;
|
||||
}
|
||||
|
||||
void ex7::CLCG_Ax(const cd_array &x, cd_array &ax, gctl::matrix_layout_e layout, gctl::conjugate_type_e conj)
|
||||
{
|
||||
gctl::matvec(ax, kernel, x, layout, conj);
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// 生成一组正演解
|
||||
gctl::array<double> tmp(2*N);
|
||||
tmp.random_float(1.0, 2.0, gctl::RdUniform);
|
||||
|
||||
cd_array fm(N);
|
||||
for (size_t i = 0; i < N; i++)
|
||||
{
|
||||
fm[i].real(tmp[2*i]);
|
||||
fm[i].imag(tmp[2*i + 1]);
|
||||
}
|
||||
|
||||
ex7 test;
|
||||
|
||||
// 计算共轭梯度B项
|
||||
cd_array B(N);
|
||||
test.cal_partb(fm, B);
|
||||
|
||||
// 声明一组解
|
||||
cd_array m(N, std::complex<double>(0.0, 0.0));
|
||||
|
||||
gctl::clcg_para my_para = test.default_clcg_para();
|
||||
my_para.abs_diff = 1;
|
||||
|
||||
test.set_clcg_para(my_para);
|
||||
|
||||
test.CLCG_Minimize(m, B, gctl::CLCG_BICG_SYM);
|
||||
std::clog << "maximal difference: " << max_diff(fm, m) << std::endl;
|
||||
|
||||
m.assign(std::complex<double>(0.0, 0.0));
|
||||
test.CLCG_Minimize(m, B, gctl::CLCG_BICG);
|
||||
std::clog << "maximal difference: " << max_diff(fm, m) << std::endl;
|
||||
|
||||
m.assign(std::complex<double>(0.0, 0.0));
|
||||
test.CLCG_Minimize(m, B, gctl::CLCG_CGS);
|
||||
std::clog << "maximal difference: " << max_diff(fm, m) << std::endl;
|
||||
|
||||
m.assign(std::complex<double>(0.0, 0.0));
|
||||
test.CLCG_Minimize(m, B, gctl::CLCG_BICGSTAB);
|
||||
std::clog << "maximal difference: " << max_diff(fm, m) << std::endl;
|
||||
return 0;
|
||||
}
|
233
src/optimization/ex8.cpp
Normal file
233
src/optimization/ex8.cpp
Normal file
@@ -0,0 +1,233 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/optimization.h"
|
||||
#include "gctl/core.h"
|
||||
#include "gctl/algorithms.h"
|
||||
|
||||
#define M 1000
|
||||
#define N 900
|
||||
|
||||
// get random floating points
|
||||
double random_double(double l, double t)
|
||||
{
|
||||
return (t-l)*rand()*1.0/RAND_MAX + l;
|
||||
}
|
||||
|
||||
// get random integral numbers
|
||||
int random_int(int small, int big)
|
||||
{
|
||||
return (rand() % (big - small)) + small;
|
||||
}
|
||||
|
||||
double max_diff(const gctl::_1d_array &a, const gctl::_1d_array &b)
|
||||
{
|
||||
double max = -1.0;
|
||||
for (size_t i = 0; i < a.size(); i++)
|
||||
{
|
||||
max = std::max(fabs(a[i] - b[i]), max);
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
class ex8 : public gctl::lbfgs_solver, public gctl::grad_norm
|
||||
{
|
||||
public:
|
||||
ex8();
|
||||
virtual ~ex8();
|
||||
virtual double LBFGS_Evaluate(const gctl::_1d_array &x, gctl::_1d_array &g);
|
||||
virtual int LBFGS_Progress(const gctl::_1d_array &x, const gctl::_1d_array &g, const double fx,
|
||||
const double converge, const double rate, const gctl::lbfgs_para param, int k, int ls, std::ostream &ss);
|
||||
|
||||
void CalTarget(const gctl::_1d_array &x);
|
||||
|
||||
private:
|
||||
gctl::_1d_array obs1, obs2, obs3, tmp, grad;
|
||||
gctl::_2d_matrix k1, k2, k3;
|
||||
};
|
||||
|
||||
ex8::ex8()
|
||||
{
|
||||
srand(time(0));
|
||||
|
||||
tmp.resize(M);
|
||||
grad.resize(N);
|
||||
|
||||
k1.resize(M, N);
|
||||
obs1.resize(M);
|
||||
// 添加一些大数
|
||||
int tmp_id, tmp_size;
|
||||
double tmp_val;
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
tmp_size = random_int(25, 35);
|
||||
for (int j = 0; j < tmp_size; j++)
|
||||
{
|
||||
tmp_id = random_int(0, N);
|
||||
tmp_val = random_double(-1.0, 1.0);
|
||||
|
||||
k1[i][tmp_id] = tmp_val;
|
||||
}
|
||||
}
|
||||
|
||||
k2.resize(M, N);
|
||||
obs2.resize(M);
|
||||
// 添加一些大数
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
tmp_size = random_int(25, 35);
|
||||
for (int j = 0; j < tmp_size; j++)
|
||||
{
|
||||
tmp_id = random_int(0, N);
|
||||
tmp_val = random_double(-200.0, 200.0);
|
||||
|
||||
k2[i][tmp_id] = tmp_val;
|
||||
}
|
||||
}
|
||||
|
||||
k3.resize(M, N);
|
||||
obs3.resize(M);
|
||||
// 添加一些大数
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
tmp_size = random_int(25, 35);
|
||||
for (int j = 0; j < tmp_size; j++)
|
||||
{
|
||||
tmp_id = random_int(0, N);
|
||||
tmp_val = random_double(-0.01, 0.01);
|
||||
|
||||
k3[i][tmp_id] = tmp_val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ex8::~ex8(){}
|
||||
|
||||
double ex8::LBFGS_Evaluate(const gctl::_1d_array &x, gctl::_1d_array &g)
|
||||
{
|
||||
gctl::matvec(tmp, k1, x);
|
||||
tmp -= obs1;
|
||||
|
||||
gctl::matvec(grad, k1, tmp, gctl::Trans);
|
||||
grad.scale(2.0/M);
|
||||
|
||||
AddSingleLoss(gctl::power2(tmp.module(gctl::L2))/M, grad);
|
||||
|
||||
gctl::matvec(tmp, k2, x);
|
||||
tmp -= obs2;
|
||||
|
||||
gctl::matvec(grad, k2, tmp, gctl::Trans);
|
||||
grad.scale(2.0/M);
|
||||
|
||||
AddSingleLoss(gctl::power2(tmp.module(gctl::L2))/M, grad);
|
||||
|
||||
gctl::matvec(tmp, k3, x);
|
||||
tmp -= obs3;
|
||||
|
||||
gctl::matvec(grad, k3, tmp, gctl::Trans);
|
||||
grad.scale(2.0/M);
|
||||
|
||||
AddSingleLoss(gctl::power2(tmp.module(gctl::L2))/M, grad);
|
||||
|
||||
return GradNormLoss(g);
|
||||
}
|
||||
|
||||
int ex8::LBFGS_Progress(const gctl::_1d_array &x, const gctl::_1d_array &g, const double fx,
|
||||
const double converge, const double rate, const gctl::lbfgs_para param, int k, int ls, std::ostream &ss)
|
||||
{
|
||||
UpdateWeights();
|
||||
|
||||
return gctl::lbfgs_solver::LBFGS_Progress(x, g, fx, converge, rate, param, k, ls, ss);
|
||||
}
|
||||
|
||||
void ex8::CalTarget(const gctl::_1d_array &x)
|
||||
{
|
||||
// 计算正演值
|
||||
gctl::matvec(obs1, k1, x);
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
// 添加噪声
|
||||
obs1[i] += random_double(-1e-3, 1e-3);
|
||||
}
|
||||
|
||||
gctl::matvec(obs2, k2, x);
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
// 添加噪声
|
||||
obs2[i] += random_double(-1e-3, 1e-3);
|
||||
}
|
||||
|
||||
gctl::matvec(obs3, k3, x);
|
||||
for (int i = 0; i < M; i++)
|
||||
{
|
||||
// 添加噪声
|
||||
obs3[i] += random_double(-1e-3, 1e-3);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// 生成一组正演解
|
||||
gctl::_1d_array fm(N);
|
||||
fm.random_float(1.0, 2.0, gctl::RdUniform);
|
||||
|
||||
ex8 test;
|
||||
|
||||
// 计算拟合目标项
|
||||
test.CalTarget(fm);
|
||||
|
||||
// 声明一组解
|
||||
gctl::_1d_array m(N, 0.0);
|
||||
|
||||
gctl::lbfgs_para self_para = test.default_lbfgs_para();
|
||||
self_para.linesearch = gctl::LBFGS_LINESEARCH_BACKTRACKING_STRONG_WOLFE;
|
||||
self_para.epsilon = 1e-6;
|
||||
|
||||
test.set_lbfgs_para(self_para);
|
||||
test.show_lbfgs_para();
|
||||
|
||||
test.InitGradNorm(3, N);
|
||||
test.set_control_weight(1.0);
|
||||
test.set_weight_step(0.00001);
|
||||
|
||||
double fx = test.LBFGS_Minimize(m);
|
||||
|
||||
std::clog << "maximal difference: " << max_diff(fm, m) << std::endl;
|
||||
|
||||
gctl::_1d_array records;
|
||||
test.get_records(records);
|
||||
for (size_t i = 0; i < records.size(); i++)
|
||||
{
|
||||
if ((i+1)%3 == 0)
|
||||
{
|
||||
std::cout << records[i] << "\n";
|
||||
}
|
||||
else std::cout << records[i] << " ";
|
||||
}
|
||||
return 0;
|
||||
}
|
76
src/optimization/ex9.cpp
Normal file
76
src/optimization/ex9.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/optimization.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
class ex9 : public lgd_solver
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
ex9(){}
|
||||
virtual ~ex9(){}
|
||||
|
||||
virtual double LGD_Evaluate(const array<double> &x, array<double> &g){return 0.0;}
|
||||
};
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
ex9 e;
|
||||
|
||||
lgd_para p = e.default_lgd_para();
|
||||
p.beta = 1.2;
|
||||
p.seed = 125;
|
||||
e.set_lgd_para(p);
|
||||
|
||||
array<double> dist;
|
||||
e.get_levy_distribution(dist);
|
||||
|
||||
double m = dist.mean();
|
||||
double s = dist.std();
|
||||
|
||||
int c = 0;
|
||||
for (size_t i = 0; i < dist.size(); i++)
|
||||
{
|
||||
if (dist[i] > m + 3*s) c++;
|
||||
}
|
||||
|
||||
std::cout << "mean = " << dist.mean() << "\n";
|
||||
std::cout << "std = " << dist.std() << "\n";
|
||||
std::cout << "rms = " << dist.rms() << "\n";
|
||||
std::cout << "max = " << dist.max() << "\n";
|
||||
std::cout << "min = " << dist.min() << "\n";
|
||||
std::cout << "ratio = " << 5000.0*c/dist.size() << "\n";
|
||||
|
||||
for (size_t i = 0; i < dist.size(); i++)
|
||||
{
|
||||
std::clog << dist[i] << "\n";
|
||||
}
|
||||
return 0;
|
||||
}
|
31
src/potential/CMakeLists.txt
Normal file
31
src/potential/CMakeLists.txt
Normal file
@@ -0,0 +1,31 @@
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
|
||||
macro(add_example name switch)
|
||||
if(${switch})
|
||||
# 添加可执行程序名称
|
||||
add_executable(${name} ${name}.cpp)
|
||||
# 设置安装后的动态库调用地址
|
||||
set_target_properties(${name} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF)
|
||||
set_target_properties(${name} PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
|
||||
target_link_libraries(${name} PUBLIC gctl_potential)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
add_example(gobser_tri2d_ex OFF)
|
||||
add_example(gobser_tri2d_sph_ex OFF)
|
||||
add_example(mobser_dipole_ex OFF)
|
||||
add_example(mobser_block_ex OFF)
|
||||
add_example(mobser_block_gradient_ex OFF)
|
||||
add_example(mobser_tri_ex OFF)
|
||||
add_example(mobser_tri_sph_ex OFF)
|
||||
add_example(mobser_tricone_ex OFF)
|
||||
add_example(mobser_tetra_ex OFF)
|
||||
add_example(mobser_tetra_ex2 OFF)
|
||||
add_example(mobser_tetra_sph_ex OFF)
|
||||
add_example(mobser_tesseroid_ex OFF)
|
||||
add_example(read_IGRF_ex OFF)
|
||||
add_example(read_Swarm_ex OFF)
|
||||
add_example(power_spectrum_ex OFF)
|
||||
add_example(forward_mag_shc OFF)
|
||||
add_example(forward_grav_shc ON)
|
109
src/potential/forward_grav_shc.cpp
Normal file
109
src/potential/forward_grav_shc.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/io.h"
|
||||
#include "../lib/potential.h"
|
||||
// 多线程异步头文件
|
||||
#include <thread>
|
||||
#include <future>
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
shc_data sd;
|
||||
array<point3ds> obsp;
|
||||
|
||||
// Read SHC coefficients
|
||||
int read_shc_file()
|
||||
{
|
||||
dsv_io shc_in;
|
||||
shc_in.delimeter(',');
|
||||
shc_in.load_text("data/gggrx/gggrx_0660pm_sha", ".tab");
|
||||
shc_in.info(ColInfo);
|
||||
|
||||
_1d_array gnm, hnm;
|
||||
shc_in.get_column(gnm, 3);
|
||||
shc_in.get_column(hnm, 4);
|
||||
|
||||
sd.init(gnm, hnm, 1, 0, 660, 660, 1738.0);
|
||||
sd.set_GM(4902.799806931690);
|
||||
|
||||
std::cout << "Done reading SHC coefficients\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Prepare observation sites
|
||||
int init_observations()
|
||||
{
|
||||
grid_points_2d(obsp, -179.5, 179.5, -89.5, 89.5, 1.0, 1.0, 1738.0 + 100.0, TopLeft);
|
||||
|
||||
std::cout << "Done initializing obervations points\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Main process
|
||||
int main(int argc, char *argv[]) try
|
||||
{
|
||||
std::future<int> future1 = std::async(std::launch::async, read_shc_file);
|
||||
std::future<int> future2 = std::async(std::launch::async, init_observations);
|
||||
|
||||
int result1 = future1.get();
|
||||
int result2 = future2.get();
|
||||
if (result1 != 0 || result2 != 0)
|
||||
throw std::runtime_error("Terminated with unexpected errors.");
|
||||
|
||||
// Calculate over all observation sites
|
||||
array<point3dc> V;
|
||||
gobser(V, sd, obsp, FullMsg);
|
||||
|
||||
array<double> Vr = V.extract<double>([](const point3dc &b) -> double {return b.z;});
|
||||
array<double> Vt = V.extract<double>([](const point3dc &b) -> double {return b.x;});
|
||||
array<double> Vp = V.extract<double>([](const point3dc &b) -> double {return b.y;});
|
||||
Vr.scale(1e+8);
|
||||
Vt.scale(1e+5);
|
||||
Vp.scale(1e+5);
|
||||
|
||||
// Save resutls
|
||||
geodsv_io magout;
|
||||
magout.init_table(obsp.size(), 6);
|
||||
magout.column_names({"lon", "lat", "rad", "Vr", "Vt", "Vp"});
|
||||
magout.fill_column_point3ds(obsp, "rad", "lon", "lat");
|
||||
magout.fill_column(Vr, "Vr");
|
||||
magout.fill_column(Vt, "Vt");
|
||||
magout.fill_column(Vp, "Vp");
|
||||
magout.save_csv("data/gggrx/gggrx_0660pm_sha_100km_grid");
|
||||
|
||||
// Create netcdf files
|
||||
save_netcdf_grid("data/gggrx/gggrx_0660pm_sha_100km_grid", Vr, 360, 180, -179.5, 1.0, -89.5, 1.0, TopLeft, "lon", "lat", "Vr");
|
||||
append_netcdf_grid("data/gggrx/gggrx_0660pm_sha_100km_grid", Vt, "lon", "lat", "Vt", TopLeft);
|
||||
append_netcdf_grid("data/gggrx/gggrx_0660pm_sha_100km_grid", Vp, "lon", "lat", "Vp", TopLeft);
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
105
src/potential/forward_mag_shc.cpp
Normal file
105
src/potential/forward_mag_shc.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 <thread>
|
||||
#include <future>
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
shc_data sd;
|
||||
array<point3ds> obsp;
|
||||
|
||||
// Read SHC coefficients
|
||||
int read_shc_file()
|
||||
{
|
||||
dsv_io shc_in;
|
||||
shc_in.head_number(9);
|
||||
shc_in.load_text("data/Ravaetal2020/LP1999_L1_d450", ".cof");
|
||||
shc_in.info(HeadInfo|ColInfo);
|
||||
|
||||
_1d_array gnm, hnm;
|
||||
shc_in.get_column(gnm, 3);
|
||||
shc_in.get_column(hnm, 4);
|
||||
|
||||
sd.init(gnm, hnm, 1, 0, 450, 450, 1737.4);
|
||||
|
||||
std::cout << "Done reading SHC coefficients\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Prepare observation sites
|
||||
int init_observations()
|
||||
{
|
||||
grid_points_2d(obsp, -179.5, 179.5, -89.5, 89.5, 1.0, 1.0, 1737.4 + 100.0, TopLeft);
|
||||
|
||||
std::cout << "Done initializing obervations points\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Main process
|
||||
int main(int argc, char *argv[]) try
|
||||
{
|
||||
std::future<int> future1 = std::async(std::launch::async, read_shc_file);
|
||||
std::future<int> future2 = std::async(std::launch::async, init_observations);
|
||||
|
||||
int result1 = future1.get();
|
||||
int result2 = future2.get();
|
||||
if (result1 != 0 || result2 != 0)
|
||||
throw std::runtime_error("Terminated with unexpected errors.");
|
||||
|
||||
// Calculate over all observation sites
|
||||
array<point3dc> B;
|
||||
magobser(B, sd, obsp, FullMsg);
|
||||
|
||||
array<double> Br = B.extract<double>([](const point3dc &b) -> double {return b.z;});
|
||||
array<double> Bt = B.extract<double>([](const point3dc &b) -> double {return b.x;});
|
||||
array<double> Bp = B.extract<double>([](const point3dc &b) -> double {return b.y;});
|
||||
|
||||
// Save resutls
|
||||
geodsv_io magout;
|
||||
magout.init_table(obsp.size(), 6);
|
||||
magout.column_names({"lon", "lat", "rad", "Br", "Bt", "Bp"});
|
||||
magout.fill_column_point3ds(obsp, "rad", "lon", "lat");
|
||||
magout.fill_column(Br, "Br");
|
||||
magout.fill_column(Bt, "Bt");
|
||||
magout.fill_column(Bp, "Bp");
|
||||
magout.save_csv("data/Ravaetal2020/LP1999_L1_d450_30km_grid");
|
||||
|
||||
// Create netcdf files
|
||||
save_netcdf_grid("data/Ravaetal2020/LP1999_L1_d450_30km_grid", Br, 360, 180, -179.5, 1.0, -89.5, 1.0, TopLeft, "lon", "lat", "Br");
|
||||
append_netcdf_grid("data/Ravaetal2020/LP1999_L1_d450_30km_grid", Bt, "lon", "lat", "Bt", TopLeft);
|
||||
append_netcdf_grid("data/Ravaetal2020/LP1999_L1_d450_30km_grid", Bp, "lon", "lat", "Bp", TopLeft);
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
79
src/potential/gobser_tri2d_ex.cpp
Normal file
79
src/potential/gobser_tri2d_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/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "../lib/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
array<vertex2dc> vert;
|
||||
array<triangle2d> elem;
|
||||
|
||||
gmshio gio;
|
||||
gio.init_file("data/cylinder2d/cylinder2d", Input);
|
||||
gio.set_packed(NotPacked, Input);
|
||||
gio.read_mesh(elem, vert);
|
||||
|
||||
for (size_t i = 0; i < elem.size(); i++)
|
||||
{
|
||||
if (cross(*elem[i].vert[1] - *elem[i].vert[0], *elem[i].vert[2] - *elem[i].vert[0]) < 0.0)
|
||||
{
|
||||
vertex2dc *tmp = elem[i].vert[0]; elem[i].vert[0] = elem[i].vert[1]; elem[i].vert[1] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
array<double> rho(elem.size(), 1.0);
|
||||
|
||||
array<point2dc> obsp(201);
|
||||
obsp.sequence(point2dc(-500.0, 0.0), point2dc(5.0, 0.0));
|
||||
|
||||
array<double> vx(obsp.size()), vz(obsp.size());
|
||||
array<double> vxx(obsp.size()), vzz(obsp.size());
|
||||
array<double> vxz(obsp.size()), vzx(obsp.size());
|
||||
gobser(vx, elem, obsp, rho, gctl::Vx);
|
||||
gobser(vz, elem, obsp, rho, gctl::Vz);
|
||||
gobser(vxx, elem, obsp, rho, gctl::Txx);
|
||||
gobser(vxz, elem, obsp, rho, gctl::Txz);
|
||||
gobser(vzx, elem, obsp, rho, gctl::Tzx);
|
||||
gobser(vzz, elem, obsp, rho, gctl::Tzz);
|
||||
|
||||
geodsv_io tio;
|
||||
tio.init_table(obsp.size(), 8);
|
||||
tio.column_names({"X", "Y", "Vx", "Vz", "Vxx", "Vxz", "Vzx", "Vzz"});
|
||||
tio.fill_column_point2dc(obsp, "X", "Y");
|
||||
tio.fill_column(vx, "Vx", 12);
|
||||
tio.fill_column(vz, "Vz", 12);
|
||||
tio.fill_column(vxx, "Vxx", 12);
|
||||
tio.fill_column(vxz, "Vxz", 12);
|
||||
tio.fill_column(vzx, "Vzx", 12);
|
||||
tio.fill_column(vzz, "Vzz", 12);
|
||||
tio.save_text("data/cylinder2d/gravity_2d");
|
||||
return 0;
|
||||
}
|
113
src/potential/gobser_tri2d_sph_ex.cpp
Normal file
113
src/potential/gobser_tri2d_sph_ex.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "toml.hpp"
|
||||
#include "../lib/potential.h"
|
||||
#include "gctl/core.h"
|
||||
#include "gctl/geometry.h"
|
||||
#include "gctl/io.h"
|
||||
|
||||
using namespace gctl;
|
||||
int main(int argc, char *argv[]) try
|
||||
{
|
||||
toml::value toml_data = toml::parse(argv[1]);
|
||||
std::string in_file = toml::find<std::string>(toml_data, "input-file");
|
||||
std::string out_file = toml::find<std::string>(toml_data, "output-file");
|
||||
std::string rho_name = toml::find<std::string>(toml_data, "rho-name");
|
||||
double ab_rho = toml::find<double>(toml_data, "ab-rho");
|
||||
|
||||
// read model
|
||||
array<triangle2d> ele;
|
||||
array<vertex2dc> vert;
|
||||
array<gmsh_physical_group> phys;
|
||||
_2i_vector ele_tag;
|
||||
|
||||
gmshio mio;
|
||||
mio.init_file(in_file, Input);
|
||||
mio.set_packed(NotPacked, Input);
|
||||
mio.read_mesh(ele, vert, &ele_tag);
|
||||
mio.read_physical_groups(phys);
|
||||
|
||||
for (size_t i = 0; i < ele.size(); i++)
|
||||
{
|
||||
if (cross(*ele[i].vert[1] - *ele[i].vert[0], *ele[i].vert[2] - *ele[i].vert[0]) < 0.0)
|
||||
{
|
||||
vertex2dc *tmp = ele[i].vert[0]; ele[i].vert[0] = ele[i].vert[1]; ele[i].vert[1] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
array<double> rho(ele.size());
|
||||
for (size_t i = 0; i < ele.size(); i++)
|
||||
{
|
||||
if (ele_tag[i][0] == mio.physical_name2tag(phys, rho_name)) rho[i] = ab_rho;
|
||||
else rho[i] = 0.0;
|
||||
}
|
||||
|
||||
// calculate gravity
|
||||
array<point2dp> obsp;
|
||||
grid_points_1d(obsp, 100.0, 80.0, -0.1, 6381000.0);
|
||||
|
||||
array<double> gx(obsp.size());
|
||||
array<double> gz(obsp.size());
|
||||
array<double> gxx(obsp.size());
|
||||
array<double> gxz(obsp.size());
|
||||
array<double> gzx(obsp.size());
|
||||
array<double> gzz(obsp.size());
|
||||
gobser(gx, ele, obsp, rho, Vx, FullMsg);
|
||||
gobser(gz, ele, obsp, rho, Vz, FullMsg);
|
||||
gobser(gxx, ele, obsp, rho, Txx, FullMsg);
|
||||
gobser(gxz, ele, obsp, rho, Txz, FullMsg);
|
||||
gobser(gzx, ele, obsp, rho, Tzx, FullMsg);
|
||||
gobser(gzz, ele, obsp, rho, Tzz, FullMsg);
|
||||
|
||||
array<double> r(obsp.size()), d(obsp.size());
|
||||
for (size_t i = 0; i < obsp.size(); i++)
|
||||
{
|
||||
r[i] = obsp[i].rad;
|
||||
d[i] = deg(obsp[i].arc) - 90.0;
|
||||
}
|
||||
|
||||
geodsv_io gio;
|
||||
gio.init_table(obsp.size(), 8);
|
||||
gio.column_names({"rad", "deg", "gx", "gz", "gxx", "gxz", "gzx", "gzz"});
|
||||
gio.fill_column(r, "rad");
|
||||
gio.fill_column(d, "deg");
|
||||
gio.fill_column(gx, "gx");
|
||||
gio.fill_column(gz, "gz");
|
||||
gio.fill_column(gxx, "gxx");
|
||||
gio.fill_column(gxz, "gxz");
|
||||
gio.fill_column(gzx, "gzx");
|
||||
gio.fill_column(gzz, "gzz");
|
||||
gio.save_csv(out_file);
|
||||
|
||||
system("gnuplot data/shell2d/plot.gnu");
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
77
src/potential/mobser_block_ex.cpp
Normal file
77
src/potential/mobser_block_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 "../lib/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// 设置块体模型
|
||||
array<mag_block> bk(1);
|
||||
bk[0].set(-50, 50, -50, 50, -50, 0);
|
||||
// 设置块体的磁化率与磁化参数
|
||||
array<double> sus(1, 0.1);
|
||||
array<magblock_para> mag_para(1);
|
||||
mag_para[0].inclina_deg = 20.0;
|
||||
mag_para[0].declina_deg = 2.0;
|
||||
bk[0].att = &mag_para[0];
|
||||
// 设置观测点位
|
||||
array<point3dc> obsp;
|
||||
gridspace(point3dc(-300, 0, 5), point3dc(300, 0, 5), point3dc(0, -300, 5), point3dc(0, 300, 5), 121, 121, obsp);
|
||||
|
||||
// 正演计算
|
||||
array<double> hax, hay, za, obsval;
|
||||
magobser(hax, bk, obsp, sus, Hax, ShortMsg);
|
||||
// 保存网格
|
||||
gctl::save_netcdf_grid("out_magobser_block", hax, 121, 121, -300.0, 5.0, -300.0, 5.0, "x", "y", "Hax");
|
||||
|
||||
magobser(hay, bk, obsp, sus, Hay, ShortMsg);
|
||||
// 保存网格
|
||||
gctl::append_netcdf_grid("out_magobser_block", hay, "x", "y", "Hay");
|
||||
|
||||
magobser(za, bk, obsp, sus, Za, ShortMsg);
|
||||
// 保存网格
|
||||
gctl::append_netcdf_grid("out_magobser_block", za, "x", "y", "Za");
|
||||
|
||||
magobser(obsval, bk, obsp, sus, 60.0, 30.0, DeltaT, ShortMsg);
|
||||
// 保存网格
|
||||
gctl::append_netcdf_grid("out_magobser_block", obsval, "x", "y", "DeltaT");
|
||||
|
||||
magobser(obsval, bk, obsp, sus, 60.0, 30.0, DeltaTx, ShortMsg);
|
||||
// 保存网格
|
||||
gctl::append_netcdf_grid("out_magobser_block", obsval, "x", "y", "DeltaTx");
|
||||
|
||||
magobser(obsval, bk, obsp, sus, 60.0, 30.0, DeltaTy, ShortMsg);
|
||||
// 保存网格
|
||||
gctl::append_netcdf_grid("out_magobser_block", obsval, "x", "y", "DeltaTy");
|
||||
|
||||
magobser(obsval, bk, obsp, sus, 60.0, 30.0, DeltaTz, ShortMsg);
|
||||
// 保存网格
|
||||
gctl::append_netcdf_grid("out_magobser_block", obsval, "x", "y", "DeltaTz");
|
||||
return 0;
|
||||
}
|
77
src/potential/mobser_block_gradient_ex.cpp
Normal file
77
src/potential/mobser_block_gradient_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 "../lib/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// 设置块体模型
|
||||
// 设置块体的磁化率与磁化参数
|
||||
int m_num = 50, n_num = 50;
|
||||
array<mag_block> bk(m_num*n_num);
|
||||
array<double> sus(m_num*n_num, 0.1);
|
||||
array<magblock_para> mag_para(m_num*n_num);
|
||||
for (int i = 0; i < m_num; i++)
|
||||
{
|
||||
for (int j = 0; j < n_num; j++)
|
||||
{
|
||||
if (j >= 20 && j <= 29 && i >= 20 && i <= 29) bk[j + i*n_num].set(j*10.0, (j+1)*10.0, i*10.0, (i+1)*10.0, -10.0, 0.0);
|
||||
else bk[j + i*n_num].set(j*10.0, (j+1)*10.0, i*10.0, (i+1)*10.0, -1e-6, 0.0);
|
||||
|
||||
mag_para[j + i*n_num].inclina_deg = 90.0;
|
||||
mag_para[j + i*n_num].declina_deg = 0.0;
|
||||
bk[j + i*n_num].att = mag_para.get(j + i*n_num);
|
||||
}
|
||||
}
|
||||
|
||||
// 设置观测点位
|
||||
array<point3dc> obsp;
|
||||
gridspace(point3dc(5, 0, 5), point3dc(495, 0, 5), point3dc(0, 5, 5), point3dc(0, 495, 5), 50, 50, obsp);
|
||||
|
||||
// 正演计算
|
||||
array<double> za, za_grad;
|
||||
magobser(za, bk, obsp, sus, Za, FullMsg);
|
||||
|
||||
for (int i = 0; i < bk.size(); i++)
|
||||
{
|
||||
bk[i].vert[0]->z = -1e-6;
|
||||
bk[i].vert[1]->z = -1e-6;
|
||||
bk[i].vert[2]->z = -1e-6;
|
||||
bk[i].vert[3]->z = -1e-6;
|
||||
}
|
||||
|
||||
loss_func lf(za, L2);
|
||||
lf.set_uncertainty(1.0);
|
||||
|
||||
magobser_wrt_thickness(za_grad, lf, obsp, sus, bk, Za, ShortMsg);
|
||||
// 保存网格
|
||||
gctl::save_netcdf_grid("out_magobser_block_gradient", za, 50, 50, 5.0, 10.0, 5.0, 10.0, "x", "y", "Za");
|
||||
gctl::append_netcdf_grid("out_magobser_block_gradient", za_grad, "x", "y", "Za_Grad");
|
||||
return 0;
|
||||
}
|
57
src/potential/mobser_dipole_ex.cpp
Normal file
57
src/potential/mobser_dipole_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/io.h"
|
||||
#include "gctl/geometry.h"
|
||||
#include "../lib/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
mag_dipole md;
|
||||
md.M = 7.61365e+22; // 7.94e+22;
|
||||
md.n.set(point3dc(0.0, 0.0, 1.0));
|
||||
|
||||
point3ds op;
|
||||
point3dc B;
|
||||
for (int i = 0; i < 181; i++)
|
||||
{
|
||||
for (int j = 0; j < 361; j++)
|
||||
{
|
||||
op.lon = -180 + 1.0*j;
|
||||
op.lat = 90 - 1.0*i;
|
||||
op.rad = GCTL_Earth_Radius;
|
||||
|
||||
B = magkernel_single(md, op);
|
||||
|
||||
std::cout << op.lon << " " << op.lat << " "
|
||||
<< B.x << " " << B.y << " " << B.z << " "
|
||||
<< B.module() << "\n";
|
||||
}
|
||||
}
|
||||
}
|
92
src/potential/mobser_tesseroid_ex.cpp
Normal file
92
src/potential/mobser_tesseroid_ex.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "../lib/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(101*101);
|
||||
for (int i = 0; i < 101; i++)
|
||||
{
|
||||
lat = 10.0 + 0.1*i;
|
||||
for (int j = 0; j < 101; j++)
|
||||
{
|
||||
lon = 20.0 + 0.1*j;
|
||||
obes[i*101+j].lon = lon;
|
||||
obes[i*101+j].lat = lat;
|
||||
obes[i*101+j].rad = GCTL_Earth_Radius + 40000.0;
|
||||
}
|
||||
}
|
||||
|
||||
gctl::array<gctl::mag_tesseroid> tesses(1);
|
||||
gctl::array<gctl::magtess_para> mtess(1);
|
||||
gctl::_1d_array inclina(1, 60.0), declina(1, 20.0);
|
||||
|
||||
tesses[0].set(GCTL_Earth_Radius - 21000.0, GCTL_Earth_Radius - 1000.0, 24, 26, 14, 16);
|
||||
|
||||
gctl::callink_magnetic_para_earth_sph(tesses, mtess, 60, 20);
|
||||
gctl::set_geomag_angles(mtess, inclina, declina);
|
||||
|
||||
gctl::array<double> sus(1, 0.08);
|
||||
gctl::array<double> data_x, data_y, data_z, deltaT;
|
||||
|
||||
magobser(data_z, tesses, obes, sus, gctl::Za, 4, gctl::ShortMsg);
|
||||
gctl::save_netcdf_grid("data/tesseroid_mag", data_z, 101, 101, 20.0, 0.1, 10.0, 0.1, "x", "y", "Za");
|
||||
|
||||
magobser(data_x, tesses, obes, sus, gctl::Hax, 4, gctl::ShortMsg);
|
||||
gctl::append_netcdf_grid("data/tesseroid_mag", data_x, "x", "y", "Hax");
|
||||
|
||||
magobser(data_y, tesses, obes, sus, gctl::Hay, 4, gctl::ShortMsg);
|
||||
gctl::append_netcdf_grid("data/tesseroid_mag", data_y, "x", "y", "Hay");
|
||||
|
||||
magobser(deltaT, tesses, obes, sus, gctl::DeltaT, 4, gctl::ShortMsg);
|
||||
gctl::append_netcdf_grid("data/tesseroid_mag", deltaT, "x", "y", "DeltaT");
|
||||
|
||||
gctl::array<gctl::point3dc> obsgrad(obes.size());
|
||||
gctl::_1d_array obs_inclina(obes.size(), 60.0), obs_declina(obes.size(), 20.0);
|
||||
|
||||
for (size_t i = 0; i < obsgrad.size(); i++)
|
||||
{
|
||||
obsgrad[i].x = data_z[i];
|
||||
obsgrad[i].y = data_x[i];
|
||||
obsgrad[i].z = data_y[i];
|
||||
}
|
||||
|
||||
magnetic_components2deltaT_sph(obsgrad, obs_inclina, obs_declina, deltaT);
|
||||
gctl::append_netcdf_grid("data/tesseroid_mag", deltaT, "x", "y", "DeltaT2");
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
127
src/potential/mobser_tetra_ex.cpp
Normal file
127
src/potential/mobser_tetra_ex.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "../lib/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
array<vertex3dc> node;
|
||||
array<mag_tetrahedron_ren17> ele17;
|
||||
array<mag_tetrahedron> ele;
|
||||
read_Tetgen_node("data/prism/prism.1", node);
|
||||
read_Tetgen_element("data/prism/prism.1", ele17, node);
|
||||
read_Tetgen_element("data/prism/prism.1", ele, node);
|
||||
|
||||
array<magtet_para_ren17> mag_para17;
|
||||
array<magtet_para> mag_para;
|
||||
array<double> sus(ele17.size(), 0.1);
|
||||
callink_magnetic_para_earth(ele17, mag_para17, 60.0, 30.0);
|
||||
callink_magnetic_para_earth(ele, mag_para, 60.0, 30.0);
|
||||
|
||||
// 设置观测点位
|
||||
array<point3dc> obsp;
|
||||
gridspace(point3dc(-30, 0, 5), point3dc(30, 0, 5), point3dc(0, -30, 5), point3dc(0, 30, 5), 121, 121, obsp);
|
||||
|
||||
// 正演计算
|
||||
array<double> obsval;
|
||||
array<point3dc> obsgrad, obsgrad2;
|
||||
array<tensor> obstensor, obstensor2;
|
||||
|
||||
// 正演磁位数据
|
||||
magobser(obsval, ele17, obsp, sus, ShortMsg);
|
||||
// 保存网格
|
||||
gctl::save_netcdf_grid("out_magobser_tetra", obsval, 121, 121, -30.0, 0.5, -30.0, 0.5, "x", "y", "Potential_17");
|
||||
|
||||
// 正演磁分量数据
|
||||
magobser(obsgrad, ele17, obsp, sus, ShortMsg);
|
||||
// 保存网格
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].x;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra", obsval, "x", "y", "Bx_17");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].y;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra", obsval, "x", "y", "By_17");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].z;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra", obsval, "x", "y", "Bz_17");
|
||||
|
||||
// 正演磁分量数据
|
||||
magobser(obsgrad2, ele, obsp, sus, ShortMsg);
|
||||
// 保存网格
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad2[i].x;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra", obsval, "x", "y", "Bx");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad2[i].y;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra", obsval, "x", "y", "By");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad2[i].z;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra", obsval, "x", "y", "Bz");
|
||||
|
||||
// 计算并保存差值
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].x - obsgrad2[i].x;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra", obsval, "x", "y", "Diff_Bx");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].y - obsgrad2[i].y;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra", obsval, "x", "y", "Diff_By");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].z - obsgrad2[i].z;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra", obsval, "x", "y", "Diff_Bz");
|
||||
|
||||
gctl::_1d_array deltaT;
|
||||
magnetic_components2deltaT(obsgrad2, deltaT, 60, 30);
|
||||
gctl::append_netcdf_grid("out_magobser_tetra", deltaT, "x", "y", "DeltaT");
|
||||
return 0;
|
||||
}
|
77
src/potential/mobser_tetra_ex2.cpp
Normal file
77
src/potential/mobser_tetra_ex2.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/io.h"
|
||||
#include "../lib/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
array<vertex3dc> node;
|
||||
array<mag_tetrahedron> ele;
|
||||
|
||||
gmshio gio;
|
||||
gio.init_file("data/pie/pie", Input);
|
||||
gio.set_packed(NotPacked, Input);
|
||||
gio.read_mesh(ele, node);
|
||||
|
||||
array<magtet_para> mag_para;
|
||||
array<double> sus(ele.size(), 40.0);
|
||||
callink_magnetic_para_earth(ele, mag_para, 90.0, 0.0);
|
||||
|
||||
// 设置观测点位
|
||||
array<point3dc> obsp;
|
||||
gridspace(point3dc(-20, 0, 5), point3dc(20, 0, 5), point3dc(0, -20, 5), point3dc(0, 20, 5), 201, 201, obsp);
|
||||
|
||||
// 正演计算
|
||||
array<double> obsval(obsp.size());
|
||||
array<point3dc> obsgrad;
|
||||
|
||||
// 正演磁分量数据
|
||||
magobser(obsgrad, ele, obsp, sus, ShortMsg);
|
||||
// 保存网格
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].x;
|
||||
}
|
||||
gctl::save_netcdf_grid("out_magobser_tetra", obsval, 201, 201, -20.0, 0.2, -20.0, 0.2, "x", "y", "Bx");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].y;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra", obsval, "x", "y", "By");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].z;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra", obsval, "x", "y", "Bz");
|
||||
|
||||
return 0;
|
||||
}
|
209
src/potential/mobser_tetra_sph_ex.cpp
Normal file
209
src/potential/mobser_tetra_sph_ex.cpp
Normal file
@@ -0,0 +1,209 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 ele17ctronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "gctl/io.h"
|
||||
#include "../lib/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
array<vertex3dc> node;
|
||||
array<mag_tetrahedron_ren17> ele17;
|
||||
array<mag_tetrahedron> ele;
|
||||
|
||||
gmshio fio;
|
||||
fio.init_file("data/tesseroid/shell3d", gctl::Input);
|
||||
fio.set_packed(gctl::NotPacked, gctl::Input);
|
||||
fio.read_node(node);
|
||||
fio.read_element(ele17, node);
|
||||
fio.read_element(ele, node);
|
||||
|
||||
array<magtet_para_ren17> mag_para17;
|
||||
array<magtet_para> mag_para;
|
||||
|
||||
// test for using magnetic susceptibility
|
||||
array<double> sus(ele17.size(), 0.08);
|
||||
array<point3dc> mag_vec;
|
||||
callink_magnetic_para_earth_sph(ele17, mag_para17, 60.0, 20.0, &mag_vec);
|
||||
callink_magnetic_para_earth_sph(ele, mag_para, 60.0, 20.0);
|
||||
|
||||
//fio.init_file("out", gctl::Output);
|
||||
//fio.set_packed(gctl::NotPacked, gctl::Output);
|
||||
//fio.save_mesh(ele17, node);
|
||||
//fio.save_data("mag_vec", mag_vec, gctl::ElemData);
|
||||
|
||||
// 设置观测点位
|
||||
double lon, lat;
|
||||
array<point3ds> obsp(101*101);
|
||||
for (int i = 0; i < 101; i++)
|
||||
{
|
||||
lat = 10.0 + 0.1*i;
|
||||
for (int j = 0; j < 101; j++)
|
||||
{
|
||||
lon = 20.0 + 0.1*j;
|
||||
obsp[i*101+j].lon = lon;
|
||||
obsp[i*101+j].lat = lat;
|
||||
obsp[i*101+j].rad = GCTL_Earth_Radius + 40000.0;
|
||||
}
|
||||
}
|
||||
|
||||
// 正演计算
|
||||
array<double> obsval(obsp.size());
|
||||
array<point3dc> obsgrad, obsgrad2;
|
||||
magobser(obsgrad, ele17, obsp, sus, ShortMsg);
|
||||
|
||||
//array<tensor> obstensor;
|
||||
//magobser(obstensor, ele17, obsp, sus, ShortMsg);
|
||||
|
||||
// 保存网格
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].x;
|
||||
}
|
||||
gctl::save_netcdf_grid("out_magobser_tetra_s", obsval, 101, 101, 20.0, 0.1, 10.0, 0.1, "x", "y", "Br_Ren");
|
||||
//system("gmtsph-regional -i out_magobser_tetra_s_Br.nc -c \"turbo -Z\" -u nT");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].y;
|
||||
}
|
||||
//system("gmtsph-regional -i out_magobser_tetra_s_Bt.nc -c \"turbo -Z\" -u nT");
|
||||
gctl::append_netcdf_grid("out_magobser_tetra_s", obsval, "x", "y", "Bt_Ren");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].z;
|
||||
}
|
||||
//system("gmtsph-regional -i out_magobser_tetra_s_Bp.nc -c \"turbo -Z\" -u nT");
|
||||
gctl::append_netcdf_grid("out_magobser_tetra_s", obsval, "x", "y", "Bp_Ren");
|
||||
|
||||
magobser(obsgrad2, ele, obsp, sus, ShortMsg);
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad2[i].x;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra_s", obsval, "x", "y", "Br");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad2[i].y;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra_s", obsval, "x", "y", "Bt");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad2[i].z;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra_s", obsval, "x", "y", "Bp");
|
||||
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].x - obsgrad2[i].x;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra_s", obsval, "x", "y", "Diff_Br");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].y - obsgrad2[i].y;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra_s", obsval, "x", "y", "Diff_Bt");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].z - obsgrad2[i].z;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra_s", obsval, "x", "y", "Diff_Bp");
|
||||
|
||||
/*
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obstensor[i][0][0];
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra_s", obsval, "x", "y", "Brr");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obstensor[i][0][1];
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra_s", obsval, "x", "y", "Brt");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obstensor[i][0][2];
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra_s", obsval, "x", "y", "Brp");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obstensor[i][1][1];
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra_s", obsval, "x", "y", "Btt");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obstensor[i][1][2];
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra_s", obsval, "x", "y", "Btp");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obstensor[i][2][2];
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra_s", obsval, "x", "y", "Bpp");
|
||||
*/
|
||||
gctl::_1d_array deltaT;
|
||||
gctl::_1d_array inclina(obsgrad2.size(), 60.0), denclina(obsgrad2.size(), 20.0);
|
||||
|
||||
magnetic_components2deltaT_sph(obsgrad2, inclina, denclina, deltaT);
|
||||
gctl::append_netcdf_grid("out_magobser_tetra_s", deltaT, "x", "y", "DeltaT");
|
||||
/*
|
||||
gctl::array<gctl::point3dc> deltaTs;
|
||||
gctl::magnetic_tensors2deltaTs_sph(obstensor, inclina, denclina, deltaTs);
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = deltaTs[i].x;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra_s", obsval, "x", "y", "DeltaTr");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = deltaTs[i].y;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra_s", obsval, "x", "y", "DeltaTt");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = deltaTs[i].z;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tetra_s", obsval, "x", "y", "DeltaTp");
|
||||
*/
|
||||
return 0;
|
||||
}
|
99
src/potential/mobser_tri_ex.cpp
Normal file
99
src/potential/mobser_tri_ex.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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/geometry.h"
|
||||
#include "../lib/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
array<vertex3dc> node;
|
||||
array<mag_triangle> mag_ele;
|
||||
|
||||
gmshio fio;
|
||||
fio.init_file("data/prism_f/prism_f", gctl::Input);
|
||||
fio.set_packed(gctl::NotPacked, gctl::Input);
|
||||
fio.read_node(node);
|
||||
fio.read_element(mag_ele, node);
|
||||
|
||||
// ensure the vertex ordering are all facing outside
|
||||
point3dc ref(0, 0, -5);
|
||||
vertex3dc *t_ptr;
|
||||
for (size_t i = 0; i < mag_ele.size(); i++)
|
||||
{
|
||||
if (dot(mag_ele[i].center() - ref,
|
||||
cross(*mag_ele[i].vert[1] - *mag_ele[i].vert[0],
|
||||
*mag_ele[i].vert[2] - *mag_ele[i].vert[0])) < 0)
|
||||
{
|
||||
t_ptr = mag_ele[i].vert[1];
|
||||
mag_ele[i].vert[1] = mag_ele[i].vert[2];
|
||||
mag_ele[i].vert[2] = t_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
array<magtri_para> mag_para;
|
||||
array<double> sus(mag_ele.size(), 0.1);
|
||||
|
||||
callink_magnetic_para_earth(mag_ele, mag_para, 60.0, 30.0);
|
||||
|
||||
// 设置观测点位
|
||||
array<point3dc> obsp;
|
||||
gridspace(point3dc(-30, 0, 5), point3dc(30, 0, 5), point3dc(0, -30, 5), point3dc(0, 30, 5), 121, 121, obsp);
|
||||
|
||||
// 正演计算
|
||||
array<double> obsval(obsp.size());
|
||||
array<point3dc> obsgrad;
|
||||
array<tensor> obstensor;
|
||||
|
||||
// 正演磁分量数据
|
||||
magobser(obsgrad, mag_ele, obsp, sus, ShortMsg);
|
||||
// 保存网格
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].x;
|
||||
}
|
||||
gctl::save_netcdf_grid("out_magobser_tri", obsval, 121, 121, -30.0, 0.5, -30.0, 0.5, "x", "y", "Bx");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].y;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tri", obsval, "x", "y", "By");
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].z;
|
||||
}
|
||||
gctl::append_netcdf_grid("out_magobser_tri", obsval, "x", "y", "Bz");
|
||||
|
||||
gctl::_1d_array deltaT;
|
||||
magnetic_components2deltaT(obsgrad, deltaT, 60, 30);
|
||||
gctl::append_netcdf_grid("out_magobser_tri", deltaT, "x", "y", "DeltaT");
|
||||
return 0;
|
||||
}
|
111
src/potential/mobser_tri_sph_ex.cpp
Normal file
111
src/potential/mobser_tri_sph_ex.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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/geometry.h"
|
||||
#include "../lib/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
array<vertex3dc> node;
|
||||
array<mag_triangle> mag_ele;
|
||||
|
||||
gmshio fio;
|
||||
fio.init_file("data/stt/stt_2d.msh", gctl::Input);
|
||||
fio.set_packed(gctl::Packed, gctl::Input);
|
||||
fio.read_mesh(mag_ele, node);
|
||||
|
||||
array<magtri_para> mag_para;
|
||||
array<double> sus(mag_ele.size(), 1.0);
|
||||
|
||||
mag_dipole md;
|
||||
md.M = 7.94e+22;
|
||||
md.n.set(point3dc(0.0, 0.0, 1.0));
|
||||
|
||||
point3ds cen_s;
|
||||
array<point3dc> mag_B(mag_ele.size());
|
||||
for (size_t i = 0; i < mag_ele.size(); i++)
|
||||
{
|
||||
cen_s = mag_ele[i].center().c2s();
|
||||
cen_s.rad -= 20000;
|
||||
mag_B[i] = magkernel_single(md, cen_s.s2c());
|
||||
}
|
||||
|
||||
callink_magnetic_para(mag_ele, mag_para, mag_B);
|
||||
|
||||
// 设置观测点位
|
||||
array<point3ds> obsp(mag_ele.size());
|
||||
for (size_t i = 0; i < mag_ele.size(); i++)
|
||||
{
|
||||
obsp[i] = mag_ele[i].center().c2s();
|
||||
obsp[i].rad += 400000;
|
||||
}
|
||||
|
||||
// 正演计算
|
||||
array<double> obsval(obsp.size());
|
||||
array<point3dc> obsgrad, obsgrad2;
|
||||
|
||||
// 正演磁分量数据
|
||||
magobser(obsgrad, mag_ele, obsp, sus, ShortMsg);
|
||||
|
||||
// 改变球体半径大小
|
||||
for (size_t i = 0; i < node.size(); i++)
|
||||
{
|
||||
node[i].set2module(6371008.8 - 40000);
|
||||
}
|
||||
|
||||
callink_magnetic_para(mag_ele, mag_para, mag_B);
|
||||
|
||||
magobser(obsgrad2, mag_ele, obsp, sus, ShortMsg);
|
||||
|
||||
// 保存网格
|
||||
fio.init_file("data/stt/stt_2d_out.msh", gctl::Output);
|
||||
fio.set_packed(gctl::NotPacked, gctl::Output);
|
||||
fio.save_mesh(mag_ele, node);
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].x - obsgrad2[i].x;
|
||||
}
|
||||
fio.save_data("Br", obsval, ElemData);
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].y - obsgrad2[i].y;
|
||||
}
|
||||
fio.save_data("Bt", obsval, ElemData);
|
||||
|
||||
for (int i = 0; i < obsp.size(); ++i)
|
||||
{
|
||||
obsval[i] = obsgrad[i].z - obsgrad2[i].z;
|
||||
}
|
||||
fio.save_data("Bp", obsval, ElemData);
|
||||
|
||||
return 0;
|
||||
}
|
120
src/potential/mobser_tricone_ex.cpp
Normal file
120
src/potential/mobser_tricone_ex.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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/geometry.h"
|
||||
#include "../lib/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
bool clockwise(const triangle &t)
|
||||
{
|
||||
if (dot(cross(*t.vert[1] - *t.vert[0], *t.vert[2] - *t.vert[0]), *t.vert[0]) < 0) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
array<vertex3dc> top_node, btm_node;
|
||||
array<magcone_ren17> top_ele, btm_ele;
|
||||
|
||||
gmshio fio;
|
||||
fio.init_file("data/stt/sph_rect.msh", gctl::Input);
|
||||
fio.set_packed(gctl::NotPacked, gctl::Input);
|
||||
fio.read_mesh(top_ele, top_node);
|
||||
fio.read_mesh(btm_ele, btm_node);
|
||||
|
||||
// 确定三角形顶点排序
|
||||
triangle t;
|
||||
vertex3dc *v = nullptr;
|
||||
for (size_t i = 0; i < top_ele.size(); i++)
|
||||
{
|
||||
t.set(*top_ele[i].vert[0], *top_ele[i].vert[1], *top_ele[i].vert[2]);
|
||||
if (clockwise(t))
|
||||
{
|
||||
v = top_ele[i].vert[0]; top_ele[i].vert[0] = top_ele[i].vert[1]; top_ele[i].vert[1] = v;
|
||||
v = btm_ele[i].vert[0]; btm_ele[i].vert[0] = btm_ele[i].vert[1]; btm_ele[i].vert[1] = v;
|
||||
}
|
||||
}
|
||||
|
||||
vertex3dc origin(point3dc(0.0, 0.0, 0.0), top_node.size());
|
||||
for (size_t i = 0; i < top_ele.size(); i++)
|
||||
{
|
||||
top_ele[i].set_origin(origin);
|
||||
btm_ele[i].set_origin(origin);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < top_node.size(); i++)
|
||||
{
|
||||
top_node[i].set2module(6371200);
|
||||
btm_node[i].set2module(6371200 - 26500);
|
||||
}
|
||||
|
||||
mag_dipole md;
|
||||
md.M = 7.61365e+22;
|
||||
md.n.set(point3dc(0.0, 0.0, 1.0));
|
||||
|
||||
point3dc cen_c;
|
||||
array<point3dc> mag_B(top_ele.size());
|
||||
for (size_t i = 0; i < top_ele.size(); i++)
|
||||
{
|
||||
cen_c = 1.0/6.0*(*top_ele[i].vert[0] + *top_ele[i].vert[1] + *top_ele[i].vert[2] +
|
||||
*btm_ele[i].vert[0] + *btm_ele[i].vert[1] + *btm_ele[i].vert[2]);
|
||||
mag_B[i] = magkernel_single(md, cen_c);
|
||||
}
|
||||
|
||||
// 计算磁体参数
|
||||
array<magcone_para_ren17> top_para, btm_para;
|
||||
array<double> sus(top_ele.size(), 0.01);
|
||||
callink_magnetic_para(top_ele, top_para, mag_B);
|
||||
callink_magnetic_para(btm_ele, btm_para, mag_B);
|
||||
|
||||
// 设置观测点位
|
||||
array<point3ds> obsp;
|
||||
grid_points_2d(obsp, 10.0, 55.0, 20.0, 65.0, 0.25, 0.25, 6371200.0 + 100000);
|
||||
|
||||
// 正演计算
|
||||
array<point3dc> obsgrad;
|
||||
|
||||
// 正演磁分量数据
|
||||
set_magcone_ren17_tolerance(1e-30);
|
||||
magobser(obsgrad, top_ele, btm_ele, obsp, sus, ShortMsg);
|
||||
|
||||
geodsv_io fout;
|
||||
fout.init_table(obsp.size(), 6);
|
||||
fout.set_column_names({"rad", "lon", "lat", "Br", "Bt", "Bp"});
|
||||
fout.fill_column_point3ds(obsp, "rad", "lon", "lat");
|
||||
fout.fill_column_point3dc(obsgrad, "Br", "Bt", "Bp", 12);
|
||||
fout.save_csv("data/stt/mag_obs");
|
||||
|
||||
system("xyz2nc -t data/stt/mag_obs.csv -g data/stt/mag_obs_ren17.nc -r 10/55/20/65 -i 0.25/0.25 -c 1,2,3,4,5 -l x,y,Br,Bt,Bp -d ','");
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
65
src/potential/power_spectrum_ex.cpp
Normal file
65
src/potential/power_spectrum_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/io.h"
|
||||
#include "gctl/geometry.h"
|
||||
#include "../lib/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
std::string data_dir = "/Volumes/DataArchive/Earth/Global/MagneticModels/EMM2017_Linux";
|
||||
text_content tc;
|
||||
tc.head_num_ = 1;
|
||||
tc.load_text(data_dir + "/EMM2017", ".COF");
|
||||
|
||||
int n, m;
|
||||
_1d_array P, C, S;
|
||||
std::stringstream tmp_ss;
|
||||
|
||||
C.resize(tc.lines_.size());
|
||||
S.resize(tc.lines_.size());
|
||||
for (size_t i = 0; i < tc.lines_.size(); i++)
|
||||
{
|
||||
str2ss(tc.lines_[i], tmp_ss);
|
||||
tmp_ss >> n >> m >> C[i] >> S[i];
|
||||
}
|
||||
|
||||
power_spectrum_shc(P, C, S, 6371200, 6371200, 1, 65);
|
||||
|
||||
for (size_t i = 0; i < P.size(); i++)
|
||||
{
|
||||
std::cout << i + 1 << " " << P[i] << "\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
95
src/potential/read_IGRF_ex.cpp
Normal file
95
src/potential/read_IGRF_ex.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "../lib/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
array<IGRF_para> IGRFs;
|
||||
read_IGRF_table("data/IGRFs/Gard21_ECM1_EMM_output", IGRFs);
|
||||
|
||||
std::cout << IGRFs.size() << "\n";
|
||||
std::cout << IGRFs.front().Year << "-" << IGRFs.front().Month << "-" << IGRFs.front().Day << " "
|
||||
<< IGRFs.front().CSystem << " " << IGRFs.front().AltiCode << " " << IGRFs.front().Altitude << " "
|
||||
<< IGRFs.front().X_nT << " " << IGRFs.front().Y_nT << " " << IGRFs.front().Z_nT << " " << IGRFs.front().dF_nT << "\n";
|
||||
std::cout << IGRFs.back().Year << "-" << IGRFs.back().Month << "-" << IGRFs.back().Day << " "
|
||||
<< IGRFs.back().CSystem << " " << IGRFs.back().AltiCode << " " << IGRFs.back().Altitude << " "
|
||||
<< IGRFs.back().X_nT << " " << IGRFs.back().Y_nT << " " << IGRFs.back().Z_nT << " " << IGRFs.back().dF_nT << "\n";
|
||||
|
||||
gmshio gio;
|
||||
gio.init_file("data/IGRFs/Gard21_ECM1.msh", Input);
|
||||
gio.init_file("data/IGRFs/Gard21_ECM1_EMM.msh", Output);
|
||||
gio.set_packed(NotPacked, Input);
|
||||
gio.set_packed(NotPacked, Output);
|
||||
|
||||
array<vertex3dc> nodes;
|
||||
array<triangle> eles;
|
||||
array<double> top, btm, bz;
|
||||
gio.read_mesh(eles, nodes);
|
||||
gio.read_data(top, "crust_top (m)");
|
||||
gio.read_data(btm, "curie_btm (m)");
|
||||
gio.read_data(bz, "Bz (nT)");
|
||||
|
||||
array<double> Bx(eles.size()), By(eles.size()), Bz(eles.size()), F(eles.size());
|
||||
array<point3ds> obs_ps(eles.size());
|
||||
array<point3dc> loc_mag(eles.size());
|
||||
for (size_t i = 0; i < eles.size(); i++)
|
||||
{
|
||||
obs_ps[i] = eles[i].center().c2s();
|
||||
|
||||
loc_mag[i].x = IGRFs[i].Z_nT; // radial
|
||||
loc_mag[i].y = IGRFs[i].Y_nT; // latitudinal
|
||||
loc_mag[i].z = IGRFs[i].X_nT; // longitudinal
|
||||
|
||||
Bx[i] = IGRFs[i].X_nT;
|
||||
By[i] = IGRFs[i].Y_nT;
|
||||
Bz[i] = IGRFs[i].Z_nT;
|
||||
F[i] = IGRFs[i].F_nT;
|
||||
}
|
||||
|
||||
array<point3dc> abs_mag;
|
||||
geomag_local2Cartesian(abs_mag, loc_mag, obs_ps);
|
||||
|
||||
gio.save_mesh(eles, nodes);
|
||||
gio.save_data("crust_top (m)", top, NodeData);
|
||||
gio.save_data("curie_btm (m)", btm, NodeData);
|
||||
gio.save_data("Bz (nT)", bz, ElemData);
|
||||
gio.save_data("EMM_B", abs_mag, ElemData);
|
||||
//gio.save_data("EMM_Bx", Bx, ElemData);
|
||||
//gio.save_data("EMM_By", By, ElemData);
|
||||
//gio.save_data("EMM_Bz", Bz, ElemData);
|
||||
//gio.save_data("EMM_F", F, ElemData);
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
50
src/potential/read_Swarm_ex.cpp
Normal file
50
src/potential/read_Swarm_ex.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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 "iomanip"
|
||||
#include "../lib/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
int spl_odr, smp_num;
|
||||
array<shc_data> SHCs;
|
||||
read_Swarm_shc("data/CHAOS8/CHAOS-8.2_core.shc", SHCs, spl_odr, smp_num);
|
||||
|
||||
std::clog << SHCs.size() << std::endl;
|
||||
std::clog << std::setprecision(10) << SHCs.back().time << std::endl;
|
||||
std::cout << std::setprecision(10) << SHCs.back().coeff_s(20, 20) << std::endl;
|
||||
std::cout << std::setprecision(10) << SHCs.back().coeff_c(20, 20) << std::endl;
|
||||
|
||||
save_Swarm_shc("tmp", SHCs, spl_odr, smp_num);
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
20
src/seismic/CMakeLists.txt
Normal file
20
src/seismic/CMakeLists.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
|
||||
macro(add_example name switch)
|
||||
if(${switch})
|
||||
# 添加可执行程序名称
|
||||
add_executable(${name} ${name}.cpp)
|
||||
# 设置安装后的动态库调用地址
|
||||
set_target_properties(${name} PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
|
||||
target_link_libraries(${name} PUBLIC ${GCTL_LIB})
|
||||
target_link_libraries(${name} PUBLIC gctl_seismic)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
add_example(check_utc_time ON)
|
||||
add_example(check_sig ON)
|
||||
add_example(check_sac ON)
|
||||
add_example(check_xc ON)
|
106
src/seismic/check_sac.cpp
Normal file
106
src/seismic/check_sac.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
/********************************************************
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* ANT 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 ANT, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the ANT's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/seismic.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
gctl::SAC sac1("/Users/zhangyi/Desktop/GX_XC/MERGED.2016.121.15.59.58.7600.GX.BBX.00.SHZ.D.SAC");
|
||||
sac1.info();
|
||||
//sac1.plot("tmp.eps");
|
||||
//sac1.save("tmp.SAC_ASC");
|
||||
|
||||
/*
|
||||
gctl::SIG_UNIT sig;
|
||||
gctl::UTC_TIME t("2016-10-17T20:00:00.000");
|
||||
sac1.signal.cut_section(sig, t, 3600);
|
||||
sig.remove_outliers(2.5);
|
||||
sig.remove_mean();
|
||||
sig.plot();
|
||||
*/
|
||||
/*
|
||||
gctl::SAC sac2("exam/data/2016.291.15.59.59.5900.GX.BBX.00.SHZ.D.SAC");
|
||||
sac2.info();
|
||||
|
||||
gctl::array<gctl::SIG_UNIT> sac1_fragments, sac2_fragments;
|
||||
sac1.signal.cut_multiple_sections(gctl::Mintue, 120, sac1_fragments);
|
||||
sac2.signal.cut_multiple_sections(gctl::Mintue, 120, sac2_fragments);
|
||||
|
||||
std::map<int, int> xc_list;
|
||||
std::map<int, int>::iterator iter;
|
||||
for (size_t i = 0; i < sac1_fragments.size(); i++)
|
||||
{
|
||||
for (size_t j = 0; j < sac2_fragments.size(); j++)
|
||||
{
|
||||
if ((sac1_fragments[i].t0 == sac2_fragments[j].t0) &&
|
||||
(sac1_fragments[i].val.size() == sac2_fragments[j].val.size()) &&
|
||||
fabs(sac1_fragments[i].delta - sac2_fragments[j].delta) < 1e-6 &&
|
||||
fabs(sac1_fragments[i].rt0 - sac2_fragments[j].rt0) < 1e-6)
|
||||
{
|
||||
xc_list[i] = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//sac1_fragments[0].remove_mean();
|
||||
//sac2_fragments[0].remove_mean();
|
||||
//sac1_fragments[0].normalize();
|
||||
//sac2_fragments[0].normalize();
|
||||
//sac1_fragments[0].plot();
|
||||
//sac2_fragments[0].plot();
|
||||
|
||||
//gctl::SIG_UNIT s;
|
||||
//s.linear_cross_correlation(sac1_fragments[0], sac2_fragments[0]);
|
||||
//s.plot();
|
||||
|
||||
std::cout << xc_list.size() << "\n";
|
||||
|
||||
int c = 0;
|
||||
gctl::array<gctl::SIG_UNIT> xcs(xc_list.size());
|
||||
for (iter = xc_list.begin(); iter != xc_list.end(); ++iter)
|
||||
{
|
||||
sac1_fragments[iter->first].remove_mean();
|
||||
sac2_fragments[iter->second].remove_mean();
|
||||
sac1_fragments[iter->first].down_sampling(100);
|
||||
sac2_fragments[iter->second].down_sampling(100);
|
||||
sac1_fragments[iter->first].normalize();
|
||||
sac2_fragments[iter->second].normalize();
|
||||
xcs[c].linear_cross_correlation(sac1_fragments[iter->first], sac2_fragments[iter->second]);
|
||||
xcs[c].remove_mean();
|
||||
xcs[c].normalize();
|
||||
c++;
|
||||
}
|
||||
|
||||
gctl::SIG_UNIT x;
|
||||
x.stack_sig_units(xcs);
|
||||
x.plot("xc.eps");
|
||||
*/
|
||||
/*
|
||||
gctl::SAC sac2;
|
||||
gctl::UTC_TIME c("2015-6-9T0:10:00.000");
|
||||
sac1.cut_section(sac2, c, 60.0);
|
||||
sac2.down_sampling(100);
|
||||
sac2.remove_mean();
|
||||
sac2.normalize();
|
||||
sac2.info();
|
||||
sac2.plot("exam/data/segment.eps");
|
||||
sac2.save("exam/data/segment.SAC");
|
||||
*/
|
||||
return 0;
|
||||
}
|
136
src/seismic/check_sig.cpp
Normal file
136
src/seismic/check_sig.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
/********************************************************
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* ANT 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 ANT, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the ANT's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/seismic.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
/*
|
||||
gctl::SIG_UNIT c;
|
||||
std::vector<gctl::SIG_UNIT> a(2);
|
||||
a[0].delta = 0.1;
|
||||
a[1].delta = 0.1;
|
||||
a[0].val.resize(1001);
|
||||
a[1].val.resize(1001);
|
||||
|
||||
a[0].t0.set_time("2010-10-01T12:24:34.340");
|
||||
a[0].te = a[0].t0;
|
||||
a[0].te.add_duration(100);
|
||||
|
||||
a[1].t0.set_time("2010-10-01T12:26:00.340");
|
||||
a[1].te = a[1].t0;
|
||||
a[1].te.add_duration(100);
|
||||
|
||||
double t;
|
||||
for (size_t i = 0; i < a[0].val.size(); i++)
|
||||
{
|
||||
t = a[0].rt0 + a[0].delta*i;
|
||||
a[0].val[i] = 10.0*sin(t*2.0*GCTL_Pi);
|
||||
a[1].val[i] = 3.0*sin(t*2.0*GCTL_Pi) + 5.0*sin(t*1.0*GCTL_Pi);
|
||||
}
|
||||
|
||||
c.merge_sig_units(a);
|
||||
c.info();
|
||||
c.plot();
|
||||
|
||||
c.resampling(0.5, gctl::Second);
|
||||
c.info();
|
||||
c.plot();
|
||||
*/
|
||||
/*
|
||||
gctl::SIG_UNIT a;
|
||||
a.delta = 0.01;
|
||||
a.val.resize(1001);
|
||||
|
||||
double f1 = 10;
|
||||
double f2 = 5;
|
||||
double f3 = 2;
|
||||
|
||||
double t;
|
||||
for (size_t i = 0; i < a.val.size(); i++)
|
||||
{
|
||||
t = a.rt0 + a.delta*i;
|
||||
a.val[i] = 3.0*sin(t*2*GCTL_Pi*f1) + 5.0*sin(t*2*GCTL_Pi*f2) + 2.0*sin(t*2*GCTL_Pi*f3);
|
||||
}
|
||||
|
||||
a.plot();
|
||||
a.filter(gctl::LowPass, gctl::Hamming, 100, 3);
|
||||
a.plot();
|
||||
*/
|
||||
|
||||
gctl::SIG_UNIT a, b, c;
|
||||
a.init(10001, 0.0, 0.01);
|
||||
b.init(10001, 0.0, 0.01);
|
||||
a.val.random_float(0.0, 0.02);
|
||||
b.val.random_float(0.0, 0.02);
|
||||
|
||||
double f1 = 1.0/10.0;
|
||||
|
||||
double t;
|
||||
for (size_t i = 0; i < a.val.size(); i++)
|
||||
{
|
||||
t = a.rt0 + a.delta*i;
|
||||
if (t >= 10 && t <= 20) a.val[i] = sin(2.0*M_PI*t*f1);
|
||||
if (t >= 60 && t <= 70) b.val[i] += sin(2.0*M_PI*t*f1);
|
||||
|
||||
}
|
||||
//a.plot();
|
||||
//b.plot();
|
||||
|
||||
gctl::SIG_UNIT xc;
|
||||
xc.linear_cross_correlation(b, a);
|
||||
//xc.plot("tmp.eps");
|
||||
/*
|
||||
gctl::array<gctl::SIG_UNIT> xcs(sigs.size() - 1);
|
||||
for (size_t i = 0; i < sigs.size() -1 ; i++)
|
||||
{
|
||||
sigs[i].t0 = gctl::UTC_START;
|
||||
sigs[i+1].t0 = gctl::UTC_START;
|
||||
xcs[i].linear_cross_correlation(sigs[i], sigs[i+1]);
|
||||
}
|
||||
|
||||
gctl::SIG_UNIT x;
|
||||
x.stack_sig_units(xcs);
|
||||
x.plot();
|
||||
*/
|
||||
//c.linear_cross_correlation(a, b);
|
||||
//c.circular_cross_correlation(a, b);
|
||||
//c.normalize();
|
||||
//for (size_t i = 0; i < c.val.size(); i++)
|
||||
//{
|
||||
// std::cout << i*c.delta + c.st << " " << c.val[i] << "\n";
|
||||
//}
|
||||
/*
|
||||
gctl::SIG_UNIT a;
|
||||
a.init(10001, 0.0, 0.01);
|
||||
a.val.random(0.0, 1.0);
|
||||
|
||||
double t;
|
||||
for (size_t i = 0; i < a.val.size(); i++)
|
||||
{
|
||||
t = a.rt0 + a.delta*i;
|
||||
a.val[i] += 3.0*sin(t*40.0*GCTL_Pi) + 5.0*sin(t*100.0*GCTL_Pi);
|
||||
}
|
||||
|
||||
a.plot();
|
||||
a.remove_mean(30);
|
||||
a.plot();
|
||||
*/
|
||||
return 0;
|
||||
}
|
65
src/seismic/check_utc_time.cpp
Normal file
65
src/seismic/check_utc_time.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 "../lib/seismic.h"
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
//gctl::UTC_TIME t(2001, 2, 29, 23, 59, 58, 224);
|
||||
/*
|
||||
gctl::UTC_TIME t("2000-2-29T23:59:58.124");
|
||||
std::cout << t.time_str(true) << "\n";
|
||||
std::cout << t.time_str() << "\n";
|
||||
std::cout << t.rdseed_time_str() << "\n";
|
||||
|
||||
t.add_duration(3600*24);
|
||||
std::cout << t.time_str() << "\n";
|
||||
|
||||
t.round_up_to(gctl::Day);
|
||||
std::cout << t.time_str() << "\n";
|
||||
|
||||
gctl::UTC_TIME t2 = t;
|
||||
|
||||
t.add_duration(120.00050001);
|
||||
t2.add_duration(120.00049999);
|
||||
std::cout << t.time_str() << "\n";
|
||||
std::cout << t2.time_str() << "\n";
|
||||
|
||||
t.set_to_now();
|
||||
std::cout << t.time_str() << "\n";
|
||||
*/
|
||||
gctl::UTC_TIME t1, t2;
|
||||
t1.set_time("2021-1-1T14:04:14.591");
|
||||
t2.set_time("2021-1-1T14:02:14.590");
|
||||
if (t1 <= t2) std::cout << "t1 <= t2\n";
|
||||
else std::cout << "t1 > t2\n";
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
75
src/seismic/check_xc.cpp
Normal file
75
src/seismic/check_xc.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/********************************************************
|
||||
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* ANT 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 ANT, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the ANT's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/seismic.h"
|
||||
|
||||
int before_processing(gctl::SIG_UNIT &sig)
|
||||
{
|
||||
//int factor = round(1/sig.delta);
|
||||
if (sig.resampling(0.1, gctl::Second)) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int after_processing(gctl::SIG_UNIT &sig)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sig1_processing(gctl::SIG_UNIT &sig)
|
||||
{
|
||||
//sig.remove_outliers(2);
|
||||
sig.remove_mean();
|
||||
//sig.normalize();
|
||||
sig.spectral_whitening(20);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sig2_processing(gctl::SIG_UNIT &sig)
|
||||
{
|
||||
//sig.remove_outliers(2);
|
||||
sig.remove_mean();
|
||||
//sig.normalize();
|
||||
sig.spectral_whitening(20);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
gctl::seismic::Xcorrelation a;
|
||||
//a.create_stations("/Users/zhangyi/Desktop/GX_XC/seed_info.md", gctl::SBHZ);
|
||||
//a.save_stations("/Users/zhangyi/Desktop/GX_XC/station_info.md");
|
||||
//a.create_station_sac("/Users/zhangyi/Desktop/GX_XC", "/Users/zhangyi/Desktop/GX_XC", before_processing, after_processing);
|
||||
|
||||
std::string s1 = "BBX";
|
||||
std::string s2 = "TLX";
|
||||
|
||||
gctl::SIG_UNIT xc;
|
||||
a.Xcorrelation_two_stations("/Users/zhangyi/Desktop/GX_XC/station_sac_list.txt", s1, s2, xc,
|
||||
gctl::Mintue, 3600, 0.75, 5, sig1_processing, sig2_processing);
|
||||
|
||||
//xc.filter(gctl::HighPass, gctl::Butterworth, 5, 1.0/5.0);
|
||||
xc.save("/Users/zhangyi/Desktop/GX_XC/xc_" +s1 + "_" + s2 + ".txt");
|
||||
|
||||
//a.Xcorrelation_all_stations("/Users/zhangyi/Desktop/TestOut", "/Users/zhangyi/Desktop/TestOut", gctl::Mintue, 180);
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
103
src/unsorted/array_ex.cpp
Normal file
103
src/unsorted/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
src/unsorted/basic_io_ex.cpp
Normal file
67
src/unsorted/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
src/unsorted/cut_2d_tri_mesh_ex.cpp
Normal file
55
src/unsorted/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
src/unsorted/cut_3d_tri_mesh_ex.cpp
Normal file
52
src/unsorted/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
src/unsorted/difference_1d_ex.cpp
Normal file
52
src/unsorted/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
src/unsorted/difference_2d_ex.cpp
Normal file
84
src/unsorted/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
src/unsorted/drtp_ex.cpp
Normal file
49
src/unsorted/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
src/unsorted/dynamic_stddev_ex.cpp
Normal file
81
src/unsorted/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
src/unsorted/ellipse_filter_ex.cpp
Normal file
45
src/unsorted/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
src/unsorted/entity_ex.cpp
Normal file
56
src/unsorted/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
src/unsorted/find_index_ex.cpp
Normal file
57
src/unsorted/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
src/unsorted/flags_parser_ex.cpp
Normal file
70
src/unsorted/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
src/unsorted/frac_model_ex.cpp
Normal file
63
src/unsorted/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
src/unsorted/gaussian_hill_ex.cpp
Normal file
84
src/unsorted/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
src/unsorted/geometry2d_ex.cpp
Normal file
82
src/unsorted/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
src/unsorted/getoption_ex.cpp
Normal file
79
src/unsorted/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
src/unsorted/gmsh_io_ex.cpp
Normal file
56
src/unsorted/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
src/unsorted/gmt_plot_grid_ex.cpp
Normal file
49
src/unsorted/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
src/unsorted/gobser_block_ex.cpp
Normal file
63
src/unsorted/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
src/unsorted/gobser_polygon_ex.cpp
Normal file
58
src/unsorted/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
src/unsorted/gobser_rect2d_ex.cpp
Normal file
56
src/unsorted/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;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user