.clang-format 0 → 100644
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
- Regex: '.*'
Priority: 1
SortPriority: 0
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
Standard: Latest
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
...
[submodule "PEGTL"]
path = subprojects/PEGTL
url = https://github.com/taocpp/PEGTL
[submodule "mfix/subprojects/mfix"]
path = subprojects/mfix
url = ../mfix
[submodule "subprojects/Catch2"]
path = subprojects/Catch2
url = https://github.com/catchorg/Catch2
src/geometry.cpp 0 → 100644
#include <iostream>
#include "solver.hpp"
namespace solver {
std::optional<solver::GeometrySettings> make_geometry(solver::InputInfo ii) {
solver::GeometrySettings geo;
std::string PROB_LO("geometry.prob_lo");
std::string PROB_HI("geometry.prob_hi");
std::string PERIODIC("geometry.is_periodic");
std::string N_CELL("amr.n_cell");
if (!ii.count(PROB_LO)) {
require(PROB_LO);
return std::nullopt;
}
if (!ii.count(PROB_HI)) {
require(PROB_HI);
return std::nullopt;
}
if (!ii.count(PERIODIC)) {
require(PERIODIC);
return std::nullopt;
}
if (!ii.count(N_CELL)) {
require(N_CELL);
return std::nullopt;
}
auto lows = std::get<solver::NumberArray>(ii[PROB_LO]);
auto highs = std::get<solver::NumberArray>(ii[PROB_HI]);
auto is_periodic = std::get<solver::NumberArray>(ii[PERIODIC]);
auto n_cell = std::get<solver::NumberArray>(ii[N_CELL]);
if (lows.size() != 3) {
std::cout << "prob_lo needs 3 elements " << std::endl;
return std::nullopt;
}
if (highs.size() != 3) {
std::cout << "prob_hi needs 3 elements " << std::endl;
return std::nullopt;
}
if (is_periodic.size() != 3) {
std::cout << "periodic needs 3 elements " << std::endl;
return std::nullopt;
}
if (n_cell.size() != 3) {
std::cout << "n_cell needs 3 elements " << std::endl;
return std::nullopt;
}
std::get<0>(geo.axes).high = highs[0];
std::get<0>(geo.axes).low = lows[0];
std::get<0>(geo.axes).periodic = is_periodic[0];
std::get<0>(geo.axes).n_cell = n_cell[0];
std::get<1>(geo.axes).high = highs[1];
std::get<1>(geo.axes).low = lows[1];
std::get<1>(geo.axes).periodic = is_periodic[1];
std::get<1>(geo.axes).n_cell = n_cell[1];
std::get<2>(geo.axes).high = highs[2];
std::get<2>(geo.axes).low = lows[2];
std::get<2>(geo.axes).periodic = is_periodic[2];
std::get<2>(geo.axes).n_cell = n_cell[2];
return geo;
}
} // namespace solver
lib_parser = static_library('mfix-parser',
'geometry.cpp',
'parser.cpp',
'solver.cpp',
'time.cpp',
include_directories: tao_inc,
install : true)
......
......
......@@ -4,7 +4,7 @@
#include "solver.hpp"
namespace {
namespace solver {
void require(std::string key) {
std::cout << "missing required key: " << key << std::endl;
......@@ -12,64 +12,20 @@ void require(std::string key) {
std::optional<solver::SolverSettings> do_make_solver(solver::InputInfo ii) {
solver::SolverSettings ss;
std::string PROB_LO("geometry.prob_lo");
std::string PROB_HI("geometry.prob_hi");
std::string PERIODIC("geometry.is_periodic");
std::string N_CELL("amr.n_cell");
if (!ii.count(PROB_LO)) {
require(PROB_LO);
return std::nullopt;
}
if (!ii.count(PROB_HI)) {
require(PROB_HI);
return std::nullopt;
}
if (!ii.count(PERIODIC)) {
require(PERIODIC);
return std::nullopt;
}
if (!ii.count(N_CELL)) {
require(N_CELL);
return std::nullopt;
}
auto lows = std::get<solver::NumberArray>(ii[PROB_LO]);
auto highs = std::get<solver::NumberArray>(ii[PROB_HI]);
auto is_periodic = std::get<solver::NumberArray>(ii[PERIODIC]);
auto n_cell = std::get<solver::NumberArray>(ii[N_CELL]);
if (lows.size() != 3) {
std::cout << "prob_lo needs 3 elements " << std::endl;
return std::nullopt;
}
if (highs.size() != 3) {
std::cout << "prob_hi needs 3 elements " << std::endl;
return std::nullopt;
}
if (is_periodic.size() != 3) {
std::cout << "periodic needs 3 elements " << std::endl;
auto new_geo = make_geometry(ii);
if (!new_geo.has_value()) {
std::cout << "Problem making geometry" << std::endl;
return std::nullopt;
}
if (n_cell.size() != 3) {
std::cout << "n_cell needs 3 elements " << std::endl;
auto new_time = make_time(ii);
if (!new_time.has_value()) {
std::cout << "Problem making time" << std::endl;
return std::nullopt;
}
std::get<0>(ss.geometry.axes).high = highs[0];
std::get<0>(ss.geometry.axes).low = lows[0];
std::get<0>(ss.geometry.axes).periodic = is_periodic[0];
std::get<0>(ss.geometry.axes).n_cell = n_cell[0];
std::get<1>(ss.geometry.axes).high = highs[1];
std::get<1>(ss.geometry.axes).low = lows[1];
std::get<1>(ss.geometry.axes).periodic = is_periodic[1];
std::get<1>(ss.geometry.axes).n_cell = n_cell[1];
std::get<2>(ss.geometry.axes).high = highs[2];
std::get<2>(ss.geometry.axes).low = lows[2];
std::get<2>(ss.geometry.axes).periodic = is_periodic[2];
std::get<2>(ss.geometry.axes).n_cell = n_cell[2];
ss.geometry = new_geo.value();
ss.time = new_time.value();
return ss;
}
} // namespace
namespace solver {
std::optional<solver::SolverSettings> make_solver(solver::InputInfo ii) {
auto maybe_state = do_make_solver(ii);
......
......
......@@ -25,12 +25,23 @@ struct GeometryAxis {
struct GeometrySettings {
std::array<GeometryAxis, 3> axes;
};
struct TimeSettings {
unsigned int max_step;
double dt_max;
double dt_min;
double tstop;
};
struct SolverSettings {
GeometrySettings geometry;
TimeSettings time;
};
std::optional<SolverSettings> make_solver(solver::InputInfo);
std::optional<GeometrySettings> make_geometry(solver::InputInfo);
std::optional<TimeSettings> make_time(solver::InputInfo);
std::string serialize(solver::SolverSettings);
void require(std::string);
} // namespace solver
#endif
src/time.cpp 0 → 100644
#include <iostream>
#include "solver.hpp"
namespace solver {
std::optional<solver::TimeSettings> make_time(solver::InputInfo ii) {
solver::TimeSettings time;
std::string DT_MAX("mfix.dt_max");
std::string DT_MIN("mfix.dt_min");
std::string MAXSTEP("mfix.max_step");
std::string TSTOP("mfix.stop_time");
if (!ii.count(DT_MAX)) {
require(DT_MAX);
return std::nullopt;
}
if (!ii.count(DT_MIN)) {
require(DT_MIN);
return std::nullopt;
}
if (!ii.count(MAXSTEP)) {
require(MAXSTEP);
return std::nullopt;
}
if (!ii.count(TSTOP)) {
require(TSTOP);
return std::nullopt;
}
auto dt_max = std::get<solver::NumberArray>(ii[DT_MAX]);
auto dt_min = std::get<solver::NumberArray>(ii[DT_MIN]);
auto maxstep = std::get<solver::NumberArray>(ii[MAXSTEP]);
auto tstop = std::get<solver::NumberArray>(ii[TSTOP]);
if (dt_max.size() != 1) {
std::cout << "dt_max is a scalar: " << dt_max.size() << std::endl;
return std::nullopt;
}
if (dt_min.size() != 1) {
std::cout << "dt_min is a scalar" << std::endl;
return std::nullopt;
}
if (maxstep.size() != 1) {
std::cout << "max_step is a scalar" << std::endl;
return std::nullopt;
}
if (tstop.size() != 1) {
std::cout << "tstop is a scalar" << std::endl;
return std::nullopt;
}
time.dt_max = dt_max[0];
time.dt_min = dt_min[0];
time.max_step = maxstep[0];
time.tstop = tstop[0];
return time;
}
} // namespace solver
Subproject commit e4aaa45a48378bf8f220a359994a42066692f194
......@@ -4,10 +4,14 @@
#include <solver.hpp>
std::string PROB_LO("geometry.prob_lo");
std::string PROB_HI("geometry.prob_hi");
std::string PERIODIC("geometry.is_periodic");
std::string DT_MAX("mfix.dt_max");
std::string DT_MIN("mfix.dt_min");
std::string MAXSTEP("mfix.max_step");
std::string N_CELL("amr.n_cell");
std::string PERIODIC("geometry.is_periodic");
std::string PROB_HI("geometry.prob_hi");
std::string PROB_LO("geometry.prob_lo");
std::string TSTOP("mfix.stop_time");
TEST_CASE("empty (invalid) map", "[]") {
solver::InputInfo ii;
......@@ -21,6 +25,10 @@ TEST_CASE("from_origin", "[]") {
ii[PROB_HI] = solver::NumberArray({0.004, 0.001, 0.001});
ii[PERIODIC] = solver::NumberArray({0, 0, 0});
ii[N_CELL] = solver::NumberArray({11, 22, 33});
ii[DT_MAX] = solver::NumberArray({99.99});
ii[DT_MIN] = solver::NumberArray({0.001});
ii[MAXSTEP] = solver::NumberArray({39});
ii[TSTOP] = solver::NumberArray({3.14});
CHECK(ii.count(PROB_LO));
CHECK(ii.count(PROB_HI));
CHECK(ii.count(PERIODIC));
......@@ -42,6 +50,11 @@ TEST_CASE("from_origin", "[]") {
CHECK(xx.n_cell == 11);
CHECK(yy.n_cell == 22);
CHECK(zz.n_cell == 33);
CHECK(sv.time.dt_max == 99.99);
CHECK(sv.time.dt_min == 0.001);
CHECK(sv.time.max_step == 39);
CHECK(sv.time.tstop == 3.14);
}
TEST_CASE("negative_positive", "[]") {
......@@ -50,6 +63,10 @@ TEST_CASE("negative_positive", "[]") {
ii[PROB_HI] = std::vector<double>({11.1, 22.2, 33.3});
ii[PERIODIC] = solver::NumberArray({1, 0, 1});
ii[N_CELL] = solver::NumberArray({11, 22, 33});
ii[DT_MAX] = solver::NumberArray({99.99});
ii[DT_MIN] = solver::NumberArray({0.001});
ii[MAXSTEP] = solver::NumberArray({39});
ii[TSTOP] = solver::NumberArray({3.14});
auto maybe_sv = solver::make_solver(ii);
......
......