Commit e3ace5a1 authored by Daniel Brown's avatar Daniel Brown

fixing is var tuned checking

parent e1141681
......@@ -1451,7 +1451,11 @@ int set_k_mirror(int mirror_index) {
// Basically anything that has altered the map_merged.knm variable that also
// includes effects that are integrated instead of calculated analytically
if ((integrating > 0) || mirror->map_merged.knm_calculated) {
mirror_knm_matrix_mult(&(mirror->knm_map), &(mirror->knm_no_rgouy), &(mirror->knm_no_rgouy));
if(is_tuned(&mirror->map_amplitude, NULL, NULL, NULL)) {
mirror_knm_matrix_mult_scale(mirror->map_amplitude, &(mirror->knm_map), &(mirror->knm_no_rgouy), &(mirror->knm_no_rgouy));
} else {
mirror_knm_matrix_mult(&(mirror->knm_map), &(mirror->knm_no_rgouy), &(mirror->knm_no_rgouy));
}
}
if ((mirror->knm_flags & PRINT_COEFFS) && mirror->map_merged.save_knm_matrices) {
......
......@@ -725,8 +725,8 @@ int is_minimizer_tuned(void *var, void **rtn, int *type){
return 0;
*rtn = &inter.minimizer;
*type = MINIMIZER;
if(rtn)*rtn = &inter.minimizer;
if(type)*type = MINIMIZER;
return 1;
}
......@@ -743,21 +743,21 @@ int is_minimizer_tuned(void *var, void **rtn, int *type){
int is_xaxis_tuned(void *var, void **rtn, int *type){
if(var == inter.x1.xaxis){
*rtn = &inter.x1;
*type = X1;
if(rtn)*rtn = &inter.x1;
if(type)*type = X1;
return 1;
} else if(var == inter.x2.xaxis){
*rtn = &inter.x2;
*type = X2;
if(rtn)*rtn = &inter.x2;
if(type)*type = X2;
return 1;
} else if(var == inter.x3.xaxis){
*rtn = &inter.x3;
*type = X3;
if(rtn)*rtn = &inter.x3;
if(type)*type = X3;
return 1;
}
*type = -1;
*rtn = NULL;
if(type)*type = -1;
if(rtn)*rtn = NULL;
return 0;
}
......@@ -830,7 +830,7 @@ int is_put_tuned(void *var, void **put, int *type) {
*
* source: pointer to double value that the tuning value comes from
* rtn : is set to a pointer to the object that is tuning.
* type : is set to
* type : is the type of thing doing the tuning
*
* @return True or False
*/
......@@ -847,7 +847,7 @@ bool is_tuned(double *var, double **source, void **tuner, int *type){
if(!rtn){
if(is_xaxis_tuned(var, tuner, type)) {
axis_t *axis = *tuner;
*source = axis->xaxis;
if(source) *source = axis->xaxis;
rtn = true;
}
}
......@@ -855,7 +855,7 @@ bool is_tuned(double *var, double **source, void **tuner, int *type){
if(!rtn){
if(is_put_tuned(var, tuner, type)){
put_command_t *put = *tuner;
*source = put->source;
if(source) *source = put->source;
rtn = true;
}
}
......
......@@ -160,6 +160,74 @@ void mirror_knm_matrix_mult(mirror_knm_t* A, mirror_knm_t* B, mirror_knm_t *resu
}
}
void mirror_knm_matrix_mult_scale(double scale, mirror_knm_t* A, mirror_knm_t* B, mirror_knm_t *result) {
/**
* This function scales A and multiplies it with B. The scaling is unusual here
* as we interpolate between A and I, so that with zero scaling we just get B.
*
* This was implemented mainly to scale maps for lock dragging.
*
* Computes (A*scale + I*(scale-1)) * B and puts it into result.
*/
assert(result != NULL && A != NULL && B != NULL);
assert(result->k11 != NULL && A->k11 != NULL && B->k11 != NULL);
assert(result->k12 != NULL && A->k12 != NULL && B->k12 != NULL);
assert(result->k21 != NULL && A->k21 != NULL && B->k21 != NULL);
assert(result->k22 != NULL && A->k22 != NULL && B->k22 != NULL);
int num_fields = (int) (inter.tem + 1) * (inter.tem + 2) / 2;
int l, n, m;
mirror_knm_t *tmp;
// if A or B are just identity matrices then just copy them into result
if (A->IsIdentities) {
if (B != result)
mirror_knm_matrix_copy(B, result);
} else if (B->IsIdentities) {
if (A != result)
mirror_knm_matrix_copy(A, result);
} else {
// if result != A | B then no need to use a temporary matrix to store result
// just bung it in the result matrix
if ((result == A) || (result == B))
tmp = &mrtmap;
else
tmp = result;
for (n = 0; n < num_fields; n++) {
for (m = 0; m < num_fields; m++) {
// initialise to 0 here just incase some other data is there
tmp->k11[n][m] = complex_0;
tmp->k12[n][m] = complex_0;
tmp->k21[n][m] = complex_0;
tmp->k22[n][m] = complex_0;
if(n != m) {
for (l = 0; l < num_fields; l++) {
tmp->k11[n][m] = z_pl_z(tmp->k11[n][m], z_by_z(z_by_x(A->k11[n][l], scale), B->k11[l][m]));
tmp->k12[n][m] = z_pl_z(tmp->k12[n][m], z_by_z(z_by_x(A->k12[n][l], scale), B->k12[l][m]));
tmp->k21[n][m] = z_pl_z(tmp->k21[n][m], z_by_z(z_by_x(A->k21[n][l], scale), B->k21[l][m]));
tmp->k22[n][m] = z_pl_z(tmp->k22[n][m], z_by_z(z_by_x(A->k22[n][l], scale), B->k22[l][m]));
}
} else {
for (l = 0; l < num_fields; l++) {
tmp->k11[n][m] = z_pl_z(tmp->k11[n][m], z_by_z(z_pl_z(co(1-scale, 0), z_by_x(A->k11[n][l], scale)), B->k11[l][m]));
tmp->k12[n][m] = z_pl_z(tmp->k12[n][m], z_by_z(z_pl_z(co(1-scale, 0), z_by_x(A->k12[n][l], scale)), B->k12[l][m]));
tmp->k21[n][m] = z_pl_z(tmp->k21[n][m], z_by_z(z_pl_z(co(1-scale, 0), z_by_x(A->k21[n][l], scale)), B->k21[l][m]));
tmp->k22[n][m] = z_pl_z(tmp->k22[n][m], z_by_z(z_pl_z(co(1-scale, 0), z_by_x(A->k22[n][l], scale)), B->k22[l][m]));
}
}
}
}
if ((result == A) || (result == B))
mirror_knm_matrix_copy(&mrtmap, result);
}
}
// Should copy one matrix into another
void mirror_knm_matrix_copy(mirror_knm_t* src, mirror_knm_t* dest) {
......@@ -1274,7 +1342,6 @@ void compute_mirror_knm_integral(mirror_t *mirror, double nr1, double nr2, bitfl
recompute = recompute | (map->_nr2 != nr2);
recompute = recompute | (map->_angle != mirror->angle);
recompute = recompute | !eq(mirror->map_amplitude, map->map_amplitude);
recompute = recompute | !ceq(mirror->knm_q.qxt1_11, map->mirror_knm_q.qxt1_11);
recompute = recompute | !ceq(mirror->knm_q.qxt2_11, map->mirror_knm_q.qxt2_11);
recompute = recompute | !ceq(mirror->knm_q.qyt1_11, map->mirror_knm_q.qyt1_11);
......@@ -1312,7 +1379,7 @@ void compute_mirror_knm_integral(mirror_t *mirror, double nr1, double nr2, bitfl
recompute = recompute | (mirror->x_off != map->_x_off);
recompute = recompute | (mirror->y_off != map->_y_off);
if (mirror->knm_force_saved){
if (!mirror->map_merged.knm_calculated){
gerror("* Mirror %s is being forced to use saved knm values but no knm values have been loaded\n", mirror->name);
......
......@@ -65,6 +65,7 @@ void alloc_knm_accel_mirror_mem(long *bytes);
void calc_mirror_knm_surf_motions_map(mirror_t *m, double nr1, double nr2, complex_t qx1, complex_t qy1, complex_t qx2, complex_t qy2);
void calc_mirror_knm_surf_motions_rom(mirror_t *mirror, double nr1, double nr2, complex_t qx11, complex_t qy11, complex_t qx22, complex_t qy22, bitflag astigmatism);
void mirror_knm_matrix_mult_scale(double scale, mirror_knm_t* A, mirror_knm_t* B, mirror_knm_t *result);
void mirror_knm_matrix_copy(mirror_knm_t* src, mirror_knm_t* dest);
void mirror_knm_matrix_mult(mirror_knm_t* A, mirror_knm_t* B, mirror_knm_t *result);
void mirror_knm_alloc(mirror_knm_t* knm, long *bytes);
......
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