tmp
This commit is contained in:
parent
aa2e475e99
commit
51deb618aa
File diff suppressed because it is too large
Load Diff
BIN
data/Ravaetal2020/LP1999_L1_d450_30km_grid.nc
Normal file
BIN
data/Ravaetal2020/LP1999_L1_d450_30km_grid.nc
Normal file
Binary file not shown.
@ -28,12 +28,18 @@
|
|||||||
#include "gctl/core.h"
|
#include "gctl/core.h"
|
||||||
#include "gctl/io.h"
|
#include "gctl/io.h"
|
||||||
#include "gctl/potential.h"
|
#include "gctl/potential.h"
|
||||||
|
// 多线程异步头文件
|
||||||
|
#include <thread>
|
||||||
|
#include <future>
|
||||||
|
|
||||||
using namespace gctl;
|
using namespace gctl;
|
||||||
|
|
||||||
int main(int argc, char *argv[]) try
|
shc_data sd;
|
||||||
|
array<point3ds> obsp;
|
||||||
|
|
||||||
|
// Read SHC coefficients
|
||||||
|
int read_shc_file()
|
||||||
{
|
{
|
||||||
// Read SHC coefficients
|
|
||||||
dsv_io shc_in;
|
dsv_io shc_in;
|
||||||
shc_in.head_number(9);
|
shc_in.head_number(9);
|
||||||
shc_in.load_text("data/Ravaetal2020/LP1999_L1_d450", ".cof");
|
shc_in.load_text("data/Ravaetal2020/LP1999_L1_d450", ".cof");
|
||||||
@ -43,46 +49,41 @@ int main(int argc, char *argv[]) try
|
|||||||
shc_in.get_column(gnm, 3);
|
shc_in.get_column(gnm, 3);
|
||||||
shc_in.get_column(hnm, 4);
|
shc_in.get_column(hnm, 4);
|
||||||
|
|
||||||
// Prepare SHC data
|
sd.init(gnm, hnm, 1, 0, 450, 450, 1737.4);
|
||||||
//shc_data sd;
|
|
||||||
//sd.init(gnm, hnm, 1, 0, 450, 450);
|
|
||||||
|
|
||||||
// Prepare observation sites
|
std::cout << "Done reading SHC coefficients\n";
|
||||||
array<point3ds> obsp;
|
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 + 30.0, TopLeft);
|
grid_points_2d(obsp, -179.5, 179.5, -89.5, 89.5, 1.0, 1.0, 1737.4 + 30.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
|
// Calculate over all observation sites
|
||||||
int id;
|
array<point3dc> B;
|
||||||
double rad, fx, fy, fz;
|
magobser(B, sd, obsp, FullMsg);
|
||||||
_1d_array P, dP;
|
|
||||||
_1d_array Br(obsp.size(), 0.0), Bt(obsp.size(), 0.0), Bp(obsp.size(), 0.0);
|
|
||||||
|
|
||||||
progress_bar bar(obsp.size(), "Progress");
|
array<double> Br = B.extract<double>([](const point3dc &b) -> double {return b.z;});
|
||||||
for (int p = 0; p < obsp.size(); p++)
|
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;});
|
||||||
bar.progressed(p);
|
|
||||||
|
|
||||||
rad = obsp[p].rad;
|
|
||||||
schmidt_legendre(90.0 - obsp[p].lat, 450, P, dP);
|
|
||||||
|
|
||||||
// 注意跳过第0阶0次项
|
|
||||||
for (size_t i = 1; i <= 450; i++)
|
|
||||||
{
|
|
||||||
id = i*(i + 1)/2;
|
|
||||||
fx = pow(1737.4/rad, i+2);
|
|
||||||
fz = -1.0*(i+1)*pow(1737.4/rad, i+2);
|
|
||||||
|
|
||||||
for (size_t j = 0; j < i+1; j++)
|
|
||||||
{
|
|
||||||
fy = j/sind(90.0 - obsp[p].lat)*pow(1737.4/rad, i+2);
|
|
||||||
|
|
||||||
Bt[p] += -1.0*fx*(cosd(j*obsp[p].lon)*dP[id + j]*gnm[id + j] + sind(j*obsp[p].lon)*dP[id + j]*hnm[id + j]);
|
|
||||||
Bp[p] += fy*(sind(j*obsp[p].lon)*P[id + j]*gnm[id + j] - cosd(j*obsp[p].lon)*P[id + j]*hnm[id + j]);
|
|
||||||
Br[p] += fz*(cosd(j*obsp[p].lon)*P[id + j]*gnm[id + j] + sind(j*obsp[p].lon)*P[id + j]*hnm[id + j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Save resutls
|
||||||
geodsv_io magout;
|
geodsv_io magout;
|
||||||
magout.init_table(obsp.size(), 6);
|
magout.init_table(obsp.size(), 6);
|
||||||
magout.column_names({"lon", "lat", "rad", "Br", "Bt", "Bp"});
|
magout.column_names({"lon", "lat", "rad", "Br", "Bt", "Bp"});
|
||||||
@ -91,6 +92,11 @@ int main(int argc, char *argv[]) try
|
|||||||
magout.fill_column(Bt, "Bt");
|
magout.fill_column(Bt, "Bt");
|
||||||
magout.fill_column(Bp, "Bp");
|
magout.fill_column(Bp, "Bp");
|
||||||
magout.save_csv("data/Ravaetal2020/LP1999_L1_d450_30km_grid");
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
catch (std::exception &e)
|
catch (std::exception &e)
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
#include "potential/gkernel_tesseroid.h"
|
#include "potential/gkernel_tesseroid.h"
|
||||||
#endif // GCTL_POTENTIAL_TESS
|
#endif // GCTL_POTENTIAL_TESS
|
||||||
|
|
||||||
|
#include "potential/mkernel_shc.h"
|
||||||
#include "potential/mkernel_dipole.h"
|
#include "potential/mkernel_dipole.h"
|
||||||
#include "potential/mkernel_block.h"
|
#include "potential/mkernel_block.h"
|
||||||
#include "potential/mkernel_triangle.h"
|
#include "potential/mkernel_triangle.h"
|
||||||
|
@ -27,12 +27,14 @@
|
|||||||
|
|
||||||
#include "gm_data.h"
|
#include "gm_data.h"
|
||||||
|
|
||||||
void gctl::shc_data::init(const _1d_array& s, const _1d_array& c, int n, int m, int N, int M, double t)
|
void gctl::shc_data::init(const _1d_array& c, const _1d_array& s,
|
||||||
|
int n, int m, int N, int M, double r, double t)
|
||||||
{
|
{
|
||||||
ns = n;
|
ns = n;
|
||||||
ms = m;
|
ms = m;
|
||||||
ne = N;
|
ne = N;
|
||||||
me = M;
|
me = M;
|
||||||
|
rad = r;
|
||||||
time = t;
|
time = t;
|
||||||
Snm.resize((ne + 1)*(ne + 2)/2, 0.0);
|
Snm.resize((ne + 1)*(ne + 2)/2, 0.0);
|
||||||
Cnm.resize((ne + 1)*(ne + 2)/2, 0.0);
|
Cnm.resize((ne + 1)*(ne + 2)/2, 0.0);
|
||||||
@ -40,7 +42,7 @@ void gctl::shc_data::init(const _1d_array& s, const _1d_array& c, int n, int m,
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
for (int n = ns; n <= ne; n++)
|
for (int n = ns; n <= ne; n++)
|
||||||
{
|
{
|
||||||
for (int m = ms; m <= me; m++)
|
for (int m = 0; m <= n; m++)
|
||||||
{
|
{
|
||||||
Snm[n*(n + 1)/2 + m] = s[i];
|
Snm[n*(n + 1)/2 + m] = s[i];
|
||||||
Cnm[n*(n + 1)/2 + m] = c[i];
|
Cnm[n*(n + 1)/2 + m] = c[i];
|
||||||
|
@ -107,12 +107,13 @@ namespace gctl
|
|||||||
struct shc_data
|
struct shc_data
|
||||||
{
|
{
|
||||||
int ns, ms, ne, me; // start degree, start order, end degree, end order
|
int ns, ms, ne, me; // start degree, start order, end degree, end order
|
||||||
|
double rad; // reference radius
|
||||||
double time; // snapshot
|
double time; // snapshot
|
||||||
array<double> Snm, Cnm; // Snm or gnm, Cnm or hnm
|
array<double> Snm, Cnm; // Snm or gnm, Cnm or hnm
|
||||||
|
|
||||||
void init(const _1d_array& s, const _1d_array& c, int n, int m, int N, int M, double t = 0.0);
|
void init(const _1d_array& c, const _1d_array& s, int n, int m, int N, int M, double r, double t = 0.0);
|
||||||
double coeff_s(int n, int m){return Snm[n*(n + 1)/2 + m];}
|
double coeff_s(int n, int m) const {return Snm[n*(n + 1)/2 + m];}
|
||||||
double coeff_c(int n, int m){return Cnm[n*(n + 1)/2 + m];}
|
double coeff_c(int n, int m) const {return Cnm[n*(n + 1)/2 + m];}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
65
lib/potential/mkernel_shc.cpp
Normal file
65
lib/potential/mkernel_shc.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 "mkernel_shc.h"
|
||||||
|
|
||||||
|
void gctl::magobser(array<point3dc> &out_obs, const shc_data &sd, const array<point3ds>& obsp, verbose_type_e verbose)
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
double rad, fx, fy, fz;
|
||||||
|
_1d_array P, dP;
|
||||||
|
|
||||||
|
out_obs.resize(obsp.size(), point3dc(0.0, 0.0, 0.0));
|
||||||
|
|
||||||
|
progress_bar bar(obsp.size(), "magobser_shc");
|
||||||
|
for (int p = 0; p < obsp.size(); p++)
|
||||||
|
{
|
||||||
|
if (verbose == gctl::FullMsg) bar.progressed(p);
|
||||||
|
else if (verbose == gctl::ShortMsg) bar.progressed_simple(p);
|
||||||
|
|
||||||
|
rad = obsp[p].rad;
|
||||||
|
schmidt_legendre(90.0 - obsp[p].lat, 450, P, dP);
|
||||||
|
|
||||||
|
// 注意跳过第0阶0次项
|
||||||
|
for (int i = sd.ns; i <= sd.ne; i++)
|
||||||
|
{
|
||||||
|
id = i*(i + 1)/2;
|
||||||
|
fx = pow(sd.rad/rad, i+2);
|
||||||
|
fz = -1.0*(i+1)*pow(sd.rad/rad, i+2);
|
||||||
|
|
||||||
|
for (int j = 0; j <= i; j++)
|
||||||
|
{
|
||||||
|
fy = j/sind(90.0 - obsp[p].lat)*pow(sd.rad/rad, i+2);
|
||||||
|
|
||||||
|
out_obs[p].x += -1.0*fx*(cosd(j*obsp[p].lon)*dP[id + j]*sd.coeff_c(i, j) + sind(j*obsp[p].lon)*dP[id + j]*sd.coeff_s(i, j));
|
||||||
|
out_obs[p].y += fy*(sind(j*obsp[p].lon)*P[id + j]*sd.coeff_c(i, j) - cosd(j*obsp[p].lon)*P[id + j]*sd.coeff_s(i, j));
|
||||||
|
out_obs[p].z += fz*(cosd(j*obsp[p].lon)*P[id + j]*sd.coeff_c(i, j) + sind(j*obsp[p].lon)*P[id + j]*sd.coeff_s(i, j));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
47
lib/potential/mkernel_shc.h
Normal file
47
lib/potential/mkernel_shc.h
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.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#ifndef _GCTL_MAG_KERNEL_SHC_H
|
||||||
|
#define _GCTL_MAG_KERNEL_SHC_H
|
||||||
|
|
||||||
|
#include "gm_data.h"
|
||||||
|
#include "gctl/utility/progress_bar.h"
|
||||||
|
|
||||||
|
namespace gctl
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @brief Calculate the magnetic componments using the spherical harmonic coefficients.
|
||||||
|
*
|
||||||
|
* @param out_obs Output magnetic field data. Directional components are stored accordingly.
|
||||||
|
* @param sd Spherical harmonic coefficients.
|
||||||
|
* @param obsp The observation points.
|
||||||
|
* @param verbose Output info level.
|
||||||
|
*/
|
||||||
|
void magobser(array<point3dc> &out_obs, const shc_data &sd, const array<point3ds>& obsp, verbose_type_e verbose = FullMsg);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _GCTL_MAG_KERNEL_SHC_H
|
Loading…
Reference in New Issue
Block a user