-
Notifications
You must be signed in to change notification settings - Fork 4
/
bm_poly.cc
235 lines (230 loc) · 7.88 KB
/
bm_poly.cc
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
/* -*- C++ -*-
* Copyright (C) 2001 Albert Davis
* Author: Albert Davis <[email protected]>
*
* 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.
*------------------------------------------------------------------
* HSPICE compatible POLY
*/
//testing=script,complete 2005.10.06
#include "u_lang.h"
#include "e_elemnt.h"
#include "bm.h"
#include <globals.h>
#include <boost/assign.hpp> // initialization templates
/*--------------------------------------------------------------------------*/
#ifndef HAVE_UINT_T
typedef int uint_t;
#endif
/*--------------------------------------------------------------------------*/
namespace {
/*--------------------------------------------------------------------------*/
const double _default_max(BIGBIG);
const double _default_min(-BIGBIG);
const bool _default_abs(false);
const bool _default_degree(0);
/*--------------------------------------------------------------------------*/
class EVAL_BM_POLY : public EVAL_BM_ACTION_BASE {
private:
PARAMETER<double> _min;
PARAMETER<double> _max;
PARAMETER<bool> _abs;
static std::map<std::string, PARA_BASE EVAL_BM_POLY::*> param_dict;
std::vector<PARAMETER<double> > _c;
PARAMETER<int> _degree;
explicit EVAL_BM_POLY(const EVAL_BM_POLY& p);
public:
explicit EVAL_BM_POLY(int c=0);
~EVAL_BM_POLY() { untested();}
private: // override vitrual
bool operator==(const COMMON_COMPONENT&)const override;
COMMON_COMPONENT* clone()const override { untested();return new EVAL_BM_POLY(*this);}
void print_common_obsolete_callback(OMSTREAM&, LANGUAGE*)const override;
// not yet bool use_obsolete_callback_print()const { untested();return false;}
void precalc_last(const CARD_LIST*)override;
void tr_eval(ELEMENT*)const override;
std::string name()const override { untested();return "poly";}
bool ac_too()const override {untested();return false;}
bool parse_numlist(CS&)override;
int set_param_by_name(std::string Name, std::string Value)override;
bool parse_params_obsolete_callback(CS&)override;
void skip_type_tail(CS& cmd)const override{ untested();cmd.umatch("(1)");}
};
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
EVAL_BM_POLY::EVAL_BM_POLY(int c)
:EVAL_BM_ACTION_BASE(c),
_min(_default_min),
_max(_default_max),
_abs(_default_abs),
_degree(_default_degree)
{ untested();
}
/*--------------------------------------------------------------------------*/
EVAL_BM_POLY::EVAL_BM_POLY(const EVAL_BM_POLY& p)
:EVAL_BM_ACTION_BASE(p),
_min(p._min),
_max(p._max),
_abs(p._abs),
_c(p._c),
_degree(p._degree)
{ untested();
}
/*--------------------------------------------------------------------------*/
bool EVAL_BM_POLY::operator==(const COMMON_COMPONENT& x)const
{ untested();
const EVAL_BM_POLY* p = dynamic_cast<const EVAL_BM_POLY*>(&x);
bool rv = p
&& _min == p->_min
&& _max == p->_max
&& _abs == p->_abs
&& _c == p->_c
&& _degree == p->_degree
&& EVAL_BM_ACTION_BASE::operator==(x);
return rv;
}
/*--------------------------------------------------------------------------*/
void EVAL_BM_POLY::print_common_obsolete_callback(OMSTREAM& o, LANGUAGE* lang)const
{ untested();
assert(lang);
o << ' ' << name() << '(';
for (std::vector<PARAMETER<double> >::const_iterator
p = _c.begin(); p != _c.end(); ++p) { untested();
o << *p << ' ';
}
o << ')';
print_pair(o, lang, "min", _min, _min.has_hard_value());
print_pair(o, lang, "max", _max, _max.has_hard_value());
print_pair(o, lang, "abs", _abs, _abs.has_hard_value());
EVAL_BM_ACTION_BASE::print_common_obsolete_callback(o, lang);
}
/*--------------------------------------------------------------------------*/
void EVAL_BM_POLY::precalc_last(const CARD_LIST* Scope)
{ untested();
assert(Scope);
EVAL_BM_ACTION_BASE::precalc_last(Scope);
for (std::vector<PARAMETER<double> >::const_iterator
p = _c.begin(); p != _c.end(); ++p) { untested();
(*p).e_val(0, Scope);
}
_min.e_val(_default_min, Scope);
_max.e_val(_default_max, Scope);
_abs.e_val(_default_abs, Scope);
}
/*--------------------------------------------------------------------------*/
void EVAL_BM_POLY::tr_eval(ELEMENT* d)const
{ untested();
double x = ioffset(d->_y[0].x);
double f0 = 0.;
double f1 = 0.;
assert(_c.size());
for (size_t i=_c.size()-1; i>0; --i) { untested();
f0 += _c[i];
f0 *= x;
f1 *= x;
f1 += _c[i]*int(i);
}
f0 += _c[0];
if (_abs && f0 < 0) { untested();
f0 = -f0;
f1 = -f1;
}
if (f0 > _max) { untested();
f0 = _max;
f1 = 0;
}else if (f0 < _min) { untested();
f0 = _min;
f1 = 0;
}
d->_y[0] = FPOLY1(x, f0, f1);
tr_final_adjust(&(d->_y[0]), d->f_is_value());
}
/*--------------------------------------------------------------------------*/
bool EVAL_BM_POLY::parse_numlist(CS& cmd)
{ untested();
size_t start = cmd.cursor();
size_t here = cmd.cursor();
for (;;) { untested();
size_t old_here = here;
PARAMETER<double> val;
val.obsolete_parse(cmd);
if (cmd.stuck(&here)) { untested();
// no more, graceful finish
break;
}else{ untested();
if (cmd.match1('=')) { untested();
// got one that doesn't belong, back up
cmd.reset(old_here);
break;
}else{ untested();
_c.push_back(val);
}
}
}
if (cmd.gotit(start)) { untested();
}else{ untested();
}
return cmd.gotit(start);
}
/*--------------------------------------------------------------------------*/
std::map<std::string, PARA_BASE EVAL_BM_POLY::*> EVAL_BM_POLY::param_dict =
boost::assign::map_list_of
("min", (PARA_BASE EVAL_BM_POLY::*) &EVAL_BM_POLY::_min)
("max", (PARA_BASE EVAL_BM_POLY::*) &EVAL_BM_POLY::_max)
("abs", (PARA_BASE EVAL_BM_POLY::*) &EVAL_BM_POLY::_abs);
/*--------------------------------------------------------------------------*/
int EVAL_BM_POLY::set_param_by_name(std::string Name, std::string Value)
{ untested();
PARA_BASE EVAL_BM_POLY::* x = (param_dict[Name]);
if(x) { untested();
PARA_BASE* p = &(this->*x);
*p = Value;
return 0; // TODO
} else { untested();
return EVAL_BM_ACTION_BASE::set_param_by_name(Name, Value);
}
}
/*--------------------------------------------------------------------------*/
bool EVAL_BM_POLY::parse_params_obsolete_callback(CS& cmd)
{ untested();
return ONE_OF
|| Get(cmd, "min", &_min)
|| Get(cmd, "max", &_max)
|| Get(cmd, "abs", &_abs)
|| EVAL_BM_ACTION_BASE::parse_params_obsolete_callback(cmd)
;
}
/*--------------------------------------------------------------------------*/
#if 0
void EVAL_BM_POLY::parse_type_tail(CS& cmd) { untested();
untested();
if(cmd.umatch("(1)")){ untested();
_degree = 1;
}else{ untested();
untested();
}
}
#endif
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
EVAL_BM_POLY p1(CC_STATIC);
DISPATCHER<COMMON_COMPONENT>::INSTALL d1(&bm_dispatcher, "poly", &p1);
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// vim:ts=8:sw=2:noet: