Skip to content

Commit

Permalink
Merge pull request #284 from project8/feature/OptionMultiMode
Browse files Browse the repository at this point in the history
Feature/option multi mode
  • Loading branch information
pslocum authored Jul 14, 2023
2 parents e2696e4 + d34c1cb commit 72a4e92
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Source/Generators/LMCCavitySignalGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ namespace locust
// This scaling factor includes a 50 ohm impedance that is applied in signal processing, as well
// as other factors as defined above, e.g. 1/4PiEps0 if converting to/from c.g.s amplitudes.
double totalScalingFactor = sqrt(50.) * unitConversion;
fPowerCombiner->AddOneModeToCavityProbe(aSignal, tKassParticleXP, excitationAmplitude, tEFieldAtProbe[channelIndex], dopplerFrequency, fDeltaT, fphiLO, totalScalingFactor, sampleIndex, channelIndex, !(fInterface->fTOld > 0.) );
fPowerCombiner->AddOneModeToCavityProbe(l, m, n, aSignal, tKassParticleXP, excitationAmplitude, tEFieldAtProbe[channelIndex], dopplerFrequency, fDeltaT, fphiLO, totalScalingFactor, sampleIndex, channelIndex, !(fInterface->fTOld > 0.) );
if (fNormCheck) fPowerCombiner->AddOneSampleToRollingAvg(l, m, n, excitationAmplitude, sampleIndex);
}

Expand Down
5 changes: 3 additions & 2 deletions Source/Kassiopeia/LMCFieldCalculator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,17 @@ namespace locust
return false;
}
}
else
else // Cavity
{
if (!bNormCheck)
{
// Allow only TE011, or TE011+TM111 if fbMultimode==true
if ((((l==0)&&(m==1)&&(n==1))&&(bTE)) || (((l==1)&&(m==1)&&(n==1))&&(!bTE)&&(fbMultiMode)))
return true;
else
return false;
}
else
else // if bNormCheck==true, allow all modes.
{
if ((l<=nModes)&&(m<=nModes)&&(n<=nModes))
return true;
Expand Down
32 changes: 24 additions & 8 deletions Source/RxComponents/LMCCavityModes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace locust

CavityModes::CavityModes():
fOrbitPhase( 0. ),
fVoltagePhase( {0.} )
fVoltagePhase( 0 )
{
}

Expand Down Expand Up @@ -61,15 +61,31 @@ namespace locust
}
}

int nchannels = 2; //TO-DO: Configure this as LMCGenerator::fNChannels.
fVoltagePhase.resize(nchannels); // max nchannels. TO-DO: Configure this as LMCGenerator::fNChannels.
for (int n = 0; n < GetNCavityModes(); n++)
{
fVoltagePhase[n].resize(GetNCavityModes());
for (int i = 0; i < GetNCavityModes(); i++)
{
fVoltagePhase[n][i].resize(GetNCavityModes());
for (int j = 0; j < GetNCavityModes(); j++)
{
fVoltagePhase[n][i][j].resize(GetNCavityModes());
}
}
}


return true;
}

bool CavityModes::AddOneModeToCavityProbe(Signal* aSignal, std::vector<double> particleXP, double excitationAmplitude, double EFieldAtProbe, std::vector<double> cavityDopplerFrequency, double dt, double phi_LO, double totalScalingFactor, unsigned sampleIndex, int channelIndex, bool initParticle)
bool CavityModes::AddOneModeToCavityProbe(int l, int m, int n, Signal* aSignal, std::vector<double> particleXP, double excitationAmplitude, double EFieldAtProbe, std::vector<double> cavityDopplerFrequency, double dt, double phi_LO, double totalScalingFactor, unsigned sampleIndex, int channelIndex, bool initParticle)
{
double dopplerFrequency = cavityDopplerFrequency[0]; // Only one shift, unlike in waveguide.
SetVoltagePhase( GetVoltagePhase(channelIndex) + dopplerFrequency * dt, channelIndex ) ;
SetVoltagePhase( GetVoltagePhase(channelIndex, l, m, n) + dopplerFrequency * dt, channelIndex, l, m, n ) ;
double voltageValue = excitationAmplitude * EFieldAtProbe;
voltageValue *= cos(GetVoltagePhase(channelIndex));
voltageValue *= cos(GetVoltagePhase(channelIndex, l, m, n));

aSignal->LongSignalTimeComplex()[sampleIndex][0] += 2. * voltageValue * totalScalingFactor * sin(phi_LO);
aSignal->LongSignalTimeComplex()[sampleIndex][1] += 2. * voltageValue * totalScalingFactor * cos(phi_LO);
Expand Down Expand Up @@ -164,14 +180,14 @@ namespace locust
return true;
}

