Skip to content

Commit

Permalink
Fix Issue #714
Browse files Browse the repository at this point in the history
  • Loading branch information
thelfer committed Feb 5, 2025
1 parent 7d3ed88 commit a879bff
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 22 deletions.
4 changes: 4 additions & 0 deletions docs/web/release-notes-4.2.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/thelfer/tfel/issues/714>

## Issue 710: [mfront] fix support for bounds on output when quantities are used in C based interfaces

For more details, see <https://github.com/thelfer/tfel/issues/710>
Expand Down
90 changes: 68 additions & 22 deletions mfront/src/OctaveMaterialPropertyInterface.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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";
Expand Down Expand Up @@ -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)) {
Expand All @@ -362,15 +408,15 @@ 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)) {
out << "// treating standard bounds\n";
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"
Expand Down

0 comments on commit a879bff

Please sign in to comment.