Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/smith/physics/heat_transfer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,26 @@ class HeatTransfer<order, dim, Parameters<parameter_space...>, 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 <typename AppliedTemperatureFunction>
void setTemperatureBCs(AppliedTemperatureFunction applied_temperature, Domain& domain)
{
auto mfem_coefficient_function = ([applied_temperature](const mfem::Vector& X_mfem, double t) {
auto X = make_tensor<dim>([&X_mfem](int k) { return X_mfem[k]; });
return applied_temperature(X, t);
});
temp_bdr_coef_ = std::make_shared<mfem::FunctionCoefficient>(mfem_coefficient_function);
auto dof_list = domain.dof_list(&temperature_.space());
bcs_.addEssential(dof_list, temp_bdr_coef_, temperature_.space(), 0);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally tried to write this line without providing the std::optional<int> component, but that caused the test to seg fault. If I provide the 0 the test passes, but I don't understand why I need to provide a component for a scalar field. Any ideas @btalamini @tupek2 ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember seeing this before. I think the path where you dont specify the int is just implemented wrong somewhere down in the depths. We should probably get rid of that option and force the component to always be passed.

}

/**
* @brief Set essential temperature boundary conditions (strongly enforced)
*
Expand Down
21 changes: 15 additions & 6 deletions src/smith/physics/tests/thermal_statics_patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <int p, typename Material>
void applyLoads(const Material& material, HeatTransfer<p, dim>& physics, std::set<int> essential_boundaries, Domain & boundary) const
void applyLoads(const Material& material, HeatTransfer<p, dim>& 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<dim>([&](int i) { return A(i); });
Expand Down Expand Up @@ -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<dim>(bc), mesh->entireBoundary());
mesh->addDomainOfBoundaryElements("essBdr", by_attr<dim>(essentialBoundaryAttributes<dim>(bc)));
exact_temperature.applyLoads(mat, thermal, mesh->domain("essBdr"), mesh->entireBoundary());

// Finalize the data structures
thermal.completeSetup();
Expand Down Expand Up @@ -264,4 +273,4 @@ int main(int argc, char* argv[])
::testing::InitGoogleTest(&argc, argv);
smith::ApplicationManager applicationManager(argc, argv);
return RUN_ALL_TESTS();
}
}