double CavityModes::GetVoltagePhase(unsigned aChannel)
double CavityModes::GetVoltagePhase(int aChannel, int l, int m, int n)
{
return fVoltagePhase[aChannel];
return fVoltagePhase[aChannel][l][m][n];
}

void CavityModes::SetVoltagePhase ( double aPhase, unsigned aChannel )
void CavityModes::SetVoltagePhase ( double aPhase, int aChannel, int l, int m, int n )
{
fVoltagePhase[aChannel] = aPhase;
fVoltagePhase[aChannel][l][m][n] = aPhase;
}


Expand Down
8 changes: 4 additions & 4 deletions Source/RxComponents/LMCCavityModes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ namespace locust
CavityModes();
virtual ~CavityModes();
virtual bool Configure( const scarab::param_node& aNode );
virtual bool AddOneModeToCavityProbe(Signal* aSignal, std::vector<double> particleXP, double excitationAmplitude, double EFieldAtProbe, std::vector<double> dopplerFrequency, double dt, double phi_LO, double totalScalingFactor, unsigned sampleIndex, int channelIndex, bool initParticle);
virtual bool AddOneModeToCavityProbe(int l, int m, int n, Signal* aSignal, std::vector<double> particleXP, double excitationAmplitude, double EFieldAtProbe, std::vector<double> dopplerFrequency, double dt, double phi_LO, double totalScalingFactor, unsigned sampleIndex, int channelIndex, bool initParticle);
virtual bool AddOneSampleToRollingAvg(int l, int m, int n, double excitationAmplitude, unsigned sampleIndex);
double GetVoltagePhase(unsigned aChannel);
void SetVoltagePhase( double aPhase, unsigned aChannel );
double GetVoltagePhase(int aChannel, int l, int m, int n);
void SetVoltagePhase( double aPhase, int aChannel, int l, int m, int n);
bool WriteRootHisto();



private:
double fOrbitPhase;
std::vector<double> fVoltagePhase;
std::vector<std::vector<std::vector<std::vector<double>>>> fVoltagePhase;
std::vector<std::vector<std::vector<double>>> fRollingAvg;
std::vector<std::vector<std::vector<int>>> fCounter;
FILE *fp;
Expand Down
2 changes: 1 addition & 1 deletion Source/RxComponents/LMCPowerCombiner.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace locust
virtual bool IsSinglePatch();
virtual Receiver* ChooseElement();
bool AddOneVoltageToStripSum(Signal* aSignal, double excitationAmplitude, double phi_LO, unsigned z_index, unsigned sampleIndex);
virtual bool AddOneModeToCavityProbe(Signal* aSignal, std::vector<double> particleXP, double excitationAmplitude, double EFieldAtProbe, std::vector<double> dopplerFrequency, double dt, double phi_LO, double totalScalingFactor, unsigned sampleIndex, int channelIndex, bool initParticle) {return true;};
virtual bool AddOneModeToCavityProbe(int l, int m, int n, Signal* aSignal, std::vector<double> particleXP, double excitationAmplitude, double EFieldAtProbe, std::vector<double> dopplerFrequency, double dt, double phi_LO, double totalScalingFactor, unsigned sampleIndex, int channelIndex, bool initParticle) {return true;};
virtual bool AddOneSampleToRollingAvg(int l, int m, int n, double excitationAmplitude, unsigned sampleIndex) {return true;};
virtual void SayHello();
virtual void Initialize() {};
Expand Down

0 comments on commit 72a4e92

Please sign in to comment.