Commit 1e8dfae4 authored by Daniel Brown's avatar Daniel Brown
Browse files

adding in storage of in/out going beam parameters used for computing mismatches

parent eb64dc92
......@@ -144,6 +144,10 @@ typedef struct frequency_linked_list {
int count;
} frequency_linked_list_t;
typedef struct q_io {
complex_t qxi, qxo, qyi, qyo;
} q_io_t;
/** Type defines the different scalings of the quantum output detectors. */
typedef enum qoutput_scale {
NOTSET = 0, /** Use default set in kat.ini */
......@@ -871,6 +875,8 @@ typedef struct mirror {
rom_map_t *map_rom;
mirror_knm_q_t prev_rom_q; /** previous q values used for knm q */
mirror_knm_q_t qm; /* mismatch beam parameters */
double angle; //!< angle of the mirror about the z axis
/** q values used internally for the integration routines*/
mirror_knm_q_t knm_q;
......@@ -1021,6 +1027,9 @@ typedef struct space {
complex_t ***q12; //!< quantum noise matrix element mode 1 -> mode 2
complex_t ***q21; //!< quantum noise matrix element mode 2 -> mode 1
q_io_t qm12;
q_io_t qm21;
// q[mode index][output][frequency][quadrature]
double gouy_x; //!< Gouy phase in x direction
......@@ -1174,6 +1183,12 @@ typedef struct beamsplitter {
//! transformation matrix for q of element; transmission in sagittal plane 2
ABCD_t qqt2s;
q_io_t qm12, qm21;
q_io_t qm13, qm31;
q_io_t qm24, qm42;
q_io_t qm34, qm43;
q_io_t qm11, qm22, qm33, qm44;
bitflag attribs; //!< bit-coded flag for which attribs have been set
double mass; //!< mass of mirror
double Ix; /** Moment of inertia about x-axis */
......@@ -1212,7 +1227,7 @@ typedef struct beamsplitter {
surface_merged_map_t map_merged;
double map_rotation; //!< map_rotation of the mirror about the z axis
bs_knm_q_t knm_q; //!< q values for knm calculation
bs_knm_q_t qm; // mode mismatch beam parameters
double r_aperture; //!< physical radius of beamsplitter
int knm_order[NUM_KNM_TYPES]; //!< states which order the distortions to the bs should apply
......@@ -1292,23 +1307,6 @@ typedef struct grating {
// sagittal ABCD matrices
//! transformation matrix for q of element; sagittal plane
ABCD_t **qqs;
complex_t ***q11; //!< quantum noise matrix element mode 1 -> mode 1
complex_t ***q12; //!< quantum noise matrix element mode 1 -> mode 2
complex_t ***q13; //!< quantum noise matrix element mode 1 -> mode 3
complex_t ***q14; //!< quantum noise matrix element mode 1 -> mode 4
complex_t ***q21; //!< quantum noise matrix element mode 2 -> mode 1
complex_t ***q22; //!< quantum noise matrix element mode 2 -> mode 2
complex_t ***q23; //!< quantum noise matrix element mode 2 -> mode 3
complex_t ***q24; //!< quantum noise matrix element mode 2 -> mode 4
complex_t ***q31; //!< quantum noise matrix element mode 3 -> mode 1
complex_t ***q32; //!< quantum noise matrix element mode 3 -> mode 2
complex_t ***q33; //!< quantum noise matrix element mode 3 -> mode 3
complex_t ***q34; //!< quantum noise matrix element mode 3 -> mode 4
complex_t ***q41; //!< quantum noise matrix element mode 4 -> mode 1
complex_t ***q42; //!< quantum noise matrix element mode 4 -> mode 2
complex_t ***q43; //!< quantum noise matrix element mode 4 -> mode 3
complex_t ***q44; //!< quantum noise matrix element mode 4 -> mode 4
char name[MAX_TOKEN_LEN]; //!< grating name
......@@ -1757,6 +1755,9 @@ typedef struct modulator {
ABCD_t qq; //!< transformation matrix for q of modulator
q_io_t qm12;
q_io_t qm21;
bitflag knm_flags;
int rebuild; //!< rebuild the modulator?
......@@ -1811,6 +1812,9 @@ typedef struct diode {
ABCD_t qq; //!< transformation matrix for q of diode
q_io_t qm12;
q_io_t qm21;
int rebuild; //!< rebuild the diode?
bitflag knm_flags;
......@@ -1854,6 +1858,11 @@ typedef struct dbs {
ABCD_t qq; //!< transformation matrix for q of diode
q_io_t qm13;
q_io_t qm21;
q_io_t qm34;
q_io_t qm42;
int rebuild; //!< rebuild the diode?
bitflag knm_flags;
......@@ -1899,6 +1908,9 @@ typedef struct lens {
ABCD_t qq; //!< transformation matrix for q of lens
q_io_t qm12;
q_io_t qm21;
complex_t ***q12; //!< quantum noise matrix element mode 1 -> mode 2
complex_t ***q21; //!< quantum noise matrix element mode 2 -> mode 1
bitflag knm_flags;
......@@ -2581,6 +2593,8 @@ typedef struct interferometer {
bool subplot; //!< create subplot for phase?
int pause; //!< put "pause -1" in gnuplot file
int printmatrix; //!< print matrix into file
int mismatches;
bool printqnoiseinputs;
//! beam tracing on/off
......
......@@ -863,6 +863,29 @@ void set_coupling_info() {
}
}
}
for (i = 0; i < inter.num_dbss; i++) {
dbs_t *dbs = &inter.dbs_list[i];
coupling_info_t * v[4] = {&dbs->a_cplng_13, &dbs->a_cplng_21, &dbs->a_cplng_34, &dbs->a_cplng_42};
int j;
for (j = 0; j < 4; j++) {
if (!options.use_coupling_reduction) {
__set_no_reduce_coupling_info(v[j]);
} else {
v[j]->coupling_off = !(dbs->mismatching & pow_two(j));
v[j]->has_xeven = true;
v[j]->has_yeven = true;
v[j]->has_xodd = true;
v[j]->has_yodd = true;
v[j]->max_coupling_order = max;
__print_coupling_info_line(dbs->name, v[j]);
}
}
}
if (inter.debug && options.use_coupling_reduction) {
message("-----------------------------------\n");
......@@ -990,7 +1013,9 @@ int set_k_mirror(int mirror_index) {
knm_q.qyt1_21 = complex_0;
knm_q.qyt2_21 = complex_0;
}
memcpy(&mirror->qm, &knm_q, sizeof(mirror_knm_q_t));
if (inter.debug & 128) {
message("* Mirror %s, knm to be calculated: ", mirror->name);
if (CALC_MR_KNM(mirror, 11)) {
......@@ -1700,7 +1725,9 @@ int set_k_beamsplitter(int bs_index) {
knm_q.qxt2_42 = complex_0;
knm_q.qyt2_42 = complex_0;
}
memcpy(&bs->qm, &knm_q, sizeof(bs_knm_q_t));
// Give the user some debug feedback on what is being calculated
if (inter.debug & 128) {
message("* Beamsplitter %s, knm to be calculated: ", bs->name);
......@@ -2223,6 +2250,10 @@ int set_k_space(int space_index) {
qyt2 = qy2;
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) {
......@@ -2283,6 +2314,10 @@ int set_k_space(int space_index) {
qyt2 = cminus(cconj(qy1));
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) {
......@@ -2437,6 +2472,11 @@ int set_k_lens(int lens_index) {
qyt2 = qy2;
if (!ceq(qxt, qxt2) || !ceq(qyt, qyt2)) {
lens->mismatching |= 1;
lens->qm12.qxi = qxt;
lens->qm12.qxo = qxt2;
lens->qm12.qyi = qyt;
lens->qm12.qyo = qyt2;
}
if (inter.trace & 64) {
......@@ -2497,6 +2537,10 @@ int set_k_lens(int lens_index) {
qyt2 = cminus(cconj(qy1));
if (!ceq(qxt, qxt2) || !ceq(qyt, qyt2)) {
lens->mismatching |= 2;
lens->qm21.qxi = qxt;
lens->qm21.qxo = qxt2;
lens->qm21.qyi = qyt;
lens->qm21.qyo = qyt2;
}
if (inter.trace & 64) {
......@@ -2642,6 +2686,10 @@ int set_k_modulator(int modulator_index) {
if (!ceq(qxt, qxt2) || !ceq(qyt, qyt2)) {
mod->mismatching |= 1;
mod->qm12.qxi = qxt;
mod->qm12.qxo = qxt2;
mod->qm12.qyi = qyt;
mod->qm12.qyo = qyt2;
}
if (inter.trace & 64) {
......@@ -2691,6 +2739,10 @@ int set_k_modulator(int modulator_index) {
if (!ceq(qxt, qxt2) || !ceq(qyt, qyt2)) {
mod->mismatching |= 2;
mod->qm21.qxi = qxt;
mod->qm21.qxo = qxt2;
mod->qm21.qyi = qyt;
mod->qm21.qyo = qyt2;
}
if (inter.trace & 64) {
......@@ -3018,6 +3070,10 @@ int set_k_dbs(int dbs_index) {
if (!ceq(qxt, qxt2) || !ceq(qyt, qyt2)) {
dbs->mismatching |= 1;
dbs->qm13.qxi = qxt;
dbs->qm13.qxo = qxt2;
dbs->qm13.qyi = qyt;
dbs->qm13.qyo = qyt2;
}
if (inter.trace & 64) {
......@@ -3073,6 +3129,11 @@ int set_k_dbs(int dbs_index) {
if (!ceq(qxt, qxt2) || !ceq(qyt, qyt2)) {
dbs->mismatching |= 2;
dbs->qm21.qxi = qxt;
dbs->qm21.qxo = qxt2;
dbs->qm21.qyi = qyt;
dbs->qm21.qyo = qyt2;
}
if (inter.trace & 64) {
......@@ -3128,6 +3189,11 @@ int set_k_dbs(int dbs_index) {
if (!ceq(qxt, qxt2) || !ceq(qyt, qyt2)) {
dbs->mismatching |= 4;
dbs->qm34.qxi = qxt;
dbs->qm34.qxo = qxt2;
dbs->qm34.qyi = qyt;
dbs->qm34.qyo = qyt2;
}
if (inter.trace & 64) {
......@@ -3183,6 +3249,11 @@ int set_k_dbs(int dbs_index) {
if (!ceq(qxt, qxt2) || !ceq(qyt, qyt2)) {
dbs->mismatching |= 8;
dbs->qm42.qxi = qxt;
dbs->qm42.qxo = qxt2;
dbs->qm42.qyi = qyt;
dbs->qm42.qyo = qyt2;
}
if (inter.trace & 64) {
......@@ -3346,6 +3417,11 @@ int set_k_diode(int diode_index) {
qyt2 = qy2;
if (!ceq(qxt, qxt2) || !ceq(qyt, qyt2)) {
diode->mismatching |= 1;
diode->qm12.qxi = qxt;
diode->qm12.qxo = qxt2;
diode->qm12.qyi = qyt;
diode->qm12.qyo = qyt2;
}
if (inter.trace & 64) {
......@@ -3399,6 +3475,11 @@ int set_k_diode(int diode_index) {
qyt2 = cminus(cconj(qy1));
if (!ceq(qxt, qxt2) || !ceq(qyt, qyt2)) {
diode->mismatching |= 2;
diode->qm21.qxi = qxt;
diode->qm21.qxo = qxt2;
diode->qm21.qyi = qyt;
diode->qm21.qyo = qyt2;
}
if (inter.trace & 64) {
......@@ -3445,113 +3526,113 @@ int set_k_diode(int diode_index) {
}
}
if (NOT node3.gnd_node &&
NOT node2.gnd_node) {
qxt = qx3;
qyt = qy3;
qxt2 = qx2;
qyt2 = qy2;
if (!ceq(qxt, qxt2) || !ceq(qyt, qyt2)) {
diode->mismatching |= 4;
}
if (inter.trace & 64) {
if (!ceq(qxt, qxt2) || !ceq(qyt, qyt2)) {
mode_match(qxt, qxt2, &kx, &kmx);
mode_match(qyt, qyt2, &ky, &kmy);
message(" t32: Kx=%s \n Ky=%s \n Kmx %9.3g Kmy %9.3g\n",
complex_form(kx), complex_form(ky), kmx, kmy);
}
}
if (inter.debug & 32) {
message("k32");
}
if (inter.set_tem_phase_zero & 1) {
phase = zphase(k_nmnm(0, 0, 0, 0, qxt, qyt, qxt2, qyt2, 0.0, 0.0, nr3, diode->knm_flags));
} else {
phase = 0.0;
}
int n, m;
for (n = 0; n < inter.num_fields; n++) {
for (m = 0; m < inter.num_fields; m++) {
get_tem_modes_from_field_index(&n1, &m1, n);
get_tem_modes_from_field_index(&n2, &m2, m);
if (n1 == NOT_FOUND || m1 == NOT_FOUND ||
n2 == NOT_FOUND || m2 == NOT_FOUND) {
bug_error("notfound 1");
}
diode->k32[n][m] = z_by_phr(k_nmnm(n1, m1, n2, m2, qxt, qyt, qxt2, qyt2,
0.0, 0.0, nr3, diode->knm_flags), -phase);
if (inter.debug & 32 && !ceq(complex_0, diode->k32[n][m])) {
message(" [%d, %d]=%s, ", n, m, complex_form(diode->k32[n][m]));
}
}
if (inter.debug & 32) {
message("\n ");
}
}
if (inter.debug & 32) {
message("\n");
}
// transmission2
qxt = cminus(cconj(qx2));
qyt = cminus(cconj(qy2));
qxt2 = cminus(cconj(qx3));
qyt2 = cminus(cconj(qy3));
if (!ceq(qxt, qxt2) || !ceq(qyt, qyt2)) {
diode->mismatching |= 8;
}
if (inter.trace & 64) {
if (!ceq(qxt, qxt2) || !ceq(qyt, qyt2)) {
mode_match(qxt, qxt2, &kx, &kmx);
mode_match(qyt, qyt2, &ky, &kmy);
message(" t23: Kx=%s \n Ky=%s \n Kmx %9.3g Kmy %9.3g\n",
complex_form(kx), complex_form(ky), kmx, kmy);
}
}
if (inter.debug & 32) {
message("k23");
}
if (inter.set_tem_phase_zero & 1) {
phase = zphase(k_nmnm(0, 0, 0, 0, qxt, qyt, qxt2, qyt2, 0.0, 0.0, nr1, diode->knm_flags));
} else {
phase = 0.0;
}
for (n = 0; n < inter.num_fields; n++) {
for (m = 0; m < inter.num_fields; m++) {
get_tem_modes_from_field_index(&n1, &m1, n);
get_tem_modes_from_field_index(&n2, &m2, m);
if (n1 == NOT_FOUND || m1 == NOT_FOUND ||
n2 == NOT_FOUND || m2 == NOT_FOUND) {
bug_error("notfound 2");
}
diode->k23[n][m] = z_by_phr(k_nmnm(n1, m1, n2, m2, qxt, qyt, qxt2, qyt2,
0.0, 0.0, nr1, diode->knm_flags), -phase);
if (inter.debug & 32 && !ceq(complex_0, diode->k23[n][m])) {
message(" [%d, %d]=%s, ", n, m, complex_form(diode->k23[n][m]));
}
}
if (inter.debug & 32) {
message("\n ");
}
}
if (inter.debug & 32) {
message("\n");
}
}
// if (NOT node3.gnd_node &&
// NOT node2.gnd_node) {
// qxt = qx3;
// qyt = qy3;
//
// qxt2 = qx2;
// qyt2 = qy2;
// if (!ceq(qxt, qxt2) || !ceq(qyt, qyt2)) {
// diode->mismatching |= 4;
// }
//
// if (inter.trace & 64) {
// if (!ceq(qxt, qxt2) || !ceq(qyt, qyt2)) {
// mode_match(qxt, qxt2, &kx, &kmx);
// mode_match(qyt, qyt2, &ky, &kmy);
// message(" t32: Kx=%s \n Ky=%s \n Kmx %9.3g Kmy %9.3g\n",
// complex_form(kx), complex_form(ky), kmx, kmy);
// }
// }
//
// if (inter.debug & 32) {
// message("k32");
// }
//
// if (inter.set_tem_phase_zero & 1) {
// phase = zphase(k_nmnm(0, 0, 0, 0, qxt, qyt, qxt2, qyt2, 0.0, 0.0, nr3, diode->knm_flags));
// } else {
// phase = 0.0;
// }
//
// int n, m;
// for (n = 0; n < inter.num_fields; n++) {
// for (m = 0; m < inter.num_fields; m++) {
// get_tem_modes_from_field_index(&n1, &m1, n);
// get_tem_modes_from_field_index(&n2, &m2, m);
// if (n1 == NOT_FOUND || m1 == NOT_FOUND ||
// n2 == NOT_FOUND || m2 == NOT_FOUND) {
// bug_error("notfound 1");
// }
// diode->k32[n][m] = z_by_phr(k_nmnm(n1, m1, n2, m2, qxt, qyt, qxt2, qyt2,
// 0.0, 0.0, nr3, diode->knm_flags), -phase);
// if (inter.debug & 32 && !ceq(complex_0, diode->k32[n][m])) {
// message(" [%d, %d]=%s, ", n, m, complex_form(diode->k32[n][m]));
// }
// }
//
// if (inter.debug & 32) {
// message("\n ");
// }
// }
//
// if (inter.debug & 32) {
// message("\n");
// }
//
// // transmission2
// qxt = cminus(cconj(qx2));
// qyt = cminus(cconj(qy2));
// qxt2 = cminus(cconj(qx3));
// qyt2 = cminus(cconj(qy3));
// if (!ceq(qxt, qxt2) || !ceq(qyt, qyt2)) {
// diode->mismatching |= 8;
// }
//
// if (inter.trace & 64) {
// if (!ceq(qxt, qxt2) || !ceq(qyt, qyt2)) {
// mode_match(qxt, qxt2, &kx, &kmx);
// mode_match(qyt, qyt2, &ky, &kmy);
// message(" t23: Kx=%s \n Ky=%s \n Kmx %9.3g Kmy %9.3g\n",
// complex_form(kx), complex_form(ky), kmx, kmy);
// }
// }
//
// if (inter.debug & 32) {
// message("k23");
// }
//
// if (inter.set_tem_phase_zero & 1) {
// phase = zphase(k_nmnm(0, 0, 0, 0, qxt, qyt, qxt2, qyt2, 0.0, 0.0, nr1, diode->knm_flags));
// } else {
// phase = 0.0;
// }
//
// for (n = 0; n < inter.num_fields; n++) {
// for (m = 0; m < inter.num_fields; m++) {
// get_tem_modes_from_field_index(&n1, &m1, n);
// get_tem_modes_from_field_index(&n2, &m2, m);
// if (n1 == NOT_FOUND || m1 == NOT_FOUND ||
// n2 == NOT_FOUND || m2 == NOT_FOUND) {
// bug_error("notfound 2");
// }
// diode->k23[n][m] = z_by_phr(k_nmnm(n1, m1, n2, m2, qxt, qyt, qxt2, qyt2,
// 0.0, 0.0, nr1, diode->knm_flags), -phase);
// if (inter.debug & 32 && !ceq(complex_0, diode->k23[n][m])) {
// message(" [%d, %d]=%s, ", n, m, complex_form(diode->k23[n][m]));
// }
// }
//
// if (inter.debug & 32) {
// message("\n ");
// }
// }
//
// if (inter.debug & 32) {
// message("\n");
// }
// }
int n, m;
......
......@@ -170,6 +170,7 @@ void initialise_simulation_variables(void) {
inter.subplot = false;
inter.pause = 0;
inter.printmatrix = 0;
inter.mismatches = 0;
inter.printqnoiseinputs = false;
inter.trace = 0;
inter.splot = 0;
......
......@@ -363,8 +363,9 @@ void check_mirror_knm_mismatch_astig(bitflag knm_calc_flags, mirror_knm_q_t *knm
// bother calculating them
if ((knm_calc_flags & MR11Calc) == MR11Calc){
if (!ceq(knm_q->qxt1_11, knm_q->qxt2_11)
|| !ceq(knm_q->qyt1_11, knm_q->qyt2_11))
|| !ceq(knm_q->qyt1_11, knm_q->qyt2_11)) {
*mismatch = *mismatch | 1;
}
if (!ceq(knm_q->qxt1_11, knm_q->qyt1_11)
|| !ceq(knm_q->qxt2_11, knm_q->qyt2_11))
......
......@@ -468,14 +468,6 @@ void __check_quant_noise_for_node(bool count, int node_index, size_t *num, const
if(!inter.node_list[node_index].gnd_node){
bool isOpenPort = is_open_port(node_index);
// need some special handling of a diode's second node if the 3rd isn't
// a proper node, as this will always be an open port
if(comp_type == DIODE
&& inter.node_list[inter.diode_list[comp_list_index].node3_index].gnd_node
&& inter.diode_list[comp_list_index].node2_index == node_index) {
isOpenPort = true;
}
if(isOpenPort){
if(!count) {
set_noise_port(&inter.qnoise_in_list[*num], comp_list_index, comp_type, OPEN_PORT, node_index);
......
......@@ -391,6 +391,7 @@ void check_all_commands(FILE *fp){
(strncasecmp(s, "pause", 5) == 0) ||
(strncasecmp(s, "printmatrix", 11) == 0) ||
(strncasecmp(s, "printnoises", 11) == 0) ||
(strncasecmp(s, "mismatches", 10) == 0) ||
(strncasecmp(s, "trace", 5) == 0) ||
(strncasecmp(s, "powers", 6) == 0) ||
(strncasecmp(s, "grating", 7) == 0) ||
......@@ -943,6 +944,8 @@ void read_file(FILE *fp) {
inter.printqnoiseinputs = true;
} else if (strncasecmp(s, "printmatrix", 11) == 0) {
inter.printmatrix = 1;
} else if (strncasecmp(s, "mismatches", 10) == 0) {
inter.mismatches = 1;
} else if (strncasecmp(s, "frequency", 9) == 0) {
read_frequency_command(s);
} else if (strncasecmp(s, "powers", 6) == 0) {
......@@ -12537,6 +12540,8 @@ void read_diode(const char *command_string) {
node2_name = vars[4];
node3_name = vars[5];
gerror("Line `%s':\n3 node isolator has been depreciated. Use `dbs` component instead.'\n", command_string);
} else if(num_vars_read == 6){
object_name = vars[0];
suppression_string = vars[1];
......
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