帶有739個頂點和1474個面孔的(433)個ERO的網眼
該代碼是Tsoulis等人在多面體重力模型的C ++ 17中的驗證實現。此外,該模型還提供了Python結合。它最初是在TU慕尼黑和ESA高級概念團隊之間的合作項目中創建的。
如果此實現對您有用,請考慮引用《開源軟件雜誌》上發表的隨附論文。
該實現基於紙質Tsoulis,D.,2012。使用線積分的均勻形狀的多面體來源的全部重力張量的分析計算。地球物理學,77(2),pp.F1-F11。及其在Fortran中的相應實現。
補充細節可以在最近的論文Tsoulis,Dimitrios中找到;佐治亞州Gavriilidou。對多面性重力信號的線積分分析公式的計算綜述。地球物理勘探,2021,69。Jg。,Nr。 8-9,S。1745-1760。以及它在MATLAB中的相應實現,該實現強烈基於Fortran的前者實施。
筆記
該項目的GitHub頁麵包含C ++庫和Python界面的完整廣泛文檔,以及重力模型和高級設置的背景。
對多面性重力模型的評估需要以下參數:
姓名 |
---|
多面體網格(作為頂點和麵部或作為多面體源文件) |
恆定密度 |
網格和常數密度必須匹配。查看文檔以查看受支持的網格文件。
計算為每個計算點p輸出以下參數。相應輸出的單位取決於輸入參數的單位(網格和密度)!因此,如果您的網格在
姓名 | 單位(如果網格 | 評論 |
---|---|---|
電勢或稱為特定能量 | ||
三個笛卡爾方向的重力加速度 | ||
引力量變化的空間變化速率 |
筆記
該重力模型的輸出遵守地球物理和地球物理標誌慣例。因此,潛力
以下示例顯示瞭如何使用Python界面計算立方體周圍的重力:
import numpy as np
from polyhedral_gravity import Polyhedron , GravityEvaluable , evaluate , PolyhedronIntegrity , NormalOrientation
# We define the cube as a polyhedron with 8 vertices and 12 triangular faces
# The polyhedron's normals point outwards (see below for checking this)
# The density is set to 1.0
cube_vertices = np . array (
[[ - 1 , - 1 , - 1 ], [ 1 , - 1 , - 1 ], [ 1 , 1 , - 1 ], [ - 1 , 1 , - 1 ],
[ - 1 , - 1 , 1 ], [ 1 , - 1 , 1 ], [ 1 , 1 , 1 ], [ - 1 , 1 , 1 ]]
)
cube_faces = np . array (
[[ 1 , 3 , 2 ], [ 0 , 3 , 1 ], [ 0 , 1 , 5 ], [ 0 , 5 , 4 ], [ 0 , 7 , 3 ], [ 0 , 4 , 7 ],
[ 1 , 2 , 6 ], [ 1 , 6 , 5 ], [ 2 , 3 , 6 ], [ 3 , 7 , 6 ], [ 4 , 5 , 6 ], [ 4 , 6 , 7 ]]
)
cube_density = 1.0
computation_point = np . array ([ 0 , 0 , 0 ])
我們首先faces
vertices
定義一個恆定密度多面體
cube_polyhedron = Polyhedron (
polyhedral_source = ( cube_vertices , cube_faces ),
density = cube_density ,
)
如果您想通過受支持的文件格式交出多面體,只需將polyhedral_source
參數替換為字符串列表,其中每個字符串都是受支持的文件格式的路徑,例如polyhedral_source=["eros.node","eros.face"]
或polyhedral_source=["eros.mesh"]
。
繼續,計算重力的最簡單方法是使用evaluate
功能:
potential , acceleration , tensor = evaluate (
polyhedron = cube_polyhedron ,
computation_points = computation_point ,
parallel = True ,
)
更高級的方法是使用GravityEvaluable
類。它可以緩存內部數據結構和屬性,這些結構和屬性可以重複用於多次評估。如果您想計算多個計算點的重力,但不知道預先知道“未來點”,這一點尤其有用。
evaluable = GravityEvaluable ( polyhedron = cube_polyhedron ) # stores intermediate computation steps
potential , acceleration , tensor = evaluable (
computation_points = computation_point ,
parallel = True ,
)
# Any future evaluable call after this one will be faster
請注意, computation_point
也可以是(n,3)形數組,以一次計算多個點。在這種情況下, evaluate(..)
或GravityEvaluable
的返回值將是包含潛力,加速度和張量的三胞胎列表。
重力模型要求所有多面體的平面單位正常始終向外指向或向內指向多面體。您可以通過normal_orientation
指定此功能。默認情況下,此屬性是在構造Polyhedron
時檢查的!因此,不用擔心,如果未明確禁用創建無效的Polyhedron
這是不可能的。您可以通過可選的integrity_check
標誌禁用/啟用此設置,甚至可以通過HEAL
自動修復訂購。如果您有信心正確定義網格(例如,通過完整性檢查檢查一次),則可以禁用此檢查(通過DISABLE
),以避免支票的額外運行時開銷。
cube_polyhedron = Polyhedron (
polyhedral_source = ( cube_vertices , cube_faces ),
density = cube_density ,
normal_orientation = NormalOrientation . INWARDS , # OUTWARDS (default) or INWARDS
integrity_check = PolyhedronIntegrity . VERIFY , # VERIFY (default), DISABLE or HEAL
)
提示
Jupyter筆記本中描繪了更多示例和圖。
以下示例顯示瞭如何使用C ++庫計算重力。它類似於上面的Python示例。
// Defining the input like above in the Python example
std::vector<std::array< double , 3 >> vertices = ...
std::vector<std::array< size_t , 3 >> faces = ...
double density = 1.0 ;
// The constant density polyhedron is defined by its vertices & faces
// It also supports the hand-over of NormalOrientation and PolyhedronIntegrity as optional arguments
// as above described for the Python Interface
Polyhedron polyhedron{vertices, faces, density};
std::vector<std::array< double , 3 >> points = ...
std::array< double , 3 > point = points[ 0 ];
bool parallel = true ;
C ++庫還提供了兩種計算重力的方法。通過免費功能evaluate
...
const auto [pot, acc, tensor] = GravityModel::evaluate(polyhedron, point, parallel);
...或通過GravityEvaluable
類。
// Instantiation of the GravityEvaluable object
GravityEvaluable evaluable{polyhedron};
// From now, we can evaluate the gravity model for any point with
const auto [potential, acceleration, tensor] = evaluable(point, parallel);
// or for multiple points with
const auto results = evaluable(points, parallel);
與Python類似,C ++實現還提供了網格檢查功能。
提示
作為參考,請查看C ++可執行文件的主要方法。
Python接口可以輕鬆地使用Conda安裝:
conda install -c conda-forge polyhedral-gravity-model
作為第二個選項,您還可以使用PIP中的PIP安裝Python接口。
pip install polyhedral-gravity
最常見平台的二進製文件可在PYPI上找到,包括Windows,Linux和MacOS。對於MacOS和Linux,提供了x86_64
和aarch64
的二進製文件。如果pip
使用源分佈,請確保安裝了C ++ 17功能的編譯器和CMAKE。
該項目使用以下依賴項,所有這些依賴都會通過cmake自動設置:
atan(..)
所需該模塊將使用C ++ 17的編譯器CMake構建。只需在存儲庫根文件夾中執行以下命令:
pip install .
要修改構建選項(例如並行化),請查看下一個段落。通過在執行pip install .
命令,例如:
export POLYHEDRAL_GRAVITY_PARALLELIZATION= " TBB "
pip install .
(可選:對於更快的構建,您可以在本地Python環境中安裝可用於系統的所有依賴項。這樣,它們就不會從Github中獲取。)
該程序是通過使用CMAKE構建的。因此,首先確保您安裝了CMAKE,然後按照以下步驟操作:
mkdir build
cd build
cmake .. < options >
cmake --build .
可用以下選項:
名稱(默認) | 選項 |
---|---|
polyhedral_gravity_parallelization( CPP ) | CPP =串行執行 / OMP 或Intel的TBB的串行執行或TBB =並行執行 |
logging_level( INFO ) | TRACE , DEBUG , INFO , WARN , ERROR , CRITICAL , OFF |
build_polyhedral_gravity_docs( OFF ) | 構建此文檔 |
build_polyhedral_gravity_tests( ON ) | 構建測試 |
build_polyhedral_python_interface( ON ) | 構建Python界面 |
在測試過程中,polyhedral_gravity_parallelization = TBB
是性能最多的。不建議將logging_level更改為INFO=2
以外的其他內容。
建議使用TBB
後端的CMAKE設置看起來像這樣:
cmake .. -POLYHEDRAL_GRAVITY_PARALLELIZATION= " TBB "
構建後,重力模型可以通過執行:
./polyhedralGravity < YAML-Configuration-File >
yaml-configuration-file包含所需參數的地方。配置文件和多面體源文件的示例可以在此存儲庫中找到文件夾/example-config/
。
配置應看起來與下面給定的示例相似。需要指定多面體網格的源文件(有關文檔中受支持的文件的更多信息),多面體的密度以及應計算重力張量的良好計算點。此外,必須指定.csv輸出文件的名稱。
---
gravityModel :
input :
polyhedron : # polyhedron source-file(s)
- " ../example-config/data/tsoulis.node " # .node contains the vertices
- " ../example-config/data/tsoulis.face " # .face contains the triangular faces
density : 2670.0 # constant density, units must match with the mesh (see section below)
points : # Location of the computation point(s) P
- [ 0, 0, 0 ] # Here it is situated at the origin
check_mesh : true # Fully optional, enables mesh autodetect+repair of
# the polyhedron's vertex ordering (not given: true)
output :
filename : " gravity_result.csv " # The name of the output file
可執行文件產生一個包含的CSV文件
該項目使用Googletest進行測試。在執行這些測試的ODER中,只需在構建目錄中執行以下命令:
ctest
對於Python測試套件,請在存儲庫根文件夾中執行以下命令:
pytest
我們很樂意以建議,錯誤報告和拉出請求的形式接受對項目的貢獻。請查看有關更多信息的貢獻指南。