Skip to content

Commit

Permalink
Merge pull request #288 from project8/feature/waveguideTests
Browse files Browse the repository at this point in the history
Feature/waveguide tests
  • Loading branch information
pslocum authored Aug 24, 2023
2 parents eb9e5c7 + 28ebd9e commit 780b346
Show file tree
Hide file tree
Showing 28 changed files with 625 additions and 262 deletions.
5 changes: 3 additions & 2 deletions Config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ set (EXAMPLE_CONFIGFILES
${CMAKE_CURRENT_BINARY_DIR}/JustKassFieldMap.xml
${CMAKE_CURRENT_BINARY_DIR}/LocustKass_Waveguide_Template.xml
${CMAKE_CURRENT_BINARY_DIR}/LocustKass_FreeSpace_Template.xml
${CMAKE_CURRENT_BINARY_DIR}/LocustKass_Cavity_CCA.xml
${CMAKE_CURRENT_BINARY_DIR}/LocustKass_Cavity_1GHz.xml
${CMAKE_CURRENT_BINARY_DIR}/LocustKass_Cavity_CCA.xml
${CMAKE_CURRENT_BINARY_DIR}/LocustKass_Cavity_1GHz.xml
FreeSpaceGeometry.xml
CavityGeometry_VTinyCoil.xml
CavityGeometry_V00_00_00.xml
WaveguideGeometry_VTinyCoil.xml
${CMAKE_CURRENT_BINARY_DIR}/LocustWaveguideTemplate.json
${CMAKE_CURRENT_BINARY_DIR}/LocustCavityCCA.json
Expand Down
140 changes: 140 additions & 0 deletions Config/CavityGeometry_V00_00_00.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<define name="magnetic_field_scale" value="3200"/>


<define name="start_coil_windings" value="4"/>
<!-- <define name="start_coil_z_position" value="0.0"/> -->
<define name="start_coil_z_position" value="-2.45"/>
<define name="start_coil_radius" value="0.6"/>
<define name="start_coil_length" value="0.1"/>
<define name="start_coil_current" value="{0.7 * [magnetic_field_scale] * [start_coil_windings]}"/>

<define name="background_coil_windings" value="190"/>
<!-- <define name="background_coil_z_position" value="0.1"/> -->
<define name="background_coil_z_position" value="-2.35"/>
<define name="background_coil_radius" value="0.4"/>
<define name="background_coil_length" value="{4.8}"/>
<define name="background_coil_current" value="{0.25 * [magnetic_field_scale]* [background_coil_windings]}"/>

<define name="end_coil_windings" value="4"/>
<!-- <define name="end_coil_z_position" value="4.9"/> -->
<define name="end_coil_z_position" value="2.45"/>
<define name="end_coil_radius" value="0.6"/>
<define name="end_coil_length" value="0.1"/>
<define name="end_coil_current" value="{0.7 * [magnetic_field_scale] * [end_coil_windings]}"/>

<define name="pinch1_coil_windings" value="1"/>
<!-- <define name="pinch1_coil_z_position" value="1.0"/> -->
<define name="pinch1_coil_z_position" value="-1.45"/>
<define name="pinch1_coil_radius" value="0.4"/>
<define name="pinch1_coil_length" value="0.025"/>
<define name="pinch1_coil_current" value="{0.15 * [magnetic_field_scale]* [pinch1_coil_windings]}"/>


<define name="pinch2_coil_windings" value="1"/>
<!-- <define name="pinch2_coil_z_position" value="4.0"/> -->
<define name="pinch2_coil_z_position" value="1.55"/>
<define name="pinch2_coil_radius" value="0.4"/>
<define name="pinch2_coil_length" value="0.025"/>
<define name="pinch2_coil_current" value="{0.15 * [magnetic_field_scale]* [pinch2_coil_windings]}"/>

<print name="pinch2_coil_current" value="[pinch2_coil_current]"/>
<print name="pinch1_coil_current" value="[pinch1_coil_current]"/>

<external_define name="max_step_length" value="0.1"/><!-- max. length of each step during tracking -->

<geometry>



<!-- solenoids -->

<tag name="magnet_tag" name="solenoid_tag" name="background_solenoid_tag">
<cylinder_tube_space name="background_solenoid_space" z1="[background_coil_z_position]" z2="{[background_coil_length] + [background_coil_z_position]}" r1="{[background_coil_radius]}" r2="{[background_coil_radius] + 0.005}" radial_mesh_count="300"/>
</tag>


<tag name="magnet_tag" name="solenoid_tag" name="pinch1_solenoid_tag">
<cylinder_tube_space name="pinch1_solenoid_space" z1="{[pinch1_coil_z_position] - [pinch1_coil_length]/2}" z2="{[pinch1_coil_z_position] + [pinch1_coil_length]/2}" r1="{[pinch1_coil_radius]}" r2="{[pinch1_coil_radius] + 0.005}" radial_mesh_count="300"/>
</tag>

<tag name="magnet_tag" name="solenoid_tag" name="pinch2_solenoid_tag">
<cylinder_tube_space name="pinch2_solenoid_space" z1="{[pinch2_coil_z_position] - [pinch2_coil_length]/2}" z2="{[pinch2_coil_z_position] + [pinch2_coil_length]/2}" r1="{[pinch2_coil_radius]}" r2="{[pinch2_coil_radius] + 0.005}" radial_mesh_count="300"/>
</tag>


<tag name="magnet_tag" name="solenoid_tag" name="start_solenoid_tag">
<cylinder_tube_space name="start_solenoid_space" z1="{[start_coil_z_position]}" z2="{[start_coil_z_position] + [start_coil_length]}" r1="{[start_coil_radius]}" r2="{[start_coil_radius] + 0.005}" radial_mesh_count="300"/>
</tag>
<tag name="magnet_tag" name="solenoid_tag" name="end_solenoid_tag">
<cylinder_tube_space name="end_solenoid_space" z1="{[end_coil_z_position]}" z2="{[end_coil_z_position] + [end_coil_length]}" r1="{[end_coil_radius]}" r2="{[end_coil_radius] + 0.005}" radial_mesh_count="300"/>
</tag>


<space name="project8_assembly">
<space name="background_solenoid" node="background_solenoid_space"/>
<space name="pinch1_solenoid" node="pinch1_solenoid_space"/>
<space name="pinch2_solenoid" node="pinch2_solenoid_space"/>
<space name="start_solenoid" node="start_solenoid_space"/>
<space name="end_solenoid" node="end_solenoid_space"/>
</space>

<!-- world -->
<!--
<cylinder_space name="world_space" z1="-200.0e-3" z2="200.0e-3" r="200.0e-3"/>
-->
<cylinder_space name="world_space" z1="-100.0" z2="100.0" r="20.0"/>
<space name="world" node="world_space">
<space name="project8" tree="project8_assembly">
<transformation rotation_axis_angle="0. 90. 90."/>
</space>
</space>

<electromagnet name="electromagnet_background_solenoid" spaces="world/project8/@background_solenoid_tag" current="[background_coil_current]"/>

<electromagnet name="electromagnet_pinch1_solenoid" spaces="world/project8/@pinch1_solenoid_tag" current="[pinch1_coil_current]"/>
<electromagnet name="electromagnet_pinch2_solenoid" spaces="world/project8/@pinch2_solenoid_tag" current="[pinch2_coil_current]"/>
<electromagnet name="electromagnet_pinch2_solenoid" spaces="world/project8/@start_solenoid_tag" current="[start_coil_current]"/>
<electromagnet name="electromagnet_pinch2_solenoid" spaces="world/project8/@end_solenoid_tag" current="[end_coil_current]"/>


</geometry>

<kemfield>

<!-- magnetic fields -->

<electromagnet_field
name="field_electromagnet"
directory="[KEMFIELD_CACHE]"
file="CavityMagnets.kbd"
system="world/project8"
spaces="world/project8/@solenoid_tag"
>
<zonal_harmonic_field_solver
number_of_bifurcations="-1"
convergence_ratio=".99"
convergence_parameter="1.e-15"
proximity_to_sourcepoint="1.e-12"
number_of_central_coefficients="500"
use_fractional_central_sourcepoint_spacing="true"
central_sourcepoint_fractional_distance="1e-2"
central_sourcepoint_spacing="2.e-5"
number_of_remote_coefficients="200"
remote_sourcepoint_start="-1.e-1"
remote_sourcepoint_end="1.e-1"
/>
</electromagnet_field>


<magnetic_superposition_field
name="total_magnetic_field"
use_caching="false"
>
<!-- <add_field name="background_field" enhancement="1.0" /> -->
<add_field name="field_electromagnet" enhancement="1.0" />
</magnetic_superposition_field>



</kemfield>

6 changes: 5 additions & 1 deletion Config/LocustWaveguideTemplate.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@

"cavity-signal":
{
"rectangular-waveguide": true,
"rectangular-waveguide": true,
"direct-kass-power": false,
"tf-receiver-filename": "${CMAKE_INSTALL_PREFIX}/data/WEGA_Impedance_Center.txt",
"tf-receiver-bin-width": 0.01e9,
"transmitter": "kass-current",
"waveguide-x": 0.010668,
"waveguide-y": 0.004318,
"waveguide-y": 10.0,
"center-to-short": 0.05,
"center-to-antenna": 0.05,
"waveguide-central-frequency": 1.63e11,
Expand Down
58 changes: 38 additions & 20 deletions Source/Core/LMCHFSSResponseFileHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,18 @@ namespace locust
double complexPhase = atan(convolutionValueImag/convolutionValueReal);
double complexMag = pow(convolutionValueReal*convolutionValueReal + convolutionValueImag*convolutionValueImag, 0.5);

return std::make_pair(complexMag, complexPhase);
/* Note that the convolution above uses a real signal to drive both the real and
* imaginary filter components, without a phase shift. For sinusoidal signals, this
* seems like a reasonable approach. It also increases the effective gain of
* the complex filter, compared to a real filter. To align the complex gain with
* that of a real filter, a gain factor of 0.5x for sinusoidal drive signals is
* applied below. For non-sinusoidal drive signals, this scaling should not necessarily
* be applicable.
*/

double gainFactor = 0.5;

return std::make_pair(gainFactor*complexMag, complexPhase);
return complexConvolution;
}

Expand Down Expand Up @@ -173,7 +184,8 @@ namespace locust
}
fFilterComplex = fFIRComplex;

if (fPrintFIR) PrintFIR( fFilter );
if (fPrintFIR) PrintFIR( fFIRComplex, fFIRNBins, "output/FIRhisto.root" );
if (fPrintFIR) PrintFIR( fTFComplex, fTFNBins, "output/TFhisto.root" );

LDEBUG( lmclog, "Finished IFFT to convert transfer function to FIR");
return true;
Expand Down Expand Up @@ -265,7 +277,7 @@ namespace locust
fFilterComplex[i][1] = gfArray[i].second.second;
}

if (fPrintFIR) PrintFIR( fFilterComplex );
if (fPrintFIR) PrintFIR( fFilterComplex, fFIRNBins, "output/FIRhisto.root" );

LDEBUG( lmclog, "Finished populating FIR filter with Green's function.");

Expand Down Expand Up @@ -293,24 +305,24 @@ namespace locust
return true;
}

bool HFSSResponseFileHandlerCore::WriteRootHisto( std::vector<double> aFilter, bool bIQ )
bool HFSSResponseFileHandlerCore::WriteRootHisto( std::vector<double> aFilter, int nBins, bool bIQ )
{
#ifdef ROOT_FOUND
char fbuffer[60];
if (!bIQ)
{
int a = sprintf(fbuffer, "FIR_I");
int a = sprintf(fbuffer, "Real");
}
else
{
int a = sprintf(fbuffer, "FIR_Q");
int a = sprintf(fbuffer, "Imag");
}
fRootHistoWriter->OpenFile("UPDATE");
const char *hName = fbuffer;
TH1D* aHisto = new TH1D(hName, "FIR coefficients; index; coefficient", fFIRNBins, 0., (double)fFIRNBins);
TH1D* aHisto = new TH1D(hName, "Coefficients; index; coefficient", nBins, 0., (double)nBins);
aHisto->SetDirectory(0);

for (unsigned i=0; i<fFIRNBins; i++)
for (unsigned i=0; i<nBins; i++)
{
aHisto->SetBinContent(i+1, aFilter[i]);
}
Expand All @@ -323,28 +335,34 @@ namespace locust
}


