Skip to content

Commit

Permalink
Merge pull request #323 from project8/feature/etalonCavity
Browse files Browse the repository at this point in the history
Feature/etalon cavity
  • Loading branch information
pslocum authored Dec 10, 2024
2 parents 3d6cf52 + 773e899 commit 70d5886
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 32 deletions.
44 changes: 39 additions & 5 deletions Source/Fields/LMCCylindricalCavity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ namespace locust
fProbeGain( {1., 1., 1.}),
fCavityProbeZ( {0., 0., 0.} ),
fCavityProbeRFrac( {0.5, 0.5, 0.5} ),
fCavityProbeTheta( {0.0, 0.0, 0.0} )
fCavityProbeTheta( {0.0, 0.0, 0.0} ),
fCaterpillarCavity( false ),
fApplyDopplerShift( true )
{}

CylindricalCavity::~CylindricalCavity() {}
Expand All @@ -33,6 +35,16 @@ namespace locust
return false;
}

if( aParam.has( "caterpillar-cavity" ) )
{
fCaterpillarCavity = aParam["caterpillar-cavity"]().as_bool();
}

if( aParam.has( "apply-doppler-shift" ) )
{
fApplyDopplerShift = aParam["apply-doppler-shift"]().as_bool();
}

if( aParam.has( "cavity-radius" ) )
{
SetDimR( aParam["cavity-radius"]().as_double() );
Expand Down Expand Up @@ -139,6 +151,9 @@ namespace locust
SetNormFactors(SetUnityNormFactors(GetNModes(), 0)); // Temporary quick normalization factors of 1.0
}

fFieldCore->ReadBesselZeroes((dataDir / "BesselZeros.txt").string(), 0 );
fFieldCore->ReadBesselZeroes((dataDir / "BesselPrimeZeros.txt").string(), 1 );

if( PlotModeMaps() )
{
double zSlice = 0.0;
Expand All @@ -149,8 +164,6 @@ namespace locust
PrintModeMaps(GetNModes(), zSlice, thetaSlice);
}

fFieldCore->ReadBesselZeroes((dataDir / "BesselZeros.txt").string(), 0 );
fFieldCore->ReadBesselZeroes((dataDir / "BesselPrimeZeros.txt").string(), 1 );
SetNormFactors(CalculateNormFactors(GetNModes(), 0)); // Calculate the realistic normalization factors.
CheckNormalization(GetNModes(), 0); // E fields integration over volume

Expand Down Expand Up @@ -227,11 +240,16 @@ namespace locust
double vz = tKassParticleXP[5];
double term1 = fFieldCore->GetBesselNKPrimeZeros(l,m) / GetDimR();
double term2 = n * LMCConst::Pi() / GetDimL();
if ( fCaterpillarCavity )
{
// Assume n-channels is the same as the number of etalon sections:
term2 *= GetNChannels();
}
double lambda = 1. / pow( 1. / 4. / LMCConst::Pi() / LMCConst::Pi() * ( term1*term1 + term2*term2 ), 0.5);
double lambda_c = 2 * LMCConst::Pi() * GetDimR() / fFieldCore->GetBesselNKPrimeZeros(l,m);
double vp = LMCConst::C() / pow( 1. - lambda*lambda/lambda_c/lambda_c, 0.5 );
double dopplerShift = 0.;
if (vp > 0.) dopplerShift = vz / vp;
if ((vp > 0.) && (fApplyDopplerShift)) dopplerShift = vz / vp;
freqPrime.push_back( ( 1. + dopplerShift ) * tKassParticleXP[7] );
return freqPrime;
}
Expand Down Expand Up @@ -325,7 +343,23 @@ namespace locust
std::vector<double> tEFieldAtProbe;
for (unsigned index=0; index<GetNChannels(); index++)
{
tEFieldAtProbe.push_back( NormalizedEFieldMag(GetNormalizedModeField(l,m,n,tProbeLocation[index],0,teMode)) );
if ( !fCaterpillarCavity )
{
tEFieldAtProbe.push_back( NormalizedEFieldMag(GetNormalizedModeField(l,m,n,tProbeLocation[index],0,teMode)) );
}
else
{
// Assume 1 channel per etalon section:
int indexSubCavity = (int)(( tKassParticleXP[2] + GetDimL()/2. ) * GetNChannels() / GetDimL());
if ( indexSubCavity == index ) // If the electron is in the etalon section where the probe is:
{
tEFieldAtProbe.push_back( NormalizedEFieldMag(GetNormalizedModeField(l,m,n,tProbeLocation[index],0,teMode)) );
}
else
{
tEFieldAtProbe.push_back( 0. );
}
}
}

return {fProbeGain[0] * tEFieldAtProbe[0], fProbeGain[1] * tEFieldAtProbe[1], fProbeGain[2] * tEFieldAtProbe[2]};
Expand Down
2 changes: 2 additions & 0 deletions Source/Fields/LMCCylindricalCavity.hh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ namespace locust
std::vector<double> fCavityProbeRFrac;
std::vector<double> fCavityProbeTheta;
std::vector<double> fProbeGain;
bool fCaterpillarCavity;
bool fApplyDopplerShift;

};

