From a879bff887f78cb7d68f6ea640a1e7db45252940 Mon Sep 17 00:00:00 2001 From: Thomas Helfer Date: Wed, 5 Feb 2025 08:47:43 +0100 Subject: [PATCH] Fix Issue #714 --- docs/web/release-notes-4.2.3.md | 4 + .../src/OctaveMaterialPropertyInterface.cxx | 90 ++++++++++++++----- 2 files changed, 72 insertions(+), 22 deletions(-) diff --git a/docs/web/release-notes-4.2.3.md b/docs/web/release-notes-4.2.3.md index 026a6739a..2b149a692 100644 --- a/docs/web/release-notes-4.2.3.md +++ b/docs/web/release-notes-4.2.3.md @@ -22,6 +22,10 @@ The page describes the new functionalities of Version 4.2.3 of the # Issues fixed +## Issue 714: [octave-interface] fix support for bounds on output when quantities are used + +For more details, see + ## Issue 710: [mfront] fix support for bounds on output when quantities are used in C based interfaces For more details, see diff --git a/mfront/src/OctaveMaterialPropertyInterface.cxx b/mfront/src/OctaveMaterialPropertyInterface.cxx index 0c000614f..c7eccb556 100644 --- a/mfront/src/OctaveMaterialPropertyInterface.cxx +++ b/mfront/src/OctaveMaterialPropertyInterface.cxx @@ -37,7 +37,8 @@ namespace mfront { std::ostream& out, const VariableDescription& v, const std::string& name, - const VariableDescriptionContainer::size_type nbr) { + const VariableDescriptionContainer::size_type nbr, + const bool use_qt) { if (!v.hasBounds()) { return; } @@ -53,11 +54,16 @@ namespace mfront { "\"OCTAVE_OUT_OF_BOUNDS_POLICY\");\n" "#endif /* OCTAVE_MAJOR_VERSION */\n"; if (b.boundsType == VariableBoundsDescription::LOWER) { - out << "if(" << v.name << " < " << b.lowerBound << "){\n" - << get_out_of_bounds_policy // + if (use_qt) { + out << "if(" << v.name << " < " << v.type << "{" << b.lowerBound + << "}){\n"; + } else { + out << "if(" << v.name << " < " << b.lowerBound << "){\n"; + } + out << get_out_of_bounds_policy // << "if(mfront_policy.is_defined()){\n" << "if(mfront_policy.is_string()){\n" - << "string msg(\"" << name << ": " << v.name + << "std::string msg(\"" << name << ": " << v.name << " is below its lower bound.\");\n" << "if(mfront_policy.string_value()==\"STRICT\"){\n" << "error(\"%s\\n\", msg.c_str());\n" @@ -71,12 +77,17 @@ namespace mfront { << "return " << nbr << ";\n" << "}\n"; } else if (b.boundsType == VariableBoundsDescription::UPPER) { - out << "if(" << v.name << " < " << b.lowerBound << "){\n" - << get_out_of_bounds_policy // + if(use_qt){ + out << "if(" << v.name << " > " << v.type << "{" << b.upperBound + << "}){\n"; + } else { + out << "if(" << v.name << " > " << b.upperBound << "){\n"; + } + out << get_out_of_bounds_policy // << "\"OCTAVE_OUT_OF_BOUNDS_POLICY\");\n" << "if(mfront_policy.is_defined()){\n" << "if(mfront_policy.is_string()){\n" - << "string msg(\"" << name << ": \"" << v.name + << "std::string msg(\"" << name << ": \"" << v.name << " is over its upper bound.\");\n" << "if(mfront_policy.string_value()==\"STRICT\"){\n" << "error(\"%s\\n\", msg.c_str());\n" @@ -87,12 +98,19 @@ namespace mfront { << "return " << nbr << ";\n" << "}\n"; } else { - out << "if((" << v.name << " < " << b.lowerBound << ")||" - << "(" << v.name << " > " << b.upperBound << ")){\n" - << get_out_of_bounds_policy // + if (use_qt) { + out << "if((" << v.name << " < " << v.type << "{" << b.lowerBound + << "})||" + << "(" << v.name << " > " << v.type << "{" << b.upperBound + << "})){\n"; + } else { + out << "if((" << v.name << " < " << b.lowerBound << ")||" + << "(" << v.name << " > " << b.upperBound << ")){\n"; + } + out << get_out_of_bounds_policy // << "if(mfront_policy.is_defined()){\n" << "if(mfront_policy.is_string()){\n" - << "string msg(\"" << name << ": " << v.name + << "std::string msg(\"" << name << ": " << v.name << " is out of its bounds.\");\n" << "if(mfront_policy.string_value()==\"STRICT\"){\n" << "error(\"%s\\n\", msg.c_str());\n" @@ -111,31 +129,59 @@ namespace mfront { std::ostream& out, const VariableDescription& v, const std::string& name, - const VariableDescriptionContainer::size_type nbr) { + const VariableDescriptionContainer::size_type nbr, + const bool use_qt) { if (!v.hasPhysicalBounds()) { return; } const auto& b = v.getPhysicalBounds(); if (b.boundsType == VariableBoundsDescription::LOWER) { - out << "if(" << v.name << " < " << b.lowerBound << "){\n"; + if (use_qt) { + out << "if(" << v.name << " < " << v.type << "{" << b.lowerBound + << "}){\n"; + } else { + out << "if(" << v.name << " < " << b.lowerBound << "){\n"; + } out << "error(\"%s\\n\", \"" << name << ": " << v.name << " is below its physical lower bound.\");\n"; out << "return -" << nbr << ";\n"; out << "}\n"; } else if (b.boundsType == VariableBoundsDescription::UPPER) { - out << "if(" << v.name << " > " << b.upperBound << "){\n"; + if (use_qt) { + out << "if(" << v.name << " > " << v.type << "{" << b.upperBound + << "}){\n"; + } else { + out << "if(" << v.name << " > " << b.upperBound << "){\n"; + } out << "error(\"%s\\n\", \"" << name << ": " << v.name << " is over its physical upper bound.\");\n"; out << "return -" << nbr << ";\n"; out << "}\n"; } else { - out << "if((" << v.name << " < " << b.lowerBound << ")||" - << "(" << v.name << " > " << b.upperBound << ")){\n"; - out << "if(" << v.name << " < " << b.lowerBound << "){\n"; + if (use_qt) { + out << "if((" << v.name << " < " << v.type << "{" << b.lowerBound + << "})||" + << "(" << v.name << " > " << v.type << "{" << b.upperBound + << "})){\n"; + } else { + out << "if((" << v.name << " < " << b.lowerBound << ")||" + << "(" << v.name << " > " << b.upperBound << ")){\n"; + } + if (use_qt) { + out << "if(" << v.name << " < " << v.type << "{" << b.lowerBound + << "}){\n"; + } else { + out << "if(" << v.name << " < " << b.lowerBound << "){\n"; + } out << "error(\"%s\\n\", \"" << name << ": " << v.name << " is below its physical lower bound.\");\n"; out << "}\n"; - out << "if(" << v.name << " > " << b.upperBound << "){\n"; + if (use_qt) { + out << "if(" << v.name << " > " << v.type << "{" << b.upperBound + << "}){\n"; + } else { + out << "if(" << v.name << " > " << b.upperBound << "){\n"; + } out << "error(\"%s\\n\", \"" << name << ": " << v.name << " is over its physical upper bound.\");\n"; out << "}\n"; @@ -335,8 +381,8 @@ namespace mfront { << "return 0;\n" << "}\n"; if (!areRuntimeChecksDisabled(mpd)) { - writePhysicalBoundsChecks(out, mpd.output, name, 0); - writeBoundsChecks(out, mpd.output, name, 0); + writePhysicalBoundsChecks(out, mpd.output, name, 0, useQuantities(mpd)); + writeBoundsChecks(out, mpd.output, name, 0, useQuantities(mpd)); } // if (useQuantities(mpd)) { @@ -362,7 +408,7 @@ namespace mfront { for (const auto& i : mpd.inputs) { const auto nbr = CMaterialPropertyInterfaceBase::getVariableNumber(mpd, i.name); - writePhysicalBoundsChecks(out, i, name, nbr); + writePhysicalBoundsChecks(out, i, name, nbr, false); } } if (hasBounds(mpd.inputs)) { @@ -370,7 +416,7 @@ namespace mfront { for (const auto& i : mpd.inputs) { const auto nbr = CMaterialPropertyInterfaceBase::getVariableNumber(mpd, i.name); - writeBoundsChecks(out, i, name, nbr); + writeBoundsChecks(out, i, name, nbr, false); } } out << "return 0;\n"