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