2 * Copyright (C) 2001 Albert Davis
3 * Author: Albert Davis <aldavis@gnu.org>
5 * This file is part of "Gnucap", the Gnu Circuit Analysis Package
7 * This program 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 3, or (at your option)
12 * This program 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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 *------------------------------------------------------------------
22 * HSPICE compatible POLY
24 //testing=script,complete 2005.10.06
28 /*--------------------------------------------------------------------------*/
30 /*--------------------------------------------------------------------------*/
31 const double _default_max(BIGBIG
);
32 const double _default_min(-BIGBIG
);
33 const bool _default_abs(false);
34 const bool _default_degree(0);
35 /*--------------------------------------------------------------------------*/
36 class EVAL_BM_POLY
: public EVAL_BM_ACTION_BASE
{
38 PARAMETER
<double> _min
;
39 PARAMETER
<double> _max
;
41 static map
<string
, PARA_BASE
EVAL_BM_POLY::*> param_dict
;
42 std::vector
<PARAMETER
<double> > _c
;
43 PARAMETER
<unsigned> _degree
;
44 explicit EVAL_BM_POLY(const EVAL_BM_POLY
& p
);
46 explicit EVAL_BM_POLY(int c
=0);
48 private: // override vitrual
49 bool operator==(const COMMON_COMPONENT
&)const;
50 COMMON_COMPONENT
* clone()const {return new EVAL_BM_POLY(*this);}
51 void print_common_obsolete_callback(OMSTREAM
&, LANGUAGE
*)const;
52 // not yet bool use_obsolete_callback_print()const {return false;}
54 void precalc_last(const CARD_LIST
*);
55 void tr_eval(ELEMENT
*)const;
56 std::string
name()const {return "poly";}
57 bool ac_too()const {untested();return false;}
58 bool parse_numlist(CS
&);
59 void set_param_by_name(string Name
, string Value
);
60 bool parse_params_obsolete_callback(CS
&);
61 void skip_type_tail(CS
& cmd
)const {cmd
.umatch("(1)");}
63 /*--------------------------------------------------------------------------*/
64 /*--------------------------------------------------------------------------*/
65 EVAL_BM_POLY::EVAL_BM_POLY(int c
)
66 :EVAL_BM_ACTION_BASE(c
),
70 _degree(_default_degree
)
73 /*--------------------------------------------------------------------------*/
74 EVAL_BM_POLY::EVAL_BM_POLY(const EVAL_BM_POLY
& p
)
75 :EVAL_BM_ACTION_BASE(p
),
83 /*--------------------------------------------------------------------------*/
84 bool EVAL_BM_POLY::operator==(const COMMON_COMPONENT
& x
)const
86 const EVAL_BM_POLY
* p
= dynamic_cast<const EVAL_BM_POLY
*>(&x
);
92 && _degree
== p
->_degree
93 && EVAL_BM_ACTION_BASE::operator==(x
);
96 /*--------------------------------------------------------------------------*/
97 void EVAL_BM_POLY::print_common_obsolete_callback(OMSTREAM
& o
, LANGUAGE
* lang
)const
100 o
<< ' ' << name() << '(';
101 for (std::vector
<PARAMETER
<double> >::const_iterator
102 p
= _c
.begin(); p
!= _c
.end(); ++p
) {
106 print_pair(o
, lang
, "min", _min
, _min
.has_hard_value());
107 print_pair(o
, lang
, "max", _max
, _max
.has_hard_value());
108 print_pair(o
, lang
, "abs", _abs
, _abs
.has_hard_value());
109 EVAL_BM_ACTION_BASE::print_common_obsolete_callback(o
, lang
);
111 /*--------------------------------------------------------------------------*/
112 void EVAL_BM_POLY::precalc_last(const CARD_LIST
* Scope
)
115 EVAL_BM_ACTION_BASE::precalc_last(Scope
);
117 for (std::vector
<PARAMETER
<double> >::const_iterator
118 p
= _c
.begin(); p
!= _c
.end(); ++p
) {
119 (*p
).e_val(0, Scope
);
121 _min
.e_val(_default_min
, Scope
);
122 _max
.e_val(_default_max
, Scope
);
123 _abs
.e_val(_default_abs
, Scope
);
125 /*--------------------------------------------------------------------------*/
126 void EVAL_BM_POLY::tr_eval(ELEMENT
* d
)const
128 double x
= ioffset(d
->_y
[0].x
);
132 for (size_t i
=_c
.size()-1; i
>0; --i
) {
140 if (_abs
&& f0
< 0) {
148 }else if (f0
< _min
) {
153 d
->_y
[0] = FPOLY1(x
, f0
, f1
);
154 tr_final_adjust(&(d
->_y
[0]), d
->f_is_value());
156 /*--------------------------------------------------------------------------*/
157 bool EVAL_BM_POLY::parse_numlist(CS
& cmd
)
159 unsigned start
= cmd
.cursor();
160 unsigned here
= cmd
.cursor();
162 unsigned old_here
= here
;
163 PARAMETER
<double> val
;
165 if (cmd
.stuck(&here
)) {
166 // no more, graceful finish
169 if (cmd
.match1('=')) {
170 // got one that doesn't belong, back up
178 if (cmd
.gotit(start
)) {
182 return cmd
.gotit(start
);
184 /*--------------------------------------------------------------------------*/
185 map
<string
, PARA_BASE
EVAL_BM_POLY::*> EVAL_BM_POLY::param_dict
=
186 boost::assign::map_list_of
187 ("min", (PARA_BASE
EVAL_BM_POLY::*) &EVAL_BM_POLY::_min
)
188 ("max", (PARA_BASE
EVAL_BM_POLY::*) &EVAL_BM_POLY::_max
)
189 ("abs", (PARA_BASE
EVAL_BM_POLY::*) &EVAL_BM_POLY::_abs
);
190 /*--------------------------------------------------------------------------*/
191 void EVAL_BM_POLY::set_param_by_name(string Name
, string Value
)
193 PARA_BASE
EVAL_BM_POLY::* x
= (param_dict
[Name
]);
195 PARA_BASE
* p
= &(this->*x
);
198 EVAL_BM_ACTION_BASE::set_param_by_name(Name
, Value
);
201 /*--------------------------------------------------------------------------*/
202 bool EVAL_BM_POLY::parse_params_obsolete_callback(CS
& cmd
)
205 || Get(cmd
, "min", &_min
)
206 || Get(cmd
, "max", &_max
)
207 || Get(cmd
, "abs", &_abs
)
208 || EVAL_BM_ACTION_BASE::parse_params_obsolete_callback(cmd
)
211 /*--------------------------------------------------------------------------*/
213 void EVAL_BM_POLY::parse_type_tail(CS
& cmd
) {
215 if(cmd
.umatch("(1)")){
222 /*--------------------------------------------------------------------------*/
223 /*--------------------------------------------------------------------------*/
224 EVAL_BM_POLY
p1(CC_STATIC
);
225 DISPATCHER
<COMMON_COMPONENT
>::INSTALL
d1(&bm_dispatcher
, "poly", &p1
);
227 /*--------------------------------------------------------------------------*/
228 /*--------------------------------------------------------------------------*/
229 // vim:ts=8:sw=2:noet: