1 /*$Id: bm_poly.cc,v 26.137 2010/04/10 02:37:05 al Exp $ -*- C++ -*-
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
29 /*--------------------------------------------------------------------------*/
31 /*--------------------------------------------------------------------------*/
32 const double _default_max(BIGBIG
);
33 const double _default_min(-BIGBIG
);
34 const bool _default_abs(false);
35 /*--------------------------------------------------------------------------*/
36 class EVAL_BM_POLY
: public EVAL_BM_ACTION_BASE
{
38 PARAMETER
<double> _min
;
39 PARAMETER
<double> _max
;
41 std::vector
<PARAMETER
<double> > _c
;
42 explicit EVAL_BM_POLY(const EVAL_BM_POLY
& p
);
44 explicit EVAL_BM_POLY(int c
=0);
46 private: // override vitrual
47 bool operator==(const COMMON_COMPONENT
&)const;
48 COMMON_COMPONENT
* clone()const {return new EVAL_BM_POLY(*this);}
49 void print_common_obsolete_callback(OMSTREAM
&, LANGUAGE
*)const;
51 void precalc_first(const CARD_LIST
*);
52 void tr_eval(ELEMENT
*)const;
53 std::string
name()const {return "poly";}
54 bool ac_too()const {untested();return false;}
55 bool parse_numlist(CS
&);
56 bool parse_params_obsolete_callback(CS
&);
57 void skip_type_tail(CS
& cmd
)const {cmd
.umatch("(1)");}
59 /*--------------------------------------------------------------------------*/
60 /*--------------------------------------------------------------------------*/
61 EVAL_BM_POLY::EVAL_BM_POLY(int c
)
62 :EVAL_BM_ACTION_BASE(c
),
68 /*--------------------------------------------------------------------------*/
69 EVAL_BM_POLY::EVAL_BM_POLY(const EVAL_BM_POLY
& p
)
70 :EVAL_BM_ACTION_BASE(p
),
77 /*--------------------------------------------------------------------------*/
78 bool EVAL_BM_POLY::operator==(const COMMON_COMPONENT
& x
)const
80 const EVAL_BM_POLY
* p
= dynamic_cast<const EVAL_BM_POLY
*>(&x
);
86 && EVAL_BM_ACTION_BASE::operator==(x
);
93 /*--------------------------------------------------------------------------*/
94 void EVAL_BM_POLY::print_common_obsolete_callback(OMSTREAM
& o
, LANGUAGE
* lang
)const
98 for (std::vector
<PARAMETER
<double> >::const_iterator
99 p
= _c
.begin(); p
!= _c
.end(); ++p
) {
103 print_pair(o
, lang
, "min", _min
, _min
.has_hard_value());
104 print_pair(o
, lang
, "max", _max
, _max
.has_hard_value());
105 print_pair(o
, lang
, "abs", _abs
, _abs
.has_hard_value());
106 EVAL_BM_ACTION_BASE::print_common_obsolete_callback(o
, lang
);
108 /*--------------------------------------------------------------------------*/
109 void EVAL_BM_POLY::precalc_first(const CARD_LIST
* Scope
)
112 EVAL_BM_ACTION_BASE::precalc_first(Scope
);
113 for (std::vector
<PARAMETER
<double> >::const_iterator
114 p
= _c
.begin(); p
!= _c
.end(); ++p
) {
115 (*p
).e_val(0, Scope
);
117 _min
.e_val(_default_min
, Scope
);
118 _max
.e_val(_default_max
, Scope
);
119 _abs
.e_val(_default_abs
, Scope
);
121 /*--------------------------------------------------------------------------*/
122 void EVAL_BM_POLY::tr_eval(ELEMENT
* d
)const
124 double x
= ioffset(d
->_y
[0].x
);
127 for (size_t i
=_c
.size()-1; i
>0; --i
) {
135 if (_abs
&& f0
< 0) {
143 }else if (f0
< _min
) {
148 d
->_y
[0] = FPOLY1(x
, f0
, f1
);
149 tr_final_adjust(&(d
->_y
[0]), d
->f_is_value());
151 /*--------------------------------------------------------------------------*/
152 bool EVAL_BM_POLY::parse_numlist(CS
& cmd
)
154 unsigned start
= cmd
.cursor();
155 unsigned here
= cmd
.cursor();
157 unsigned old_here
= here
;
158 PARAMETER
<double> val
;
160 if (cmd
.stuck(&here
)) {
161 // no more, graceful finish
164 if (cmd
.match1('=')) {
165 // got one that doesn't belong, back up
173 if (cmd
.gotit(start
)) {
177 return cmd
.gotit(start
);
179 /*--------------------------------------------------------------------------*/
180 bool EVAL_BM_POLY::parse_params_obsolete_callback(CS
& cmd
)
183 || Get(cmd
, "min", &_min
)
184 || Get(cmd
, "max", &_max
)
185 || Get(cmd
, "abs", &_abs
)
186 || EVAL_BM_ACTION_BASE::parse_params_obsolete_callback(cmd
)
189 /*--------------------------------------------------------------------------*/
190 /*--------------------------------------------------------------------------*/
191 EVAL_BM_POLY
p1(CC_STATIC
);
192 DISPATCHER
<COMMON_COMPONENT
>::INSTALL
d1(&bm_dispatcher
, "poly", &p1
);
194 /*--------------------------------------------------------------------------*/
195 /*--------------------------------------------------------------------------*/
196 // vim:ts=8:sw=2:noet: