Skip to content

Commit 001536f

Browse files
update more parameter retrieval to use constexpr evaluation. (#189)
* update more parameter retrieval to use constexpr evaluation. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * clang-tidy fixes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * clang-tidy fixes --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 35a43c8 commit 001536f

18 files changed

Lines changed: 302 additions & 242 deletions

.github/workflows/asan.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ jobs:
2121
name: ASan
2222
runs-on: ubuntu-latest
2323
container:
24-
image: helics/buildenv:sanitizers-22
24+
image: "helics/buildenv:sanitizers-22"
2525
env:
26-
ASAN_OPTIONS: detect_leaks=0
27-
LSAN_OPTIONS: verbosity=1:log_threads=1
26+
ASAN_OPTIONS: "detect_leaks=0"
27+
LSAN_OPTIONS: "verbosity=1:log_threads=1"
2828

2929
steps:
3030
- uses: actions/checkout@v6

ThirdParty/Minizip/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ if(NOT CPACK_INCLUDED)
5050
include(CPack)
5151
endif(NOT CPACK_INCLUDED)
5252

53-
if(NOT DEFINED ZLIB_BUILD_MINIZIP)
53+
if(NOT DEFINED ZLIB_BUILD_MINIZIP AND NOT GRIDDYN_MINIZIP_USE_EXISTING_ZLIB_TARGETS)
5454
if(MINIZIP_BUILD_SHARED)
5555
list(APPEND REQUIRED_COMPONENTS "shared")
5656
endif(MINIZIP_BUILD_SHARED)
@@ -60,7 +60,7 @@ if(NOT DEFINED ZLIB_BUILD_MINIZIP)
6060
endif(MINIZIP_BUILD_STATIC)
6161

6262
find_package(ZLIB REQUIRED COMPONENTS ${REQUIRED_COMPONENTS} CONFIG)
63-
endif(NOT DEFINED ZLIB_BUILD_MINIZIP)
63+
endif(NOT DEFINED ZLIB_BUILD_MINIZIP AND NOT GRIDDYN_MINIZIP_USE_EXISTING_ZLIB_TARGETS)
6464

6565
if(MINIZIP_ENABLE_BZIP2)
6666
find_package(BZip2 REQUIRED)
@@ -279,4 +279,3 @@ if(MINIZIP_INSTALL)
279279
COMPONENT Development
280280
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
281281
endif(MINIZIP_INSTALL)
282-

src/core/CoreObjectTemplates.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#pragma once
88

99
#include "CoreObject.h"
10+
#include <span>
1011
#include <type_traits>
1112
namespace griddyn {
1213
/**
@@ -55,9 +56,9 @@ A* cloneBase(const A* originalObject, CoreObject* obj)
5556
template<class A, class B>
5657
void getParamString(const A* cobj,
5758
stringVec& pstr,
58-
const stringVec& numStr,
59-
const stringVec& strStr,
60-
const stringVec& flagStr,
59+
std::span<const std::string_view> numStr,
60+
std::span<const std::string_view> strStr,
61+
std::span<const std::string_view> flagStr,
6162
ParamStringType pstype)
6263
{
6364
static_assert(std::is_base_of<B, A>::value,
@@ -77,13 +78,13 @@ void getParamString(const A* cobj,
7778
cobj->B::getParameterStrings(pstr, ParamStringType::STR);
7879
break;
7980
case ParamStringType::LOCAL_NUM:
80-
pstr = numStr;
81+
pstr.assign(numStr.begin(), numStr.end());
8182
break;
8283
case ParamStringType::LOCAL_STR:
83-
pstr = strStr;
84+
pstr.assign(strStr.begin(), strStr.end());
8485
break;
8586
case ParamStringType::LOCAL_FLAGS:
86-
pstr = flagStr;
87+
pstr.assign(flagStr.begin(), flagStr.end());
8788
break;
8889
case ParamStringType::NUMERIC:
8990
pstr.reserve(pstr.size() + numStr.size());

src/griddyn/GridComponent.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "gmlc/utilities/vectorOps.hpp"
1414
#include "utilities/MatrixData.hpp"
1515
#include <algorithm>
16+
#include <array>
1617
#include <cassert>
1718
#include <format>
1819
#include <functional>
@@ -573,22 +574,17 @@ void GridComponent::disconnect()
573574
{
574575
opFlags.set(DISCONNECTED);
575576
}
576-
static const stringVec& localNumericStrings()
577-
{
578-
static const stringVec strings{"status", "basefrequency", "basepower"};
579-
return strings;
580-
}
577+
static constexpr auto localNumericStrings =
578+
std::array<std::string_view, 3>{"status", "basefrequency", "basepower"};
581579

582-
static const stringVec& localStringStrings()
583-
{
584-
static const stringVec strings{"status"};
585-
return strings;
586-
}
580+
static constexpr auto localStringStrings = std::array<std::string_view, 1>{"status"};
581+
582+
static constexpr std::array<std::string_view, 0> localFlagStrings{};
587583

588584
void GridComponent::getParameterStrings(stringVec& pstr, ParamStringType pstype) const
589585
{
590586
getParamString<GridComponent, CoreObject>(
591-
this, pstr, localNumericStrings(), localStringStrings(), {}, pstype);
587+
this, pstr, localNumericStrings, localStringStrings, localFlagStrings, pstype);
592588
}
593589

594590
void GridComponent::set(std::string_view param, std::string_view val)

src/griddyn/links/AcLine.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "gmlc/utilities/stringOps.h"
1818
#include "gmlc/utilities/vectorOps.hpp"
1919
#include "utilities/MatrixDataCompact.hpp"
20+
#include <array>
2021
#include <cmath>
2122
#include <complex>
2223
#include <cstring>
@@ -155,23 +156,23 @@ void AcLine::timestep(const CoreTime time, const IOdata& /*inputs*/, const Solve
155156

156157
void AcLine::checkMerge() {}
157158

158-
static const stringVec LOC_NUM_STRINGS{"r",
159-
"x",
160-
"link",
161-
"b",
162-
"g",
163-
"tap",
164-
"tapangle",
165-
"switch1",
166-
"switch2",
167-
"fault",
168-
"p"};
169-
static const stringVec LOC_STR_STRINGS{"from", "to"};
170-
static const stringVec FLAG_STRINGS{};
159+
static constexpr auto locNumStrings = std::array<std::string_view, 11>{"r",
160+
"x",
161+
"link",
162+
"b",
163+
"g",
164+
"tap",
165+
"tapangle",
166+
"switch1",
167+
"switch2",
168+
"fault",
169+
"p"};
170+
static constexpr auto locStrStrings = std::array<std::string_view, 2>{"from", "to"};
171+
static constexpr std::array<std::string_view, 0> flagStrings{};
171172
void AcLine::getParameterStrings(stringVec& pstr, ParamStringType pstype) const
172173
{
173174
getParamString<AcLine, GridComponent>(
174-
this, pstr, LOC_NUM_STRINGS, LOC_STR_STRINGS, FLAG_STRINGS, pstype);
175+
this, pstr, locNumStrings, locStrStrings, flagStrings, pstype);
175176
}
176177

177178
// set properties

src/griddyn/links/AdjustableTransformer.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "utilities/MatrixData.hpp"
1818
#include "utilities/MatrixDataTranslate.hpp"
1919
#include <algorithm>
20+
#include <array>
2021
#include <cassert>
2122
#include <cmath>
2223
#include <iostream>
@@ -82,30 +83,31 @@ CoreObject* AdjustableTransformer::clone(CoreObject* obj) const
8283
return lnk;
8384
}
8485

