MFEM  v4.3.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
pgridfunc.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2021, 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 #include "../config/config.hpp"
13 
14 #ifdef MFEM_USE_MPI
15 
16 #include "fem.hpp"
17 #include <iostream>
18 #include <limits>
19 #include "../general/forall.hpp"
20 using namespace std;
21 
22 namespace mfem
23 {
24 
25 ParGridFunction::ParGridFunction(ParFiniteElementSpace *pf, GridFunction *gf)
26 {
27  fes = pfes = pf;
28  SetDataAndSize(gf->GetData(), gf->Size());
29 }
30 
31 ParGridFunction::ParGridFunction(ParFiniteElementSpace *pf, HypreParVector *tv)
32  : GridFunction(pf), pfes(pf)
33 {
34  Distribute(tv);
35 }
36 
38  const int *partitioning)
39 {
40  const FiniteElementSpace *glob_fes = gf->FESpace();
41  // duplicate the FiniteElementCollection from 'gf'
42  fec = FiniteElementCollection::New(glob_fes->FEColl()->Name());
43  // create a local ParFiniteElementSpace from the global one:
44  fes = pfes = new ParFiniteElementSpace(pmesh, glob_fes, partitioning, fec);
45  SetSize(pfes->GetVSize());
46 
47  if (partitioning)
48  {
49  // Assumption: the map "local element id" -> "global element id" is
50  // increasing, i.e. the local numbering preserves the element order from
51  // the global numbering.
52  Array<int> gvdofs, lvdofs;
53  Vector lnodes;
54  int element_counter = 0;
55  const int MyRank = pfes->GetMyRank();
56  const int glob_ne = glob_fes->GetNE();
57  for (int i = 0; i < glob_ne; i++)
58  {
59  if (partitioning[i] == MyRank)
60  {
61  pfes->GetElementVDofs(element_counter, lvdofs);
62  glob_fes->GetElementVDofs(i, gvdofs);
63  gf->GetSubVector(gvdofs, lnodes);
64  SetSubVector(lvdofs, lnodes);
65  element_counter++;
66  }
67  }
68  }
69 }
70 
71 ParGridFunction::ParGridFunction(ParMesh *pmesh, std::istream &input)
72  : GridFunction(pmesh, input)
73 {
74  // Convert the FiniteElementSpace, fes, to a ParFiniteElementSpace:
75  pfes = new ParFiniteElementSpace(pmesh, fec, fes->GetVDim(),
76  fes->GetOrdering());
77  delete fes;
78  fes = pfes;
79 }
80 
82 {
85 }
86 
88 {
91  pfes = dynamic_cast<ParFiniteElementSpace*>(f);
92  MFEM_ASSERT(pfes != NULL, "not a ParFiniteElementSpace");
93 }
94 
96 {
99  pfes = f;
100 }
101 
103 {
105  GridFunction::MakeRef(f, v);
106  pfes = dynamic_cast<ParFiniteElementSpace*>(f);
107  MFEM_ASSERT(pfes != NULL, "not a ParFiniteElementSpace");
108 }
109 
111 {
113  GridFunction::MakeRef(f, v);
114  pfes = f;
115 }
116 
118 {
120  GridFunction::MakeRef(f, v, v_offset);
121  pfes = dynamic_cast<ParFiniteElementSpace*>(f);
122  MFEM_ASSERT(pfes != NULL, "not a ParFiniteElementSpace");
123 }
124 
126 {
128  GridFunction::MakeRef(f, v, v_offset);
129  pfes = f;
130 }
131 
133 {
134  const Operator *prolong = pfes->GetProlongationMatrix();
135  prolong->Mult(*tv, *this);
136 }
137 
138 void ParGridFunction::AddDistribute(double a, const Vector *tv)
139 {
140  pfes->Dof_TrueDof_Matrix()->Mult(a, *tv, 1.0, *this);
141 }
142 
144 {
146  GetTrueDofs(*tv);
147  return tv;
148 }
149 
151 {
152  MFEM_VERIFY(pfes->Conforming(), "not implemented for NC meshes");
154  pfes->DivideByGroupSize(tv);
155 }
156 
158 {
159  MFEM_VERIFY(pfes->Conforming(), "not implemented for NC meshes");
161  pfes->DivideByGroupSize(tv);
162 }
163 
165 {
167  ParallelAverage(*tv);
168  return tv;
169 }
170 
172 {
173  pfes->GetRestrictionMatrix()->Mult(*this, tv);
174 }
175 
177 {
178  pfes->GetRestrictionMatrix()->Mult(*this, tv);
179 }
180 
182 {
184  ParallelProject(*tv);
185  return tv;
186 }
187 
189 {
191 }
192 
194 {
196 }
197 
199 {
201  ParallelAssemble(*tv);
202  return tv;
203 }
204 
206 {
208 
209  if (pfes->GetFaceNbrVSize() <= 0)
210  {
211  return;
212  }
213 
214  ParMesh *pmesh = pfes->GetParMesh();
215 
218 
219  int *send_offset = pfes->send_face_nbr_ldof.GetI();
220  const int *d_send_ldof = mfem::Read(pfes->send_face_nbr_ldof.GetJMemory(),
221  send_data.Size());
222  int *recv_offset = pfes->face_nbr_ldof.GetI();
223  MPI_Comm MyComm = pfes->GetComm();
224 
225  int num_face_nbrs = pmesh->GetNFaceNeighbors();
226  MPI_Request *requests = new MPI_Request[2*num_face_nbrs];
227  MPI_Request *send_requests = requests;
228  MPI_Request *recv_requests = requests + num_face_nbrs;
229  MPI_Status *statuses = new MPI_Status[num_face_nbrs];
230 
231  auto d_data = this->Read();
232  auto d_send_data = send_data.Write();
233  MFEM_FORALL(i, send_data.Size(),
234  {
235  const int ldof = d_send_ldof[i];
236  d_send_data[i] = d_data[ldof >= 0 ? ldof : -1-ldof];
237  });
238 
239  bool mpi_gpu_aware = Device::GetGPUAwareMPI();
240  auto send_data_ptr = mpi_gpu_aware ? send_data.Read() : send_data.HostRead();
241  auto face_nbr_data_ptr = mpi_gpu_aware ? face_nbr_data.Write() :
243  for (int fn = 0; fn < num_face_nbrs; fn++)
244  {
245  int nbr_rank = pmesh->GetFaceNbrRank(fn);
246  int tag = 0;
247 
248  MPI_Isend(&send_data_ptr[send_offset[fn]],
249  send_offset[fn+1] - send_offset[fn],
250  MPI_DOUBLE, nbr_rank, tag, MyComm, &send_requests[fn]);
251 
252  MPI_Irecv(&face_nbr_data_ptr[recv_offset[fn]],
253  recv_offset[fn+1] - recv_offset[fn],
254  MPI_DOUBLE, nbr_rank, tag, MyComm, &recv_requests[fn]);
255  }
256 
257  MPI_Waitall(num_face_nbrs, send_requests, statuses);
258  MPI_Waitall(num_face_nbrs, recv_requests, statuses);
259 
260  delete [] statuses;
261  delete [] requests;
262 }
263 
264 double ParGridFunction::GetValue(int i, const IntegrationPoint &ip, int vdim)
265 const
266 {
267  Array<int> dofs;
268  Vector DofVal, LocVec;
269  int nbr_el_no = i - pfes->GetParMesh()->GetNE();
270  if (nbr_el_no >= 0)
271  {
272  int fes_vdim = pfes->GetVDim();
273  pfes->GetFaceNbrElementVDofs(nbr_el_no, dofs);
274  const FiniteElement *fe = pfes->GetFaceNbrFE(nbr_el_no);
275  if (fes_vdim > 1)
276  {
277  int s = dofs.Size()/fes_vdim;
278  Array<int> dofs_(&dofs[(vdim-1)*s], s);
279  face_nbr_data.GetSubVector(dofs_, LocVec);
280  DofVal.SetSize(s);
281  }
282  else
283  {
284  face_nbr_data.GetSubVector(dofs, LocVec);
285  DofVal.SetSize(dofs.Size());
286  }
287  if (fe->GetMapType() == FiniteElement::VALUE)
288  {
289  fe->CalcShape(ip, DofVal);
290  }
291  else
292  {
295  Tr->SetIntPoint(&ip);
296  fe->CalcPhysShape(*Tr, DofVal);
297  }
298  }
299  else
300  {
301  fes->GetElementDofs(i, dofs);
302  fes->DofsToVDofs(vdim-1, dofs);
303  DofVal.SetSize(dofs.Size());
304  const FiniteElement *fe = fes->GetFE(i);
305  if (fe->GetMapType() == FiniteElement::VALUE)
306  {
307  fe->CalcShape(ip, DofVal);
308  }
309  else
310  {
312  Tr->SetIntPoint(&ip);
313  fe->CalcPhysShape(*Tr, DofVal);
314  }
315  GetSubVector(dofs, LocVec);
316  }
317 
318  return (DofVal * LocVec);
319 }
320 
322  Vector &val) const
323 {
324  int nbr_el_no = i - pfes->GetParMesh()->GetNE();
325  if (nbr_el_no >= 0)
326  {
327  Array<int> dofs;
328  pfes->GetFaceNbrElementVDofs(nbr_el_no, dofs);
329  Vector loc_data;
330  face_nbr_data.GetSubVector(dofs, loc_data);
331  const FiniteElement *FElem = pfes->GetFaceNbrFE(nbr_el_no);
332  int dof = FElem->GetDof();
333  if (FElem->GetRangeType() == FiniteElement::SCALAR)
334  {
335  Vector shape(dof);
336  if (FElem->GetMapType() == FiniteElement::VALUE)
337  {
338  FElem->CalcShape(ip, shape);
339  }
340  else
341  {
344  Tr->SetIntPoint(&ip);
345  FElem->CalcPhysShape(*Tr, shape);
346  }
347  int vdim = fes->GetVDim();
348  val.SetSize(vdim);
349  for (int k = 0; k < vdim; k++)
350  {
351  val(k) = shape * ((const double *)loc_data + dof * k);
352  }
353  }
354  else
355  {
356  int spaceDim = fes->GetMesh()->SpaceDimension();
357  DenseMatrix vshape(dof, spaceDim);
360  Tr->SetIntPoint(&ip);
361  FElem->CalcVShape(*Tr, vshape);
362  val.SetSize(spaceDim);
363  vshape.MultTranspose(loc_data, val);
364  }
365  }
366  else
367  {
368  GridFunction::GetVectorValue(i, ip, val);
369  }
370 }
371 
373  const IntegrationPoint &ip,
374  int comp, Vector *tr) const
375 {
376  // We can assume faces and edges are local
378  {
379  return GridFunction::GetValue(T, ip, comp, tr);
380  }
381 
382  // Check for evaluation in a local element
383  int nbr_el_no = T.ElementNo - pfes->GetParMesh()->GetNE();
384  if (nbr_el_no < 0)
385  {
386  return GridFunction::GetValue(T, ip, comp, tr);
387  }
388 
389  // Evaluate using DoFs from a neighboring element
390  if (tr)
391  {
392  T.SetIntPoint(&ip);
393  T.Transform(ip, *tr);
394  }
395 
396  Array<int> dofs;
397  const FiniteElement * fe = pfes->GetFaceNbrFE(nbr_el_no);
398  pfes->GetFaceNbrElementVDofs(nbr_el_no, dofs);
399 
400  pfes->DofsToVDofs(comp-1, dofs);
401  Vector DofVal(dofs.Size()), LocVec;
402  if (fe->GetMapType() == FiniteElement::VALUE)
403  {
404  fe->CalcShape(ip, DofVal);
405  }
406  else
407  {
408  fe->CalcPhysShape(T, DofVal);
409  }
410  face_nbr_data.GetSubVector(dofs, LocVec);
411 
412  return (DofVal * LocVec);
413 }
414 
416  const IntegrationPoint &ip,
417  Vector &val, Vector *tr) const
418 {
419  // We can assume faces and edges are local
421  {
422  return GridFunction::GetVectorValue(T, ip, val, tr);
423  }
424 
425  // Check for evaluation in a local element
426  int nbr_el_no = T.ElementNo - pfes->GetParMesh()->GetNE();
427  if (nbr_el_no < 0)
428  {
429  return GridFunction::GetVectorValue(T, ip, val, tr);
430  }
431 
432  // Evaluate using DoFs from a neighboring element
433  if (tr)
434  {
435  T.SetIntPoint(&ip);
436  T.Transform(ip, *tr);
437  }
438 
439  Array<int> vdofs;
440  pfes->GetFaceNbrElementVDofs(nbr_el_no, vdofs);
441  const FiniteElement *fe = pfes->GetFaceNbrFE(nbr_el_no);
442 
443  int dof = fe->GetDof();
444  Vector loc_data;
445  face_nbr_data.GetSubVector(vdofs, loc_data);
446  if (fe->GetRangeType() == FiniteElement::SCALAR)
447  {
448  Vector shape(dof);
449  if (fe->GetMapType() == FiniteElement::VALUE)
450  {
451  fe->CalcShape(ip, shape);
452  }
453  else
454  {
455  fe->CalcPhysShape(T, shape);
456  }
457  int vdim = pfes->GetVDim();
458  val.SetSize(vdim);
459  for (int k = 0; k < vdim; k++)
460  {
461  val(k) = shape * ((const double *)loc_data + dof * k);
462  }
463  }
464  else
465  {
466  int spaceDim = pfes->GetMesh()->SpaceDimension();
467  DenseMatrix vshape(dof, spaceDim);
468  fe->CalcVShape(T, vshape);
469  val.SetSize(spaceDim);
470  vshape.MultTranspose(loc_data, val);
471  }
472 }
473 
474 void ParGridFunction::GetElementDofValues(int el, Vector &dof_vals) const
475 {
476  int ne = fes->GetNE();
477  if (el >= ne)
478  {
479  MFEM_ASSERT(face_nbr_data.Size() > 0,
480  "ParGridFunction::GetElementDofValues: ExchangeFaceNbrData "
481  "must be called before accessing face neighbor elements.");
482  // Face neighbor element
483  Array<int> dof_idx;
484  pfes->GetFaceNbrElementVDofs(el - ne, dof_idx);
485  face_nbr_data.GetSubVector(dof_idx, dof_vals);
486  }
487  else
488  {
489  GridFunction::GetElementDofValues(el, dof_vals);
490  }
491 }
492 
494 {
495  DeltaCoefficient *delta_c = dynamic_cast<DeltaCoefficient *>(&coeff);
496 
497  if (delta_c == NULL)
498  {
500  }
501  else
502  {
503  double loc_integral, glob_integral;
504 
505  ProjectDeltaCoefficient(*delta_c, loc_integral);
506 
507  MPI_Allreduce(&loc_integral, &glob_integral, 1, MPI_DOUBLE, MPI_SUM,
508  pfes->GetComm());
509 
510  (*this) *= (delta_c->Scale() / glob_integral);
511  }
512 }
513 
515 {
516  // local maximal element attribute for each dof
517  Array<int> ldof_attr;
518 
519  // local projection
520  GridFunction::ProjectDiscCoefficient(coeff, ldof_attr);
521 
522  // global maximal element attribute for each dof
523  Array<int> gdof_attr;
524  ldof_attr.Copy(gdof_attr);
525  GroupCommunicator &gcomm = pfes->GroupComm();
526  gcomm.Reduce<int>(gdof_attr, GroupCommunicator::Max);
527  gcomm.Bcast(gdof_attr);
528 
529  // set local value to zero if global maximal element attribute is larger than
530  // the local one, and mark (in gdof_attr) if we have the correct value
531  for (int i = 0; i < pfes->GetVSize(); i++)
532  {
533  if (gdof_attr[i] > ldof_attr[i])
534  {
535  (*this)(i) = 0.0;
536  gdof_attr[i] = 0;
537  }
538  else
539  {
540  gdof_attr[i] = 1;
541  }
542  }
543 
544  // parallel averaging plus interpolation to determine final values
546  gcomm.Reduce<int>(gdof_attr, GroupCommunicator::Sum);
547  gcomm.Bcast(gdof_attr);
548  for (int i = 0; i < fes->GetVSize(); i++)
549  {
550  (*this)(i) /= gdof_attr[i];
551  }
552  this->ParallelAssemble(*tv);
553  this->Distribute(tv);
554  delete tv;
555 }
556 
557 
559 {
560  // Harmonic (x1 ... xn) = [ (1/x1 + ... + 1/xn) / n ]^-1.
561  // Arithmetic(x1 ... xn) = (x1 + ... + xn) / n.
562 
563  // Number of zones that contain a given dof.
564  Array<int> zones_per_vdof;
565  AccumulateAndCountZones(coeff, type, zones_per_vdof);
566 
567  // Count the zones globally.
568  GroupCommunicator &gcomm = pfes->GroupComm();
569  gcomm.Reduce<int>(zones_per_vdof, GroupCommunicator::Sum);
570  gcomm.Bcast(zones_per_vdof);
571 
572  // Accumulate for all vdofs.
573  gcomm.Reduce<double>(data, GroupCommunicator::Sum);
574  gcomm.Bcast<double>(data);
575 
576  ComputeMeans(type, zones_per_vdof);
577 }
578 
580  AvgType type)
581 {
582  // Harmonic (x1 ... xn) = [ (1/x1 + ... + 1/xn) / n ]^-1.
583  // Arithmetic(x1 ... xn) = (x1 + ... + xn) / n.
584 
585  // Number of zones that contain a given dof.
586  Array<int> zones_per_vdof;
587  AccumulateAndCountZones(vcoeff, type, zones_per_vdof);
588 
589  // Count the zones globally.
590  GroupCommunicator &gcomm = pfes->GroupComm();
591  gcomm.Reduce<int>(zones_per_vdof, GroupCommunicator::Sum);
592  gcomm.Bcast(zones_per_vdof);
593 
594  // Accumulate for all vdofs.
595  gcomm.Reduce<double>(data, GroupCommunicator::Sum);
596  gcomm.Bcast<double>(data);
597 
598  ComputeMeans(type, zones_per_vdof);
599 }
600 
602  Coefficient *coeff[], VectorCoefficient *vcoeff, Array<int> &attr)
603 {
604  Array<int> values_counter;
605  AccumulateAndCountBdrValues(coeff, vcoeff, attr, values_counter);
606 
607  Vector values(Size());
608  for (int i = 0; i < values.Size(); i++)
609  {
610  values(i) = values_counter[i] ? (*this)(i) : 0.0;
611  }
612 
613  // Count the values globally.
614  GroupCommunicator &gcomm = pfes->GroupComm();
615  gcomm.Reduce<int>(values_counter, GroupCommunicator::Sum);
616  // Accumulate the values globally.
617  gcomm.Reduce<double>(values, GroupCommunicator::Sum);
618  // Only the values in the master are guaranteed to be correct!
619  for (int i = 0; i < values.Size(); i++)
620  {
621  if (values_counter[i])
622  {
623  (*this)(i) = values(i)/values_counter[i];
624  }
625  }
626 
627 #ifdef MFEM_DEBUG
628  Array<int> ess_vdofs_marker;
629  pfes->GetEssentialVDofs(attr, ess_vdofs_marker);
630  for (int i = 0; i < values_counter.Size(); i++)
631  {
632  MFEM_ASSERT(pfes->GetLocalTDofNumber(i) == -1 ||
633  bool(values_counter[i]) == bool(ess_vdofs_marker[i]),
634  "internal error");
635  }
636 #endif
637 }
638 
640  Array<int> &bdr_attr)
641 {
642  Array<int> values_counter;
643  AccumulateAndCountBdrTangentValues(vcoeff, bdr_attr, values_counter);
644 
645  Vector values(Size());
646  for (int i = 0; i < values.Size(); i++)
647  {
648  values(i) = values_counter[i] ? (*this)(i) : 0.0;
649  }
650 
651  // Count the values globally.
652  GroupCommunicator &gcomm = pfes->GroupComm();
653  gcomm.Reduce<int>(values_counter, GroupCommunicator::Sum);
654  // Accumulate the values globally.
655  gcomm.Reduce<double>(values, GroupCommunicator::Sum);
656  // Only the values in the master are guaranteed to be correct!
657  for (int i = 0; i < values.Size(); i++)
658  {
659  if (values_counter[i])
660  {
661  (*this)(i) = values(i)/values_counter[i];
662  }
663  }
664 
665 #ifdef MFEM_DEBUG
666  Array<int> ess_vdofs_marker;
667  pfes->GetEssentialVDofs(bdr_attr, ess_vdofs_marker);
668  for (int i = 0; i < values_counter.Size(); i++)
669  {
670  MFEM_ASSERT(pfes->GetLocalTDofNumber(i) == -1 ||
671  bool(values_counter[i]) == bool(ess_vdofs_marker[i]),
672  "internal error");
673  }
674 #endif
675 }
676 
678  Coefficient *ell_coeff,
679  JumpScaling jump_scaling,
680  const IntegrationRule *irs[]) const
681 {
682  const_cast<ParGridFunction *>(this)->ExchangeFaceNbrData();
683 
684  int fdof, intorder, k;
685  ElementTransformation *transf;
686  Vector shape, el_dofs, err_val, ell_coeff_val;
687  Array<int> vdofs;
688  IntegrationPoint eip;
689  double error = 0.0;
690 
691  ParMesh *mesh = pfes->GetParMesh();
692 
693  std::map<int,int> local_to_shared;
694  for (int i = 0; i < mesh->GetNSharedFaces(); ++i)
695  {
696  int i_local = mesh->GetSharedFace(i);
697  local_to_shared[i_local] = i;
698  }
699 
700  for (int i = 0; i < mesh->GetNumFaces(); i++)
701  {
702  double shared_face_factor = 1.0;
703  bool shared_face = false;
704  int iel1, iel2, info1, info2;
705  mesh->GetFaceElements(i, &iel1, &iel2);
706  mesh->GetFaceInfos(i, &info1, &info2);
707 
708  double h = mesh->GetElementSize(iel1);
709  intorder = fes->GetFE(iel1)->GetOrder();
710 
711  FaceElementTransformations *face_elem_transf;
712  const FiniteElement *fe1, *fe2;
713  if (info2 >= 0 && iel2 < 0)
714  {
715  int ishared = local_to_shared[i];
716  face_elem_transf = mesh->GetSharedFaceTransformations(ishared);
717  iel2 = face_elem_transf->Elem2No - mesh->GetNE();
718  fe2 = pfes->GetFaceNbrFE(iel2);
719  if ( (k = fe2->GetOrder()) > intorder )
720  {
721  intorder = k;
722  }
723  shared_face = true;
724  shared_face_factor = 0.5;
725  h = std::min(h, mesh->GetFaceNbrElementSize(iel2));
726  }
727  else
728  {
729  if (iel2 >= 0)
730  {
731  fe2 = pfes->GetFE(iel2);
732  if ( (k = fe2->GetOrder()) > intorder )
733  {
734  intorder = k;
735  }
736  h = std::min(h, mesh->GetElementSize(iel2));
737  }
738  else
739  {
740  fe2 = NULL;
741  }
742  face_elem_transf = mesh->GetFaceElementTransformations(i);
743  }
744  int p = intorder;
745 
746  intorder = 2 * intorder; // <-------------
747  const IntegrationRule *ir;
748  if (irs)
749  {
750  ir = irs[face_elem_transf->GetGeometryType()];
751  }
752  else
753  {
754  ir = &(IntRules.Get(face_elem_transf->GetGeometryType(), intorder));
755  }
756  err_val.SetSize(ir->GetNPoints());
757  ell_coeff_val.SetSize(ir->GetNPoints());
758  // side 1
759  transf = face_elem_transf->Elem1;
760  fe1 = fes->GetFE(iel1);
761  fdof = fe1->GetDof();
762  fes->GetElementVDofs(iel1, vdofs);
763  shape.SetSize(fdof);
764  el_dofs.SetSize(fdof);
765  for (k = 0; k < fdof; k++)
766  if (vdofs[k] >= 0)
767  {
768  el_dofs(k) = (*this)(vdofs[k]);
769  }
770  else
771  {
772  el_dofs(k) = - (*this)(-1-vdofs[k]);
773  }
774  for (int j = 0; j < ir->GetNPoints(); j++)
775  {
776  face_elem_transf->Loc1.Transform(ir->IntPoint(j), eip);
777  fe1->CalcShape(eip, shape);
778  transf->SetIntPoint(&eip);
779  ell_coeff_val(j) = ell_coeff->Eval(*transf, eip);
780  err_val(j) = exsol->Eval(*transf, eip) - (shape * el_dofs);
781  }
782  if (fe2 != NULL)
783  {
784  // side 2
785  transf = face_elem_transf->Elem2;
786  fdof = fe2->GetDof();
787  shape.SetSize(fdof);
788  el_dofs.SetSize(fdof);
789  if (shared_face)
790  {
791  pfes->GetFaceNbrElementVDofs(iel2, vdofs);
792  for (k = 0; k < fdof; k++)
793  if (vdofs[k] >= 0)
794  {
795  el_dofs(k) = face_nbr_data[vdofs[k]];
796  }
797  else
798  {
799  el_dofs(k) = - face_nbr_data[-1-vdofs[k]];
800  }
801  }
802  else
803  {
804  pfes->GetElementVDofs(iel2, vdofs);
805  for (k = 0; k < fdof; k++)
806  if (vdofs[k] >= 0)
807  {
808  el_dofs(k) = (*this)(vdofs[k]);
809  }
810  else
811  {
812  el_dofs(k) = - (*this)(-1 - vdofs[k]);
813  }
814  }
815  for (int j = 0; j < ir->GetNPoints(); j++)
816  {
817  face_elem_transf->Loc2.Transform(ir->IntPoint(j), eip);
818  fe2->CalcShape(eip, shape);
819  transf->SetIntPoint(&eip);
820  ell_coeff_val(j) += ell_coeff->Eval(*transf, eip);
821  ell_coeff_val(j) *= 0.5;
822  err_val(j) -= (exsol->Eval(*transf, eip) - (shape * el_dofs));
823  }
824  }
825  transf = face_elem_transf;
826  for (int j = 0; j < ir->GetNPoints(); j++)
827  {
828  const IntegrationPoint &ip = ir->IntPoint(j);
829  transf->SetIntPoint(&ip);
830  double nu = jump_scaling.Eval(h, p);
831  error += shared_face_factor*(ip.weight * nu * ell_coeff_val(j) *
832  transf->Weight() *
833  err_val(j) * err_val(j));
834  }
835  }
836 
837  error = (error < 0.0) ? -sqrt(-error) : sqrt(error);
838  return GlobalLpNorm(2.0, error, pfes->GetComm());
839 }
840 
841 void ParGridFunction::Save(std::ostream &out) const
842 {
843  double *data_ = const_cast<double*>(HostRead());
844  for (int i = 0; i < size; i++)
845  {
846  if (pfes->GetDofSign(i) < 0) { data_[i] = -data_[i]; }
847  }
848 
849  GridFunction::Save(out);
850 
851  for (int i = 0; i < size; i++)
852  {
853  if (pfes->GetDofSign(i) < 0) { data_[i] = -data_[i]; }
854  }
855 }
856 
857 void ParGridFunction::Save(const char *fname, int precision) const
858 {
859  int rank = pfes->GetMyRank();
860  ostringstream fname_with_suffix;
861  fname_with_suffix << fname << "." << setfill('0') << setw(6) << rank;
862  ofstream ofs(fname_with_suffix.str().c_str());
863  ofs.precision(precision);
864  Save(ofs);
865 }
866 
867 void ParGridFunction::SaveAsOne(const char *fname, int precision) const
868 {
869  ofstream ofs;
870  int rank = pfes->GetMyRank();
871  if (rank == 0)
872  {
873  ofs.open(fname);
874  ofs.precision(precision);
875  }
876  SaveAsOne(ofs);
877 }
878 
879 #ifdef MFEM_USE_ADIOS2
881  const std::string& variable_name,
882  const adios2stream::data_type type) const
883 {
884  double *data_ = const_cast<double*>(HostRead());
885  for (int i = 0; i < size; i++)
886  {
887  if (pfes->GetDofSign(i) < 0) { data_[i] = -data_[i]; }
888  }
889 
890  GridFunction::Save(out, variable_name, type);
891 
892  for (int i = 0; i < size; i++)
893  {
894  if (pfes->GetDofSign(i) < 0) { data_[i] = -data_[i]; }
895  }
896 }
897 #endif
898 
899 void ParGridFunction::SaveAsOne(std::ostream &out) const
900 {
901  int i, p;
902 
903  MPI_Comm MyComm;
904  MPI_Status status;
905  int MyRank, NRanks;
906 
907  MyComm = pfes -> GetComm();
908 
909  MPI_Comm_size(MyComm, &NRanks);
910  MPI_Comm_rank(MyComm, &MyRank);
911 
912  double **values = new double*[NRanks];
913  int *nv = new int[NRanks];
914  int *nvdofs = new int[NRanks];
915  int *nedofs = new int[NRanks];
916  int *nfdofs = new int[NRanks];
917  int *nrdofs = new int[NRanks];
918 
919  double * h_data = const_cast<double *>(this->HostRead());
920 
921  values[0] = h_data;
922  nv[0] = pfes -> GetVSize();
923  nvdofs[0] = pfes -> GetNVDofs();
924  nedofs[0] = pfes -> GetNEDofs();
925  nfdofs[0] = pfes -> GetNFDofs();
926 
927  if (MyRank == 0)
928  {
929  pfes -> Save(out);
930  out << '\n';
931 
932  for (p = 1; p < NRanks; p++)
933  {
934  MPI_Recv(&nv[p], 1, MPI_INT, p, 455, MyComm, &status);
935  MPI_Recv(&nvdofs[p], 1, MPI_INT, p, 456, MyComm, &status);
936  MPI_Recv(&nedofs[p], 1, MPI_INT, p, 457, MyComm, &status);
937  MPI_Recv(&nfdofs[p], 1, MPI_INT, p, 458, MyComm, &status);
938  values[p] = new double[nv[p]];
939  MPI_Recv(values[p], nv[p], MPI_DOUBLE, p, 460, MyComm, &status);
940  }
941 
942  int vdim = pfes -> GetVDim();
943 
944  for (p = 0; p < NRanks; p++)
945  {
946  nrdofs[p] = nv[p]/vdim - nvdofs[p] - nedofs[p] - nfdofs[p];
947  }
948 
950  {
951  for (int d = 0; d < vdim; d++)
952  {
953  for (p = 0; p < NRanks; p++)
954  for (i = 0; i < nvdofs[p]; i++)
955  {
956  out << *values[p]++ << '\n';
957  }
958 
959  for (p = 0; p < NRanks; p++)
960  for (i = 0; i < nedofs[p]; i++)
961  {
962  out << *values[p]++ << '\n';
963  }
964 
965  for (p = 0; p < NRanks; p++)
966  for (i = 0; i < nfdofs[p]; i++)
967  {
968  out << *values[p]++ << '\n';
969  }
970 
971  for (p = 0; p < NRanks; p++)
972  for (i = 0; i < nrdofs[p]; i++)
973  {
974  out << *values[p]++ << '\n';
975  }
976  }
977  }
978  else
979  {
980  for (p = 0; p < NRanks; p++)
981  for (i = 0; i < nvdofs[p]; i++)
982  for (int d = 0; d < vdim; d++)
983  {
984  out << *values[p]++ << '\n';
985  }
986 
987  for (p = 0; p < NRanks; p++)
988  for (i = 0; i < nedofs[p]; i++)
989  for (int d = 0; d < vdim; d++)
990  {
991  out << *values[p]++ << '\n';
992  }
993 
994  for (p = 0; p < NRanks; p++)
995  for (i = 0; i < nfdofs[p]; i++)
996  for (int d = 0; d < vdim; d++)
997  {
998  out << *values[p]++ << '\n';
999  }
1000 
1001  for (p = 0; p < NRanks; p++)
1002  for (i = 0; i < nrdofs[p]; i++)
1003  for (int d = 0; d < vdim; d++)
1004  {
1005  out << *values[p]++ << '\n';
1006  }
1007  }
1008 
1009  for (p = 1; p < NRanks; p++)
1010  {
1011  values[p] -= nv[p];
1012  delete [] values[p];
1013  }
1014  out.flush();
1015  }
1016  else
1017  {
1018  MPI_Send(&nv[0], 1, MPI_INT, 0, 455, MyComm);
1019  MPI_Send(&nvdofs[0], 1, MPI_INT, 0, 456, MyComm);
1020  MPI_Send(&nedofs[0], 1, MPI_INT, 0, 457, MyComm);
1021  MPI_Send(&nfdofs[0], 1, MPI_INT, 0, 458, MyComm);
1022  MPI_Send(h_data, nv[0], MPI_DOUBLE, 0, 460, MyComm);
1023  }
1024 
1025  delete [] values;
1026  delete [] nv;
1027  delete [] nvdofs;
1028  delete [] nedofs;
1029  delete [] nfdofs;
1030  delete [] nrdofs;
1031 }
1032 
1033 double GlobalLpNorm(const double p, double loc_norm, MPI_Comm comm)
1034 {
1035  double glob_norm;
1036 
1037  if (p < infinity())
1038  {
1039  // negative quadrature weights may cause the error to be negative
1040  if (loc_norm < 0.0)
1041  {
1042  loc_norm = -pow(-loc_norm, p);
1043  }
1044  else
1045  {
1046  loc_norm = pow(loc_norm, p);
1047  }
1048 
1049  MPI_Allreduce(&loc_norm, &glob_norm, 1, MPI_DOUBLE, MPI_SUM, comm);
1050 
1051  if (glob_norm < 0.0)
1052  {
1053  glob_norm = -pow(-glob_norm, 1.0/p);
1054  }
1055  else
1056  {
1057  glob_norm = pow(glob_norm, 1.0/p);
1058  }
1059  }
1060  else
1061  {
1062  MPI_Allreduce(&loc_norm, &glob_norm, 1, MPI_DOUBLE, MPI_MAX, comm);
1063  }
1064 
1065  return glob_norm;
1066 }
1067 
1069  BilinearFormIntegrator &blfi,
1070  GridFunction &flux, bool wcoef, int subdomain)
1071 {
1072  ParFiniteElementSpace *ffes =
1073  dynamic_cast<ParFiniteElementSpace*>(flux.FESpace());
1074  MFEM_VERIFY(ffes, "the flux FE space must be ParFiniteElementSpace");
1075 
1076  Array<int> count(flux.Size());
1077  SumFluxAndCount(blfi, flux, count, wcoef, subdomain);
1078 
1079  // Accumulate flux and counts in parallel
1080  ffes->GroupComm().Reduce<double>(flux, GroupCommunicator::Sum);
1081  ffes->GroupComm().Bcast<double>(flux);
1082 
1083  ffes->GroupComm().Reduce<int>(count, GroupCommunicator::Sum);
1084  ffes->GroupComm().Bcast<int>(count);
1085 
1086  // complete averaging
1087  for (int i = 0; i < count.Size(); i++)
1088  {
1089  if (count[i] != 0) { flux(i) /= count[i]; }
1090  }
1091 
1092  if (ffes->Nonconforming())
1093  {
1094  // On a partially conforming flux space, project on the conforming space.
1095  // Using this code may lead to worse refinements in ex6, so we do not use
1096  // it by default.
1097 
1098  // Vector conf_flux;
1099  // flux.ConformingProject(conf_flux);
1100  // flux.ConformingProlongate(conf_flux);
1101  }
1102 }
1103 
1104 
1106  const ParGridFunction &x,
1107  ParFiniteElementSpace &smooth_flux_fes,
1108  ParFiniteElementSpace &flux_fes,
1109  Vector &errors,
1110  int norm_p, double solver_tol, int solver_max_it)
1111 {
1112  // Compute fluxes in discontinuous space
1113  GridFunction flux(&flux_fes);
1114  flux = 0.0;
1115 
1116  ParFiniteElementSpace *xfes = x.ParFESpace();
1117  Array<int> xdofs, fdofs;
1118  Vector el_x, el_f;
1119 
1120  for (int i = 0; i < xfes->GetNE(); i++)
1121  {
1122  xfes->GetElementVDofs(i, xdofs);
1123  x.GetSubVector(xdofs, el_x);
1124 
1126  flux_integrator.ComputeElementFlux(*xfes->GetFE(i), *Transf, el_x,
1127  *flux_fes.GetFE(i), el_f, false);
1128 
1129  flux_fes.GetElementVDofs(i, fdofs);
1130  flux.AddElementVector(fdofs, el_f);
1131  }
1132 
1133  // Assemble the linear system for L2 projection into the "smooth" space
1134  ParBilinearForm *a = new ParBilinearForm(&smooth_flux_fes);
1135  ParLinearForm *b = new ParLinearForm(&smooth_flux_fes);
1137 
1138  if (xfes->GetNE())
1139  {
1140  MFEM_VERIFY(smooth_flux_fes.GetFE(0) != NULL,
1141  "Could not obtain FE of smooth flux space.");
1142 
1143  if (smooth_flux_fes.GetFE(0)->GetRangeType() == FiniteElement::SCALAR)
1144  {
1146  vmass->SetVDim(smooth_flux_fes.GetVDim());
1147  a->AddDomainIntegrator(vmass);
1149  }
1150  else
1151  {
1154  }
1155  }
1156 
1157  b->Assemble();
1158  a->Assemble();
1159  a->Finalize();
1160 
1161  // The destination of the projected discontinuous flux
1162  ParGridFunction smooth_flux(&smooth_flux_fes);
1163  smooth_flux = 0.0;
1164 
1165  HypreParMatrix* A = a->ParallelAssemble();
1166  HypreParVector* B = b->ParallelAssemble();
1167  HypreParVector* X = smooth_flux.ParallelProject();
1168 
1169  delete a;
1170  delete b;
1171 
1172  // Define and apply a parallel PCG solver for AX=B with the BoomerAMG
1173  // preconditioner from hypre.
1174  HypreBoomerAMG *amg = new HypreBoomerAMG(*A);
1175  amg->SetPrintLevel(0);
1176  HyprePCG *pcg = new HyprePCG(*A);
1177  pcg->SetTol(solver_tol);
1178  pcg->SetMaxIter(solver_max_it);
1179  pcg->SetPrintLevel(0);
1180  pcg->SetPreconditioner(*amg);
1181  pcg->Mult(*B, *X);
1182 
1183  // Extract the parallel grid function corresponding to the finite element
1184  // approximation X. This is the local solution on each processor.
1185  smooth_flux = *X;
1186 
1187  delete A;
1188  delete B;
1189  delete X;
1190  delete amg;
1191  delete pcg;
1192 
1193  // Proceed through the elements one by one, and find the Lp norm differences
1194  // between the flux as computed per element and the flux projected onto the
1195  // smooth_flux_fes space.
1196  double total_error = 0.0;
1197  errors.SetSize(xfes->GetNE());
1198  for (int i = 0; i < xfes->GetNE(); i++)
1199  {
1200  errors(i) = ComputeElementLpDistance(norm_p, i, smooth_flux, flux);
1201  total_error += pow(errors(i), norm_p);
1202  }
1203 
1204  double glob_error;
1205  MPI_Allreduce(&total_error, &glob_error, 1, MPI_DOUBLE, MPI_SUM,
1206  xfes->GetComm());
1207 
1208  return pow(glob_error, 1.0/norm_p);
1209 }
1210 
1211 } // namespace mfem
1212 
1213 #endif // MFEM_USE_MPI
int GetNPoints() const
Returns the number of the points in the integration rule.
Definition: intrules.hpp:247
Abstract class for all finite elements.
Definition: fe.hpp:243
int GetNFaceNeighbors() const
Definition: pmesh.hpp:339
void SetTol(double tol)
Definition: hypre.cpp:3569
Ordering::Type GetOrdering() const
Return the ordering method.
Definition: fespace.hpp:552
int Size() const
Return the logical size of the array.
Definition: array.hpp:134
void SetSubVector(const Array< int > &dofs, const double value)
Set the entries listed in dofs to the given value.
Definition: vector.cpp:551
void Reduce(T *ldata, void(*Op)(OpData< T >)) const
Reduce within each group where the master is the root.
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
Definition: fespace.hpp:540
Class for an integration rule - an Array of IntegrationPoint.
Definition: intrules.hpp:90
HypreParVector * NewTrueDofVector()
Definition: pfespace.hpp:321
Class for grid function - Vector with associated FE space.
Definition: gridfunc.hpp:30
void Bcast(T *ldata, int layout) const
Broadcast within each group where the master is the root.
Memory< double > data
Definition: vector.hpp:64
virtual void CalcVShape(const IntegrationPoint &ip, DenseMatrix &shape) const
Evaluate the values of all shape functions of a vector finite element in reference space at the given...
Definition: fe.cpp:40
void SumFluxAndCount(BilinearFormIntegrator &blfi, GridFunction &flux, Array< int > &counts, bool wcoef, int subdomain)
Definition: gridfunc.cpp:249
const IntegrationRule & Get(int GeomType, int Order)
Returns an integration rule for given GeomType and Order.
Definition: intrules.cpp:920
ParMesh * GetParMesh() const
Definition: pfespace.hpp:267
HypreParVector * ParallelAssemble() const
Returns a new vector assembled on the true dofs.
Definition: pgridfunc.cpp:198
Geometry::Type GetGeometryType() const
Return the Geometry::Type of the reference element.
Definition: eltrans.hpp:149
Base class for vector Coefficients that optionally depend on time and space.
virtual void GetEssentialVDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_dofs, int component=-1) const
Determine the boundary degrees of freedom.
Definition: pfespace.cpp:776
void ProjectDeltaCoefficient(DeltaCoefficient &delta_coeff, double &integral)
Definition: gridfunc.cpp:2215
HypreParVector * ParallelProject() const
Returns a new vector restricted to the true dofs.
Definition: pgridfunc.cpp:181
virtual void GetElementDofValues(int el, Vector &dof_vals) const
Definition: pgridfunc.cpp:474
virtual void GetVectorValue(int i, const IntegrationPoint &ip, Vector &val) const
Definition: gridfunc.cpp:425
virtual const Operator * GetProlongationMatrix() const
The returned Operator is owned by the FiniteElementSpace.
Definition: pfespace.cpp:910
void SetSize(int s)
Resize the vector to size s.
Definition: vector.hpp:513
void GetElementVDofs(int i, Array< int > &vdofs) const
Returns indexes of degrees of freedom in array dofs for i&#39;th element.
Definition: fespace.cpp:262
double Scale()
Return the scale factor times the optional time dependent function. Returns with when not set by th...
void ProjectDiscCoefficient(VectorCoefficient &coeff, Array< int > &dof_attr)
Definition: gridfunc.cpp:2433
int GetNSharedFaces() const
Return the number of shared faces (3D), edges (2D), vertices (1D)
Definition: pmesh.cpp:2731
ParFiniteElementSpace * pfes
Points to the same object as fes.
Definition: pgridfunc.hpp:35
void SetIntPoint(const IntegrationPoint *ip)
Set the integration point ip that weights and Jacobians will be evaluated at.
Definition: eltrans.hpp:85
void Copy(Array &copy) const
Create a copy of the internal array to the provided copy.
Definition: array.hpp:851
A specialized ElementTransformation class representing a face and its two neighboring elements...
Definition: eltrans.hpp:467
void GetSubVector(const Array< int > &dofs, Vector &elemvect) const
Extract entries listed in dofs to the output Vector elemvect.
Definition: vector.cpp:525
int GetOrder() const
Returns the order of the finite element. In the case of anisotropic orders, returns the maximum order...
Definition: fe.hpp:327
Data type dense matrix using column-major storage.
Definition: densemat.hpp:23
virtual double * HostWrite()
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), false).
Definition: vector.hpp:438
Delta function coefficient optionally multiplied by a weight coefficient and a scaled time dependent ...
int Size() const
Returns the size of the vector.
Definition: vector.hpp:190
IntegrationPointTransformation Loc2
Definition: eltrans.hpp:511
int GetNE() const
Returns number of elements.
Definition: mesh.hpp:846
virtual double GetValue(int i, const IntegrationPoint &ip, int vdim=1) const
Definition: pgridfunc.cpp:264
virtual void Save(std::ostream &out) const
Definition: pgridfunc.cpp:841
void DivideByGroupSize(double *vec)
Scale a vector of true dofs.
Definition: pfespace.cpp:730
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
virtual void ProjectDiscCoefficient(VectorCoefficient &coeff)
Project a discontinuous vector coefficient as a grid function on a continuous finite element space...
Definition: pgridfunc.cpp:514
virtual void SetSpace(FiniteElementSpace *f)
Associate a new FiniteElementSpace with the ParGridFunction.
Definition: pgridfunc.cpp:87
void AccumulateAndCountBdrTangentValues(VectorCoefficient &vcoeff, Array< int > &bdr_attr, Array< int > &values_counter)
Definition: gridfunc.cpp:2139
Abstract parallel finite element space.
Definition: pfespace.hpp:28
int GetMapType() const
Returns the FiniteElement::MapType of the element describing how reference functions are mapped to ph...
Definition: fe.hpp:349
virtual void ProjectCoefficient(Coefficient &coeff)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
Definition: pgridfunc.cpp:493
virtual void GetElementDofs(int elem, Array< int > &dofs) const
Returns indices of degrees of freedom of element &#39;elem&#39;.
Definition: fespace.cpp:2298
Vector send_data
Vector used as an MPI buffer to send face-neighbor data in ExchangeFaceNbrData() to neighboring proce...
Definition: pgridfunc.hpp:44
int GetLocalTDofNumber(int ldof) const
Definition: pfespace.cpp:819
void ComputeMeans(AvgType type, Array< int > &zones_per_vdof)
Definition: gridfunc.cpp:2190
ElementTransformation * Elem2
Definition: eltrans.hpp:509
double * GetData() const
Return a pointer to the beginning of the Vector data.
Definition: vector.hpp:199
FaceElementTransformations * GetFaceElementTransformations(int FaceNo, int mask=31)
Definition: mesh.cpp:886
int Size_of_connections() const
Definition: table.hpp:98
void SetPrintLevel(int print_lvl)
Definition: hypre.cpp:3589
HypreParMatrix * ParallelAssemble()
Returns the matrix assembled on the true dofs, i.e. P^t A P.
virtual void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
Definition: operator.hpp:93
int GetNumFaces() const
Return the number of faces (3D), edges (2D) or vertices (1D).
Definition: mesh.cpp:4915
void GetFaceNbrElementVDofs(int i, Array< int > &vdofs) const
Definition: pfespace.cpp:1219
virtual void MakeRef(FiniteElementSpace *f, double *v)
Make the ParGridFunction reference external data on a new FiniteElementSpace.
Definition: pgridfunc.cpp:102
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
Definition: gridfunc.cpp:3484
virtual void GetElementDofValues(int el, Vector &dof_vals) const
Definition: gridfunc.cpp:1753
int GetNE() const
Returns number of elements in the mesh.
Definition: fespace.hpp:567
The BoomerAMG solver in hypre.
Definition: hypre.hpp:1387
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
Definition: intrules.hpp:250
Class for parallel linear form.
Definition: plinearform.hpp:26
void MultTranspose(const double *x, double *y) const
Multiply a vector with the transpose matrix.
Definition: densemat.cpp:203
Communicator performing operations within groups defined by a GroupTopology with arbitrary-size data ...
const FiniteElement * GetFaceNbrFE(int i) const
Definition: pfespace.cpp:1253
MPI_Comm GetComm() const
Definition: pfespace.hpp:263
double f(const Vector &xvec)
Definition: lor_mms.hpp:32
double GetElementSize(ElementTransformation *T, int type=0)
Definition: mesh.cpp:76
virtual const FiniteElement * GetFE(int i) const
Definition: pfespace.cpp:511
static void Sum(OpData< T >)
Reduce operation Sum, instantiated for int and double.
ElementTransformation * GetFaceNbrElementTransformation(int i) const
Definition: pfespace.hpp:390
virtual void Update()
Transform by the Space UpdateMatrix (e.g., on Mesh change).
Definition: pgridfunc.cpp:81
Mesh * GetMesh() const
Returns the mesh.
Definition: fespace.hpp:410
IntegrationPointTransformation Loc1
Definition: eltrans.hpp:511
virtual double * Write(bool on_dev=true)
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), on_dev).
Definition: vector.hpp:434
int GetSharedFace(int sface) const
Return the local face index for the given shared face.
Definition: pmesh.cpp:2750
Memory< int > & GetJMemory()
Definition: table.hpp:119
double b
Definition: lissajous.cpp:42
void SetPrintLevel(int print_level)
Definition: hypre.hpp:1467
FaceElementTransformations * GetSharedFaceTransformations(int sf, bool fill2=true)
Definition: pmesh.cpp:2622
virtual void CalcShape(const IntegrationPoint &ip, Vector &shape) const =0
Evaluate the values of all shape functions of a scalar finite element in reference space at the given...
HypreParMatrix * Dof_TrueDof_Matrix() const
The true dof-to-dof interpolation matrix.
Definition: pfespace.hpp:311
void Assemble(int skip_zeros=1)
Assemble the local matrix.
virtual double ComputeDGFaceJumpError(Coefficient *exsol, Coefficient *ell_coeff, JumpScaling jump_scaling, const IntegrationRule *irs[]=NULL) const
Returns the Face Jumps error for L2 elements.
Definition: pgridfunc.cpp:677
double Weight()
Return the weight of the Jacobian matrix of the transformation at the currently set IntegrationPoint...
Definition: eltrans.hpp:123
void AccumulateAndCountZones(Coefficient &coeff, AvgType type, Array< int > &zones_per_vdof)
Accumulates (depending on type) the values of coeff at all shared vdofs and counts in how many zones ...
Definition: gridfunc.cpp:1901
virtual void MakeRef(FiniteElementSpace *f, double *v)
Make the GridFunction reference external data on a new FiniteElementSpace.
Definition: gridfunc.cpp:201
int GetVDim() const
Returns vector dimension.
Definition: fespace.hpp:534
FiniteElementSpace * FESpace()
Definition: gridfunc.hpp:629
const T * Read(const Memory< T > &mem, int size, bool on_dev=true)
Get a pointer for read access to mem with the mfem::Device&#39;s DeviceMemoryClass, if on_dev = true...
Definition: device.hpp:319
void AddElementVector(const Array< int > &dofs, const Vector &elemvect)
Add elements of the elemvect Vector to the entries listed in dofs. Negative dof values cause the -dof...
Definition: vector.cpp:617
virtual const double * HostRead() const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), false).
Definition: vector.hpp:430
void SetMaxIter(int max_iter)
Definition: hypre.cpp:3579
virtual void GetVectorValue(int i, const IntegrationPoint &ip, Vector &val) const
Definition: pgridfunc.cpp:321
int SpaceDimension() const
Definition: mesh.hpp:912
Wrapper for hypre&#39;s parallel vector class.
Definition: hypre.hpp:99
ElementTransformation * GetElementTransformation(int i) const
Returns ElementTransformation for the i-th element.
Definition: fespace.hpp:600
double GlobalLpNorm(const double p, double loc_norm, MPI_Comm comm)
Compute a global Lp norm from the local Lp norms computed by each processor.
Definition: pgridfunc.cpp:1033
void AddDomainIntegrator(LinearFormIntegrator *lfi)
Adds new Domain Integrator. Assumes ownership of lfi.
Definition: linearform.cpp:39
void GetFaceElements(int Face, int *Elem1, int *Elem2) const
Definition: mesh.cpp:1055
Abstract base class BilinearFormIntegrator.
Definition: bilininteg.hpp:34
void GetFaceInfos(int Face, int *Inf1, int *Inf2) const
Definition: mesh.cpp:1061
PCG solver in hypre.
Definition: hypre.hpp:1060
void ProjectBdrCoefficient(Coefficient *coeff[], VectorCoefficient *vcoeff, Array< int > &attr)
Definition: pgridfunc.cpp:601
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition: fespace.hpp:87
int GetDof() const
Returns the number of degrees of freedom in the finite element.
Definition: fe.hpp:323
virtual void Mult(const Vector &x, Vector &y) const
Matrix vector multiplication.
Definition: sparsemat.cpp:613
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
Definition: coefficient.hpp:39
FiniteElementSpace * fes
FE space on which the grid function lives. Owned if fec is not NULL.
Definition: gridfunc.hpp:34
virtual void ComputeFlux(BilinearFormIntegrator &blfi, GridFunction &flux, bool wcoef=true, int subdomain=-1)
Definition: pgridfunc.cpp:1068
static void Max(OpData< T >)
Reduce operation Max, instantiated for int and double.
void CalcPhysShape(ElementTransformation &Trans, Vector &shape) const
Evaluate the values of all shape functions of a scalar finite element in physical space at the point ...
Definition: fe.cpp:182
GroupCommunicator & GroupComm()
Return a reference to the internal GroupCommunicator (on VDofs)
Definition: pfespace.hpp:328
void Transform(const IntegrationPoint &, IntegrationPoint &)
Definition: eltrans.cpp:533
static bool GetGPUAwareMPI()
Definition: device.hpp:290
FiniteElementCollection * fec
Used when the grid function is read from a file. It can also be set explicitly, see MakeOwner()...
Definition: gridfunc.hpp:40
double L2ZZErrorEstimator(BilinearFormIntegrator &flux_integrator, const ParGridFunction &x, ParFiniteElementSpace &smooth_flux_fes, ParFiniteElementSpace &flux_fes, Vector &errors, int norm_p, double solver_tol, int solver_max_it)
Definition: pgridfunc.cpp:1105
void Distribute(const Vector *tv)
Definition: pgridfunc.cpp:132
virtual void Update()
Transform by the Space UpdateMatrix (e.g., on Mesh change).
Definition: gridfunc.cpp:164
double ComputeElementLpDistance(double p, int i, GridFunction &gf1, GridFunction &gf2)
Compute the Lp distance between two grid functions on the given element.
Definition: gridfunc.cpp:3926
bool Nonconforming() const
Definition: pfespace.hpp:398
void SaveAsOne(const char *fname, int precision=16) const
Definition: pgridfunc.cpp:867
static FiniteElementCollection * New(const char *name)
Factory method: return a newly allocated FiniteElementCollection according to the given name...
Definition: fe_coll.cpp:48
void GetFaceNbrElementTransformation(int i, IsoparametricTransformation *ElTr)
Definition: pmesh.cpp:1879
double a
Definition: lissajous.cpp:41
Vector face_nbr_data
Vector used to store data from face-neighbor processors, initialized by ExchangeFaceNbrData().
Definition: pgridfunc.hpp:39
virtual const char * Name() const
Definition: fe_coll.hpp:61
Class for integration point with weight.
Definition: intrules.hpp:25
virtual void Finalize(int skip_zeros=1)
Finalizes the matrix initialization.
virtual const SparseMatrix * GetRestrictionMatrix() const
Get the R matrix which restricts a local dof vector to true dof vector.
Definition: pfespace.hpp:379
virtual void ProjectBdrCoefficientTangent(VectorCoefficient &vcoeff, Array< int > &bdr_attr)
Project the tangential components of the given VectorCoefficient on the boundary. Only boundary attri...
Definition: pgridfunc.cpp:639
double GetFaceNbrElementSize(int i, int type=0)
Definition: pmesh.cpp:1932
HypreParVector * ParallelAverage() const
Returns a new vector averaged on the true dofs.
Definition: pgridfunc.cpp:164
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
Definition: hypre.cpp:3594
void AddDomainIntegrator(BilinearFormIntegrator *bfi)
Adds new Domain Integrator. Assumes ownership of bfi.
void Destroy()
Destroy a vector.
Definition: vector.hpp:590
virtual const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i&#39;th element in t...
Definition: fespace.cpp:2388
ElementTransformation * Elem1
Definition: eltrans.hpp:509
HypreParVector * GetTrueDofs() const
Returns the true dofs in a new HypreParVector.
Definition: pgridfunc.cpp:143
void AddDistribute(double a, const Vector *tv)
Definition: pgridfunc.cpp:138
double infinity()
Define a shortcut for std::numeric_limits&lt;double&gt;::infinity()
Definition: vector.hpp:46
virtual void ProjectCoefficient(Coefficient &coeff)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
Definition: gridfunc.cpp:2278
Class for parallel bilinear form.
virtual void SetSpace(FiniteElementSpace *f)
Associate a new FiniteElementSpace with the GridFunction.
Definition: gridfunc.cpp:193
int GetFaceNbrVSize() const
Definition: pfespace.hpp:384
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the coefficient in the element described by T at the point ip.
for VectorFiniteElements (Nedelec, Raviart-Thomas)
Definition: lininteg.hpp:266
Vector data type.
Definition: vector.hpp:60
const FiniteElementCollection * FEColl() const
Definition: fespace.hpp:554
virtual void Transform(const IntegrationPoint &, Vector &)=0
Transform integration point from reference coordinates to physical coordinates and store them in the ...
Vector coefficient defined by a vector GridFunction.
HYPRE_Int Mult(HypreParVector &x, HypreParVector &y, double alpha=1.0, double beta=0.0) const
Computes y = alpha * A * x + beta * y.
Definition: hypre.cpp:1529
int * GetI()
Definition: table.hpp:113
virtual void ComputeElementFlux(const FiniteElement &el, ElementTransformation &Trans, Vector &u, const FiniteElement &fluxelem, Vector &flux, bool with_coef=true)
Virtual method required for Zienkiewicz-Zhu type error estimators.
Definition: bilininteg.hpp:217
RefCoord s[3]
Class for parallel grid function.
Definition: pgridfunc.hpp:32
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
Definition: globals.hpp:66
Abstract operator.
Definition: operator.hpp:24
Wrapper for hypre&#39;s ParCSR matrix class.
Definition: hypre.hpp:277
double Eval(double h, int p) const
Definition: gridfunc.hpp:722
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve Ax=b with hypre&#39;s PCG.
Definition: hypre.cpp:3617
int GetRangeType() const
Returns the FiniteElement::RangeType of the element, one of {SCALAR, VECTOR}.
Definition: fe.hpp:340
Class for parallel meshes.
Definition: pmesh.hpp:32
IntegrationRules IntRules(0, Quadrature1D::GaussLegendre)
A global object with all integration rules (defined in intrules.cpp)
Definition: intrules.hpp:377
int GetFaceNbrRank(int fn) const
Definition: pmesh.cpp:2514
virtual const double * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
Definition: vector.hpp:426
void ParallelAssemble(Vector &tv)
Assemble the vector on the true dofs, i.e. P^t v.
Definition: plinearform.cpp:87
void AccumulateAndCountBdrValues(Coefficient *coeff[], VectorCoefficient *vcoeff, Array< int > &attr, Array< int > &values_counter)
Definition: gridfunc.cpp:1997
virtual double GetValue(int i, const IntegrationPoint &ip, int vdim=1) const
Definition: gridfunc.cpp:402
void ParallelProject(Vector &tv) const
Returns the vector restricted to the true dofs.
Definition: pgridfunc.cpp:171
ParFiniteElementSpace * ParFESpace() const
Definition: pgridfunc.hpp:108
void DofsToVDofs(Array< int > &dofs, int ndofs=-1) const
Definition: fespace.cpp:197