Skip to content

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 SeriesCircuit aggregates them
  • Later: a DCSolver will 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), add Capacitor and 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:

  • csimlib provides all functionality (library)
  • csim command-line tool (executable)
  • test_csim unit 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

  1. Clone the starter repository
  2. https://github.com/breiting/circuitsim
  3. Build & run first tests
  4. Review code
  5. Implement a first component
  6. Document and commit regularly with git