tmp
This commit is contained in:
parent
3a10544632
commit
aa2e475e99
101934
data/Ravaetal2020/LP1999_L1_d450.cof
Normal file
101934
data/Ravaetal2020/LP1999_L1_d450.cof
Normal file
File diff suppressed because it is too large
Load Diff
64801
data/Ravaetal2020/LP1999_L1_d450_30km_grid.csv
Normal file
64801
data/Ravaetal2020/LP1999_L1_d450_30km_grid.csv
Normal file
File diff suppressed because it is too large
Load Diff
@ -25,5 +25,6 @@ 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 ON)
|
||||
add_example(power_spectrum_ex OFF)
|
||||
add_example(read_Swarm_ex OFF)
|
||||
add_example(power_spectrum_ex OFF)
|
||||
add_example(forward_mag_shc ON)
|
99
example/forward_mag_shc.cpp
Normal file
99
example/forward_mag_shc.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/core.h"
|
||||
#include "gctl/io.h"
|
||||
#include "gctl/potential.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char *argv[]) try
|
||||
{
|
||||
// Read SHC coefficients
|
||||
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);
|
||||
|
||||
// Prepare SHC data
|
||||
//shc_data sd;
|
||||
//sd.init(gnm, hnm, 1, 0, 450, 450);
|
||||
|
||||
// Prepare observation sites
|
||||
array<point3ds> obsp;
|
||||
grid_points_2d(obsp, -179.5, 179.5, -89.5, 89.5, 1.0, 1.0, 1737.4 + 30.0, TopLeft);
|
||||
|
||||
// Calculate over all observation sites
|
||||
int id;
|
||||
double rad, fx, fy, fz;
|
||||
_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");
|
||||
for (int p = 0; p < obsp.size(); p++)
|
||||
{
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
@ -27,6 +27,29 @@
|
||||
|
||||
#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)
|
||||
{
|
||||
ns = n;
|
||||
ms = m;
|
||||
ne = N;
|
||||
me = M;
|
||||
time = t;
|
||||
Snm.resize((ne + 1)*(ne + 2)/2, 0.0);
|
||||
Cnm.resize((ne + 1)*(ne + 2)/2, 0.0);
|
||||
|
||||
int i = 0;
|
||||
for (int n = ns; n <= ne; n++)
|
||||
{
|
||||
for (int m = ms; m <= me; m++)
|
||||
{
|
||||
Snm[n*(n + 1)/2 + m] = s[i];
|
||||
Cnm[n*(n + 1)/2 + m] = c[i];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
gctl::tensor gctl::transform_matrix(const point3ds &op)
|
||||
{
|
||||
tensor R;
|
||||
|
@ -110,6 +110,7 @@ namespace gctl
|
||||
double time; // snapshot
|
||||
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);
|
||||
double coeff_s(int n, int m){return Snm[n*(n + 1)/2 + m];}
|
||||
double coeff_c(int n, int m){return Cnm[n*(n + 1)/2 + m];}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user