KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_sim_model_ngspice.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.TXT for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
26#include <boost/algorithm/string/predicate.hpp>
27
28
30{
31public:
34 {}
35};
36
37
38BOOST_FIXTURE_TEST_SUITE( SimModelNgspice, TEST_SIM_MODEL_NGSPICE_FIXTURE )
39
40
41BOOST_AUTO_TEST_CASE( ParamDuplicates )
42{
43 for( MODEL_TYPE type : MODEL_TYPE_ITERATOR() )
44 {
45 BOOST_TEST_CONTEXT( "Model name: " << ModelInfo( type ).name )
46 {
47 const std::vector<SIM_MODEL::PARAM::INFO> modelParams = ModelInfo( type ).modelParams;
48 const std::vector<SIM_MODEL::PARAM::INFO> instanceParams = ModelInfo( type ).instanceParams;
49
50 for( const SIM_MODEL::PARAM::INFO& modelParam : modelParams )
51 {
52 BOOST_TEST_CONTEXT( "Model param name: " << modelParam.name )
53 {
54 // Ensure there's no model parameters that have the same name.
55 BOOST_CHECK( std::none_of( modelParams.begin(), modelParams.end(),
56 [&modelParam]( const auto& aOtherModelParam )
57 {
58 return modelParam.id != aOtherModelParam.id
59 && modelParam.name == aOtherModelParam.name;
60 } ) );
61
62 // Ensure there's no model parameters that have the same name as an
63 // instance parameter.
64 BOOST_CHECK( std::none_of( instanceParams.begin(), instanceParams.end(),
65 [&modelParam]( const auto& aInstanceParam )
66 {
67 return modelParam.name == aInstanceParam.name;
68 } ) );
69
70 if( boost::ends_with( modelParam.name, "_" ) )
71 {
72 // Ensure that for each model parameter ending with a "_" there exists an
73 // instance parameter with the same name but without this final character.
74 // We append an "_" to model parameters to disambiguate from these
75 // corresponding instance parameters.
76 BOOST_CHECK( std::any_of( instanceParams.begin(), instanceParams.end(),
77 [&modelParam]( const auto& aInstanceParam )
78 {
79 return modelParam.name.substr( 0, modelParam.name.length() - 1 )
80 == aInstanceParam.name;
81 } ) );
82 }
83 }
84 }
85
86 // Ensure there's no instance parameters that have the same name.
87 for( const SIM_MODEL::PARAM::INFO& instanceParam : instanceParams )
88 {
89 BOOST_TEST_CONTEXT( "Instance param name: " << instanceParam.name )
90 {
91 BOOST_CHECK( std::none_of( instanceParams.begin(), instanceParams.end(),
92 [&instanceParam]( const auto& aOtherInstanceParam )
93 {
94 return instanceParam.id != aOtherInstanceParam.id
95 && instanceParam.dir != SIM_MODEL::PARAM::DIR_OUT
96 && aOtherInstanceParam.dir != SIM_MODEL::PARAM::DIR_OUT
97 && instanceParam.name == aOtherInstanceParam.name;
98 } ) );
99 }
100 }
101 }
102 }
103}
104
105
107{
108 // Count the total number of model and instance parameters for each model so that there will be
109 // an error if someone accidentally removes a parameter.
110
111 for( MODEL_TYPE type : MODEL_TYPE_ITERATOR() )
112 {
113 const std::vector<SIM_MODEL::PARAM::INFO> modelParams = ModelInfo( type ).modelParams;
114 const std::vector<SIM_MODEL::PARAM::INFO> instanceParams = ModelInfo( type ).instanceParams;
115
116 switch( type )
117 {
118 case MODEL_TYPE::NONE:
119 case MODEL_TYPE::_ENUM_END:
120 break;
121
122 /*case MODEL_TYPE::RESISTOR:
123 BOOST_CHECK_EQUAL( modelParams.size(), 22 );
124 BOOST_CHECK_EQUAL( instanceParams.size(), 25 );
125 break;
126
127 case MODEL_TYPE::CAPACITOR:
128 BOOST_CHECK_EQUAL( modelParams.size(), 19 );
129 BOOST_CHECK_EQUAL( instanceParams.size(), 22 );
130 break;
131
132 case MODEL_TYPE::INDUCTOR:
133 BOOST_CHECK_EQUAL( modelParams.size(), 9 );
134 BOOST_CHECK_EQUAL( instanceParams.size(), 20 );
135 break;*/
136
137 /*case MODEL_TYPE::LTRA:
138 BOOST_CHECK_EQUAL( modelParams.size(), 18 );
139 BOOST_CHECK_EQUAL( instanceParams.size(), 9 );
140 break;
141
142 case MODEL_TYPE::TRANLINE:
143 BOOST_CHECK_EQUAL( modelParams.size(), 0 );
144 BOOST_CHECK_EQUAL( instanceParams.size(), 17 );
145 break;
146
147 case MODEL_TYPE::URC:
148 BOOST_CHECK_EQUAL( modelParams.size(), 7 );
149 BOOST_CHECK_EQUAL( instanceParams.size(), 5 );
150 break;*/
151
152 /*case MODEL_TYPE::TRANSLINE:
153 BOOST_CHECK_EQUAL( modelParams.size(), 6 );
154 BOOST_CHECK_EQUAL( instanceParams.size(), 3 );
155 break;*/
156
157 /*case MODEL_TYPE::SWITCH:
158 BOOST_CHECK_EQUAL( modelParams.size(), 7 );
159 BOOST_CHECK_EQUAL( instanceParams.size(), 8 );
160 break;
161
162 case MODEL_TYPE::CSWITCH:
163 BOOST_CHECK_EQUAL( modelParams.size(), 7 );
164 BOOST_CHECK_EQUAL( instanceParams.size(), 7 );
165 break;*/
166
167 case MODEL_TYPE::DIODE:
168 BOOST_CHECK_EQUAL( modelParams.size(), 76 );
169 BOOST_CHECK_EQUAL( instanceParams.size(), 30 );
170 break;
171
172 case MODEL_TYPE::BJT:
173 BOOST_CHECK_EQUAL( modelParams.size(), 152 );
174 BOOST_CHECK_EQUAL( instanceParams.size(), 53 );
175 break;
176
177 case MODEL_TYPE::VBIC:
178 BOOST_CHECK_EQUAL( modelParams.size(), 117 );
179 BOOST_CHECK_EQUAL( instanceParams.size(), 45 );
180 break;
181
182 case MODEL_TYPE::HICUM2:
183 BOOST_CHECK_EQUAL( modelParams.size(), 149 );
184 BOOST_CHECK_EQUAL( instanceParams.size(), 61 );
185 break;
186
187 case MODEL_TYPE::JFET:
188 BOOST_CHECK_EQUAL( modelParams.size(), 34 );
189 BOOST_CHECK_EQUAL( instanceParams.size(), 28 );
190 break;
191
192 case MODEL_TYPE::JFET2:
193 BOOST_CHECK_EQUAL( modelParams.size(), 46 );
194 BOOST_CHECK_EQUAL( instanceParams.size(), 30 );
195 break;
196
197 case MODEL_TYPE::MES:
198 BOOST_CHECK_EQUAL( modelParams.size(), 22 );
199 BOOST_CHECK_EQUAL( instanceParams.size(), 25 );
200 break;
201
202 case MODEL_TYPE::MESA:
203 BOOST_CHECK_EQUAL( modelParams.size(), 71 );
204 BOOST_CHECK_EQUAL( instanceParams.size(), 30 );
205 break;
206
207 case MODEL_TYPE::HFET1:
208 BOOST_CHECK_EQUAL( modelParams.size(), 68 );
209 BOOST_CHECK_EQUAL( instanceParams.size(), 28 );
210 break;
211
212 case MODEL_TYPE::HFET2:
213 BOOST_CHECK_EQUAL( modelParams.size(), 40 );
214 BOOST_CHECK_EQUAL( instanceParams.size(), 28 );
215 break;
216
217 case MODEL_TYPE::VDMOS:
218 BOOST_CHECK_EQUAL( modelParams.size(), 69 );
219 BOOST_CHECK_EQUAL( instanceParams.size(), 36 );
220 break;
221
222 case MODEL_TYPE::MOS1:
223 BOOST_CHECK_EQUAL( modelParams.size(), 35 );
224 BOOST_CHECK_EQUAL( instanceParams.size(), 76 );
225 break;
226
227 case MODEL_TYPE::MOS2:
228 BOOST_CHECK_EQUAL( modelParams.size(), 42 );
229 BOOST_CHECK_EQUAL( instanceParams.size(), 76 );
230 break;
231
232 case MODEL_TYPE::MOS3:
233 BOOST_CHECK_EQUAL( modelParams.size(), 48 );
234 BOOST_CHECK_EQUAL( instanceParams.size(), 81 );
235 break;
236
237 case MODEL_TYPE::BSIM1:
238 BOOST_CHECK_EQUAL( modelParams.size(), 81 );
239 BOOST_CHECK_EQUAL( instanceParams.size(), 14 );
240 break;
241
242 case MODEL_TYPE::BSIM2:
243 BOOST_CHECK_EQUAL( modelParams.size(), 137 );
244 BOOST_CHECK_EQUAL( instanceParams.size(), 14 );
245 break;
246
247 case MODEL_TYPE::MOS6:
248 BOOST_CHECK_EQUAL( modelParams.size(), 42 );
249 BOOST_CHECK_EQUAL( instanceParams.size(), 78 );
250 break;
251
252 case MODEL_TYPE::BSIM3:
253 BOOST_CHECK_EQUAL( modelParams.size(), 429 );
254 BOOST_CHECK_EQUAL( instanceParams.size(), 46 );
255 break;
256
257 case MODEL_TYPE::MOS9:
258 BOOST_CHECK_EQUAL( modelParams.size(), 48 );
259 BOOST_CHECK_EQUAL( instanceParams.size(), 81 );
260 break;
261
262 case MODEL_TYPE::B4SOI:
263 BOOST_CHECK_EQUAL( modelParams.size(), 915 );
264 BOOST_CHECK_EQUAL( instanceParams.size(), 74 );
265 break;
266
267 case MODEL_TYPE::BSIM4:
268 BOOST_CHECK_EQUAL( modelParams.size(), 892 );
269 BOOST_CHECK_EQUAL( instanceParams.size(), 84 );
270 break;
271
272 case MODEL_TYPE::B3SOIFD:
273 BOOST_CHECK_EQUAL( modelParams.size(), 393 );
274 BOOST_CHECK_EQUAL( instanceParams.size(), 27 );
275 break;
276
277 case MODEL_TYPE::B3SOIDD:
278 BOOST_CHECK_EQUAL( modelParams.size(), 393 );
279 BOOST_CHECK_EQUAL( instanceParams.size(), 27 );
280 break;
281
282 case MODEL_TYPE::B3SOIPD:
283 BOOST_CHECK_EQUAL( modelParams.size(), 470 );
284 BOOST_CHECK_EQUAL( instanceParams.size(), 36 );
285 break;
286
287 case MODEL_TYPE::HISIM2:
288 BOOST_CHECK_EQUAL( modelParams.size(), 486 );
289 BOOST_CHECK_EQUAL( instanceParams.size(), 59 );
290 break;
291
292 case MODEL_TYPE::HISIMHV1:
293 BOOST_CHECK_EQUAL( modelParams.size(), 610 );
294 BOOST_CHECK_EQUAL( instanceParams.size(), 72 );
295 break;
296
297 case MODEL_TYPE::HISIMHV2:
298 BOOST_CHECK_EQUAL( modelParams.size(), 730 );
299 BOOST_CHECK_EQUAL( instanceParams.size(), 74 );
300 break;
301
302 default:
303 BOOST_FAIL( wxString::Format(
304 "Unhandled type: %d "
305 "(if you created a new type you need to handle it in this switch "
306 "statement)",
307 type ) );
308 }
309 }
310}
311
312
const char * name
Definition: DXF_plotter.cpp:57
@ NONE
No connection to this item.
SIM_MODEL::TYPE TYPE
Definition: sim_model.cpp:57
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(ParamDuplicates)