Select Git revision
SimulationEngineTest.cpp

Philipp Schäfer authored
- now takes parameters for rays as function input instead of using member variables
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
SimulationEngineTest.cpp 4.62 KiB
/*
* ----------------------------------------------------------------
*
* ITA geometrical acoustics
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2019
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
* Tests the image (source) model algorithm.
*
*/
//#include <ITAStopWatch.h>
//#include <ITAStringUtils.h>
#include <ITAGeo/Atmosphere/StratifiedAtmosphere.h>
#include <ITAPropagationPathSim/AtmosphericRayTracing/Simulation/Engine.h>
#include <ITAPropagationPathSim/AtmosphericRayTracing/ODESolver/ODESolver.h>
#include <ITAPropagationPathSim/AtmosphericRayTracing/Rays.h>
#include <ITAPropagationPathSim/AtmosphericRayTracing/Export/ITAGeo.h>
#include <ITAGeo/Base.h>
//#include <cassert>
#include <vector>
#include <stdio.h>
#include <math.h>
using namespace std;
using namespace ITAGeo;
using namespace ITAPropagationPathSim::AtmosphericRayTracing;
using namespace ITAPropagationPathSim::AtmosphericRayTracing::Simulation;
void runTest(const CStratifiedAtmosphere& atmosphere, const double& sourceAltitude, const VistaVector3D& rayDirection, const string& fileSuffix)
{
double tMax = 10;
auto engine = Simulation::CEngine(CAbortAtMaxTime(tMax));
double dt = 0.01;
engine.settings.adaptiveIntegration.bActive = true;
engine.settings.adaptiveIntegration.dMaxError = 0.015;
engine.settings.adaptiveIntegration.dUncriticalError = 0.005;
engine.settings.adaptiveIntegration.iMaxAdaptationLevel = 32;// 32;
engine.settings.dIntegrationTimeStep = dt;
VistaVector3D sourcePosition = VistaVector3D(0, 0, sourceAltitude);
cout << fileSuffix << ":" << endl;
cout << "Starting Simulation-Engine..." << endl;
engine.settings.solverMethod = Simulation::EULER;
std::vector<std::shared_ptr<CRay>> resultEuler = engine.Run(atmosphere, sourcePosition, { rayDirection });
engine.settings.solverMethod = Simulation::RUNGE_KUTTA;
std::vector<std::shared_ptr<CRay>> resultRunge = engine.Run(atmosphere, sourcePosition, { rayDirection });
cout << "Starting export..." << endl;
Export::ToPropagationPath(*resultEuler[0]).Store("SimulationEngineTest_Euler_" + fileSuffix + ".json");
Export::ToPropagationPath(*resultRunge[0]).Store("SimulationEngineTest_RungeKutta_" + fileSuffix + ".json");
cout << "Finished" << endl << endl;
}
void TestHomogeneousAtmosphere(const double& sourceAltitude, const VistaVector3D& rayDirection, const string& fileSuffix)
{
auto humidProfile = std::make_unique<HumidityProfiles::CConstant>(50);
auto tempProfile = std::make_unique<TemperatureProfiles::CRoom>();
auto windProfile = std::make_unique<WindProfiles::CZero>();
auto homogeneousAtmosphere = CStratifiedAtmosphere(std::move(tempProfile), std::move(windProfile), std::move(humidProfile));
runTest(homogeneousAtmosphere, sourceAltitude, rayDirection, fileSuffix);
}
void TestInhomogeneousAtmosphere(const double& sourceAltitude, const VistaVector3D& rayDirection, const string& fileSuffix)
{
auto humidProfile = std::make_unique<HumidityProfiles::CConstant>(50);
auto tempProfile = std::make_unique<TemperatureProfiles::CISA>();
auto windProfile = std::make_unique<WindProfiles::CLog>(0.6, 0.1, VistaVector3D(1, 0, 0));
auto inhomogeneousAtmosphere = CStratifiedAtmosphere(std::move(tempProfile), std::move(windProfile), std::move(humidProfile));
runTest(inhomogeneousAtmosphere, sourceAltitude, rayDirection, fileSuffix);
}
int main(int iNumInArgs, char* pcInArgs[])
{
double sourceAltitude = 1000;
auto rayDirection = VistaVector3D(1, 0, -1).GetNormalized();
TestHomogeneousAtmosphere(sourceAltitude, rayDirection, "HomogeneousDiagonal");
sourceAltitude = 1000;
rayDirection = VistaVector3D(1, 0, -1).GetNormalized();
TestInhomogeneousAtmosphere(sourceAltitude, rayDirection, "InhomogeneousDiagonal");
sourceAltitude = 1000;
rayDirection = VistaVector3D(0, 0, -1).GetNormalized();
TestInhomogeneousAtmosphere(sourceAltitude, rayDirection, "InhomogeneousDownward");
sourceAltitude = 50;
rayDirection = VistaVector3D(1, 0, 0).GetNormalized();
TestInhomogeneousAtmosphere(sourceAltitude, rayDirection, "Multi-Reflection");
sourceAltitude = 50;
const double theta = 101;
rayDirection = VistaVector3D(-sin(theta / 180.0 * M_PI), 0, cos(theta /180.0*M_PI));
TestInhomogeneousAtmosphere(sourceAltitude, rayDirection, "Upwind");
}