This commit is contained in:
张壹 2024-12-03 15:11:35 +08:00
parent 76a3acc06c
commit 28c2ec1fae
4 changed files with 104 additions and 1 deletions

View File

@ -23,3 +23,4 @@ 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(power_spectrum_ex OFF)

View File

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

View File

@ -240,3 +240,26 @@ void gctl::magnetic_tensors2deltaTs_sph(const array<tensor> &Mag_tensors, const
}
return;
}
void gctl::power_spectrum_shc(array<double> &P, const array<double> &C, const array<double> &S, double R, double r, int n, int N)
{
if (n < 0 || n >= N || C.size() < (N + 1)*(N + 2)/2 || S.size() < (N + 1)*(N + 2)/2)
{
throw std::runtime_error("[gctl::power_spectrum_shc] Invalid input parameters.");
}
P.resize(N - n + 1, 0);
int id;
for (int i = n; i < N + 1; i++)
{
id = i*(i + 1)/2;
for (int j = 0; j < i + 1; j++)
{
P[i - n] += (C[id + j]*C[id + j] + S[id + j]*S[id + j]);
}
P[i - n] *= (n + 1)*pow(R/r, 2*n + 4);
}
return;
}

View File

@ -196,6 +196,20 @@ namespace gctl
* @param T0_declina Declination degrees of the earth normal magnetic field.
*/
void magnetic_tensors2deltaTs_sph(const array<tensor> &Mag_tensors, const _1d_array &T0_inclina, const _1d_array &T0_declina, array<point3dc> &deltaTs);
/**
* @brief Calculate the power spectrum of given spherical harmonic coefficients.
*
* @param P Returned power spectrum
* @param C Cosine coefficients strats from 0 order 0 degree up to least N order N degree
* @param S Sine coefficients strats from 0 order 0 degree up to least N order N degree
* @param R Reference radius (usually is 6371.2 km)
* @param r Observation radius
* @param n Strat order
* @param N End order
*/
void power_spectrum_shc(array<double> &P, const array<double> &C, const array<double> &S,
double R, double r, int n, int N);
}
#endif // _GCTL_GM_DATA_H