Skip to content

Instantly share code, notes, and snippets.

@Denzo77
Denzo77 / energyplus_pyfmu_example.py
Created March 25, 2020 12:43
Example usage of EnergyPlus hosted by PyFMI, including changing variables.
from pyfmi import load_fmu
import numpy as np
import matplotlib.pyplot as plt
# Runs the "Actuator" example provided by EnergyPlusToFMU
# Adapted from https://gist.github.com/TStesco/d02d19e7e382ab8c37d51c96d7891f6d
# Tested with:
# - Fedora 31 (up to date as of 2020-03-25)
# - EnergyPlus v9.0.1
# - EnergyPlusToFMU v2.1.0
@Denzo77
Denzo77 / single_instance.cpp
Last active August 21, 2020 20:02
Alternative to Singleton pattern for enforcing singleton classes in cpp, originally posted on https://stackoverflow.com/questions/3926530/a-singleton-that-is-not-globally-accessible/3926915#3926915
#include <stdexcept>
// inherit from this class (privately) to ensure only a single instance
// of the derived class is created using runtime checking.
template <typename D> // CRTP (to give each instantiation its own flag)
class single_instance
{
protected: // protected constructors to ensure this is used as a mixin
single_instance()
{
@Denzo77
Denzo77 / newtype.h
Last active February 19, 2020 13:01
An example generic newtype implementation for cpp. See https://github.com/satori16/NewType for another take on this.
/**
* @brief Newtype pattern impl for cpp. Derives a new type from one that
* implements arithmetic operations to allow typesafe arithmetic.
*
* # Purpose:
* It is useful to restrict arithmetic on builtin types to
* variables that represent the same quantity, e.g. only allow 'meters' to be
* added to 'meters'. This struct provides a template definition for easily
* deriving these 'new types'.
*