1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
// license:GPL-2.0+
// copyright-holders:Couriersud
/*
* nld_fourterm.c
*
*/
#include "netlist/solver/nld_solver.h"
#include "netlist/nl_factory.h"
#include "nlid_fourterm.h"
#include <cmath>
namespace netlist
{
namespace analog
{
// ----------------------------------------------------------------------------------------
// nld_VCCS
// ----------------------------------------------------------------------------------------
NETLIB_RESET(VCCS)
{
const nl_fptype m_mult = m_G() * m_gfac; // 1.0 ==> 1V ==> 1A
const nl_fptype GI = nlconst::one() / m_RI();
m_IP.set_conductivity(GI);
m_IN.set_conductivity(GI);
m_OP.set_go_gt(-m_mult, nlconst::zero());
m_OP1.set_go_gt(m_mult, nlconst::zero());
m_ON.set_go_gt(m_mult, nlconst::zero());
m_ON1.set_go_gt(-m_mult, nlconst::zero());
}
NETLIB_UPDATE(VCCS)
{
/* only called if connected to a rail net ==> notify the solver to recalculate */
if (!m_IP.net().isRailNet())
m_IP.solve_now();
else if (!m_IN.net().isRailNet())
m_IN.solve_now();
else if (!m_OP.net().isRailNet())
m_OP.solve_now();
else if (!m_ON.net().isRailNet())
m_ON.solve_now();
}
// ----------------------------------------------------------------------------------------
// nld_LVCCS
// ----------------------------------------------------------------------------------------
NETLIB_RESET(LVCCS)
{
NETLIB_NAME(VCCS)::reset();
}
NETLIB_UPDATE_PARAM(LVCCS)
{
NETLIB_NAME(VCCS)::update_param();
}
NETLIB_UPDATE_TERMINALS(LVCCS)
{
const nl_fptype m_mult = m_G() * m_gfac; // 1.0 ==> 1V ==> 1A
const nl_fptype vi = m_IP.net().Q_Analog() - m_IN.net().Q_Analog();
const auto c1(nlconst::magic(0.2));
if (std::abs(m_mult / m_cur_limit() * vi) > nlconst::half())
m_vi = m_vi + c1 * std::tanh((vi - m_vi) / c1);
else
m_vi = vi;
const nl_fptype x = m_mult / m_cur_limit() * m_vi;
const nl_fptype X = std::tanh(x);
const nl_fptype beta = m_mult * (nlconst::one() - X*X);
const nl_fptype I = m_cur_limit() * X - beta * m_vi;
m_OP.set_go_gt_I(-beta, nlconst::zero(), I);
m_OP1.set_go_gt(beta, nlconst::zero());
m_ON.set_go_gt_I(beta, nlconst::zero(), -I);
m_ON1.set_go_gt(-beta, nlconst::zero());
}
// ----------------------------------------------------------------------------------------
// nld_CCCS
// ----------------------------------------------------------------------------------------
NETLIB_RESET(CCCS)
{
NETLIB_NAME(VCCS)::reset();
}
NETLIB_UPDATE_PARAM(CCCS)
{
NETLIB_NAME(VCCS)::update_param();
}
// ----------------------------------------------------------------------------------------
// nld_VCVS
// ----------------------------------------------------------------------------------------
NETLIB_RESET(VCVS)
{
m_gfac = nlconst::one() / m_RO();
NETLIB_NAME(VCCS)::reset();
m_OP2.set_conductivity(nlconst::one() / m_RO());
m_ON2.set_conductivity(nlconst::one() / m_RO());
}
} //namespace analog
namespace devices {
NETLIB_DEVICE_IMPL_NS(analog, VCVS, "VCVS", "")
NETLIB_DEVICE_IMPL_NS(analog, VCCS, "VCCS", "")
NETLIB_DEVICE_IMPL_NS(analog, CCCS, "CCCS", "")
NETLIB_DEVICE_IMPL_NS(analog, LVCCS, "LVCCS", "")
} // namespace devices
} // namespace netlist
|