Commit a96c52cb authored by Daniel Brown's avatar Daniel Brown

Working on TF refractive index fixes

parent c665cb31
*.err
*.log
kat.exe
kat
src/cuba.h
src/kat_config.h
# Stop extra files
test.*
test_plot.*
.DS_store
\ No newline at end of file
......@@ -1373,14 +1373,17 @@ typedef struct signal {
double amplitude; //!< signal amplitude
transfer_func_t *tf; // Transfer function to scale signal by
complex_t *a1; //!< ???
complex_t *a2; //!< ???
complex_t *a3; //!< ???
complex_t *a4; //!< ???
complex_t *ao1; //!< ???
complex_t *ao2; //!< ???
complex_t *ao3; //!< ???
complex_t *ao4; //!< ???
// These temporary arrays are used for signal calculations.
// They store separately the transmitted and reflected fields going
// to a particular port of a mirror or bs.
complex_t *at1; /** Field transmitted through to node 1 */
complex_t *at2; /** Field transmitted through to node 2 */
complex_t *at3; /** Field transmitted through to node 3 */
complex_t *at4; /** Field transmitted through to node 4 */
complex_t *ar1; /** Field reflected through to node 1 */
complex_t *ar2; /** Field reflected through to node 2 */
complex_t *ar3; /** Field reflected through to node 3 */
complex_t *ar4; /** Field reflected through to node 4 */
int surface_mode_index; /** If signal is driving a surface mode, then this stores the index of that surface motion */
} signal_t;
......
......@@ -954,10 +954,10 @@ void fill_bs_signal_rhs(signal_t *signal, ifo_matrix_vars_t* M_car, ifo_matrix_v
for(i=0; i < inter.num_fields; i++){
get_tem_modes_from_field_index(&ni, &mi, i);
signal->ao1[i] = complex_0;
signal->ao2[i] = complex_0;
signal->ao3[i] = complex_0;
signal->ao4[i] = complex_0;
signal->ar1[i] = complex_0;
signal->ar2[i] = complex_0;
signal->ar3[i] = complex_0;
signal->ar4[i] = complex_0;
for(j=0; j < inter.num_fields; j++){
get_tem_modes_from_field_index(&nj, &mj, j);
......@@ -965,24 +965,24 @@ void fill_bs_signal_rhs(signal_t *signal, ifo_matrix_vars_t* M_car, ifo_matrix_v
if(!node1->gnd_node && !node2->gnd_node) {
if(include_mode_coupling(&bs->a_cplng_21, ni,nj,mi,mj)){
cidx = M_car->node_rhs_idx_1[node2->list_index] + get_node_rhs_idx(1, f_sig->carrier->index, j, M_car->num_frequencies);
signal->ao1[i] = z_pl_z(signal->ao1[i], z_by_z(*bs->a21f[f_sig->carrier->index][f_sig->carrier->index][j][i], crhs[cidx]));
signal->ar1[i] = z_pl_z(signal->ar1[i], z_by_z(*bs->a21f[f_sig->carrier->index][f_sig->carrier->index][j][i], crhs[cidx]));
}
if(include_mode_coupling(&bs->a_cplng_12, ni,nj,mi,mj)){
cidx = M_car->node_rhs_idx_1[node1->list_index] + get_node_rhs_idx(1, f_sig->carrier->index, j, M_car->num_frequencies);
signal->ao2[i] = z_pl_z(signal->ao2[i], z_by_z(*bs->a12f[f_sig->carrier->index][f_sig->carrier->index][j][i], crhs[cidx]));
signal->ar2[i] = z_pl_z(signal->ar2[i], z_by_z(*bs->a12f[f_sig->carrier->index][f_sig->carrier->index][j][i], crhs[cidx]));
}
}
if(!node3->gnd_node && !node4->gnd_node) {
if(include_mode_coupling(&bs->a_cplng_43, ni,nj,mi,mj)){
cidx = M_car->node_rhs_idx_1[node4->list_index] + get_node_rhs_idx(1, f_sig->carrier->index, j, M_car->num_frequencies);
signal->ao3[i] = z_pl_z(signal->ao3[i], z_by_z(*bs->a43f[f_sig->carrier->index][f_sig->carrier->index][j][i], crhs[cidx]));
signal->ar3[i] = z_pl_z(signal->ar3[i], z_by_z(*bs->a43f[f_sig->carrier->index][f_sig->carrier->index][j][i], crhs[cidx]));
}
if(include_mode_coupling(&bs->a_cplng_34, ni,nj,mi,mj)){
cidx = M_car->node_rhs_idx_1[node3->list_index] + get_node_rhs_idx(1, f_sig->carrier->index, j, M_car->num_frequencies);
signal->ao4[i] = z_pl_z(signal->ao4[i], z_by_z(*bs->a34f[f_sig->carrier->index][f_sig->carrier->index][j][i], crhs[cidx]));
signal->ar4[i] = z_pl_z(signal->ar4[i], z_by_z(*bs->a34f[f_sig->carrier->index][f_sig->carrier->index][j][i], crhs[cidx]));
}
}
}
......@@ -1005,25 +1005,25 @@ void fill_bs_signal_rhs(signal_t *signal, ifo_matrix_vars_t* M_car, ifo_matrix_v
if (tn && signal->type == SIG_X) {
field = get_field_index_from_tem(tn - 1, tm);
if(!node1->gnd_node && !node2->gnd_node){
a12 = z_by_x(z_by_z(signal->ao2[field], cconj(txs2)), sqrt(tn));
a21 = z_by_x(z_by_z(signal->ao1[field], cconj(txs1)), sqrt(tn));
a12 = z_by_x(z_by_z(signal->ar2[field], cconj(txs2)), sqrt(tn));
a21 = z_by_x(z_by_z(signal->ar1[field], cconj(txs1)), sqrt(tn));
}
if(!node3->gnd_node && !node4->gnd_node){
a34 = z_by_x(z_by_z(signal->ao4[field], cconj(txs4)), sqrt(tn));
a43 = z_by_x(z_by_z(signal->ao3[field], cconj(txs3)), sqrt(tn));
a34 = z_by_x(z_by_z(signal->ar4[field], cconj(txs4)), sqrt(tn));
a43 = z_by_x(z_by_z(signal->ar3[field], cconj(txs3)), sqrt(tn));
}
} else if (tm && signal->type == SIG_Y) {
field = get_field_index_from_tem(tn, tm - 1);
if(!node1->gnd_node && !node2->gnd_node){
a12 = z_by_x(z_by_z(signal->ao2[field], cconj(txs2)), sqrt(tm));
a21 = z_by_x(z_by_z(signal->ao1[field], cconj(txs1)), sqrt(tm));
a12 = z_by_x(z_by_z(signal->ar2[field], cconj(txs2)), sqrt(tm));
a21 = z_by_x(z_by_z(signal->ar1[field], cconj(txs1)), sqrt(tm));
}
if(!node3->gnd_node && !node4->gnd_node){
a34 = z_by_x(z_by_z(signal->ao4[field], cconj(txs4)), sqrt(tm));
a43 = z_by_x(z_by_z(signal->ao3[field], cconj(txs3)), sqrt(tm));
a34 = z_by_x(z_by_z(signal->ar4[field], cconj(txs4)), sqrt(tm));
a43 = z_by_x(z_by_z(signal->ar3[field], cconj(txs3)), sqrt(tm));
}
}
......@@ -1036,13 +1036,13 @@ void fill_bs_signal_rhs(signal_t *signal, ifo_matrix_vars_t* M_car, ifo_matrix_v
field = get_field_index_from_tem(ttn, ttm);
if(!node1->gnd_node && !node2->gnd_node){
a12 = z_pl_z(a12,z_by_x(z_by_z(signal->ao2[field], txs2), -1.0 * sqrt(ttn)));
a21 = z_pl_z(a21,z_by_x(z_by_z(signal->ao1[field], txs1), -1.0 * sqrt(ttn)));
a12 = z_pl_z(a12,z_by_x(z_by_z(signal->ar2[field], txs2), -1.0 * sqrt(ttn)));
a21 = z_pl_z(a21,z_by_x(z_by_z(signal->ar1[field], txs1), -1.0 * sqrt(ttn)));
}
if(!node3->gnd_node && !node4->gnd_node){
a34 = z_pl_z(a34,z_by_x(z_by_z(signal->ao4[field], txs4), -1.0 * sqrt(ttn)));
a43 = z_pl_z(a43,z_by_x(z_by_z(signal->ao3[field], txs3), -1.0 * sqrt(ttn)));
a34 = z_pl_z(a34,z_by_x(z_by_z(signal->ar4[field], txs4), -1.0 * sqrt(ttn)));
a43 = z_pl_z(a43,z_by_x(z_by_z(signal->ar3[field], txs3), -1.0 * sqrt(ttn)));
}
} else {
ttn = tn;
......@@ -1051,13 +1051,13 @@ void fill_bs_signal_rhs(signal_t *signal, ifo_matrix_vars_t* M_car, ifo_matrix_v
field = get_field_index_from_tem(ttn, ttm);
if(!node1->gnd_node && !node2->gnd_node){
a12 = z_pl_z(a12,z_by_x(z_by_z(signal->ao2[field], txs2), -1.0 * sqrt(ttm)));
a21 = z_pl_z(a21,z_by_x(z_by_z(signal->ao1[field], txs1), -1.0 * sqrt(ttm)));
a12 = z_pl_z(a12,z_by_x(z_by_z(signal->ar2[field], txs2), -1.0 * sqrt(ttm)));
a21 = z_pl_z(a21,z_by_x(z_by_z(signal->ar1[field], txs1), -1.0 * sqrt(ttm)));
}
if(!node3->gnd_node && !node4->gnd_node){
a34 = z_pl_z(a34,z_by_x(z_by_z(signal->ao4[field], txs4), -1.0 * sqrt(ttm)));
a43 = z_pl_z(a43,z_by_x(z_by_z(signal->ao3[field], txs3), -1.0 * sqrt(ttm)));
a34 = z_pl_z(a34,z_by_x(z_by_z(signal->ar4[field], txs4), -1.0 * sqrt(ttm)));
a43 = z_pl_z(a43,z_by_x(z_by_z(signal->ar3[field], txs3), -1.0 * sqrt(ttm)));
}
}
}
......@@ -1384,15 +1384,29 @@ void fill_mirror_signal_rhs(signal_t *signal, ifo_matrix_vars_t* M_car, ifo_matr
ph2 = 180.0;
else
ph2 = 0.0;
double nr1 = 1.0, nr2 = 1.0;
if(node1->n) nr1 = *node1->n;
if(node2->n) nr2 = *node2->n;
for(f=0; f<M_sig->num_frequencies; f++){
frequency_t *f_sig = M_sig->frequencies[f];
double phase = f_sig->order * signal->phase; // amplitude modulated for alignment signals
double factor = signal->amplitude * EPSILON * 0.5; //Epsilon/2 for fsig
// reflection
double phase_r = f_sig->order * signal->phase; // amplitude modulated for alignment signals
double factor_r = signal->amplitude * EPSILON / 2; //Epsilon/2 for fsig
double factor_t = signal->amplitude * EPSILON / 4;
// i factor for transmission is provided in the matrix multiplication
// a12f and a21f later
double phase_t = f_sig->order * signal->phase;
complex_t q1, q2;
complex_t txs1 = complex_0, txs2 = complex_0;
// Compute coupling coefficients as in 4.6.2 Alignment transfer function
// in the manual
if(!node1->gnd_node){
if (signal->type == SIG_X) {
q1 = node1->qx;
......@@ -1430,22 +1444,25 @@ void fill_mirror_signal_rhs(signal_t *signal, ifo_matrix_vars_t* M_car, ifo_matr
txs1 = co(0, zmod(txs1));
txs2 = co(0, zmod(txs2));
// testing : ################################################################################
int cidx, sidx, car_field;
int i, j, field_index;
// Store RHS vectors for convenience
complex_t *crhs = (complex_t*)M_car->rhs_values;
complex_t *srhs = (complex_t*)M_sig->rhs_values;
int i,j,field_index;
// compute purely reflected carrier field, do this by taking the incoming beam and computing matrix multiplication
// with the reflection elements of the matrix. Store reflected field in memory already allocated for this in the
// signal structure
// compute purely reflected and transmitted carrier field, do this by
// taking the incoming beam and computing the matrix multiplication
// with the reflection and transmissiong elements of the matrix. Store reflected field in
// memory already allocated for this in the signal structure
// In here will be the r, it, tuning factors for the generated sidebands
int ni, mi, nj, mj;
for(i=0; i < inter.num_fields; i++){
signal->ao1[i] = complex_0;
signal->ao2[i] = complex_0;
signal->ar1[i] = complex_0;
signal->ar2[i] = complex_0;
signal->at1[i] = complex_0;
signal->at2[i] = complex_0;
get_tem_modes_from_field_index(&ni, &mi, i);
......@@ -1454,12 +1471,22 @@ void fill_mirror_signal_rhs(signal_t *signal, ifo_matrix_vars_t* M_car, ifo_matr
if(!node1->gnd_node && include_mode_coupling(&mirror->a_cplng_11, ni,nj,mi,mj)) {
cidx = M_car->node_rhs_idx_1[node1->list_index] + get_node_rhs_idx(1, f_sig->carrier->index, j, M_car->num_frequencies);
signal->ao1[i] = z_pl_z(signal->ao1[i], z_by_z(*mirror->a11f[f_sig->carrier->index][f_sig->carrier->index][j][i], crhs[cidx]));
signal->ar1[i] = z_pl_z(signal->ar1[i], z_by_z(*mirror->a11f[f_sig->carrier->index][f_sig->carrier->index][j][i], crhs[cidx]));
}
if(!node2->gnd_node && include_mode_coupling(&mirror->a_cplng_22, ni,nj,mi,mj)) {
cidx = M_car->node_rhs_idx_1[node2->list_index] + get_node_rhs_idx(2, f_sig->carrier->index, j, M_car->num_frequencies);
signal->ao2[i] = z_pl_z(signal->ao2[i], z_by_z(*mirror->a22f[f_sig->carrier->index][f_sig->carrier->index][j][i], crhs[cidx]));
signal->ar2[i] = z_pl_z(signal->ar2[i], z_by_z(*mirror->a22f[f_sig->carrier->index][f_sig->carrier->index][j][i], crhs[cidx]));
}
if(!node1->gnd_node && !node2->gnd_node && include_mode_coupling(&mirror->a_cplng_12, ni,nj,mi,mj)) {
cidx = M_car->node_rhs_idx_1[node2->list_index] + get_node_rhs_idx(1, f_sig->carrier->index, j, M_car->num_frequencies);
signal->at2[i] = z_pl_z(signal->at2[i], z_by_z(*mirror->a12f[f_sig->carrier->index][f_sig->carrier->index][j][i], crhs[cidx]));
}
if(!node1->gnd_node && !node2->gnd_node && include_mode_coupling(&mirror->a_cplng_21, ni,nj,mi,mj)) {
cidx = M_car->node_rhs_idx_1[node2->list_index] + get_node_rhs_idx(2, f_sig->carrier->index, j, M_car->num_frequencies);
signal->at1[i] = z_pl_z(signal->at1[i], z_by_z(*mirror->a21f[f_sig->carrier->index][f_sig->carrier->index][j][i], crhs[cidx]));
}
}
}
......@@ -1467,13 +1494,17 @@ void fill_mirror_signal_rhs(signal_t *signal, ifo_matrix_vars_t* M_car, ifo_matr
for (field_index = 0; field_index < inter.num_fields; field_index++) {
complex_t a11 = complex_0;
complex_t a22 = complex_0;
complex_t a12 = complex_0;
complex_t a21 = complex_0;
int tn, tm;
double turn;
get_tem_modes_from_field_index(&tn, &tm, field_index);
//turn = turnit(tn);
// ddb - I don't think we are using turn it here initially as we take the
// outgoing field, which is already turned.
// outgoing field, which is already turned. The turning of the carrier
// field is done in the carrier coupling coefficients
turn = 1.0;
//TODO: test and the finalize the above !
......@@ -1482,38 +1513,66 @@ void fill_mirror_signal_rhs(signal_t *signal, ifo_matrix_vars_t* M_car, ifo_matr
if (tn && signal->type == SIG_X) {
car_field = get_field_index_from_tem(tn - 1, tm);
if(!node1->gnd_node) a11 = z_by_x(z_by_z(signal->ao1[car_field], cconj(txs1)), 1.0 * sqrt(tn));
if(!node2->gnd_node) a22 = z_by_x(z_by_z(signal->ao2[car_field], cconj(txs2)), 1.0 * sqrt(tn));
if(!node1->gnd_node) a11 = z_by_x(z_by_z(signal->ar1[car_field], cconj(txs1)), 1.0 * sqrt(tn));
if(!node2->gnd_node) a22 = z_by_x(z_by_z(signal->ar2[car_field], cconj(txs2)), 1.0 * sqrt(tn));
if(!node1->gnd_node && !node2->gnd_node) {
a12 = z_by_x(z_by_z(signal->at2[car_field], cconj(txs2)), 1.0 * sqrt(tn));
a21 = z_by_x(z_by_z(signal->at1[car_field], cconj(txs1)), 1.0 * sqrt(tn));
}
} else if (tm && signal->type == SIG_Y) {
car_field = get_field_index_from_tem(tn, tm - 1);
if(!node1->gnd_node) a11 = z_by_x(z_by_z(signal->ao1[car_field], cconj(txs1)), 1.0 * sqrt(tm));
if(!node2->gnd_node) a22 = z_by_x(z_by_z(signal->ao2[car_field], cconj(txs2)), 1.0 * sqrt(tm));
if(!node1->gnd_node) a11 = z_by_x(z_by_z(signal->ar1[car_field], cconj(txs1)), 1.0 * sqrt(tm));
if(!node2->gnd_node) a22 = z_by_x(z_by_z(signal->ar2[car_field], cconj(txs2)), 1.0 * sqrt(tm));
if(!node1->gnd_node && !node2->gnd_node) {
a12 = z_by_x(z_by_z(signal->at2[car_field], cconj(txs2)), 1.0 * sqrt(tm));
a21 = z_by_x(z_by_z(signal->at1[car_field], cconj(txs1)), 1.0 * sqrt(tm));
}
}
if (tn + tm < inter.tem) {
if (signal->type == SIG_X) {
car_field = get_field_index_from_tem(tn + 1, tm);
if(!node1->gnd_node) a11 = z_pl_z(a11, z_by_x(z_by_z(signal->ao1[car_field], txs1), -1.0 * sqrt(tn + 1)));
if(!node2->gnd_node) a22 = z_pl_z(a22, z_by_x(z_by_z(signal->ao2[car_field], txs2), -1.0 * sqrt(tn + 1)));
if(!node1->gnd_node) a11 = z_pl_z(a11, z_by_x(z_by_z(signal->ar1[car_field], txs1), -1.0 * sqrt(tn + 1)));
if(!node2->gnd_node) a22 = z_pl_z(a22, z_by_x(z_by_z(signal->ar2[car_field], txs2), -1.0 * sqrt(tn + 1)));
if(!node1->gnd_node && !node2->gnd_node) {
a12 = z_pl_z(a12, z_by_x(z_by_z(signal->at2[car_field], txs2), -1.0 * sqrt(tn + 1)));
a21 = z_pl_z(a21, z_by_x(z_by_z(signal->at1[car_field], txs1), -1.0 * sqrt(tn + 1)));
}
} else {
car_field = get_field_index_from_tem(tn, tm + 1);
if(!node1->gnd_node) a11 = z_pl_z(a11, z_by_x( z_by_z(signal->ao1[car_field], txs1), -1.0 * sqrt(tm + 1)));
if(!node2->gnd_node) a22 = z_pl_z(a22, z_by_x( z_by_z(signal->ao2[car_field], txs2), -1.0 * sqrt(tm + 1)));
if(!node1->gnd_node) a11 = z_pl_z(a11, z_by_x( z_by_z(signal->ar1[car_field], txs1), -1.0 * sqrt(tm + 1)));
if(!node2->gnd_node) a22 = z_pl_z(a22, z_by_x( z_by_z(signal->ar2[car_field], txs2), -1.0 * sqrt(tm + 1)));
if(!node1->gnd_node && !node2->gnd_node) {
a12 = z_pl_z(a12, z_by_x(z_by_z(signal->at2[car_field], txs2), -1.0 * sqrt(tm + 1)));
a21 = z_pl_z(a21, z_by_x(z_by_z(signal->at1[car_field], txs1), -1.0 * sqrt(tm + 1)));
}
}
}
if (!node1->gnd_node) {
sidx = M_sig->node_rhs_idx_1[node1->list_index] + get_node_rhs_idx(2, f, field_index, M_sig->num_frequencies);
srhs[sidx] = z_by_xph(a11, turn * factor, phase);
srhs[sidx] = z_by_xph(a11, nr1 * turn * factor_r, phase_r);
if (!node2->gnd_node) {
z_inc_z(&srhs[sidx], z_by_xph(a21, (nr2-nr1)*factor_t, phase_t));
}
// check if we need to conjugate the value for the lower sideband
if(f_sig->order == -1) srhs[sidx].im *= -1;
}
if (!node2->gnd_node) {
sidx = M_sig->node_rhs_idx_1[node2->list_index] + get_node_rhs_idx(1, f, field_index, M_sig->num_frequencies);
srhs[sidx] = z_by_xph(a22, turn * factor, phase + ph2);
srhs[sidx] = z_by_xph(a22, nr2 * turn * factor_r, phase_r + ph2);
if (!node1->gnd_node) {
z_inc_z(&srhs[sidx], z_by_xph(a12, (nr2-nr1)*factor_t, phase_t));
}
// check if we need to conjugate the value for the lower sideband
if(f_sig->order == -1) srhs[sidx].im *= -1;
}
......
......@@ -2440,25 +2440,25 @@ int allocate_memory_for_signal_list(long int *bytes) {
signal_t *sig = &inter.signal_list[i];
sig->comp_index = i;
inter.signal_list[i].a1 = (complex_t *) calloc(mem.num_fields + 1, sizeof (complex_t));
inter.signal_list[i].a2 = (complex_t *) calloc(mem.num_fields + 1, sizeof (complex_t));
inter.signal_list[i].a3 = (complex_t *) calloc(mem.num_fields + 1, sizeof (complex_t));
inter.signal_list[i].a4 = (complex_t *) calloc(mem.num_fields + 1, sizeof (complex_t));
inter.signal_list[i].ao1 = (complex_t *) calloc(mem.num_fields + 1, sizeof (complex_t));
inter.signal_list[i].ao2 = (complex_t *) calloc(mem.num_fields + 1, sizeof (complex_t));
inter.signal_list[i].ao3 = (complex_t *) calloc(mem.num_fields + 1, sizeof (complex_t));
inter.signal_list[i].ao4 = (complex_t *) calloc(mem.num_fields + 1, sizeof (complex_t));
if (inter.signal_list[i].a1 == NULL ||
inter.signal_list[i].a2 == NULL ||
inter.signal_list[i].a3 == NULL ||
inter.signal_list[i].a4 == NULL ||
inter.signal_list[i].ao1 == NULL ||
inter.signal_list[i].ao2 == NULL ||
inter.signal_list[i].ao3 == NULL ||
inter.signal_list[i].ao4 == NULL) {
inter.signal_list[i].at1 = (complex_t *) calloc(mem.num_fields + 1, sizeof (complex_t));
inter.signal_list[i].at2 = (complex_t *) calloc(mem.num_fields + 1, sizeof (complex_t));
inter.signal_list[i].at3 = (complex_t *) calloc(mem.num_fields + 1, sizeof (complex_t));
inter.signal_list[i].at4 = (complex_t *) calloc(mem.num_fields + 1, sizeof (complex_t));
inter.signal_list[i].ar1 = (complex_t *) calloc(mem.num_fields + 1, sizeof (complex_t));
inter.signal_list[i].ar2 = (complex_t *) calloc(mem.num_fields + 1, sizeof (complex_t));
inter.signal_list[i].ar3 = (complex_t *) calloc(mem.num_fields + 1, sizeof (complex_t));
inter.signal_list[i].ar4 = (complex_t *) calloc(mem.num_fields + 1, sizeof (complex_t));
if (inter.signal_list[i].at1 == NULL ||
inter.signal_list[i].at2 == NULL ||
inter.signal_list[i].at3 == NULL ||
inter.signal_list[i].at4 == NULL ||
inter.signal_list[i].ar1 == NULL ||
inter.signal_list[i].ar2 == NULL ||
inter.signal_list[i].ar3 == NULL ||
inter.signal_list[i].ar4 == NULL) {
return (20);
}
......
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