chombo-discharge
Loading...
Searching...
No Matches
CD_PetscHelmholtzOp.H
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021-2026 SINTEF Energy Research
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
12
13#ifdef CH_USE_PETSC
14
15#ifndef CD_PETSCHELMHOLTZOP_H
16#define CD_PETSCHELMHOLTZOP_H
17
18// Petsc includes
19#include <petsc.h>
20
21// Std includes
22#include <vector>
23
24// Chombo includes
25#include <RefCountedPtr.H>
26#include <RealVect.H>
27#include <LayoutData.H>
28#include <BaseFab.H>
29
30// Our includes
31#include <CD_PetscGrid.H>
37#include <CD_EBAMRData.H>
38#include <CD_NamespaceHeader.H>
39
150{
151public:
155 PetscHelmholtzOp() noexcept;
156
161 PetscHelmholtzOp(const PetscHelmholtzOp& a_other) = delete;
162
167 PetscHelmholtzOp(const PetscHelmholtzOp&& a_other) = delete;
168
175 operator=(const PetscHelmholtzOp& a_other) = delete;
176
183 operator=(const PetscHelmholtzOp&& a_other) = delete;
184
188 virtual ~PetscHelmholtzOp() noexcept;
189
194 virtual void
195 clear() noexcept;
196
214 virtual void
215 define(const RefCountedPtr<PetscGrid>& a_petscGrid,
216 const Vector<MFMultigridInterpolator>& a_interpolators,
217 const RefCountedPtr<PetscHelmholtzDomainBC>& a_domainBc,
218 const RefCountedPtr<PetscHelmholtzEBBC>& a_ebBc,
219 const RefCountedPtr<PetscHelmholtzJumpBC>& a_jumpBc,
220 const MFAMRCellData& a_aCoef,
221 const MFAMRFluxData& a_bCoef,
222 const MFAMRIVData& a_bCoefIrreg,
223 const RealVect& a_probLo,
224 const Vector<Real>& a_dx,
225 const Real a_alpha,
226 const Real a_beta) noexcept;
227
235 virtual void
236 setAlphaAndBeta(const Real a_alpha, const Real a_beta) noexcept;
237
248 virtual void
249 setCoefficients(const MFAMRCellData& a_aCoef, const MFAMRFluxData& a_bCoef, const MFAMRIVData& a_bCoefIrreg) noexcept;
250
257 virtual void
258 fillMatrix() noexcept;
259
264 virtual const Mat&
265 getMatrix() const noexcept;
266
275 virtual Real
276 getRowWeight(const int a_level) const noexcept;
277
285 virtual void
286 scaleRows(Vec& a_vec, const bool a_inverse) const noexcept;
287
300 virtual void
301 addBoundaryConditionsToRHS(Vec& a_rhs, const EBAMRIVData& a_sigma) const noexcept;
302
303protected:
308
313
317 RefCountedPtr<PetscGrid> m_petscGrid;
318
323
328
333
338
342 MFAMRCellData m_aCoef;
343
347 MFAMRFluxData m_bCoef;
348
352 MFAMRIVData m_bCoefIrreg;
353
357 RealVect m_probLo;
358
362 Vector<Real> m_dx;
363
368
372 Real m_beta;
373
378
384 EBAMRIFData m_boundaryWeights[2];
385
392 Vector<RefCountedPtr<LayoutData<BaseFab<PetscStencil>>>> m_domainFluxStencils[SpaceDim][2];
393
401 Vector<RefCountedPtr<LayoutData<BaseFab<PetscStencil>>>> m_fineCFFluxStencils[SpaceDim][2];
402
410 Vector<RefCountedPtr<LayoutData<BaseFab<std::vector<PetscStencil>>>>> m_coarCFFluxStencils[SpaceDim][2];
411
419 EBAMRFluxData m_bCoefFiCo;
420
425 virtual void
426 checkSupported() const noexcept;
427
434 virtual void
435 addToMatrix(const PetscInt a_row, const PetscStencil& a_stencil) noexcept;
436
442 virtual void
443 createMatrix() noexcept;
444
449 virtual void
450 defineDomainFluxStencils() noexcept;
451
456 virtual void
458
463 virtual void
464 copyFineBcoefToCoarse() noexcept;
465
472 virtual RefCountedPtr<EBMultigridInterpolator>
473 getInterpolator(const int a_level, const int a_phase) const noexcept;
474
484 virtual IntVectSet
485 getCoveredCells(const int a_level, const DataIndex& a_din, const int a_phase) const noexcept;
486
494 virtual bool
495 isInterfaceCell(const IntVect& a_iv, const int a_level, const DataIndex& a_din) const noexcept;
496
508 virtual VoFStencil
509 getCutFaceFluxStencil(const FaceIndex& a_face,
510 const IntVectSet& a_coveredCells,
511 const int a_level,
512 const DataIndex& a_din,
513 const int a_phase) const noexcept;
514
525 virtual PetscInt
526 getCoarseRow(const IntVect& a_ivGhost,
527 const int a_refRat,
528 const int a_level,
529 const DataIndex& a_din,
530 const int a_phase) const noexcept;
531
542 virtual Real
543 getBcoef(const IntVect& a_iv,
544 const int a_dir,
545 const Side::LoHiSide a_side,
546 const int a_level,
547 const DataIndex& a_din,
548 const int a_phase) const noexcept;
549};
550
551#include <CD_NamespaceFooter.H>
552
553#endif
554
555#endif
Class for holding data across EBAMR hierarchies.
Parent base class for multigrid interpolation.
Declaration of a wrapper class for holding multifluid EBMultigridInterpolators.
File containing declaration of PetscGrid.
Declaration of a domain boundary condition class for PetscHelmholtzOp.
Declaration of a base class for electrode (EB) boundary conditions of PetscHelmholtzOp.
Declaration of a base class for the interface (jump) conditions of PetscHelmholtzOp.
Multigrid interpolator class.
Definition CD_EBMGLeastSquaresInterpolator.H:55
Wrapper class for holding multifluid EBMultigridInterpolators.
Definition CD_MFMultigridInterpolator.H:27
Class which maps a multifluid cut-cell AMR hierarchy to PETSc.
Definition CD_PetscGrid.H:47
Base class for domain boundary conditions of PetscHelmholtzOp.
Definition CD_PetscHelmholtzDomainBC.H:51
Base class for the boundary conditions on the EB faces of cut cells that are not interface cells (ele...
Definition CD_PetscHelmholtzEBBC.H:35
Base class for the conditions on the interface between two phases, for PetscHelmholtzOp.
Definition CD_PetscHelmholtzJumpBC.H:41
Real m_beta
Operator beta.
Definition CD_PetscHelmholtzOp.H:372
virtual void defineDomainFluxStencils() noexcept
Define the flux stencils through the domain faces, m_domainFluxStencils.
Definition CD_PetscHelmholtzOp.cpp:1092
RefCountedPtr< PetscHelmholtzJumpBC > m_jumpBc
Conditions on the EB faces of interface cells.
Definition CD_PetscHelmholtzOp.H:332
Vector< RefCountedPtr< LayoutData< BaseFab< PetscStencil > > > > m_domainFluxStencils[SpaceDim][2]
Flux stencils through the domain faces, without beta and b, over PETSc rows.
Definition CD_PetscHelmholtzOp.H:392
virtual void setCoefficients(const MFAMRCellData &a_aCoef, const MFAMRFluxData &a_bCoef, const MFAMRIVData &a_bCoefIrreg) noexcept
Point the operator to other a- and b-coefficients. The matrix is not changed until fillMatrix is call...
Definition CD_PetscHelmholtzOp.cpp:174
PetscHelmholtzOp() noexcept
Default constructor. Must subsequently call define.
Definition CD_PetscHelmholtzOp.cpp:32
virtual IntVectSet getCoveredCells(const int a_level, const DataIndex &a_din, const int a_phase) const noexcept
Get the cells around a grid that are covered by the finer level.
Definition CD_PetscHelmholtzOp.cpp:334
PetscHelmholtzOp & operator=(const PetscHelmholtzOp &a_other)=delete
Disallowed copy assignment operator.
RefCountedPtr< PetscGrid > m_petscGrid
PETSc grid.
Definition CD_PetscHelmholtzOp.H:317
MFAMRIVData m_bCoefIrreg
b-coefficient on the EB faces.
Definition CD_PetscHelmholtzOp.H:352
PetscHelmholtzOp(const PetscHelmholtzOp &a_other)=delete
Disallowed copy constructor.
Real m_alpha
Operator alpha.
Definition CD_PetscHelmholtzOp.H:367
virtual void checkSupported() const noexcept
Abort unless the grids are supported by this operator: an interpolator for each phase on every level ...
Definition CD_PetscHelmholtzOp.cpp:268
virtual void define(const RefCountedPtr< PetscGrid > &a_petscGrid, const Vector< MFMultigridInterpolator > &a_interpolators, const RefCountedPtr< PetscHelmholtzDomainBC > &a_domainBc, const RefCountedPtr< PetscHelmholtzEBBC > &a_ebBc, const RefCountedPtr< PetscHelmholtzJumpBC > &a_jumpBc, const MFAMRCellData &a_aCoef, const MFAMRFluxData &a_bCoef, const MFAMRIVData &a_bCoefIrreg, const RealVect &a_probLo, const Vector< Real > &a_dx, const Real a_alpha, const Real a_beta) noexcept
Define the operator.
Definition CD_PetscHelmholtzOp.cpp:98
RefCountedPtr< PetscHelmholtzDomainBC > m_domainBc
Domain boundary conditions.
Definition CD_PetscHelmholtzOp.H:322
virtual void clear() noexcept
Release the matrix, the boundary conditions, the coefficients and all per-level data,...
Definition CD_PetscHelmholtzOp.cpp:61
PetscHelmholtzOp & operator=(const PetscHelmholtzOp &&a_other)=delete
Disallowed move assignment operator.
RefCountedPtr< PetscHelmholtzEBBC > m_ebBc
Boundary conditions on the EB faces of cut cells that are not interface cells.
Definition CD_PetscHelmholtzOp.H:327
virtual ~PetscHelmholtzOp() noexcept
Destructor. Destroys the matrix, unless PETSc has already been finalized.
Definition CD_PetscHelmholtzOp.cpp:46
virtual void addToMatrix(const PetscInt a_row, const PetscStencil &a_stencil) noexcept
Add a stencil to a row of the matrix, with ADD_VALUES.
Definition CD_PetscHelmholtzOp.cpp:518
Vector< Real > m_dx
Grid resolution on each level.
Definition CD_PetscHelmholtzOp.H:362
virtual bool isInterfaceCell(const IntVect &a_iv, const int a_level, const DataIndex &a_din) const noexcept
Check if a cell is an interface cell, i.e. cut in both phases.
Definition CD_PetscHelmholtzOp.cpp:363
virtual const Mat & getMatrix() const noexcept
Get the assembled matrix.
Definition CD_PetscHelmholtzOp.cpp:189
virtual void addBoundaryConditionsToRHS(Vec &a_rhs, const EBAMRIVData &a_sigma) const noexcept
Move the boundary data part of the domain boundary fluxes into a right-hand side.
Definition CD_PetscHelmholtzOp.cpp:909
virtual Real getRowWeight(const int a_level) const noexcept
Get the weight that the rows of a level are multiplied by.
Definition CD_PetscHelmholtzOp.cpp:202
virtual VoFStencil getCutFaceFluxStencil(const FaceIndex &a_face, const IntVectSet &a_coveredCells, const int a_level, const DataIndex &a_din, const int a_phase) const noexcept
Get the flux b * dphi/dx through the centroid of an interior cut face, as in EBHelmholtzOp.
Definition CD_PetscHelmholtzOp.cpp:383
bool m_isDefined
Is defined or not.
Definition CD_PetscHelmholtzOp.H:307
Vector< RefCountedPtr< LayoutData< BaseFab< std::vector< PetscStencil > > > > > m_coarCFFluxStencils[SpaceDim][2]
Flux stencils through the fine faces on a refinement boundary, seen from the coarse side.
Definition CD_PetscHelmholtzOp.H:410
Vector< RefCountedPtr< LayoutData< BaseFab< PetscStencil > > > > m_fineCFFluxStencils[SpaceDim][2]
Flux stencils through the fine faces on a refinement boundary, seen from the fine side.
Definition CD_PetscHelmholtzOp.H:401
PetscHelmholtzOp(const PetscHelmholtzOp &&a_other)=delete
Disallowed move constructor.
virtual void createMatrix() noexcept
Allocate the boundary weights, and create the matrix with an exact preallocation.
Definition CD_PetscHelmholtzOp.cpp:455
MFAMRCellData m_aCoef
Cell-centered a-coefficient.
Definition CD_PetscHelmholtzOp.H:342
virtual void copyFineBcoefToCoarse() noexcept
Copy the b-coefficient of each finer level into the index space of the coarse level,...
Definition CD_PetscHelmholtzOp.cpp:1114
virtual void defineCoarseFineFluxStencils() noexcept
Define the flux stencils through the refinement boundaries, m_fineCFFluxStencils and m_coarCFFluxSten...
Definition CD_PetscHelmholtzOp.cpp:1103
EBAMRIFData m_boundaryWeights[2]
Weight w_B of the boundary data in the flux through each domain face.
Definition CD_PetscHelmholtzOp.H:384
virtual Real getBcoef(const IntVect &a_iv, const int a_dir, const Side::LoHiSide a_side, const int a_level, const DataIndex &a_din, const int a_phase) const noexcept
Get the b-coefficient on a face.
Definition CD_PetscHelmholtzOp.cpp:299
virtual RefCountedPtr< EBMultigridInterpolator > getInterpolator(const int a_level, const int a_phase) const noexcept
Get the coarse-fine interpolator of a level and phase.
Definition CD_PetscHelmholtzOp.cpp:323
virtual PetscInt getCoarseRow(const IntVect &a_ivGhost, const int a_refRat, const int a_level, const DataIndex &a_din, const int a_phase) const noexcept
Get the row of the coarse cell across a refinement boundary from a fine cell.
Definition CD_PetscHelmholtzOp.cpp:423
virtual void setAlphaAndBeta(const Real a_alpha, const Real a_beta) noexcept
Set alpha and beta. The matrix is not changed until fillMatrix is called.
Definition CD_PetscHelmholtzOp.cpp:162
EBAMRFluxData m_bCoefFiCo
The b-coefficient of the finer level, in the index space of the coarse level.
Definition CD_PetscHelmholtzOp.H:419
MFAMRFluxData m_bCoef
Face-centered b-coefficient.
Definition CD_PetscHelmholtzOp.H:347
virtual void fillMatrix() noexcept
Fill the matrix from the current alpha, beta, and a- and b-coefficients.
Definition CD_PetscHelmholtzOp.cpp:548
Vector< MFMultigridInterpolator > m_interpolators
Coarse-fine ghost cell interpolators of each phase, on each level. Entry 0 is not used.
Definition CD_PetscHelmholtzOp.H:337
virtual void scaleRows(Vec &a_vec, const bool a_inverse) const noexcept
Multiply, or divide, each local row of a vector by its row weight.
Definition CD_PetscHelmholtzOp.cpp:212
Mat m_matrix
The assembled matrix.
Definition CD_PetscHelmholtzOp.H:377
RealVect m_probLo
Lower-left corner of the computational domain.
Definition CD_PetscHelmholtzOp.H:357
bool m_verbose
Verbose output or not.
Definition CD_PetscHelmholtzOp.H:312
A linear stencil over global PETSc rows, i.e. a list of (row, weight) pairs.
Definition CD_PetscStencil.H:43