MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
mesh-optimizer.cpp
Go to the documentation of this file.
1// Copyright (c) 2010-2026, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11//
12// --------------------------------------------------
13// Mesh Optimizer Miniapp: Optimize high-order meshes
14// --------------------------------------------------
15//
16// This miniapp performs mesh optimization using the Target-Matrix Optimization
17// Paradigm (TMOP) by P.Knupp et al., and a global variational minimization
18// approach. It minimizes the quantity sum_T int_T mu(J(x)), where T are the
19// target (ideal) elements, J is the Jacobian of the transformation from the
20// target to the physical element, and mu is the mesh quality metric. This
21// metric can measure shape, size or alignment of the region around each
22// quadrature point. The combination of targets & quality metrics is used to
23// optimize the physical node positions, i.e., they must be as close as possible
24// to the shape / size / alignment of their targets. This code also demonstrates
25// a possible use of nonlinear operators (the class TMOP_QualityMetric, defining
26// mu(J), and the class TMOP_Integrator, defining int mu(J)), as well as their
27// coupling to Newton methods for solving minimization problems. Note that the
28// utilized Newton methods are oriented towards avoiding invalid meshes with
29// negative Jacobian determinants. Each Newton step requires the inversion of a
30// Jacobian matrix, which is done through an inner linear solver.
31//
32// Compile with: make mesh-optimizer
33//
34// Sample runs:
35// Adapted analytic shape:
36// mesh-optimizer -m square01.mesh -o 2 -rs 2 -mid 2 -tid 4 -ni 200 -bnd -qt 1 -qo 8
37// Adapted analytic size+orientation:
38// mesh-optimizer -m square01.mesh -o 2 -rs 2 -mid 14 -tid 4 -ni 100 -bnd -qt 1 -qo 8
39// Adapted analytic shape+orientation (AD):
40// mesh-optimizer -m square01.mesh -o 3 -rs 2 -mid 85 -tid 4 -ni 100 -bnd -qt 1 -qo 8 -rtol 1e-6
41//
42// Adapted analytic shape and/or size with hr-adaptivity:
43// mesh-optimizer -m square01.mesh -o 2 -tid 9 -ni 50 -li 20 -hmid 55 -mid 7 -hr
44// mesh-optimizer -m square01.mesh -o 2 -tid 10 -ni 50 -li 20 -hmid 55 -mid 7 -hr
45// mesh-optimizer -m square01.mesh -o 2 -tid 11 -ni 50 -li 20 -hmid 58 -mid 7 -hr
46//
47// Adapted discrete size:
48// mesh-optimizer -m square01.mesh -o 2 -rs 2 -mid 94 -tid 5 -ni 50 -qo 4 -nor
49// (requires GSLIB):
50// * mesh-optimizer -m square01.mesh -o 2 -rs 2 -mid 80 -tid 5 -ni 50 -qo 4 -nor -mno 1 -ae 1
51// Adapted discrete size NC mesh;
52// mesh-optimizer -m amr-quad-q2.mesh -o 2 -rs 2 -mid 94 -tid 5 -ni 50 -qo 4 -nor
53// Adapted discrete size 3D with PA:
54// mesh-optimizer -m cube.mesh -o 2 -rs 2 -mid 321 -tid 5 -ls 3 -nor -pa -rtol 1e-8
55// Adapted discrete size 3D with PA on device (requires CUDA):
56// * mesh-optimizer -m cube.mesh -o 3 -rs 3 -mid 321 -tid 5 -ls 3 -nor -lc 0.1 -pa -d cuda
57// Adapted discrete size; explicit combo of metrics; mixed tri/quad mesh:
58// mesh-optimizer -m ../../data/square-mixed.mesh -o 2 -rs 2 -mid 2 -tid 5 -ni 200 -bnd -qo 6 -cmb 2 -nor
59// Adapted discrete size+aspect_ratio:
60// mesh-optimizer -m square01.mesh -o 2 -rs 2 -mid 7 -tid 6 -ni 100
61// Adapted discrete size+orientation (AD):
62// mesh-optimizer -m square01.mesh -o 2 -rs 2 -mid 36 -tid 8 -qo 4 -nor -rtol 1e-6
63// Adapted discrete aspect ratio (3D):
64// mesh-optimizer -m cube.mesh -o 2 -rs 2 -mid 302 -tid 7 -ni 20 -bnd -qt 1 -qo 8
65//
66// Periodic 2D + adapted discrete size:
67// mesh-optimizer -m ../../data/periodic-square.mesh -o 2 -rs 4 -mid 94 -tid 5 -qo 4 -nor
68// mesh-optimizer -m periodic-tri.mesh -o 2 -rs 4 -mid 94 -tid 5 -qo 4 -nor
69// Periodic 3D + adapted discrete size + PA:
70// mesh-optimizer -m periodic-cube.mesh -o 2 -rs 2 -mid 338 -tid 5 -nor -rtol 1e-6 -qo 4 -pa
71// Periodic 2D NC mesh + adapted discrete size + PA:
72// (the mesh is in the mfem/data GitHub repository)
73// * mesh-optimizer -m ../../../data/periodic/per-amr-square.mesh -o 2 -mid 94 -tid 5 -ni 50 -qo 4 -nor -pa
74//
75// Adaptive limiting:
76// mesh-optimizer -m stretched2D.mesh -rs 1 -o 2 -mid 2 -tid 1 -ni 50 -qo 5 -nor -vl 1 -alc 1.0
77// mesh-optimizer -m stretched3D.mesh -rs 2 -o 2 -mid 302 -tid 1 -rtol 1e-7 -qo 5 -nor -vl 1 -alc 2.0 -pa
78// Adaptive limiting through the L-BFGS solver:
79// mesh-optimizer -m stretched2D.mesh -o 2 -mid 2 -tid 1 -ni 400 -qo 5 -nor -vl 1 -alc 0.5 -st 1 -rtol 1e-8
80//
81// Blade shape:
82// mesh-optimizer -m blade.mesh -o 4 -mid 2 -tid 1 -ni 30 -ls 3 -art 1 -bnd -qt 1 -qo 8
83// Blade shape + bounded Jacobian determinant:
84// * mesh-optimizer -m blade.mesh -o 4 -mid 2 -tid 1 -ni 30 -ls 3 -art 1 -bnd -qt 1 -qo 8 -db
85// Blade shape (AD):
86// mesh-optimizer -m blade.mesh -o 4 -mid 11 -tid 1 -ni 30 -ls 3 -art 1 -bnd -qt 1 -qo 8
87// (requires CUDA):
88// * mesh-optimizer -m blade.mesh -o 4 -mid 2 -tid 1 -ni 30 -ls 3 -art 1 -bnd -qt 1 -qo 8 -d cuda
89// Blade limited shape:
90// mesh-optimizer -m blade.mesh -o 4 -mid 2 -tid 1 -bnd -qt 1 -qo 8 -lc 5000
91// ICF shape and equal size:
92// mesh-optimizer -o 3 -mid 80 -bec -tid 2 -ni 25 -ls 3 -art 2 -qo 5
93// ICF shape and initial size:
94// mesh-optimizer -o 3 -mid 9 -tid 3 -ni 30 -ls 3 -bnd -qt 1 -qo 8
95// ICF shape:
96// mesh-optimizer -o 3 -mid 1 -tid 1 -ni 100 -bnd -qt 1 -qo 8
97// ICF limited shape:
98// mesh-optimizer -o 3 -mid 1 -tid 1 -ni 100 -bnd -qt 1 -qo 8 -lc 10
99// ICF combo shape + size (rings, slow convergence):
100// mesh-optimizer -o 3 -mid 1 -tid 1 -ni 1000 -bnd -qt 1 -qo 8 -cmb 1
101// Mixed tet / cube / hex mesh with limiting:
102// mesh-optimizer -m ../../data/fichera-mixed-p2.mesh -o 4 -rs 1 -mid 301 -tid 1 -fix-bnd -qo 6 -nor -lc 0.25
103// 3D pinched sphere shape (the mesh is in the mfem/data GitHub repository):
104// * mesh-optimizer -m ../../../mfem_data/ball-pert.mesh -o 4 -mid 303 -tid 1 -ni 20 -li 500 -fix-bnd
105// 2D non-conforming shape and equal size:
106// mesh-optimizer -m ./amr-quad-q2.mesh -o 2 -rs 1 -mid 9 -tid 2 -ni 200 -bnd -qt 1 -qo 8
107//
108// 2D untangling:
109// mesh-optimizer -m jagged.mesh -o 2 -mid 22 -tid 1 -ni 50 -li 50 -qo 4 -fd -vl 1
110// 2D untangling with shifted barrier metric:
111// mesh-optimizer -m jagged.mesh -o 2 -mid 4 -tid 1 -ni 50 -qo 4 -vl 1 -btype 1
112// 3D untangling (the mesh is in the mfem/data GitHub repository):
113// * mesh-optimizer -m ../../../mfem_data/cube-holes-inv.mesh -o 3 -mid 313 -tid 1 -rtol 1e-5 -li 50 -qo 4 -fd -vl 1
114
115#include "mfem.hpp"
117#include <fstream>
118#include <iostream>
119#include "mesh-optimizer.hpp"
120
121using namespace mfem;
122using namespace std;
123
124int main(int argc, char *argv[])
125{
126 // Set the method's default parameters.
127 const char *mesh_file = "icf.mesh";
128 int mesh_poly_deg = 1;
129 int rs_levels = 0;
130 real_t jitter = 0.0;
131 int metric_id = 1;
132 int target_id = 1;
133 real_t lim_const = 0.0;
134 real_t adapt_lim_const = 0.0;
135 int quad_type = 1;
136 int quad_order = 8;
137 int solver_type = 0;
138 int solver_iter = 20;
139#ifdef MFEM_USE_SINGLE
140 real_t solver_rtol = 1e-4;
141#else
142 real_t solver_rtol = 1e-10;
143#endif
144 int solver_art_type = 0;
145 int lin_solver = 2;
146 int max_lin_iter = 100;
147 bool move_bnd = true;
148 int combomet = 0;
149 bool bal_expl_combo = false;
150 bool hradaptivity = false;
151 int h_metric_id = -1;
152 bool normalization = false;
153 bool visualization = true;
154 int verbosity_level = 0;
155 bool fdscheme = false;
156 int adapt_eval = 0;
157 bool exactaction = false;
158 bool integ_over_targ = true;
159 const char *devopt = "cpu";
160 bool pa = false;
161 int n_hr_iter = 5;
162 int n_h_iter = 1;
163 int mesh_node_order = 0;
164 int barrier_type = 0;
165 int worst_case_type = 0;
166 bool detj_bound = false;
167
168 // Parse command-line options.
169 OptionsParser args(argc, argv);
170 args.AddOption(&mesh_file, "-m", "--mesh",
171 "Mesh file to use.");
172 args.AddOption(&mesh_poly_deg, "-o", "--order",
173 "Polynomial degree of mesh finite element space.");
174 args.AddOption(&rs_levels, "-rs", "--refine-serial",
175 "Number of times to refine the mesh uniformly in serial.");
176 args.AddOption(&jitter, "-ji", "--jitter",
177 "Random perturbation scaling factor.");
178 args.AddOption(&metric_id, "-mid", "--metric-id",
179 "Mesh optimization metric:\n\t"
180 "T-metrics\n\t"
181 "1 : |T|^2 -- 2D no type\n\t"
182 "2 : 0.5|T|^2/tau-1 -- 2D shape (condition number)\n\t"
183 "7 : |T-T^-t|^2 -- 2D shape+size\n\t"
184 "9 : tau*|T-T^-t|^2 -- 2D shape+size\n\t"
185 "14 : |T-I|^2 -- 2D shape+size+orientation\n\t"
186 "22 : 0.5(|T|^2-2*tau)/(tau-tau_0) -- 2D untangling\n\t"
187 "50 : 0.5|T^tT|^2/tau^2-1 -- 2D shape\n\t"
188 "55 : (tau-1)^2 -- 2D size\n\t"
189 "56 : 0.5(sqrt(tau)-1/sqrt(tau))^2 -- 2D size\n\t"
190 "58 : |T^tT|^2/(tau^2)-2*|T|^2/tau+2 -- 2D shape\n\t"
191 "77 : 0.5(tau-1/tau)^2 -- 2D size\n\t"
192 "80 : (1-gamma)mu_2 + gamma mu_77 -- 2D shape+size\n\t"
193 "85 : |T-|T|/sqrt(2)I|^2 -- 2D shape+orientation\n\t"
194 "90 : balanced combo mu_50 & mu_77 -- 2D shape+size\n\t"
195 "94 : balanced combo mu_2 & mu_56 -- 2D shape+size\n\t"
196 "98 : (1/tau)|T-I|^2 -- 2D shape+size+orientation\n\t"
197 // "211: (tau-1)^2-tau+sqrt(tau^2+eps) -- 2D untangling\n\t"
198 // "252: 0.5(tau-1)^2/(tau-tau_0) -- 2D untangling\n\t"
199 "301: (|T||T^-1|)/3-1 -- 3D shape\n\t"
200 "302: (|T|^2|T^-1|^2)/9-1 -- 3D shape\n\t"
201 "303: (|T|^2)/3/tau^(2/3)-1 -- 3D shape\n\t"
202 "304: (|T|^3)/3^{3/2}/tau-1 -- 3D shape\n\t"
203 //"311: (tau-1)^2-tau+sqrt(tau^2+eps)-- 3D untangling\n\t"
204 "313: (|T|^2)(tau-tau0)^(-2/3)/3 -- 3D untangling\n\t"
205 "315: (tau-1)^2 -- 3D no type\n\t"
206 "316: 0.5(sqrt(tau)-1/sqrt(tau))^2 -- 3D no type\n\t"
207 "321: |T-T^-t|^2 -- 3D shape+size\n\t"
208 "322: |T-adjT^-t|^2 -- 3D shape+size\n\t"
209 "323: |J|^3-3sqrt(3)ln(det(J))-3sqrt(3) -- 3D shape+size\n\t"
210 "328: balanced combo mu_301 & mu_316 -- 3D shape+size\n\t"
211 "332: (1-gamma) mu_302 + gamma mu_315 -- 3D shape+size\n\t"
212 "333: (1-gamma) mu_302 + gamma mu_316 -- 3D shape+size\n\t"
213 "334: (1-gamma) mu_303 + gamma mu_316 -- 3D shape+size\n\t"
214 "328: balanced combo mu_302 & mu_318 -- 3D shape+size\n\t"
215 "347: (1-gamma) mu_304 + gamma mu_316 -- 3D shape+size\n\t"
216 // "352: 0.5(tau-1)^2/(tau-tau_0) -- 3D untangling\n\t"
217 "360: (|T|^3)/3^{3/2}-tau -- 3D shape\n\t"
218 "A-metrics\n\t"
219 "11 : (1/4*alpha)|A-(adjA)^T(W^TW)/omega|^2 -- 2D shape\n\t"
220 "36 : (1/alpha)|A-W|^2 -- 2D shape+size+orientation\n\t"
221 "49 : (1-gamma) mu_2 + gamma nu_50 -- 2D shape+skew\n\t"
222 "51 : see fem/tmop.hpp -- 2D size+skew\n\t"
223 "107: (1/2*alpha)|A-|A|/|W|W|^2 -- 2D shape+orientation\n\t"
224 "126: (1-gamma)nu_11 + gamma*nu_14a -- 2D shape+size\n\t"
225 );
226 args.AddOption(&target_id, "-tid", "--target-id",
227 "Target (ideal element) type:\n\t"
228 "1: Ideal shape, unit size\n\t"
229 "2: Ideal shape, equal size\n\t"
230 "3: Ideal shape, initial size\n\t"
231 "4: Given full analytic Jacobian (in physical space)\n\t"
232 "5: Ideal shape, given size (in physical space)");
233 args.AddOption(&lim_const, "-lc", "--limit-const", "Limiting constant.");
234 args.AddOption(&adapt_lim_const, "-alc", "--adapt-limit-const",
235 "Adaptive limiting coefficient constant.");
236 args.AddOption(&quad_type, "-qt", "--quad-type",
237 "Quadrature rule type:\n\t"
238 "1: Gauss-Lobatto\n\t"
239 "2: Gauss-Legendre\n\t"
240 "3: Closed uniform points");
241 args.AddOption(&quad_order, "-qo", "--quad_order",
242 "Order of the quadrature rule.");
243 args.AddOption(&solver_type, "-st", "--solver-type",
244 " Type of solver: (default) 0: Newton, 1: LBFGS");
245 args.AddOption(&solver_iter, "-ni", "--newton-iters",
246 "Maximum number of Newton iterations.");
247 args.AddOption(&solver_rtol, "-rtol", "--newton-rel-tolerance",
248 "Relative tolerance for the Newton solver.");
249 args.AddOption(&solver_art_type, "-art", "--adaptive-rel-tol",
250 "Type of adaptive relative linear solver tolerance:\n\t"
251 "0: None (default)\n\t"
252 "1: Eisenstat-Walker type 1\n\t"
253 "2: Eisenstat-Walker type 2");
254 args.AddOption(&lin_solver, "-ls", "--lin-solver",
255 "Linear solver:\n\t"
256 "0: l1-Jacobi\n\t"
257 "1: CG\n\t"
258 "2: MINRES\n\t"
259 "3: MINRES + Jacobi preconditioner\n\t"
260 "4: MINRES + l1-Jacobi preconditioner");
261 args.AddOption(&max_lin_iter, "-li", "--lin-iter",
262 "Maximum number of iterations in the linear solve.");
263 args.AddOption(&move_bnd, "-bnd", "--move-boundary", "-fix-bnd",
264 "--fix-boundary",
265 "Enable motion along horizontal and vertical boundaries.");
266 args.AddOption(&combomet, "-cmb", "--combo-type",
267 "Combination of metrics options:\n\t"
268 "0: Use single metric\n\t"
269 "1: Shape + space-dependent size given analytically\n\t"
270 "2: Shape + adapted size given discretely; shared target");
271 args.AddOption(&bal_expl_combo, "-bec", "--balance-explicit-combo",
272 "-no-bec", "--balance-explicit-combo",
273 "Automatic balancing of explicit combo metrics.");
274 args.AddOption(&hradaptivity, "-hr", "--hr-adaptivity", "-no-hr",
275 "--no-hr-adaptivity",
276 "Enable hr-adaptivity.");
277 args.AddOption(&h_metric_id, "-hmid", "--h-metric",
278 "Same options as metric_id. Used to determine refinement"
279 " type for each element if h-adaptivity is enabled.");
280 args.AddOption(&normalization, "-nor", "--normalization", "-no-nor",
281 "--no-normalization",
282 "Make all terms in the optimization functional unitless.");
283 args.AddOption(&fdscheme, "-fd", "--fd_approximation",
284 "-no-fd", "--no-fd-approx",
285 "Enable finite difference based derivative computations.");
286 args.AddOption(&exactaction, "-ex", "--exact_action",
287 "-no-ex", "--no-exact-action",
288 "Enable exact action of TMOP_Integrator.");
289 args.AddOption(&integ_over_targ, "-it", "--integrate-target",
290 "-ir", "--integrate-reference",
291 "Integrate over target (-it) or reference (-ir) element.");
292 args.AddOption(&visualization, "-vis", "--visualization", "-no-vis",
293 "--no-visualization",
294 "Enable or disable GLVis visualization.");
295 args.AddOption(&verbosity_level, "-vl", "--verbosity-level",
296 "Verbosity level for the involved iterative solvers:\n\t"
297 "0: no output\n\t"
298 "1: Newton iterations\n\t"
299 "2: Newton iterations + linear solver summaries\n\t"
300 "3: newton iterations + linear solver iterations");
301 args.AddOption(&adapt_eval, "-ae", "--adaptivity-evaluator",
302 "0 - Advection based (DEFAULT), 1 - GSLIB.");
303 args.AddOption(&devopt, "-d", "--device",
304 "Device configuration string, see Device::Configure().");
305 args.AddOption(&pa, "-pa", "--partial-assembly", "-no-pa",
306 "--no-partial-assembly", "Enable Partial Assembly.");
307 args.AddOption(&n_hr_iter, "-nhr", "--n_hr_iter",
308 "Number of hr-adaptivity iterations.");
309 args.AddOption(&n_h_iter, "-nh", "--n_h_iter",
310 "Number of h-adaptivity iterations per r-adaptivity"
311 "iteration.");
312 args.AddOption(&mesh_node_order, "-mno", "--mesh_node_ordering",
313 "Ordering of mesh nodes."
314 "0 (default): byNodes, 1: byVDIM");
315 args.AddOption(&barrier_type, "-btype", "--barrier-type",
316 "0 - None,"
317 "1 - Shifted Barrier,"
318 "2 - Pseudo Barrier.");
319 args.AddOption(&worst_case_type, "-wctype", "--worst-case-type",
320 "0 - None,"
321 "1 - Beta,"
322 "2 - PMean.");
323 args.AddOption(&detj_bound, "-db", "--detj-bound",
324 "-no-db", "--no-detj-bound",
325 "Enable or disable strict enforcement of positive Jacobian "
326 "determinants to guarantee mesh validity for tensor-product " "elements.");
327 args.Parse();
328 if (!args.Good())
329 {
330 args.PrintUsage(cout);
331 return 1;
332 }
333 args.PrintOptions(cout);
334
335 if (h_metric_id < 0) { h_metric_id = metric_id; }
336
337 if (hradaptivity)
338 {
339 MFEM_VERIFY(strcmp(devopt,"cpu")==0, "HR-adaptivity is currently only"
340 " supported on cpus.");
341 }
342 Device device(devopt);
343 device.Print();
344
345 // Initialize and refine the starting mesh.
346 Mesh *mesh = new Mesh(mesh_file, 1, 1, false);
347 for (int lev = 0; lev < rs_levels; lev++) { mesh->UniformRefinement(); }
348 const int dim = mesh->Dimension();
349
350 if (hradaptivity) { mesh->EnsureNCMesh(); }
351
352 auto s = mesh->GetNodalFESpace();
353 const bool periodic = (s && s->IsDGSpace()) ? true : false;
354
355 // Define a FE space on the mesh, based on the input order. This space will
356 // also be used to represent the nodal positions of the mesh. We use a vector
357 // FE space which is a tensor product of a scalar FE space. The number of
358 // components in the vector finite element space matches the dimension.
360 if (mesh_poly_deg <= 0) { mesh_poly_deg = 2; }
361 if (periodic)
362 {
363 fec = new L2_FECollection(mesh_poly_deg, dim, BasisType::GaussLobatto);
364 }
365 else { fec = new H1_FECollection(mesh_poly_deg, dim); }
366 auto fespace = new FiniteElementSpace(mesh, fec, dim, mesh_node_order);
367
368 // Make the starting mesh curved. This means we define the mesh elements
369 // through a FE-based transformation of the reference element.
370 mesh->SetNodalFESpace(fespace);
371
372 // Get the mesh nodes (vertices and other DOFs in the FE space) as a FE grid
373 // function in pfespace. Note that changing x automatically changes the
374 // shapes of the mesh elements.
375 GridFunction x(fespace);
376 mesh->SetNodalGridFunction(&x);
377
378 // We create an H1 space for the mesh displacement. The displacement is
379 // always in a continuous space, even if the mesh is periodic.
380 // The nonlinear problem will be solved for the continuous displacement.
381 H1_FECollection fec_h1(mesh_poly_deg, dim);
382 FiniteElementSpace fes_h1(mesh, &fec_h1, dim, mesh_node_order);
383 GridFunction dx(&fes_h1); dx = 0.0;
384
385 // Define a vector representing the minimal local mesh size in the mesh
386 // nodes. We index the nodes by the scalar version of the DOFs in pfespace.
387 // In addition, compute average mesh size and total volume.
388 Vector h0(fes_h1.GetNDofs());
389 h0 = infinity();
390 real_t mesh_volume = 0.0;
391 Array<int> dofs;
392 for (int i = 0; i < mesh->GetNE(); i++)
393 {
394 // Get the local scalar element degrees of freedom in dofs.
395 fes_h1.GetElementDofs(i, dofs);
396 // Adjust the value of h0 in dofs based on the local mesh size.
397 const real_t hi = mesh->GetElementSize(i);
398 for (int j = 0; j < dofs.Size(); j++)
399 {
400 h0(dofs[j]) = min(h0(dofs[j]), hi);
401 }
402 mesh_volume += mesh->GetElementVolume(i);
403 }
404 const real_t small_phys_size = pow(mesh_volume, 1.0 / dim) / 100.0;
405
406 // Add a random perturbation to the nodes in the interior of the domain.
407 // We define a random grid function of pfespace and make sure that it is
408 // zero on the boundary and its values are locally of the order of h0.
409 // The latter is based on the DofToVDof() method which maps the scalar to
410 // the vector degrees of freedom in pfespace.
411 if (jitter > 0)
412 {
413 GridFunction rdm(&fes_h1);
414 rdm.Randomize();
415 rdm -= 0.25; // Shift to random values in [-0.5,0.5].
416 rdm *= jitter;
417 rdm.HostReadWrite();
418 // Scale the random values to be of order of the local mesh size.
419 for (int i = 0; i < fes_h1.GetNDofs(); i++)
420 {
421 for (int d = 0; d < dim; d++)
422 {
423 rdm(fes_h1.DofToVDof(i,d)) *= h0(i);
424 }
425 }
426 // Set the boundary values to zero. Note that periodic periodic boundaries
427 // will be free to move.
428 Array<int> vdofs;
429 for (int i = 0; i < fes_h1.GetNBE(); i++)
430 {
431 fespace->GetBdrElementVDofs(i, vdofs);
432 for (int j = 0; j < vdofs.Size(); j++) { rdm(vdofs[j]) = 0.0; }
433 }
434
435 if (periodic)
436 {
437 // For H1 the perturbation is controlled by the true nodes.
438 rdm.SetFromTrueVector();
439 GridFunction rdm_l2(fespace);
440 rdm_l2.ProjectGridFunction(rdm);
441 x -= rdm_l2;
442 }
443 else
444 {
445 x -= rdm;
446 // For H1 the perturbation is controlled by the true nodes.
448 }
449
450 if (visualization)
451 {
452 socketstream vis1;
453 common::VisualizeMesh(vis1, "localhost", 19916, *mesh, "Perturbed",
454 300, 600, 300, 300);
455 }
456 }
457
458 // Save the starting (prior to the optimization) mesh to a file. This
459 // output can be viewed later using GLVis: "glvis -m perturbed.mesh".
460 {
461 ofstream mesh_ofs("perturbed.mesh");
462 mesh->Print(mesh_ofs);
463 }
464
465 // Store the starting (prior to the optimization) positions.
466 GridFunction x0(x);
467
468 // Form the integrator that uses the chosen metric and target.
469 real_t min_detJ = -0.1;
470 TMOP_QualityMetric *metric = NULL;
471 switch (metric_id)
472 {
473 // T-metrics
474 case 1: metric = new TMOP_Metric_001; break;
475 case 2: metric = new TMOP_Metric_002; break;
476 case 4: metric = new TMOP_Metric_004; break;
477 case 7: metric = new TMOP_Metric_007; break;
478 case 9: metric = new TMOP_Metric_009; break;
479 case 14: metric = new TMOP_Metric_014; break;
480 case 22: metric = new TMOP_Metric_022(min_detJ); break;
481 case 50: metric = new TMOP_Metric_050; break;
482 case 55: metric = new TMOP_Metric_055; break;
483 case 56: metric = new TMOP_Metric_056; break;
484 case 58: metric = new TMOP_Metric_058; break;
485 case 66: metric = new TMOP_Metric_066(0.5); break;
486 case 77: metric = new TMOP_Metric_077; break;
487 case 80: metric = new TMOP_Metric_080(0.5); break;
488 case 85: metric = new TMOP_Metric_085; break;
489 case 90: metric = new TMOP_Metric_090; break;
490 case 94: metric = new TMOP_Metric_094; break;
491 case 98: metric = new TMOP_Metric_098; break;
492 // case 211: metric = new TMOP_Metric_211; break;
493 // case 252: metric = new TMOP_Metric_252(min_detJ); break;
494 case 301: metric = new TMOP_Metric_301; break;
495 case 302: metric = new TMOP_Metric_302; break;
496 case 303: metric = new TMOP_Metric_303; break;
497 case 304: metric = new TMOP_Metric_304; break;
498 // case 311: metric = new TMOP_Metric_311; break;
499 case 313: metric = new TMOP_Metric_313(min_detJ); break;
500 case 315: metric = new TMOP_Metric_315; break;
501 case 316: metric = new TMOP_Metric_316; break;
502 case 321: metric = new TMOP_Metric_321; break;
503 case 322: metric = new TMOP_Metric_322; break;
504 case 323: metric = new TMOP_Metric_323; break;
505 case 328: metric = new TMOP_Metric_328; break;
506 case 332: metric = new TMOP_Metric_332(0.5); break;
507 case 333: metric = new TMOP_Metric_333(0.5); break;
508 case 334: metric = new TMOP_Metric_334(0.5); break;
509 case 338: metric = new TMOP_Metric_338; break;
510 case 347: metric = new TMOP_Metric_347(0.5); break;
511 // case 352: metric = new TMOP_Metric_352(min_detJ); break;
512 case 360: metric = new TMOP_Metric_360; break;
513 // A-metrics
514 case 11: metric = new TMOP_AMetric_011; break;
515 case 36: metric = new TMOP_AMetric_036; break;
516 case 49: metric = new TMOP_AMetric_049(0.9); break;
517 case 51: metric = new TMOP_AMetric_051; break;
518 case 107: metric = new TMOP_AMetric_107; break;
519 case 126: metric = new TMOP_AMetric_126(0.9); break;
520 default:
521 cout << "Unknown metric_id: " << metric_id << endl;
522 return 3;
523 }
524 TMOP_QualityMetric *h_metric = NULL;
525 if (hradaptivity)
526 {
527 switch (h_metric_id)
528 {
529 case 1: h_metric = new TMOP_Metric_001; break;
530 case 2: h_metric = new TMOP_Metric_002; break;
531 case 7: h_metric = new TMOP_Metric_007; break;
532 case 9: h_metric = new TMOP_Metric_009; break;
533 case 55: h_metric = new TMOP_Metric_055; break;
534 case 56: h_metric = new TMOP_Metric_056; break;
535 case 58: h_metric = new TMOP_Metric_058; break;
536 case 77: h_metric = new TMOP_Metric_077; break;
537 case 315: h_metric = new TMOP_Metric_315; break;
538 case 316: h_metric = new TMOP_Metric_316; break;
539 case 321: h_metric = new TMOP_Metric_321; break;
540 default: cout << "Metric_id not supported for h-adaptivity: " << h_metric_id <<
541 endl;
542 return 3;
543 }
544 }
545
547 switch (barrier_type)
548 {
549 case 0: btype = TMOP_WorstCaseUntangleOptimizer_Metric::BarrierType::None;
550 break;
551 case 1: btype = TMOP_WorstCaseUntangleOptimizer_Metric::BarrierType::Shifted;
552 break;
553 case 2: btype = TMOP_WorstCaseUntangleOptimizer_Metric::BarrierType::Pseudo;
554 break;
555 default: cout << "barrier_type not supported: " << barrier_type << endl;
556 return 3;
557 }
558
560 switch (worst_case_type)
561 {
562 case 0: wctype = TMOP_WorstCaseUntangleOptimizer_Metric::WorstCaseType::None;
563 break;
564 case 1: wctype = TMOP_WorstCaseUntangleOptimizer_Metric::WorstCaseType::Beta;
565 break;
566 case 2: wctype = TMOP_WorstCaseUntangleOptimizer_Metric::WorstCaseType::PMean;
567 break;
568 default: cout << "worst_case_type not supported: " << worst_case_type << endl;
569 return 3;
570 }
571
572 TMOP_QualityMetric *untangler_metric = NULL;
573 if (barrier_type > 0 || worst_case_type > 0)
574 {
575 if (barrier_type > 0)
576 {
577 MFEM_VERIFY(metric_id == 4 || metric_id == 14 || metric_id == 66,
578 "Metric not supported for shifted/pseudo barriers.");
579 }
580 untangler_metric = new TMOP_WorstCaseUntangleOptimizer_Metric(*metric,
581 2,
582 1.5,
583 0.001, //0.01 for pseudo barrier
584 0.001,
585 btype,
586 wctype);
587 }
588
589 if (metric_id < 300 || h_metric_id < 300)
590 {
591 MFEM_VERIFY(dim == 2, "Incompatible metric for 3D meshes");
592 }
593 if (metric_id >= 300 || h_metric_id >= 300)
594 {
595 MFEM_VERIFY(dim == 3, "Incompatible metric for 2D meshes");
596 }
597
599 TargetConstructor *target_c = NULL;
600 HessianCoefficient *adapt_coeff = NULL;
601 HRHessianCoefficient *hr_adapt_coeff = NULL;
602 int ind_fec_order = (target_id >= 5 && target_id <= 8 && !fdscheme) ?
603 1 : mesh_poly_deg;
604 H1_FECollection ind_fec(ind_fec_order, dim);
605 FiniteElementSpace ind_fes(mesh, &ind_fec);
606 FiniteElementSpace ind_fesv(mesh, &ind_fec, dim);
607 GridFunction size(&ind_fes), aspr(&ind_fes), ori(&ind_fes);
608 GridFunction aspr3d(&ind_fesv);
609
610 const AssemblyLevel al =
611 pa ? AssemblyLevel::PARTIAL : AssemblyLevel::LEGACY;
612
613 switch (target_id)
614 {
615 case 1: target_t = TargetConstructor::IDEAL_SHAPE_UNIT_SIZE; break;
616 case 2: target_t = TargetConstructor::IDEAL_SHAPE_EQUAL_SIZE; break;
617 case 3: target_t = TargetConstructor::IDEAL_SHAPE_GIVEN_SIZE; break;
618 case 4: // Analytic
619 {
621 AnalyticAdaptTC *tc = new AnalyticAdaptTC(target_t);
622 adapt_coeff = new HessianCoefficient(dim, metric_id);
623 tc->SetAnalyticTargetSpec(NULL, NULL, adapt_coeff);
624 target_c = tc;
625 break;
626 }
627 case 5: // Discrete size 2D or 3D
628 {
630 DiscreteAdaptTC *tc = new DiscreteAdaptTC(target_t);
631 if (adapt_eval == 0)
632 {
634 }
635 else
636 {
637#ifdef MFEM_USE_GSLIB
639#else
640 MFEM_ABORT("MFEM is not built with GSLIB.");
641#endif
642 }
643 ConstructSizeGF(size);
645 tc->SetMinSizeForTargets(size.Min());
646 target_c = tc;
647 break;
648 }
649 case 6: // Discrete size + aspect ratio - 2D
650 {
651 GridFunction d_x(&ind_fes), d_y(&ind_fes), disc(&ind_fes);
652
654 DiscreteAdaptTC *tc = new DiscreteAdaptTC(target_t);
656 disc.ProjectCoefficient(mat_coeff);
657 if (adapt_eval == 0)
658 {
660 }
661 else
662 {
663#ifdef MFEM_USE_GSLIB
665#else
666 MFEM_ABORT("MFEM is not built with GSLIB.");
667#endif
668 }
669
670 // Diffuse the interface
672
673 // Get partials with respect to x and y of the grid function
674 disc.GetDerivative(1,0,d_x);
675 disc.GetDerivative(1,1,d_y);
676
677 // Compute the squared magnitude of the gradient
678 for (int i = 0; i < size.Size(); i++)
679 {
680 size(i) = std::pow(d_x(i),2)+std::pow(d_y(i),2);
681 }
682 const real_t max = size.Max();
683
684 for (int i = 0; i < d_x.Size(); i++)
685 {
686 d_x(i) = std::abs(d_x(i));
687 d_y(i) = std::abs(d_y(i));
688 }
689 const real_t eps = 0.01;
690 const real_t aspr_ratio = 20.0;
691 const real_t size_ratio = 40.0;
692
693 for (int i = 0; i < size.Size(); i++)
694 {
695 size(i) = (size(i)/max);
696 aspr(i) = (d_x(i)+eps)/(d_y(i)+eps);
697 aspr(i) = 0.1 + 0.9*(1-size(i))*(1-size(i));
698 if (aspr(i) > aspr_ratio) {aspr(i) = aspr_ratio;}
699 if (aspr(i) < 1.0/aspr_ratio) {aspr(i) = 1.0/aspr_ratio;}
700 }
701 Vector vals;
702 const int NE = mesh->GetNE();
703 real_t volume = 0.0, volume_ind = 0.0;
704
705 for (int i = 0; i < NE; i++)
706 {
708 const IntegrationRule &ir =
709 IntRules.Get(mesh->GetElementBaseGeometry(i), Tr->OrderJ());
710 size.GetValues(i, ir, vals);
711 for (int j = 0; j < ir.GetNPoints(); j++)
712 {
713 const IntegrationPoint &ip = ir.IntPoint(j);
714 Tr->SetIntPoint(&ip);
715 volume += ip.weight * Tr->Weight();
716 volume_ind += vals(j) * ip.weight * Tr->Weight();
717 }
718 }
719
720 const real_t avg_zone_size = volume / NE;
721
722 const real_t small_avg_ratio = (volume_ind + (volume - volume_ind) /
723 size_ratio) /
724 volume;
725
726 const real_t small_zone_size = small_avg_ratio * avg_zone_size;
727 const real_t big_zone_size = size_ratio * small_zone_size;
728
729 for (int i = 0; i < size.Size(); i++)
730 {
731 const real_t val = size(i);
732 const real_t a = (big_zone_size - small_zone_size) / small_zone_size;
733 size(i) = big_zone_size / (1.0+a*val);
734 }
735
736 DiffuseField(size, 2);
737 DiffuseField(aspr, 2);
738
740 tc->SetMinSizeForTargets(size.Min());
742 target_c = tc;
743 break;
744 }
745 case 7: // Discrete aspect ratio 3D
746 {
748 DiscreteAdaptTC *tc = new DiscreteAdaptTC(target_t);
749 if (adapt_eval == 0)
750 {
752 }
753 else
754 {
755#ifdef MFEM_USE_GSLIB
757#else
758 MFEM_ABORT("MFEM is not built with GSLIB.");
759#endif
760 }
762 aspr3d.ProjectCoefficient(fd_aspr3d);
763
765 target_c = tc;
766 break;
767 }
768 case 8: // shape/size + orientation 2D
769 {
771 DiscreteAdaptTC *tc = new DiscreteAdaptTC(target_t);
772 if (adapt_eval == 0)
773 {
775 }
776 else
777 {
778#ifdef MFEM_USE_GSLIB
780#else
781 MFEM_ABORT("MFEM is not built with GSLIB.");
782#endif
783 }
784
785 ConstantCoefficient size_coeff(0.1*0.1);
786 size.ProjectCoefficient(size_coeff);
788 tc->SetMinSizeForTargets(size.Min());
789
791 ori.ProjectCoefficient(ori_coeff);
793 target_c = tc;
794 break;
795 }
796 // Targets used for hr-adaptivity tests.
797 case 9: // size target in an annular region.
798 case 10: // size+aspect-ratio in an annular region.
799 case 11: // size+aspect-ratio target for a rotate sine wave
800 {
802 AnalyticAdaptTC *tc = new AnalyticAdaptTC(target_t);
803 hr_adapt_coeff = new HRHessianCoefficient(dim, target_id - 9);
804 tc->SetAnalyticTargetSpec(NULL, NULL, hr_adapt_coeff);
805 target_c = tc;
806 break;
807 }
808 default: cout << "Unknown target_id: " << target_id << endl; return 3;
809 }
810 if (target_c == NULL)
811 {
812 target_c = new TargetConstructor(target_t);
813 }
814 target_c->SetNodes(x0);
815
816 TMOP_QualityMetric *metric_to_use = barrier_type > 0 || worst_case_type > 0
817 ? untangler_metric
818 : metric;
819 auto tmop_integ = new TMOP_Integrator(metric_to_use, target_c, h_metric);
820 tmop_integ->IntegrateOverTarget(integ_over_targ);
821 if (barrier_type > 0 || worst_case_type > 0)
822 {
823 tmop_integ->ComputeUntangleMetricQuantiles(x, *fespace);
824 }
825
826 // Finite differences for computations of derivatives.
827 if (fdscheme)
828 {
829 MFEM_VERIFY(pa == false, "PA for finite differences is not implemented.");
830 tmop_integ->EnableFiniteDifferences(x);
831 }
832 tmop_integ->SetExactActionFlag(exactaction);
833
834 // Setup the quadrature rules for the TMOP integrator.
835 IntegrationRules *irules = NULL;
836 switch (quad_type)
837 {
838 case 1: irules = &IntRulesLo; break;
839 case 2: irules = &IntRules; break;
840 case 3: irules = &IntRulesCU; break;
841 default: cout << "Unknown quad_type: " << quad_type << endl; return 3;
842 }
843 tmop_integ->SetIntegrationRules(*irules, quad_order);
844 if (dim == 2)
845 {
846 cout << "Triangle quadrature points: "
847 << irules->Get(Geometry::TRIANGLE, quad_order).GetNPoints()
848 << "\nQuadrilateral quadrature points: "
849 << irules->Get(Geometry::SQUARE, quad_order).GetNPoints() << endl;
850 }
851 if (dim == 3)
852 {
853 cout << "Tetrahedron quadrature points: "
854 << irules->Get(Geometry::TETRAHEDRON, quad_order).GetNPoints()
855 << "\nHexahedron quadrature points: "
856 << irules->Get(Geometry::CUBE, quad_order).GetNPoints()
857 << "\nPrism quadrature points: "
858 << irules->Get(Geometry::PRISM, quad_order).GetNPoints() << endl;
859 }
860
861 // Automatically balanced gamma in composite metrics.
862 auto metric_combo = dynamic_cast<TMOP_Combo_QualityMetric *>(metric);
863 if (metric_combo && bal_expl_combo)
864 {
865 Vector bal_weights;
866 auto ir = irules->Get(mesh->GetTypicalElementGeometry(), quad_order);
867 metric_combo->ComputeBalancedWeights(x, *target_c, bal_weights, pa, &ir);
868 metric_combo->SetWeights(bal_weights);
869 }
870
871 // Limit the node movement.
872 // The limiting distances can be given by a general function of space.
873 FiniteElementSpace dist_fespace(mesh, &fec_h1); // scalar space
874 GridFunction dist(&dist_fespace);
875 dist = 1.0;
876 // The small_phys_size is relevant only with proper normalization.
877 if (normalization) { dist = small_phys_size; }
878 ConstantCoefficient lim_coeff(lim_const);
879 if (lim_const != 0.0) { tmop_integ->EnableLimiting(x0, dist, lim_coeff); }
880
881 // Adaptive limiting.
882 GridFunction adapt_lim_gf0_1(&ind_fes);
883 GridFunction adapt_lim_gf0_2(&ind_fes);
884 ConstantCoefficient adapt_lim_coeff_1(adapt_lim_const);
885 const real_t adapt_lim_const_2 = 0.5 * adapt_lim_const;
886 ConstantCoefficient adapt_lim_coeff_2(adapt_lim_const_2);
887 AdaptivityEvaluator *adapt_lim_eval = NULL;
888 if (adapt_lim_const > 0.0)
889 {
890 FunctionCoefficient adapt_lim_gf0_coeff_1(adapt_lim_fun);
891 FunctionCoefficient adapt_lim_gf0_coeff_2(adapt_lim_fun2);
892 adapt_lim_gf0_1.ProjectCoefficient(adapt_lim_gf0_coeff_1);
893 adapt_lim_gf0_2.ProjectCoefficient(adapt_lim_gf0_coeff_2);
894
895 if (adapt_eval == 0) { adapt_lim_eval = new AdvectorCG(al); }
896 else if (adapt_eval == 1)
897 {
898#ifdef MFEM_USE_GSLIB
899 adapt_lim_eval = new InterpolatorFP;
900#else
901 MFEM_ABORT("MFEM is not built with GSLIB support!");
902#endif
903 }
904 else { MFEM_ABORT("Bad interpolation option."); }
905
907 Array<Coefficient *> coeff(2);
908 Array<real_t> delta_max(2);
909 z0[0] = &adapt_lim_gf0_1;
910 z0[1] = &adapt_lim_gf0_2;
911 coeff[0] = &adapt_lim_coeff_1;
912 coeff[1] = &adapt_lim_coeff_2;
913 delta_max[0] = 1.0;
914 delta_max[1] = 0.5;
915 tmop_integ->EnableAdaptiveLimiting(z0, coeff, *adapt_lim_eval, delta_max);
916 if (visualization)
917 {
918 socketstream vis1, vis2;
919 common::VisualizeField(vis1, "localhost", 19916, adapt_lim_gf0_1,
920 "Zeta0(1) - initial mesh", 300, 600, 300, 300);
921 common::VisualizeField(vis2, "localhost", 19916, adapt_lim_gf0_2,
922 "Zeta0(2) - initial mesh", 300, 900, 300, 300);
923 }
924 }
925
926 //
927 // Setup the NonlinearForm which defines the integral of interest, its
928 // first and second derivatives.
929 //
930 // Note that the TMOP optimization always operates on H1 spaces. For periodic
931 // meshes, TMOP solves for a continuous periodic displacement.
932 NonlinearForm a(&fes_h1);
933 if (pa) { a.SetAssemblyLevel(AssemblyLevel::PARTIAL); }
934 // We can use a combination of metrics, i.e., optimize the sum of two
935 // integrals, where both are scaled by used-defined space-dependent weights.
936 // Note that there are no command-line options for the weights and the type
937 // of the second metric; one should update those in the code.
938 ConstantCoefficient *metric_coeff1 = NULL;
939 TMOP_QualityMetric *metric2 = NULL;
940 TargetConstructor *target_c2 = NULL;
941 FunctionCoefficient metric_coeff2(weight_fun);
942 TMOPComboIntegrator *combo = nullptr;
943 if (combomet > 0)
944 {
945 // First metric.
946 metric_coeff1 = new ConstantCoefficient(1.0);
947 tmop_integ->SetCoefficient(*metric_coeff1);
948
949 // Second metric.
950 if (dim == 2) { metric2 = new TMOP_Metric_077; }
951 else { metric2 = new TMOP_Metric_315; }
952 TMOP_Integrator *tmop_integ2 = NULL;
953 if (combomet == 1)
954 {
955 target_c2 = new TargetConstructor(
957 target_c2->SetVolumeScale(0.01);
958 target_c2->SetNodes(x0);
959 tmop_integ2 = new TMOP_Integrator(metric2, target_c2, h_metric);
960 tmop_integ2->SetCoefficient(metric_coeff2);
961 }
962 else { tmop_integ2 = new TMOP_Integrator(metric2, target_c, h_metric); }
963 tmop_integ2->IntegrateOverTarget(integ_over_targ);
964 tmop_integ2->SetIntegrationRules(*irules, quad_order);
965 if (fdscheme) { tmop_integ2->EnableFiniteDifferences(x); }
966 tmop_integ2->SetExactActionFlag(exactaction);
967
968 combo = new TMOPComboIntegrator;
969 combo->AddTMOPIntegrator(tmop_integ);
970 combo->AddTMOPIntegrator(tmop_integ2);
971 if (lim_const != 0.0) { combo->EnableLimiting(x0, dist, lim_coeff); }
972
973 a.AddDomainIntegrator(combo);
974 }
975 else { a.AddDomainIntegrator(tmop_integ); }
976 // The PA setup must be performed after all integrators have been added.
977 if (pa) { a.Setup(); }
978
979 // Has to be after the enabling of the limiting / alignment, as it computes
980 // normalization factors for these terms as well.
981 if (normalization)
982 {
983 tmop_integ->EnableNormalization(x0);
984 if (combomet) { combo->EnableNormalization(x0); }
985 }
986
987 // Compute the minimum det(J) of the starting mesh.
988 min_detJ = infinity();
989 const int NE = mesh->GetNE();
990 for (int i = 0; i < NE; i++)
991 {
992 const IntegrationRule &ir =
993 irules->Get(fespace->GetFE(i)->GetGeomType(), quad_order);
995 for (int j = 0; j < ir.GetNPoints(); j++)
996 {
997 transf->SetIntPoint(&ir.IntPoint(j));
998 min_detJ = min(min_detJ, transf->Jacobian().Det());
999 }
1000 }
1001 cout << "Minimum det(J) of the original mesh is " << min_detJ << endl;
1002
1003 if (min_detJ < 0.0 && barrier_type == 0
1004 && metric_id != 22 && metric_id != 211 && metric_id != 252
1005 && metric_id != 311 && metric_id != 313 && metric_id != 352)
1006 {
1007 MFEM_ABORT("The input mesh is inverted! Try an untangling metric.");
1008 }
1009 if (min_detJ < 0.0)
1010 {
1011 MFEM_VERIFY(target_t == TargetConstructor::IDEAL_SHAPE_UNIT_SIZE,
1012 "Untangling is supported only for ideal targets.");
1013
1014 const DenseMatrix &Wideal =
1016 min_detJ /= Wideal.Det();
1017
1018 // Slightly below minJ0 to avoid div by 0.
1019 min_detJ -= 0.01 * h0.Min();
1020 }
1021
1022 // For HR tests, the energy is normalized by the number of elements.
1023 if (periodic) { tmop_integ->SetInitialMeshPos(&x0); }
1024 const real_t init_energy = a.GetGridFunctionEnergy(periodic ? dx : x) /
1025 (hradaptivity ? mesh->GetNE() : 1);
1026 real_t init_metric_energy = init_energy;
1027 if (lim_const > 0.0 || adapt_lim_const > 0.0)
1028 {
1029 lim_coeff.constant = 0.0;
1030 adapt_lim_coeff_1.constant = 0.0;
1031 adapt_lim_coeff_2.constant = 0.0;
1032 init_metric_energy = a.GetGridFunctionEnergy(periodic ? dx : x) /
1033 (hradaptivity ? mesh->GetNE() : 1);
1034 lim_coeff.constant = lim_const;
1035 adapt_lim_coeff_1.constant = adapt_lim_const;
1036 adapt_lim_coeff_2.constant = adapt_lim_const_2;
1037 }
1038
1039 // Visualize the starting mesh and metric values.
1040 // Note that for combinations of metrics, this only shows the first metric.
1041 if (visualization)
1042 {
1043 char title[] = "Initial metric values";
1044 vis_tmop_metric_s(mesh_poly_deg, *metric, *target_c, *mesh, title, 0);
1045 }
1046
1047 // Fix all boundary nodes, or fix only a given component depending on the
1048 // boundary attributes of the given mesh.
1049 // Attributes 1/2/3 correspond to fixed x/y/z components of the node.
1050 // Attribute 4 corresponds to an entirely fixed node.
1051 // All other attributes represent unconstrained boundary nodes.
1052 if (move_bnd == false)
1053 {
1054 Array<int> ess_bdr(mesh->bdr_attributes.Max());
1055 ess_bdr = 1;
1056 a.SetEssentialBC(ess_bdr);
1057 }
1058 else
1059 {
1060 int n = 0;
1061 for (int i = 0; i < mesh->GetNBE(); i++)
1062 {
1063 const int nd = fes_h1.GetBE(i)->GetDof();
1064 const int attr = mesh->GetBdrElement(i)->GetAttribute();
1065 MFEM_VERIFY(!(dim == 2 && attr == 3),
1066 "Boundary attribute 3 must be used only for 3D meshes. "
1067 "Adjust the attributes (1/2/3/4 for fixed x/y/z/all "
1068 "components, rest for free nodes), or use -fix-bnd.");
1069 if (attr == 1 || attr == 2 || attr == 3) { n += nd; }
1070 if (attr == 4) { n += nd * dim; }
1071 }
1072 Array<int> vdofs, ess_vdofs(n);
1073 n = 0;
1074 for (int i = 0; i < mesh->GetNBE(); i++)
1075 {
1076 const int nd = fes_h1.GetBE(i)->GetDof();
1077 const int attr = mesh->GetBdrElement(i)->GetAttribute();
1078 fes_h1.GetBdrElementVDofs(i, vdofs);
1079 if (attr == 1) // Fix x components.
1080 {
1081 for (int j = 0; j < nd; j++)
1082 { ess_vdofs[n++] = vdofs[j]; }
1083 }
1084 else if (attr == 2) // Fix y components.
1085 {
1086 for (int j = 0; j < nd; j++)
1087 { ess_vdofs[n++] = vdofs[j+nd]; }
1088 }
1089 else if (attr == 3) // Fix z components.
1090 {
1091 for (int j = 0; j < nd; j++)
1092 { ess_vdofs[n++] = vdofs[j+2*nd]; }
1093 }
1094 else if (attr == 4) // Fix all components.
1095 {
1096 for (int j = 0; j < vdofs.Size(); j++)
1097 { ess_vdofs[n++] = vdofs[j]; }
1098 }
1099 }
1100 a.SetEssentialVDofs(ess_vdofs);
1101 }
1102
1103 // As we use the inexact Newton method to solve the resulting nonlinear
1104 // system, here we setup the linear solver for the system's Jacobian.
1105 Solver *S = NULL, *S_prec = NULL;
1106#ifdef MFEM_USE_SINGLE
1107 const real_t linsol_rtol = 1e-5;
1108#else
1109 const real_t linsol_rtol = 1e-12;
1110#endif
1111 // Level of output.
1112 IterativeSolver::PrintLevel linsolver_print;
1113 if (verbosity_level == 2)
1114 { linsolver_print.Errors().Warnings().FirstAndLast(); }
1115 if (verbosity_level > 2)
1116 { linsolver_print.Errors().Warnings().Iterations(); }
1117 if (lin_solver == 0)
1118 {
1119 S = new DSmoother(1, 1.0, max_lin_iter);
1120 }
1121 else if (lin_solver == 1)
1122 {
1123 CGSolver *cg = new CGSolver;
1124 cg->SetMaxIter(max_lin_iter);
1125 cg->SetRelTol(linsol_rtol);
1126 cg->SetAbsTol(0.0);
1127 cg->SetPrintLevel(linsolver_print);
1128 S = cg;
1129 }
1130 else
1131 {
1132 MINRESSolver *minres = new MINRESSolver;
1133 minres->SetMaxIter(max_lin_iter);
1134 minres->SetRelTol(linsol_rtol);
1135 minres->SetAbsTol(0.0);
1136 minres->SetPrintLevel(linsolver_print);
1137 if (lin_solver == 3 || lin_solver == 4)
1138 {
1139 if (pa)
1140 {
1141 MFEM_VERIFY(lin_solver != 4, "PA l1-Jacobi is not implemented");
1142 auto js = new OperatorJacobiSmoother;
1143 js->SetPositiveDiagonal(true);
1144 S_prec = js;
1145 }
1146 else
1147 {
1148 auto ds = new DSmoother((lin_solver == 3) ? 0 : 1, 1.0, 1);
1149 ds->SetPositiveDiagonal(true);
1150 S_prec = ds;
1151 }
1152 minres->SetPreconditioner(*S_prec);
1153 }
1154 S = minres;
1155 }
1156
1157 //
1158 // Perform the nonlinear optimization.
1159 //
1160 const IntegrationRule &ir =
1161 irules->Get(mesh->GetTypicalElementGeometry(), quad_order);
1162 TMOPNewtonSolver solver(ir, solver_type);
1163 // Provide all integration rules in case of a mixed mesh.
1164 solver.SetIntegrationRules(*irules, quad_order);
1165 // Specify linear solver when we use a Newton-based solver.
1166 if (solver_type == 0) { solver.SetPreconditioner(*S); }
1167 // For untangling, the solver will update the min det(T) values.
1168 solver.SetMinDetPtr(&min_detJ);
1169 solver.SetMaxIter(solver_iter);
1170 solver.SetRelTol(solver_rtol);
1171 solver.SetAbsTol(0.0);
1172 if (solver_art_type > 0)
1173 {
1174 solver.SetAdaptiveLinRtol(solver_art_type, 0.5, 0.9);
1175 }
1176 if (detj_bound)
1177 {
1178 const int bound_refs = 4; // number of refinements to compute bounds
1179 const int bound_recs = 4; // number of recursions for the bound search
1180 solver.EnsurePositiveDeterminantBound(*mesh, bound_refs, bound_recs);
1181 }
1182 // Level of output.
1183 IterativeSolver::PrintLevel newton_print;
1184 if (verbosity_level > 0) { newton_print.Errors().Warnings().Iterations(); }
1185 else { newton_print.Errors().Warnings(); }
1186 solver.SetPrintLevel(newton_print);
1187 // hr-adaptivity solver.
1188 // If hr-adaptivity is disabled, r-adaptivity is done once using the
1189 // TMOPNewtonSolver.
1190 // Otherwise, "hr_iter" iterations of r-adaptivity are done followed by
1191 // "h_per_r_iter" iterations of h-adaptivity after each r-adaptivity.
1192 // The solver terminates if an h-adaptivity iteration does not modify
1193 // any element in the mesh.
1194 TMOPHRSolver hr_solver(*mesh, a, solver,
1195 x, move_bnd, hradaptivity,
1196 mesh_poly_deg, h_metric_id,
1197 n_hr_iter, n_h_iter);
1198 hr_solver.AddGridFunctionForUpdate(&x0);
1199 hr_solver.AddFESpaceForUpdate(&fes_h1);
1200 if (adapt_lim_const > 0.)
1201 {
1202 hr_solver.AddGridFunctionForUpdate(&adapt_lim_gf0_1);
1203 hr_solver.AddGridFunctionForUpdate(&adapt_lim_gf0_2);
1204 hr_solver.AddFESpaceForUpdate(&ind_fes);
1205 }
1206 hr_solver.Mult();
1207
1208 // Save the optimized mesh to a file. This output can be viewed later
1209 // using GLVis: "glvis -m optimized.mesh".
1210 {
1211 ofstream mesh_ofs("optimized.mesh");
1212 mesh_ofs.precision(14);
1213 mesh->Print(mesh_ofs);
1214 }
1215
1216 // Report the final energy of the functional.
1217 if (periodic)
1218 {
1219 GridFunction dx_L2(x); dx_L2 -= x0;
1220 // Assumes Gauss-Lobatto and continuity in x and x_0 across faces.
1221 dx.ProjectGridFunction(dx_L2);
1222 }
1223 if (periodic) { tmop_integ->SetInitialMeshPos(&x0); }
1224 const real_t fin_energy = a.GetGridFunctionEnergy(periodic ? dx : x) /
1225 (hradaptivity ? mesh->GetNE() : 1);
1226 real_t fin_metric_energy = fin_energy;
1227 if (lim_const > 0.0 || adapt_lim_const > 0.0)
1228 {
1229 lim_coeff.constant = 0.0;
1230 adapt_lim_coeff_1.constant = 0.0;
1231 adapt_lim_coeff_2.constant = 0.0;
1232 fin_metric_energy = a.GetGridFunctionEnergy(periodic ? dx : x) /
1233 (hradaptivity ? mesh->GetNE() : 1);
1234 lim_coeff.constant = lim_const;
1235 adapt_lim_coeff_1.constant = adapt_lim_const;
1236 adapt_lim_coeff_2.constant = adapt_lim_const_2;
1237 }
1238 std::cout << std::scientific << std::setprecision(4);
1239 cout << "Initial strain energy: " << init_energy
1240 << " = metrics: " << init_metric_energy
1241 << " + extra terms: " << init_energy - init_metric_energy << endl;
1242 cout << " Final strain energy: " << fin_energy
1243 << " = metrics: " << fin_metric_energy
1244 << " + extra terms: " << fin_energy - fin_metric_energy << endl;
1245 cout << "The strain energy decreased by: "
1246 << (init_energy - fin_energy) * 100.0 / init_energy << " %." << endl;
1247
1248 // Visualize the final mesh and metric values.
1249 if (visualization)
1250 {
1251 char title[] = "Final metric values";
1252 vis_tmop_metric_s(mesh_poly_deg, *metric, *target_c, *mesh, title, 600);
1253 }
1254
1255 if (adapt_lim_const > 0.0 && visualization)
1256 {
1257 socketstream vis1, vis2;
1258 common::VisualizeField(vis1, "localhost", 19916, adapt_lim_gf0_1,
1259 "Zeta0(1) - final mesh", 600, 600, 300, 300);
1260 common::VisualizeField(vis2, "localhost", 19916, adapt_lim_gf0_2,
1261 "Zeta0(2) - final mesh", 600, 900, 300, 300);
1262 }
1263
1264 // Visualize the mesh displacement.
1265 if (visualization)
1266 {
1267 osockstream sock(19916, "localhost");
1268 sock << "solution\n";
1269 mesh->Print(sock);
1270 x0 -= x;
1271 x0.Save(sock);
1272 sock.send();
1273 sock << "window_title 'Displacements'\n"
1274 << "window_geometry "
1275 << 1200 << " " << 0 << " " << 600 << " " << 600 << "\n"
1276 << "keys jRmclA" << endl;
1277 }
1278
1279 delete S;
1280 delete S_prec;
1281 delete target_c2;
1282 delete metric2;
1283 delete metric_coeff1;
1284 delete adapt_lim_eval;
1285 delete target_c;
1286 delete hr_adapt_coeff;
1287 delete adapt_coeff;
1288 delete h_metric;
1289 delete metric;
1290 delete untangler_metric;
1291 delete fespace;
1292 delete fec;
1293 delete mesh;
1294
1295 return 0;
1296}
virtual void SetAnalyticTargetSpec(Coefficient *sspec, VectorCoefficient *vspec, TMOPMatrixCoefficient *mspec)
Definition tmop.cpp:2603
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
Definition array.cpp:69
int Size() const
Return the logical size of the array.
Definition array.hpp:192
@ GaussLobatto
Closed type.
Definition fe_base.hpp:36
Conjugate gradient method.
Definition solvers.hpp:627
A coefficient that is constant across space and time.
Jacobi-type diagonal smoother of a sparse matrix.
void SetPositiveDiagonal(bool pos_diag=true)
Replace diagonal entries with their absolute values. Relevant only with JacobiType::JACOBI.
Data type dense matrix using column-major storage.
Definition densemat.hpp:24
real_t Det() const
Definition densemat.cpp:496
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
Definition device.hpp:129
void Print(std::ostream &os=mfem::out)
Print the configuration of the MFEM virtual device object.
Definition device.cpp:319
virtual void SetSerialDiscreteTargetAspectRatio(const GridFunction &tspec_)
Definition tmop.cpp:2851
void SetMinSizeForTargets(real_t min_size_)
Definition tmop.hpp:1961
virtual void SetSerialDiscreteTargetSize(const GridFunction &tspec_)
Definition tmop.cpp:2831
void SetAdaptivityEvaluator(AdaptivityEvaluator *ae)
Definition tmop.hpp:1919
virtual void SetSerialDiscreteTargetOrientation(const GridFunction &tspec_)
Definition tmop.cpp:2861
real_t Weight()
Return the weight of the Jacobian matrix of the transformation at the currently set IntegrationPoint....
Definition eltrans.hpp:144
virtual int OrderJ() const =0
Return the order of the elements of the Jacobian of the transformation.
const DenseMatrix & Jacobian()
Return the Jacobian matrix of the transformation at the currently set IntegrationPoint,...
Definition eltrans.hpp:132
void SetIntPoint(const IntegrationPoint *ip)
Set the integration point ip that weights and Jacobians will be evaluated at.
Definition eltrans.hpp:106
int GetAttribute() const
Return element's attribute.
Definition element.hpp:58
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
Definition fe_coll.hpp:27
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition fespace.hpp:210
const FiniteElement * GetBE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th boundary fac...
Definition fespace.cpp:3906
DofTransformation * GetElementDofs(int elem, Array< int > &dofs) const
Returns indices of degrees of freedom of element 'elem'. The returned indices are offsets into an ldo...
Definition fespace.cpp:3538
int GetNDofs() const
Returns number of degrees of freedom. This is the number of Local Degrees of Freedom.
Definition fespace.hpp:821
int GetNBE() const
Returns number of boundary elements in the mesh.
Definition fespace.hpp:876
DofTransformation * GetBdrElementVDofs(int i, Array< int > &vdofs) const
Returns indices of degrees of freedom for i'th boundary element. The returned indices are offsets int...
Definition fespace.cpp:314
int DofToVDof(int dof, int vd, int ndofs=-1) const
Compute a single vdof corresponding to the index dof and the vector index vd.
Definition fespace.cpp:268
int GetDof() const
Returns the number of degrees of freedom in the finite element.
Definition fe_base.hpp:410
A general function coefficient.
const DenseMatrix & GetGeomToPerfGeomJac(int GeomType) const
Definition geom.hpp:102
Class for grid function - Vector with associated FE space.
Definition gridfunc.hpp:53
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
void SetFromTrueVector()
Shortcut for calling SetFromTrueDofs() with GetTrueVector() as argument.
Definition gridfunc.hpp:193
virtual void ProjectCoefficient(Coefficient &coeff, ProjectType type=ProjectType::DEFAULT)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
void ProjectGridFunction(const GridFunction &src)
Project the src GridFunction to this GridFunction, both of which must be on the same mesh.
Arbitrary order H1-conforming (continuous) finite elements.
Definition fe_coll.hpp:291
Class for integration point with weight.
Definition intrules.hpp:35
Class for an integration rule - an Array of IntegrationPoint.
Definition intrules.hpp:96
int GetNPoints() const
Returns the number of the points in the integration rule.
Definition intrules.hpp:255
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
Definition intrules.hpp:258
Container class for integration rules.
Definition intrules.hpp:430
const IntegrationRule & Get(int GeomType, int Order)
Returns an integration rule for given GeomType and Order.
void SetRelTol(real_t rtol)
Definition solvers.hpp:238
virtual void SetPrintLevel(int print_lvl)
Legacy method to set the level of verbosity of the solver output.
Definition solvers.cpp:76
void SetMaxIter(int max_it)
Definition solvers.hpp:240
void SetAbsTol(real_t atol)
Definition solvers.hpp:239
Arbitrary order "L2-conforming" discontinuous finite elements.
Definition fe_coll.hpp:369
MINRES method.
Definition solvers.hpp:742
void SetPreconditioner(Solver &pr) override
This should be called before SetOperator.
Definition solvers.hpp:754
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
const FiniteElementSpace * GetNodalFESpace() const
Definition mesh.cpp:7206
Geometry::Type GetTypicalElementGeometry() const
If the local mesh is not empty, return GetElementGeometry(0); otherwise, return a typical Geometry pr...
Definition mesh.cpp:1705
virtual void Print(std::ostream &os=mfem::out, const std::string &comments="") const
Print the mesh to the given stream using the default MFEM mesh format.
Definition mesh.hpp:2610
int GetNE() const
Returns number of elements.
Definition mesh.hpp:1390
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
real_t GetElementSize(int i, int type=0)
Get the size of the i-th element relative to the perfect reference element.
Definition mesh.cpp:111
void GetElementTransformation(int i, IsoparametricTransformation *ElTr) const
Builds the transformation defining the i-th element in ElTr. ElTr must be allocated in advance and wi...
Definition mesh.cpp:361
void SetNodalGridFunction(GridFunction *nodes, bool make_owner=false)
Definition mesh.cpp:7200
real_t GetElementVolume(int i)
Definition mesh.cpp:125
virtual void SetNodalFESpace(FiniteElementSpace *nfes)
Definition mesh.cpp:7153
int GetNBE() const
Returns number of boundary elements.
Definition mesh.hpp:1393
void EnsureNCMesh(bool simplices_nonconforming=false)
Definition mesh.cpp:11781
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Definition mesh.cpp:12125
Geometry::Type GetElementBaseGeometry(int i) const
Definition mesh.hpp:1569
void SetAdaptiveLinRtol(const int type=2, const real_t rtol0=0.5, const real_t rtol_max=0.9, const real_t alpha=0.5 *(1.0+sqrt(5.0)), const real_t gamma=1.0)
Enable adaptive linear solver relative tolerance algorithm.
Definition solvers.cpp:2172
Jacobi smoothing for a given bilinear form (no matrix necessary).
Definition solvers.hpp:422
void SetPositiveDiagonal(bool pos_diag=true)
Replace diagonal entries with their absolute values.
Definition solvers.hpp:458
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.
Base class for solvers.
Definition operator.hpp:855
void EnableLimiting(const GridFunction &n0, const GridFunction &dist, Coefficient &w0, TMOP_LimiterFunction *lfunc=NULL)
Adds the limiting term to the first integrator. Disables it for the rest.
Definition tmop.cpp:6117
void EnableNormalization(const GridFunction &x)
Normalization factor that considers all integrators in the combination.
Definition tmop.cpp:6258
void AddTMOPIntegrator(TMOP_Integrator *ti)
Adds a new TMOP_Integrator to the combination.
Definition tmop.hpp:2632
void AddGridFunctionForUpdate(GridFunction *gf)
Definition tmop_amr.hpp:252
void AddFESpaceForUpdate(FiniteElementSpace *fes)
Definition tmop_amr.hpp:253
void SetPreconditioner(Solver &pr) override
This should be called before SetOperator.
void EnsurePositiveDeterminantBound(Mesh &mesh, int ref_factor, int max_recursion_depth=0)
Ensure a positive lower bound for the Jacobian determinant in tensor-product elements during line-sea...
void SetIntegrationRules(IntegrationRules &irules, int order)
Prescribe a set of integration rules; relevant for mixed meshes.
void SetMinDetPtr(real_t *md_ptr)
2D barrier Shape+Size+Orientation (VOS) metric (polyconvex).
Definition tmop.hpp:1273
2D barrier Size+Skew (VQ) metric.
Definition tmop.hpp:1313
2D barrier Shape+Orientation (OS) metric (polyconvex).
Definition tmop.hpp:1335
2D barrier Shape+Size (VS) metric (polyconvex).
Definition tmop.hpp:1355
A TMOP integrator class based on any given TMOP_QualityMetric and TargetConstructor.
Definition tmop.hpp:1995
void SetExactActionFlag(bool flag_)
Flag to control if exact action of Integration is effected.
Definition tmop.hpp:2594
void SetCoefficient(Coefficient &w1)
Sets a scaling Coefficient for the quality metric term of the integrator.
Definition tmop.hpp:2372
void EnableFiniteDifferences(const GridFunction &x)
Enables FD-based approximation and computes dx.
Definition tmop.cpp:5910
void SetIntegrationRules(IntegrationRules &irules, int order)
Prescribe a set of integration rules; relevant for mixed meshes.
Definition tmop.hpp:2341
void IntegrateOverTarget(bool integ_over_target_)
Definition tmop.hpp:2357
2D non-barrier metric without a type.
Definition tmop.hpp:290
2D barrier Shape+Size (VS) metric (not polyconvex).
Definition tmop.hpp:425
2D barrier Shape+Size (VS) metric (not polyconvex).
Definition tmop.hpp:443
2D non-barrier Shape+Size+Orientation (VOS) metric (polyconvex).
Definition tmop.hpp:461
2D Shifted barrier form of shape metric (mu_2).
Definition tmop.hpp:492
2D barrier shape (S) metric (not polyconvex).
Definition tmop.hpp:587
2D barrier Shape+Orientation (OS) metric (polyconvex).
Definition tmop.hpp:675
2D compound barrier Shape+Size (VS) metric (balanced).
Definition tmop.hpp:692
2D compound barrier Shape+Size (VS) metric (balanced).
Definition tmop.hpp:713
2D barrier Shape+Size+Orientation (VOS) metric (polyconvex).
Definition tmop.hpp:734
3D barrier Shape (S) metric, well-posed (polyconvex & invex).
Definition tmop.hpp:794
3D barrier Shape (S) metric, well-posed (polyconvex & invex).
Definition tmop.hpp:815
3D barrier Shape (S) metric, well-posed (polyconvex & invex).
Definition tmop.hpp:836
3D barrier Shape (S) metric, well-posed (polyconvex & invex).
Definition tmop.hpp:857
3D Shape (S) metric, untangling version of 303.
Definition tmop.hpp:899
3D Size (V) metric.
Definition tmop.hpp:920
3D Size (V) metric.
Definition tmop.hpp:938
3D barrier Shape+Size (VS) metric, well-posed (invex).
Definition tmop.hpp:980
3D barrier Shape+Size (VS) metric, well-posed (invex).
Definition tmop.hpp:1001
3D barrier Shape+Size (VS) metric, well-posed (invex).
Definition tmop.hpp:1022
3D compound barrier Shape+Size (VS) metric (polyconvex, balanced).
Definition tmop.hpp:1043
3D compound barrier Shape+Size (VS) metric (polyconvex).
Definition tmop.hpp:1064
3D barrier Shape+Size (VS) metric, well-posed (polyconvex).
Definition tmop.hpp:1085
3D barrier Shape+Size (VS) metric, well-posed (polyconvex).
Definition tmop.hpp:1105
3D compound barrier Shape+Size (VS) metric (polyconvex, balanced).
Definition tmop.hpp:1127
3D barrier Shape+Size (VS) metric, well-posed (polyconvex).
Definition tmop.hpp:1168
3D non-barrier Shape (S) metric.
Definition tmop.hpp:1211
Abstract class for local mesh quality metrics in the target-matrix optimization paradigm (TMOP) by P....
Definition tmop.hpp:28
Base class representing target-matrix construction algorithms for mesh optimization via the target-ma...
Definition tmop.hpp:1586
void SetVolumeScale(real_t vol_scale)
Used by target type IDEAL_SHAPE_EQUAL_SIZE. The default volume scale is 1.
Definition tmop.hpp:1676
void SetNodes(const GridFunction &n)
Set the nodes to be used in the target-matrix construction.
Definition tmop.hpp:1670
TargetType
Target-matrix construction algorithms supported by this class.
Definition tmop.hpp:1590
A general vector function coefficient.
Vector data type.
Definition vector.hpp:82
void Randomize(int seed=0)
Set random values in the vector.
Definition vector.cpp:955
virtual real_t * HostReadWrite()
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), false).
Definition vector.hpp:540
real_t Min() const
Returns the minimal element of the vector.
Definition vector.cpp:1154
int dim
Definition ex24.cpp:53
@ disc
Definition ex25.cpp:151
int main()
real_t a
Definition lissajous.cpp:41
real_t adapt_lim_fun(const Vector &x)
IntegrationRules IntRulesCU(0, Quadrature1D::ClosedUniform)
real_t weight_fun(const Vector &x)
real_t adapt_lim_fun2(const Vector &x)
real_t material_indicator_2d(const Vector &x)
IntegrationRules IntRulesLo(0, Quadrature1D::GaussLobatto)
void ConstructSizeGF(GridFunction &size)
real_t discrete_ori_2d(const Vector &x)
void discrete_aspr_3d(const Vector &x, Vector &v)
void VisualizeMesh(socketstream &sock, const char *vishost, int visport, Mesh &mesh, const char *title, int x, int y, int w, int h, const char *keys)
void DiffuseField(ParGridFunction &field, int smooth_steps)
void VisualizeField(socketstream &sock, const char *vishost, int visport, GridFunction &gf, const char *title, int x, int y, int w, int h, const char *keys, bool vec)
Geometry Geometries
Definition fe.cpp:49
AssemblyLevel
Enumeration defining the assembly level for bilinear and nonlinear form classes derived from Operator...
void vis_tmop_metric_s(int order, TMOP_QualityMetric &qm, const TargetConstructor &tc, Mesh &mesh, char *title, int position)
float real_t
Definition config.hpp:46
constexpr real_t infinity()
Define a shortcut for std::numeric_limits<double>::infinity()
Definition vector.hpp:47
IntegrationRules IntRules(0, Quadrature1D::GaussLegendre)
A global object with all integration rules (defined in intrules.cpp)
Definition intrules.hpp:549
STL namespace.
Settings for the output behavior of the IterativeSolver.
Definition solvers.hpp:103