Lab Project
โก CircuitSim¶
Learning Professional Software Design & Architecture through Simulation
๐ฏ Motivation¶
Why CircuitSim?
- To apply theoretical knowledge to a real-world project
- To learn professional C++17 design and architecture
- To understand how to structure, test, and evolve real software
- To connect engineering with software architecture thinking
๐งฉ What is CircuitSim?¶
A modular simulation framework for modeling electrical circuits in modern C++.
Youโll design and build a system that:
- models components like resistors, switches, batteries
- allows circuits to be combined (series, parallel)
- measures voltage and current
- later: simulates time-dependent behavior (capacitors, etc.)
๐งฑ Learning Goals¶
You will learn to:
- Design extensible class hierarchies (inheritance, composition)
- Apply design patterns (Composite, Strategy, State, Observer)
- Use CMake and GoogleTest professionally
- Write maintainable, testable, modern C++ code
- Refactor for clarity and flexibility
๐งฐ Tools and Technology¶
| Tool | Purpose |
|---|---|
| C++17 | Core programming language |
| CMake | Build system & dependency management |
| GoogleTest | Unit testing |
| Git | Version control |
| Linux | Target platform |
๐งฉ Architecture Overview¶
Component (interface)
โ
โโโ Resistor
โโโ VoltageSource
โโโ Battery
โโโ Switch
โ
โโโ SeriesCircuit (Composite)
โโโ ParallelCircuit (Composite)
Later:
โโโ Capacitor
โโโ DCSolver
โโโ Multimeter
All components follow the same base interface and can be combined freely.
๐งฎ Example: Modeling a Simple Circuit¶
Looking into the future:
auto battery = std::make_shared<Battery>(9.0, 2000);
auto r1 = std::make_shared<Resistor>(3.0);
auto r2 = std::make_shared<Resistor>(6.0);
SeriesCircuit circuit({battery, r1, r2});
- Each component knows its voltage and current
- The
SeriesCircuitaggregates them - Later: a
DCSolverwill compute correct voltages & currents automatically
๐งญ Rough Course Roadmap¶
May change according to progress in lecture!
Unit 1 โ Architecture & Configuration Management¶
- Setup project, review code, implement a first component (
VoltageSource)
Unit 2 โ Composition & Modeling¶
- Implement more components
Switch,SeriesCircuit,ParallelCircuit
Unit 3 โ Simulation & Dynamics¶
- Switch to
SmartPointers - Introduce
Step(dt), addCapacitorand time simulation
Unit 4 โ Refactoring & Patterns¶
- Refine design (Factory, Observer, Strategy)
Unit 5 โ Integration & Finalization¶
- Finishing touches, visualization, logging, export, ...
โ๏ธ Project Structure¶
circuitsim/
โโโ app/ # demo application
โโโ csim/inc/ # headers (.hpp)
โโโ csim/src/ # implementation (.cpp)
โโโ tests/ # unit tests (GoogleTest)
โโโ CMakeLists.txt # project build
Development artifacts:
csimlibprovides all functionality (library)csimcommand-line tool (executable)test_csimunit test (executable)
๐งช Testing Philosophy¶
Testing is part of the design process.
- Each component is independently verifiable
- High coverage with GoogleTest
- Fail fast, refactor safely
- Reuse tests as design documentation
๐งฉ Example Test Case
TEST(SeriesCircuitTest, CombinedVoltageIsSum) {
auto r1 = Resistor(100.0);
auto r2 = Resistor(200.0);
r1.SetVoltage(2.0);
r2.SetVoltage(4.0);
SeriesCircuit s({r1, r2});
EXPECT_NEAR(s.Voltage(), 6.0, 1e-9);
}
โ Clear โ Deterministic โ Physically meaningful
๐ Final Deliverable¶
By the end of the course, youโll have:
- โ A modular, testable simulation engine
- โ Clean, extensible architecture
- โ Comprehensive unit tests
- โ Full project build (CMake + GTest)
- โ Professional project template for other projects
๐ Next Steps¶
- Clone the starter repository
https://github.com/breiting/circuitsim- Build & run first tests
- Review code
- Implement a first component
- Document and commit regularly with git