Branch data Line data Source code
1 : : /*
2 : : * e_trsolver.h - transient solver external interface class definitions
3 : : *
4 : : * Copyright (C) 2004, 2005, 2006, 2007, 2008 Stefan Jahn <stefan@lkcc.org>
5 : : *
6 : : * This is free software; you can redistribute it and/or modify
7 : : * it under the terms of the GNU General Public License as published by
8 : : * the Free Software Foundation; either version 2, or (at your option)
9 : : * any later version.
10 : : *
11 : : * This software is distributed in the hope that it will be useful,
12 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : : * GNU General Public License for more details.
15 : : *
16 : : * You should have received a copy of the GNU General Public License
17 : : * along with this package; see the file COPYING. If not, write to
18 : : * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19 : : * Boston, MA 02110-1301, USA.
20 : : *
21 : : * $Id$
22 : : *
23 : : */
24 : :
25 : : /** \file e_trsolver.h
26 : : * \brief The externally controlled trsolver external class header file.
27 : : *
28 : : */
29 : :
30 : : /**
31 : : * \ingroup QucsInterface
32 : : */
33 : :
34 : : #ifndef __E_TRSOLVER_H__
35 : : #define __E_TRSOLVER_H__
36 : :
37 : : #include "qucs_interface.h"
38 : : #include "trsolver.h"
39 : : #include <vector>
40 : :
41 : : namespace qucs {
42 : :
43 : : /**
44 : : * \class e_trsolver
45 : : *
46 : : * \ingroup QucsInterface
47 : : *
48 : : * \brief External interface class for transient simulation
49 : : *
50 : : * This class provides access to the transient solving functionality
51 : : * of Qucs for external software.
52 : : *
53 : : *
54 : : */
55 : : class e_trsolver : public trsolver
56 : : {
57 : : public:
58 [ # # ]: 208 : ACREATOR (e_trsolver);
59 : : //e_trsolver ();
60 : : e_trsolver (char *);
61 : : e_trsolver (e_trsolver &);
62 : : ~e_trsolver ();
63 : :
64 : : int init (nr_double_t, nr_double_t, int);
65 : : // int finish ();
66 : 0 : bool isExternal() { return true; };
67 : :
68 : : public:
69 : :
70 : : int stepsolve_sync (nr_double_t synctime);
71 : : void acceptstep_sync (void);
72 : : int stepsolve_async (nr_double_t steptime);
73 : : void acceptstep_async (void);
74 : : void rejectstep_async (void);
75 : : void getsolution (double *);
76 : :
77 : : /** \brief Sets the voltage of an exterally controlled voltage source.
78 : : * \param ecvsname The name of the voltage source to be set.
79 : : * \param V New value of the voltage.
80 : : * \return Integer flag reporting success or failure.
81 : : *
82 : : * This method searches for the ecvs component with the given
83 : : * name in \a ecvsname. If the ecvs exists, the value of the voltage
84 : : * to be set at the next time step is set to the supplied value in
85 : : * \a V.
86 : : *
87 : : * You can set the voltage of ecvs components in subcircuits created
88 : : * by using a name up of the subcircuit heirarchy it is in, e.g. the
89 : : * name
90 : : *
91 : : * SUBtop.SUBlower.ECVS1
92 : : *
93 : : * to set the voltage of an ecvs named ECVS1 which is located in
94 : : * subcircuit SUBlower, which is itself in subcircuit SUBtop in
95 : : * the top level circuit.
96 : : *
97 : : * Returns 0 if the ecvs was found, and -1 otherwise.
98 : : */
99 : : int setECVSVoltage(char * ecvsname, nr_double_t V);
100 : :
101 : : /// Returns the number of rows in the Jacobian matrix for the circuit
102 : : int getJacRows ();
103 : :
104 : : /// Returns the number of columns in the Jacobian matrix for the circuit
105 : : int getJacCols ();
106 : :
107 : : /** \brief Obtains the data from the Jacobian matrix for the circuit
108 : : * \param r Pointer to character array containing the name of the voltage
109 : : * \param c Reference to nr_double_t in which the node voltage will be returned
110 : : * \return The Jacobian matrix data at the specified location.
111 : : *
112 : : */
113 : : void getJacData (int r, int c, nr_double_t& data);
114 : :
115 : : /** \brief Obtains the voltage of a node by name
116 : : * \param label Pointer to character array containing the name of the voltage
117 : : * \param nodeV Reference to nr_double_t in which the node voltage will be returned
118 : : * \return Integer flag reporting success or failure
119 : : *
120 : : * This method searches for the node with the given name in \a label.
121 : : * If the node exists, the value of the voltage at that node is
122 : : * copied to \a nodeV. Returns 0 if the node was found, and -1
123 : : * otherwise.
124 : : */
125 : : int getNodeV (char * label, nr_double_t& nodeV);
126 : :
127 : : /** \brief Obtains the voltage reported by a voltage probe
128 : : * \param probename Pointer to character array containing the name of the probe
129 : : * \param probeV Reference to nr_double_t in which the node voltage will be returned
130 : : * \return Integer flag reporting success or failure
131 : : *
132 : : * This method searches for the voltage probe with the given name
133 : : * in \a probename. If the probe exists, the value of the probe voltage
134 : : * is copied to \a probeV. Returns 0 if the probe with the given name
135 : : * was found and -1 otherwise.
136 : : */
137 : : int getVProbeV (char * probename, nr_double_t& probeV);
138 : :
139 : : /** \brief Obtains the current reported by a current probe
140 : : * \param probename Pointer to character array containing the name of the probe
141 : : * \param probeI Reference to nr_double_t in which the current will be returned
142 : : * \return Integer flag reporting success or failure
143 : : *
144 : : * This method searches for the current probe with the given name
145 : : * in \a probename. If the probe exists, the value of the probe current
146 : : * is copied to \a probeI. Returns 0 if the probe with the given name
147 : : * was found and -1 otherwise.
148 : : */
149 : : int getIProbeI (char * probename, nr_double_t& probeI);
150 : :
151 : : // debugging functions
152 : : void debug (void);
153 : : void printx (void);
154 : :
155 : : /** \var void (*messagefcn)(int level, const char * format, ...);
156 : : * \brief Pointer to function used to print messages during a sim
157 : : * \param level Inter flag indicating the log level
158 : : * \param format Formatting string in the same format as printf
159 : : * \param ... Additional arguments to the printing function
160 : : *
161 : : * By default this points to the standard Qucs logprint function
162 : : * (found in logging.c) on creation of an e_trsolver instance.
163 : : * The log \a level flag indicates whether the message is a status
164 : : * update or an error message. \a format contains the formatting
165 : : * string in the same style as printf (when using logprint). The
166 : : * additional arguments are used by logprint in the supplied
167 : : * formatting string.
168 : : */
169 : : void (*messagefcn)(int level, const char * format, ...);
170 : :
171 : : private:
172 : :
173 : : int MaxIterations;
174 : : nr_double_t reltol;
175 : : nr_double_t abstol;
176 : : nr_double_t vntol;
177 : : nr_double_t time;
178 : : nr_double_t saveCurrent;
179 : : nr_double_t lastsynctime;
180 : : int running;
181 : : int rejected;
182 : : int convError;
183 : :
184 : : void initETR (nr_double_t start, nr_double_t, int);
185 : : void truncateHistory (nr_double_t);
186 : : void updateExternalInterpTime(nr_double_t);
187 : : void storeHistoryAges (void);
188 : : void updateHistoryAges(nr_double_t);
189 : :
190 : : // int solve_nonlinear_step (void);
191 : : void adjustDelta_sync (nr_double_t);
192 : :
193 : : // Asynchronous specific items
194 : :
195 : : // For going back in history of a solution after multiple
196 : : // solution steps
197 : : std::vector<nr_double_t> initialhistages;
198 : : tvector<nr_double_t> * lastsolution[8];
199 : : nr_double_t lastasynctime;
200 : : nr_double_t lastdeltas[8];
201 : : nr_double_t lastdelta;
202 : : // restores the solver to an earlier stored state, used
203 : : // when an asynchronous major step is rejected by the
204 : : // parent process
205 : : void restoreSolution (void);
206 : : void copySolution (tvector<nr_double_t> * [8], tvector<nr_double_t> * [8]);
207 : : void fillLastSolution (tvector<nr_double_t> * );
208 : : };
209 : :
210 : : } // namespace qucs
211 : :
212 : : #endif /* __e_trsolver_H__ */
213 : :
|