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)
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 * behavioral modeling hyperbolic tangent
24 //testing=script 2005.10.07
29 /*--------------------------------------------------------------------------*/
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
{
37 PARAMETER
<double> _gain
;
38 PARAMETER
<double> _limit
;
39 explicit EVAL_BM_TANH(const EVAL_BM_TANH
& p
);
41 explicit EVAL_BM_TANH(int c
=0);
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
),
63 /*--------------------------------------------------------------------------*/
64 EVAL_BM_TANH::EVAL_BM_TANH(const EVAL_BM_TANH
& p
)
65 :EVAL_BM_ACTION_BASE(p
),
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
);
76 && _limit
== p
->_limit
77 && EVAL_BM_ACTION_BASE::operator==(x
);
83 /*--------------------------------------------------------------------------*/
84 void EVAL_BM_TANH::print_common_obsolete_callback(OMSTREAM
& o
, LANGUAGE
* lang
)const
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
)
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
;
106 if (aa
> LOGBIGBIG
) {
109 }else if (aa
< -LOGBIGBIG
) {
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
)) {
135 /*--------------------------------------------------------------------------*/
136 bool EVAL_BM_TANH::parse_params_obsolete_callback(CS
& cmd
)
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: