ZLayout EDA Library v1.0.0
Advanced Electronic Design Automation Layout Library with Bilingual Documentation
Loading...
Searching...
No Matches
passive_components.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
12#include <memory>
13#include <string>
14#include <vector>
15
16namespace zlayout {
17namespace components {
18
22class Resistor : public Component {
23public:
24 Resistor(const std::string& name, double resistance, double tolerance = 5.0);
25
26 // Electrical properties
27 double getResistance() const { return resistance_; }
28 void setResistance(double resistance);
29
30 double getTolerance() const { return tolerance_; }
31 void setTolerance(double tolerance) { tolerance_ = tolerance; }
32
33 double getPowerRating() const { return power_rating_; }
34 void setPowerRating(double power) { power_rating_ = power; }
35
36 // Temperature coefficient
37 double getTempCoeff() const { return temp_coeff_; }
38 void setTempCoeff(double coeff) { temp_coeff_ = coeff; }
39
40 // Standard values
41 static std::vector<double> getStandardValues(); // E12, E24, E48, E96 series
42 static double getNearestStandardValue(double value, int series = 24);
43
44 // Parasitic effects
45 double getParasiticCapacitance() const { return parasitic_capacitance_; }
46 double getParasiticInductance() const { return parasitic_inductance_; }
47
48 // Simulation
49 void simulate(double time_step) override;
50 std::string getDescription() const override;
51
52private:
53 double resistance_; // Ω
54 double tolerance_; // %
55 double power_rating_; // W
56 double temp_coeff_; // ppm/°C
57 double parasitic_capacitance_; // pF
58 double parasitic_inductance_; // nH
59};
60
64class Capacitor : public Component {
65public:
66 enum class DielectricType {
67 Ceramic, // C0G, X7R, Y5V
68 Electrolytic, // Aluminum, Tantalum
69 Film, // Polyester, Polypropylene
70 Mica, // Silver mica
71 Supercap // Super capacitor
72 };
73
74 Capacitor(const std::string& name, double capacitance, DielectricType dielectric);
75
76 // Electrical properties
77 double getCapacitance() const { return capacitance_; }
78 void setCapacitance(double capacitance);
79
80 double getTolerance() const { return tolerance_; }
81 void setTolerance(double tolerance) { tolerance_ = tolerance; }
82
83 double getVoltageRating() const { return voltage_rating_; }
84 void setVoltageRating(double voltage) { voltage_rating_ = voltage; }
85
86 DielectricType getDielectric() const { return dielectric_; }
87 void setDielectric(DielectricType type) { dielectric_ = type; }
88
89 // Parasitic effects
90 double getESR() const { return esr_; } // Equivalent Series Resistance
91 void setESR(double esr) { esr_ = esr; }
92
93 double getESL() const { return esl_; } // Equivalent Series Inductance
94 void setESL(double esl) { esl_ = esl; }
95
96 double getLeakageCurrent() const { return leakage_current_; }
97 void setLeakageCurrent(double current) { leakage_current_ = current; }
98
99 // Temperature characteristics
100 double getTempCoeff() const { return temp_coeff_; }
101 void setTempCoeff(double coeff) { temp_coeff_ = coeff; }
102
103 // Standard values
104 static std::vector<double> getStandardValues();
105 static double getNearestStandardValue(double value);
106
107 // Simulation
108 void simulate(double time_step) override;
109 std::string getDescription() const override;
110
111private:
112 double capacitance_; // F
113 double tolerance_; // %
114 double voltage_rating_; // V
115 DielectricType dielectric_;
116 double esr_; // Ω
117 double esl_; // H
118 double leakage_current_; // A
119 double temp_coeff_; // ppm/°C
120
121 // State variables for simulation
122 double charge_; // C
123 double voltage_; // V
124};
125
129class Inductor : public Component {
130public:
131 enum class CoreType {
132 Air, // Air core
133 Ferrite, // Ferrite core
134 Iron, // Iron core
135 Laminated, // Laminated iron
136 Powdered // Powdered iron
137 };
138
139 Inductor(const std::string& name, double inductance, CoreType core);
140
141 // Electrical properties
142 double getInductance() const { return inductance_; }
143 void setInductance(double inductance);
144
145 double getTolerance() const { return tolerance_; }
146 void setTolerance(double tolerance) { tolerance_ = tolerance; }
147
148 double getCurrentRating() const { return current_rating_; }
149 void setCurrentRating(double current) { current_rating_ = current; }
150
151 CoreType getCoreType() const { return core_type_; }
152 void setCoreType(CoreType type) { core_type_ = type; }
153
154 // Parasitic effects
155 double getDCR() const { return dcr_; } // DC Resistance
156 void setDCR(double dcr) { dcr_ = dcr; }
157
158 double getSRF() const { return srf_; } // Self Resonant Frequency
159 void setSRF(double srf) { srf_ = srf; }
160
161 double getParasiticCapacitance() const { return parasitic_capacitance_; }
162 void setParasiticCapacitance(double cap) { parasitic_capacitance_ = cap; }
163
164 // Magnetic properties
165 double getSaturationCurrent() const { return saturation_current_; }
166 void setSaturationCurrent(double current) { saturation_current_ = current; }
167
168 double getQualityFactor() const { return quality_factor_; }
169 void setQualityFactor(double q) { quality_factor_ = q; }
170
171 // Standard values
172 static std::vector<double> getStandardValues();
173 static double getNearestStandardValue(double value);
174
175 // Simulation
176 void simulate(double time_step) override;
177 std::string getDescription() const override;
178
179private:
180 double inductance_; // H
181 double tolerance_; // %
182 double current_rating_; // A
183 CoreType core_type_;
184 double dcr_; // Ω
185 double srf_; // Hz
186 double parasitic_capacitance_; // F
187 double saturation_current_; // A
188 double quality_factor_; // Q
189
190 // State variables for simulation
191 double current_; // A
192 double flux_; // Wb
193};
194
198class Crystal : public Component {
199public:
200 enum class CrystalType {
201 Quartz, // Quartz crystal
202 SAW, // Surface Acoustic Wave
203 MEMS, // Microelectromechanical systems
204 Ceramic // Ceramic resonator
205 };
206
207 Crystal(const std::string& name, double frequency, CrystalType type);
208
209 // Frequency characteristics
210 double getFrequency() const { return frequency_; }
211 void setFrequency(double freq) { frequency_ = freq; }
212
213 double getFrequencyTolerance() const { return frequency_tolerance_; }
214 void setFrequencyTolerance(double tolerance) { frequency_tolerance_ = tolerance; }
215
216 double getFrequencyStability() const { return frequency_stability_; }
217 void setFrequencyStability(double stability) { frequency_stability_ = stability; }
218
219 CrystalType getCrystalType() const { return crystal_type_; }
220 void setCrystalType(CrystalType type) { crystal_type_ = type; }
221
222 // Electrical model
223 double getMotionalCapacitance() const { return c1_; }
224 void setMotionalCapacitance(double c1) { c1_ = c1; }
225
226 double getMotionalInductance() const { return l1_; }
227 void setMotionalInductance(double l1) { l1_ = l1; }
228
229 double getMotionalResistance() const { return r1_; }
230 void setMotionalResistance(double r1) { r1_ = r1; }
231
232 double getShuntCapacitance() const { return c0_; }
233 void setShuntCapacitance(double c0) { c0_ = c0; }
234
235 // Drive level
236 double getDriveLevel() const { return drive_level_; }
237 void setDriveLevel(double level) { drive_level_ = level; }
238
239 // Simulation
240 void simulate(double time_step) override;
241 std::string getDescription() const override;
242
243private:
244 double frequency_; // Hz
245 double frequency_tolerance_; // ppm
246 double frequency_stability_; // ppm
247 CrystalType crystal_type_;
248
249 // Equivalent circuit model
250 double c1_; // F (motional capacitance)
251 double l1_; // H (motional inductance)
252 double r1_; // Ω (motional resistance)
253 double c0_; // F (shunt capacitance)
254 double drive_level_; // W
255};
256
260class Transformer : public Component {
261public:
262 enum class TransformerType {
263 Power, // Power transformer
264 Signal, // Signal transformer
265 Isolation, // Isolation transformer
266 Current, // Current transformer
267 Voltage // Voltage transformer
268 };
269
270 Transformer(const std::string& name, double turns_ratio, TransformerType type);
271
272 // Turns ratio
273 double getTurnsRatio() const { return turns_ratio_; }
274 void setTurnsRatio(double ratio) { turns_ratio_ = ratio; }
275
276 TransformerType getTransformerType() const { return transformer_type_; }
277 void setTransformerType(TransformerType type) { transformer_type_ = type; }
278
279 // Electrical parameters
280 double getPrimaryInductance() const { return primary_inductance_; }
281 void setPrimaryInductance(double l) { primary_inductance_ = l; }
282
283 double getSecondaryInductance() const { return secondary_inductance_; }
284 void setSecondaryInductance(double l) { secondary_inductance_ = l; }
285
286 double getMutualInductance() const { return mutual_inductance_; }
287 void setMutualInductance(double m) { mutual_inductance_ = m; }
288
289 double getCouplingCoefficient() const { return coupling_coefficient_; }
290 void setCouplingCoefficient(double k) { coupling_coefficient_ = k; }
291
292 // Resistance
293 double getPrimaryResistance() const { return primary_resistance_; }
294 void setPrimaryResistance(double r) { primary_resistance_ = r; }
295
296 double getSecondaryResistance() const { return secondary_resistance_; }
297 void setSecondaryResistance(double r) { secondary_resistance_ = r; }
298
299 // Power rating
300 double getPowerRating() const { return power_rating_; }
301 void setPowerRating(double power) { power_rating_ = power; }
302
303 // Simulation
304 void simulate(double time_step) override;
305 std::string getDescription() const override;
306
307private:
308 double turns_ratio_; // N2/N1
309 TransformerType transformer_type_;
310 double primary_inductance_; // H
311 double secondary_inductance_; // H
312 double mutual_inductance_; // H
313 double coupling_coefficient_; // k
314 double primary_resistance_; // Ω
315 double secondary_resistance_; // Ω
316 double power_rating_; // W
317};
318
323public:
324 // Standard component creation
325 static std::shared_ptr<Resistor> createResistor(
326 const std::string& name, double resistance, double tolerance = 5.0);
327
328 static std::shared_ptr<Capacitor> createCapacitor(
329 const std::string& name, double capacitance,
331
332 static std::shared_ptr<Inductor> createInductor(
333 const std::string& name, double inductance,
335
336 static std::shared_ptr<Crystal> createCrystal(
337 const std::string& name, double frequency,
339
340 static std::shared_ptr<Transformer> createTransformer(
341 const std::string& name, double turns_ratio,
343
344 // Component from specifications
345 static std::shared_ptr<Component> createFromSpecs(
346 const std::string& component_type, const std::string& name,
347 const std::map<std::string, std::string>& specs);
348
349 // Standard library components
351};
352
353} // namespace components
354} // namespace zlayout
void setTolerance(double tolerance)
static double getNearestStandardValue(double value)
void simulate(double time_step) override
static std::vector< double > getStandardValues()
std::string getDescription() const override
DielectricType getDielectric() const
void setCapacitance(double capacitance)
Capacitor(const std::string &name, double capacitance, DielectricType dielectric)
void setDielectric(DielectricType type)
Component(const std::string &name, ComponentCategory category)
Component library for managing component definitions.
std::string getDescription() const override
Crystal(const std::string &name, double frequency, CrystalType type)
void setCrystalType(CrystalType type)
void setFrequencyStability(double stability)
void simulate(double time_step) override
void setFrequencyTolerance(double tolerance)
static std::vector< double > getStandardValues()
std::string getDescription() const override
void simulate(double time_step) override
void setTolerance(double tolerance)
static double getNearestStandardValue(double value)
void setSaturationCurrent(double current)
void setInductance(double inductance)
Inductor(const std::string &name, double inductance, CoreType core)
static std::shared_ptr< Resistor > createResistor(const std::string &name, double resistance, double tolerance=5.0)
static std::shared_ptr< Transformer > createTransformer(const std::string &name, double turns_ratio, Transformer::TransformerType type=Transformer::TransformerType::Signal)
static std::shared_ptr< Crystal > createCrystal(const std::string &name, double frequency, Crystal::CrystalType type=Crystal::CrystalType::Quartz)
static std::shared_ptr< Capacitor > createCapacitor(const std::string &name, double capacitance, Capacitor::DielectricType dielectric=Capacitor::DielectricType::Ceramic)
static void registerStandardComponents(ComponentLibrary &library)
static std::shared_ptr< Component > createFromSpecs(const std::string &component_type, const std::string &name, const std::map< std::string, std::string > &specs)
static std::shared_ptr< Inductor > createInductor(const std::string &name, double inductance, Inductor::CoreType core=Inductor::CoreType::Air)
void setTolerance(double tolerance)
static std::vector< double > getStandardValues()
void setResistance(double resistance)
std::string getDescription() const override
static double getNearestStandardValue(double value, int series=24)
Resistor(const std::string &name, double resistance, double tolerance=5.0)
void simulate(double time_step) override
void setTransformerType(TransformerType type)
void simulate(double time_step) override
TransformerType getTransformerType() const
Transformer(const std::string &name, double turns_ratio, TransformerType type)
std::string getDescription() const override
Hierarchical EDA Component System.
Main namespace for ZLayout library.
Definition component.hpp:20