Commit c0896c3f authored by Daniel Brown's avatar Daniel Brown

Adding options to mismatch command

parent 253dfc5f
......@@ -2468,6 +2468,13 @@ typedef struct mhomodyne {
bool is_quantum;
} mhomodyne_t;
typedef enum {
IGNORE_LOW_R_MIRROR_BS = 1,
IGNORE_LOW_T_MIRROR_BS = 2,
AVERAGE_Q = 4,
PRINT_EACH_STEP = 8
} mismatches_options_t;
//! interferometer type
typedef struct interferometer {
char *basename; //!< basename for input and output files
......@@ -2595,6 +2602,8 @@ typedef struct interferometer {
int printmatrix; //!< print matrix into file
int mismatches;
mismatches_options_t mismatches_options;
bool printqnoiseinputs;
//! beam tracing on/off
......@@ -2705,7 +2714,8 @@ typedef struct interferometer {
double fsig; //!< positive signal frequency
double mfsig; //!< negative signal frequency
double mismatch_lower; // lower level or mismatch to report
double mismatches_lower; // lower level or mismatch to report
double mismatches_R_T_limit;
int *gnuterm; //!< list of gnuplot terminals
char **gnutermfn; //!< gnuplot terminal function
......
......@@ -104,11 +104,20 @@ double mismatch(complex_t q1, complex_t q2) {
}
void __print_mismatch(const char *dir, double mx, double my) {
const char *fmt = "\t%s: %18.10g (x) %18.10g (y)\n";
const char *fmt1 = "\t%s: %18.10g (x) %18.10g (y)\n";
const char *fmt2 = "\t%s: %18.10g\n";
if(!(isnan(mx) && isnan(my))){
if(mx >= inter.mismatch_lower || my >= inter.mismatch_lower){
message(fmt, dir, mx, my);
if(inter.mismatches_options & AVERAGE_Q){
double am = (mx+my)/2;
if(am >= inter.mismatches_lower){
message(fmt2, dir, am);
}
} else {
if(mx >= inter.mismatches_lower || my >= inter.mismatches_lower){
message(fmt1, dir, mx, my);
}
}
}
}
......@@ -132,48 +141,61 @@ void output_mismatch() {
message("mirror: %s\n", m->name);
__print_mismatch("1->1", mismatch(m->qm.qxt1_11, m->qm.qxt2_11),
mismatch(m->qm.qyt1_11, m->qm.qyt2_11));
bool print_refl = !((inter.mismatches_options & IGNORE_LOW_R_MIRROR_BS) && m->R < inter.mismatches_lower);
bool print_trans = !((inter.mismatches_options & IGNORE_LOW_T_MIRROR_BS) && m->T < inter.mismatches_lower);
__print_mismatch("1->2", mismatch(m->qm.qxt1_12, m->qm.qxt2_12),
mismatch(m->qm.qyt1_12, m->qm.qyt2_12));
if(print_refl) {
__print_mismatch("1->1", mismatch(m->qm.qxt1_11, m->qm.qxt2_11),
mismatch(m->qm.qyt1_11, m->qm.qyt2_11));
}
__print_mismatch("2->1", mismatch(m->qm.qxt1_21, m->qm.qxt2_21),
mismatch(m->qm.qyt1_21, m->qm.qyt2_21));
if(print_trans){
__print_mismatch("1->2", mismatch(m->qm.qxt1_12, m->qm.qxt2_12),
mismatch(m->qm.qyt1_12, m->qm.qyt2_12));
__print_mismatch("2->1", mismatch(m->qm.qxt1_21, m->qm.qxt2_21),
mismatch(m->qm.qyt1_21, m->qm.qyt2_21));
}
__print_mismatch("2->2", mismatch(m->qm.qxt1_22, m->qm.qxt2_22),
mismatch(m->qm.qyt1_22, m->qm.qyt2_22));
if(print_refl) {
__print_mismatch("2->2", mismatch(m->qm.qxt1_22, m->qm.qxt2_22),
mismatch(m->qm.qyt1_22, m->qm.qyt2_22));
}
}
for(i=0; i<inter.num_beamsplitters; i++) {
beamsplitter_t *bs = &inter.bs_list[i];
bool print_refl = !((inter.mismatches_options & IGNORE_LOW_R_MIRROR_BS) && bs->R < inter.mismatches_lower);
bool print_trans = !((inter.mismatches_options & IGNORE_LOW_T_MIRROR_BS) && bs->T < inter.mismatches_lower);
message("bs: %s\n", bs->name);
__print_mismatch("1->2", mismatch(bs->qm.qxt1_12, bs->qm.qxt2_12),
if(print_refl) __print_mismatch("1->2", mismatch(bs->qm.qxt1_12, bs->qm.qxt2_12),
mismatch(bs->qm.qyt1_12, bs->qm.qyt2_12));
__print_mismatch("1->3", mismatch(bs->qm.qxt1_13, bs->qm.qxt2_13),
if(print_trans) __print_mismatch("1->3", mismatch(bs->qm.qxt1_13, bs->qm.qxt2_13),
mismatch(bs->qm.qyt1_13, bs->qm.qyt2_13));
__print_mismatch("2->1", mismatch(bs->qm.qxt1_21, bs->qm.qxt2_21),
if(print_refl) __print_mismatch("2->1", mismatch(bs->qm.qxt1_21, bs->qm.qxt2_21),
mismatch(bs->qm.qyt1_21, bs->qm.qyt2_21));
__print_mismatch("2->4", mismatch(bs->qm.qxt1_24, bs->qm.qxt2_24),
if(print_trans) __print_mismatch("2->4", mismatch(bs->qm.qxt1_24, bs->qm.qxt2_24),
mismatch(bs->qm.qyt1_24, bs->qm.qyt2_24));
__print_mismatch("3->1", mismatch(bs->qm.qxt1_31, bs->qm.qxt2_31),
if(print_trans) __print_mismatch("3->1", mismatch(bs->qm.qxt1_31, bs->qm.qxt2_31),
mismatch(bs->qm.qyt1_31, bs->qm.qyt2_31));
__print_mismatch("3->4", mismatch(bs->qm.qxt1_34, bs->qm.qxt2_34),
if(print_refl) __print_mismatch("3->4", mismatch(bs->qm.qxt1_34, bs->qm.qxt2_34),
mismatch(bs->qm.qyt1_34, bs->qm.qyt2_34));
__print_mismatch("4->2", mismatch(bs->qm.qxt1_42, bs->qm.qxt2_42),
if(print_trans) __print_mismatch("4->2", mismatch(bs->qm.qxt1_42, bs->qm.qxt2_42),
mismatch(bs->qm.qyt1_42, bs->qm.qyt2_42));
__print_mismatch("4->3", mismatch(bs->qm.qxt1_43, bs->qm.qxt2_43),
if(print_refl) __print_mismatch("4->3", mismatch(bs->qm.qxt1_43, bs->qm.qxt2_43),
mismatch(bs->qm.qyt1_43, bs->qm.qyt2_43));
}
message("\n---- End interferometer mismatches ----\n");
......
......@@ -91,6 +91,8 @@ static double y_axis_point; //!< Current distance along y-axis
int current_point; //!< The current point used for progress output
int current_point_tot; //!< Overall current point used for progress output
bool printed_mismatches = false;
//! A flag indicating that result 'looks like' a transfer function to Finesse
extern int *transfer;
......@@ -3684,7 +3686,12 @@ void tune_parameters(void) {
fill_detectors();
}
output_mismatch();
bool print_each_step = inter.mismatches_options & PRINT_EACH_STEP;
if ((!printed_mismatches && !print_each_step) || print_each_step){
output_mismatch();
printed_mismatches = true;
}
}
//! Rebuild all components in system
......
......@@ -171,7 +171,9 @@ void initialise_simulation_variables(void) {
inter.pause = 0;
inter.printmatrix = 0;
inter.mismatches = 0;
inter.mismatch_lower = 1e-6;
inter.mismatches_options = IGNORE_LOW_R_MIRROR_BS | IGNORE_LOW_T_MIRROR_BS | AVERAGE_Q;
inter.mismatches_lower = 1e-6;
inter.mismatches_R_T_limit = 1e-6;
inter.printqnoiseinputs = false;
inter.trace = 0;
inter.splot = 0;
......@@ -2046,6 +2048,8 @@ void read_init(void) {
read_init_integer(s, 18, &init.calc_knm_transpose);
} else if (string_matches(s, "cuba_numprocs")) {
read_init_integer(s, 13, &init.cuba_numprocs);
} else if (string_matches(s, "mismatches_R_T_limit")) {
read_init_double(s, 20, &inter.mismatches_R_T_limit);
} else {
warn("Init file kat.ini: input line '%s':\n missing keyword\n", s);
}
......
......@@ -2057,6 +2057,12 @@ void print_help2(void) {
" (the beam direction is defined locally through the node order:\n"
" i.e. mirror: node1 -> node2, beam splitter: node1 -> node3)\n"
" beam parameter z<0 when waist position is down beam\n"
" ** mismatches [limit] [n]: `n' bit coded word, for mismatch output options.\n"
" `limit' [0 < limit < 1] Lower mismatch limit for display cut off\n"
" mismatches 1: Ignore low R mirrors/bs\n"
" mismatches 2: Ignore low T mirrors/bs\n"
" mismatches 4: Display average of x and y beam parameters\n"
" mismatches 8: Display mismatch output each step\n"
" ** frequency n: `n' bit coded word, produces the following output:\n"
" frequency 1: print all frequencies computed\n"
" frequency 2: print frequency coupling matrix for each modulator\n"
......
......@@ -1342,13 +1342,22 @@ void read_QF_mech_transfer_function(const char *command_string){
void read_mismatches_command(const char *command_string){
char command_name[MAX_TOKEN_LEN] = {0};
char limit[MAX_TOKEN_LEN] = {0};
char flag[MAX_TOKEN_LEN] = {0};
char rest[MAX_TOKEN_LEN] = {0};
int n = sscanf(command_string, "%s %s %[^\n]", command_name, flag, rest);
int n = sscanf(command_string, "%s %s %s %[^\n]", command_name, limit, flag, rest);
if(n > 1){
atod(flag, &inter.mismatch_lower);
atod(limit, &inter.mismatches_lower);
if (inter.mismatches_lower < 0 || inter.mismatches_lower > 1){
gerror("Line `%s':\nLimit must be between 0 and 1\n", command_string);
}
}
if(n > 2){
inter.mismatches_options = atoi(flag);
}
inter.mismatches = 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