From 7260e78291bd1c2b63fda8e74607f181c42c611e Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Fri, 19 Nov 2021 14:29:33 -0700 Subject: [PATCH 1/2] add support for domain integrators restricted to certain attributes for FunctionalOutput --- CMakeLists.txt | 4 +-- src/common/functional_output.hpp | 62 +++++++++++++++++++++++++++++--- test/catch.hpp | 7 +++- 3 files changed, 66 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 06cd467a..b0997915 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -143,7 +143,7 @@ endif (MFEM_USE_EGADS) target_compile_features(mach PUBLIC - cxx_std_11 + cxx_std_17 ) set_target_properties(mach @@ -275,7 +275,7 @@ if (BUILD_PYTHON_WRAPPER) target_compile_features(pyMach PUBLIC - cxx_std_11 + cxx_std_17 ) if (MACH_USE_CLANG_TIDY) diff --git a/src/common/functional_output.hpp b/src/common/functional_output.hpp index 5ee6e3aa..ea508114 100644 --- a/src/common/functional_output.hpp +++ b/src/common/functional_output.hpp @@ -1,6 +1,11 @@ #ifndef MACH_FUNCTIONAL_OUTPUT #define MACH_FUNCTIONAL_OUTPUT +#include +#include +#include +#include + #include "mfem.hpp" #include "nlohmann/json.hpp" @@ -35,6 +40,17 @@ class FunctionalOutput final template void addOutputDomainIntegrator(T *integrator); + /// Adds domain integrator restricted to certain elements specified by the + /// attributes listed in @a bdr_attr_marker to the nonlinear form that backs + /// this output, and adds a reference to it to in integs as a MachIntegrator + /// \param[in] integrator - integrator to add to functional + /// \param[in] bdr_attr_marker - lists element attributes this integrator + /// should be used on + /// \tparam T - type of integrator, used for constructing MachIntegrator + template + void addOutputDomainIntegrator(T *integrator, + std::vector bdr_attr_marker); + /// Adds interface integrator to the nonlinear form that backs this output, /// and adds a reference to it to in integs as a MachIntegrator /// \param[in] integrator - integrator to add to functional @@ -47,6 +63,17 @@ class FunctionalOutput final /// \param[in] integrator - integrator to add to functional /// \tparam T - type of integrator, used for constructing MachIntegrator template + void addOutputBdrFaceIntegrator(T *integrator); + + /// Adds boundary integrator restricted to certain boundaries specified by + /// the attributes listed in @a bdr_attr_marker to the nonlinear form that + /// backs this output, and adds a reference to it to in integs as a + /// MachIntegrator + /// \param[in] integrator - integrator to add to functional + /// \param[in] bdr_attr_marker - lists boundary attributes this integrator + /// should be used on + /// \tparam T - type of integrator, used for constructing MachIntegrator + template void addOutputBdrFaceIntegrator(T *integrator, std::vector bdr_attr_marker); @@ -64,8 +91,12 @@ class FunctionalOutput final /// Collection of integrators to be applied. std::vector integs; + + /// Collection of element attribute markers for domain integrators + std::list> domain_markers; + /// Collection of boundary markers for boundary integrators - std::vector> bdr_markers; + std::list> bdr_markers; /// map of linear forms that will compute \frac{\partial J}{\partial field} /// for each field the functional depends on @@ -84,6 +115,19 @@ void FunctionalOutput::addOutputDomainIntegrator(T *integrator) *integrator, *func_fields, output_sens, output_scalar_sens); } +template +void FunctionalOutput::addOutputDomainIntegrator( + T *integrator, + std::vector bdr_attr_marker) +{ + integs.emplace_back(*integrator); + auto &marker = domain_markers.emplace_back(bdr_attr_marker.size()); + marker.Assign(bdr_attr_marker.data()); + output.AddDomainIntegrator(integrator, marker); + mach::addSensitivityIntegrator( + *integrator, *func_fields, output_sens, output_scalar_sens); +} + template void FunctionalOutput::addOutputInteriorFaceIntegrator(T *integrator) { @@ -93,15 +137,25 @@ void FunctionalOutput::addOutputInteriorFaceIntegrator(T *integrator) *integrator, *func_fields, output_sens, output_scalar_sens); } +template +void FunctionalOutput::addOutputBdrFaceIntegrator( + T *integrator) +{ + integs.emplace_back(*integrator); + output.AddBdrFaceIntegrator(integrator); + mach::addSensitivityIntegrator( + *integrator, *func_fields, output_sens, output_scalar_sens); +} + template void FunctionalOutput::addOutputBdrFaceIntegrator( T *integrator, std::vector bdr_attr_marker) { integs.emplace_back(*integrator); - bdr_markers.emplace_back(bdr_attr_marker.size()); - bdr_markers.back().Assign(bdr_attr_marker.data()); - output.AddBdrFaceIntegrator(integrator, bdr_markers.back()); + auto &marker = bdr_markers.emplace_back(bdr_attr_marker.size()); + marker.Assign(bdr_attr_marker.data()); + output.AddBdrFaceIntegrator(integrator, marker); mach::addSensitivityIntegrator( *integrator, *func_fields, output_sens, output_scalar_sens); } diff --git a/test/catch.hpp b/test/catch.hpp index 2edfc9f1..c1a2e025 100644 --- a/test/catch.hpp +++ b/test/catch.hpp @@ -7559,7 +7559,12 @@ namespace Catch { #ifdef CATCH_PLATFORM_MAC - #define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */ + // use inline assembler + #if defined(__i386__) || defined(__x86_64__) + #define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */ + #elif defined(__aarch64__) + #define CATCH_TRAP() __asm__(".inst 0xd4200000") /* NOLINT */ + #endif #elif defined(CATCH_PLATFORM_LINUX) // If we can use inline assembler, do it because this allows us to break From 29e2f885a480e942e59f9425ba6bfb981942ffc9 Mon Sep 17 00:00:00 2001 From: Tucker Babcock Date: Fri, 19 Nov 2021 14:30:32 -0700 Subject: [PATCH 2/2] make format --- src/common/functional_output.hpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/common/functional_output.hpp b/src/common/functional_output.hpp index ea508114..19ab16eb 100644 --- a/src/common/functional_output.hpp +++ b/src/common/functional_output.hpp @@ -45,7 +45,7 @@ class FunctionalOutput final /// this output, and adds a reference to it to in integs as a MachIntegrator /// \param[in] integrator - integrator to add to functional /// \param[in] bdr_attr_marker - lists element attributes this integrator - /// should be used on + /// should be used on /// \tparam T - type of integrator, used for constructing MachIntegrator template void addOutputDomainIntegrator(T *integrator, @@ -71,7 +71,7 @@ class FunctionalOutput final /// MachIntegrator /// \param[in] integrator - integrator to add to functional /// \param[in] bdr_attr_marker - lists boundary attributes this integrator - /// should be used on + /// should be used on /// \tparam T - type of integrator, used for constructing MachIntegrator template void addOutputBdrFaceIntegrator(T *integrator, @@ -117,8 +117,8 @@ void FunctionalOutput::addOutputDomainIntegrator(T *integrator) template void FunctionalOutput::addOutputDomainIntegrator( - T *integrator, - std::vector bdr_attr_marker) + T *integrator, + std::vector bdr_attr_marker) { integs.emplace_back(*integrator); auto &marker = domain_markers.emplace_back(bdr_attr_marker.size()); @@ -138,8 +138,7 @@ void FunctionalOutput::addOutputInteriorFaceIntegrator(T *integrator) } template -void FunctionalOutput::addOutputBdrFaceIntegrator( - T *integrator) +void FunctionalOutput::addOutputBdrFaceIntegrator(T *integrator) { integs.emplace_back(*integrator); output.AddBdrFaceIntegrator(integrator);