diff --git a/CMakeLists.txt b/CMakeLists.txt index d3a1975274..4ec117f47e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,7 +81,7 @@ endif() # Tune BLT to our needs if (NOT BLT_CXX_STD) - set(BLT_CXX_STD "c++17" CACHE STRING "") + set(BLT_CXX_STD "c++20" CACHE STRING "") endif() # These BLT tools are not used in Smith, turn them off diff --git a/cmake/SmithCompilerFlags.cmake b/cmake/SmithCompilerFlags.cmake index 7546975849..505645d554 100644 --- a/cmake/SmithCompilerFlags.cmake +++ b/cmake/SmithCompilerFlags.cmake @@ -30,7 +30,6 @@ endif() set(_extra_flags "-Wshadow -Wdouble-promotion -Wconversion -Wundef -Wnull-dereference -Wold-style-cast") blt_append_custom_compiler_flag(FLAGS_VAR CMAKE_CXX_FLAGS DEFAULT ${_extra_flags}) -# Only clang has fine-grained control over the designated initializer warnings -# This can be added to the GCC flags when C++20 is available -# This should be compatible with Clang 8 through Clang 12 -blt_append_custom_compiler_flag(FLAGS_VAR CMAKE_CXX_FLAGS CLANG "-Wpedantic -Wno-c++2a-extensions -Wunused-private-field") +# Clang specific warnings +# Note: pedantic is a gcc flag but throws a false positive in src/smith/numerics/petsc_solvers.cpp +blt_append_custom_compiler_flag(FLAGS_VAR CMAKE_CXX_FLAGS CLANG "-Wpedantic -Wunused-private-field") diff --git a/src/smith/infrastructure/about.cpp b/src/smith/infrastructure/about.cpp index 43d5b75070..8e34b9ea1b 100644 --- a/src/smith/infrastructure/about.cpp +++ b/src/smith/infrastructure/about.cpp @@ -55,27 +55,26 @@ namespace smith { std::string about() { - using namespace axom::fmt; [[maybe_unused]] constexpr std::string_view on = "ON"; [[maybe_unused]] constexpr std::string_view off = "OFF"; std::string about = "\n"; // Version info - about += format("Smith Version: {0}\n", version()); + about += axom::fmt::format("Smith Version: {0}\n", version()); about += "\n"; // General configuration #ifdef SMITH_DEBUG - about += format("Debug Build: {0}\n", on); + about += axom::fmt::format("Debug Build: {0}\n", on); #else - about += format("Debug Build: {0}\n", off); + about += axom::fmt::format("Debug Build: {0}\n", off); #endif #ifdef SMITH_USE_CUDA - about += format("CUDA: {0}\n", on); + about += axom::fmt::format("CUDA: {0}\n", on); #else - about += format("CUDA: {0}\n", off); + about += axom::fmt::format("CUDA: {0}\n", off); #endif about += "\n"; @@ -91,21 +90,21 @@ std::string about() about += "Enabled Libraries:\n"; // Axom - about += format("Axom Version: {0}\n", axom::getVersion()); + about += axom::fmt::format("Axom Version: {0}\n", axom::getVersion()); // Camp - about += format("Camp Version: {0}\n", CAMP_VERSION); + about += axom::fmt::format("Camp Version: {0}\n", CAMP_VERSION); // Caliper #ifdef SMITH_USE_CALIPER - about += format("Caliper Version: {0}\n", CALIPER_VERSION); + about += axom::fmt::format("Caliper Version: {0}\n", CALIPER_VERSION); #else disabled_libs.push_back("Caliper"); #endif // Conduit #ifdef SMITH_USE_CONDUIT - about += format("Conduit Version: {0}\n", CONDUIT_VERSION); + about += axom::fmt::format("Conduit Version: {0}\n", CONDUIT_VERSION); #else disabled_libs.push_back("Conduit"); #endif @@ -117,9 +116,9 @@ std::string about() if (H5get_libversion(&h5_maj, &h5_min, &h5_rel) < 0) { SLIC_ERROR("Failed to retrieve HDF5 version."); } else { - h5_version = format("{0}.{1}.{2}", h5_maj, h5_min, h5_rel); + h5_version = axom::fmt::format("{0}.{1}.{2}", h5_maj, h5_min, h5_rel); } - about += format("HDF5 Version: {0}\n", h5_version); + about += axom::fmt::format("HDF5 Version: {0}\n", h5_version); #else disabled_libs.push_back("HDF5"); #endif @@ -130,7 +129,7 @@ std::string about() if (axom::utilities::string::startsWith(lua_version, "Lua ")) { lua_version.erase(0, 4); } - about += format("Lua Version: {0}\n", lua_version); + about += axom::fmt::format("Lua Version: {0}\n", lua_version); #else disabled_libs.push_back("Lua"); #endif @@ -149,28 +148,29 @@ std::string about() mfem_full_version.erase(0, 5); } if (mfem_sha[0] != '\0') { - mfem_full_version += format(" (Git SHA: {0})", mfem_sha); + mfem_full_version += axom::fmt::format(" (Git SHA: {0})", mfem_sha); } - about += format("MFEM Version: {0}\n", mfem_full_version); + about += axom::fmt::format("MFEM Version: {0}\n", mfem_full_version); // RAJA #ifdef SMITH_USE_RAJA - about += format("RAJA Version: {0}.{1}.{2}\n", RAJA_VERSION_MAJOR, RAJA_VERSION_MINOR, RAJA_VERSION_PATCHLEVEL); + about += axom::fmt::format("RAJA Version: {0}.{1}.{2}\n", RAJA_VERSION_MAJOR, RAJA_VERSION_MINOR, + RAJA_VERSION_PATCHLEVEL); #else disabled_libs.push_back("RAJA"); #endif // Tribol #ifdef SMITH_USE_TRIBOL - about += format("Tribol Version: {0}\n", TRIBOL_VERSION_FULL); + about += axom::fmt::format("Tribol Version: {0}\n", TRIBOL_VERSION_FULL); #else disabled_libs.push_back("Tribol"); #endif // Umpire #ifdef SMITH_USE_UMPIRE - about += format("Umpire Version: {0}.{1}.{2}\n", umpire::get_major_version(), umpire::get_minor_version(), - umpire::get_patch_version()); + about += axom::fmt::format("Umpire Version: {0}.{1}.{2}\n", umpire::get_major_version(), + umpire::get_minor_version(), umpire::get_patch_version()); #else disabled_libs.push_back("Umpire"); #endif diff --git a/src/smith/physics/functional_objective.hpp b/src/smith/physics/functional_objective.hpp index fc9b1c8cea..9df4693976 100644 --- a/src/smith/physics/functional_objective.hpp +++ b/src/smith/physics/functional_objective.hpp @@ -118,7 +118,7 @@ class FunctionalObjective, std::integer_ const std::vector& fs) const { return (*objective_)(time, *shape_disp, *fs[i]...); - }; + } /// @brief Utility to get array of jacobian functions, one for each input field in fs template @@ -128,10 +128,10 @@ class FunctionalObjective, std::integer_ using JacFuncType = std::function{}, time, *shape_disp, *fs[i]...))( double, ConstFieldPtr, const std::vector&)>; return std::array{ - [=](double _time, ConstFieldPtr _shape_disp, const std::vector& _fs) { + [this](double _time, ConstFieldPtr _shape_disp, const std::vector& _fs) { return (*objective_)(DifferentiateWRT{}, _time, *_shape_disp, *_fs[i]...); }...}; - }; + } /// @brief timestep, this needs to be held here and modified for rate dependent applications. mutable double dt_ = std::numeric_limits::max(); diff --git a/src/smith/physics/functional_weak_form.hpp b/src/smith/physics/functional_weak_form.hpp index af7723f5b9..0e9374bee1 100644 --- a/src/smith/physics/functional_weak_form.hpp +++ b/src/smith/physics/functional_weak_form.hpp @@ -407,10 +407,10 @@ class FunctionalWeakForm, using JacFuncType = std::function{}, time, *shape_disp, *fs[i]...))( double, ConstFieldPtr, const std::vector&)>; return std::array{ - [=](double _time, ConstFieldPtr _shape_disp, const std::vector& _fs) { + [this](double _time, ConstFieldPtr _shape_disp, const std::vector& _fs) { return (*weak_form_)(DifferentiateWRT{}, _time, *_shape_disp, *_fs[i]...); }...}; - }; + } /// @brief Utility to get array of jvp functions, one for each input field in fs template @@ -421,10 +421,10 @@ class FunctionalWeakForm, std::function{}, time, *shape_disp, *v, *fs[i]...))( double, ConstFieldPtr, ConstFieldPtr, const std::vector&)>; return std::array{ - [=](double _time, ConstFieldPtr _shape_disp, ConstFieldPtr _v, const std::vector& _fs) { + [this](double _time, ConstFieldPtr _shape_disp, ConstFieldPtr _v, const std::vector& _fs) { return (*v_dot_weak_form_residual_)(DifferentiateWRT{}, _time, *_shape_disp, *_v, *_fs[i]...); }...}; - }; + } /// @brief timestep, this needs to be held here and modified for rate dependent applications mutable double dt_ = std::numeric_limits::max(); diff --git a/src/smith/physics/materials/parameterized_solid_material.hpp b/src/smith/physics/materials/parameterized_solid_material.hpp index 3f9b0fb2d4..b24daa2059 100644 --- a/src/smith/physics/materials/parameterized_solid_material.hpp +++ b/src/smith/physics/materials/parameterized_solid_material.hpp @@ -200,7 +200,7 @@ struct ParameterizedJ2Nonlinear { { using std::exp; return sigma_sat - (sigma_sat - sigma_y) * exp(-accumulated_plastic_strain / strain_constant); - }; + } }; } // namespace smith::solid_mechanics diff --git a/src/smith/physics/materials/solid_material.hpp b/src/smith/physics/materials/solid_material.hpp index 552ebf107a..0bdadd4aa5 100644 --- a/src/smith/physics/materials/solid_material.hpp +++ b/src/smith/physics/materials/solid_material.hpp @@ -193,7 +193,7 @@ struct LinearHardening { auto operator()(T1 accumulated_plastic_strain, T2 accumulated_plastic_strain_rate) const { return sigma_y + Hi * accumulated_plastic_strain + overstress(eta, accumulated_plastic_strain_rate); - }; + } }; /** @@ -220,7 +220,7 @@ struct PowerLawHardening { using std::pow; return sigma_y * pow(1.0 + accumulated_plastic_strain / eps0, 1.0 / n) + overstress(eta, accumulated_plastic_strain_rate); - }; + } }; /** @@ -252,7 +252,7 @@ struct VoceHardening { auto& epsilon_p_dot = accumulated_plastic_strain_rate; auto Y_vis = overstress(eta, epsilon_p_dot); return Y_eq + Y_vis; - }; + } }; /// @brief J2 material with nonlinear isotropic hardening and linear kinematic hardening diff --git a/src/smith/physics/state/state_manager.hpp b/src/smith/physics/state/state_manager.hpp index c451c03233..4326c030f7 100644 --- a/src/smith/physics/state/state_manager.hpp +++ b/src/smith/physics/state/state_manager.hpp @@ -160,21 +160,14 @@ class StateManager { std::string(geom_name))); axom::sidre::Group* geom_group = qdatas_group->getGroup(std::string(geom_name)); - // Verify size correctness - auto verify_size = [](axom::sidre::Group* group, axom::IndexType value, const std::string& view_name, - const std::string& err_msg) { - SLIC_ERROR_IF( - !group->hasView(view_name), - axom::fmt::format("Loaded Sidre Datastore does not have value '{}' for Quadrature Data.", view_name)); - auto prev_value = group->getView(view_name)->getData(); - SLIC_ERROR_IF(value != prev_value, axom::fmt::format(err_msg, value, prev_value)); - }; - verify_size(geom_group, num_states, "num_states", - "Current number of Quadrature Data States '{}' does not match value in restart '{}'."); - verify_size(geom_group, state_size, "state_size", - "Current size of Quadrature Data State '{}' does not match value in restart '{}'."); - verify_size(geom_group, total_size, "total_size", - "Current total size of Quadrature Data States '{}' does not match value in restart '{}'."); + verifyQuadratureDataSize( + geom_group, num_states, "num_states", + "Current number of Quadrature Data States '{}' does not match value in restart '{}'."); + verifyQuadratureDataSize(geom_group, state_size, "state_size", + "Current size of Quadrature Data State '{}' does not match value in restart '{}'."); + verifyQuadratureDataSize( + geom_group, total_size, "total_size", + "Current total size of Quadrature Data States '{}' does not match value in restart '{}'."); // Tell Sidre where the external array is SLIC_ERROR_ROOT_IF(!geom_group->hasView("states"), @@ -453,6 +446,23 @@ class StateManager { static double time(std::string mesh_tag); private: + /** + * @brief Verifies the current and restart size of Quadrature Data and errors + * with a helpful error message. + * @param[in] group Sidre Group that holds the Quadrature Datas + * @param[in] value Desired size of the Quadrature Data + * @param[in] view_name Name of the view that holds the specific Quadrature Data + * @param[in] err_msg Format string for helpful error message + */ + static void verifyQuadratureDataSize(axom::sidre::Group* group, axom::IndexType value, const char* view_name, + const char* err_msg) + { + SLIC_ERROR_IF(!group->hasView(view_name), + axom::fmt::format("Loaded Sidre Datastore does not have value '{}' for Quadrature Data.", view_name)); + auto prev_value = group->getView(view_name)->getData(); + SLIC_ERROR_IF(value != prev_value, axom::fmt::format(axom::fmt::runtime(err_msg), value, prev_value)); + } + /** * @brief Creates a new datacollection based on a registered mesh * @param[in] mesh_tag The mesh name used to name the new datacollection diff --git a/src/smith/physics/tests/dynamic_solid_adjoint.cpp b/src/smith/physics/tests/dynamic_solid_adjoint.cpp index b9fb65e30e..50e19abbfd 100644 --- a/src/smith/physics/tests/dynamic_solid_adjoint.cpp +++ b/src/smith/physics/tests/dynamic_solid_adjoint.cpp @@ -526,13 +526,13 @@ TEST_F(BucklingSensitivityFixture, QuasiStaticShapeSensitivities) solid_solver->setFixedBCs(applied_displacement_surface); auto K = smith::StateManager::newState(DensitySpace{}, kname, mesh_tag); - K.setFromFieldFunction([=](smith::tensor x) { + K.setFromFieldFunction([this](smith::tensor x) { double scaling = ((x[0] < 3) && (x[0] > 2)) ? 0.99 : 0.001; return scaling * mat.K0; }); auto G = smith::StateManager::newState(DensitySpace{}, gname, mesh_tag); - G.setFromFieldFunction([=](smith::tensor x) { + G.setFromFieldFunction([this](smith::tensor x) { double scaling = ((x[0] <= 3) && (x[0] >= 2)) ? 0.99 : 0.001; return scaling * mat.G0; }); diff --git a/src/smith/physics/tests/thermomech_finite_diff.cpp b/src/smith/physics/tests/thermomech_finite_diff.cpp index 0f76f8f05a..30a41609ab 100644 --- a/src/smith/physics/tests/thermomech_finite_diff.cpp +++ b/src/smith/physics/tests/thermomech_finite_diff.cpp @@ -68,7 +68,7 @@ void FiniteDifferenceParameter(LoadingType load, size_t sensitivity_parameter_in // Construct the appropriate dimension mesh and give it to the data store std::string filename = SMITH_REPO_DIR "/data/meshes/patch2D_tris_and_quads.mesh"; - std::string mesh_tag("mesh"); + std::string mesh_tag = MESHTAG; auto mesh = std::make_shared(buildMeshFromFile(filename), mesh_tag, serial_refinement, parallel_refinement); @@ -281,7 +281,7 @@ void FiniteDifferenceShapeTest(LoadingType load) // Construct the appropriate dimension mesh and give it to the data store std::string filename = SMITH_REPO_DIR "/data/meshes/patch2D_tris_and_quads.mesh"; - std::string mesh_tag("mesh"); + std::string mesh_tag = MESHTAG; auto mesh = std::make_shared(buildMeshFromFile(filename), mesh_tag, serial_refinement, parallel_refinement); diff --git a/src/smith/physics/tests/thermomech_statics_patch.cpp b/src/smith/physics/tests/thermomech_statics_patch.cpp index 186f05f24d..a11a2c58f0 100644 --- a/src/smith/physics/tests/thermomech_statics_patch.cpp +++ b/src/smith/physics/tests/thermomech_statics_patch.cpp @@ -218,24 +218,24 @@ class ManufacturedSolution { tm.setDisplacementBCs(disp_ebc_func, disp_ess_bdr); // natural BCs - auto flux = [=](auto X, auto n0, auto /* time */, auto /* T */) { + auto flux = [this, &material](auto X, auto n0, auto /* time */, auto /* T */) { typename MaterialType::State state{}; - auto theta = evalT(get<0>(X)); - auto dtheta_dX = gradT(get<0>(X)); - auto du_dX = gradU(get<0>(X)); + auto theta = this->evalT(get<0>(X)); + auto dtheta_dX = this->gradT(get<0>(X)); + auto du_dX = this->gradU(get<0>(X)); auto [stress, heat_accumulation, internal_heat_source, heat_flux] = material(state, du_dX, theta, dtheta_dX); return dot(heat_flux, n0); }; tm.setFluxBCs(flux, tm.mesh().entireBoundary()); - auto traction = [=](auto X, auto n0, auto /* time */) { + auto traction = [this, &material](auto X, auto n0, auto /* time */) { typename MaterialType::State state{}; - auto theta = evalT(get_value(X)); - auto dtheta_dX = gradT(get_value(X)); - auto du_dX = gradU(get_value(X)); + auto theta = this->evalT(get_value(X)); + auto dtheta_dX = this->gradT(get_value(X)); + auto du_dX = this->gradU(get_value(X)); auto [stress, heat_accumulation, internal_heat_source, heat_flux] = material(state, du_dX, theta, dtheta_dX); return dot(stress, n0); @@ -243,14 +243,14 @@ class ManufacturedSolution { tm.setTraction(traction, tm.mesh().entireBoundary()); // Forcing functions - auto heat_source = [=](auto X, auto /* time */, auto /* T */, auto /* dTdX*/) { + auto heat_source = [this, &material](auto X, auto /* time */, auto /* T */, auto /* dTdX*/) { typename MaterialType::State state{}; auto X_val_temp = get<0>(X); auto X_val = get_value(X_val_temp); - auto theta = evalT(X_val); - auto dtheta_dX = gradT(make_dual(X_val)); - auto du_dX = gradU(X_val); + auto theta = this->evalT(X_val); + auto dtheta_dX = this->gradT(make_dual(X_val)); + auto du_dX = this->gradU(X_val); auto [stress, heat_accumulation, internal_heat_source, heat_flux] = material(state, du_dX, theta, dtheta_dX); auto dFluxdX = get_gradient(heat_flux); @@ -259,13 +259,13 @@ class ManufacturedSolution { }; tm.setSource(heat_source, tm.mesh().entireBody()); - auto body_force = [=](auto X, auto /* time */) { + auto body_force = [this, &material](auto X, auto /* time */) { typename MaterialType::State state{}; auto X_val = get_value(X); - auto theta = evalT(make_dual(X_val)); - auto dtheta_dX = gradT(X_val); - auto du_dX = gradU(make_dual(X_val)); + auto theta = this->evalT(make_dual(X_val)); + auto dtheta_dX = this->gradT(X_val); + auto du_dX = this->gradU(make_dual(X_val)); auto [stress, heat_accumulation, internal_heat_source, heat_flux] = material(state, du_dX, theta, dtheta_dX); auto dPdX = get_gradient(stress);