initial upload
This commit is contained in:
parent
954ece83c7
commit
e4c7c12e5f
36
.gitignore
vendored
36
.gitignore
vendored
@ -1,34 +1,2 @@
|
||||
# ---> C++
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
.DS_Store
|
||||
build/
|
15
CMakeLists.txt
Normal file
15
CMakeLists.txt
Normal file
@ -0,0 +1,15 @@
|
||||
cmake_minimum_required(VERSION 3.15.2)
|
||||
# 设置项目名称与语言
|
||||
project(GCTL_ELECMAG VERSION 1.0)
|
||||
# 添加配置配件编写的函数
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
message(STATUS "Platform: " ${CMAKE_HOST_SYSTEM_NAME})
|
||||
message(STATUS "Install prefix: " ${CMAKE_INSTALL_PREFIX})
|
||||
message(STATUS "Processor: " ${CMAKE_HOST_SYSTEM_PROCESSOR})
|
||||
|
||||
find_package(GCTL REQUIRED)
|
||||
include_directories(${GCTL_INC_DIR})
|
||||
|
||||
# 添加库源文件地址
|
||||
add_subdirectory(lib)
|
21
GCTL_ELECMAGConfig.cmake.in
Normal file
21
GCTL_ELECMAGConfig.cmake.in
Normal file
@ -0,0 +1,21 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
set(@PROJECT_NAME@_VERSION "@PROJECT_VERSION@")
|
||||
set_and_check(@PROJECT_NAME@_INSTALL_PREFIX "${PACKAGE_PREFIX_DIR}")
|
||||
set_and_check(@PROJECT_NAME@_INC_DIR "${PACKAGE_PREFIX_DIR}/include")
|
||||
set_and_check(@PROJECT_NAME@_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")
|
||||
set_and_check(@PROJECT_NAME@_LIB_DIR "${PACKAGE_PREFIX_DIR}/lib")
|
||||
set_and_check(@PROJECT_NAME@_LIBRARY_DIR "${PACKAGE_PREFIX_DIR}/lib")
|
||||
|
||||
set(@PROJECT_NAME@_LIB gctl_elecmag)
|
||||
set(@PROJECT_NAME@_LIBRARY gctl_elecmag)
|
||||
|
||||
if(NOT GCTL_FOUND)
|
||||
find_package(GCTL REQUIRED)
|
||||
include_directories(${GCTL_INC_DIR})
|
||||
endif()
|
||||
|
||||
# include target information
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
||||
|
||||
check_required_components(@PROJECT_NAME@)
|
54
installer
Executable file
54
installer
Executable file
@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ $# == 0 || ${1} == "help" ]]; then
|
||||
echo "Compiles executables/libraries and maintains installed files. Two tools 'Cmake' and 'stow' are empolyed here. For more information, see https://cmake.org and https://www.gnu.org/software/stow/."
|
||||
echo ""
|
||||
echo "School of Earth Sciences, Zhejiang University"
|
||||
echo "Yi Zhang (yizhang-geo@zju.edu.cn)"
|
||||
echo ""
|
||||
echo "Usage: ./config.sh [option] [Cmake options]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo "(1) configure: Configure Cmake project(s). This option could take extra Cmake options as in <option>=<value>."
|
||||
echo "(2) build: Build executables/libraries."
|
||||
echo "(3) install: Install executables/libraries to the directory of CMAKE_INSTALL_PREFIX and sym-links them to the target address. This offers a quick and clean remove of the installed files."
|
||||
echo "(4) clean: Clean build/ folder(s)."
|
||||
echo "(5) uninstall: Delete the installed files and sym-links."
|
||||
echo "(6) info: Print out current setups."
|
||||
echo "(7) help: Show help information."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
package=gctl_elecmag
|
||||
address=/opt/stow
|
||||
taress=/usr/local
|
||||
option="-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${address}/${package}"
|
||||
|
||||
if [[ $# -gt 1 ]]; then
|
||||
for opt in "$@"; do
|
||||
if [[ ${opt} != "configure" ]]; then
|
||||
option="${option} -D${opt}"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ ${1} == "configure" && ! -d "build/" ]]; then
|
||||
mkdir build && cd build && cmake .. ${option}
|
||||
elif [[ ${1} == "configure" ]]; then
|
||||
cd build && rm -rf * && cmake .. ${option}
|
||||
elif [[ ${1} == "build" ]]; then
|
||||
cd build && make
|
||||
elif [[ ${1} == "install" ]]; then
|
||||
cd build && sudo make install
|
||||
sudo stow --dir=${address} --target=${taress} -S ${package}
|
||||
elif [[ ${1} == "clean" ]]; then
|
||||
rm -rf build/
|
||||
elif [[ ${1} == "uninstall" ]]; then
|
||||
sudo stow --dir=${address} --target=${taress} -D ${package}
|
||||
sudo rm -rf ${address}/${package}
|
||||
elif [[ ${1} == "info" ]]; then
|
||||
echo "package name:" ${package}
|
||||
echo "stow address:" ${address}
|
||||
echo "target address:" ${taress}
|
||||
echo "Cmake options:" ${option}
|
||||
fi
|
62
lib/CMakeLists.txt
Normal file
62
lib/CMakeLists.txt
Normal file
@ -0,0 +1,62 @@
|
||||
# 设置编译选项
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -O3")
|
||||
# 设置库文件的输出地址
|
||||
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
|
||||
# 设定库源文件文件夹
|
||||
aux_source_directory(electromagnetic/ GCTL_ELECMAG_SRC)
|
||||
|
||||
# 以下部分为库的编译
|
||||
# 注意目标名必须唯一 所以不能直接生成相同名称的动态库与静态库
|
||||
# 注意此处不必为目标名称添加lib前缀和相应后缀,cmake会自行添加
|
||||
add_library(gctl_elecmag SHARED ${GCTL_ELECMAG_SRC})
|
||||
# 首先添加静态库的生成命令
|
||||
add_library(gctl_elecmag_static STATIC ${GCTL_ELECMAG_SRC})
|
||||
# 设置静态库的输出名称从而获得与动态库名称相同的静态库
|
||||
set_target_properties(gctl_elecmag_static PROPERTIES OUTPUT_NAME "gctl_elecmag")
|
||||
# 设置输出目标属性以同时输出动态库与静态库
|
||||
set_target_properties(gctl_elecmag PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||
set_target_properties(gctl_elecmag_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||
# 设置动态库的版本号
|
||||
set_target_properties(gctl_elecmag PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
|
||||
# 设置动态库的运行搜索地址
|
||||
set_target_properties(gctl_elecmag PROPERTIES INSTALL_RPATH /usr/local/lib)
|
||||
set_target_properties(gctl_elecmag_static PROPERTIES INSTALL_RPATH /usr/local/lib)
|
||||
|
||||
#连接动态库
|
||||
target_link_libraries(gctl_elecmag PUBLIC ${GCTL_LIB})
|
||||
target_link_libraries(gctl_elecmag_static ${GCTL_LIB})
|
||||
|
||||
set(CONFIG_FILE_PATH lib/cmake/${PROJECT_NAME})
|
||||
|
||||
configure_package_config_file(${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in
|
||||
${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||
INSTALL_DESTINATION ${CONFIG_FILE_PATH})
|
||||
|
||||
write_basic_package_version_file(${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY SameMajorVersion)
|
||||
|
||||
# 库的安装命令
|
||||
if(WIN32)
|
||||
install(TARGETS gctl_elecmag DESTINATION lib)
|
||||
install(TARGETS gctl_elecmag_static DESTINATION lib)
|
||||
else()
|
||||
install(TARGETS gctl_elecmag gctl_elecmag_static
|
||||
EXPORT ${PROJECT_NAME}Targets
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib)
|
||||
install(EXPORT ${PROJECT_NAME}Targets
|
||||
DESTINATION ${CONFIG_FILE_PATH})
|
||||
install(FILES
|
||||
${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||
${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||
DESTINATION ${CONFIG_FILE_PATH})
|
||||
endif()
|
||||
|
||||
# 头文件安装命令
|
||||
file(GLOB GCTL_HEAD *.h)
|
||||
file(GLOB GCTL_ELECMAG_HEAD electromagnetic/*.h)
|
||||
|
||||
install(FILES ${GCTL_HEAD} DESTINATION include/gctl)
|
||||
install(FILES ${GCTL_ELECMAG_HEAD} DESTINATION include/gctl/electromagnetic)
|
33
lib/electromagnetic.h
Normal file
33
lib/electromagnetic.h
Normal file
@ -0,0 +1,33 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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_ELECTROMAGNETIC_H
|
||||
#define _GCTL_ELECTROMAGNETIC_H
|
||||
|
||||
#include "electromagnetic/magnetometric.h"
|
||||
|
||||
#endif // _GCTL_ELECTROMAGNETIC_H
|
96
lib/electromagnetic/magnetometric.cpp
Normal file
96
lib/electromagnetic/magnetometric.cpp
Normal file
@ -0,0 +1,96 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* 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/maths/legendre.h"
|
||||
#include "magnetometric.h"
|
||||
|
||||
double gctl::mmr_hemisphere_bz(double x, double y, double cx, double cy, double I,
|
||||
double hx, double hy, double hr, double cndt, double bkg_cndt, size_t order)
|
||||
{
|
||||
if (hr <= 0)
|
||||
{
|
||||
throw gctl::runtime_error("Invalid depression radius. From gctl::mmr_hemisphere_bz(...)");
|
||||
}
|
||||
|
||||
double d = sqrt((cx - hx)*(cx - hx) + (cy - hy)*(cy - hy));
|
||||
double r = sqrt((x - hx)*(x - hx) + (y - hy)*(y - hy));
|
||||
double l = sqrt((cx - x)*(cx - x) + (cy - y)*(cy - y));
|
||||
double ct = (d*d + r*r - l*l)/(2.0*d*r);
|
||||
double rho = 1.0/cndt;
|
||||
double bkg_rho = 1.0/bkg_cndt;
|
||||
|
||||
//double st = sqrt(1.0 - ct*ct);
|
||||
//if ((x - hx)*(cy - hy) - (cx - hx)*(y - hy) < 0) st *= -1.0;
|
||||
double st = ((x - hx)*(cy - hy) - (cx - hx)*(y - hy))/(r*d);
|
||||
|
||||
double Cn, Bz = 0.0;
|
||||
if (r <= GCTL_ZERO)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
else if (d > hr)
|
||||
{
|
||||
if (r <= hr)
|
||||
{
|
||||
for (size_t i = 1; i <= order; i++)
|
||||
{
|
||||
Cn = (rho - bkg_rho)/((i+1)*rho + i*bkg_rho);
|
||||
Bz += Cn*pow(r/d, i+1)*gctl::legendre_polynomials(i, ct, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 1; i <= order; i++)
|
||||
{
|
||||
Cn = (rho - bkg_rho)/((i+1)*rho + i*bkg_rho);
|
||||
Bz += Cn*pow(hr/r, i)*pow(hr/d, i+1)*gctl::legendre_polynomials(i, ct, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (r <= hr)
|
||||
{
|
||||
for (size_t i = 1; i <= order; i++)
|
||||
{
|
||||
Cn = (rho - bkg_rho)/((i+1)*rho + i*bkg_rho);
|
||||
Bz += Cn*pow(r/hr, i+1)*pow(d/hr, i)*gctl::legendre_polynomials(i, ct, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 1; i <= order; i++)
|
||||
{
|
||||
Cn = (rho - bkg_rho)/((i+1)*rho + i*bkg_rho);
|
||||
Bz += Cn*pow(d/r, i)*gctl::legendre_polynomials(i, ct, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Bz *= GCTL_MU0*I*st/(4.0*GCTL_Pi*r); // 转换为z轴朝上的坐标体系 -1 * -1
|
||||
return Bz;
|
||||
}
|
58
lib/electromagnetic/magnetometric.h
Normal file
58
lib/electromagnetic/magnetometric.h
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.
|
||||
******************************************************/
|
||||
|
||||
#ifndef _GCTL_MAGNETOMETRIC_H
|
||||
#define _GCTL_MAGNETOMETRIC_H
|
||||
|
||||
#include "cstddef"
|
||||
|
||||
namespace gctl
|
||||
{
|
||||
/**
|
||||
* @brief Forward modeling of the magnetometric resistivity (MMR) data of a outcropping hemispherical depression
|
||||
*
|
||||
* @note Edwards et al., (1978). On the theory of magnetometric resistivity (MMR) methods. Geophysics, 43(6), 1176-1203.
|
||||
*
|
||||
* @param x Field point coordinate x
|
||||
* @param y Field point coordinate y
|
||||
* @param cx Current source coordinate x
|
||||
* @param cy Current source coordinate y
|
||||
* @param I Current value
|
||||
* @param hx Center coordinate x of the depression
|
||||
* @param hy Center coordinate y of the depression
|
||||
* @param hr Radius of the depression
|
||||
* @param cndt conductivity of the depression
|
||||
* @param bkg_cndt conductivity of the host medium
|
||||
* @param order Calculating order of the legendre polynomials (default is 10)
|
||||
* @return Vertical component (Bz) of the anomalous magnetic field
|
||||
*/
|
||||
double mmr_hemisphere_bz(double x, double y, double cx, double cy, double I,
|
||||
double hx, double hy, double hr, double cndt, double bkg_cndt, size_t order = 10);
|
||||
|
||||
} // namespace gctl
|
||||
|
||||
#endif // _GCTL_MAGNETOMETRIC_H
|
Loading…
Reference in New Issue
Block a user