19 constexpr
double bc_time_fd_step = 1.0e-4;
21 class SecondTimeDerivativeScalarCoefficient :
public mfem::Coefficient {
23 explicit SecondTimeDerivativeScalarCoefficient(std::shared_ptr<mfem::Coefficient> source) : source_(std::move(source))
27 double Eval(mfem::ElementTransformation& T,
const mfem::IntegrationPoint& ip)
override
29 const double t0 = GetTime();
32 const double f0 = source_->Eval(T, ip);
33 source_->SetTime(t0 + h);
34 const double f1 = source_->Eval(T, ip);
35 source_->SetTime(t0 + 2.0 * h);
36 const double f2 = source_->Eval(T, ip);
38 return (f2 - 2.0 * f1 + f0) / (h * h);
42 std::shared_ptr<mfem::Coefficient> source_;
45 class SecondTimeDerivativeVectorCoefficient :
public mfem::VectorCoefficient {
47 explicit SecondTimeDerivativeVectorCoefficient(std::shared_ptr<mfem::VectorCoefficient> source)
48 : mfem::VectorCoefficient(source->GetVDim()), source_(std::move(source))
52 void Eval(mfem::Vector& V, mfem::ElementTransformation& T,
const mfem::IntegrationPoint& ip)
override
54 const double t0 = GetTime();
56 mfem::Vector v0(vdim), v1(vdim), v2(vdim);
58 source_->Eval(v0, T, ip);
59 source_->SetTime(t0 + h);
60 source_->Eval(v1, T, ip);
61 source_->SetTime(t0 + 2.0 * h);
62 source_->Eval(v2, T, ip);
71 std::shared_ptr<mfem::VectorCoefficient> source_;
77 mfem::ParFiniteElementSpace&
space)
78 : mfem_mesh_(mfem_mesh), bcs_(mfem_mesh), space_(
space)
89 second_derivative_manager_.emplace(mfem_mesh_);
90 rebuildSecondDerivativeManager(*second_derivative_manager_);
91 return *second_derivative_manager_;
98 auto deriv_coef = std::make_shared<SecondTimeDerivativeVectorCoefficient>(
99 get<std::shared_ptr<mfem::VectorCoefficient>>(bc.coefficient()));
102 auto deriv_coef = std::make_shared<SecondTimeDerivativeScalarCoefficient>(
103 get<std::shared_ptr<mfem::Coefficient>>(bc.coefficient()));
104 target.
addEssential(bc.getLocalDofList(), deriv_coef, space_, bc.component());
This file contains the declaration of the boundary condition class.
This file contains the declaration of the boundary condition manager class.
A container for the boundary condition information relating to a specific physics module.
void addEssentialByTrueDofs(const mfem::Array< int > &true_dofs, std::shared_ptr< mfem::VectorCoefficient > ess_bdr_coef, mfem::ParFiniteElementSpace &space)
std::vector< BoundaryCondition > & essentials()
Accessor for the essential BC objects.
void addEssential(const std::set< int > &ess_bdr, smith::GeneralCoefficient ess_bdr_coef, mfem::ParFiniteElementSpace &space, const std::optional< int > component={})
Set the essential boundary conditions from a list of boundary markers and a coefficient.
A generic class for setting Dirichlet boundary conditions on arbitrary physics.
const smith::BoundaryConditionManager & getSecondDerivativeManager() const
Return the BC manager whose prescribed values are the second time derivative of the value-level BC,...
DirichletBoundaryConditions(const mfem::ParMesh &mfem_mesh, mfem::ParFiniteElementSpace &space)
Construct from mfem::ParMesh.
Helper class for constructing a mesh consistent with Smith.
Contains DirichletBoundaryConditions class for interaction with the differentiable solve interfaces.
Smith mesh class which assists in constructing the appropriate parallel mfem meshes and registering a...
Accelerator functionality.
constexpr T & get(variant< T0, T1 > &v)
Returns the variant member of specified type.
SMITH_HOST_DEVICE auto max(dual< gradient_type > a, double b)
Implementation of max for dual numbers.
bool is_vector_valued(const GeneralCoefficient &coef)
convenience function for querying the type stored in a GeneralCoefficient
SMITH_HOST_DEVICE auto abs(dual< gradient_type > x)
Implementation of absolute value function for dual numbers.
mfem::ParFiniteElementSpace & space(FieldState field)
Get the space from the primal field of a field states.