1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
/***********************************************/
/**
* @file griddedData2SphericalDistance.cpp
*
* @brief Spherical distance between all point pairs of two grids.
*
* @author Andreas KVas
* @date 2018-01-10
*/
/***********************************************/
// Latex documentation
#define DOCSTRING docstring
static const char *docstring = R"(
Compute the spherical distance on the unit sphere in radians between all point pairs of two grids.
The spherical distance is computed by
\begin{equation}
\psi_{12} = \arccos(\M n_1 \cdot \M n_2),
\end{equation}
where $\M n_i$ is the (normalized) position. This implies that all points are projected onto the unit sphere.
)";
/***********************************************/
#include "programs/program.h"
#include "files/fileMatrix.h"
#include "classes/grid/grid.h"
/***** CLASS ***********************************/
/** @brief Spherical distance between all point pairs of two grids.
* @ingroup programsGroup */
class GriddedData2SphericalDistance
{
public:
void run(Config &config, Parallel::CommunicatorPtr comm);
};
GROOPS_REGISTER_PROGRAM(GriddedData2SphericalDistance, SINGLEPROCESS, "spherical distance between all point pairs of two grids.", Grid, Matrix)
/***********************************************/
void GriddedData2SphericalDistance::run(Config &config, Parallel::CommunicatorPtr /*comm*/)
{
try
{
FileName fileNameDistance;
GridPtr gridPtr1, gridPtr2;
readConfig(config, "outputfileMatrix", fileNameDistance, Config::MUSTSET, "", "matrix containing the spherical distance between all point pairs [rad]");
readConfig(config, "grid1", gridPtr1, Config::MUSTSET, "", "");
readConfig(config, "grid2", gridPtr2, Config::MUSTSET, "", "");
if(isCreateSchema(config)) return;
std::vector<Vector3d> points1 = gridPtr1->points();
std::vector<Vector3d> points2 = gridPtr2->points();
std::for_each(points1.begin(), points1.end(), [](Vector3d &p) {p.normalize();});
std::for_each(points2.begin(), points2.end(), [](Vector3d &p) {p.normalize();});
logStatus<<"compute distance"<<Log::endl;
Matrix S(points1.size(), points2.size());
for(UInt i=0; i<points1.size(); i++)
for(UInt k=0; k<points2.size(); k++)
S(i,k) = std::acos(std::min(std::max(inner(points1.at(i), points2.at(k)), -1.), 1.));
logStatus<<"writing matrix to file <"<<fileNameDistance<<">"<<Log::endl;
writeFileMatrix(fileNameDistance, S);
}
catch(std::exception &e)
{
GROOPS_RETHROW(e)
}
}
/***********************************************/
|