Expand Down
3 changes: 2 additions & 1 deletion Source/Fields/LMCField.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ namespace locust
fCentralFrequency(1.63e11),
fAvgDotProductFactor( 0. ),
fNModes( 2 ),
fNChannels( 1 ),
fbMultiMode( false ),
fTM111( false ),
fTM111( false ),
fR( 0.18 ),
fL( 3.0 ),
fX( 0.010668 ),
Expand Down
60 changes: 34 additions & 26 deletions Source/Fields/LMCModeMapCavity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace locust
fDim2_max(6.284),
fDim3_min(0.),
fDim3_max(0.1524),
fZshift(0.),
fnPixel1(10),
fnPixel2(10),
fnPixel3(10)
Expand Down Expand Up @@ -73,6 +74,11 @@ namespace locust
{
fDim3_max = aParam["dim3-max"]().as_double();
}
if( aParam.has( "mode-map-z-shift" ) )
{
fZshift = aParam["mode-map-z-shift"]().as_double();
}


return true;
}
Expand Down Expand Up @@ -116,27 +122,28 @@ namespace locust
std::string token;
std::stringstream ss(lineContent);
int wordCount = 0;
double r, theta, z;
double r, theta, z;
int i,j,k;
double Erho,Etheta;
double Ex, Ey, Ez;
while (ss >> token)
{
if (wordCount == 0)
{
r = std::stod(token);
r = std::stod(token);
i = (int)((r-fDim1_min)/(fDim1_max-fDim1_min)*(fnPixel1)); // var1 position
}
}
else if (wordCount == 1)
{
theta = std::stod(token);
j = (int)((theta-fDim2_min)/(fDim2_max-fDim2_min)*(fnPixel2)); // var2 position
}
{
theta = std::stod(token);
j = (int)((theta-fDim2_min)/(fDim2_max-fDim2_min)*(fnPixel2)); // var2 position
}
else if (wordCount == 2)
{
z = std::stod(token);
k = (int)((z-fDim3_min)/(fDim3_max-fDim3_min)*(fnPixel3)); // var3 position
}
{
z = std::stod(token);
z += fZshift;
k = (int)((z-fDim3_min)/(fDim3_max-fDim3_min)*(fnPixel3)); // var3 position
}
else if (wordCount == 3) Ex = std::stod(token); // mode E field value
else if (wordCount == 4) Ey = std::stod(token); // mode E field value
else if (wordCount == 5) Ez = std::stod(token); // mode E field value
Expand All @@ -148,37 +155,38 @@ namespace locust
++wordCount;
}

if ((i==fnPixel1) or (j==fnPixel2) or (k==fnPixel3))
{
continue;
}
if ((i==fnPixel1) or (j==fnPixel2) or (k==fnPixel3))
{
continue;
}
if ((i>=fnPixel1) or (j>=fnPixel2) or (k>=fnPixel3))
{
LERROR(lmclog,"Imported mode map dimensions don't agree with those in \"" << aFilename <<".\" Double check dim[1,2,3]-max.");
return false;
}

//Must convert E field from cartesian coordinates to cylindrical coordinates
if(r<1.e-10)
{
Erho = 0.;
Etheta = 0.;
}
else
{
if(r<1.e-10)
{
Erho = 0.;
Etheta = 0.;
}
else
{
Erho = ((Ex * r*cos(theta)) + Ey * r*sin(theta)) / r;
Etheta = ((Ey * r*cos(theta)) - Ex * r*sin(theta)) / r;
}
Etheta = ((Ey * r*cos(theta)) - Ex * r*sin(theta)) / r;
}

std::vector E_input = {Erho,Etheta,Ez};
fModeMapTE_E[i][j][k] = E_input;
// printf("read var1 is %g, var2 is %g, E is %g\n", fModeMapTE_E.back()[0], fModeMapTE_E.back()[1], fModeMapTE_E.back()[2]);
//printf("read var1 is %g, var2 is %g, E is %g\n", fModeMapTE_E.back()[0], fModeMapTE_E.back()[1], fModeMapTE_E.back()[2]);

}
}

modeMapFile.close();

//Reset dimensions from import file to actual cavity dimensions in case they don't match up
//Reset dimensions from import file to actual cavity dimensions in case they don't match up
MatchCavityDimensions(aParam);

return true;
Expand Down
1 change: 1 addition & 0 deletions Source/Fields/LMCModeMapCavity.hh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace locust
int fnPixel1, fnPixel2, fnPixel3;
double fDim1_min, fDim2_min, fDim3_min;
double fDim1_max, fDim2_max, fDim3_max;
double fZshift;
std::vector< std::vector< std::vector< std::vector< double >>>> fModeMapTE_E;

};
Expand Down

0 comments on commit 70d5886

Please sign in to comment.