mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
turbSubHarmonic_test.cpp
Go to the documentation of this file.
1/** \file turbSubHarmonic_test.cpp
2 * \brief Tests low-frequency turbulence subharmonic generation.
3 */
4#include "../../../catch2/catch.hpp"
5
6#define MX_NO_ERROR_REPORTS
7
8#include <cmath>
9
13
14/** \defgroup turbSubHarmonic_unit_tests turbSubHarmonic Unit Tests
15 * \ingroup ao_sim_unit_tests
16 */
17
18namespace unitTest::ao_sim_turbSubHarmonic_test
19{
20
21/** \brief Verifies real quadrature subharmonics generate isotropic nonzero tilt variance.
22 *
23 * Exercises mx::AO::sim::turbSubHarmonic::initGrid and mx::AO::sim::turbSubHarmonic::screen through both
24 * pre-calculated and direct mode evaluation.
25 *
26 * \ingroup turbSubHarmonic_unit_tests
27 */
28TEST_CASE( "turbSubHarmonic generates cosine and sine quadratures", "[ao::sim::turbSubHarmonic]" )
29{
30 using realT = double;
33
34#ifdef MXLIB_BUILD_COVERAGE
35 constexpr uint32_t wfSz = 32;
36 constexpr uint32_t scrnSz = 64;
37 constexpr size_t trials = 8;
38 constexpr realT tiltRatioMargin = 0.5;
39#else
40 constexpr uint32_t wfSz = 64;
41 constexpr uint32_t scrnSz = 192;
42 constexpr size_t trials = 128;
43 constexpr realT tiltRatioMargin = 0.35;
44#endif
45
46 aoSystemT aosys;
47 aosys.D( 25.0 );
48 aosys.lam_sci( 0.5e-6 );
49 aosys.atm.setSingleLayer( 0.16, 0.5e-6, 0.0, 0.0, 0.0, 0.0, 0.0 );
50
51 atmosphereT atmosphere;
52 atmosphere.setup( wfSz, 0, &aosys, 1 );
53 atmosphere.setLayers( scrnSz );
54
56 preCalculated.turbAtmo( &atmosphere );
57 preCalculated.level( 1 );
58 preCalculated.outerSubHarmonics( true );
59 preCalculated.preCalc( true );
60 preCalculated.initGrid( 0 );
61
63 direct.turbAtmo( &atmosphere );
64 direct.level( 1 );
65 direct.outerSubHarmonics( true );
66 direct.preCalc( false );
67 direct.initGrid( 0 );
68
69 mx::improc::eigenImage<realT> preScreen( scrnSz, scrnSz );
70 mx::improc::eigenImage<realT> directScreen( scrnSz, scrnSz );
71
72 atmosphere.normVar().seed( 12345 );
73 preScreen.setZero();
74 preCalculated.screen( preScreen );
75 atmosphere.normVar().seed( 12345 );
76 directScreen.setZero();
77 direct.screen( directScreen );
78
79 REQUIRE( ( preScreen - directScreen ).abs().maxCoeff() < 1e-12 );
80
81 realT xTiltMeanSq{ 0 };
82 realT yTiltMeanSq{ 0 };
83 for( size_t trial = 0; trial < trials; ++trial )
84 {
85 preScreen.setZero();
86 preCalculated.screen( preScreen );
87
88 realT xTilt{ 0 };
89 realT yTilt{ 0 };
90 for( uint32_t jj = 0; jj < scrnSz; ++jj )
91 {
92 realT y = jj - 0.5 * ( scrnSz - 1 );
93 for( uint32_t ii = 0; ii < scrnSz; ++ii )
94 {
95 realT x = ii - 0.5 * ( scrnSz - 1 );
96 xTilt += x * preScreen( ii, jj );
97 yTilt += y * preScreen( ii, jj );
98 }
99 }
100
101 xTiltMeanSq += xTilt * xTilt;
102 yTiltMeanSq += yTilt * yTilt;
103 }
104
105 xTiltMeanSq /= trials;
106 yTiltMeanSq /= trials;
107
108 REQUIRE( xTiltMeanSq > 1e-6 );
109 REQUIRE( yTiltMeanSq > 1e-6 );
110 REQUIRE( xTiltMeanSq / yTiltMeanSq == Approx( 1.0 ).margin( tiltRatioMargin ) );
111}
112
113} // namespace unitTest::ao_sim_turbSubHarmonic_test
Declares and defines an analytical AO system.
void setSingleLayer(realT r0, realT lam0, realT L0, realT l0, realT lz, realT vw, realT dir)
Set a single layer model.
Describes an analytic adaptive optics (AO) system.
Definition aoSystem.hpp:64
void D(realT nD)
Set the value of the primary mirror diameter.
void lam_sci(realT nlam)
Set the science wavelength.
A class to manage low-frequency sub-harmonic phase screen generation in atmospheric turbulence.
void outerSubHarmonics(bool osh)
Set whether or not the outer subharmonics are included.
void turbAtmo(turbAtmosphereT *atm)
Set the pointer to the turbulent atmosphere.
void preCalc(bool pc)
Set whether or not to pre-calculate the modes.
void level(uint32_t ml)
Set the subharmonic level to apply.
void initGrid(uint32_t layerNo)
Allocate needed memory and initialize the subharmonic transform.
void screen(improc::eigenImage< realT > &scrn)
Generate a realization of the subharmonic phase screen and add it to the input screen.
Eigen::Array< scalarT, -1, -1 > eigenImage
Definition of the eigenImage type, which is an alias for Eigen::Array.
TEST_CASE("turbSubHarmonic generates cosine and sine quadratures", "[ao::sim::turbSubHarmonic]")
Verifies real quadrature subharmonics generate isotropic nonzero tilt variance.
AO-system test type that forces local template instantiation under sanitizers.
A turbulent atmosphere simulator.
Declaration and definition of a turbulent atmosphere.
A class to manage low-frequency sub-harmonic phase screen generation in atmospheric turbulence.