Skip to content

Commit

Permalink
Merge pull request #295 from project8/feature/MultiMode
Browse files Browse the repository at this point in the history
Feature/MultiMode
  • Loading branch information
pslocum authored Jun 26, 2024
2 parents f57e319 + 8eeafad commit 5a187e0
Show file tree
Hide file tree
Showing 29 changed files with 957 additions and 1,016 deletions.
51 changes: 46 additions & 5 deletions Source/Applications/Testing/testLMCCavity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
using namespace scarab;
using namespace locust;

LOGGER( testlog, "testLMCCavity" );
LOGGER( lmclog, "testLMCCavity" );

class testCavity_app : public main_app
{
Expand All @@ -68,14 +68,21 @@ class testCavity_app : public main_app
fDHOThresholdFactor(0.01),
fCavityFrequency(1.067e9),
fCavityQ(1000.),
fL(0),
fM(1),
fN(1),
fbTE(true),
fExpandSweep(1.0),
fUnitTestOutputFile(false),
fOutputPath( TOSTRING(PB_OUTPUT_DIR) )
{
add_option("-r,--dho-time-resolution", fDHOTimeResolution, "[1.e-8] Time resolution used in Green's function (s).");
add_option("-m,--dho-threshold-factor", fDHOThresholdFactor, "[0.01] Minimum fractional threshold of Green's function used to calculate FIR.");
add_option("-t,--dho-threshold-factor", fDHOThresholdFactor, "[0.01] Minimum fractional threshold of Green's function used to calculate FIR.");
add_option("-f,--dho-cavity-frequency", fCavityFrequency, "[1.067e9] Cavity resonant frequency (Hz).");
add_option("-g,--dho-cavity-Q", fCavityQ, "[1000] Cavity Q.");
add_option("-l,--l-index", fL, "[0] Azimuthal mode index.");
add_option("-m,--m-index", fM, "[1] Radial mode index.");
add_option("-n,--n-index", fN, "[1] Axial mode index.");
add_option("-x,--expand-sweep", fExpandSweep, "[1.0] Factor by which to expand range of frequency sweep.");
add_option("-w, --write-output", fUnitTestOutputFile, "[0==false] Write histo to Root file.");
add_option("-o, --output-path", fOutputPath, "[PB_OUTPUT_DIR]");
Expand All @@ -99,6 +106,22 @@ class testCavity_app : public main_app
{
return fCavityQ;
}
double GetL()
{
return fL;
}
double GetM()
{
return fM;
}
double GetN()
{
return fN;
}
bool GetbTE()
{
return fbTE;
}
double GetExpandSweep()
{
return fExpandSweep;
Expand All @@ -118,6 +141,10 @@ class testCavity_app : public main_app
double fDHOThresholdFactor;
double fCavityFrequency;
double fCavityQ;
int fL;
int fM;
int fN;
bool fbTE;
double fExpandSweep;
bool fUnitTestOutputFile;
std::string fOutputPath;
Expand All @@ -142,9 +169,23 @@ TEST_CASE( "testLMCCavity with default parameter values (pass)", "[single-file]"
aCavityUtility.SetOutputPath(the_main.GetOutputPath());
aCavityUtility.SetExpandFactor(the_main.GetExpandSweep());
aCavityUtility.SetOutputFile(the_main.UnitTestOutputFile());
bool checkCavityQ = aCavityUtility.CheckCavityQ( the_main.GetDHOTimeResolution(), the_main.GetDHOThresholdFactor(), the_main.GetCavityFrequency(), the_main.GetCavityQ() );

REQUIRE( checkCavityQ );
int l = the_main.GetL();
int m = the_main.GetM();
int n = the_main.GetN();
bool bTE = the_main.GetbTE();
bool checkCavityQ;

if ( (l<2) && (m<2) && (n<2) )
{

checkCavityQ = aCavityUtility.CheckCavityQ( bTE, l, m, n, the_main.GetDHOTimeResolution(), the_main.GetDHOThresholdFactor(), the_main.GetCavityFrequency(), the_main.GetCavityQ() );
REQUIRE( checkCavityQ );
}
else
{
LERROR(lmclog,"This unit test presently only supports mode indices lmn < 2.");
REQUIRE( false );
}

}

Expand Down
31 changes: 10 additions & 21 deletions Source/Applications/Testing/testLMCPlaneWaveFIR.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class testLMCPlaneWaveFIR
std::string filepath = tDataDir + "/PatchTFLocust.txt";
param_0->add( "tf-receiver-filename", filepath.c_str() );
param_0->add( "tf-receiver-bin-width", 0.01e9 );
param_0->add( "print-fir-debug", false );
return param_0;
}

Expand All @@ -71,7 +72,7 @@ class testLMCPlaneWaveFIR
LWARN(testlog,"TFReceiverHandler was not configured correctly.");
return false;
}
if ( !fTFReceiverHandler->ReadHFSSFile() )
if ( !fTFReceiverHandler->ReadHFSSFile(0,0,0,0) )
{
LWARN(testlog,"TF file was not read correctly.");
return false;
Expand All @@ -87,17 +88,16 @@ class testLMCPlaneWaveFIR



bool PopulateSignal(Signal* aSignal, int N0, double timeStamp)
bool PopulateSignal(Signal* aSignal, int N0)
{
double LO_phase = 0.;
double voltage_phase = 0.;
double phaseLagRF = 2.*LMCConst::Pi() * timeStamp/(1./fRF_frequency);
fPhaseLagLO += 2.*LMCConst::Pi() * fLO_frequency * 1./fAcquisitionRate;

for( unsigned index = 0; index < N0; ++index )
{
LO_phase = fPhaseLagLO;
voltage_phase = phaseLagRF + 2.*LMCConst::Pi()*fRF_frequency*(double)index/fFilterRate;
voltage_phase = 2.*LMCConst::Pi()*fRF_frequency*(double)index/fFilterRate;

// keep only lower sideband RF-LO
aSignal->LongSignalTimeComplex()[index][0] = fAmplitude*cos(voltage_phase-LO_phase);
Expand All @@ -111,7 +111,7 @@ class testLMCPlaneWaveFIR
std::deque<double> SignalToDeque(Signal* aSignal)
{
std::deque<double> incidentSignal;
for (unsigned i=0; i<fTFReceiverHandler->GetFilterSize(); i++)
for (unsigned i=0; i<fTFReceiverHandler->GetFilterSizeArray(0,0,0,0); i++)
{
incidentSignal.push_back(aSignal->LongSignalTimeComplex()[i][0]);
}
Expand Down Expand Up @@ -155,8 +155,8 @@ TEST_CASE( "LMCPlaneWaveFIR with default parameter values (pass)", "[single-file

/* initialize time series */
Signal* aSignal = new Signal();
int N0 = aTestLMCPlaneWaveFIR.fTFReceiverHandler->GetFilterSize();
aTestLMCPlaneWaveFIR.fFilterRate = (1./aTestLMCPlaneWaveFIR.fTFReceiverHandler->GetFilterResolution());
int N0 = aTestLMCPlaneWaveFIR.fTFReceiverHandler->GetFilterSizeArray(0,0,0,0);
aTestLMCPlaneWaveFIR.fFilterRate = (1./aTestLMCPlaneWaveFIR.fTFReceiverHandler->GetFilterResolutionArray(0,0,0,0));
aSignal->Initialize( N0 , 1 );

double firGainMax = 0.;
Expand All @@ -165,24 +165,13 @@ TEST_CASE( "LMCPlaneWaveFIR with default parameter values (pass)", "[single-file
for (unsigned rfStep=0; rfStep<25; rfStep++)
{
aTestLMCPlaneWaveFIR.fRF_frequency = iHarmonic*20.9e9 + 0.5e9*rfStep;

double convolutionMag = 0.;
for (unsigned i=0; i<1000; i++)
{
/* populate time series and convolve it with the FIR filter */
double timeStamp = i/aTestLMCPlaneWaveFIR.fAcquisitionRate;
aTestLMCPlaneWaveFIR.PopulateSignal(aSignal, N0, timeStamp);
double convolution = aTestLMCPlaneWaveFIR.fTFReceiverHandler->ConvolveWithFIRFilter(aTestLMCPlaneWaveFIR.SignalToDeque(aSignal));
if (fabs(convolution) > convolutionMag)
{
convolutionMag = convolution;
}
}
/* populate time series and convolve it with the FIR filter */
aTestLMCPlaneWaveFIR.PopulateSignal(aSignal, N0);
double convolutionMag = aTestLMCPlaneWaveFIR.fTFReceiverHandler->ConvolveWithComplexFIRFilterArray(0,0,0,0,aTestLMCPlaneWaveFIR.SignalToDeque(aSignal)).first;
// https://www.antenna-theory.com/definitions/antennafactor.php
double firGain = 10.*log10(pow(1./(aTestLMCPlaneWaveFIR.fAmplitude/convolutionMag/9.73*(3.e8/aTestLMCPlaneWaveFIR.fRF_frequency)),2.));
if (firGain > firGainMax) firGainMax = firGain;
LPROG( testlog, "FIR gain at frequency " << aTestLMCPlaneWaveFIR.fRF_frequency << " is " << firGain << " dB" );
//printf("firGain at frequency %g is %g dB\n", aTestLMCPlaneWaveFIR.fRF_frequency, firGain);
}
}

Expand Down
2 changes: 0 additions & 2 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ set( LOCUST_MC_HEADER_FILES
Transmitters/LMCFieldBuffer.hh
Transmitters/LMCTransmitterInterface.hh
Transmitters/LMCTransmitter.hh
Transmitters/LMCAntennaSignalTransmitter.hh
Transmitters/LMCPlaneWaveTransmitter.hh
Transmitters/LMCTransmitterHardware.hh
Transmitters/LMCDipoleAntenna.hh
Expand Down Expand Up @@ -115,7 +114,6 @@ set( LOCUST_MC_SOURCE_FILES


Transmitters/LMCTransmitter.cc
Transmitters/LMCAntennaSignalTransmitter.cc
Transmitters/LMCPlaneWaveTransmitter.cc
Transmitters/LMCFieldBuffer.cc
Transmitters/LMCTransmitterHardware.cc
Expand Down
38 changes: 36 additions & 2 deletions Source/Core/LMCFIRFileHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,30 @@ namespace locust

bool FIRTransmitterHandler::Configure(const scarab::param_node& aParam)
{
int fNModes = 2;
if( aParam.has( "n-modes" ) )
{
fNModes = aParam["n-modes"]().as_int();
}
if( aParam.has( "fir-transmitter-filename" ) )
{
fHFSSFilename=aParam["fir-transmitter-filename"]().as_string();
}
if( aParam.has( "fir-transmitter-dt" ) )
{
fResolution=aParam["fir-transmitter-dt"]().as_double();
for(int bTE = 0; bTE<2; bTE++)
{
for(int l = 0; l<fNModes; l++)
{
for(int m = 0; m<fNModes; m++)
{
for(int n = 0; n<fNModes; n++)
{
fResolutionArray[bTE][l][m][n]=aParam["fir-transmitter-dt"]().as_double(); //Should eventually be implemented to read in specific values for different modes
}
}
}
}
}
if( aParam.has( "fir-transmitter-nskips" ) )
{
Expand All @@ -52,13 +69,30 @@ namespace locust

bool FIRReceiverHandler::Configure(const scarab::param_node& aParam)
{
int fNModes = 2;
if( aParam.has( "n-modes" ) )
{
fNModes = aParam["n-modes"]().as_int();
}
if( aParam.has( "fir-receiver-filename" ) )
{
fHFSSFilename=aParam["fir-receiver-filename"]().as_string();
}
if( aParam.has( "fir-receiver-dt" ) )
{
fResolution=aParam["fir-receiver-dt"]().as_double();
for(int bTE = 0; bTE<2; bTE++)
{
for(int l = 0; l<fNModes; l++)
{
for(int m = 0; m<fNModes; m++)
{
for(int n = 0; n<fNModes; n++)
{
fResolutionArray[bTE][l][m][n]=aParam["fir-receiver-dt"]().as_double(); //Should eventually be implemented to read in specific values for different modes
}
}
}
}
}
if( aParam.has( "fir-receiver-nskips" ) )
{
Expand Down
Loading

0 comments on commit 5a187e0

Please sign in to comment.