Commit efb5aeac authored by Philipp Schäfer's avatar Philipp Schäfer
Browse files

ART - Simulation

- IAbortCriterion now is called IExternalWatcher
- this watcher now has a finalize method which is called after the calculation of the ray
parent 0ea5cec4
......@@ -43,11 +43,11 @@ namespace ITAPropagationPathSim
class ITA_PROPAGATION_PATH_SIM_API CEngine
{
public:
IAbortCriterion& iAbortCriterion; //!< Reference to externally defined abort criterion.
IExternalWatcher& externalWatcher; //!< Reference to externally defined abort criterion.
Simulation::Settings settings;
public:
CEngine(IAbortCriterion& abortCriterion = CAbortAtMaxTime()): iAbortCriterion(abortCriterion) {}
CEngine(IExternalWatcher& watcher = CAbortAtMaxTime()): externalWatcher(watcher) {}
public:
std::vector<std::shared_ptr<CRay>> Run(const ITAGeo::CStratifiedAtmosphere& atmosphere, const VistaVector3D& v3SourcePosition, const std::vector<VistaVector3D>& v3RayDirections) const;
......
......@@ -32,19 +32,22 @@ namespace ITAPropagationPathSim
namespace AtmosphericRayTracing
{
namespace Simulation {
class ITA_PROPAGATION_PATH_SIM_API IAbortCriterion
class ITA_PROPAGATION_PATH_SIM_API IExternalWatcher
{
public:
//! Returns true if the abort criterion for tracing the given ray is reached
virtual bool AbortRequested(const std::shared_ptr<CRay>& pRay) = 0;
//! This is called after the tracing of a ray is finished
virtual void FinalizeRay(const std::shared_ptr<CRay>& pRay) = 0;
};
class ITA_PROPAGATION_PATH_SIM_API CAbortAtMaxTime : public IAbortCriterion
class ITA_PROPAGATION_PATH_SIM_API CAbortAtMaxTime : public IExternalWatcher
{
private:
double dTMax;
public:
CAbortAtMaxTime(double tMax = 30) : dTMax(tMax) {}
bool AbortRequested(const std::shared_ptr<CRay>& pRay) { return pRay->LastTimeStamp() >= dTMax; }
void FinalizeRay(const std::shared_ptr<CRay>& pRay) {}
};
enum ITA_PROPAGATION_PATH_SIM_API SolverMethod
......
......@@ -175,7 +175,7 @@ void EigenraySearch::CAdaptiveWorker::CalculateEigenraySpreadingLoss(const ITAGe
if (adaptiveRayGrid.MaxAngularResolution() > rayAdaptationSettings.accuracy.maxAngleForGeomSpreading || !adaptiveRayGrid.Is2D())
{
adaptiveRayGrid.ZoomIntoRay(pMinDistanceRay, rayAdaptationSettings.accuracy.maxAngleForGeomSpreading, rayAdaptationSettings.accuracy.maxAngleForGeomSpreading);
simulationEngine.iAbortCriterion = Simulation::CAbortAtMaxTime(time);
simulationEngine.externalWatcher = Simulation::CAbortAtMaxTime(time);
simulationEngine.Run(atmosphere, adaptiveRayGrid.NewRaysOfLastAdaptation());
}
else
......
......@@ -53,7 +53,7 @@ namespace ITAPropagationPathSim
float DistanceToVirtualReceiver( const VistaVector3D& point, const VistaVector3D& receiverPos, const int reflectionOrder );
//! Does a rough search for potential eigenrays directions for multiple reflection orders
class CInitialWorker : public Simulation::IAbortCriterion
class CInitialWorker : public Simulation::IExternalWatcher
{
private:
Simulation::CEngine simulationEngine;
......@@ -67,6 +67,7 @@ namespace ITAPropagationPathSim
public:
//! Interface function to receive data from Simulation::Engine and abort the ray tracer
virtual bool AbortRequested(const RayPtr& pRay);
virtual void FinalizeRay(const RayPtr& pRay) {}
public:
CInitialWorker(const VistaVector3D& sourcePosition, const VistaVector3D& receiverPosition, const Simulation::Settings& simSettings, const RayTracingAbortSettings& abortSettings);
......@@ -79,7 +80,7 @@ namespace ITAPropagationPathSim
};
//! Based on a result of CInitialWorker, this worker adaptively reduces the directional limits while increasing the resolution to find an eigenray of a specific reflection order
class CAdaptiveWorker : public Simulation::IAbortCriterion
class CAdaptiveWorker : public Simulation::IExternalWatcher
{
private:
Simulation::CEngine simulationEngine;
......@@ -101,6 +102,7 @@ namespace ITAPropagationPathSim
public:
//! Interface function to receive data from Simulation::Engine and abort the ray tracer
virtual bool AbortRequested(const RayPtr& pRay);
virtual void FinalizeRay(const RayPtr& pRay) {}
public:
CAdaptiveWorker(const CRayGrid& rayGrid, const VistaVector3D& receiverPosition, const Simulation::Settings& simSettings, const Settings& eigenraySettings, const int activeReflectionOrder);
......
......@@ -19,11 +19,11 @@ class CWorker
{
private:
std::shared_ptr<CRay> pRay;
IAbortCriterion& rAbortCriterion; //!< Reference to externally defined abort criterion.
CAdaptiveSolver mSolver;
IExternalWatcher& rExternalWatcher; //!< Reference to externally defined abort criterion.
CAdaptiveSolver solver;
public:
CWorker(std::shared_ptr<CRay> ray, const Settings& simSettings, IAbortCriterion& abortCriterion) :
pRay(ray), rAbortCriterion(abortCriterion), mSolver(CAdaptiveSolver(simSettings)) {}
CWorker(std::shared_ptr<CRay> ray, const Settings& simSettings, IExternalWatcher& externalWatcher) :
pRay(ray), rExternalWatcher(externalWatcher), solver(CAdaptiveSolver(simSettings)) {}
private:
bool GroundReflectionOccured(const double& rz1, const double& rz2) const
......@@ -59,7 +59,7 @@ class CWorker
const VistaVector3D n = pRay->at(idx).wavefrontNormal;
pRay->Append(r, n, t);
if (rAbortCriterion.AbortRequested(pRay))
if (rExternalWatcher.AbortRequested(pRay))
return;
}
......@@ -70,11 +70,10 @@ class CWorker
}
void ExtendRayPeriodically()
{
while (!rAbortCriterion.AbortRequested(pRay))
while (!rExternalWatcher.AbortRequested(pRay))
ExtendRayByOnePeriod();
}
public:
void TraceRay(const ITAGeo::CStratifiedAtmosphere& atmosphere)
void CalculateRay(const ITAGeo::CStratifiedAtmosphere& atmosphere)
{
VistaVector3D r = pRay->LastPoint();
double rz = r[Vista::Z];
......@@ -84,11 +83,11 @@ class CWorker
VistaVector3D s = ODESolver::NormalToSlowness(n, rz, atmosphere);
VistaVector3D rNew, sNew;
while ( !rAbortCriterion.AbortRequested(pRay) )
while ( !rExternalWatcher.AbortRequested(pRay) )
{
mSolver.Process(r, s, atmosphere, rNew, sNew);
solver.Process(r, s, atmosphere, rNew, sNew);
n = ODESolver::SlownessToNormal(s);
const double dt = mSolver.CurrentStepSize();
const double dt = solver.CurrentStepSize();
if (GroundReflectionOccured(r[Vista::Z], rNew[Vista::Z]))
{
......@@ -98,7 +97,7 @@ class CWorker
rGround[Vista::Z] = 0; //Making sure z-component is truely zero
pRay->AppendReflection(rGround, n, time + dtGround);
if ( rAbortCriterion.AbortRequested(pRay) )
if ( rExternalWatcher.AbortRequested(pRay) )
return;
if (pRay->ReflectionOrder() >= 2) //Ray is periodic
......@@ -114,6 +113,12 @@ class CWorker
pRay->Append(r, n, time);
}
}
public:
void TraceRay(const ITAGeo::CStratifiedAtmosphere& atmosphere)
{
CalculateRay(atmosphere);
rExternalWatcher.FinalizeRay(pRay);
}
};
}}}
......@@ -127,7 +132,7 @@ std::vector<std::shared_ptr<CRay>> CEngine::Run(const ITAGeo::CStratifiedAtmosph
for each (std::shared_ptr<CRay> pRay in rays)
{
auto worker = CWorker(pRay, settings, iAbortCriterion);
auto worker = CWorker(pRay, settings, externalWatcher);
worker.TraceRay(atmosphere);
}
return rays;
......@@ -139,7 +144,7 @@ void CEngine::Run(const ITAGeo::CStratifiedAtmosphere& atmosphere, const std::se
if (pRay == nullptr)
continue;
auto worker = CWorker(pRay, settings, iAbortCriterion);
auto worker = CWorker(pRay, settings, externalWatcher);
worker.TraceRay(atmosphere);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment