]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Avoid 'using namespace' declarations. 13300/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Thu, 27 Jan 2022 19:22:45 +0000 (12:22 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Thu, 27 Jan 2022 21:13:22 +0000 (14:13 -0700)
These declarations are dangerous and lead to difficult to find errors when
used in header files, but also in .cc files when used in scopes that one
can re-enter and when we use unity builds. Avoid where possible.

source/algorithms/timestep_control.cc
source/grid/manifold.cc
source/non_matching/quadrature_generator.cc
source/sundials/arkode.cc
source/sundials/ida.cc
source/sundials/kinsol.cc

index a0e4670584229f739aaccbbc21882c54222765be..00262893d252ac4ff63178b8c54ea1fb389aa4fb 100644 (file)
 
 DEAL_II_NAMESPACE_OPEN
 
-using namespace Algorithms;
-
-TimestepControl::TimestepControl(double start,
-                                 double final,
-                                 double tolerance,
-                                 double start_step,
-                                 double print_step,
-                                 double max_step)
-  : start_val(start)
-  , final_val(final)
-  , tolerance_val(tolerance)
-  , start_step_val(start_step)
-  , max_step_val(max_step)
-  , min_step_val(0)
-  , current_step_val(start_step)
-  , step_val(start_step)
-  , print_step(print_step)
-  , next_print_val(print_step > 0. ? start_val + print_step : start_val - 1.)
+namespace Algorithms
 {
-  now_val = start_val;
+  TimestepControl::TimestepControl(double start,
+                                   double final,
+                                   double tolerance,
+                                   double start_step,
+                                   double print_step,
+                                   double max_step)
+    : start_val(start)
+    , final_val(final)
+    , tolerance_val(tolerance)
+    , start_step_val(start_step)
+    , max_step_val(max_step)
+    , min_step_val(0)
+    , current_step_val(start_step)
+    , step_val(start_step)
+    , print_step(print_step)
+    , next_print_val(print_step > 0. ? start_val + print_step : start_val - 1.)
+  {
+    now_val = start_val;
+
+    // avoid compiler warning
+    (void)min_step_val;
+  }
+
+
+
+  void
+  TimestepControl::declare_parameters(ParameterHandler &param)
+  {
+    param.declare_entry("Start", "0.", Patterns::Double());
+    param.declare_entry("Final", "1.", Patterns::Double());
+    param.declare_entry("First step", "1.e-2", Patterns::Double(0.));
+    param.declare_entry("Max step", "1.", Patterns::Double(0.));
+    param.declare_entry("Tolerance", "1.e-2", Patterns::Double(0.));
+    param.declare_entry("Print step", "-1.", Patterns::Double());
+  }
+
+
+
+  void
+  TimestepControl::parse_parameters(ParameterHandler &param)
+  {
+    start(param.get_double("Start"));
+    start_step(param.get_double("First step"));
+    max_step(param.get_double("Max step"));
+    final(param.get_double("Final"));
+    tolerance(param.get_double("Tolerance"));
+    print_step = param.get_double("Print step");
+  }
+
+
+
+  bool
+  TimestepControl::advance()
+  {
+    bool changed = false;
+
+    // Try incrementing time by s
+    double now_trial = now_val + step_val;
+    current_step_val = step_val;
+
+    // If we just missed the final time, increase the step size a bit. This way,
+    // we avoid a very small final step. If the step shot over the final time,
+    // adjust it so we hit the final time exactly.
+    double s1 = .01 * step_val;
+    if (now_trial > final_val - s1)
+      {
+        current_step_val = final_val - now_val;
+        now_trial        = final_val;
+        changed          = true;
+      }
+
+    now_val = now_trial;
+    return changed;
+  }
+
+
+  bool
+  TimestepControl::print()
+  {
+    if (print_step == 0.)
+      return false;
+    if (print_step < 0.)
+      return true;
+
+    bool result = (now_val >= next_print_val);
+
+    if (result)
+      {
+        next_print_val += print_step;
+        if (next_print_val > final_val)
+          next_print_val = final_val;
+      }
+    return result;
+  }
+
+} // namespace Algorithms
 
-  // avoid compiler warning
-  (void)min_step_val;
-}
-
-
-
-void
-TimestepControl::declare_parameters(ParameterHandler &param)
-{
-  param.declare_entry("Start", "0.", Patterns::Double());
-  param.declare_entry("Final", "1.", Patterns::Double());
-  param.declare_entry("First step", "1.e-2", Patterns::Double(0.));
-  param.declare_entry("Max step", "1.", Patterns::Double(0.));
-  param.declare_entry("Tolerance", "1.e-2", Patterns::Double(0.));
-  param.declare_entry("Print step", "-1.", Patterns::Double());
-}
-
-
-
-void
-TimestepControl::parse_parameters(ParameterHandler &param)
-{
-  start(param.get_double("Start"));
-  start_step(param.get_double("First step"));
-  max_step(param.get_double("Max step"));
-  final(param.get_double("Final"));
-  tolerance(param.get_double("Tolerance"));
-  print_step = param.get_double("Print step");
-}
-
-
-
-bool
-TimestepControl::advance()
-{
-  bool changed = false;
-
-  // Try incrementing time by s
-  double now_trial = now_val + step_val;
-  current_step_val = step_val;
-
-  // If we just missed the final time, increase the step size a bit. This way,
-  // we avoid a very small final step. If the step shot over the final time,
-  // adjust it so we hit the final time exactly.
-  double s1 = .01 * step_val;
-  if (now_trial > final_val - s1)
-    {
-      current_step_val = final_val - now_val;
-      now_trial        = final_val;
-      changed          = true;
-    }
-
-  now_val = now_trial;
-  return changed;
-}
-
-
-bool
-TimestepControl::print()
-{
-  if (print_step == 0.)
-    return false;
-  if (print_step < 0.)
-    return true;
-
-  bool result = (now_val >= next_print_val);
-
-  if (result)
-    {
-      next_print_val += print_step;
-      if (next_print_val > final_val)
-        next_print_val = final_val;
-    }
-  return result;
-}
 
 DEAL_II_NAMESPACE_CLOSE
