Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/validate-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v5
with:
version: "0.5.26"
python-version: ${{ matrix.python-version }}
- name: Install the project
run: uv sync --all-extras --dev
Expand Down
22 changes: 6 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,12 @@ This repository ships with the [DoIt!](https://pydoit.org/) task automation tool

The following DoIt! tasks are available:

- `doc`: Generates Markdown tables from common-schema
- `render_template`: Demonstrate how to render a template
- `schema`: Generates JSON schema from common-schema
- `test`: Performs unit tests and example file validation tests
- `validate`: Validates common-schema against meta-schema

Details of some of the tasks above are explained more below.

### Rendering a Jinja Template: `render_template`

This task takes an example template using the [Jinja](https://palletsprojects.com/p/jinja/) templating system and renders it.
The example file used is located at `rendering_examples/template_rendering/main.md`.
The base file is written in the [Markdown](https://commonmark.org/) language.
It includes examples of using the `add_schema_table` hook to insert Schema 205 tables into markdown text.

The rendered result appears in `build/rendered_template/main.md`.
- `generate_markdown`: Generates Markdown tables from common-schema
- `generate_web_docs`: Generates web documentation from templates
- `generate_meta_schemas`: Generates validation files for common-schema
- `generate_json_schemas`: Generates JSON schema from common-schema
- `validate_schemas`: Validates common-schema against meta-schema
- `generate_cpp_project`: Generates header and source files, with basic CMake build integration


Development Workflow
Expand Down
40 changes: 40 additions & 0 deletions cpp/base_classes/grid-variables-template.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef GRID_VARIABLES_BASE_H_
#define GRID_VARIABLES_BASE_H_

#include <memory>
#include <vector>
#include <iostream>
#include <sstream>

#include <performance-map-template.h>
#include <btwxt/grid-axis.h>

namespace schema_source {
namespace ashrae205 {


// ------------------------------------------------------------------------------------------------
/// @class GridVariablesTemplate grid_variables_base.h

class GridVariablesTemplate {

public:
GridVariablesTemplate() = default;
virtual ~GridVariablesTemplate() = default;
GridVariablesTemplate(const GridVariablesTemplate& other) = default;
GridVariablesTemplate& operator=(const GridVariablesTemplate& other) = default;

virtual void populate_performance_map(ashrae205::PerformanceMapTemplate* performance_map) = 0;

inline void add_grid_axis(ashrae205::PerformanceMapTemplate* performance_map, std::vector<double>& axis)
{
performance_map->add_grid_axis(axis);
}
inline void add_grid_axis(ashrae205::PerformanceMapTemplate* performance_map, std::vector<int>& axis)
{
performance_map->add_grid_axis(axis);
}
};
}
}
#endif
46 changes: 46 additions & 0 deletions cpp/base_classes/lookup-variables-template.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#ifndef LOOKUP_VARIABLES_TEMPLATE_H_
#define LOOKUP_VARIABLES_TEMPLATE_H_

#include <memory>
#include <vector>
#include <iostream>
#include <sstream>
#include "performance-map-template.h"

namespace schema_source {
namespace ashrae205 {

template <class T>
using is_scoped_enum = std::integral_constant<bool, !std::is_convertible<T,int>{}
&& std::is_enum<T>{}>;

// ------------------------------------------------------------------------------------------------
/// @class LookupVariablesTemplate lookup_variables_base.h

class LookupVariablesTemplate {

public:
LookupVariablesTemplate() = default;
virtual ~LookupVariablesTemplate() = default;
LookupVariablesTemplate(const LookupVariablesTemplate& other) = default;
LookupVariablesTemplate& operator=(const LookupVariablesTemplate& other) = default;

virtual void populate_performance_map(ashrae205::PerformanceMapTemplate* performance_map) = 0;

inline void add_data_table(ashrae205::PerformanceMapTemplate* performance_map, std::vector<double>& table)
{
performance_map->add_data_table(table);
}

template < class T, typename = std::enable_if<is_scoped_enum<T>::value> >
void add_data_table(PerformanceMapTemplate* performance_map, std::vector<T>& table)
{
std::vector<double> converted_enums;
std::transform(table.begin(), table.end(), std::back_inserter(converted_enums),
[](T n) { return static_cast<double>(n); });
performance_map->add_data_table(converted_enums);
}
};
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,64 @@
#include <vector>
#include <iostream>
#include <nlohmann/json.hpp>
#include <courierr/courierr.h>
#include <courier/courier.h>
#include <btwxt/btwxt.h>

namespace schema_source {
namespace ashrae205 {

// ------------------------------------------------------------------------------------------------
/// @class PerformanceMapBase performance_map_base.h
/// @class PerformanceMapTemplate performance-map-template.h

class PerformanceMapBase {
class PerformanceMapTemplate {

public:
PerformanceMapBase() = default;
virtual ~PerformanceMapBase() = default;
PerformanceMapBase(const PerformanceMapBase& other) = delete;
PerformanceMapBase& operator=(const PerformanceMapBase& other) = delete;
PerformanceMapBase(PerformanceMapBase&& other) = default;
PerformanceMapBase& operator=(PerformanceMapBase&& other) = default;
PerformanceMapTemplate() = default;
virtual ~PerformanceMapTemplate() = default;
PerformanceMapTemplate(const PerformanceMapTemplate& other) = delete;
PerformanceMapTemplate& operator=(const PerformanceMapTemplate& other) = delete;
PerformanceMapTemplate(PerformanceMapTemplate&& other) = default;
PerformanceMapTemplate& operator=(PerformanceMapTemplate&& other) = default;

// ----------------------------------------------------------------------------------------------
/// @brief
/// @brief
/// @param j
// ----------------------------------------------------------------------------------------------
virtual void initialize(const nlohmann::json& j) = 0;

// ----------------------------------------------------------------------------------------------
/// @brief
/// @brief
/// @param axis TBD
// ----------------------------------------------------------------------------------------------
inline void add_grid_axis(std::vector<double>& axis) {
grid_axes.emplace_back(axis);
}

// ----------------------------------------------------------------------------------------------
/// @brief
/// @brief
/// @param axis TBD
// ----------------------------------------------------------------------------------------------
inline void add_grid_axis(std::vector<int>& axis) {
grid_axes.emplace_back(std::vector<double>(axis.begin(), axis.end()));
}

// ----------------------------------------------------------------------------------------------
/// @brief
/// @brief
/// @param table TBD
// ----------------------------------------------------------------------------------------------
inline void add_data_table(std::vector<double>& table) {
btwxt->add_grid_point_data_set(table);
}

// ----------------------------------------------------------------------------------------------
/// @brief
/// @brief
// ----------------------------------------------------------------------------------------------
inline void finalize_grid(const std::shared_ptr<::Courierr::Courierr>& logger) {
btwxt = std::make_unique<Btwxt::RegularGridInterpolator>(grid_axes, logger);
inline void finalize_grid(const std::shared_ptr<::Courier::Courier>& logger) {
btwxt = std::make_unique<Btwxt::RegularGridInterpolator>(grid_axes, "RS0003", logger);
}

// ----------------------------------------------------------------------------------------------
/// @brief
/// @brief
/// @param table_index TBD
// ----------------------------------------------------------------------------------------------
inline double calculate_performance(const std::vector<double> &target,
Expand All @@ -76,7 +79,7 @@ class PerformanceMapBase {
// ----------------------------------------------------------------------------------------------
/// @brief Using pre-populated grid axes and lookup tables, calculate a set of performance
/// results.
/// @param target
/// @param target
// ----------------------------------------------------------------------------------------------
inline std::vector<double> calculate_performance(const std::vector<double> &target,
Btwxt::InterpolationMethod performance_interpolation_method = Btwxt::InterpolationMethod::linear)
Expand All @@ -88,11 +91,12 @@ class PerformanceMapBase {
return btwxt->get_values_at_target(target);
}

inline std::shared_ptr<Courierr::Courierr> get_logger() { return btwxt->get_logger(); }

private:
std::unique_ptr<Btwxt::RegularGridInterpolator> btwxt;
std::vector<std::vector<double>> grid_axes;
};

#endif
}
}

#endif
9 changes: 9 additions & 0 deletions cpp/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencies:
- name: "nlohmann_json"
url: "https://github.com/nlohmann/json.git"
- name: "btwxt"
url: "https://github.com/bigladder/btwxt.git"
- name: "courier"
url: "https://github.com/bigladder/courier.git"
- name: "fmt"
url: "https://github.com/fmtlib/fmt.git"
48 changes: 48 additions & 0 deletions cpp/extensions/add_performance_variable_enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from dataclasses import dataclass
from lattice.cpp.header_entries import HeaderEntry, Struct, DataElement
from lattice.cpp.header_translator import HeaderEntryExtensionInterface

@dataclass
class CounterEnum(HeaderEntry):
elements: list

def __post_init__(self):
super().__post_init__()
self.type = "enum"
self._closure = "};"
self._enumerants = list()

for element in self.elements:
self._enumerants.append(f"{element}_index")
self._enumerants.append("index_count");

self.trace()

def __str__(self):
enums = self._enumerants
entry = f"{self._indent}{self.type} {self._opener}\n"
entry += ",\n".join([f"{self._indent}\t{e}" for e in enums])
entry += f"\n{self._indent}{self._closure}"
return entry


class GridVarCounterEnumPlugin(HeaderEntryExtensionInterface, base_class="GridVariablesTemplate"):
""""""
def process_data_group(self, parent_node: HeaderEntry):
for entry in parent_node.child_entries:
if isinstance(entry, Struct) and entry.superclass == "ashrae205::GridVariablesTemplate":
data_elements = [child.name for child in entry.child_entries if isinstance(child, DataElement)]
e = CounterEnum(entry.name, entry, data_elements)
else:
self.process_data_group(entry)


class LookupVarCounterEnumPlugin(HeaderEntryExtensionInterface, base_class="LookupVariablesTemplate"):
""""""
def process_data_group(self, parent_node: HeaderEntry):
for entry in parent_node.child_entries:
if isinstance(entry, Struct) and entry.superclass == "ashrae205::LookupVariablesTemplate":
data_elements = [child.name for child in entry.child_entries if isinstance(child, DataElement)]
e = CounterEnum(entry.name, entry, data_elements)
else:
self.process_data_group(entry)
42 changes: 42 additions & 0 deletions cpp/extensions/lookup_struct.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import re
import copy
from dataclasses import dataclass
from lattice.cpp.header_entries import DataElement, HeaderEntry, Struct
# from lattice.cpp.header_entries import register_data_group_operation
from lattice.cpp.header_translator import HeaderEntryExtensionInterface

@dataclass
class LookupStruct(HeaderEntry):
"""
Special case struct for Lookup Variables. Its str overload adds a LookupStruct declaration.
"""
def __post_init__(self):
super().__post_init__()
self.name = f"{self.name}Struct"
self.type = "struct"
self._closure = "};"

self.trace()

def __str__(self):
# Add a LookupStruct that offers a SOA access rather than AOS
struct = f"{self._indent}{self.type} {self.name} {self._opener}\n"
for c in [ch for ch in self.child_entries if isinstance(ch, DataElement)]:
m = re.match(r'std::vector\<(.*)\>', c.type)
assert m is not None
struct += f"{self._indent}\t{m.group(1)} {c.name};\n"
struct += f"{self._indent}{self._closure}"

return struct


class LookupStructPlugin(HeaderEntryExtensionInterface, base_class="LookupVariablesTemplate"):
""""""
def process_data_group(self, parent_node: HeaderEntry):
for entry in parent_node.child_entries:
if isinstance(entry, Struct) and entry.superclass == "ashrae205::LookupVariablesTemplate":
ls = LookupStruct(entry.name, entry.parent)
for child in [ch for ch in entry.child_entries if isinstance(ch, DataElement)]:
ls._add_child_entry(copy.copy(child))
else:
self.process_data_group(entry)
Loading