Skip to content

Commit 1da8805

Browse files
committed
Fix of 'Fixed' generator for matrix values
1 parent 2369a36 commit 1da8805

3 files changed

Lines changed: 42 additions & 5 deletions

File tree

CMake.in.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ SET(OFBUILD_CUSTOM_CMAKE_VERSION "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.
2323
SET(OPENFLUID_VERSION_MAJOR 2)
2424
SET(OPENFLUID_VERSION_MINOR 2)
2525
SET(OPENFLUID_VERSION_PATCH 1)
26-
SET(OPENFLUID_VERSION_STATUS "beta3") # example: SET(OPENFLUID_VERSION_STATUS "rc1")
26+
SET(OPENFLUID_VERSION_STATUS "beta4") # example: SET(OPENFLUID_VERSION_STATUS "rc1")
2727

2828
SET(OPENFLUID_VERSION_FULL "${OPENFLUID_VERSION_MAJOR}.${OPENFLUID_VERSION_MINOR}.${OPENFLUID_VERSION_PATCH}")
2929

src/openfluid/machine/FixedGenerator.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,27 +199,29 @@ template <>
199199
void LinearFixedGenerator<openfluid::core::MatrixValue>::processVarValue(const openfluid::ware::WareParams_t& Params)
200200
{
201201
std::string VarSizeStr;
202+
bool ExplicitSize = false;
202203
if (OPENFLUID_GetWareParameter(Params,"varsize", VarSizeStr))
203204
{
204205
LinearGeneratorMixin::processVarValue(VarSizeStr);
206+
ExplicitSize = true;
205207
}
206208
std::string StringVarValue;
207209
if (!OPENFLUID_GetWareParameter(Params,"fixedvalue",StringVarValue))
208210
{
209-
throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION,"missing fixed vector value for generator");
211+
throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION,"missing fixed matrix value for generator");
210212
}
211213
if (openfluid::core::StringValue(StringVarValue).guessTypeConversion() == openfluid::core::Value::MATRIX)
212214
{
213215
openfluid::core::MatrixValue MV;
214216
if (!OPENFLUID_GetWareParameter(Params,"fixedvalue",MV))
215217
{
216218
throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION,
217-
"badly formatted fixed vector value for generator");
219+
"badly formatted fixed matrix value for generator");
218220
}
219-
if (MV.getRowsNbr() != m_VarDimensions.Rows || MV.getColsNbr() != m_VarDimensions.Cols)
221+
if (ExplicitSize && (MV.getRowsNbr() != m_VarDimensions.Rows || MV.getColsNbr() != m_VarDimensions.Cols))
220222
{
221223
throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION,
222-
"wrong size for fixed vector value for generator");
224+
"wrong size for fixed matrix value for generator");
223225
}
224226
m_VarValue = MV;
225227
}

src/openfluid/machine/tests/Generator_TEST.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,3 +521,38 @@ BOOST_AUTO_TEST_CASE(check_fixed_vector)
521521
BOOST_REQUIRE_THROW(TS.wholeSimulation(), openfluid::base::FrameworkException);
522522
}
523523
}
524+
525+
526+
BOOST_AUTO_TEST_CASE(check_fixed_matrix)
527+
{
528+
openfluid::machine::GeneratorSpecs Specs{openfluid::fluidx::GeneratorDescriptor::GeneratorMethod::FIXED,
529+
{{"SU","a"}},
530+
openfluid::core::Value::MATRIX};
531+
{
532+
// TEST MATRIX
533+
std::cout << "checking fixed matrix " << std::endl;
534+
openfluid::ware::WareParams_t Params = {{"deltat", "0"}, {"fixedvalue", "[[3,2],[5,4]]"}};
535+
536+
TestSimulation TS;
537+
TS.defaultSetup();
538+
TS.addGenerator(Specs, Params);
539+
TS.wholeSimulation();
540+
541+
const auto Matrix = TS.getLatestValue("SU", 1, "a").value()->asMatrixValue();
542+
BOOST_REQUIRE_CLOSE(Matrix.get(1,1), 4, 0.00001);
543+
}
544+
545+
{
546+
// TEST VECTOR CELLS FROM VAL
547+
std::cout << "checking fixed matrix CELLS FROM VAL" << std::endl;
548+
openfluid::ware::WareParams_t Params = {{"deltat", "0"}, {"fixedvalue", "2.4"}, {"varsize","[3,6]"}};
549+
550+
TestSimulation TS;
551+
TS.defaultSetup();
552+
TS.addGenerator(Specs, Params);
553+
TS.wholeSimulation();
554+
555+
const auto Matrix = TS.getLatestValue("SU", 1, "a").value()->asMatrixValue();
556+
BOOST_REQUIRE_CLOSE(Matrix.get(1,1), 2.4, 0.00001);
557+
}
558+
}

0 commit comments

Comments
 (0)