MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
pdiffusion.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// MFEM ultraweak DPG parallel example for diffusion
13//
14// Compile with: make pdiffusion
15//
16// Sample runs
17// mpirun -np 4 pdiffusion -m ../../data/inline-quad.mesh -o 3 -sref 1 -pref 2 -theta 0.0 -prob 0
18// mpirun -np 4 pdiffusion -m ../../data/inline-quad.mesh -o 3 -sref 1 -pref 2 -theta 0.0 -prob 0 -pmg
19// mpirun -np 4 pdiffusion -m ../../data/inline-hex.mesh -o 2 -sref 0 -pref 1 -theta 0.0 -prob 0 -sc
20// mpirun -np 4 pdiffusion -m ../../data/beam-tet.mesh -o 3 -sref 0 -pref 2 -theta 0.0 -prob 0 -sc
21
22// L-shape runs
23// Note: uniform ref are expected to give sub-optimal rate for the L-shape problem (rate = 2/3)
24// mpirun -np 4 pdiffusion -o 2 -sref 1 -pref 5 -theta 0.0 -prob 1
25
26// L-shape AMR runs
27// mpirun -np 4 pdiffusion -o 1 -sref 1 -pref 10 -theta 0.8 -prob 1
28// mpirun -np 4 pdiffusion -o 2 -sref 1 -pref 8 -theta 0.75 -prob 1 -sc
29// mpirun -np 4 pdiffusion -o 3 -sref 1 -pref 6 -theta 0.75 -prob 1 -sc -do 2
30
31// Description:
32// This example code demonstrates the use of MFEM to define and solve
33// the "ultraweak" (UW) DPG formulation for the Poisson problem in parallel
34
35// - Δ u = f, in Ω
36// u = u₀, on ∂Ω
37//
38// It solves two kinds of problems
39// a) A manufactured solution problem where u_exact = sin(π * (x + y + z)).
40// This example computes and prints out convergence rates for the L2 error.
41// b) The L-shape benchmark problem with AMR. The AMR process is driven by the
42// DPG built-in residual indicator.
43
44// The DPG UW deals with the First Order System
45// ∇ u - σ = 0, in Ω
46// - ∇⋅σ = f, in Ω
47// u = u₀, in ∂Ω
48
49// Ultraweak-DPG is obtained by integration by parts of both equations and the
50// introduction of trace unknowns on the mesh skeleton
51
52// u ∈ L²(Ω), σ ∈ (L²(Ω))ᵈⁱᵐ
53// û ∈ H^1/2, σ̂ ∈ H^-1/2
54// -(u , ∇⋅τ) + < û, τ⋅n> - (σ , τ) = 0, ∀ τ ∈ H(div,Ω)
55// (σ , ∇ v) - < σ̂, v > = (f,v) ∀ v ∈ H¹(Ω)
56// û = u₀ on ∂Ω
57
58// Note:
59// û := u and σ̂ := -σ on the mesh skeleton
60
61// -------------------------------------------------------------
62// | | u | σ | û | σ̂ | RHS |
63// -------------------------------------------------------------
64// | τ | -(u,∇⋅τ) | -(σ,τ) | < û, τ⋅n> | | 0 |
65// | | | | | | |
66// | v | | (σ,∇ v) | | -<σ̂,v> | (f,v) |
67
68// where (τ,v) ∈ H(div,Ω) × H¹(Ω)
69
70// For more information see https://doi.org/10.1007/978-3-319-01818-8_6
71
72#include "mfem.hpp"
73#include "util/pweakform.hpp"
76#include <fstream>
77#include <iostream>
78
79using namespace std;
80using namespace mfem;
81using namespace mfem::common;
82
88
89static const char *enum_str[] =
90{
91 "manufactured",
92 "lshape"
93};
94
96
97real_t exact_u(const Vector & X);
98void exact_gradu(const Vector & X, Vector &gradu);
100void exact_sigma(const Vector & X, Vector & sigma);
101real_t exact_hatu(const Vector & X);
102void exact_hatsigma(const Vector & X, Vector & hatsigma);
103real_t f_exact(const Vector & X);
104
105int main(int argc, char *argv[])
106{
107 // 0. Initialize MPI and HYPRE.
108 Mpi::Init();
109 int myid = Mpi::WorldRank();
110 Hypre::Init();
111
112 // 1. Parse command-line options.
113 const char *mesh_file = "../../data/inline-quad.mesh";
114 int order = 1;
115 int delta_order = 1;
116 int sref = 0; // initial uniform mesh refinements
117 int pref = 0; // parallel mesh refinements for AMR
118 int iprob = 0;
119 bool pmg = false;
120 int pmg_levels = -1;
121 real_t relax_factor = 2.0/3;
122 bool static_cond = false;
123 real_t theta = 0.7;
124 bool visualization = true;
125 int visport = 19916;
126 bool paraview = false;
127
128 OptionsParser args(argc, argv);
129 args.AddOption(&mesh_file, "-m", "--mesh",
130 "Mesh file to use.");
131 args.AddOption(&order, "-o", "--order",
132 "Finite element order (polynomial degree).");
133 args.AddOption(&delta_order, "-do", "--delta_order",
134 "Order enrichment for DPG test space.");
135 args.AddOption(&sref, "-sref", "--num-serial-refinements",
136 "Number of initial serial uniform refinements");
137 args.AddOption(&pref, "-pref", "--num-parallel-refinements",
138 "Number of AMR refinements");
139 args.AddOption(&theta, "-theta", "--theta-factor",
140 "Refinement factor (0 indicates uniform refinements) ");
141 args.AddOption(&iprob, "-prob", "--problem", "Problem case"
142 " 0: manufactured, 1: L-shape");
143 args.AddOption(&static_cond, "-sc", "--static-condensation", "-no-sc",
144 "--no-static-condensation", "Enable static condensation.");
145 args.AddOption(&pmg, "-pmg", "--p-refinement-multigrid", "-no-pmg",
146 "--no-p-refinement-multigrid", "Enable P-Refinement Multigrid.");
147 args.AddOption(&pmg_levels, "-pmgl","--p-refinement-multigrid-levels",
148 "Number of levels for P-Refinement Multigrid.");
149 args.AddOption(&relax_factor, "-rf", "--relaxation-factor",
150 "Relaxation factor for the p-multigrid smoother.");
151 args.AddOption(&visualization, "-vis", "--visualization", "-no-vis",
152 "--no-visualization",
153 "Enable or disable GLVis visualization.");
154 args.AddOption(&paraview, "-paraview", "--paraview", "-no-paraview",
155 "--no-paraview",
156 "Enable or disable ParaView visualization.");
157 args.AddOption(&visport, "-p", "--send-port", "Socket for GLVis.");
158 args.Parse();
159 if (!args.Good())
160 {
161 if (myid == 0)
162 {
163 args.PrintUsage(cout);
164 }
165 return 1;
166 }
167
168 if (iprob > 1) { iprob = 1; }
169 prob = (prob_type)iprob;
170
171 if (prob == prob_type::lshape)
172 {
173 mesh_file = "../../data/l-shape.mesh";
174 }
175
176 if (myid == 0)
177 {
178 args.PrintOptions(cout);
179 }
180
181 Mesh mesh(mesh_file, 1, 1);
182 int dim = mesh.Dimension();
183 MFEM_VERIFY(dim > 1, "Dimension = 1 is not supported in this example");
184
185 if (prob == prob_type::lshape)
186 {
187 /** rotate mesh to be consistent with l-shape benchmark problem
188 See https://doi.org/10.1016/j.amc.2013.05.068 */
189 mesh.EnsureNodes();
190 GridFunction *nodes = mesh.GetNodes();
191 int size = nodes->Size()/2;
192 for (int i = 0; i<size; i++)
193 {
194 real_t x = (*nodes)[2*i];
195 (*nodes)[2*i] = 2*(*nodes)[2*i+1]-1;
196 (*nodes)[2*i+1] = -2*x+1;
197 }
198 }
199
200 for (int i = 0; i<sref; i++)
201 {
202 mesh.UniformRefinement();
203 }
204
205 mesh.EnsureNCMesh();
206
207 ParMesh pmesh(MPI_COMM_WORLD, mesh);
208 mesh.Clear();
209
210 // Define spaces
211 enum TrialSpace
212 {
213 u_space = 0,
214 sigma_space = 1,
215 hatu_space = 2,
216 hatsigma_space = 3
217 };
218 enum TestSpace
219 {
220 tau_space = 0,
221 v_space = 1
222 };
223 // L2 space for u
224 FiniteElementCollection *u_fec = new L2_FECollection(order-1,dim);
225 ParFiniteElementSpace *u_fes = new ParFiniteElementSpace(&pmesh,u_fec);
226
227 // Vector L2 space for σ
228 FiniteElementCollection *sigma_fec = new L2_FECollection(order-1,dim);
229 ParFiniteElementSpace *sigma_fes = new ParFiniteElementSpace(&pmesh,sigma_fec,
230 dim);
231
232 // H^1/2 space for û
233 FiniteElementCollection * hatu_fec = new H1_Trace_FECollection(order,dim);
234 ParFiniteElementSpace *hatu_fes = new ParFiniteElementSpace(&pmesh,hatu_fec);
235
236 // H^-1/2 space for σ̂
237 FiniteElementCollection * hatsigma_fec = new RT_Trace_FECollection(order-1,dim);
238 ParFiniteElementSpace *hatsigma_fes = new ParFiniteElementSpace(&pmesh,
239 hatsigma_fec);
240
241 // testspace fe collections
242 int test_order = order+delta_order;
243 FiniteElementCollection * tau_fec = new RT_FECollection(test_order-1, dim);
244 FiniteElementCollection * v_fec = new H1_FECollection(test_order, dim);
245
248
249 trial_fes.Append(u_fes);
250 trial_fes.Append(sigma_fes);
251 trial_fes.Append(hatu_fes);
252 trial_fes.Append(hatsigma_fes);
253 test_fec.Append(tau_fec);
254 test_fec.Append(v_fec);
255
256 // Required coefficients for the weak formulation
257 ConstantCoefficient one(1.0);
258 ConstantCoefficient negone(-1.0);
259 FunctionCoefficient f(f_exact); // rhs for the manufactured solution problem
260
261 // Required coefficients for the exact solutions
265
266 ParDPGWeakForm * a = new ParDPGWeakForm(trial_fes,test_fec);
267 a->StoreMatrices(true); // this is needed for estimation of residual
268
269 // -(u,∇⋅τ)
270 a->AddTrialIntegrator(new MixedScalarWeakGradientIntegrator(one),
271 TrialSpace::u_space,TestSpace::tau_space);
272
273 // -(σ,τ)
274 a->AddTrialIntegrator(new TransposeIntegrator(new VectorFEMassIntegrator(
275 negone)), TrialSpace::sigma_space, TestSpace::tau_space);
276
277 // (σ,∇ v)
278 a->AddTrialIntegrator(new TransposeIntegrator(new GradientIntegrator(one)),
279 TrialSpace::sigma_space,TestSpace::v_space);
280
281 // <û,τ⋅n>
282 a->AddTrialIntegrator(new NormalTraceIntegrator,
283 TrialSpace::hatu_space,TestSpace::tau_space);
284
285 // -<σ̂,v> (sign is included in σ̂)
286 a->AddTrialIntegrator(new TraceIntegrator,
287 TrialSpace::hatsigma_space, TestSpace::v_space);
288
289 // test integrators (space-induced norm for H(div) × H1)
290 // (∇⋅τ,∇⋅δτ)
291 a->AddTestIntegrator(new DivDivIntegrator(one),
292 TestSpace::tau_space, TestSpace::tau_space);
293 // (τ,δτ)
294 a->AddTestIntegrator(new VectorFEMassIntegrator(one),
295 TestSpace::tau_space, TestSpace::tau_space);
296 // (∇v,∇δv)
297 a->AddTestIntegrator(new DiffusionIntegrator(one),
298 TestSpace::v_space, TestSpace::v_space);
299 // (v,δv)
300 a->AddTestIntegrator(new MassIntegrator(one),
301 TestSpace::v_space, TestSpace::v_space);
302
303 // RHS
304 if (prob == prob_type::manufactured)
305 {
306 a->AddDomainLFIntegrator(new DomainLFIntegrator(f),TestSpace::v_space);
307 }
308
309 // GridFunction for Dirichlet bdr data
310 ParGridFunction hatu_gf;
311
312 // Visualization streams
313 socketstream u_out;
314 socketstream sigma_out;
315
316 if (myid == 0)
317 {
318 std::cout << "\n Ref |"
319 << " Dofs |"
320 << " L2 Error |"
321 << " Rate |"
322 << " Residual |"
323 << " Rate |"
324 << " PCG it |" << endl;
325 std::cout << std::string(72,'-') << endl;
326 }
327
328 Array<int> elements_to_refine; // for AMR
329 real_t err0 = 0.;
330 int dof0=0.;
331 real_t res0=0.0;
332
333 ParGridFunction u_gf(u_fes);
334 ParGridFunction sigma_gf(sigma_fes);
335 u_gf = 0.0;
336 sigma_gf = 0.0;
337
338 ParaViewDataCollection * paraview_dc = nullptr;
339
340 if (paraview)
341 {
342 paraview_dc = new ParaViewDataCollection(enum_str[prob], &pmesh);
343 paraview_dc->SetPrefixPath("ParaView/Diffusion");
344 paraview_dc->SetLevelsOfDetail(order);
345 paraview_dc->SetCycle(0);
346 paraview_dc->SetDataFormat(VTKFormat::BINARY);
347 paraview_dc->SetHighOrderOutput(true);
348 paraview_dc->SetTime(0.0); // set the time
349 paraview_dc->RegisterField("u",&u_gf);
350 paraview_dc->RegisterField("sigma",&sigma_gf);
351 }
352
353 if (static_cond) { a->EnableStaticCondensation(); }
354 for (int it = 0; it<=pref; it++)
355 {
356 a->Assemble();
357
359 Array<int> ess_bdr;
360 if (pmesh.bdr_attributes.Size())
361 {
362 ess_bdr.SetSize(pmesh.bdr_attributes.Max());
363 ess_bdr = 1;
364 hatu_fes->GetEssentialTrueDofs(ess_bdr, ess_tdof_list);
365 }
366
367 // shift the ess_tdofs
368 for (int i = 0; i < ess_tdof_list.Size(); i++)
369 {
370 ess_tdof_list[i] += u_fes->GetTrueVSize() + sigma_fes->GetTrueVSize();
371 }
372
373 Array<int> offsets(5);
374 offsets[0] = 0;
375 offsets[1] = u_fes->GetVSize();
376 offsets[2] = sigma_fes->GetVSize();
377 offsets[3] = hatu_fes->GetVSize();
378 offsets[4] = hatsigma_fes->GetVSize();
379 offsets.PartialSum();
380 BlockVector x(offsets);
381 x = 0.0;
382 hatu_gf.MakeRef(hatu_fes,x.GetBlock(2),0);
383 hatu_gf.ProjectBdrCoefficient(uex,ess_bdr);
384
385 Vector X,B;
386 OperatorPtr Ah;
388
389 BlockOperator * A = Ah.As<BlockOperator>();
390
391 Solver * preconditioner = nullptr;
393 if (static_cond)
394 {
395 a->GetTraceFESpaces(prec_fes);
396 }
397 else
398 {
399 prec_fes = trial_fes;
400 }
401 if (pmg)
402 {
403#ifdef MFEM_USE_MUMPS
404 bool mumps_coarse_solver = true;
405#else
406 bool mumps_coarse_solver = false;
407#endif
408 std::vector<Array<int>> ess_bdr_marker(prec_fes.Size());
409 for (int b = 0; b<prec_fes.Size(); b++)
410 {
411 ess_bdr_marker[b].SetSize(pmesh.bdr_attributes.Max());
412 int ess_block = (static_cond) ? 0 : 2;
413 if (b == ess_block)
414 {
415 ess_bdr_marker[b] = ess_bdr;
416 }
417 else
418 {
419 ess_bdr_marker[b] = 0;
420 }
421 }
422 preconditioner = new PRefinementMultigrid(prec_fes, ess_bdr_marker, *A,
423 pmg_levels, relax_factor, mumps_coarse_solver);
424 }
425 else
426 {
427 preconditioner = new BlockDiagonalPreconditioner(A->RowOffsets());
428 auto block_diag = dynamic_cast<BlockDiagonalPreconditioner*>(preconditioner);
429 block_diag->owns_blocks = 1;
430 for (int i = 0; i<A->NumRowBlocks(); i++)
431 {
432 auto prec = MakeFESpaceDefaultSolver(prec_fes[i],0);
433 prec->SetOperator(A->GetBlock(i,i));
434 block_diag->SetDiagonalBlock(i,prec);
435 }
436 }
437
438 CGSolver cg(MPI_COMM_WORLD);
439 cg.SetRelTol(1e-12);
440 cg.SetMaxIter(2000);
441 cg.SetPrintLevel(0);
442 cg.SetOperator(*A);
443 cg.SetPreconditioner(*preconditioner);
444 cg.Mult(B, X);
445
446 delete preconditioner;
447
448 a->RecoverFEMSolution(X,x);
449
450 Vector & residuals = a->ComputeResidual(x);
451
452 real_t residual = residuals.Norml2();
453
454 real_t maxresidual = residuals.Max();
455 real_t globalresidual = residual * residual;
456
457 MPI_Allreduce(MPI_IN_PLACE, &maxresidual, 1, MPITypeMap<real_t>::mpi_type,
458 MPI_MAX, MPI_COMM_WORLD);
459 MPI_Allreduce(MPI_IN_PLACE, &globalresidual, 1,
460 MPITypeMap<real_t>::mpi_type, MPI_SUM, MPI_COMM_WORLD);
461
462 globalresidual = sqrt(globalresidual);
463
464 u_gf.MakeRef(u_fes,x.GetBlock(0),0);
465 sigma_gf.MakeRef(sigma_fes,x.GetBlock(1),0);
466
467 int dofs = u_fes->GlobalTrueVSize() + sigma_fes->GlobalTrueVSize()
468 + hatu_fes->GlobalTrueVSize() + hatsigma_fes->GlobalTrueVSize();
469
470 real_t u_err = u_gf.ComputeL2Error(uex);
471 real_t sigma_err = sigma_gf.ComputeL2Error(sigmaex);
472 real_t L2Error = sqrt(u_err*u_err + sigma_err*sigma_err);
473 real_t rate_err = (it) ? dim*log(err0/L2Error)/log((real_t)dof0/dofs) : 0.0;
474 real_t rate_res = (it) ? dim*log(res0/globalresidual)/log((
475 real_t)dof0/dofs) : 0.0;
476 err0 = L2Error;
477 res0 = globalresidual;
478 dof0 = dofs;
479
480 if (myid == 0)
481 {
482 std::ios oldState(nullptr);
483 oldState.copyfmt(std::cout);
484 std::cout << std::right << std::setw(5) << it << " | "
485 << std::setw(10) << dof0 << " | "
486 << std::setprecision(3)
487 << std::setw(10) << std::scientific << err0 << " | "
488 << std::setprecision(2)
489 << std::setw(6) << std::fixed << rate_err << " | "
490 << std::setprecision(3)
491 << std::setw(10) << std::scientific << res0 << " | "
492 << std::setprecision(2)
493 << std::setw(6) << std::fixed << rate_res << " | "
494 << std::setw(6) << std::fixed << cg.GetNumIterations() << " | "
495 << std::endl;
496 std::cout.copyfmt(oldState);
497 }
498
499 if (visualization)
500 {
501 const char * keys = (it == 0 && dim == 2) ? "jRcm\n" : nullptr;
502 char vishost[] = "localhost";
503
504 VisualizeField(u_out,vishost,visport,u_gf,
505 "Numerical u", 0,0,500,500,keys);
506 VisualizeField(sigma_out,vishost,visport,sigma_gf,
507 "Numerical flux", 500,0,500,500,keys);
508 }
509
510 if (paraview)
511 {
512 paraview_dc->SetCycle(it);
513 paraview_dc->SetTime((real_t)it);
514 paraview_dc->Save();
515 }
516
517 if (it == pref) { break; }
518
519 elements_to_refine.SetSize(0);
520 for (int iel = 0; iel<pmesh.GetNE(); iel++)
521 {
522 if (residuals[iel] >= theta * maxresidual)
523 {
524 elements_to_refine.Append(iel);
525 }
526 }
527
528 pmesh.GeneralRefinement(elements_to_refine);
529
530 for (int i =0; i<trial_fes.Size(); i++)
531 {
532 trial_fes[i]->Update(false);
533 }
534 a->Update();
535 }
536
537 if (paraview)
538 {
539 delete paraview_dc;
540 }
541
542 delete a;
543 delete tau_fec;
544 delete v_fec;
545 delete hatsigma_fes;
546 delete hatsigma_fec;
547 delete hatu_fes;
548 delete hatu_fec;
549 delete sigma_fec;
550 delete sigma_fes;
551 delete u_fec;
552 delete u_fes;
553
554 return 0;
555}
556
558{
559 switch (prob)
560 {
562 {
563 real_t x = X[0];
564 real_t y = X[1];
565 real_t r = sqrt(x*x + y*y);
566 real_t alpha = 2./3.;
567 real_t phi = atan2(y,x);
568 if (phi < 0) { phi += 2*M_PI; }
569 return pow(r,alpha) * sin(alpha * phi);
570 }
571 break;
572 default:
573 {
574 real_t alpha = M_PI * (X.Sum());
575 return sin(alpha);
576 }
577 break;
578 }
579}
580
581void exact_gradu(const Vector & X, Vector & du)
582{
583 du.SetSize(X.Size());
584 switch (prob)
585 {
587 {
588 real_t x = X[0];
589 real_t y = X[1];
590 real_t r = sqrt(x*x + y*y);
591 real_t alpha = 2./3.;
592 real_t phi = atan2(y,x);
593 if (phi < 0) { phi += 2*M_PI; }
594
595 real_t r_x = x/r;
596 real_t r_y = y/r;
597 real_t phi_x = - y / (r*r);
598 real_t phi_y = x / (r*r);
599 real_t beta = alpha * pow(r,alpha - 1.);
600 du[0] = beta*(r_x * sin(alpha*phi) + r * phi_x * cos(alpha*phi));
601 du[1] = beta*(r_y * sin(alpha*phi) + r * phi_y * cos(alpha*phi));
602 }
603 break;
604 default:
605 {
606 real_t alpha = M_PI * (X.Sum());
607 du.SetSize(X.Size());
608 for (int i = 0; i<du.Size(); i++)
609 {
610 du[i] = M_PI * cos(alpha);
611 }
612 }
613 break;
614 }
615}
616
618{
619 switch (prob)
620 {
621 case prob_type::manufactured:
622 {
623 real_t alpha = M_PI * (X.Sum());
624 real_t u = sin(alpha);
625 return - M_PI*M_PI * u * X.Size();
626 }
627 break;
628 default:
629 MFEM_ABORT("Should be unreachable");
630 return 1;
631 break;
632 }
633}
634
635void exact_sigma(const Vector & X, Vector & sigma)
636{
637 // σ = ∇ u
639}
640
642{
643 return exact_u(X);
644}
645
646void exact_hatsigma(const Vector & X, Vector & hatsigma)
647{
648 exact_sigma(X,hatsigma);
649 hatsigma *= -1.;
650}
651
653{
654 MFEM_VERIFY(prob!=prob_type::lshape,
655 "f_exact should not be called for l-shape benchmark problem, i.e., f = 0")
656 return -exact_laplacian_u(X);
657}
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
Definition array.cpp:69
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
Definition array.hpp:869
int Size() const
Return the logical size of the array.
Definition array.hpp:192
void PartialSum()
Fill the entries of the array with the cumulative sum of the entries.
Definition array.cpp:104
int Append(const T &el)
Append element 'el' to array, resize if necessary.
Definition array.hpp:941
A class to handle Block diagonal preconditioners in a matrix-free implementation.
A class to handle Block systems in a matrix-free implementation.
Array< int > & RowOffsets()
Return the row offsets for block starts.
Operator & GetBlock(int i, int j)
Return a reference to block i,j.
int NumRowBlocks() const
Return the number of row blocks.
A class to handle Vectors in a block fashion.
Vector & GetBlock(int i)
Get the i-th vector in the block.
Conjugate gradient method.
Definition solvers.hpp:627
A coefficient that is constant across space and time.
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection.
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
void SetTime(real_t t)
Set physical time (for time-dependent simulations)
void SetPrefixPath(const std::string &prefix)
Set the path where the DataCollection will be saved.
for Raviart-Thomas elements
Class for domain integration .
Definition lininteg.hpp:108
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
Definition fe_coll.hpp:27
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
Definition fespace.hpp:824
A general function coefficient.
Class for grid function - Vector with associated FE space.
Definition gridfunc.hpp:53
Arbitrary order H1-conforming (continuous) finite elements.
Definition fe_coll.hpp:291
Arbitrary order "H^{1/2}-conforming" trace finite elements defined on the interface between mesh elem...
Definition fe_coll.hpp:357
static void Init()
Initialize hypre by calling HYPRE_Init() and set default options. After calling Hypre::Init(),...
Definition hypre.cpp:33
Arbitrary order "L2-conforming" discontinuous finite elements.
Definition fe_coll.hpp:369
Mesh data type.
Definition mesh.hpp:67
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
Definition mesh.hpp:309
void GeneralRefinement(const Array< Refinement > &refinements, int nonconforming=-1, int nc_limit=0)
Definition mesh.cpp:11713
void EnsureNodes()
Make sure that the mesh has valid nodes, i.e. its geometry is described by a vector finite element gr...
Definition mesh.cpp:7159
void Clear()
Clear the contents of the Mesh.
Definition mesh.hpp:835
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
void GetNodes(Vector &node_coord) const
Definition mesh.cpp:10112
void EnsureNCMesh(bool simplices_nonconforming=false)
Definition mesh.cpp:11781
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Definition mesh.cpp:12125
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).
Pointer to an Operator of a specified type.
Definition handle.hpp:34
OpType * As() const
Return the Operator pointer statically cast to a specified OpType. Similar to the method Get().
Definition handle.hpp:104
void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, Vector &b, Operator *&A, Vector &X, Vector &B, int copy_interior=0)
Form a constrained linear system using a matrix-free approach.
Definition operator.cpp:129
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.
Creates a p-refinement multigrid preconditioner for a given set of parallel finite element spaces and...
Class representing the parallel weak formulation. (Convenient for DPG Equations)
Definition pweakform.hpp:26
Abstract parallel finite element space.
Definition pfespace.hpp:31
void GetEssentialTrueDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_tdof_list, int component=-1) const override
HYPRE_BigInt GlobalTrueVSize() const
Definition pfespace.hpp:361
int GetTrueVSize() const override
Return the number of local vector true dofs.
Definition pfespace.hpp:365
Class for parallel grid function.
Definition pgridfunc.hpp:50
real_t ComputeL2Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL, const Array< int > *elems=NULL) const override
Returns ||u_ex - u_h||_L2 in parallel for H1 or L2 elements.
void ProjectBdrCoefficient(Coefficient *coeff[], VectorCoefficient *vcoeff, const Array< int > &attr)
void MakeRef(FiniteElementSpace *f, real_t *v) override
Make the ParGridFunction reference external data on a new FiniteElementSpace.
Class for parallel meshes.
Definition pmesh.hpp:35
void SetLevelsOfDetail(int levels_of_detail_)
Set the refinement level.
void SetHighOrderOutput(bool high_order_output_)
Sets whether or not to output the data as high-order elements (false by default).
void SetDataFormat(VTKFormat fmt)
Set the data format for the ParaView output files.
Writer for ParaView visualization (PVD and VTU format)
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
Definition fe_coll.hpp:430
Arbitrary order "H^{-1/2}-conforming" face finite elements defined on the interface between mesh elem...
Definition fe_coll.hpp:492
Base class for solvers.
Definition operator.hpp:855
A general vector function coefficient.
Vector data type.
Definition vector.hpp:82
real_t Norml2() const
Returns the l2 norm of the vector.
Definition vector.cpp:968
real_t Max() const
Returns the maximal element of the vector.
Definition vector.cpp:1200
int Size() const
Returns the size of the vector.
Definition vector.hpp:234
real_t Sum() const
Return the sum of the vector entries.
Definition vector.cpp:1246
void SetSize(int s)
Resize the vector to size s.
Definition vector.hpp:633
const int * ess_tdof_list
real_t sigma(const Vector &x)
Definition maxwell.cpp:91
const real_t alpha
Definition ex15.cpp:369
int dim
Definition ex24.cpp:53
prob_type
Definition ex25.cpp:149
@ lshape
Definition ex25.cpp:152
int main()
real_t b
Definition lissajous.cpp:42
real_t a
Definition lissajous.cpp:41
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 u(const Vector &xvec)
Definition lor_mms.hpp:22
Solver * MakeFESpaceDefaultSolver(const ParFiniteElementSpace *pfespace, int print_level)
Creates a default solver for a given parallel FE space. The default solvers are the following:
float real_t
Definition config.hpp:46
std::function< real_t(const Vector &)> f(real_t mass_coeff)
Definition lor_mms.hpp:30
const char vishost[]
STL namespace.
void exact_gradu(const Vector &X, Vector &gradu)
real_t exact_hatu(const Vector &X)
real_t exact_laplacian_u(const Vector &X)
real_t exact_u(const Vector &X)
void exact_sigma(const Vector &X, Vector &sigma)
void exact_hatsigma(const Vector &X, Vector &hatsigma)
prob_type prob
prob_type
@ manufactured
@ lshape
real_t f_exact(const Vector &X)
Helper struct to convert a C++ type to an MPI type.
std::array< int, NCMesh::MaxFaceNodes > nodes