Commit f8786df0 authored by Daniel Brown's avatar Daniel Brown
Browse files

Node_t now stores where the fields are located in the RHS vector. I did this...

Node_t now stores where the fields are located in the RHS vector. I did this as it seems more logical for the nodes to store the location of the fields as that is technically where the field exists, not in the components, which just determine the coupling.
parent e6af2477
......@@ -30,7 +30,7 @@ GREP = grep
KAT_CONFIG_H = kat_config.h
WARN_CFLAGS = -Wall # -pipe -Wextra -W
BASE_CFLAGS = $(WARN_CFLAGS) $(THREADS_CFLAGS) $(CFLAGS) -fopenmp
BASE_CFLAGS = $(WARN_CFLAGS) $(THREADS_CFLAGS) $(CFLAGS) -fopenmp
#OPTIM_CFLAGS = -O3 -ffast-math -fexpensive-optimizations -fomit-frame-pointer -funroll-loops -DNDEBUG
#FAST_CFLAGS = $(BASE_CFLAGS) $(OPTIM_CFLAGS)
FAST_CFLAGS = $(BASE_CFLAGS)
......
......@@ -210,7 +210,9 @@ struct node {
double *n; //!< refractive index of an attached space
bool q_is_set; //!< is Gaussian beam parameter set?
bool gnd_node; //!< is this node a GND_NODE?
int rhs_base_idx; // index where fields at this node are stored in matrix
// all-in ifo matrix variables
int rhs_idx_1; // index where field 1 at this node are stored in matrix
int rhs_idx_2; // index where field 2 at this node are stored in matrix
};
//! node type
......@@ -559,7 +561,6 @@ struct mirror {
char name[MAX_TOKEN_LEN]; //!< mirror name
// Full CCS matrix variables
int ccs_rhs_idx; // rhs vector starting index for all fields for this components
int ports;
};
......
......@@ -195,40 +195,62 @@ void build_ccs_matrix(matrix_ccs_vars_t *matrix){
matrix->pcol_head = NULL;
int fields_per_nodes = get_submatrix_num_fields(1);
// loop through the optical components and set their position in the
// CCS matrix.
int i;
for (i = 0; i < inter.num_mirrors; i++) {
mirror = &(inter.mirror_list[i]);
mirror->ccs_rhs_idx = ccs_rhs_idx; // set the starting index for all of
// the components fields
node1 = &inter.node_list[mirror->node1_index];
node2 = &inter.node_list[mirror->node2_index];
// ports are the number of inputs and outputs for the component
// couplings are the number of relations between the various ports
int ports = 4;
int nodes = 2;
int couplings = 0;
if (node1->gnd_node)
ports -= 2;
nodes -= 1;
else {
++inter.node_list[mirror->node1_index].connect;
// check if this node has been located in the rhs vector already...
if(node1->rhs_idx_1 < 0){
node1->rhs_idx_1 = ccs_rhs_idx;
ccs_rhs_idx += fields_per_nodes;
}
// ...and for the 2nd field...
if(node1->rhs_idx_2 < 0){
node1->rhs_idx_2 = ccs_rhs_idx;
ccs_rhs_idx += fields_per_nodes;
}
++inter.node_list[mirror->node1_index].connect; // mark node as connected
couplings += 1;
}
if (node2->gnd_node)
ports -= 2;
nodes -= 1;
else {
++inter.node_list[mirror->node2_index].connect;
// check if this node has been located in the rhs vector already...
if(node2->rhs_idx_1 < 0){
node2->rhs_idx_1 = ccs_rhs_idx;
ccs_rhs_idx += fields_per_nodes;
}
// ...and for the 2nd field...
if(node2->rhs_idx_2 < 0){
node2->rhs_idx_2 = ccs_rhs_idx;
ccs_rhs_idx += fields_per_nodes;
}
++inter.node_list[mirror->node2_index].connect; // mark node as connected
couplings += 1;
}
if (!node2->gnd_node && !node1->gnd_node)
couplings += 2;
if (ports == 0)
if (nodes == 0)
bug_error("Need to handle there not being any ports connected to component %s", mirror->name);
else {
// create new pseudo-column to hold information on the optic and
......@@ -243,13 +265,9 @@ void build_ccs_matrix(matrix_ccs_vars_t *matrix){
// store pseudo-column in linked list
add_pcol(matrix,p);
mirror->ccs_rhs_idx = ccs_rhs_idx;
// increase rhs index for next component to use
ccs_rhs_idx = get_submatrix_num_fields(ports);
// compute how many non-zeros this component will need
// coupling at ports modes for each frequency diagonal elements
nnz += couplings * num_fields_sqrd * inter.num_frequencies + get_submatrix_num_fields(ports);
nnz += couplings * num_fields_sqrd * inter.num_frequencies + get_submatrix_num_fields(nodes*2);
}
}
......@@ -278,11 +296,39 @@ void build_ccs_matrix(matrix_ccs_vars_t *matrix){
// there is no point computing the field at this node as nothing is read
// or put there and it doesn't link anything up...
if(!node1->gnd_node && !node1->connect && node1->io){
if(node1->rhs_idx_1 > 0)
bug_error("node1 shouldn't be located in rhs vector as it isn't connected");
else {
node1->rhs_idx_1 = ccs_rhs_idx;
ccs_rhs_idx += ccs_rhs_idx;
}
if(node1->rhs_idx_2 > 0)
bug_error("node1 shouldn't be located in rhs vector as it isn't connected");
else {
node1->rhs_idx_2 = ccs_rhs_idx;
ccs_rhs_idx += ccs_rhs_idx;
}
space->ccs_rhs_idx = ccs_rhs_idx;
ports += 2;
}
if(!node2->gnd_node && !node2->connect && node2->io){
if(node2->rhs_idx_1 > 0)
bug_error("node1 shouldn't be located in rhs vector as it isn't connected");
else {
node2->rhs_idx_1 = ccs_rhs_idx;
ccs_rhs_idx += ccs_rhs_idx;
}
if(node2->rhs_idx_2 > 0)
bug_error("node1 shouldn't be located in rhs vector as it isn't connected");
else {
node2->rhs_idx_2 = ccs_rhs_idx;
ccs_rhs_idx += ccs_rhs_idx;
}
space->ccs_rhs_idx = ccs_rhs_idx;
ports += 2;
}
......@@ -303,7 +349,6 @@ void build_ccs_matrix(matrix_ccs_vars_t *matrix){
space->ports = ports;
ccs_rhs_idx += get_submatrix_num_fields(ports);
nnz += couplings * num_fields_sqrd * inter.num_frequencies + get_submatrix_num_fields(ports);
}
......
......@@ -716,6 +716,16 @@ int allocate_memory(long int *bytes, long int *bytes1, long int *bytes2) {
if (inter.node_list == NULL) {
return (32);
}
// initialise node variables. Need this for
// all-in ifo matrix building
int i;
for(i=0; i<mem.num_nodes; i++){
inter.node_list[i].rhs_idx_1 = -1;
inter.node_list[i].rhs_idx_2 = -1;
}
*bytes += (mem.num_nodes + 1) * sizeof (node_t);
}
......
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