1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
|
/*$Id: u_sim_data.cc 2016/03/23 al $ -*- C++ -*-
* Copyright (C) 2001 Albert Davis
* Author: Albert Davis <aldavis@gnu.org>
*
* This file is part of "Gnucap", the Gnu Circuit Analysis Package
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*------------------------------------------------------------------
* aux functions associated with the SIM class
*/
//testing=script 2015.01.28
#include "m_wave.h"
#include "e_node.h"
#include "u_nodemap.h"
#include "e_cardlist.h"
#include "u_status.h"
/*--------------------------------------------------------------------------*/
SIM_DATA::SIM_DATA()
:_time0(0.),
_freq(0.),
_temp_c(0.),
_damp(0.),
_dtmin(0.),
_genout(0.),
_bypass_ok(true),
_fulldamp(false),
_last_time(0.),
_freezetime(false),
_user_nodes(0),
_subckt_nodes(0),
_model_nodes(0),
_total_nodes(0),
_jomega(0.,0.),
_limiting(true),
_vmax(0.),
_vmin(0.),
_uic(false),
_inc_mode(tsNO),
//_mode(),
//_phase(),
_nm(NULL),
_i(NULL),
_v0(NULL),
_vt1(NULL),
_ac(NULL),
_nstat(NULL),
_vdc(NULL),
_aa(),
_lu(),
_acx(),
_eq(),
_loadq(),
_acceptq(),
_evalq1(),
_evalq2(),
_late_evalq(),
_evalq(NULL),
_evalq_uc(NULL),
_waves(NULL),
_has_op(s_NONE)
{
_evalq = &_evalq1;
_evalq_uc = &_evalq2;
std::fill_n(_iter, iCOUNT, 0);
}
/*--------------------------------------------------------------------------*/
SIM_DATA::~SIM_DATA()
{
if (_nm) {unreachable();
delete [] _nm;
_nm = NULL;
}else{
}
if (_i) {unreachable();
delete [] _i;
_i = NULL;
}else{
}
if (_v0) {unreachable();
delete [] _v0;
_v0 = NULL;
}else{
}
if (_vt1) {unreachable();
delete [] _vt1;
_vt1 = NULL;
}else{
}
if (_ac) {unreachable();
delete [] _ac;
_ac = NULL;
}else{
}
if (_nstat) {unreachable();
delete [] _nstat;
_nstat = NULL;
}else{
}
if (_vdc) {unreachable();
delete [] _vdc;
_vdc = NULL;
}else{
}
//assert(_eq.empty()); //not empty means an analysis ended with an unhandled event
// could be DC, could be tran with event time past the end
assert(_loadq.empty());
assert(_acceptq.empty());
assert(_evalq1.empty());
assert(_evalq2.empty());
assert(_late_evalq.empty());
assert(_evalq);
assert(_evalq_uc);
_evalq = NULL;
_evalq_uc = NULL;
if (_waves) {
delete [] _waves;
_waves = NULL;
}else{
}
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
void SIM_DATA::set_limit()
{
for (int ii = 1; ii <= _total_nodes; ++ii) {
set_limit(_v0[ii]);
}
}
/*--------------------------------------------------------------------------*/
void SIM_DATA::set_limit(double v)
{
if (v+.4 > _vmax) {
_vmax = v+.5;
error(bTRACE, "new max = %g, new limit = %g\n", v, _vmax);
}
if (v-.4 < _vmin) {
_vmin = v-.5;
error(bTRACE, "new min = %g, new limit = %g\n", v, _vmin);
}
}
/*--------------------------------------------------------------------------*/
void SIM_DATA::clear_limit()
{
_vmax = OPT::vmax;
_vmin = OPT::vmin;
}
/*--------------------------------------------------------------------------*/
void SIM_DATA::keep_voltages()
{
if (!_freezetime) {
for (int ii = 1; ii <= _total_nodes; ++ii) {
_vdc[ii] = _v0[ii];
}
_last_time = (_time0 > 0.) ? _time0 : 0.;
}else{untested();
//BUG// probably incorrect
}
}
/*--------------------------------------------------------------------------*/
void SIM_DATA::restore_voltages()
{
for (int ii = 1; ii <= _total_nodes; ++ii) {
_vt1[ii] = _v0[ii] = _vdc[ii];
}
}
/*--------------------------------------------------------------------------*/
void SIM_DATA::zero_voltages()
{
for (int ii = 1; ii <= _total_nodes; ++ii) {
_vt1[ii] = _v0[ii] = _vdc[ii] = _i[ii] = 0.;
}
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* map__nodes: map intermediate node number to internal node number.
* Ideally, this function would find some near-optimal order
* and squash out gaps.
*/
void SIM_DATA::map__nodes()
{
_nm = new int[_total_nodes+1];
::status.order.reset().start();
switch (OPT::order) {
default: unreachable();
error(bWARNING, "invalid order spec: %d\n", OPT::order);
// fall through
case oAUTO: order_auto(); break;
case oREVERSE: order_reverse(); break;
case oFORWARD: order_forward(); break;
}
::status.order.stop();
}
/*--------------------------------------------------------------------------*/
/* order_reverse: force ordering to reverse of user ordering
* subcircuits at beginning, results on border at the bottom
*/
void SIM_DATA::order_reverse()
{
_nm[0] = 0;
for (int node = 1; node <= _total_nodes; ++node) {
_nm[node] = _total_nodes - node + 1;
}
}
/*--------------------------------------------------------------------------*/
/* order_forward: use user ordering, with subcircuits added to end
* results in border at the top (worst possible if lots of subcircuits)
*/
void SIM_DATA::order_forward()
{
_nm[0] = 0;
for (int node = 1; node <= _total_nodes; ++node) {
_nm[node] = node;
}
}
/*--------------------------------------------------------------------------*/
/* order_auto: full automatic ordering
* reverse, for now
*/
void SIM_DATA::order_auto()
{
_nm[0] = 0;
for (int node = 1; node <= _total_nodes; ++node) {
_nm[node] = _total_nodes - node + 1;
}
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* init: allocate, set up, etc ... for any type of simulation
* also called by status and probe for access to internals and subckts
*/
void SIM_DATA::init(CARD_LIST* scope)
{
assert(scope);
if (scope == &CARD_LIST::card_list) {
}else{itested();
}
if (is_first_expand()) {
uninit();
init_node_count(scope->nodes()->how_many(), 0, 0);
scope->expand();
map__nodes();
scope->map_nodes();
alloc_hold_vectors();
_aa.reinit(_total_nodes);
_lu.reinit(_total_nodes);
_acx.reinit(_total_nodes);
scope->tr_iwant_matrix();
scope->ac_iwant_matrix();
_last_time = 0;
}else{
scope->precalc_first();
}
}
/*--------------------------------------------------------------------------*/
/* alloc_hold_vectors:
* allocate space to hold data between commands.
* for restart, convergence assistance, bias for AC, post-processing, etc.
* must be done BEFORE deciding what array elements to allocate,
* but after mapping
* if they already exist, leave them alone to save data
*/
void SIM_DATA::alloc_hold_vectors()
{
assert(is_first_expand());
assert(!_nstat);
_nstat = new LOGIC_NODE[_total_nodes+1];
for (int ii=0; ii <= _total_nodes; ++ii) {
_nstat[_nm[ii]].set_user_number(ii);
}
assert(!_vdc);
_vdc = new double[_total_nodes+1];
std::fill_n(_vdc, _total_nodes+1, 0);
assert(_nstat);
assert(_vdc);
}
/*--------------------------------------------------------------------------*/
/* alloc_vectors:
* these are new with every run and are discarded after the run.
*/
void SIM_DATA::alloc_vectors()
{
assert(_evalq1.empty());
assert(_evalq2.empty());
assert(_evalq != _evalq_uc);
assert(!_ac);
assert(!_i);
assert(!_v0);
assert(!_vt1);
_ac = new COMPLEX[_total_nodes+1];
_i = new double[_total_nodes+1];
_v0 = new double[_total_nodes+1];
_vt1 = new double[_total_nodes+1];
std::fill_n(_ac, _total_nodes+1, 0);
std::fill_n(_i, _total_nodes+1, 0);
std::fill_n(_v0, _total_nodes+1, 0);
std::fill_n(_vt1,_total_nodes+1, 0);
}
/*--------------------------------------------------------------------------*/
void SIM_DATA::unalloc_vectors()
{
_evalq1.clear();
_evalq2.clear();
delete [] _i;
_i = NULL;
delete [] _v0;
_v0 = NULL;
delete [] _vt1;
_vt1 = NULL;
delete [] _ac;
_ac = NULL;
}
/*--------------------------------------------------------------------------*/
/* uninit: undo all the allocation associated with any simulation
* called when the circuit changes after a run, so it needs a restart
* may be called multiple times without damage to make sure it is clean
*/
void SIM_DATA::uninit()
{
if (_vdc) {
_acx.reinit(0);
_lu.reinit(0);
_aa.reinit(0);
delete [] _vdc;
_vdc = NULL;
delete [] _nstat;
_nstat = NULL;
delete [] _nm;
_nm = NULL;
}else{
assert(_acx.size() == 0);
assert(_lu.size() == 0);
assert(_aa.size() == 0);
assert(!_nstat);
assert(!_nm);
}
_has_op = s_NONE;
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// vim:ts=8:sw=2:noet:
|