Commit cd6075d2 authored by Daniel Brown's avatar Daniel Brown

adding in q change check for ROM and fixing q changed flag for nodes

parent 2de5a0f3
......@@ -852,7 +852,8 @@ typedef struct mirror {
/** ROM maps are treated separately from usual maps as they cannot be
merged with normal ones. */
romhom_weights_t *map_rom;
mirror_knm_q_t prev_rom_q; /** previous q values used for knm q */
double angle; //!< angle of the mirror about the z axis
/** q values used internally for the integration routines*/
mirror_knm_q_t knm_q;
......
......@@ -1208,7 +1208,6 @@ int set_k_mirror(int mirror_index) {
break;
case 4:
if (mirror->map_rom) {
// ROMHOM
check_mirror_knm_mismatch_astig(mirror->knm_calc_flags, &mirror->knm_q, &mm, &astig);
......@@ -3033,11 +3032,11 @@ void set_k_all_components(bool rebuilding) {
node_t n1 = inter.node_list[mirror->node1_index];
node_t n2 = inter.node_list[mirror->node2_index];
//printf("mirror %s node %s changed %d\n",mirror->name, n1.name, n1.q_changed);
//printf("mirror %s node %s changed %d\n",mirror->name, n2.name, n2.q_changed);
if(((!n1.gnd_node) && (n1.q_changed))
|| ((!n2.gnd_node) && (n2.q_changed)))
//warn("mirror %s node %s changed %d\n",mirror->name, n1.name, n1.q_changed);
//warn("mirror %s node %s changed %d\n",mirror->name, n2.name, n2.q_changed);
if(((!n1.gnd_node) && (n1.q_changed)) ||
((!n2.gnd_node) && (n2.q_changed)))
mm = set_k_mirror(i);
}
......@@ -4313,7 +4312,6 @@ int trace_cavity(ABCD_t *Mlocal_x, ABCD_t *Mlocal_y,
*/
void trace_beam(int startnode) {
int j, component1_index, component2_index;
// sanity checks on input
// start node should be in the range: 0 <= startnode < inter.num_nodes
assert(startnode >= 0);
......@@ -5394,6 +5392,7 @@ void set_q(int node_index, int component_index, complex_t qx, complex_t qy) {
assert(node_index < inter.num_nodes);
// the component index should be >= 0
assert(component_index >= 0);
// and less than the total number of components in the interferometer
#ifndef NDEBUG
if (component_index >= inter.num_components) {
......@@ -5405,10 +5404,8 @@ void set_q(int node_index, int component_index, complex_t qx, complex_t qy) {
assert(component_index < inter.num_components);
node = &(inter.node_list[node_index]);
if ((!(node->q_is_set)) ||
(node->q_is_set && (!ceq(node->qx, qx) || !ceq(node->qy, qy)))) {
if ((!(node->q_is_set)) || (node->q_is_set && (!ceq(node->qx, qx) || !ceq(node->qy, qy)))) {
if (node->q_is_set) {
if (inter.trace & 4 || inter.trace & 32) {
message("q value already set at node %s, overwritten!\n",
......@@ -5426,11 +5423,12 @@ void set_q(int node_index, int component_index, complex_t qx, complex_t qy) {
if (inter.debug & 256) {
message("--- setting q for node %s\n", get_node_name(node_index));
}
node->q_changed = !ceq(qx, node->qx) || !ceq(qy, node->qy);
node->qx = qx;
node->qy = qy;
node->component_index = component_index;
node->q_is_set = true;
node->q_changed = true;
// now check whether a space is connected and set second
// q value if necessary
......@@ -5482,11 +5480,12 @@ void set_q(int node_index, int component_index, complex_t qx, complex_t qy) {
if (inter.trace & 32) {
message(" overwriting second q value at space %s\n", space.name);
}
node->q_changed = !ceq(qxt, node->qx) || !ceq(qyt, node->qy);
node->qx = qxt;
node->qy = qyt;
node->component_index = component1_index;
node->q_is_set = true;
node->q_changed = true;
if (inter.debug & 256) {
message(" 1 :qx %s, qy %s\n", complex_form(node->qx),
......@@ -5497,11 +5496,13 @@ void set_q(int node_index, int component_index, complex_t qx, complex_t qy) {
if (inter.trace & 32) {
message(" setting second q value at space %s\n", space.name);
}
node->q_changed = !ceq(qxt, node->qx) || !ceq(qyt, node->qy);
node->qx = qxt;
node->qy = qyt;
node->component_index = component1_index;
node->q_is_set = true;
/*
* if (inter.debug & 256)
* {
......@@ -5558,11 +5559,13 @@ void set_q(int node_index, int component_index, complex_t qx, complex_t qy) {
if (inter.trace & 32) {
message(" overwriting second q value at space %s\n", space.name);
}
node->q_changed = !ceq(qxt, node->qx) || !ceq(qyt, node->qy);
node->qx = qxt;
node->qy = qyt;
node->component_index = component2_index;
node->q_is_set = true;
if (inter.debug & 256) {
message(" 1 :qx %s, qy %s\n", complex_form(node->qx),
complex_form(node->qy));
......@@ -5572,11 +5575,13 @@ void set_q(int node_index, int component_index, complex_t qx, complex_t qy) {
if (inter.trace & 32) {
message(" setting second q value at space %s\n", space.name);
}
node->q_changed = !ceq(qxt, node->qx) || !ceq(qyt, node->qy);
node->qx = qxt;
node->qy = qyt;
node->component_index = component2_index;
node->q_is_set = true;
/*
* if (inter.debug & 256)
* {
......
......@@ -1629,7 +1629,7 @@ void data_point_new(){
case SIG_AMP:
sig_mod_phase = 0; // 0 for amplitude modulation
sig_factor *= 0.5; // energy conserving amplitude modulation uses
// m/4 rather than m/2
// m/4 rather than m/2
break;
case SIG_PHS:
......
......@@ -208,6 +208,27 @@ void mirror_knm_matrix_ident(mirror_knm_t* M) {
}
}
bool knm_q_cmp(mirror_knm_q_t *q1, mirror_knm_q_t *q2) {
if(!ceq(q1->qxt1_11, q2->qxt1_11)) return false;
if(!ceq(q1->qxt1_12, q2->qxt1_12)) return false;
if(!ceq(q1->qxt1_21, q2->qxt1_21)) return false;
if(!ceq(q1->qxt1_22, q2->qxt1_22)) return false;
if(!ceq(q1->qxt2_11, q2->qxt2_11)) return false;
if(!ceq(q1->qxt2_12, q2->qxt2_12)) return false;
if(!ceq(q1->qxt2_21, q2->qxt2_21)) return false;
if(!ceq(q1->qxt2_22, q2->qxt2_22)) return false;
if(!ceq(q1->qyt1_11, q2->qyt1_11)) return false;
if(!ceq(q1->qyt1_12, q2->qyt1_12)) return false;
if(!ceq(q1->qyt1_21, q2->qyt1_21)) return false;
if(!ceq(q1->qyt1_22, q2->qyt1_22)) return false;
if(!ceq(q1->qyt2_11, q2->qyt2_11)) return false;
if(!ceq(q1->qyt2_12, q2->qyt2_12)) return false;
if(!ceq(q1->qyt2_21, q2->qyt2_21)) return false;
if(!ceq(q1->qyt2_22, q2->qyt2_22)) return false;
return true;
}
/** q values passed to this should have been turned depending on the direction of
* incoming and outgoing beam
*/
......@@ -879,6 +900,12 @@ void compute_mirror_knm_romhom(mirror_t *mirror, double nr1, double nr2, int mis
return;
}
mirror_knm_q_t *kq = &(mirror->knm_q);
// If the q values used are the same then no need to recompute HOM
if(knm_q_cmp(kq, &(mirror->prev_rom_q)))
return;
romhom_weights_t *rom = mirror->map_rom;
mirror_knm_t *knm = &(mirror->knm_romhom);
......@@ -896,8 +923,6 @@ void compute_mirror_knm_romhom(mirror_t *mirror, double nr1, double nr2, int mis
get_tem_modes_from_field_index(&max_n, &max_m, inter.num_fields - 1);
max_m = max_n; // max m is no the m is also the max_n. e.g. we get n=1 m=2 for maxtem 2
mirror_knm_q_t *kq = &(mirror->knm_q);
if(!ceq(kq->qxt1_11, kq->qxt2_11) || !ceq(kq->qyt1_11, kq->qyt2_11)) {
warn("Mismatch on side 1 reflection at %s, can't compute coupling using ROM\n", mirror->name);
warn("1->1: qx = %s, qx' = %s\n", complex_form15(kq->qxt1_11), complex_form15(kq->qxt2_11));
......@@ -1013,13 +1038,19 @@ void compute_mirror_knm_romhom(mirror_t *mirror, double nr1, double nr2, int mis
}
// Disable transmission calculation as ROM maps are only for reflection currently
// if (CALC_MR_KNM(mirror,12)) {
// results[1] = do_romhom_int(rom, ws->u_xy, &ws->ux_cache_12, &ws->uy_cache_12, n1, m1, n2, m2, 1);
// }
//
// if (CALC_MR_KNM(mirror,21)) {
// results[2] = do_romhom_int(rom, ws->u_xy, &ws->ux_cache_21, &ws->uy_cache_21, n1, m1, n2, m2, 1);
// }
if (CALC_MR_KNM(mirror,12)) {
complex_t znm1c2 = z_by_zc(z_by_z(acc_12_nr1_1->acc_n->prefac[n1], acc_12_nr1_1->acc_m->prefac[m1]),
z_by_z(acc_12_nr2_2->acc_n->prefac[n2], acc_12_nr2_2->acc_m->prefac[m2]));
//results[1] = z_by_z(do_romhom_real_int(rom, ws->d_u_xy, &ws->ux_cache_12, &ws->uy_cache_12, n1, m1, n2, m2, 1), znm1c2);
}
if (CALC_MR_KNM(mirror,21)) {
complex_t znm2c1 = z_by_zc(z_by_z(acc_21_nr2_1->acc_n->prefac[n1], acc_21_nr2_1->acc_m->prefac[m1]),
z_by_z(acc_21_nr1_2->acc_n->prefac[n2], acc_21_nr1_2->acc_m->prefac[m2]));
//results[2] = z_by_z(do_romhom_real_int(rom, ws->d_u_xy, &ws->ux_cache_21, &ws->uy_cache_21, n1, m1, n2, m2, 1), znm2c1);
}
if (CALC_MR_KNM(mirror,22)) {
complex_t znm2c2 = z_by_zc(z_by_z(acc_22_nr2_1->acc_n->prefac[n1], acc_22_nr2_1->acc_m->prefac[m1]),
......@@ -1049,6 +1080,8 @@ void compute_mirror_knm_romhom(mirror_t *mirror, double nr1, double nr2, int mis
}
}
memcpy(&mirror->prev_rom_q, kq, sizeof(mirror_knm_q_t));
endTimer(timer);
}
......
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