From fd59605b5292f3ad1ad6d0e7780d17353a736b96 Mon Sep 17 00:00:00 2001 From: Fabian Castelli Date: Sat, 21 Aug 2021 17:23:26 +0200 Subject: [PATCH] AssertDimension macro in examples --- doc/doxygen/headers/coding_conventions.h | 3 +-- examples/step-12/step-12.cc | 3 +-- examples/step-12b/step-12b.cc | 3 +-- examples/step-17/step-17.cc | 5 ++--- examples/step-18/step-18.cc | 10 ++++------ examples/step-20/doc/results.dox | 6 ++---- examples/step-20/step-20.cc | 3 +-- examples/step-21/step-21.cc | 6 ++---- examples/step-29/step-29.cc | 15 +++++---------- examples/step-30/step-30.cc | 9 +++------ examples/step-35/step-35.cc | 6 ++---- examples/step-43/step-43.cc | 3 +-- examples/step-58/step-58.cc | 20 ++++++-------------- examples/step-61/step-61.cc | 3 +-- examples/step-63/step-63.cc | 6 ++---- examples/step-8/step-8.cc | 3 +-- examples/step-9/step-9.cc | 4 ++++ 17 files changed, 39 insertions(+), 69 deletions(-) diff --git a/doc/doxygen/headers/coding_conventions.h b/doc/doxygen/headers/coding_conventions.h index c7a22bc8d0..128f14060b 100644 --- a/doc/doxygen/headers/coding_conventions.h +++ b/doc/doxygen/headers/coding_conventions.h @@ -308,8 +308,7 @@ we list here: operator+=(Vector &lhs, const Vector &rhs) { - Assert (lhs.size() == rhs.size(), - ExcDimensionMismatch(lhs.size(), rhs.size()); + AssertDimension (lhs.size(), rhs.size()); for (unsigned int i=0; i &p, Vector & values) const override { - Assert(values.size() == dim, ExcDimensionMismatch(values.size(), dim)); + AssertDimension(values.size(), dim); Assert(dim >= 2, ExcInternalError()); Point point_1, point_2; @@ -209,8 +209,7 @@ namespace Step17 { const unsigned int n_points = points.size(); - Assert(value_list.size() == n_points, - ExcDimensionMismatch(value_list.size(), n_points)); + AssertDimension(value_list.size(), n_points); for (unsigned int p = 0; p < n_points; ++p) RightHandSide::vector_value(points[p], value_list[p]); diff --git a/examples/step-18/step-18.cc b/examples/step-18/step-18.cc index b54569e9e2..f0906082ac 100644 --- a/examples/step-18/step-18.cc +++ b/examples/step-18/step-18.cc @@ -559,7 +559,7 @@ namespace Step18 inline void BodyForce::vector_value(const Point & /*p*/, Vector &values) const { - Assert(values.size() == dim, ExcDimensionMismatch(values.size(), dim)); + AssertDimension(values.size(), dim); const double g = 9.81; const double rho = 7700; @@ -577,8 +577,7 @@ namespace Step18 { const unsigned int n_points = points.size(); - Assert(value_list.size() == n_points, - ExcDimensionMismatch(value_list.size(), n_points)); + AssertDimension(value_list.size(), n_points); for (unsigned int p = 0; p < n_points; ++p) BodyForce::vector_value(points[p], value_list[p]); @@ -650,7 +649,7 @@ namespace Step18 IncrementalBoundaryValues::vector_value(const Point & /*p*/, Vector &values) const { - Assert(values.size() == dim, ExcDimensionMismatch(values.size(), dim)); + AssertDimension(values.size(), dim); values = 0; values(2) = -present_timestep * velocity; @@ -665,8 +664,7 @@ namespace Step18 { const unsigned int n_points = points.size(); - Assert(value_list.size() == n_points, - ExcDimensionMismatch(value_list.size(), n_points)); + AssertDimension(value_list.size(), n_points); for (unsigned int p = 0; p < n_points; ++p) IncrementalBoundaryValues::vector_value(points[p], value_list[p]); diff --git a/examples/step-20/doc/results.dox b/examples/step-20/doc/results.dox index 9afeb6fdaa..bccc6f073c 100644 --- a/examples/step-20/doc/results.dox +++ b/examples/step-20/doc/results.dox @@ -179,8 +179,7 @@ void KInverse::value_list (const std::vector > &points, std::vector > &values) const { - Assert (points.size() == values.size(), - ExcDimensionMismatch (points.size(), values.size())); + AssertDimension (points.size(), values.size()); for (unsigned int p=0; p::value_list (const std::vector > &points, std::vector > &values) const { - Assert (points.size() == values.size(), - ExcDimensionMismatch (points.size(), values.size())); + AssertDimension (points.size(), values.size()); for (unsigned int p=0; p::vector_value(const Point &p, Vector & values) const { - Assert(values.size() == dim + 1, - ExcDimensionMismatch(values.size(), dim + 1)); + AssertDimension(values.size(), dim + 1); values(0) = alpha * p[1] * p[1] / 2 + beta - alpha * p[0] * p[0] / 2; values(1) = alpha * p[0] * p[1]; diff --git a/examples/step-21/step-21.cc b/examples/step-21/step-21.cc index cd96bfdec3..a3032ae782 100644 --- a/examples/step-21/step-21.cc +++ b/examples/step-21/step-21.cc @@ -267,8 +267,7 @@ namespace Step21 value_list(const std::vector> &points, std::vector> & values) const override { - Assert(points.size() == values.size(), - ExcDimensionMismatch(points.size(), values.size())); + AssertDimension(points.size(), values.size()); for (unsigned int p = 0; p < points.size(); ++p) { @@ -336,8 +335,7 @@ namespace Step21 value_list(const std::vector> &points, std::vector> & values) const override { - Assert(points.size() == values.size(), - ExcDimensionMismatch(points.size(), values.size())); + AssertDimension(points.size(), values.size()); for (unsigned int p = 0; p < points.size(); ++p) { diff --git a/examples/step-29/step-29.cc b/examples/step-29/step-29.cc index 03a3f0479f..fa77819392 100644 --- a/examples/step-29/step-29.cc +++ b/examples/step-29/step-29.cc @@ -102,7 +102,7 @@ namespace Step29 virtual void vector_value(const Point & /*p*/, Vector &values) const override { - Assert(values.size() == 2, ExcDimensionMismatch(values.size(), 2)); + AssertDimension(values.size(), 2); values(0) = 1; values(1) = 0; @@ -112,8 +112,7 @@ namespace Step29 vector_value_list(const std::vector> &points, std::vector> & value_list) const override { - Assert(value_list.size() == points.size(), - ExcDimensionMismatch(value_list.size(), points.size())); + AssertDimension(value_list.size(), points.size()); for (unsigned int p = 0; p < points.size(); ++p) DirichletBoundaryValues::vector_value(points[p], value_list[p]); @@ -326,9 +325,7 @@ namespace Step29 const DataPostprocessorInputs::Vector &inputs, std::vector> & computed_quantities) const { - Assert(computed_quantities.size() == inputs.solution_values.size(), - ExcDimensionMismatch(computed_quantities.size(), - inputs.solution_values.size())); + AssertDimension(computed_quantities.size(), inputs.solution_values.size()); // The computation itself is straightforward: We iterate over each // entry in the output vector and compute $|u|$ from the @@ -341,10 +338,8 @@ namespace Step29 // something called a "norm".) for (unsigned int i = 0; i < computed_quantities.size(); ++i) { - Assert(computed_quantities[i].size() == 1, - ExcDimensionMismatch(computed_quantities[i].size(), 1)); - Assert(inputs.solution_values[i].size() == 2, - ExcDimensionMismatch(inputs.solution_values[i].size(), 2)); + AssertDimension(computed_quantities[i].size(), 1); + AssertDimension(inputs.solution_values[i].size(), 2); const std::complex u(inputs.solution_values[i](0), inputs.solution_values[i](1)); diff --git a/examples/step-30/step-30.cc b/examples/step-30/step-30.cc index 87ac7be48a..1f151aab4b 100644 --- a/examples/step-30/step-30.cc +++ b/examples/step-30/step-30.cc @@ -63,8 +63,7 @@ namespace Step30 const unsigned int /*component*/ = 0) const override { (void)points; - Assert(values.size() == points.size(), - ExcDimensionMismatch(values.size(), points.size())); + AssertDimension(values.size(), points.size()); std::fill(values.begin(), values.end(), 0.); } @@ -79,8 +78,7 @@ namespace Step30 std::vector & values, const unsigned int /*component*/ = 0) const override { - Assert(values.size() == points.size(), - ExcDimensionMismatch(values.size(), points.size())); + AssertDimension(values.size(), points.size()); for (unsigned int i = 0; i < values.size(); ++i) { @@ -110,8 +108,7 @@ namespace Step30 void value_list(const std::vector> &points, std::vector> & values) const { - Assert(values.size() == points.size(), - ExcDimensionMismatch(values.size(), points.size())); + AssertDimension(values.size(), points.size()); for (unsigned int i = 0; i < points.size(); ++i) { diff --git a/examples/step-35/step-35.cc b/examples/step-35/step-35.cc index a0dc153f79..bee2871a98 100644 --- a/examples/step-35/step-35.cc +++ b/examples/step-35/step-35.cc @@ -352,8 +352,7 @@ namespace Step35 const unsigned int) const { const unsigned int n_points = points.size(); - Assert(values.size() == n_points, - ExcDimensionMismatch(values.size(), n_points)); + AssertDimension(values.size(), n_points); for (unsigned int i = 0; i < n_points; ++i) values[i] = Velocity::value(points[i]); } @@ -411,8 +410,7 @@ namespace Step35 (void)component; AssertIndexRange(component, 1); const unsigned int n_points = points.size(); - Assert(values.size() == n_points, - ExcDimensionMismatch(values.size(), n_points)); + AssertDimension(values.size(), n_points); for (unsigned int i = 0; i < n_points; ++i) values[i] = Pressure::value(points[i]); } diff --git a/examples/step-43/step-43.cc b/examples/step-43/step-43.cc index bd6fdf7869..f44a9c8de5 100644 --- a/examples/step-43/step-43.cc +++ b/examples/step-43/step-43.cc @@ -185,8 +185,7 @@ namespace Step43 void KInverse::value_list(const std::vector> &points, std::vector> & values) const { - Assert(points.size() == values.size(), - ExcDimensionMismatch(points.size(), values.size())); + AssertDimension(points.size(), values.size()); for (unsigned int p = 0; p < points.size(); ++p) { diff --git a/examples/step-58/step-58.cc b/examples/step-58/step-58.cc index bacc1c947b..e21bc2a775 100644 --- a/examples/step-58/step-58.cc +++ b/examples/step-58/step-58.cc @@ -477,16 +477,12 @@ namespace Step58 const DataPostprocessorInputs::Vector &inputs, std::vector> & computed_quantities) const { - Assert(computed_quantities.size() == inputs.solution_values.size(), - ExcDimensionMismatch(computed_quantities.size(), - inputs.solution_values.size())); + AssertDimension(computed_quantities.size(), inputs.solution_values.size()); for (unsigned int q = 0; q < computed_quantities.size(); ++q) { - Assert(computed_quantities[q].size() == 1, - ExcDimensionMismatch(computed_quantities[q].size(), 1)); - Assert(inputs.solution_values[q].size() == 2, - ExcDimensionMismatch(inputs.solution_values[q].size(), 2)); + AssertDimension(computed_quantities[q].size(), 1); + AssertDimension(inputs.solution_values[q].size(), 2); const std::complex psi(inputs.solution_values[q](0), inputs.solution_values[q](1)); @@ -536,17 +532,13 @@ namespace Step58 const DataPostprocessorInputs::Vector &inputs, std::vector> & computed_quantities) const { - Assert(computed_quantities.size() == inputs.solution_values.size(), - ExcDimensionMismatch(computed_quantities.size(), - inputs.solution_values.size())); + AssertDimension(computed_quantities.size(), inputs.solution_values.size()); double max_phase = -numbers::PI; for (unsigned int q = 0; q < computed_quantities.size(); ++q) { - Assert(computed_quantities[q].size() == 1, - ExcDimensionMismatch(computed_quantities[q].size(), 1)); - Assert(inputs.solution_values[q].size() == 2, - ExcDimensionMismatch(inputs.solution_values[q].size(), 2)); + AssertDimension(computed_quantities[q].size(), 1); + AssertDimension(inputs.solution_values[q].size(), 2); max_phase = std::max(max_phase, diff --git a/examples/step-61/step-61.cc b/examples/step-61/step-61.cc index d3c35b6b2a..a13ae7f6f4 100644 --- a/examples/step-61/step-61.cc +++ b/examples/step-61/step-61.cc @@ -141,8 +141,7 @@ namespace Step61 void Coefficient::value_list(const std::vector> &points, std::vector> & values) const { - Assert(points.size() == values.size(), - ExcDimensionMismatch(points.size(), values.size())); + AssertDimension(points.size(), values.size()); for (unsigned int p = 0; p < points.size(); ++p) values[p] = unit_symmetric_tensor(); } diff --git a/examples/step-63/step-63.cc b/examples/step-63/step-63.cc index eb4122d19b..01db361eaf 100644 --- a/examples/step-63/step-63.cc +++ b/examples/step-63/step-63.cc @@ -388,8 +388,7 @@ namespace Step63 std::vector & values, const unsigned int component) const { - Assert(values.size() == points.size(), - ExcDimensionMismatch(values.size(), points.size())); + AssertDimension(values.size(), points.size()); for (unsigned int i = 0; i < points.size(); ++i) values[i] = RightHandSide::value(points[i], component); @@ -439,8 +438,7 @@ namespace Step63 std::vector & values, const unsigned int component) const { - Assert(values.size() == points.size(), - ExcDimensionMismatch(values.size(), points.size())); + AssertDimension(values.size(), points.size()); for (unsigned int i = 0; i < points.size(); ++i) values[i] = BoundaryValues::value(points[i], component); diff --git a/examples/step-8/step-8.cc b/examples/step-8/step-8.cc index 15f3734fca..8b5700c42c 100644 --- a/examples/step-8/step-8.cc +++ b/examples/step-8/step-8.cc @@ -138,8 +138,7 @@ namespace Step8 void right_hand_side(const std::vector> &points, std::vector> & values) { - Assert(values.size() == points.size(), - ExcDimensionMismatch(values.size(), points.size())); + AssertDimension(values.size(), points.size()); Assert(dim >= 2, ExcNotImplemented()); // The rest of the function implements computing force values. We will use diff --git a/examples/step-9/step-9.cc b/examples/step-9/step-9.cc index d29c49fed8..c00b03a26c 100644 --- a/examples/step-9/step-9.cc +++ b/examples/step-9/step-9.cc @@ -117,6 +117,10 @@ namespace Step9 // this macro call declares and defines a class // ExcDimensionMismatch inheriting from ExceptionBase which // implements all necessary error output functions. + // + // @note This exception is similarly used inside the + // AssertDimension macro, which is a handy wrapper to the + // check the dimensions of two given objects. }; // The following two functions implement the interface described above. The -- 2.39.5