void HFSSResponseFileHandlerCore::PrintFIR( std::vector<double> aFilter )
void HFSSResponseFileHandlerCore::PrintFIR( std::vector<double> aFilter, int nBins, const char* filename )
{
LDEBUG( lmclog, "Printing FIR coefficients to file ... ");
FILE * fFIRout = fopen("output/FIR.txt", "w");
for (int i = 0; i < fFIRNBins; i++)
LDEBUG( lmclog, "Printing coefficients to file ... ");
std::string textFile(filename);
std::string suffix(".txt");
textFile.replace(textFile.find(".root"),5,suffix);
FILE * fFIRout = fopen(textFile.c_str(), "w");
for (int i = 0; i < nBins; i++)
{
fprintf(fFIRout,"%g\n", aFilter[i]);
}
fclose(fFIRout);
#ifdef ROOT_FOUND
WriteRootHisto( aFilter, 0 );
WriteRootHisto( aFilter, fFIRNBins, 0 );
#endif

}

void HFSSResponseFileHandlerCore::PrintFIR( fftw_complex* aFilter )
void HFSSResponseFileHandlerCore::PrintFIR( fftw_complex* aFilter, int nBins, const char* filename )
{
std::vector<double> vecFilter0;
std::vector<double> vecFilter1;
LDEBUG( lmclog, "Printing FIR coefficients to file ... ");
FILE * fFIRout = fopen("output/FIR.txt", "w");
for (int i = 0; i < fFIRNBins; i++)
LDEBUG( lmclog, "Printing coefficients to file ... ");
std::string textFile(filename);
std::string suffix(".txt");
textFile.replace(textFile.find(".root"),5,suffix);
FILE * fFIRout = fopen(textFile.c_str(), "w");
for (int i = 0; i < nBins; i++)
{
fprintf(fFIRout,"%g %g\n", aFilter[i][0], aFilter[i][1]);
vecFilter0.push_back(aFilter[i][0]);
Expand All @@ -353,11 +371,11 @@ namespace locust
fclose(fFIRout);
#ifdef ROOT_FOUND
fRootHistoWriter = RootHistoWriter::get_instance();
fRootHistoWriter->SetFilename("output/FIRhisto.root");
fRootHistoWriter->SetFilename(filename);
fRootHistoWriter->OpenFile("RECREATE");
fRootHistoWriter->CloseFile();
WriteRootHisto( vecFilter0, 0 );
WriteRootHisto( vecFilter1, 1 );
WriteRootHisto( vecFilter0, nBins, 0 );
WriteRootHisto( vecFilter1, nBins, 1 );
#endif
}

Expand Down
8 changes: 4 additions & 4 deletions Source/Core/LMCHFSSResponseFileHandler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace locust
@details
Available configuration options:
- "hfss-filetype": string -- The type of file being handler. Currently only Transfer function and Finite Impulse Response
- "print-fir-debug": bool -- Print text file of FIR coefficients.
- "print-fir-debug": bool -- Print text file of FIR and TF coefficients and/or plot Root histograms to file.
*/

class HFSSResponseFileHandlerCore
Expand All @@ -35,9 +35,9 @@ namespace locust
virtual std::pair<double,double> ConvolveWithComplexFIRFilter(std::deque<double> inputBuffer);
int GetFilterSize() const;//Number of entries in the filter
double GetFilterResolution() const;//Get the resolution of the filter
void PrintFIR( std::vector<double> );
void PrintFIR( fftw_complex* aFilter );
bool WriteRootHisto( std::vector<double> aFilter, bool bIQ );
void PrintFIR( std::vector<double>, int nBins, const char* filename );
void PrintFIR( fftw_complex* aFilter, int nBins, const char* filename );
bool WriteRootHisto( std::vector<double> aFilter, int nBins, bool bIQ );


protected:
Expand Down
Loading

0 comments on commit 780b346

Please sign in to comment.