Commit b6be3a80 authored by GILLES Sebastien's avatar GILLES Sebastien

#1520 In AtQuadraturePoint policy, replace in the Write method the number of...

#1520 In AtQuadraturePoint policy, replace in the Write method the number of values, which was an ill-advised field: if there were a domain selection the computed value would have been higher than the actual number of lines written below.

The test GlobalCoordsQuadPts has been further refactored to be more robust: it was relying too much of a very specific layout for the AtQuadraturePoint write method.
parent 1a096c4f
......@@ -211,11 +211,6 @@ namespace MoReFEM
const auto quadrature_rule_name = quadrature_rule.GetName();
const auto Nquadrature_point = quadrature_rule.NquadraturePoint();
const auto Ngeo_elt = std::distance(iterator_range.first, iterator_range.second);
const auto Nvalues = Ngeo_elt * Nquadrature_point;
out << "# Nvalues" << std::endl;
out << Nvalues << std::endl;
for (auto it_geom_elt = iterator_range.first; it_geom_elt != iterator_range.second; ++it_geom_elt)
{
......
......@@ -210,46 +210,37 @@ namespace MoReFEM::TestNS::GlobalCoordsQuadPt
const std::string output_file = output_directory.AddFile(quadrature_order);
obtained_global_coords.Write(output_file);
std::cout << "OUT = " << output_file << std::endl;
// Read from output and compare results.
std::ifstream file_stream;
FilesystemNS::File::Read(file_stream, output_file, __FILE__, __LINE__);
std::string line;
// skip first three lines
for (int i = 0; i < 3; ++i)
getline(file_stream, line);
constexpr const auto setw_ensight = 12ul;
constexpr const auto vector_size = 3ul;
constexpr const auto ensight_precision = 1.e-6;
bool skipped_Nvalue_line = false;
std::string str_value;
// skip first two lines
for (int i = 0; i < 2; ++i)
getline(file_stream, line);
std::vector<double> obtained_values;
while (getline(file_stream, line))
{
if (skipped_Nvalue_line)
{
for (auto index = 0ul; index < setw_ensight * vector_size; index += setw_ensight)
{
str_value.assign(line, index, setw_ensight);
obtained_values.push_back(std::stod(str_value));
}
}
// Skips the first three fields:
// "# Geometric element index; quadrature point; TimeManager::NtimesModified() at last update"
for (int i = 0; i < 3; ++i)
getline(file_stream, line, ';');
skipped_Nvalue_line = true;
const auto item_list = Utilities::String::Split(line, ";");
BOOST_CHECK_EQUAL(item_list.size(), 4ul);
const auto coords_list = std::string(item_list.back()); // istringstream can't act upon a
// std::string_view hence this copy.
std::istringstream iconv(coords_list);
double value;
while (iconv >> value)
obtained_values.push_back(value);
}
const auto end_obtained = obtained_values.cend();
assert("Output vector and reference vector do not have the same size."
&& obtained_values.size() == expected_global_coords.size());
BOOST_CHECK_EQUAL(obtained_values.size(), expected_global_coords.size());
constexpr const auto ensight_precision = 1.e-6;
for (auto it_obtained = obtained_values.cbegin(), it_expected = expected_global_coords.cbegin();
it_obtained != end_obtained;
++it_obtained, ++it_expected)
......@@ -258,17 +249,9 @@ namespace MoReFEM::TestNS::GlobalCoordsQuadPt
const auto expected_value = *it_expected;
// Takes into account the precision at which we wrote the quadrature point coordinates.
if (!NumericNS::AreEqual(expected_value, obtained_value, ensight_precision))
{
std::ostringstream oconv;
oconv << "Mismatch between expected and obtained value for the quadrature rule "
<< quadrature_rule.GetName() << " : obtained value is " << obtained_value << " whereas "
<< expected_value << " was expected.";
throw Exception(oconv.str(), __FILE__, __LINE__);
}
BOOST_CHECK(NumericNS::AreEqual(expected_value, obtained_value, ensight_precision));
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment