[r577]: trunk / src / electronics / simulation / circuit.h  Maximize  Restore  History

Download this file

139 lines (113 with data), 3.7 kB

  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
/***************************************************************************
* Copyright (C) 2003-2005 by David Saxton *
* david@bluehaze.org *
* *
* 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 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef CIRCUIT_H
#define CIRCUIT_H
#include <vector>
#include <set>
#include <cassert>
#include "qstringlist.h"
#include "elementset.h"
class Pin;
class Element;
class ElementSet;
class LogicOut;
typedef std::set<Pin *> PinSet;
typedef std::set<Element*> ElementList;
typedef std::vector<LogicOut *> logicOutVec;
class LogicCacheNode
{
public:
LogicCacheNode();
~LogicCacheNode();
LogicCacheNode *addOrGetHigh();
LogicCacheNode *addOrGetLow();
QuickVector *getData() const;
void setData(const ElementSet *newData);
private:
LogicCacheNode *high;
LogicCacheNode *low;
QuickVector *data;
};
/**
Usage of this class (usually invoked from CircuitDocument):
(1) Add Wires, Pins and Elements to the class as appropriate
(2) Call init to initialize the simulation
(3) Control the simulation with step()
This class can be considered a bridge between the gui-tainted CircuitDocument - specific
to this implementation, and the pure untainted ElementSet. Please keep it that way.
@short Simulates a collection of components
@author David Saxton
*/
class Circuit
{
public:
Circuit();
~Circuit();
void addPin(Pin *node);
PinSet *getPins() { return &m_pinList; }
void addElement(Element *element);
bool containsNonLinear() const { return m_elementSet->containsNonLinear(); }
void init();
/**
* Called after everything else has been setup - before doNonLogic or
* doLogic are called for the first time. Preps the circuit.
*/
void initCache();
/**
* Marks all cached results as invalidated and removes them.
*/
void setCacheInvalidated();
/**
* Solves for non-logic elements
*/
void doNonLogic();
/**
* Solves for logic elements (i.e just does fbSub)
*/
void doLogic() { m_elementSet->doLinear(false); }
void displayEquations();
void updateCurrents();
/**
* This will identify the ground node and non-ground nodes in the given set.
* Ground will be given the eqId -1, non-ground of 0.
* @param highest The highest ground type of the groundnodes found. If no
ground nodes were found, this will be (gt_never-1).
* @returns the number of ground nodes. If all nodes are at or below the
* gt_never threshold, then this will be zero.
*/
static int identifyGround(PinSet nodeList, int *highest = 0);
void setChanged() { isSetChanged = true; }
void clearChanged() { isSetChanged = false; }
inline bool isChanged() { return isSetChanged; }
protected:
void cacheAndUpdate();
/**
* Update the nodal voltages from those calculated in ElementSet
*/
void updateNodalVoltages();
/**
* Step the reactive elements.
*/
void stepReactive();
/**
* Returns true if any of the nodes are ground
*/
static bool recursivePinAdd(Pin *node, PinSet *unassignedNodes, PinSet *associated, PinSet *nodes);
PinSet m_pinList;
ElementList m_elementList;
ElementSet *m_elementSet;
//Stuff for caching
bool m_bCanCache;
LogicCacheNode *m_pLogicCacheBase;
logicOutVec m_pLogicOut;
private:
bool isSetChanged;
};
#endif

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks