Commit 17d3eb2d authored by Daniel Brown's avatar Daniel Brown
Browse files

starting functions for creating all-in interferometer matrix

parent 3e8e6c83
......@@ -69,8 +69,9 @@ KAT_SOURCES = kat.c \
kat_knm_bs.c \
kat_knm_int.c \
kat_thermal.c \
kat_knm_aperture.c
kat_knm_aperture.c \
kat_matrix_ccs.c
# the kat-specific objects
KAT_OBJECTS = $(KAT_SOURCES:.c=.o)
......
......@@ -55,6 +55,8 @@
#include "kat_spa.h"
#include "klu.h"
#include "kat_klu.h"
#include "kat_matrix_ccs.h"
#ifdef SERVERMODE
#include "kat_server.h"
#endif
......@@ -79,6 +81,9 @@ klu_l_symbolic *Symbolic;
klu_l_numeric *Numeric;
klu_l_common Common;
matrix_ccs_vars_t inter_matrix_ccs;
matrix_ccs_vars_t quant_matrix_ccs;
time_t now; //!< Current time
char mydate[12] = {0}; //!< Date as at time of compilation
......
......@@ -1710,7 +1710,7 @@ typedef struct sparse_var sparse_var_t;
//! variables for KLU sparse routines
struct matrix_ccs {
struct klu_sparse_var {
/* Adapted from the KLU user guide:
The matrix is described with four parameters:
nz=inter.num_nonzero: integer scaler, number of non-zero elements (a `non-zero'
......@@ -1754,7 +1754,7 @@ struct matrix_ccs {
};
//! variables for sparse routines
typedef struct matrix_ccs klu_sparse_var_t;
typedef struct klu_sparse_var klu_sparse_var_t;
//! collects all the index variables together to help bounds checking
......
......@@ -1221,7 +1221,7 @@ void data_point(void) {
double f = light_input->f0;
double f1 = f;
unsigned int tid_spa;
uint tid_spa;
tid_spa = startTimer("SPA_FILL");
fill_matrix(f1, STANDARD);
......
#include "kat.h"
#include "kat_klu.h"
#include "kat_inline.c"
#include "kat_spa.h"
#include "kat_check.h"
#include "kat_io.h"
#include "kat_aux.h"
#include "kat_matrix_ccs.h"
extern const complex_t complex_i;
extern const complex_t complex_1;
extern const complex_t complex_m1;
extern const complex_t complex_0;
//extern init_variables_t in;
extern interferometer_t inter;
extern options_t options;
extern memory_t mem;
void alloc_matrix_ccs(long *bytes, matrix_ccs_vars_t *matrix_ccs){
assert(bytes != NULL);
assert(num_fields >= 1);
assert(num_nodes >= 1);
assert(num_freqs >= 1);
// create the standard interferometer matrix
debug_msg("Allocating all-in interferometer matrix\n");
// Allocate vectors for storing matrix in CCS format for all nodes, frequencies
// and fields in one large matrix
// Each component sub-matrix will have the fields for each port, for each
// frequency for each field. Factor of 2 for real and imag part.
int NNZ = 2L * mem.num_nodes * mem.num_fields * mem.num_frequencies;
// allocate column pointers
int try_bytes = 0;
try_bytes = (inter.num_eqns + 1) * sizeof (int);
if ((matrix_ccs->col_ptr = (int *) malloc(try_bytes)) == NULL) {
gerror("Could not allocate CCS col_ptr");
} else
*bytes += try_bytes;
try_bytes = 2 * inter.num_eqns * sizeof (double);
// allocate ride-hand-side vector (again using double for complex values)
if ((matrix_ccs->rhs_values = (double *) malloc(try_bytes)) == NULL) {
gerror("Could not allocate CCS rhs_values");
} else
*bytes += try_bytes;
try_bytes = NNZ * sizeof (int);
// allocate ride-hand-side vector (again using double for complex values)
if ((matrix_ccs->row_idx = (int *) malloc(try_bytes)) == NULL) {
gerror("Could not allocate CCS row_idx");
} else
*bytes += try_bytes;
try_bytes = 2 * NNZ * sizeof (double);
// allocate ride-hand-side vector (again using double for complex values)
if ((matrix_ccs->values = (double *) malloc(try_bytes)) == NULL) {
gerror("Could not allocate CCS values");
} else
*bytes += try_bytes;
}
/*
* Each optical component sub-matrix contains all the frequencies, modes for each
* of the nodes for the component. This is a general index computation for a
* component of N-nodes. The layout is such that the modes are group together by
* frequency and then the frequencies are grouped by the node:
*
* [node 1][node 2]...[node N]
* | \___________
* | \
* | freqs at node 1 \ freqs at node 2
* [f=0][f=1]...[f=fN] [f=0][f=1]...[f=fN]
* | \________________
* | \
* | modes at node 1 for freq 0 \ modes at node 1 for freq fN
* [nm=0][nm=1]...[nm=num_fields] [nm=0][nm=1]...[nm=num_fields]
*
*
* The returned index for the requested field is local to the sub-matrix
* i.e. node=1,freq=0,field=0 = 0
*
* Thus the global position of the optical sub-matrix needs to be added to this
* index to get the actual position in the full matrix.
*
* mode index corresponds to those in mem.all_tem_HG
* freq index corresponds to those in
*/
void get_submatrix_field_index(int node, int frequency, int mode, int *idx){
}
/*
* This sets the position of all the components in the sparse matrix. Compoents
* occupy the diagonals i.e. optics fill in the diagonals, i.e.
*
* |O1 || a_O1 |
* | O2 || a_O2 |
* | O3 || a_O3 |
* | O4|| a_O4 |
*
* Each optic O is really a sub-matrix that relates the coupling at the component
* between all the fields, modes and frequencies. The vectors a_O are then the
* field amplitudes of each of the optics for each mode and frequency.
*
* The vector is setup such that the each
*
*
*
*
*
*/
void position_components(){
}
/*
* File: kat_matrix_ccs.h
* Author: Daniel
*
* Created on 12 August 2013, 10:33
*/
#ifndef KAT_MATRIX_CCS_H
#define KAT_MATRIX_CCS_H
typedef struct matrix_ccs_vars{
double *values; //!< sparse CCS matrix numerical values (length=2*inter.num_nonzero)
int *row_idx; //!< sparse CCS matrix row index (length=inter.num_nonzero)
int *col_ptr; //!< sparse CCS matrix column pointer (length=inter.num_eqns+1)
double *rhs_values; //!< ride-hand-side for sparse matrix (length=2*inter.num_eqns)
} matrix_ccs_vars_t;
void alloc_matrix_ccs(long *bytes, matrix_ccs_vars_t *matrix_ccs);
#endif /* KAT_MATRIX_CCS_H */
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