remove lib prefix from plugin name
[gnucap-felix.git] / apps / bm_tanh.cc
blob0e9f3ddedbd9942a35b00ec7205c4468c4d4938f
1 /*$Id: bm_tanh.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 * behavioral modeling hyperbolic tangent
24 //testing=script 2005.10.07
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_gain (NOT_INPUT);
33 const double _default_limit (NOT_INPUT);
34 /*--------------------------------------------------------------------------*/
35 class EVAL_BM_TANH : public EVAL_BM_ACTION_BASE {
36 private:
37 PARAMETER<double> _gain;
38 PARAMETER<double> _limit;
39 explicit EVAL_BM_TANH(const EVAL_BM_TANH& p);
40 public:
41 explicit EVAL_BM_TANH(int c=0);
42 ~EVAL_BM_TANH() {}
43 private: // override virtual
44 bool operator==(const COMMON_COMPONENT&)const;
45 COMMON_COMPONENT* clone()const {return new EVAL_BM_TANH(*this);}
46 void print_common_obsolete_callback(OMSTREAM&, LANGUAGE*)const;
48 void precalc_first(const CARD_LIST*);
49 void tr_eval(ELEMENT*)const;
50 std::string name()const {return "tanh";}
51 bool ac_too()const {untested();return false;}
52 bool parse_numlist(CS&);
53 bool parse_params_obsolete_callback(CS&);
55 /*--------------------------------------------------------------------------*/
56 /*--------------------------------------------------------------------------*/
57 EVAL_BM_TANH::EVAL_BM_TANH(int c)
58 :EVAL_BM_ACTION_BASE(c),
59 _gain(NOT_INPUT),
60 _limit(NOT_INPUT)
63 /*--------------------------------------------------------------------------*/
64 EVAL_BM_TANH::EVAL_BM_TANH(const EVAL_BM_TANH& p)
65 :EVAL_BM_ACTION_BASE(p),
66 _gain(p._gain),
67 _limit(p._limit)
70 /*--------------------------------------------------------------------------*/
71 bool EVAL_BM_TANH::operator==(const COMMON_COMPONENT& x)const
73 const EVAL_BM_TANH* p = dynamic_cast<const EVAL_BM_TANH*>(&x);
74 bool rv = p
75 && _gain == p->_gain
76 && _limit == p->_limit
77 && EVAL_BM_ACTION_BASE::operator==(x);
78 if (rv) {
79 untested();
81 return rv;
83 /*--------------------------------------------------------------------------*/
84 void EVAL_BM_TANH::print_common_obsolete_callback(OMSTREAM& o, LANGUAGE* lang)const
86 assert(lang);
87 o << name();
88 print_pair(o, lang, "gain", _gain);
89 print_pair(o, lang, "limit", _limit);
90 EVAL_BM_ACTION_BASE::print_common_obsolete_callback(o, lang);
92 /*--------------------------------------------------------------------------*/
93 void EVAL_BM_TANH::precalc_first(const CARD_LIST* Scope)
95 assert(Scope);
96 EVAL_BM_ACTION_BASE::precalc_first(Scope);
97 _gain.e_val(_default_gain, Scope);
98 _limit.e_val(_default_limit, Scope);
100 /*--------------------------------------------------------------------------*/
101 void EVAL_BM_TANH::tr_eval(ELEMENT* d)const
103 double x = ioffset(d->_y[0].x);
104 double aa = x * _gain/_limit;
105 double f1, f0;
106 if (aa > LOGBIGBIG) {
107 f1 = 0;
108 f0 = _limit;
109 }else if (aa < -LOGBIGBIG) {
110 f1 = 0;
111 f0 = -_limit;
112 }else{
113 double cosine = cosh(aa);
114 f1 = _gain / (cosine*cosine);
115 f0 = _limit * tanh(aa);
117 d->_y[0] = FPOLY1(x, f0, f1);
118 tr_final_adjust(&(d->_y[0]), d->f_is_value());
120 /*--------------------------------------------------------------------------*/
121 bool EVAL_BM_TANH::parse_numlist(CS& cmd)
123 unsigned here = cmd.cursor();
124 PARAMETER<double> gain(NOT_VALID);
125 PARAMETER<double> limit(NOT_VALID);
126 cmd >> gain >> limit;
127 if (cmd.gotit(here)) {
128 _gain = gain;
129 _limit = limit;
130 return true;
131 }else{
132 return false;
135 /*--------------------------------------------------------------------------*/
136 bool EVAL_BM_TANH::parse_params_obsolete_callback(CS& cmd)
138 return ONE_OF
139 || Get(cmd, "gain", &_gain)
140 || Get(cmd, "limit", &_limit)
141 || EVAL_BM_ACTION_BASE::parse_params_obsolete_callback(cmd)
144 /*--------------------------------------------------------------------------*/
145 /*--------------------------------------------------------------------------*/
146 EVAL_BM_TANH p1(CC_STATIC);
147 DISPATCHER<COMMON_COMPONENT>::INSTALL d1(&bm_dispatcher, "tanh", &p1);
149 /*--------------------------------------------------------------------------*/
150 /*--------------------------------------------------------------------------*/
151 // vim:ts=8:sw=2:noet: