Aufgrund einer Wartung wird GitLab am 29.10. zwischen 9:00 und 10:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 29.10. between 9:00 and 10:00 am.

Commit 1bf96bc3 authored by Philipp Schäfer's avatar Philipp Schäfer

Atmosphere - AirAttenuation

- finished first version of model for air attenuation for atmospheric rays
parent 735220b9
......@@ -9,6 +9,7 @@ include( VistaCommon )
vista_use_package( ITABase REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITAFFT REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITAGeo REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITAPropagationPathSim REQUIRED FIND_DEPENDENCIES )
# includes
......
......@@ -25,19 +25,33 @@
// ITA includes
#include <ITAGeo/Atmosphere/StratifiedAtmosphere.h>
//#include <ITAPropagationPathSim/Rays.h> //TODO: Link ITAPropagationPathSim to this library
#include <ITAPropagationPathSim/AtmosphericRayTracing/Rays.h>
#include <ITAThirdOctaveMagnitudeSpectrum.h>
// STL includes
//#include <vector>
namespace ITAPropagationModels
{
namespace Atmosphere
{
ITA_PROPAGATION_MODELS_API ITABase::CThirdOctaveGainMagnitudeSpectrum Test();
//! Returns a third octave magnitude spectrum containing a filter describing the effects of attenuation due to sound propagation through the atmosphere
/**
* Evaluates and accumulates the air attenuation between adjacent ray points according to ISO 9613.
* The result contains factors representing the remaining portion of sound pressure after sound travelled along the ray path.
* Optionally, a downsampling factor can be given to the function in order to only evaluate for every x-th ray point.
*/
ITA_PROPAGATION_MODELS_API ITABase::CThirdOctaveFactorMagnitudeSpectrum AirAttenuationSpectrum(
const ITAPropagationPathSim::AtmosphericRayTracing::CRay& oRay, const ITAGeo::CStratifiedAtmosphere& oAtmosphere, const int iDownSamplingFactor = 1);
//! Writes a third octave magnitude spectrum containing a filter describing the effects of attenuation due to sound propagation through the atmosphere
/**
* Evaluates and accumulates the air attenuation between adjacent ray points according to ISO 9613.
* The result contains factors representing the remaining portion of sound pressure after sound travelled along the ray path.
* Optionally, a downsampling factor can be given to the function in order to only evaluate for every x-th ray point.
*/
ITA_PROPAGATION_MODELS_API void AirAttenuationSpectrum(ITABase::CThirdOctaveFactorMagnitudeSpectrum& outputSpectrum,
const ITAPropagationPathSim::AtmosphericRayTracing::CRay& oRay, const ITAGeo::CStratifiedAtmosphere& oAtmosphere, const int iDownSamplingFactor = 1);
}
}
......
#include <ITAPropagationModels/Atmosphere/AirAttenuation.h>
#include <ITAISO9613.h>
#include <ITAException.h>
#include <cassert>
#include <cmath>
#include <algorithm>
using namespace ITAPropagationModels;
ITABase::CThirdOctaveFactorMagnitudeSpectrum Atmosphere::AirAttenuationSpectrum(const ITAPropagationPathSim::AtmosphericRayTracing::CRay& oRay, const ITAGeo::CStratifiedAtmosphere& oAtmosphere, const int iDownSamplingFactor /*= 1*/)
{
ITABase::CThirdOctaveFactorMagnitudeSpectrum outputSpectrum;
AirAttenuationSpectrum(outputSpectrum, oRay, oAtmosphere, iDownSamplingFactor);
return outputSpectrum;
}
void Atmosphere::AirAttenuationSpectrum(ITABase::CThirdOctaveFactorMagnitudeSpectrum& outputSpectrum, const ITAPropagationPathSim::AtmosphericRayTracing::CRay& oRay, const ITAGeo::CStratifiedAtmosphere& oAtmosphere, const int iDownSamplingFactor /*= 1*/)
{
if (oRay.NumPoints() < 2)
ITA_EXCEPT_INVALID_PARAMETER("Ray must at least have two points.");
ITABase::CThirdOctaveDecibelMagnitudeSpectrum oTotalDecibelSpectrum;
oTotalDecibelSpectrum.SetIdentity();
for (int idxCurrent = 0; idxCurrent < oRay.NumPoints() - 1; idxCurrent += iDownSamplingFactor )
{
const int idxNext = std::min(idxCurrent + iDownSamplingFactor, oRay.NumPoints() - 1);
const float fAltitude = std::abs(oRay[idxCurrent].position[Vista::Z]);
const float fDistance = (oRay[idxNext].position - oRay[idxCurrent].position).GetLength();
ITABase::CThirdOctaveDecibelMagnitudeSpectrum oTmpSpectrum;
ITABase::ISO9613::AtmosphericAbsorption(oTmpSpectrum,
fDistance, oAtmosphere.Temperature(fAltitude), oAtmosphere.RelativeHumidity(fAltitude), oAtmosphere.StaticPressure(fAltitude));
oTotalDecibelSpectrum.Add(oTmpSpectrum);
}
using namespace ITAGeo;
using namespace ITAPropagationModels;
\ No newline at end of file
for (int idx = 0; idx < oTotalDecibelSpectrum.GetNumBands(); idx++)
outputSpectrum[idx] = pow(10, -oTotalDecibelSpectrum[idx] / 20.0);
}
/*
* ----------------------------------------------------------------
*
* ITA geometrical acoustics
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2019
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#include <ITAPropagationModels/Atmosphere/AirAttenuation.h>
#include <ITAGeo/Atmosphere/StratifiedAtmosphere.h>
#include <ITAPropagationPathSim/AtmosphericRayTracing/Rays.h>
//#include <ITAException.h>
#include <ITAStopWatch.h>
#include <iostream>
using namespace std;
using namespace ITAGeo;
using namespace ITAPropagationModels;
using namespace ITAPropagationPathSim;
void TestAttenuation()
{
auto oAtmosphere = CStratifiedAtmosphere();
const VistaVector3D v3SourcePos = VistaVector3D(0, 0, 2000);
auto oRay = AtmosphericRayTracing::CRay(v3SourcePos, 135, 0);
const VistaVector3D v3WfNormal = oRay.InitialDirection();
const int ciNPoints = 102;
for (int idx = 1; idx <= ciNPoints; idx++)
{
const double dDeltaR = idx * 2000.0 / ciNPoints;
const double dTime = idx * 6 / ciNPoints;
oRay.Append(v3SourcePos + v3WfNormal * dDeltaR, v3WfNormal, dTime);
}
ITABase::CThirdOctaveFactorMagnitudeSpectrum oAttenuationSpectrum;
Atmosphere::AirAttenuationSpectrum(oAttenuationSpectrum, oRay, oAtmosphere);
cout << "Spectrum using all ray points:" << endl << oAttenuationSpectrum << endl << endl;
Atmosphere::AirAttenuationSpectrum(oAttenuationSpectrum, oRay, oAtmosphere, 5);
cout << "Spectrum using every fifth ray point:" << endl << oAttenuationSpectrum << endl << endl;
}
void BenchmarkAttenuation()
{
auto oAtmosphere = CStratifiedAtmosphere();
const VistaVector3D v3SourcePos = VistaVector3D(0, 0, 2000);
auto oRay = AtmosphericRayTracing::CRay(v3SourcePos, 135, 0);
const VistaVector3D v3WfNormal = oRay.InitialDirection();
const int ciNPoints = 1003;
for (int idx = 1; idx <= ciNPoints; idx++)
{
const double dDeltaR = idx * 3000.0 / ciNPoints;
const double dTime = idx * 10 / ciNPoints;
oRay.Append(v3SourcePos + v3WfNormal * dDeltaR, v3WfNormal, dTime);
}
ITAStopWatch watch;
ITABase::CThirdOctaveFactorMagnitudeSpectrum oSpectrum;
for (int idx = 0; idx < 100; idx++)
{
watch.start();
Atmosphere::AirAttenuationSpectrum(oSpectrum, oRay, oAtmosphere);
watch.stop();
}
cout << "Benchmark for " << ciNPoints << " segments:"
<< endl << watch << endl << endl;
watch.reset();
const int iDownSamplingFactor = 5;
for (int idx = 0; idx < 100; idx++)
{
watch.start();
Atmosphere::AirAttenuationSpectrum(oSpectrum, oRay, oAtmosphere, iDownSamplingFactor);
watch.stop();
}
cout << "Benchmark for " << std::ceil((double)ciNPoints / (double)iDownSamplingFactor)
<< " segments (downsampling of factor " << iDownSamplingFactor << "):"
<< endl << watch << endl << endl;
watch.reset();
for (int idx = 0; idx < 100; idx++)
{
watch.start();
oSpectrum = Atmosphere::AirAttenuationSpectrum(oRay, oAtmosphere);
watch.stop();
}
cout << "Benchmark for " << ciNPoints << " segments returning a spectrum:"
<< endl << watch << endl << endl;
}
int main( int, char** )
{
TestAttenuation();
BenchmarkAttenuation();
return 0;
}
cmake_minimum_required( VERSION 2.8 )
project( ITAPropagationModelsTest )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
vista_use_package( ITABase REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITAPropagationModels REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITAFFT REQUIRED FIND_DEPENDENCIES )
if( ITA_CORE_LIBS_BUILD_STATIC )
add_definitions( -DITA_BASE_STATIC )
endif( )
if( ITA_GEOMETRICAL_ACOUSTICS_BUILD_STATIC )
add_definitions( -DITA_PROPAGATION_MODELS_STATIC _DITA_PROPAGATION_PATH_SIM_STATIC -DITA_GEO_STATIC )
endif( )
add_executable( AtmosphericAttenuationTest AtmosphericAttenuationTest.cpp )
target_link_libraries( AtmosphericAttenuationTest ${VISTA_USE_PACKAGE_LIBRARIES} )
vista_configure_app( AtmosphericAttenuationTest )
vista_install( AtmosphericAttenuationTest )
vista_create_default_info_file( AtmosphericAttenuationTest )
set_property( TARGET AtmosphericAttenuationTest PROPERTY FOLDER "ITAGeometricalAcoustics/Tests/ITAPropagationModels" )
......@@ -6,3 +6,4 @@ add_subdirectory( "UTD" )
add_subdirectory( "FilterEngine" )
add_subdirectory( "ReceiverDirectivityTest" )
add_subdirectory( "SourceDirectivityTest" )
add_subdirectory( "AtmosphericAttenuationTest" )
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