remove lib prefix from plugin name
[gnucap-felix.git] / apps / bm_poly.cc
blobb2d665188631cf9f6b110cf7a16dd19550081498
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)
10 * any later version.
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
20 * 02110-1301, USA.
21 *------------------------------------------------------------------
22 * HSPICE compatible POLY
24 //testing=script,complete 2005.10.06
25 #include "globals.h"
26 #include "u_lang.h"
27 #include "e_elemnt.h"
28 #include "bm.h"
29 /*--------------------------------------------------------------------------*/
30 namespace {
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 {
37 private:
38 PARAMETER<double> _min;
39 PARAMETER<double> _max;
40 PARAMETER<bool> _abs;
41 std::vector<PARAMETER<double> > _c;
42 explicit EVAL_BM_POLY(const EVAL_BM_POLY& p);
43 public:
44 explicit EVAL_BM_POLY(int c=0);
45 ~EVAL_BM_POLY() {}
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),
63 _min(_default_min),
64 _max(_default_max),
65 _abs(_default_abs)
68 /*--------------------------------------------------------------------------*/
69 EVAL_BM_POLY::EVAL_BM_POLY(const EVAL_BM_POLY& p)
70 :EVAL_BM_ACTION_BASE(p),
71 _min(p._min),
72 _max(p._max),
73 _abs(p._abs),
74 _c(p._c)
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);
81 bool rv = p
82 && _min == p->_min
83 && _max == p->_max
84 && _abs == p->_abs
85 && _c == p->_c
86 && EVAL_BM_ACTION_BASE::operator==(x);
87 if (rv) {
88 incomplete();
89 untested();
91 return rv;
93 /*--------------------------------------------------------------------------*/
94 void EVAL_BM_POLY::print_common_obsolete_callback(OMSTREAM& o, LANGUAGE* lang)const
96 assert(lang);
97 o << name() << '(';
98 for (std::vector<PARAMETER<double> >::const_iterator
99 p = _c.begin(); p != _c.end(); ++p) {
100 o << *p << ' ';
102 o << ')';
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)
111 assert(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);
125 double f0 = 0.;
126 double f1 = 0.;
127 for (size_t i=_c.size()-1; i>0; --i) {
128 f0 += _c[i];
129 f0 *= x;
130 f1 *= x;
131 f1 += _c[i]*int(i);
133 f0 += _c[0];
135 if (_abs && f0 < 0) {
136 f0 = -f0;
137 f1 = -f1;
140 if (f0 > _max) {
141 f0 = _max;
142 f1 = 0;
143 }else if (f0 < _min) {
144 f0 = _min;
145 f1 = 0;
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();
156 for (;;) {
157 unsigned old_here = here;
158 PARAMETER<double> val;
159 cmd >> val;
160 if (cmd.stuck(&here)) {
161 // no more, graceful finish
162 break;
163 }else{
164 if (cmd.match1('=')) {
165 // got one that doesn't belong, back up
166 cmd.reset(old_here);
167 break;
168 }else{
169 _c.push_back(val);
173 if (cmd.gotit(start)) {
174 }else{
175 untested();
177 return cmd.gotit(start);
179 /*--------------------------------------------------------------------------*/
180 bool EVAL_BM_POLY::parse_params_obsolete_callback(CS& cmd)
182 return ONE_OF
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: