From a213af10477078888c8063377c693515c44dfeb3 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Mon, 3 Dec 2018 18:34:04 +0100 Subject: [PATCH] Fix all Wfloat-conversion warnings --- cmake/setup_compiler_flags_gnu.cmake | 9 +++++---- examples/step-44/step-44.cc | 13 +++++++------ include/deal.II/lac/precondition.h | 6 ++++-- include/deal.II/lac/vector.templates.h | 8 +++++--- .../matrix_free/mapping_info.templates.h | 2 +- .../deal.II/numerics/vector_tools.templates.h | 8 ++++---- source/base/function_lib.cc | 3 ++- source/base/polynomials_bernardi_raugel.cc | 5 +++-- source/base/process_grid.cc | 2 +- source/grid/grid_generator.cc | 2 +- source/grid/grid_in.cc | 10 +++++----- source/grid/grid_out.cc | 7 ++++--- source/lac/scalapack.cc | 19 +++++++++++-------- 13 files changed, 53 insertions(+), 41 deletions(-) diff --git a/cmake/setup_compiler_flags_gnu.cmake b/cmake/setup_compiler_flags_gnu.cmake index b971b51edd..ede5ec6e34 100644 --- a/cmake/setup_compiler_flags_gnu.cmake +++ b/cmake/setup_compiler_flags_gnu.cmake @@ -56,13 +56,14 @@ ENABLE_IF_LINKS(DEAL_II_LINKER_FLAGS "-Wl,--as-needed") # ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-Wall") ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-Wextra") +ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-Wfloat-conversion") +ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-Woverloaded-virtual") ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-Wpointer-arith") -ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-Wwrite-strings") -ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-Wsynth") ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-Wsign-compare") -ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-Wswitch") -ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-Woverloaded-virtual") ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-Wsuggest-override") +ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-Wswitch") +ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-Wsynth") +ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-Wwrite-strings") # # Disable Wplacement-new that will trigger a lot of warnings diff --git a/examples/step-44/step-44.cc b/examples/step-44/step-44.cc index 6adad3e281..c40d4af574 100644 --- a/examples/step-44/step-44.cc +++ b/examples/step-44/step-44.cc @@ -3052,8 +3052,9 @@ namespace Step44 std::cout << " SLV " << std::flush; if (parameters.type_lin == "CG") { - const int solver_its = tangent_matrix.block(u_dof, u_dof).m() * - parameters.max_iterations_lin; + const int solver_its = + static_cast(tangent_matrix.block(u_dof, u_dof).m() * + parameters.max_iterations_lin); const double tol_sol = parameters.tol_lin * system_rhs.block(u_dof).l2_norm(); @@ -3272,8 +3273,8 @@ namespace Step44 preconditioner_K_Jp_inv.use_matrix( tangent_matrix.block(J_dof, p_dof)); ReductionControl solver_control_K_Jp_inv( - tangent_matrix.block(J_dof, p_dof).m() * - parameters.max_iterations_lin, + static_cast(tangent_matrix.block(J_dof, p_dof).m() * + parameters.max_iterations_lin), 1.0e-30, parameters.tol_lin); SolverSelector> solver_K_Jp_inv; @@ -3315,8 +3316,8 @@ namespace Step44 preconditioner_K_con_inv.use_matrix( tangent_matrix.block(u_dof, u_dof)); ReductionControl solver_control_K_con_inv( - tangent_matrix.block(u_dof, u_dof).m() * - parameters.max_iterations_lin, + static_cast(tangent_matrix.block(u_dof, u_dof).m() * + parameters.max_iterations_lin), 1.0e-30, parameters.tol_lin); SolverSelector> solver_K_con_inv; diff --git a/include/deal.II/lac/precondition.h b/include/deal.II/lac/precondition.h index 45bdb20c13..e61138208a 100644 --- a/include/deal.II/lac/precondition.h +++ b/include/deal.II/lac/precondition.h @@ -2206,8 +2206,10 @@ PreconditionChebyshev:: const_cast< PreconditionChebyshev *>( this) - ->data.degree = 1 + std::log(1. / eps + std::sqrt(1. / eps / eps - 1)) / - std::log(1. / sigma); + ->data.degree = + 1 + static_cast( + std::log(1. / eps + std::sqrt(1. / eps / eps - 1)) / + std::log(1. / sigma)); } const_cast< diff --git a/include/deal.II/lac/vector.templates.h b/include/deal.II/lac/vector.templates.h index c35616d887..d299a8f7f4 100644 --- a/include/deal.II/lac/vector.templates.h +++ b/include/deal.II/lac/vector.templates.h @@ -565,7 +565,8 @@ Vector::l2_norm() const norm2, 0, vec_size, norm_square, thread_loop_partitioner); if (numbers::is_finite(norm_square) && norm_square >= std::numeric_limits::min()) - return std::sqrt(norm_square); + return static_cast::real_type>( + std::sqrt(norm_square)); else { real_type scale = 0.; @@ -578,7 +579,7 @@ Vector::l2_norm() const numbers::NumberTraits::abs(values[i]); if (scale < abs_x) { - sum = 1. + sum * (scale / abs_x) * (scale / abs_x); + sum = 1 + sum * (scale / abs_x) * (scale / abs_x); scale = abs_x; } else @@ -586,7 +587,8 @@ Vector::l2_norm() const } } AssertIsFinite(scale * std::sqrt(sum)); - return scale * std::sqrt(sum); + return static_cast::real_type>(scale * + std::sqrt(sum)); } } diff --git a/include/deal.II/matrix_free/mapping_info.templates.h b/include/deal.II/matrix_free/mapping_info.templates.h index 2a5f7f1354..e64815cd18 100644 --- a/include/deal.II/matrix_free/mapping_info.templates.h +++ b/include/deal.II/matrix_free/mapping_info.templates.h @@ -514,7 +514,7 @@ namespace internal // compress out very small values for (unsigned int d = 0; d < dim; ++d) for (unsigned int e = 0; e < dim; ++e) - if (std::fabs(jac_0[d][e])) + if (std::fabs(jac_0[d][e]) != 0.) cell_data.const_jac[d][e][j] = jac_0[d][e]; continue; } diff --git a/include/deal.II/numerics/vector_tools.templates.h b/include/deal.II/numerics/vector_tools.templates.h index 5fc5378e52..6eac0117ad 100644 --- a/include/deal.II/numerics/vector_tools.templates.h +++ b/include/deal.II/numerics/vector_tools.templates.h @@ -1194,7 +1194,7 @@ namespace VectorTools // steps may not be sufficient, since roundoff errors may accumulate for // badly conditioned matrices. This behavior can be observed, e.g. for // FE_Q_Hierarchical for degree higher than three. - ReductionControl control(6. * rhs.size(), 0., 1e-12, false, false); + ReductionControl control(6 * rhs.size(), 0., 1e-12, false, false); SolverCG> cg(control); PreconditionJacobi preconditioner; preconditioner.initialize(mass_matrix, 1.); @@ -1554,7 +1554,7 @@ namespace VectorTools // steps may not be sufficient, since roundoff errors may accumulate for // badly conditioned matrices. This behavior can be observed, e.g. for // FE_Q_Hierarchical for degree higher than three. - ReductionControl control(5. * rhs.size(), 0., 1e-12, false, false); + ReductionControl control(5 * rhs.size(), 0., 1e-12, false, false); SolverCG> cg(control); typename PreconditionJacobi::AdditionalData data(0.8); PreconditionJacobi preconditioner; @@ -1647,7 +1647,7 @@ namespace VectorTools // steps may not be sufficient, since roundoff errors may accumulate for // badly conditioned matrices. This behavior can be observed, e.g. for // FE_Q_Hierarchical for degree higher than three. - ReductionControl control(5. * rhs.size(), 0., 1e-12, false, false); + ReductionControl control(5 * rhs.size(), 0., 1e-12, false, false); SolverCG> cg(control); typename PreconditionJacobi::AdditionalData data(0.8); PreconditionJacobi preconditioner; @@ -3341,7 +3341,7 @@ namespace VectorTools // steps may not be sufficient, since roundoff errors may accumulate for // badly conditioned matrices. This behavior can be observed, e.g. for // FE_Q_Hierarchical for degree higher than three. - ReductionControl control(5. * rhs.size(), 0., 1.e-12, false, false); + ReductionControl control(5 * rhs.size(), 0., 1.e-12, false, false); GrowingVectorMemory> memory; SolverCG> cg(control, memory); diff --git a/source/base/function_lib.cc b/source/base/function_lib.cc index 400547f9b1..891cf67524 100644 --- a/source/base/function_lib.cc +++ b/source/base/function_lib.cc @@ -2647,7 +2647,8 @@ namespace Functions else if (p[d] >= interval_endpoints[d].second - delta_x) ix[d] = n_subintervals[d] - 1; else - ix[d] = (p[d] - interval_endpoints[d].first) / delta_x; + ix[d] = static_cast( + (p[d] - interval_endpoints[d].first) / delta_x); } // now compute the relative point within the interval/rectangle/box diff --git a/source/base/polynomials_bernardi_raugel.cc b/source/base/polynomials_bernardi_raugel.cc index 67e581fcb9..af1570d297 100644 --- a/source/base/polynomials_bernardi_raugel.cc +++ b/source/base/polynomials_bernardi_raugel.cc @@ -97,8 +97,9 @@ PolynomialsBernardiRaugel::compute( std::vector> bubble_third_derivatives; std::vector> bubble_fourth_derivatives; - int n_bubbles = std::pow(3, dim); // size for create_polynomials_bubble - int n_q = 1 << dim; // size for create_polynomials_q + constexpr int n_bubbles = + Utilities::pow(3, dim); // size for create_polynomials_bubble + constexpr int n_q = 1 << dim; // size for create_polynomials_q // don't resize if the provided vector has 0 length Q_values.resize((values.size() == 0) ? 0 : n_q); diff --git a/source/base/process_grid.cc b/source/base/process_grid.cc index dcb77b7162..b9cc3149d5 100644 --- a/source/base/process_grid.cc +++ b/source/base/process_grid.cc @@ -65,7 +65,7 @@ namespace // Np = Pc * Pc / ratio // for quadratic matrices the ratio equals 1 const double ratio = double(n) / m; - int Pc = std::floor(std::sqrt(ratio * Np)); + int Pc = static_cast(std::sqrt(ratio * Np)); // one could rounds up Pc to the number which has zero remainder from the // division of Np while ( Np % Pc != 0 ) diff --git a/source/grid/grid_generator.cc b/source/grid/grid_generator.cc index 392680e204..0adc1855fa 100644 --- a/source/grid/grid_generator.cc +++ b/source/grid/grid_generator.cc @@ -2004,7 +2004,7 @@ namespace GridGenerator const double h) -> void { // use std::round instead of std::ceil to improve aspect ratio // in case padding is only slightly larger than h. - const unsigned int rounded = std::round(padding / h); + const auto rounded = static_cast(std::round(padding / h)); // in case padding is much smaller than h, make sure we // have at least 1 element const unsigned int num = (padding > 0. && rounded == 0) ? 1 : rounded; diff --git a/source/grid/grid_in.cc b/source/grid/grid_in.cc index 8e091d0a48..46f105e3e4 100644 --- a/source/grid/grid_in.cc +++ b/source/grid/grid_in.cc @@ -412,7 +412,7 @@ GridIn::read_vtk(std::istream &in) // the order used in the following blocks makes sense for (unsigned int i = 0; i < cells.size(); i++) { - double id; + types::manifold_id id; in >> id; if (set == "MaterialID") cells[i].material_id = id; @@ -428,7 +428,7 @@ GridIn::read_vtk(std::istream &in) i < subcelldata.boundary_quads.size(); i++) { - double id; + types::manifold_id id; in >> id; if (set == "MaterialID") subcelldata.boundary_quads[i].material_id = id; @@ -441,7 +441,7 @@ GridIn::read_vtk(std::istream &in) i < subcelldata.boundary_lines.size(); i++) { - double id; + types::manifold_id id; in >> id; if (set == "MaterialID") subcelldata.boundary_lines[i].material_id = id; @@ -457,7 +457,7 @@ GridIn::read_vtk(std::istream &in) i < subcelldata.boundary_lines.size(); i++) { - double id; + types::manifold_id id; in >> id; if (set == "MaterialID") subcelldata.boundary_lines[i].material_id = id; @@ -1437,7 +1437,7 @@ GridIn::read_msh(std::istream &in) in >> version >> file_type >> data_size; Assert((version >= 2.0) && (version <= 4.0), ExcNotImplemented()); - gmsh_file_format = version; + gmsh_file_format = static_cast(version); Assert(file_type == 0, ExcNotImplemented()); Assert(data_size == sizeof(double), ExcNotImplemented()); diff --git a/source/grid/grid_out.cc b/source/grid/grid_out.cc index 543f400ebd..325e78dbae 100644 --- a/source/grid/grid_out.cc +++ b/source/grid/grid_out.cc @@ -2330,9 +2330,10 @@ GridOut::write_svg(const Triangulation<2, 2> &tria, std::ostream &out) const camera_horizontal, camera_focus); - const unsigned int font_size_this_cell = - .5 + cell_label_font_size * - std::pow(.5, cell->level() - 4. + 3.5 * distance_factor); + const auto font_size_this_cell = static_cast( + .5 + + cell_label_font_size * + std::pow(.5, cell->level() - 4. + 3.5 * distance_factor)); out << " ::invert() AssertThrow(info == 0, LAPACKSupport::ExcErrorCode("pgetri", info)); - lwork = work[0]; + lwork = static_cast(work[0]); liwork = iwork[0]; work.resize(lwork); iwork.resize(liwork); @@ -1655,7 +1655,7 @@ ScaLAPACKMatrix::eigenpairs_symmetric( &info); AssertThrow(info == 0, LAPACKSupport::ExcErrorCode("psyevx", info)); } - lwork = work[0]; + lwork = static_cast(work[0]); work.resize(lwork); if (all_eigenpairs) @@ -1929,7 +1929,7 @@ ScaLAPACKMatrix::eigenpairs_symmetric_MRRR( AssertThrow(info == 0, LAPACKSupport::ExcErrorCode("psyevr", info)); - lwork = work[0]; + lwork = static_cast(work[0]); work.resize(lwork); liwork = iwork[0]; iwork.resize(liwork); @@ -2091,7 +2091,7 @@ ScaLAPACKMatrix::compute_SVD(ScaLAPACKMatrix *U, &info); AssertThrow(info == 0, LAPACKSupport::ExcErrorCode("pgesvd", info)); - lwork = work[0]; + lwork = static_cast(work[0]); work.resize(lwork); pgesvd(&jobu, @@ -2197,7 +2197,7 @@ ScaLAPACKMatrix::least_squares(ScaLAPACKMatrix &B, &info); AssertThrow(info == 0, LAPACKSupport::ExcErrorCode("pgels", info)); - lwork = work[0]; + lwork = static_cast(work[0]); work.resize(lwork); pgels(&trans, @@ -2346,7 +2346,7 @@ ScaLAPACKMatrix::reciprocal_condition_number( &liwork, &info); AssertThrow(info == 0, LAPACKSupport::ExcErrorCode("pdpocon", info)); - lwork = std::ceil(work[0]); + lwork = static_cast(std::ceil(work[0])); work.resize(lwork); // now the actual run: @@ -2846,7 +2846,8 @@ ScaLAPACKMatrix::save_parallel( * the minimum value for NB yields that only ceil(400/32)=13 processes will be * writing the matrix to disk. */ - const int NB = std::max((int)std::ceil((double)n_columns / n_mpi_processes), + const int NB = std::max(static_cast(std::ceil( + static_cast(n_columns) / n_mpi_processes)), column_block_size); ScaLAPACKMatrix tmp(n_rows, n_columns, column_grid, MB, NB); @@ -3268,8 +3269,10 @@ ScaLAPACKMatrix::load_parallel(const std::string &filename) const int MB = n_rows; // for the choice of NB see explanation in save_parallel() - const int NB = std::max((int)std::ceil((double)n_columns / n_mpi_processes), + const int NB = std::max(static_cast(std::ceil( + static_cast(n_columns) / n_mpi_processes)), column_block_size); + ScaLAPACKMatrix tmp(n_rows, n_columns, column_grid, MB, NB); // get pointer to data held by the process -- 2.39.5