85-
static const stringVec LOC_NUM_STRINGS{"vmin",
86-
"vmax",
87-
"vtarget",
88-
"pmin",
89-
"pmax",
90-
"ptarget",
91-
"qmin",
92-
"qmax",
93-
"qtarget",
94-
"direction",
95-
"mintap",
96-
"maxtap",
97-
"mintapangle",
98-
"maxtapangle",
99-
"stepsize",
100-
"nsteps",
101-
"dtapdt",
102-
"dtapadt"};
103-
static const stringVec LOC_STR_STRINGS{"controlmode", "changemode", "centermode"};
104-
static const stringVec FLAG_STRINGS{"no_pflow_adjustments"};
86+
static constexpr auto locNumStrings = std::array<std::string_view, 18>{"vmin",
87+
"vmax",
88+
"vtarget",
89+
"pmin",
90+
"pmax",
91+
"ptarget",
92+
"qmin",
93+
"qmax",
94+
"qtarget",
95+
"direction",
96+
"mintap",
97+
"maxtap",
98+
"mintapangle",
99+
"maxtapangle",
100+
"stepsize",
101+
"nsteps",
102+
"dtapdt",
103+
"dtapadt"};
104+
static constexpr auto locStrStrings =
105+
std::array<std::string_view, 3>{"controlmode", "changemode", "centermode"};
106+
static constexpr auto flagStrings = std::array<std::string_view, 1>{"no_pflow_adjustments"};
105107
void AdjustableTransformer::getParameterStrings(stringVec& pstr, ParamStringType pstype) const
106108
{
107109
getParamString<AdjustableTransformer, AcLine>(
108-
this, pstr, LOC_NUM_STRINGS, LOC_STR_STRINGS, FLAG_STRINGS, pstype);
110+
this, pstr, locNumStrings, locStrStrings, flagStrings, pstype);
109111
}
110112

111113
// set properties

src/griddyn/links/Link.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "gmlc/utilities/vectorOps.hpp"
2121
#include "utilities/MatrixDataCompact.hpp"
2222
#include <algorithm>
23+
#include <array>
2324
#include <cmath>
2425
#include <complex>
2526
#include <cstdio>
@@ -177,13 +178,14 @@ void Link::timestep(const CoreTime time, const IOdata& /*inputs*/, const SolverM
177178
}*/
178179
}
179180

180-
static const stringVec LOC_NUM_STRINGS{"loss", "switch1", "switch2", "p"};
181-
static const stringVec LOC_STR_STRINGS{"from", "to"};
182-
static const stringVec FLAG_STRINGS{};
181+
static constexpr auto locNumStrings =
182+
std::array<std::string_view, 4>{"loss", "switch1", "switch2", "p"};
183+
static constexpr auto locStrStrings = std::array<std::string_view, 2>{"from", "to"};
184+
static constexpr std::array<std::string_view, 0> flagStrings{};
183185
void Link::getParameterStrings(stringVec& pstr, ParamStringType pstype) const
184186
{
185187
getParamString<Link, GridPrimary>(
186-
this, pstr, LOC_NUM_STRINGS, LOC_STR_STRINGS, FLAG_STRINGS, pstype);
188+
this, pstr, locNumStrings, locStrStrings, flagStrings, pstype);
187189
}
188190

189191
// set properties

0 commit comments

Comments
 (0)