index 71f0d0573d15f939e4a44a2b139a9856fe8ef073..af15a11cabb721e9240a5a7f6a4b9d6611dd2152 100644 (file)
@@ -32,8 +32,6 @@ DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
 
 DEAL_II_NAMESPACE_OPEN
 
-using namespace Manifolds;
-
 /* -------------------------- Manifold --------------------- */
 template <int dim, int spacedim>
 Point<spacedim>
@@ -318,7 +316,7 @@ Point<spacedim>
 Manifold<dim, spacedim>::get_new_point_on_line(
   const typename Triangulation<dim, spacedim>::line_iterator &line) const
 {
-  const auto points_weights = get_default_points_and_weights(line);
+  const auto points_weights = Manifolds::get_default_points_and_weights(line);
   return get_new_point(make_array_view(points_weights.first.begin(),
                                        points_weights.first.end()),
                        make_array_view(points_weights.second.begin(),
@@ -332,7 +330,7 @@ Point<spacedim>
 Manifold<dim, spacedim>::get_new_point_on_quad(
   const typename Triangulation<dim, spacedim>::quad_iterator &quad) const
 {
-  const auto points_weights = get_default_points_and_weights(quad);
+  const auto points_weights = Manifolds::get_default_points_and_weights(quad);
   return get_new_point(make_array_view(points_weights.first.begin(),
                                        points_weights.first.end()),
                        make_array_view(points_weights.second.begin(),
@@ -463,7 +461,8 @@ Point<3>
 Manifold<3, 3>::get_new_point_on_hex(
   const Triangulation<3, 3>::hex_iterator &hex) const
 {
-  const auto points_weights = get_default_points_and_weights(hex, true);
+  const auto points_weights =
+    Manifolds::get_default_points_and_weights(hex, true);
   return get_new_point(make_array_view(points_weights.first.begin(),
                                        points_weights.first.end()),
                        make_array_view(points_weights.second.begin(),
index cef3e4e3b4d3494ba9d3fb085b3d079989a577f5..0775c86910432f59dc6e668d9edcedc4cfbc3621 100644 (file)
@@ -27,6 +27,7 @@
 #include <vector>
 
 DEAL_II_NAMESPACE_OPEN
+
 namespace NonMatching
 {
   namespace internal
@@ -1253,8 +1254,6 @@ namespace NonMatching
     } // namespace QuadratureGeneratorImplementation
   }   // namespace internal
 
-  using namespace internal::QuadratureGeneratorImplementation;
-
 
 
   AdditionalQGeneratorData::AdditionalQGeneratorData(
index b8da2b5f5b204fee14283d7bb7b1797fe39b6026..5118490a36d91e423b0db82c58b5879b95e859e2 100644 (file)
@@ -61,8 +61,6 @@ DEAL_II_NAMESPACE_OPEN
 
 namespace SUNDIALS
 {
-  using namespace internal;
-
   namespace
   {
     template <typename VectorType>
@@ -519,7 +517,8 @@ namespace SUNDIALS
 
     if (get_local_tolerances)
       {
-        const auto abs_tols = make_nvector_view(get_local_tolerances());
+        const auto abs_tols =
+          internal::make_nvector_view(get_local_tolerances());
         status =
           ARKodeSVtolerances(arkode_mem, data.relative_tolerance, abs_tols);
         AssertARKode(status);
index 27b78198517c983b04209b37499d18ea4af044ef..fe212f4e3e9d93efd4b9e46bb6989b68d3ac3d44 100644 (file)
@@ -54,8 +54,6 @@ DEAL_II_NAMESPACE_OPEN
 
 namespace SUNDIALS
 {
-  using namespace internal;
-
   namespace
   {
     template <typename VectorType>
index 78e951b8d2ca52d32c0345ecad0164b54aa15b7d..d26f1bfe12a8f44ce290b117e712e7ab3cde6f32 100644 (file)
@@ -50,9 +50,6 @@ DEAL_II_NAMESPACE_OPEN
 
 namespace SUNDIALS
 {
-  using namespace internal;
-
-
   template <typename VectorType>
   KINSOL<VectorType>::AdditionalData::AdditionalData(
     const SolutionStrategy &strategy,
@@ -328,7 +325,7 @@ namespace SUNDIALS
   unsigned int
   KINSOL<VectorType>::solve(VectorType &initial_guess_and_solution)
   {
-    NVectorView<VectorType> u_scale, f_scale;
+    internal::NVectorView<VectorType> u_scale, f_scale;
 
     VectorType u_scale_temp, f_scale_temp;
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.