15 x = std::min(std::max(tol,x),
real_t(1.0)-tol);
16 return std::log(x/(1.0-x));
24 return 1.0/(1.0+std::exp(-x));
28 return std::exp(x)/(1.0+std::exp(x));
36 return tmp - std::pow(tmp,2);
91 return value1 - value2;
139 MFEM_ASSERT(rho_min_ >= 0.0,
"rho_min must be >= 0");
140 MFEM_ASSERT(rho_min_ < 1.0,
"rho_min must be < 1");
141 MFEM_ASSERT(
u,
"displacement field is not set");
142 MFEM_ASSERT(
rho_filter,
"density field is not set");
151 real_t density = L*div_u*div_u;
153 for (
int i=0; i<
dim; i++)
155 for (
int j=0; j<
dim; j++)
184 for (
int i=0; i<xx.
Size(); i++)
186 xx[i]=xx[i]-center[i];
218 Mesh * mesh =
nullptr;
256 pmesh =
dynamic_cast<ParMesh *
>(mesh);
257 if (pmesh) { parallel =
true; }
288 MFEM_ABORT(
"Wrong code path. Call GetLinearForm");
311 Mesh * mesh =
nullptr;
342 pmesh =
dynamic_cast<ParMesh *
>(mesh);
343 if (pmesh) { parallel =
true; }
369 MFEM_ABORT(
"Wrong code path. Call GetLinearForm");
396 real_t tol = 1e-12,
int max_its = 100)
409 std::unique_ptr<LinearForm> int_sigmoid_psi;
426 int_sigmoid_psi->Assemble();
430 int_sigmoid_psi->Assemble();
431 real_t f_b = int_sigmoid_psi->Sum();
436 MPI_SUM, MPI_COMM_WORLD);
438 MPI_SUM, MPI_COMM_WORLD);
441 f_a -= target_volume;
442 f_b -= target_volume;
448 for (
int k=0; k < max_its; k++)
450 c = (f_a *
b - f_b *
a) / (f_a - f_b);
452 if (std::fabs(
b -
a) < tol * std::fabs(
b +
a)) { done =
true;
break; }
455 int_sigmoid_psi->Assemble();
456 f_c = int_sigmoid_psi->Sum();
461 MPI_SUM, MPI_COMM_WORLD);
464 f_c -= target_volume;
470 if (side == -1) { f_a /= 2.0; }
473 else if (f_c * f_a > 0)
477 if (side == 1) { f_b /= 2.0; }
487 mfem_warning(
"Projection reached maximum iteration without converging. "
488 "Result may not be accurate.");
492 int_sigmoid_psi->Assemble();
493 real_t material_volume = int_sigmoid_psi->
Sum();
497 MPI_Allreduce(MPI_IN_PLACE, &material_volume, 1,
501 return material_volume;
508 : mesh(mesh_), order(order_), diffcf(diffcf_), rhscf(rhscf_)
512 pmesh =
dynamic_cast<ParMesh *
>(mesh);
513 if (pmesh) { parallel =
true; }
572 if (update_ess_tdofs)
623 MFEM_VERIFY(neumann_bdr.
Size(),
"neumann_bdr attributes not provided");
626 else if (gradient_cf)
628 MFEM_VERIFY(neumann_bdr.
Size(),
"neumann_bdr attributes not provided");
649 ess_tdof_list, X, B);
681 cg->SetRelTol(1e-12);
682 cg->SetMaxIter(10000);
683 cg->SetPrintLevel(0);
684 cg->SetPreconditioner(*M);
706 MFEM_ABORT(
"Wrong code path. Call GetFEMSolution");
714 delete u; u =
nullptr;
715 delete fes; fes =
nullptr;
717 delete pfes; pfes=
nullptr;
719 delete fec; fec =
nullptr;
730 : mesh(mesh_), order(order_), lambda_cf(lambda_cf_), mu_cf(mu_cf_)
733 pmesh =
dynamic_cast<ParMesh *
>(mesh);
734 if (pmesh) { parallel =
true; }
862 cg->SetRelTol(1e-10);
863 cg->SetMaxIter(10000);
864 cg->SetPrintLevel(0);
865 cg->SetPreconditioner(*M);
870 a->RecoverFEMSolution(X, *b, *x);
890 MFEM_ABORT(
"Wrong code path. Call GetFEMSolution");
898 delete u; u =
nullptr;
899 delete fes; fes =
nullptr;
901 delete pfes; pfes=
nullptr;
903 delete fec; fec =
nullptr;
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
int Size() const
Return the logical size of the array.
@ Positive
Bernstein polynomials.
Class for boundary integration .
Class for boundary integration .
Conjugate gradient method.
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
virtual real_t Eval(ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the coefficient in the element described by T at the point ip.
A coefficient that is constant across space and time.
Data type dense matrix using column-major storage.
real_t Trace() const
Trace of a square matrix.
Returns f(u(x)) - f(v(x)) where u, v are scalar GridFunctions and f:R → R.
GridFunctionCoefficient OtherGridF_cf
void SetFunction(std::function< real_t(const real_t)> fun_)
DiffMappedGridFunctionCoefficient(const GridFunction *gf, const GridFunction *other_gf, std::function< real_t(const real_t)> fun_, int comp=1)
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient in the element described by T at the point ip.
const GridFunction * OtherGridF
DiffMappedGridFunctionCoefficient()
std::function< real_t(const real_t)> fun
Class for solving Poisson's equation:
ParGridFunction * GetParFEMSolution()
void SetNeumannData(Coefficient *neumann_cf_)
LinearForm * GetLinearForm()
void AssembleDiffusionBilinear(bool update_ess_tdofs=true)
ParLinearForm * GetParLinearForm()
void SetDiffusionCoefficient(Coefficient *diffcf_)
void SetGradientData(VectorCoefficient *gradient_cf_)
void SetRHSCoefficient(Coefficient *rhscf_)
void SetNeumannBoundary(const Array< int > &neumann_bdr_)
void SetOrder(int order_)
void SetEssBdrData(Coefficient *essbdr_cf_)
void SetMesh(Mesh *mesh_)
void UpdateEssentialTDofs()
void SetMassCoefficient(Coefficient *masscf_)
GridFunction * GetFEMSolution()
void SetEssentialBoundary(const Array< int > &ess_bdr_)
Class for domain integration .
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
virtual void GetEssentialTrueDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_tdof_list, int component=-1) const
Get a list of essential true dofs, ess_tdof_list, corresponding to the boundary attributes marked in ...
Gauss-Seidel smoother of a sparse matrix.
Coefficient defined by a GridFunction. This coefficient is mesh dependent.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
Class for grid function - Vector with associated FE space.
virtual real_t GetValue(int i, const IntegrationPoint &ip, int vdim=1) const
void GetVectorGradient(ElementTransformation &tr, DenseMatrix &grad) const
Compute the vector gradient with respect to the physical element variable.
virtual real_t ComputeMaxError(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Returns Max|u_ex - u_h| error for H1 or L2 elements.
FiniteElementSpace * FESpace()
void ProjectBdrCoefficient(Coefficient &coeff, const Array< int > &attr)
Project a Coefficient on the GridFunction, modifying only DOFs on the boundary associated with the bo...
Arbitrary order H1-conforming (continuous) finite elements.
The BoomerAMG solver in hypre.
Class for integration point with weight.
Class for solving linear elasticity:
void SetEssBdrData(VectorCoefficient *essbdr_cf_)
ParLinearForm * GetParLinearForm()
GridFunction * GetFEMSolution()
void SetEssentialBoundary(const Array< int > &ess_bdr_)
void SetRHSCoefficient(VectorCoefficient *rhs_cf_)
~LinearElasticitySolver()
void SetMesh(Mesh *mesh_)
LinearForm * GetLinearForm()
void SetOrder(int order_)
ParGridFunction * GetParFEMSolution()
void SetNeumannBoundary(const Array< int > &neumann_bdr_)
void SetLameCoefficients(Coefficient *lambda_cf_, Coefficient *mu_cf_)
Returns f(u(x)) where u is a scalar GridFunction and f:R → R.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient at ip.
MappedGridFunctionCoefficient()
void SetFunction(std::function< real_t(const real_t)> fun_)
std::function< real_t(const real_t)> fun
MappedGridFunctionCoefficient(const GridFunction *gf, std::function< real_t(const real_t)> fun_, int comp=1)
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
int Dimension() const
Dimension of the reference space used within the elements.
Pointer to an Operator of a specified type.
void Clear()
Clear the OperatorHandle, deleting the held Operator (if owned), while leaving the type id unchanged.
Abstract parallel finite element space.
void GetEssentialTrueDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_tdof_list, int component=-1) const override
int TrueVSize() const
Obsolete, kept for backward compatibility.
Class for parallel grid function.
ParFiniteElementSpace * ParFESpace() const
Class for parallel meshes.
Solid isotropic material penalization (SIMP) coefficient.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient in the element described by T at the point ip.
SIMPInterpolationCoefficient(GridFunction *rho_filter_, real_t min_val_=1e-6, real_t max_val_=1.0, real_t exponent_=3)
GridFunction * rho_filter
Strain energy density coefficient.
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient in the element described by T at the point ip.
StrainEnergyDensityCoefficient(Coefficient *lambda_, Coefficient *mu_, GridFunction *u_, GridFunction *rho_filter_, real_t rho_min_=1e-6, real_t exponent_=3.0)
GridFunction * rho_filter
Base class for vector Coefficients that optionally depend on time and space.
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the vector coefficient in the element described by T at the point ip, storing the result in ...
real_t Norml2() const
Returns the l2 norm of the vector.
int Size() const
Returns the size of the vector.
real_t Sum() const
Return the sum of the vector entries.
void SetSize(int s)
Resize the vector to size s.
void NewDataAndSize(real_t *d, int s)
Set the Vector data and size, deleting the old data, if owned.
real_t * GetData() const
Return a pointer to the beginning of the Vector data.
Volumetric force for linear elasticity.
VolumeForceCoefficient(real_t r_, Vector ¢er_, Vector &force_)
void Set(real_t r_, Vector ¢er_, Vector &force_)
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the vector coefficient in the element described by T at the point ip, storing the result in ...
const int * ess_tdof_list
real_t sigmoid(real_t x)
Sigmoid function.
real_t proj(GridFunction &psi, GridFunction &alpha_grad, real_t target_volume, real_t tol=1e-12, int max_its=100)
Bregman projection of ρ = sigmoid(ψ) onto the subspace ∫_Ω ρ dx = θ vol(Ω) as follows:
void mfem_warning(const char *msg)
real_t inv_sigmoid(real_t x)
Inverse sigmoid function.
real_t der_sigmoid(real_t x)
Derivative of sigmoid function.
Helper struct to convert a C++ type to an MPI type.