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 The 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, see <https://www.gnu.org/licenses/>.
18 */
19
22#include <boost/algorithm/string/predicate.hpp>
23
24
32
33
34BOOST_FIXTURE_TEST_SUITE( SimModelNgspice, TEST_SIM_MODEL_NGSPICE_FIXTURE )
35
36
37BOOST_AUTO_TEST_CASE( ParamDuplicates )
38{
39 for( MODEL_TYPE type : MODEL_TYPE_ITERATOR() )
40 {
41 BOOST_TEST_CONTEXT( "Model name: " << ModelInfo( type ).name )
42 {
43 const std::vector<SIM_MODEL::PARAM::INFO> modelParams = ModelInfo( type ).modelParams;
44 const std::vector<SIM_MODEL::PARAM::INFO> instanceParams = ModelInfo( type ).instanceParams;
45
46 for( const SIM_MODEL::PARAM::INFO& modelParam : modelParams )
47 {
48 BOOST_TEST_CONTEXT( "Model param name: " << modelParam.name )
49 {
50 // Ensure there's no model parameters that have the same name.
51 BOOST_CHECK( std::none_of( modelParams.begin(), modelParams.end(),
52 [&modelParam]( const auto& aOtherModelParam )
53 {
54 return modelParam.id != aOtherModelParam.id
55 && modelParam.name == aOtherModelParam.name;
56 } ) );
57
58 // Ensure there's no model parameters that have the same name as an
59 // instance parameter.
60 BOOST_CHECK( std::none_of( instanceParams.begin(), instanceParams.end(),
61 [&modelParam]( const auto& aInstanceParam )
62 {
63 return modelParam.name == aInstanceParam.name;
64 } ) );
65
66 if( boost::ends_with( modelParam.name, "_" ) )
67 {
68 // Ensure that for each model parameter ending with a "_" there exists an
69 // instance parameter with the same name but without this final character.
70 // We append an "_" to model parameters to disambiguate from these
71 // corresponding instance parameters.
72 BOOST_CHECK( std::any_of( instanceParams.begin(), instanceParams.end(),
73 [&modelParam]( const auto& aInstanceParam )
74 {
75 return modelParam.name.substr( 0, modelParam.name.length() - 1 )
76 == aInstanceParam.name;
77 } ) );
78 }
79 }
80 }
81
82 // Ensure there's no instance parameters that have the same name.
83 for( const SIM_MODEL::PARAM::INFO& instanceParam : instanceParams )
84 {
85 BOOST_TEST_CONTEXT( "Instance param name: " << instanceParam.name )
86 {
87 BOOST_CHECK( std::none_of( instanceParams.begin(), instanceParams.end(),
88 [&instanceParam]( const auto& aOtherInstanceParam )
89 {
90 return instanceParam.id != aOtherInstanceParam.id
91 && instanceParam.dir != SIM_MODEL::PARAM::DIR_OUT
92 && aOtherInstanceParam.dir != SIM_MODEL::PARAM::DIR_OUT
93 && instanceParam.name == aOtherInstanceParam.name;
94 } ) );
95 }
96 }
97 }
98 }
99}
100
101
103{
104 // Count the total number of model and instance parameters for each model so that there will be
105 // an error if someone accidentally removes a parameter.
106
107 for( MODEL_TYPE type : MODEL_TYPE_ITERATOR() )
108 {
109 const std::vector<SIM_MODEL::PARAM::INFO> modelParams = ModelInfo( type ).modelParams;
110 const std::vector<SIM_MODEL::PARAM::INFO> instanceParams = ModelInfo( type ).instanceParams;
111
112 switch( type )
113 {
114 case MODEL_TYPE::NONE:
115 case MODEL_TYPE::_ENUM_END:
116 break;
117
118 /*case MODEL_TYPE::RESISTOR:
119 BOOST_CHECK_EQUAL( modelParams.size(), 22 );
120 BOOST_CHECK_EQUAL( instanceParams.size(), 25 );
121 break;
122
123 case MODEL_TYPE::CAPACITOR:
124 BOOST_CHECK_EQUAL( modelParams.size(), 19 );
125 BOOST_CHECK_EQUAL( instanceParams.size(), 22 );
126 break;
127
128 case MODEL_TYPE::INDUCTOR:
129 BOOST_CHECK_EQUAL( modelParams.size(), 9 );
130 BOOST_CHECK_EQUAL( instanceParams.size(), 20 );
131 break;*/
132
133 /*case MODEL_TYPE::LTRA:
134 BOOST_CHECK_EQUAL( modelParams.size(), 18 );
135 BOOST_CHECK_EQUAL( instanceParams.size(), 9 );
136 break;
137
138 case MODEL_TYPE::TRANLINE:
139 BOOST_CHECK_EQUAL( modelParams.size(), 0 );
140 BOOST_CHECK_EQUAL( instanceParams.size(), 17 );
141 break;
142
143 case MODEL_TYPE::URC:
144 BOOST_CHECK_EQUAL( modelParams.size(), 7 );
145 BOOST_CHECK_EQUAL( instanceParams.size(), 5 );
146 break;*/
147
148 /*case MODEL_TYPE::TRANSLINE:
149 BOOST_CHECK_EQUAL( modelParams.size(), 6 );
150 BOOST_CHECK_EQUAL( instanceParams.size(), 3 );
151 break;*/
152
153 /*case MODEL_TYPE::SWITCH:
154 BOOST_CHECK_EQUAL( modelParams.size(), 7 );
155 BOOST_CHECK_EQUAL( instanceParams.size(), 8 );
156 break;
157
158 case MODEL_TYPE::CSWITCH:
159 BOOST_CHECK_EQUAL( modelParams.size(), 7 );
160 BOOST_CHECK_EQUAL( instanceParams.size(), 7 );
161 break;*/
162
163 case MODEL_TYPE::DIODE:
164 BOOST_CHECK_EQUAL( modelParams.size(), 76 );
165 BOOST_CHECK_EQUAL( instanceParams.size(), 30 );
166 break;
167
168 case MODEL_TYPE::BJT:
169 BOOST_CHECK_EQUAL( modelParams.size(), 152 );
170 BOOST_CHECK_EQUAL( instanceParams.size(), 53 );
171 break;
172
173 case MODEL_TYPE::VBIC:
174 BOOST_CHECK_EQUAL( modelParams.size(), 117 );
175 BOOST_CHECK_EQUAL( instanceParams.size(), 45 );
176 break;
177
178 case MODEL_TYPE::HICUM2:
179 BOOST_CHECK_EQUAL( modelParams.size(), 149 );
180 BOOST_CHECK_EQUAL( instanceParams.size(), 61 );
181 break;
182
183 case MODEL_TYPE::JFET:
184 BOOST_CHECK_EQUAL( modelParams.size(), 34 );
185 BOOST_CHECK_EQUAL( instanceParams.size(), 28 );
186 break;
187
188 case MODEL_TYPE::JFET2:
189 BOOST_CHECK_EQUAL( modelParams.size(), 46 );
190 BOOST_CHECK_EQUAL( instanceParams.size(), 30 );
191 break;
192
193 case MODEL_TYPE::MES:
194 BOOST_CHECK_EQUAL( modelParams.size(), 22 );
195 BOOST_CHECK_EQUAL( instanceParams.size(), 25 );
196 break;
197
198 case MODEL_TYPE::MESA:
199 BOOST_CHECK_EQUAL( modelParams.size(), 71 );
200 BOOST_CHECK_EQUAL( instanceParams.size(), 30 );
201 break;
202
203 case MODEL_TYPE::HFET1:
204 BOOST_CHECK_EQUAL( modelParams.size(), 68 );
205 BOOST_CHECK_EQUAL( instanceParams.size(), 28 );
206 break;
207
208 case MODEL_TYPE::HFET2:
209 BOOST_CHECK_EQUAL( modelParams.size(), 40 );
210 BOOST_CHECK_EQUAL( instanceParams.size(), 28 );
211 break;
212
213 case MODEL_TYPE::VDMOS:
214 BOOST_CHECK_EQUAL( modelParams.size(), 69 );
215 BOOST_CHECK_EQUAL( instanceParams.size(), 36 );
216 break;
217
218 case MODEL_TYPE::MOS1:
219 BOOST_CHECK_EQUAL( modelParams.size(), 35 );
220 BOOST_CHECK_EQUAL( instanceParams.size(), 76 );
221 break;
222
223 case MODEL_TYPE::MOS2:
224 BOOST_CHECK_EQUAL( modelParams.size(), 42 );
225 BOOST_CHECK_EQUAL( instanceParams.size(), 76 );
226 break;
227
228 case MODEL_TYPE::MOS3:
229 BOOST_CHECK_EQUAL( modelParams.size(), 48 );
230 BOOST_CHECK_EQUAL( instanceParams.size(), 81 );
231 break;
232
233 case MODEL_TYPE::BSIM1:
234 BOOST_CHECK_EQUAL( modelParams.size(), 81 );
235 BOOST_CHECK_EQUAL( instanceParams.size(), 14 );
236 break;
237
238 case MODEL_TYPE::BSIM2:
239 BOOST_CHECK_EQUAL( modelParams.size(), 137 );
240 BOOST_CHECK_EQUAL( instanceParams.size(), 14 );
241 break;
242
243 case MODEL_TYPE::MOS6:
244 BOOST_CHECK_EQUAL( modelParams.size(), 42 );
245 BOOST_CHECK_EQUAL( instanceParams.size(), 78 );
246 break;
247
248 case MODEL_TYPE::BSIM3:
249 BOOST_CHECK_EQUAL( modelParams.size(), 429 );
250 BOOST_CHECK_EQUAL( instanceParams.size(), 46 );
251 break;
252
253 case MODEL_TYPE::MOS9:
254 BOOST_CHECK_EQUAL( modelParams.size(), 48 );
255 BOOST_CHECK_EQUAL( instanceParams.size(), 81 );
256 break;
257
258 case MODEL_TYPE::B4SOI:
259 BOOST_CHECK_EQUAL( modelParams.size(), 915 );
260 BOOST_CHECK_EQUAL( instanceParams.size(), 74 );
261 break;
262
263 case MODEL_TYPE::BSIM4:
264 BOOST_CHECK_EQUAL( modelParams.size(), 892 );
265 BOOST_CHECK_EQUAL( instanceParams.size(), 84 );
266 break;
267
268 case MODEL_TYPE::B3SOIFD:
269 BOOST_CHECK_EQUAL( modelParams.size(), 393 );
270 BOOST_CHECK_EQUAL( instanceParams.size(), 27 );
271 break;
272
273 case MODEL_TYPE::B3SOIDD:
274 BOOST_CHECK_EQUAL( modelParams.size(), 393 );
275 BOOST_CHECK_EQUAL( instanceParams.size(), 27 );
276 break;
277
278 case MODEL_TYPE::B3SOIPD:
279 BOOST_CHECK_EQUAL( modelParams.size(), 470 );
280 BOOST_CHECK_EQUAL( instanceParams.size(), 36 );
281 break;
282
283 case MODEL_TYPE::HISIM2:
284 BOOST_CHECK_EQUAL( modelParams.size(), 486 );
285 BOOST_CHECK_EQUAL( instanceParams.size(), 59 );
286 break;
287
288 case MODEL_TYPE::HISIMHV1:
289 BOOST_CHECK_EQUAL( modelParams.size(), 610 );
290 BOOST_CHECK_EQUAL( instanceParams.size(), 72 );
291 break;
292
293 case MODEL_TYPE::HISIMHV2:
294 BOOST_CHECK_EQUAL( modelParams.size(), 730 );
295 BOOST_CHECK_EQUAL( instanceParams.size(), 74 );
296 break;
297
298 default:
299 BOOST_FAIL( wxString::Format(
300 "Unhandled type: %d "
301 "(if you created a new type you need to handle it in this switch "
302 "statement)",
303 type ) );
304 }
305 }
306}
307
308
const char * name
SIM_MODEL_NGSPICE(TYPE aType)
@ NONE
Definition eda_shape.h:72
SIM_MODEL::TYPE TYPE
Definition sim_model.cpp:54
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_AUTO_TEST_CASE(ParamDuplicates)
BOOST_CHECK_EQUAL(result, "25.4")