130int main(
int argc,
char *argv[])
138 real_t vol_fraction = 0.5;
145 bool glvis_visualization =
true;
146 bool paraview_output =
false;
149 args.
AddOption(&ref_levels,
"-r",
"--refine",
150 "Number of times to refine the mesh uniformly.");
152 "Order (degree) of the finite elements.");
154 "Step length for gradient descent.");
155 args.
AddOption(&growth,
"-growth",
"--alpha-growth-rate",
156 "Growth rate of step length for gradient descent.");
158 "Length scale for ρ.");
159 args.
AddOption(&max_it,
"-mi",
"--max-it",
160 "Maximum number of gradient descent iterations.");
161 args.
AddOption(&ntol,
"-ntol",
"--rel-tol",
162 "Normalized exit tolerance.");
163 args.
AddOption(&itol,
"-itol",
"--abs-tol",
164 "Increment exit tolerance.");
165 args.
AddOption(&vol_fraction,
"-vf",
"--volume-fraction",
166 "Volume fraction for the material density.");
167 args.
AddOption(&lambda,
"-lambda",
"--lambda",
171 args.
AddOption(&rho_min,
"-rmin",
"--psi-min",
172 "Minimum of density coefficient.");
173 args.
AddOption(&glvis_visualization,
"-vis",
"--visualization",
"-no-vis",
174 "--no-visualization",
175 "Enable or disable GLVis visualization.");
176 args.
AddOption(¶view_output,
"-pv",
"--paraview",
"-no-pv",
178 "Enable or disable ParaView output.");
192 for (
int i = 0; i<mesh.
GetNBE(); i++)
202 center(0) = 0.5*(coords1[0] + coords2[0]);
203 center(1) = 0.5*(coords1[1] + coords2[1]);
205 if (
abs(center(0) - 0.0) < 1e-10)
219 for (
int lev = 0; lev < ref_levels; lev++)
236 mfem::out <<
"Number of state unknowns: " << state_size << std::endl;
237 mfem::out <<
"Number of filter unknowns: " << filter_size << std::endl;
238 mfem::out <<
"Number of control unknowns: " << control_size << std::endl;
246 rho_filter = vol_fraction;
266 ElasticitySolver->
SetMesh(&mesh);
269 Vector center(2); center(0) = 2.9; center(1) = 0.5;
270 Vector force(2); force(0) = 0.0; force(1) = -1.0;
298 mass.FormSystemMatrix(empty,M);
313 real_t domain_volume = vol_form(onegf);
314 const real_t target_volume = domain_volume * vol_fraction;
320 if (glvis_visualization)
343 for (
int k = 1; k <= max_it; k++)
345 if (k > 1) {
alpha = std::pow((
real_t) k,growth); }
347 mfem::out <<
"\nStep = " << k << std::endl;
352 FilterSolver->
Solve();
361 ElasticitySolver->
Solve();
369 FilterSolver->
Solve();
384 const real_t material_volume =
proj(psi, alpha_grad, target_volume);
388 real_t norm_reduced_gradient = norm_increment/
alpha;
392 mfem::out <<
"norm of the reduced gradient = " << norm_reduced_gradient <<
394 mfem::out <<
"norm of the increment = " << norm_increment << endl;
395 mfem::out <<
"compliance = " << compliance << std::endl;
396 mfem::out <<
"volume fraction = " << material_volume / domain_volume <<
399 if (glvis_visualization)
403 sout_r <<
"solution\n" << mesh << r_gf
404 <<
"window_title 'Design density r(ρ̃)'" << flush;
415 if (norm_reduced_gradient < ntol && norm_increment < itol)
421 delete ElasticitySolver;
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.
@ GaussLobatto
Closed type.
A coefficient that is constant across space and time.
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection.
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
void SetTime(real_t t)
Set physical time (for time-dependent simulations)
void SetPrefixPath(const std::string &prefix)
Set the path where the DataCollection will be saved.
Returns f(u(x)) - f(v(x)) where u, v are scalar GridFunctions and f:R → R.
Class for solving Poisson's equation:
void AssembleDiffusionBilinear(bool update_ess_tdofs=true)
void SetDiffusionCoefficient(Coefficient *diffcf_)
void SetRHSCoefficient(Coefficient *rhscf_)
void SetOrder(int order_)
void SetMesh(Mesh *mesh_)
void SetMassCoefficient(Coefficient *masscf_)
GridFunction * GetFEMSolution()
void SetEssentialBoundary(const Array< int > &ess_bdr_)
Class for domain integration .
Abstract data type element.
virtual void GetVertices(Array< int > &v) const =0
Get the indices defining the vertices.
void SetAttribute(const int attr)
Set element's attribute.
int GetOrder() const
Return the order (polynomial degree) of the FE collection, corresponding to the order/degree returned...
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
virtual int GetTrueVSize() const
Return the number of vector true (conforming) dofs.
Coefficient defined by a GridFunction. This coefficient is mesh dependent.
Class for grid function - Vector with associated FE space.
virtual real_t ComputeL1Error(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Returns ||u_ex - u_h||_L1 for H1 or L2 elements.
virtual void ProjectCoefficient(Coefficient &coeff, ProjectType type=ProjectType::DEFAULT)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
Arbitrary order H1-conforming (continuous) finite elements.
Integrator that inverts the matrix assembled by another integrator.
Arbitrary order "L2-conforming" discontinuous finite elements.
Class for solving linear elasticity:
GridFunction * GetFEMSolution()
void SetEssentialBoundary(const Array< int > &ess_bdr_)
void SetRHSCoefficient(VectorCoefficient *rhs_cf_)
void SetMesh(Mesh *mesh_)
LinearForm * GetLinearForm()
void SetOrder(int order_)
void SetLameCoefficients(Coefficient *lambda_cf_, Coefficient *mu_cf_)
Returns f(u(x)) where u is a scalar GridFunction and f:R → R.
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.
const Element * GetBdrElement(int i) const
Return pointer to the i'th boundary element object.
virtual void SetAttributes(bool elem_attrs_changed=true, bool bdr_face_attrs_changed=true)
Determine the sets of unique attribute values in domain if elem_attrs_changed and boundary elements i...
int GetNBE() const
Returns number of boundary elements.
static Mesh MakeCartesian2D(int nx, int ny, Element::Type type, bool generate_edges=false, real_t sx=1.0, real_t sy=1.0, bool sfc_ordering=true)
Creates mesh for the rectangle [0,sx]x[0,sy], divided into nx*ny quadrilaterals if type = QUADRILATER...
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
const real_t * GetVertex(int i) const
Return pointer to vertex i's coordinates.
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
void PrintUsage(std::ostream &out) const
Print the usage message.
void PrintOptions(std::ostream &out) const
Print the options.
void AddOption(bool *var, const char *enable_short_name, const char *enable_long_name, const char *disable_short_name, const char *disable_long_name, const char *description, bool required=false)
Add a boolean option and set 'var' to receive the value. Enable/disable tags are used to set the bool...
bool Good() const
Return true if the command line options were parsed successfully.
void SetLevelsOfDetail(int levels_of_detail_)
Set the refinement level.
void SetHighOrderOutput(bool high_order_output_)
Sets whether or not to output the data as high-order elements (false by default).
void SetDataFormat(VTKFormat fmt)
Set the data format for the ParaView output files.
Writer for ParaView visualization (PVD and VTU format)
Scalar coefficient defined as the product of two scalar coefficients or a scalar and a scalar coeffic...
Solid isotropic material penalization (SIMP) coefficient.
void Mult(const Vector &x, Vector &y) const override
Matrix vector multiplication.
Strain energy density coefficient.
Vector & Add(const real_t a, const Vector &Va)
(*this) += a * Va
Volumetric force for linear elasticity.
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.
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:
real_t u(const Vector &xvec)
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
real_t inv_sigmoid(real_t x)
Inverse sigmoid function.
MFEM_HOST_DEVICE real_t abs(const Complex &z)