Commit 628e7e86 authored by Daniel Brown's avatar Daniel Brown

Trying out mismatching outputs

parent 7886b9b3
......@@ -72,6 +72,95 @@ bool defaultKNMChangeWarning = false;
zmatrix tmp_knm = NULL;
double mismatch(complex_t q1, complex_t q2) {
/**
* Given two beam parameters this computes a figure of merit for
* how much they overlap, or the amount of mismatch between them.
*
* 0 being no matching
* 1 being perfect matching
*
* Will return nan if the beam parameter imaginary part is zero or negative.
*
* See ddb thesis equation 1.63.
*
* @param q1
* @param q2
* @return Mismatch figure of merit or nan if not calculable
*/
double result;
if(q1.im <= 0 || q2.im <= 0) {
result = NAN;
} else {
complex_t t1 = z_m_z(cconj(q1), q2);
double abs_t1 = zmod(t1);
result = 4.0 * fabs(q1.im * q2.im) / (abs_t1 * abs_t1);
}
assert((result >= 0 && result <=1) || isnan(result));
return result;
}
/**
* When called this will output the current mismatch status of the interferometer.
*/
void output_mismatch() {
// Idea here is to loop through each component and output the mode matching
// for each beam direction within the component.
int i = 0;
double mx, my;
message("\n---- Start interferometer mismatches ----\n");
for(i=0; i<inter.num_mirrors; i++) {
mirror_t *m = &inter.mirror_list[i];
message("mirror: %s\n", m->name);
mx = mismatch(m->qm.qxt1_11, m->qm.qxt2_11);
my = mismatch(m->qm.qyt1_11, m->qm.qyt2_11);
message("\t11: %g %g\n", mx, my);
mx = mismatch(m->qm.qxt1_12, m->qm.qxt2_12);
my = mismatch(m->qm.qyt1_12, m->qm.qyt2_12);
message("\t12: %g %g\n", mx, my);
mx = mismatch(m->qm.qxt1_21, m->qm.qxt2_21);
my = mismatch(m->qm.qyt1_21, m->qm.qyt2_21);
message("\t21: %g %g\n", mx, my);
mx = mismatch(m->qm.qxt1_22, m->qm.qxt2_22);
my = mismatch(m->qm.qyt1_22, m->qm.qyt2_22);
message("\t22: %g %g\n", mx, my);
}
for(i=0; i<inter.num_spaces; i++) {
space_t *s = &inter.space_list[i];
message("space: %s\n", s->name);
mx = mismatch(s->qm12.qxi, s->qm12.qxo);
my = mismatch(s->qm12.qyi, s->qm12.qyo);
message("\t12: %g %g\n", mx, my);
mx = mismatch(s->qm21.qxi, s->qm21.qxo);
my = mismatch(s->qm21.qyi, s->qm21.qyo);
message("\t21: %g %g\n", mx, my);
}
message("\n---- End interferometer mismatches ----\n");
}
//! Compute coupling coefficients between two beams
/**
......@@ -2248,12 +2337,14 @@ int set_k_space(int space_index) {
qxt2 = qx2;
qyt2 = qy2;
space->qm12.qxi = qxt;
space->qm12.qxo = qxt2;
space->qm12.qyi = qyt;
space->qm12.qyo = qyt2;
if (!ceq(qxt, qxt2) || !ceq(qyt, qyt2)) {
space->mismatching |= 1;
space->qm12.qxi = qxt;
space->qm12.qxo = qxt2;
space->qm12.qyi = qyt;
space->qm12.qyo = qyt2;
}
if (inter.trace & 64) {
......@@ -2312,12 +2403,14 @@ int set_k_space(int space_index) {
qxt2 = cminus(cconj(qx1));
qyt2 = cminus(cconj(qy1));
space->qm21.qxi = qxt;
space->qm21.qxo = qxt2;
space->qm21.qyi = qyt;
space->qm21.qyo = qyt2;
if (!ceq(qxt, qxt2) || !ceq(qyt, qyt2)) {
space->mismatching |= 2;
space->qm21.qxi = qxt;
space->qm21.qxo = qxt2;
space->qm21.qyi = qyt;
space->qm21.qyo = qyt2;
}
if (inter.trace & 64) {
......
......@@ -33,6 +33,7 @@
void set_coupling_info();
void knm_matrix_mult(zmatrix A, zmatrix B, zmatrix C);
void output_mismatch();
inline complex_t rev_gouy(complex_t k, int n1, int m1, int n2, int m2,
complex_t qx1, complex_t qx2, complex_t qy1, complex_t qy2);
......
......@@ -3683,6 +3683,8 @@ void tune_parameters(void) {
fill_detectors();
}
output_mismatch();
}
//! Rebuild all components in system
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment