diff --git a/src/smith/physics/heat_transfer.hpp b/src/smith/physics/heat_transfer.hpp index c4b171c5b..d6a34250c 100644 --- a/src/smith/physics/heat_transfer.hpp +++ b/src/smith/physics/heat_transfer.hpp @@ -308,6 +308,26 @@ class HeatTransfer, std::integer_sequ } } + /** + * @brief Set essential temperature boundary conditions (strongly enforced) + * + * @param[in] applied_temperature The prescribed boundary temperature function + * @param[in] domain The domain over which the temperature is prescribed + * + * @note This should be called prior to completeSetup() + */ + template + void setTemperatureBCs(AppliedTemperatureFunction applied_temperature, Domain& domain) + { + auto mfem_coefficient_function = ([applied_temperature](const mfem::Vector& X_mfem, double t) { + auto X = make_tensor([&X_mfem](int k) { return X_mfem[k]; }); + return applied_temperature(X, t); + }); + temp_bdr_coef_ = std::make_shared(mfem_coefficient_function); + auto dof_list = domain.dof_list(&temperature_.space()); + bcs_.addEssential(dof_list, temp_bdr_coef_, temperature_.space(), 0); + } + /** * @brief Set essential temperature boundary conditions (strongly enforced) * diff --git a/src/smith/physics/tests/thermal_statics_patch.cpp b/src/smith/physics/tests/thermal_statics_patch.cpp index ccf9886f4..58278ebee 100644 --- a/src/smith/physics/tests/thermal_statics_patch.cpp +++ b/src/smith/physics/tests/thermal_statics_patch.cpp @@ -67,14 +67,22 @@ class AffineSolution { * * @param material Material model used in the problem * @param physics The HeatTransfer module for the problem - * @param essential_boundaries Boundary attributes on which essential boundary conditions are desired + * @param essential_domain Domain on which essential boundary conditions are desired */ template - void applyLoads(const Material& material, HeatTransfer& physics, std::set essential_boundaries, Domain & boundary) const + void applyLoads(const Material& material, HeatTransfer& physics, Domain &essential_domain, Domain & boundary) const { // essential BCs - auto ebc_func = [*this](const auto& X, auto){ return this->operator()(X); }; - physics.setTemperatureBCs(essential_boundaries, ebc_func); + auto ebc_func = [*this](const auto &X, auto) { + mfem::Vector X_mfem(dim); + X_mfem(0) = X[0]; + X_mfem(1) = X[1]; + if constexpr (dim==3) { + X_mfem(2) = X[2]; + } + return this->operator()(X_mfem); + }; + physics.setTemperatureBCs(ebc_func, essential_domain); // natural BCs auto temp_grad = make_tensor([&](int i) { return A(i); }); @@ -178,7 +186,8 @@ double solution_error(const ExactSolution& exact_temperature, PatchBoundaryCondi heat_transfer::LinearIsotropicConductor mat(1.0,1.0,1.0); thermal.setMaterial(mat, mesh->entireBody()); - exact_temperature.applyLoads(mat, thermal, essentialBoundaryAttributes(bc), mesh->entireBoundary()); + mesh->addDomainOfBoundaryElements("essBdr", by_attr(essentialBoundaryAttributes(bc))); + exact_temperature.applyLoads(mat, thermal, mesh->domain("essBdr"), mesh->entireBoundary()); // Finalize the data structures thermal.completeSetup(); @@ -264,4 +273,4 @@ int main(int argc, char* argv[]) ::testing::InitGoogleTest(&argc, argv); smith::ApplicationManager applicationManager(argc, argv); return RUN_ALL_TESTS(); -} +} \ No newline at end of file