MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
ex37p.cpp
Go to the documentation of this file.
1// MFEM Example 37 - Parallel Version
2//
3// Compile with: make ex37p
4//
5// Sample runs:
6// mpirun -np 4 ex37p -alpha 10 -pv
7// mpirun -np 4 ex37p -lambda 0.1 -mu 0.1 -growth 1
8// mpirun -np 4 ex37p -o 2 -alpha 10.0 -mi 50 -vf 0.4 -ntol 1e-5 -growth 1.5
9// mpirun -np 4 ex37p -r 6 -o 2 -alpha 10.0 -epsilon 0.02 -mi 50 -ntol 1e-5
10//
11// Description: This example code demonstrates the use of MFEM to solve a
12// density-filtered [3] topology optimization problem. The
13// objective is to minimize the compliance
14//
15// minimize ∫_Ω f⋅u dx over u ∈ [H¹(Ω)]² and ρ ∈ L¹(Ω)
16//
17// subject to
18//
19// -Div(r(ρ̃)Cε(u)) = f in Ω + BCs
20// -ϵ²Δρ̃ + ρ̃ = ρ in Ω + Neumann BCs
21// 0 ≤ ρ ≤ 1 in Ω
22// ∫_Ω ρ dx = θ vol(Ω)
23//
24// Here, r(ρ̃) = ρ₀ + ρ̃³ (1-ρ₀) is the solid isotropic material
25// penalization (SIMP) law, C is the elasticity tensor for an
26// isotropic linearly elastic material, ϵ > 0 is the design
27// length scale, and 0 < θ < 1 is the volume fraction.
28//
29// The problem is discretized and gradients are computing using
30// finite elements [1]. The design is optimized using an entropic
31// mirror descent algorithm introduced by Keith and Surowiec [2]
32// that is tailored to the bound constraint 0 ≤ ρ ≤ 1.
33//
34// This example highlights the ability of MFEM to deliver high-
35// order solutions to inverse design problems and showcases how
36// to set up and solve PDE-constrained optimization problems
37// using the so-called reduced space approach.
38//
39// [1] Andreassen, E., Clausen, A., Schevenels, M., Lazarov, B. S., & Sigmund, O.
40// (2011). Efficient topology optimization in MATLAB using 88 lines of
41// code. Structural and Multidisciplinary Optimization, 43(1), 1-16.
42// [2] Keith, B. and Surowiec, T. (2023) Proximal Galerkin: A structure-
43// preserving finite element method for pointwise bound constraints.
44// arXiv:2307.12444 [math.NA]
45// [3] Lazarov, B. S., & Sigmund, O. (2011). Filters in topology optimization
46// based on Helmholtz‐type differential equations. International Journal
47// for Numerical Methods in Engineering, 86(6), 765-781.
48
49#include "mfem.hpp"
50#include <iostream>
51#include <fstream>
52#include "ex37.hpp"
53
54using namespace std;
55using namespace mfem;
56
57/*
58 * ---------------------------------------------------------------
59 * ALGORITHM PREAMBLE
60 * ---------------------------------------------------------------
61 *
62 * The Lagrangian for this problem is
63 *
64 * L(u,ρ,ρ̃,w,w̃) = (f,u) - (r(ρ̃) C ε(u),ε(w)) + (f,w)
65 * - (ϵ² ∇ρ̃,∇w̃) - (ρ̃,w̃) + (ρ,w̃)
66 *
67 * where
68 *
69 * r(ρ̃) = ρ₀ + ρ̃³ (1 - ρ₀) (SIMP rule)
70 *
71 * ε(u) = (∇u + ∇uᵀ)/2 (symmetric gradient)
72 *
73 * C e = λtr(e)I + 2μe (isotropic material)
74 *
75 * NOTE: The Lame parameters can be computed from Young's modulus E
76 * and Poisson's ratio ν as follows:
77 *
78 * λ = E ν/((1+ν)(1-2ν)), μ = E/(2(1+ν))
79 *
80 * ---------------------------------------------------------------
81 *
82 * Discretization choices:
83 *
84 * u ∈ V ⊂ (H¹)ᵈ (order p)
85 * ψ ∈ L² (order p - 1), ρ = sigmoid(ψ)
86 * ρ̃ ∈ H¹ (order p)
87 * w ∈ V (order p)
88 * w̃ ∈ H¹ (order p)
89 *
90 * ---------------------------------------------------------------
91 * ALGORITHM
92 * ---------------------------------------------------------------
93 *
94 * Update ρ with projected mirror descent via the following algorithm.
95 *
96 * 1. Initialize ψ = inv_sigmoid(vol_fraction) so that ∫ sigmoid(ψ) = θ vol(Ω)
97 *
98 * While not converged:
99 *
100 * 2. Solve filter equation ∂_w̃ L = 0; i.e.,
101 *
102 * (ϵ² ∇ ρ̃, ∇ v ) + (ρ̃,v) = (ρ,v) ∀ v ∈ H¹.
103 *
104 * 3. Solve primal problem ∂_w L = 0; i.e.,
105 *
106 * (λ r(ρ̃) ∇⋅u, ∇⋅v) + (2 μ r(ρ̃) ε(u), ε(v)) = (f,v) ∀ v ∈ V.
107 *
108 * NB. The dual problem ∂_u L = 0 is the negative of the primal problem due to symmetry.
109 *
110 * 4. Solve for filtered gradient ∂_ρ̃ L = 0; i.e.,
111 *
112 * (ϵ² ∇ w̃ , ∇ v ) + (w̃ ,v) = (-r'(ρ̃) ( λ |∇⋅u|² + 2 μ |ε(u)|²),v) ∀ v ∈ H¹.
113 *
114 * 5. Project the gradient onto the discrete latent space; i.e., solve
115 *
116 * (G,v) = (w̃,v) ∀ v ∈ L².
117 *
118 * 6. Bregman proximal gradient update; i.e.,
119 *
120 * ψ ← ψ - αG + c,
121 *
122 * where α > 0 is a step size parameter and c ∈ R is a constant ensuring
123 *
124 * ∫_Ω sigmoid(ψ - αG + c) dx = θ vol(Ω).
125 *
126 * end
127 */
128
129int main(int argc, char *argv[])
130{
131 // 0. Initialize MPI and HYPRE.
132 Mpi::Init();
133 int num_procs = Mpi::WorldSize();
134 int myid = Mpi::WorldRank();
135 Hypre::Init();
136
137 // 1. Parse command-line options.
138 int ref_levels = 5;
139 int order = 2;
140 real_t alpha = 1.0;
141 real_t growth = 2;
142 real_t epsilon = 0.01;
143 real_t vol_fraction = 0.5;
144 int max_it = 1e3;
145 real_t itol = 1e-2;
146 real_t ntol = 1e-4;
147 real_t rho_min = 1e-6;
148 real_t lambda = 1.0;
149 real_t mu = 1.0;
150 bool glvis_visualization = true;
151 bool paraview_output = false;
152
153 OptionsParser args(argc, argv);
154 args.AddOption(&ref_levels, "-r", "--refine",
155 "Number of times to refine the mesh uniformly.");
156 args.AddOption(&order, "-o", "--order",
157 "Order (degree) of the finite elements.");
158 args.AddOption(&alpha, "-alpha", "--alpha-step-length",
159 "Step length for gradient descent.");
160 args.AddOption(&growth, "-growth", "--alpha-growth-rate",
161 "Growth rate of step length for gradient descent.");
162 args.AddOption(&epsilon, "-epsilon", "--epsilon-thickness",
163 "Length scale for ρ.");
164 args.AddOption(&max_it, "-mi", "--max-it",
165 "Maximum number of gradient descent iterations.");
166 args.AddOption(&ntol, "-ntol", "--rel-tol",
167 "Normalized exit tolerance.");
168 args.AddOption(&itol, "-itol", "--abs-tol",
169 "Increment exit tolerance.");
170 args.AddOption(&vol_fraction, "-vf", "--volume-fraction",
171 "Volume fraction for the material density.");
172 args.AddOption(&lambda, "-lambda", "--lambda",
173 "Lamé constant λ.");
174 args.AddOption(&mu, "-mu", "--mu",
175 "Lamé constant μ.");
176 args.AddOption(&rho_min, "-rmin", "--psi-min",
177 "Minimum of density coefficient.");
178 args.AddOption(&glvis_visualization, "-vis", "--visualization", "-no-vis",
179 "--no-visualization",
180 "Enable or disable GLVis visualization.");
181 args.AddOption(&paraview_output, "-pv", "--paraview", "-no-pv",
182 "--no-paraview",
183 "Enable or disable ParaView output.");
184 args.Parse();
185 if (!args.Good())
186 {
187 if (myid == 0)
188 {
189 args.PrintUsage(cout);
190 }
191 MPI_Finalize();
192 return 1;
193 }
194 if (myid == 0)
195 {
196 mfem::out << num_procs << " number of process created.\n";
197 args.PrintOptions(cout);
198 }
199
201 true, 3.0, 1.0);
202 int dim = mesh.Dimension();
203
204 // 2. Set BCs.
205 for (int i = 0; i<mesh.GetNBE(); i++)
206 {
207 Element * be = mesh.GetBdrElement(i);
208 Array<int> vertices;
209 be->GetVertices(vertices);
210
211 real_t * coords1 = mesh.GetVertex(vertices[0]);
212 real_t * coords2 = mesh.GetVertex(vertices[1]);
213
214 Vector center(2);
215 center(0) = 0.5*(coords1[0] + coords2[0]);
216 center(1) = 0.5*(coords1[1] + coords2[1]);
217
218 if (abs(center(0) - 0.0) < 1e-10)
219 {
220 // the left edge
221 be->SetAttribute(1);
222 }
223 else
224 {
225 // all other boundaries
226 be->SetAttribute(2);
227 }
228 }
229 mesh.SetAttributes();
230
231 // 3. Refine the mesh.
232 for (int lev = 0; lev < ref_levels; lev++)
233 {
234 mesh.UniformRefinement();
235 }
236
237 ParMesh pmesh(MPI_COMM_WORLD, mesh);
238 mesh.Clear();
239
240 // 4. Define the necessary finite element spaces on the mesh.
241 H1_FECollection state_fec(order, dim); // space for u
242 H1_FECollection filter_fec(order, dim); // space for ρ̃
243 L2_FECollection control_fec(order-1, dim,
244 BasisType::GaussLobatto); // space for ψ
245 ParFiniteElementSpace state_fes(&pmesh, &state_fec,dim);
246 ParFiniteElementSpace filter_fes(&pmesh, &filter_fec);
247 ParFiniteElementSpace control_fes(&pmesh, &control_fec);
248
249 HYPRE_BigInt state_size = state_fes.GlobalTrueVSize();
250 HYPRE_BigInt control_size = control_fes.GlobalTrueVSize();
251 HYPRE_BigInt filter_size = filter_fes.GlobalTrueVSize();
252 if (myid==0)
253 {
254 cout << "Number of state unknowns: " << state_size << endl;
255 cout << "Number of filter unknowns: " << filter_size << endl;
256 cout << "Number of control unknowns: " << control_size << endl;
257 }
258
259 // 5. Set the initial guess for ρ.
260 ParGridFunction u(&state_fes);
261 ParGridFunction psi(&control_fes);
262 ParGridFunction psi_old(&control_fes);
263 ParGridFunction rho_filter(&filter_fes);
264 u = 0.0;
265 rho_filter = vol_fraction;
266 psi = inv_sigmoid(vol_fraction);
267 psi_old = inv_sigmoid(vol_fraction);
268
269 // ρ = sigmoid(ψ)
271 // Interpolation of ρ = sigmoid(ψ) in control fes (for ParaView output)
272 ParGridFunction rho_gf(&control_fes);
273 // ρ - ρ_old = sigmoid(ψ) - sigmoid(ψ_old)
274 DiffMappedGridFunctionCoefficient succ_diff_rho(&psi, &psi_old, sigmoid);
275
276 // 6. Set-up the physics solver.
277 int maxat = pmesh.bdr_attributes.Max();
278 Array<int> ess_bdr(maxat);
279 ess_bdr = 0;
280 ess_bdr[0] = 1;
281 ConstantCoefficient one(1.0);
282 ConstantCoefficient lambda_cf(lambda);
283 ConstantCoefficient mu_cf(mu);
284 LinearElasticitySolver * ElasticitySolver = new LinearElasticitySolver();
285 ElasticitySolver->SetMesh(&pmesh);
286 ElasticitySolver->SetOrder(state_fec.GetOrder());
287 ElasticitySolver->SetupFEM();
288 Vector center(2); center(0) = 2.9; center(1) = 0.5;
289 Vector force(2); force(0) = 0.0; force(1) = -1.0;
290 real_t r = 0.05;
291 VolumeForceCoefficient vforce_cf(r,center,force);
292 ElasticitySolver->SetRHSCoefficient(&vforce_cf);
293 ElasticitySolver->SetEssentialBoundary(ess_bdr);
294
295 // 7. Set-up the filter solver.
297 DiffusionSolver * FilterSolver = new DiffusionSolver();
298 FilterSolver->SetMesh(&pmesh);
299 FilterSolver->SetOrder(filter_fec.GetOrder());
300 FilterSolver->SetDiffusionCoefficient(&eps2_cf);
301 FilterSolver->SetMassCoefficient(&one);
302 Array<int> ess_bdr_filter;
303 if (pmesh.bdr_attributes.Size())
304 {
305 ess_bdr_filter.SetSize(pmesh.bdr_attributes.Max());
306 ess_bdr_filter = 0;
307 }
308 FilterSolver->SetEssentialBoundary(ess_bdr_filter);
309 FilterSolver->SetupFEM();
310 FilterSolver->AssembleDiffusionBilinear();
311
312 ParBilinearForm mass(&control_fes);
313 mass.AddDomainIntegrator(new InverseIntegrator(new MassIntegrator(one)));
314 mass.Assemble();
316 Array<int> empty;
317 mass.FormSystemMatrix(empty,M);
318
319 // 8. Define the Lagrange multiplier and gradient functions.
320 ParGridFunction grad(&control_fes);
321 ParGridFunction w_filter(&filter_fes);
322
323 // 9. Define some tools for later.
324 ConstantCoefficient zero(0.0);
325 ParGridFunction onegf(&control_fes);
326 onegf = 1.0;
327 ParGridFunction zerogf(&control_fes);
328 zerogf = 0.0;
329 ParLinearForm vol_form(&control_fes);
330 vol_form.AddDomainIntegrator(new DomainLFIntegrator(one));
331 vol_form.Assemble();
332 real_t domain_volume = vol_form(onegf);
333 const real_t target_volume = domain_volume * vol_fraction;
334
335 // 10. Connect to GLVis. Prepare for VisIt output.
336 char vishost[] = "localhost";
337 int visport = 19916;
338 socketstream sout_r;
339 if (glvis_visualization)
340 {
341 sout_r.open(vishost, visport);
342 sout_r.precision(8);
343 }
344
345 mfem::ParaViewDataCollection paraview_dc("ex37p", &pmesh);
346 if (paraview_output)
347 {
348 rho_gf.ProjectCoefficient(rho);
349 paraview_dc.SetPrefixPath("ParaView");
350 paraview_dc.SetLevelsOfDetail(order);
351 paraview_dc.SetDataFormat(VTKFormat::BINARY);
352 paraview_dc.SetHighOrderOutput(true);
353 paraview_dc.SetCycle(0);
354 paraview_dc.SetTime(0.0);
355 paraview_dc.RegisterField("displacement",&u);
356 paraview_dc.RegisterField("density",&rho_gf);
357 paraview_dc.RegisterField("filtered_density",&rho_filter);
358 paraview_dc.Save();
359 }
360
361 // 11. Iterate:
362 for (int k = 1; k <= max_it; k++)
363 {
364 if (k > 1) { alpha = std::pow((real_t) k,growth); }
365
366 if (myid == 0)
367 {
368 cout << "\nStep = " << k << endl;
369 }
370
371 // Step 1 - Filter solve
372 // Solve (ϵ^2 ∇ ρ̃, ∇ v ) + (ρ̃,v) = (ρ,v)
373 FilterSolver->SetRHSCoefficient(&rho);
374 FilterSolver->Solve();
375 rho_filter = *FilterSolver->GetFEMSolution();
376
377 // Step 2 - State solve
378 // Solve (λ r(ρ̃) ∇⋅u, ∇⋅v) + (2 μ r(ρ̃) ε(u), ε(v)) = (f,v)
379 SIMPInterpolationCoefficient SIMP_cf(&rho_filter,rho_min, 1.0);
380 ProductCoefficient lambda_SIMP_cf(lambda_cf,SIMP_cf);
381 ProductCoefficient mu_SIMP_cf(mu_cf,SIMP_cf);
382 ElasticitySolver->SetLameCoefficients(&lambda_SIMP_cf,&mu_SIMP_cf);
383 ElasticitySolver->Solve();
384 u = *ElasticitySolver->GetFEMSolution();
385
386 // Step 3 - Adjoint filter solve
387 // Solve (ϵ² ∇ w̃, ∇ v) + (w̃ ,v) = (-r'(ρ̃) ( λ |∇⋅u|² + 2 μ |ε(u)|²),v)
388 StrainEnergyDensityCoefficient rhs_cf(&lambda_cf,&mu_cf,&u, &rho_filter,
389 rho_min);
390 FilterSolver->SetRHSCoefficient(&rhs_cf);
391 FilterSolver->Solve();
392 w_filter = *FilterSolver->GetFEMSolution();
393
394 // Step 4 - Compute gradient
395 // Solve G = M⁻¹w̃
396 GridFunctionCoefficient w_cf(&w_filter);
397 ParLinearForm w_rhs(&control_fes);
399 w_rhs.Assemble();
400 M.Mult(w_rhs,grad);
401
402 // Step 5 - Update design variable ψ ← proj(ψ - αG)
403 psi.Add(-alpha, grad);
404 ParGridFunction alpha_grad(grad);
405 alpha_grad *= alpha;
406 const real_t material_volume = proj(psi, alpha_grad, target_volume);
407
408 // Compute ||ρ - ρ_old|| in control fes.
409 real_t norm_increment = zerogf.ComputeL1Error(succ_diff_rho);
410 real_t norm_reduced_gradient = norm_increment/alpha;
411 psi_old = psi;
412
413 real_t compliance = (*(ElasticitySolver->GetLinearForm()))(u);
414 MPI_Allreduce(MPI_IN_PLACE, &compliance, 1, MPITypeMap<real_t>::mpi_type,
415 MPI_SUM, MPI_COMM_WORLD);
416 if (myid == 0)
417 {
418 mfem::out << "norm of the reduced gradient = " << norm_reduced_gradient << endl;
419 mfem::out << "norm of the increment = " << norm_increment << endl;
420 mfem::out << "compliance = " << compliance << endl;
421 mfem::out << "volume fraction = " << material_volume / domain_volume << endl;
422 }
423
424 if (glvis_visualization)
425 {
426 ParGridFunction r_gf(&filter_fes);
427 r_gf.ProjectCoefficient(SIMP_cf);
428 sout_r << "parallel " << num_procs << " " << myid << "\n";
429 sout_r << "solution\n" << pmesh << r_gf
430 << "window_title 'Design density r(ρ̃)'" << flush;
431 }
432
433 if (paraview_output)
434 {
435 rho_gf.ProjectCoefficient(rho);
436 paraview_dc.SetCycle(k);
437 paraview_dc.SetTime((real_t)k);
438 paraview_dc.Save();
439 }
440
441 if (norm_reduced_gradient < ntol && norm_increment < itol)
442 {
443 break;
444 }
445 }
446
447 delete ElasticitySolver;
448 delete FilterSolver;
449
450 return 0;
451}
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
Definition array.cpp:69
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
Definition array.hpp:869
int Size() const
Return the logical size of the array.
Definition array.hpp:192
@ GaussLobatto
Closed type.
Definition fe_base.hpp:36
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.
Definition ex37.hpp:66
Class for solving Poisson's equation:
Definition ex37.hpp:216
void AssembleDiffusionBilinear(bool update_ess_tdofs=true)
Definition ex37.hpp:570
void SetDiffusionCoefficient(Coefficient *diffcf_)
Definition ex37.hpp:261
void SetRHSCoefficient(Coefficient *rhscf_)
Definition ex37.hpp:263
void SetOrder(int order_)
Definition ex37.hpp:260
void SetMesh(Mesh *mesh_)
Definition ex37.hpp:251
void SetMassCoefficient(Coefficient *masscf_)
Definition ex37.hpp:262
GridFunction * GetFEMSolution()
Definition ex37.hpp:692
void SetEssentialBoundary(const Array< int > &ess_bdr_)
Definition ex37.hpp:264
Class for domain integration .
Definition lininteg.hpp:108
Abstract data type element.
Definition element.hpp:29
virtual void GetVertices(Array< int > &v) const =0
Get the indices defining the vertices.
void SetAttribute(const int attr)
Set element's attribute.
Definition element.hpp:61
int GetOrder() const
Return the order (polynomial degree) of the FE collection, corresponding to the order/degree returned...
Definition fe_coll.hpp:248
Coefficient defined by a GridFunction. This coefficient is mesh dependent.
Arbitrary order H1-conforming (continuous) finite elements.
Definition fe_coll.hpp:291
Wrapper for hypre's ParCSR matrix class.
Definition hypre.hpp:419
HYPRE_Int Mult(HypreParVector &x, HypreParVector &y, real_t alpha=1.0, real_t beta=0.0) const
Computes y = alpha * A * x + beta * y.
Definition hypre.cpp:1873
static void Init()
Initialize hypre by calling HYPRE_Init() and set default options. After calling Hypre::Init(),...
Definition hypre.cpp:33
Integrator that inverts the matrix assembled by another integrator.
Arbitrary order "L2-conforming" discontinuous finite elements.
Definition fe_coll.hpp:369
Class for solving linear elasticity:
Definition ex37.hpp:309
GridFunction * GetFEMSolution()
Definition ex37.hpp:876
void SetEssentialBoundary(const Array< int > &ess_bdr_)
Definition ex37.hpp:349
void SetRHSCoefficient(VectorCoefficient *rhs_cf_)
Definition ex37.hpp:348
void SetMesh(Mesh *mesh_)
Definition ex37.hpp:337
LinearForm * GetLinearForm()
Definition ex37.hpp:358
void SetOrder(int order_)
Definition ex37.hpp:346
void SetLameCoefficients(Coefficient *lambda_cf_, Coefficient *mu_cf_)
Definition ex37.hpp:347
void AddDomainIntegrator(LinearFormIntegrator *lfi)
Adds new Domain Integrator. Assumes ownership of lfi.
Returns f(u(x)) where u is a scalar GridFunction and f:R → R.
Definition ex37.hpp:41
Mesh data type.
Definition mesh.hpp:67
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
Definition mesh.hpp:309
void Clear()
Clear the contents of the Mesh.
Definition mesh.hpp:835
int Dimension() const
Dimension of the reference space used within the elements.
Definition mesh.hpp:1314
const Element * GetBdrElement(int i) const
Return pointer to the i'th boundary element object.
Definition mesh.hpp:1462
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...
Definition mesh.cpp:2016
int GetNBE() const
Returns number of boundary elements.
Definition mesh.hpp:1393
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...
Definition mesh.cpp:4776
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Definition mesh.cpp:12125
const real_t * GetVertex(int i) const
Return pointer to vertex i's coordinates.
Definition mesh.hpp:1429
static int WorldRank()
Return the MPI rank in MPI_COMM_WORLD.
static int WorldSize()
Return the size of MPI_COMM_WORLD.
static void Init(int &argc, char **&argv, int required=default_thread_required, int *provided=nullptr)
Singleton creation with Mpi::Init(argc, argv).
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...
Definition optparser.hpp:82
bool Good() const
Return true if the command line options were parsed successfully.
Class for parallel bilinear form.
Abstract parallel finite element space.
Definition pfespace.hpp:31
HYPRE_BigInt GlobalTrueVSize() const
Definition pfespace.hpp:361
Class for parallel grid function.
Definition pgridfunc.hpp:50
void ProjectCoefficient(Coefficient &coeff, ProjectType type=ProjectType::DEFAULT) override
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
MFEM_DEPRECATED real_t ComputeL1Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL) const override
Returns ||u_ex - u_h||_L1 in parallel for H1 or L2 elements.
Class for parallel linear form.
void Assemble()
Assembles the ParLinearForm i.e. sums over all domain/bdr integrators.
Class for parallel meshes.
Definition pmesh.hpp:35
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.
Definition ex37.hpp:98
Strain energy density coefficient.
Definition ex37.hpp:122
Vector data type.
Definition vector.hpp:82
Vector & Add(const real_t a, const Vector &Va)
(*this) += a * Va
Definition vector.cpp:326
Volumetric force for linear elasticity.
Definition ex37.hpp:168
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.
const real_t alpha
Definition ex15.cpp:369
int dim
Definition ex24.cpp:53
real_t mu
Definition ex25.cpp:140
real_t epsilon
Definition ex25.cpp:141
int main()
HYPRE_Int HYPRE_BigInt
real_t sigmoid(real_t x)
Sigmoid function.
Definition ex37.hpp:20
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:
Definition ex37.hpp:395
real_t u(const Vector &xvec)
Definition lor_mms.hpp:22
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
Definition globals.hpp:66
real_t inv_sigmoid(real_t x)
Inverse sigmoid function.
Definition ex37.hpp:12
float real_t
Definition config.hpp:46
const char vishost[]
STL namespace.
MFEM_HOST_DEVICE real_t abs(const Complex &z)
Helper struct to convert a C++ type to an MPI type.