From 664aa63a4860d22a690d82e8a4a7811d7d6c8569 Mon Sep 17 00:00:00 2001 From: Penny Slocum Date: Sat, 15 Jul 2023 22:21:37 -0400 Subject: [PATCH 1/9] Define mode fields == 0. for points outside Pozar cylindrical cavity or rectangular waveguide. --- Source/Fields/LMCPozarCylindricalCavity.cc | 32 +++++++++++++++++++ Source/Fields/LMCPozarRectangularWaveguide.cc | 32 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/Source/Fields/LMCPozarCylindricalCavity.cc b/Source/Fields/LMCPozarCylindricalCavity.cc index 924105ac..4270da1f 100644 --- a/Source/Fields/LMCPozarCylindricalCavity.cc +++ b/Source/Fields/LMCPozarCylindricalCavity.cc @@ -25,6 +25,13 @@ namespace locust double z = zKass + L/2.; + if ((r > R) || (fabs(z) > L/2.)) // outside the cavity + { + return {0.,0.}; + } + else + { + // from Pozar std::vector TE_E; double x_lm = GetBesselNKPrimeZeros(l,m); @@ -51,6 +58,7 @@ namespace locust TE_E.push_back(tEtheta); return TE_E; + } } std::vector PozarCylindricalCavity::TE_H(double R, double L, int l, int m, int n, double r, double theta, double zKass, bool includeOtherPols) @@ -58,6 +66,13 @@ namespace locust double z = zKass + L/2.; + if ((r > R) || (fabs(z) > L/2.)) // outside the cavity + { + return {0.,0.,0.}; + } + else + { + // from Pozar std::vector TE_H; double x_lm = GetBesselNKPrimeZeros(l,m); @@ -83,12 +98,20 @@ namespace locust TE_H.push_back(tHz); // z TE_H.push_back(tHtheta); // theta return TE_H; // r, z, theta + } } std::vector PozarCylindricalCavity::TM_E(double R, double L, int l, int m, int n, double r, double theta, double zKass, bool includeOtherPols) { double z = zKass + L/2.; + if ((r > R) || (fabs(z) > L/2.)) // outside the cavity + { + return {0.,0.,0.}; + } + else + { + // from Pozar std::vector TM_E; double x_lm = GetBesselNKZeros(l,m); @@ -115,12 +138,20 @@ namespace locust TM_E.push_back(tEz); // z TM_E.push_back(tEtheta); // theta return TM_E; // r, z, theta + } } std::vector PozarCylindricalCavity::TM_H(double R, double L, int l, int m, int n, double r, double theta, double zKass, bool includeOtherPols) { double z = zKass + L/2.; + if ((r > R) || (fabs(z) > L/2.)) // outside the cavity + { + return {0.,0.}; + } + else + { + // from Pozar std::vector TM_H; double x_lm = GetBesselNKZeros(l,m); @@ -144,6 +175,7 @@ namespace locust TM_H.push_back(tHr); // r TM_H.push_back(tHtheta); // theta return TM_H; + } } } /* namespace locust */ diff --git a/Source/Fields/LMCPozarRectangularWaveguide.cc b/Source/Fields/LMCPozarRectangularWaveguide.cc index ebdca47e..8e591404 100644 --- a/Source/Fields/LMCPozarRectangularWaveguide.cc +++ b/Source/Fields/LMCPozarRectangularWaveguide.cc @@ -23,6 +23,13 @@ namespace locust double x = xKass + dimX/2.; double y = yKass + dimY/2.; + if ((fabs(x) > dimX/2.) || (fabs(y) > dimY/2.)) + { + return {0.,0.}; + } + else + { + // from Pozar std::vector TE_E; double k1 = m * LMCConst::Pi() / dimX; @@ -35,6 +42,7 @@ namespace locust TE_E.push_back(tEx); TE_E.push_back(tEy); return TE_E; + } } @@ -43,6 +51,13 @@ namespace locust double x = xKass + dimX/2.; double y = yKass + dimY/2.; + if ((fabs(x) > dimX/2.) || (fabs(y) > dimY/2.)) + { + return {0.,0.}; + } + else + { + // from Pozar std::vector TE_H; double k1 = m * LMCConst::Pi() / dimX; @@ -57,6 +72,7 @@ namespace locust TE_H.push_back(tHx); TE_H.push_back(tHy); return TE_H; + } } @@ -65,6 +81,13 @@ namespace locust double x = xKass + dimX/2.; double y = yKass + dimY/2.; + if ((fabs(x) > dimX/2.) || (fabs(y) > dimY/2.)) + { + return {0.,0.}; + } + else + { + // from Pozar std::vector TM_E; double k1 = m * LMCConst::Pi() / dimX; @@ -78,6 +101,7 @@ namespace locust TM_E.push_back(tEx); TM_E.push_back(tEy); return TM_E; + } } std::vector PozarRectangularWaveguide::TM_H(double dimX, double dimY, int m, int n, double xKass, double yKass, double fcyc) @@ -85,6 +109,13 @@ namespace locust double x = xKass + dimX/2.; double y = yKass + dimY/2.; + if ((fabs(x) > dimX/2.) || (fabs(y) > dimY/2.)) + { + return {0.,0.}; + } + else + { + // from Pozar std::vector TM_H; double k1 = m * LMCConst::Pi() / dimX; @@ -96,6 +127,7 @@ namespace locust TM_H.push_back(tHx); TM_H.push_back(tHy); return TM_H; + } } From b8c370099c07694307c18a3b95bee49ee37fd367 Mon Sep 17 00:00:00 2001 From: Penny Slocum Date: Sat, 15 Jul 2023 22:22:51 -0400 Subject: [PATCH 2/9] Build docker on push to feature branch. --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 60e61d63..59ba978c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -3,7 +3,7 @@ name: Build and Test Locust on: pull_request: push: - branches: [master, develop] + branches: [master, develop, feature/zeroModeFields] tags: ['*'] workflow_dispatch: From 92d49cc3284b9046997e11361644fed08ca91be7 Mon Sep 17 00:00:00 2001 From: Penny Slocum Date: Sun, 16 Jul 2023 21:58:37 -0400 Subject: [PATCH 3/9] Bug fix to convert from Pozar coordinates to Kass coordinates. --- Source/Fields/LMCPozarCylindricalCavity.cc | 8 ++++---- Source/Fields/LMCPozarRectangularWaveguide.cc | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/Fields/LMCPozarCylindricalCavity.cc b/Source/Fields/LMCPozarCylindricalCavity.cc index 4270da1f..76bfeb0e 100644 --- a/Source/Fields/LMCPozarCylindricalCavity.cc +++ b/Source/Fields/LMCPozarCylindricalCavity.cc @@ -25,7 +25,7 @@ namespace locust double z = zKass + L/2.; - if ((r > R) || (fabs(z) > L/2.)) // outside the cavity + if ((r > R) || (fabs(zKass) > L/2.)) // outside the cavity { return {0.,0.}; } @@ -66,7 +66,7 @@ namespace locust double z = zKass + L/2.; - if ((r > R) || (fabs(z) > L/2.)) // outside the cavity + if ((r > R) || (fabs(zKass) > L/2.)) // outside the cavity { return {0.,0.,0.}; } @@ -105,7 +105,7 @@ namespace locust { double z = zKass + L/2.; - if ((r > R) || (fabs(z) > L/2.)) // outside the cavity + if ((r > R) || (fabs(zKass) > L/2.)) // outside the cavity { return {0.,0.,0.}; } @@ -145,7 +145,7 @@ namespace locust { double z = zKass + L/2.; - if ((r > R) || (fabs(z) > L/2.)) // outside the cavity + if ((r > R) || (fabs(zKass) > L/2.)) // outside the cavity { return {0.,0.}; } diff --git a/Source/Fields/LMCPozarRectangularWaveguide.cc b/Source/Fields/LMCPozarRectangularWaveguide.cc index 8e591404..1b8d29c6 100644 --- a/Source/Fields/LMCPozarRectangularWaveguide.cc +++ b/Source/Fields/LMCPozarRectangularWaveguide.cc @@ -23,7 +23,7 @@ namespace locust double x = xKass + dimX/2.; double y = yKass + dimY/2.; - if ((fabs(x) > dimX/2.) || (fabs(y) > dimY/2.)) + if ((fabs(xKass) > dimX/2.) || (fabs(yKass) > dimY/2.)) { return {0.,0.}; } @@ -51,7 +51,7 @@ namespace locust double x = xKass + dimX/2.; double y = yKass + dimY/2.; - if ((fabs(x) > dimX/2.) || (fabs(y) > dimY/2.)) + if ((fabs(xKass) > dimX/2.) || (fabs(yKass) > dimY/2.)) { return {0.,0.}; } @@ -81,7 +81,7 @@ namespace locust double x = xKass + dimX/2.; double y = yKass + dimY/2.; - if ((fabs(x) > dimX/2.) || (fabs(y) > dimY/2.)) + if ((fabs(xKass) > dimX/2.) || (fabs(yKass) > dimY/2.)) { return {0.,0.}; } @@ -109,7 +109,7 @@ namespace locust double x = xKass + dimX/2.; double y = yKass + dimY/2.; - if ((fabs(x) > dimX/2.) || (fabs(y) > dimY/2.)) + if ((fabs(xKass) > dimX/2.) || (fabs(yKass) > dimY/2.)) { return {0.,0.}; } From 9c795d63fca75f3d2d470084c8331ee758d78bfc Mon Sep 17 00:00:00 2001 From: Penny Slocum Date: Tue, 25 Jul 2023 15:49:54 -0400 Subject: [PATCH 4/9] Only populate the frequency history at times when the electron is inside the cavity. --- Source/Kassiopeia/LMCFieldCalculator.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Source/Kassiopeia/LMCFieldCalculator.cc b/Source/Kassiopeia/LMCFieldCalculator.cc index 83b96967..ed3d1b49 100644 --- a/Source/Kassiopeia/LMCFieldCalculator.cc +++ b/Source/Kassiopeia/LMCFieldCalculator.cc @@ -394,12 +394,18 @@ namespace locust double tVx = tKassParticleXP[3]; double tVy = tKassParticleXP[4]; double vMag = pow(tVx*tVx + tVy*tVy,0.5); + double zLocation = tKassParticleXP[2]; + double dimZ = fInterface->fField->GetDimL(); + double orbitPhase = tKassParticleXP[6]; // radians + + double cycFrequency = 0.; + if (fabs(zLocation) < dimZ/2.) // Check whether the electron is inside the cavity length. + { + cycFrequency = tKassParticleXP[7]; // rad/s + } if ( !BypassTF ) { - double orbitPhase = tKassParticleXP[6]; // radians - double cycFrequency = tKassParticleXP[7]; // rad/s - // populate FIR filter with frequency for just this sample interval: for (int i=0; i < fNFilterBinsRequired; i++) { From 938eea2dbeb6044053fbb66d8806860ddb8c59fe Mon Sep 17 00:00:00 2001 From: Penny Slocum Date: Tue, 25 Jul 2023 17:24:34 -0400 Subject: [PATCH 5/9] Instead of zeroing fcyc outside the cavity, zero the impulse amplitude. So the phase advancement is preserved, but without driving the cavity ring-up. --- Source/Kassiopeia/LMCFieldCalculator.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Kassiopeia/LMCFieldCalculator.cc b/Source/Kassiopeia/LMCFieldCalculator.cc index ed3d1b49..a6ae21b2 100644 --- a/Source/Kassiopeia/LMCFieldCalculator.cc +++ b/Source/Kassiopeia/LMCFieldCalculator.cc @@ -397,11 +397,11 @@ namespace locust double zLocation = tKassParticleXP[2]; double dimZ = fInterface->fField->GetDimL(); double orbitPhase = tKassParticleXP[6]; // radians - - double cycFrequency = 0.; + double cycFrequency = tKassParticleXP[7]; + double amplitude = 0.; if (fabs(zLocation) < dimZ/2.) // Check whether the electron is inside the cavity length. { - cycFrequency = tKassParticleXP[7]; // rad/s + amplitude = 1.; } if ( !BypassTF ) @@ -421,7 +421,7 @@ namespace locust if (*it != 0.) { - fFIRBuffer.push_back(cos(orbitPhase)); + fFIRBuffer.push_back(amplitude * cos(orbitPhase)); } else { From 2d48d5e3b950f9bf02f33b3e5013a770d81ab1db Mon Sep 17 00:00:00 2001 From: Penny Slocum Date: Wed, 26 Jul 2023 14:38:54 -0400 Subject: [PATCH 6/9] Fix some indenting. --- Source/Kassiopeia/LMCFieldCalculator.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Source/Kassiopeia/LMCFieldCalculator.cc b/Source/Kassiopeia/LMCFieldCalculator.cc index a6ae21b2..c4e202c6 100644 --- a/Source/Kassiopeia/LMCFieldCalculator.cc +++ b/Source/Kassiopeia/LMCFieldCalculator.cc @@ -396,13 +396,14 @@ namespace locust double vMag = pow(tVx*tVx + tVy*tVy,0.5); double zLocation = tKassParticleXP[2]; double dimZ = fInterface->fField->GetDimL(); - double orbitPhase = tKassParticleXP[6]; // radians - double cycFrequency = tKassParticleXP[7]; - double amplitude = 0.; - if (fabs(zLocation) < dimZ/2.) // Check whether the electron is inside the cavity length. - { - amplitude = 1.; - } + double orbitPhase = tKassParticleXP[6]; // radians + double cycFrequency = tKassParticleXP[7]; + double amplitude = 0.; + if (fabs(zLocation) < dimZ/2.) + { + amplitude = 1.; + } + if ( !BypassTF ) { From a3ad04044f19107b5f4282c4ab50dee7241a044c Mon Sep 17 00:00:00 2001 From: Penny Slocum Date: Wed, 26 Jul 2023 14:39:43 -0400 Subject: [PATCH 7/9] Remove automatic build on feature branch. --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 59ba978c..60e61d63 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -3,7 +3,7 @@ name: Build and Test Locust on: pull_request: push: - branches: [master, develop, feature/zeroModeFields] + branches: [master, develop] tags: ['*'] workflow_dispatch: From 017df92cada8009c353b7ff6a72ebea11795023b Mon Sep 17 00:00:00 2001 From: Penny Slocum Date: Fri, 28 Jul 2023 20:13:28 -0400 Subject: [PATCH 8/9] Replace GF on SetGFarray for GF.size() > 0. --- .../RxComponents/LMCAnalyticResponseFunction.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Source/RxComponents/LMCAnalyticResponseFunction.cc b/Source/RxComponents/LMCAnalyticResponseFunction.cc index de6a1359..52b53f62 100644 --- a/Source/RxComponents/LMCAnalyticResponseFunction.cc +++ b/Source/RxComponents/LMCAnalyticResponseFunction.cc @@ -52,13 +52,26 @@ namespace locust { return fTFarray; } + void AnalyticResponseFunction::SetGFarray( std::vector > > aGFarray ) { - for (unsigned index=0; index 0) + { + for (unsigned index=0; index > > AnalyticResponseFunction::GetGFarray() { return fGFarray; From 46ee93fb1492c1ef5e2afa825be46fe2413f1963 Mon Sep 17 00:00:00 2001 From: Penny Slocum Date: Fri, 28 Jul 2023 20:25:54 -0400 Subject: [PATCH 9/9] Write GF to Root histo if "print-fir-debug"=true. --- Source/Core/LMCHFSSResponseFileHandler.cc | 64 +++++++++++++++++++---- Source/Core/LMCHFSSResponseFileHandler.hh | 9 ++++ 2 files changed, 64 insertions(+), 9 deletions(-) diff --git a/Source/Core/LMCHFSSResponseFileHandler.cc b/Source/Core/LMCHFSSResponseFileHandler.cc index f04f7344..8d58f28e 100644 --- a/Source/Core/LMCHFSSResponseFileHandler.cc +++ b/Source/Core/LMCHFSSResponseFileHandler.cc @@ -292,27 +292,73 @@ namespace locust fIsFIRCreated=true; return true; } + + bool HFSSResponseFileHandlerCore::WriteRootHisto( std::vector aFilter, bool bIQ ) + { +#ifdef ROOT_FOUND + char fbuffer[60]; + if (!bIQ) + { + int a = sprintf(fbuffer, "FIR_I"); + } + else + { + int a = sprintf(fbuffer, "FIR_Q"); + } + fRootHistoWriter->OpenFile("UPDATE"); + const char *hName = fbuffer; + TH1D* aHisto = new TH1D(hName, "FIR coefficients; index; coefficient", fFIRNBins, 0., (double)fFIRNBins); + aHisto->SetDirectory(0); + + for (unsigned i=0; iSetBinContent(i+1, aFilter[i]); + } + + fRootHistoWriter->Write1DHisto(aHisto); + fRootHistoWriter->CloseFile(); + delete aHisto; +#endif + return true; + } + void HFSSResponseFileHandlerCore::PrintFIR( std::vector aFilter ) { - LDEBUG( lmclog, "Printing FIR coefficients to file ... "); - FILE * fFIRout = fopen("output/FIR.txt", "w"); - for (int i = 0; i < fFIRNBins; i++) + LDEBUG( lmclog, "Printing FIR coefficients to file ... "); + FILE * fFIRout = fopen("output/FIR.txt", "w"); + for (int i = 0; i < fFIRNBins; i++) { fprintf(fFIRout,"%g\n", aFilter[i]); } fclose(fFIRout); +#ifdef ROOT_FOUND + WriteRootHisto( aFilter, 0 ); +#endif + } void HFSSResponseFileHandlerCore::PrintFIR( fftw_complex* aFilter ) { - LDEBUG( lmclog, "Printing FIR coefficients to file ... "); - FILE * fFIRout = fopen("output/FIR.txt", "w"); - for (int i = 0; i < fFIRNBins; i++) - { + std::vector vecFilter0; + std::vector vecFilter1; + LDEBUG( lmclog, "Printing FIR coefficients to file ... "); + FILE * fFIRout = fopen("output/FIR.txt", "w"); + for (int i = 0; i < fFIRNBins; i++) + { fprintf(fFIRout,"%g %g\n", aFilter[i][0], aFilter[i][1]); - } - fclose(fFIRout); + vecFilter0.push_back(aFilter[i][0]); + vecFilter1.push_back(aFilter[i][1]); + } + fclose(fFIRout); +#ifdef ROOT_FOUND + fRootHistoWriter = RootHistoWriter::get_instance(); + fRootHistoWriter->SetFilename("output/FIRhisto.root"); + fRootHistoWriter->OpenFile("RECREATE"); + fRootHistoWriter->CloseFile(); + WriteRootHisto( vecFilter0, 0 ); + WriteRootHisto( vecFilter1, 1 ); +#endif } FIRFileHandlerCore::FIRFileHandlerCore():HFSSResponseFileHandlerCore() diff --git a/Source/Core/LMCHFSSResponseFileHandler.hh b/Source/Core/LMCHFSSResponseFileHandler.hh index 8aa8a649..5307495c 100644 --- a/Source/Core/LMCHFSSResponseFileHandler.hh +++ b/Source/Core/LMCHFSSResponseFileHandler.hh @@ -6,6 +6,10 @@ #include "param.hh" #include "LMCComplexFFT.hh" +#ifdef ROOT_FOUND + #include "LMCRootHistoWriter.hh" +#endif + namespace locust { /*! @@ -33,6 +37,7 @@ namespace locust double GetFilterResolution() const;//Get the resolution of the filter void PrintFIR( std::vector ); void PrintFIR( fftw_complex* aFilter ); + bool WriteRootHisto( std::vector aFilter, bool bIQ ); protected: @@ -51,6 +56,10 @@ namespace locust std::string fWindowName; double fWindowParam; bool fPrintFIR; +#ifdef ROOT_FOUND + FileWriter* fRootHistoWriter; +#endif + //Member functions