From f582a8ff109c8774781e611a9b46bbbb136f68ac Mon Sep 17 00:00:00 2001 From: DSPOM Date: Mon, 16 May 2022 20:35:13 +0200 Subject: [PATCH] feat: update to newest OSDI header --- src/osdi/osdi.h | 31 ++++++++++++++++++++----------- src/osdi/osdiload.c | 13 +++++++------ src/osdi/osdisetup.c | 39 +++++++++++++++++++++------------------ 3 files changed, 48 insertions(+), 35 deletions(-) diff --git a/src/osdi/osdi.h b/src/osdi/osdi.h index e7aaa4095..e923ef1ff 100644 --- a/src/osdi/osdi.h +++ b/src/osdi/osdi.h @@ -25,6 +25,11 @@ #define ACCESS_FLAG_SET 1 #define ACCESS_FLAG_INSTANCE 4 +#define JACOBIAN_ENTRY_RESIST_CONST 1 +#define JACOBIAN_ENTRY_REACT_CONST 2 +#define JACOBIAN_ENTRY_RESIST 4 +#define JACOBIAN_ENTRY_REACT 8 + #define CALC_RESIST_RESIDUAL 1 #define CALC_REACT_RESIDUAL 2 #define CALC_RESIST_JACOBIAN 4 @@ -74,11 +79,19 @@ typedef struct OsdiNodePair { uint32_t node_2; }OsdiNodePair; +typedef struct OsdiJacobianEntry { + OsdiNodePair nodes; + uint32_t react_ptr_off; + uint32_t flags; +}OsdiJacobianEntry; + typedef struct OsdiNode { char *name; - bool is_reactive; char *units; char *residual_units; + uint32_t resist_residual_off; + uint32_t react_residual_off; + bool is_flow; }OsdiNode; typedef struct OsdiParamOpvar { @@ -103,12 +116,11 @@ typedef struct OsdiDescriptor { OsdiNode *nodes; uint32_t num_jacobian_entries; - OsdiNodePair *jacobian_entries; - bool *const_jacobian_entries; + OsdiJacobianEntry *jacobian_entries; uint32_t num_collapsible; OsdiNodePair *collapsible; - size_t collapsed_offset; + uint32_t collapsed_offset; OsdiNoiseSource *noise_sources; uint32_t num_noise_src; @@ -118,14 +130,11 @@ typedef struct OsdiDescriptor { uint32_t num_opvars; OsdiParamOpvar *param_opvar; - size_t residual_resist_offset; - size_t residual_react_offset; - size_t node_mapping_offset; - size_t jacobian_ptr_resist_offset; - size_t jacobian_ptr_react_offset; + uint32_t node_mapping_offset; + uint32_t jacobian_ptr_resist_offset; - size_t instance_size; - size_t model_size; + uint32_t instance_size; + uint32_t model_size; void *(*access)(void *inst, void *model, uint32_t id, uint32_t flags); diff --git a/src/osdi/osdiload.c b/src/osdi/osdiload.c index 29694999e..c59af340e 100644 --- a/src/osdi/osdiload.c +++ b/src/osdi/osdiload.c @@ -136,17 +136,18 @@ extern int OSDIload(GENmodel *inModel, CKTcircuit *ckt) { uint32_t *node_mapping = (uint32_t *)(((char *)inst) + descr->node_mapping_offset); - double *residual_react = - (double *)(((char *)inst) + descr->residual_react_offset); - /* use numeric integration to obtain the remainer of the RHS*/ int state = gen_inst->GENstate; for (uint32_t i = 0; i < descr->num_nodes; i++) { - if (descr->nodes[i].is_reactive) { + if (descr->nodes[i].react_residual_off != UINT32_MAX) { + + double residual_react = *(( + double *)(((char *)inst) + descr->nodes[i].react_residual_off)); + /* store charges in state vector*/ - ckt->CKTstate0[state] = residual_react[i]; + ckt->CKTstate0[state] = residual_react; if (is_init_tran) { - ckt->CKTstate1[state] = residual_react[i]; + ckt->CKTstate1[state] = residual_react; } /* we only care about the numeric integration itself not ceq/geq diff --git a/src/osdi/osdisetup.c b/src/osdi/osdisetup.c index d796254db..f827cf941 100644 --- a/src/osdi/osdisetup.c +++ b/src/osdi/osdisetup.c @@ -26,7 +26,6 @@ static int handle_init_info(OsdiInitInfo info, const OsdiDescriptor *descr) { return (OK); } - for (uint32_t i = 0; i < info.num_errors; i++) { OsdiInitError *err = &info.errors[i]; switch (err->code) { @@ -90,19 +89,19 @@ static uint32_t collapse_nodes(const OsdiDescriptor *descr, void *inst, /* terminals created by the simulator cannot be collapsed */ if (node_mapping[from] < connected_terminals && - (to == descr->num_nodes || node_mapping[to] < connected_terminals || - node_mapping[to] == descr->num_nodes)) { + (to == UINT32_MAX || node_mapping[to] < connected_terminals || + node_mapping[to] == UINT32_MAX)) { continue; } /* ensure that to is always the smaller node */ - if (to != descr->num_nodes && node_mapping[from] < node_mapping[to]) { + if (to != UINT32_MAX && node_mapping[from] < node_mapping[to]) { uint32_t temp = from; from = to; to = temp; } from = node_mapping[from]; - if (to != descr->num_nodes) { + if (to != UINT32_MAX) { to = node_mapping[to]; } @@ -110,10 +109,8 @@ static uint32_t collapse_nodes(const OsdiDescriptor *descr, void *inst, for (uint32_t j = 0; j < descr->num_nodes; j++) { if (node_mapping[j] == from) { node_mapping[j] = to; - } else if (node_mapping[j] > from) { - if (node_mapping[j]!= num_nodes){ - node_mapping[j] -= 1; - } + } else if (node_mapping[j] > from && node_mapping[j] != UINT32_MAX) { + node_mapping[j] -= 1; } } num_nodes -= 1; @@ -128,7 +125,7 @@ static void write_node_mapping(const OsdiDescriptor *descr, void *inst, uint32_t *node_mapping = (uint32_t *)(((char *)inst) + descr->node_mapping_offset); for (uint32_t i = 0; i < descr->num_nodes; i++) { - if (node_mapping[i] == descr->num_nodes) { + if (node_mapping[i] == UINT32_MAX) { /* gnd node */ node_mapping[i] = 0; } else { @@ -145,12 +142,9 @@ static int init_matrix(SMPmatrix *matrix, const OsdiDescriptor *descr, double **jacobian_ptr_resist = (double **)(((char *)inst) + descr->jacobian_ptr_resist_offset); - double **jacobian_ptr_react = - (double **)(((char *)inst) + descr->jacobian_ptr_react_offset); - for (uint32_t i = 0; i < descr->num_jacobian_entries; i++) { - uint32_t equation = descr->jacobian_entries[i].node_1; - uint32_t unkown = descr->jacobian_entries[i].node_2; + uint32_t equation = descr->jacobian_entries[i].nodes.node_1; + uint32_t unkown = descr->jacobian_entries[i].nodes.node_2; equation = node_mapping[equation]; unkown = node_mapping[unkown]; double *ptr = SMPmakeElt(matrix, (int)equation, (int)unkown); @@ -159,8 +153,13 @@ static int init_matrix(SMPmatrix *matrix, const OsdiDescriptor *descr, return (E_NOMEM); } jacobian_ptr_resist[i] = ptr; + uint32_t react_off = descr->jacobian_entries[i].react_ptr_off; // complex number for ac analysis - jacobian_ptr_react[i] = ptr + 1; + if (react_off != UINT32_MAX) { + + double **jacobian_ptr_react = (double **)(((char *)inst) + react_off); + *jacobian_ptr_react = ptr + 1; + } } return (OK); } @@ -187,7 +186,7 @@ int OSDIsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, /* determine the number of states required by each instance */ int num_states = 0; for (uint32_t i = 0; i < descr->num_nodes; i++) { - if (descr->nodes[i].is_reactive) { + if (descr->nodes[i].react_residual_off != UINT32_MAX) { num_states += 2; } } @@ -252,7 +251,11 @@ int OSDIsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, /* create internal nodes as required */ for (uint32_t i = connected_terminals; i < num_nodes; i++) { // TODO handle currents correctly - error = CKTmkVolt(ckt, &tmp, gen_inst->GENname, descr->nodes[i].name); + if (descr->nodes[i].is_flow) { + error = CKTmkCur(ckt, &tmp, gen_inst->GENname, descr->nodes[i].name); + } else { + error = CKTmkVolt(ckt, &tmp, gen_inst->GENname, descr->nodes[i].name); + } if (error) return (error); node_ids[i] = (uint32_t)tmp->number;