Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
analysis.cpp
Go to the documentation of this file.
1 /*
2  * analysis.cpp - analysis class implementation
3  *
4  *
5  * Copyright (C) 2003-2008 Stefan Jahn <stefan@lkcc.org>
6  *
7  * This is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this package; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  * $Id: analysis.cpp 1869 2013-03-06 12:50:21Z crobarcro $
23  *
24  */
25 
33 #if HAVE_CONFIG_H
34 # include <config.h>
35 #endif
36 
37 //#include <stdio.h>
38 //#include <stdlib.h>
39 //#include <string.h>
40 
41 #include "object.h"
42 #include "complex.h"
43 #include "sweep.h"
44 #include "vector.h"
45 #include "strlist.h"
46 #include "dataset.h"
47 #include "ptrlist.h"
48 #include "analysis.h"
49 
50 namespace qucs {
51 
52 //Constructor. Creates an unnamed instance of the analysis class.
53 analysis::analysis () : object () {
54  data = NULL;
55  subnet = NULL;
56  env = NULL;
57  actions = NULL;
59  runs = 0;
60  progress = true;
61 }
62 
63 // Constructor creates a named instance of the analysis class.
64 analysis::analysis (char * n) : object (n) {
65  data = NULL;
66  subnet = NULL;
67  env = NULL;
68  actions = NULL;
70  runs = 0;
71  progress = true;
72 }
73 
74 // Destructor deletes the analysis class object.
76  if (actions) delete actions;
77 }
78 
79 /* The copy constructor creates a new instance of the analysis class
80  based on the given analysis object. */
81 analysis::analysis (analysis & a) : object (a) {
82  data = a.data;
83  subnet = a.subnet;
84  env = a.env;
85  actions = a.actions ? new ptrlist<analysis> (*a.actions) : NULL;
86  type = a.type;
87  runs = a.runs;
88  progress = a.progress;
89 }
90 
91 /* This function adds the given analysis to the actions being
92  associated with the current analysis object. */
94  if (!actions) actions = new ptrlist<analysis> ();
95  actions->add (a);
96 }
97 
98 /* This function deletes the given analysis from the actions being
99  associated with the current analysis object. */
101  if (actions) actions->del (a);
102 }
103 
104 /* The following function creates a sweep object depending on the
105  analysis's properties. Supported sweep types are: linear,
106  logarithmic, lists and constants. */
107 sweep * analysis::createSweep (const char * n) {
108  sweep * swp = NULL;
109  // get type of sweep
110  char * type = getPropertyString ("Type");
111 
112  // linearly or logarithmically stepped sweeps
113  if (!strcmp (type, "lin") || !strcmp (type, "log")) {
114  nr_double_t start = getPropertyDouble ("Start");
115  nr_double_t stop = getPropertyDouble ("Stop");
116  int points = getPropertyInteger ("Points");
117  if (!strcmp (type, "lin")) {
118  swp = new linsweep (n);
119  ((linsweep *) swp)->create (start, stop, points);
120  }
121  else if (!strcmp (type, "log")) {
122  swp = new logsweep (n);
123  ((logsweep *) swp)->create (start, stop, points);
124  }
125  }
126 
127  // lists of values
128  else if (!strcmp (type, "list")) {
129  vector * values = getPropertyVector ("Values");
130  int points = values->getSize ();
131  swp = new lstsweep (n);
132  ((lstsweep *) swp)->create (points);
133  for (int i = 0; i < values->getSize (); i++)
134  swp->set (i, real (values->get (i)));
135  }
136 
137  // constant value
138  else if (!strcmp (type, "const")) {
139  nr_double_t val = getPropertyDouble ("Values");
140  swp = new consweep (n);
141  ((consweep *) swp)->create (1);
142  swp->set (0, val);
143  }
144 
145  swp->setParent (this);
146  return swp;
147 }
148 
149 /* Saves the given variable into the dataset. Creates the dataset
150  vector if necessary. */
151 void analysis::saveVariable (const char * n, nr_complex_t z, vector * f) {
152  vector * d;
153  if ((d = data->findVariable (n)) == NULL) {
154  d = new vector (n);
155  if (f != NULL) {
156  d->setDependencies (new strlist ());
157  d->getDependencies()->add (f->getName ());
158  }
159  d->setOrigin (getName ());
160  data->addVariable (d);
161  }
162  d->add (z);
163 }
164 
165 } // namespace qucs
start
Definition: parse_zvr.y:126
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
net * subnet
Definition: analysis.h:273
matrix real(matrix a)
Real part matrix.
Definition: matrix.cpp:568
void saveVariable(const char *, nr_complex_t, qucs::vector *)
Save variable into analysis dataset.
Definition: analysis.cpp:151
void delAnalysis(analysis *)
Definition: analysis.cpp:100
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
void add(type_t *)
Definition: ptrlist.cpp:69
analysis()
Constructor (Unnamed)
Definition: analysis.cpp:53
int getPropertyInteger(const char *)
Definition: object.cpp:198
~analysis()
Destructor.
Definition: analysis.cpp:75
n
Definition: parse_citi.y:147
environment * env
Definition: analysis.h:275
vector * getPropertyVector(const char *)
Definition: object.cpp:150
i
Definition: parse_mdl.y:516
stop
Definition: parse_zvr.y:127
points
Definition: parse_zvr.y:129
The analysis class header file.
dataset * data
Definition: analysis.h:274
void del(type_t *)
Definition: ptrlist.cpp:106
void addAnalysis(analysis *)
Definition: analysis.cpp:93
class for performing circuit analyses.
Definition: analysis.h:82
sweep * createSweep(const char *)
create a named sweep object
Definition: analysis.cpp:107
char * getName(void)
Definition: object.cpp:84
values
Definition: parse_spice.y:223
char * getPropertyString(const char *)
Definition: object.cpp:159
ptrlist< analysis > * actions
Definition: analysis.h:276