Helmholtz operator alpha*a*phi + beta*div(b*grad(phi)), assembled as a PETSc matrix over the rows of a PetscGrid.
More...
|
|
| PetscHelmholtzOp () noexcept |
| | Default constructor. Must subsequently call define.
|
| | PetscHelmholtzOp (const PetscHelmholtzOp &a_other)=delete |
| | Disallowed copy constructor.
|
| | PetscHelmholtzOp (const PetscHelmholtzOp &&a_other)=delete |
| | Disallowed move constructor.
|
| PetscHelmholtzOp & | operator= (const PetscHelmholtzOp &a_other)=delete |
| | Disallowed copy assignment operator.
|
| PetscHelmholtzOp & | operator= (const PetscHelmholtzOp &&a_other)=delete |
| | Disallowed move assignment operator.
|
|
virtual | ~PetscHelmholtzOp () noexcept |
| | Destructor. Destroys the matrix, unless PETSc has already been finalized.
|
|
virtual void | clear () noexcept |
| | Release the matrix, the boundary conditions, the coefficients and all per-level data, so that the operator can be defined again, e.g. after a regrid.
|
| 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.
|
| 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.
|
| 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 called.
|
| virtual void | fillMatrix () noexcept |
| | Fill the matrix from the current alpha, beta, and a- and b-coefficients.
|
| virtual const Mat & | getMatrix () const noexcept |
| | Get the assembled matrix.
|
| virtual Real | getRowWeight (const int a_level) const noexcept |
| | Get the weight that the rows of a level are multiplied by.
|
| 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.
|
| 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.
|
|
|
virtual void | checkSupported () const noexcept |
| | Abort unless the grids are supported by this operator: an interpolator for each phase on every level above the coarsest, and no periodic directions.
|
| virtual void | addToMatrix (const PetscInt a_row, const PetscStencil &a_stencil) noexcept |
| | Add a stencil to a row of the matrix, with ADD_VALUES.
|
| virtual void | createMatrix () noexcept |
| | Allocate the boundary weights, and create the matrix with an exact preallocation.
|
| virtual void | defineDomainFluxStencils () noexcept |
| | Define the flux stencils through the domain faces, m_domainFluxStencils.
|
| virtual void | defineCoarseFineFluxStencils () noexcept |
| | Define the flux stencils through the refinement boundaries, m_fineCFFluxStencils and m_coarCFFluxStencils.
|
| virtual void | copyFineBcoefToCoarse () noexcept |
| | Copy the b-coefficient of each finer level into the index space of the coarse level, m_bCoefFiCo.
|
| virtual RefCountedPtr< EBMultigridInterpolator > | getInterpolator (const int a_level, const int a_phase) const noexcept |
| | Get the coarse-fine interpolator of a level and phase.
|
| 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.
|
| 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.
|
| 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.
|
| 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.
|
| 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.
|
|
|
bool | m_isDefined |
| | Is defined or not.
|
|
bool | m_verbose |
| | Verbose output or not.
|
|
RefCountedPtr< PetscGrid > | m_petscGrid |
| | PETSc grid.
|
|
RefCountedPtr< PetscHelmholtzDomainBC > | m_domainBc |
| | Domain boundary conditions.
|
|
RefCountedPtr< PetscHelmholtzEBBC > | m_ebBc |
| | Boundary conditions on the EB faces of cut cells that are not interface cells.
|
|
RefCountedPtr< PetscHelmholtzJumpBC > | m_jumpBc |
| | Conditions on the EB faces of interface cells.
|
|
Vector< MFMultigridInterpolator > | m_interpolators |
| | Coarse-fine ghost cell interpolators of each phase, on each level. Entry 0 is not used.
|
|
MFAMRCellData | m_aCoef |
| | Cell-centered a-coefficient.
|
|
MFAMRFluxData | m_bCoef |
| | Face-centered b-coefficient.
|
|
MFAMRIVData | m_bCoefIrreg |
| | b-coefficient on the EB faces.
|
|
RealVect | m_probLo |
| | Lower-left corner of the computational domain.
|
|
Vector< Real > | m_dx |
| | Grid resolution on each level.
|
|
Real | m_alpha |
| | Operator alpha.
|
|
Real | m_beta |
| | Operator beta.
|
|
Mat | m_matrix |
| | The assembled matrix.
|
| EBAMRIFData | m_boundaryWeights [2] |
| | Weight w_B of the boundary data in the flux through each domain face.
|
| Vector< RefCountedPtr< LayoutData< BaseFab< PetscStencil > > > > | m_domainFluxStencils [SpaceDim][2] |
| | Flux stencils through the domain faces, without beta and b, over PETSc rows.
|
| Vector< RefCountedPtr< LayoutData< BaseFab< PetscStencil > > > > | m_fineCFFluxStencils [SpaceDim][2] |
| | Flux stencils through the fine faces on a refinement boundary, seen from the fine side.
|
| 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.
|
| EBAMRFluxData | m_bCoefFiCo |
| | The b-coefficient of the finer level, in the index space of the coarse level.
|
Helmholtz operator alpha*a*phi + beta*div(b*grad(phi)), assembled as a PETSc matrix over the rows of a PetscGrid.
Unlike EBHelmholtzOp, which applies the operator to data, this class assembles the operator once as a matrix so that it can be solved with PETSc. The domain boundary conditions enter through PetscHelmholtzDomainBC, which gives the flux through a domain face as w_B * g + sum_i w_i * phi_i with g the boundary data. The w_i go into the matrix. The w_B are kept per domain face when the matrix is assembled, and w_B * g goes into the right-hand side, see addBoundaryConditionsToRHS. The boundary data can thus change without the matrix being reassembled.
The operator is composite: it spans all AMR levels, and its rows are the valid cells of every level, in each phase. Embedded boundaries (electrodes) and the interface between two phases are supported; periodic directions are not, and abort.
The operator is assembled finite-volume style. The row of a cell is its finite-volume balance divided by dx^SpaceDim and kappa-weighted, as in FieldSolverGMG, and then multiplied by the row weight (dx/dx_0)^SpaceDim of its level (see getRowWeight): kappa*alpha*a*phi plus beta/dx times the sum, over the faces of the cell (including the EB face), of the face area fraction (the boundary area on the EB face) times b times s*F. Here F is the face flux, the derivative of phi in the +dir direction on the face, which is a stencil over PETSc rows, and s = -1 on the low side of the cell and +1 on the high side. The right-hand side must use the same weighting: a volume source is multiplied by kappa, every factor that multiplies the stencil part of a face flux in the matrix also multiplies its boundary data part w_B * g on the right-hand side (see addBoundaryConditionsToRHS), and the whole right-hand side is then multiplied by the row weights (scaleRows; addBoundaryConditionsToRHS does not apply them). Cells covered by a finer level have no row. The faces are assembled as follows:
- Face between two valid cells on the same level: the two-point flux, as on a single level.
- Face of a cut cell: as in EBHelmholtzOp, the two-point fluxes b * dphi/dx through the face and its neighbouring face are interpolated to the face centroid (EBArith::getInterpStencil), with b on each face. The interpolation falls back to the face itself if it would use a cell covered by the finer level. Coarse-fine ghost cells in it are replaced by their interpolation stencils.
- Domain face of a cut cell: the domain BC fluxes of the face and its neighbouring domain face, interpolated to the face centroid in the same way, as EBHelmholtzDomainBC does. On the right-hand side the boundary data of each of these faces enters with its own w_B.
- EB face: the flux from PetscHelmholtzEBBC::getEBFluxStencil, times the boundary area and the b-coefficient on the EB, and w_B * g on the right-hand side. On an interface cell, which is cut in both phases, the flux comes from PetscHelmholtzJumpBC::getInterfaceFluxStencil instead; it already contains the b-coefficients, so it is only multiplied by the boundary area, and w_g * g goes on the right-hand side.
- Domain face: the stencils and the boundary weight w_B from PetscHelmholtzDomainBC::getFaceFluxStencil. The stencil has parts on the next coarser level, this level, and the next finer level. The part on this level may contain coarse-fine ghost cells, which are replaced as on the fine side of a refinement boundary below. Any other entry that is not a PETSc row, e.g. a cell covered by a finer grid, aborts, as do entries outside the ghost cells of the PetscGrid maps.
- Fine side of a refinement boundary: the two-point flux between the fine cell and the ghost cell across the face. The ghost cell is not a PETSc row, so it is replaced by its interpolation stencil from EBMultigridInterpolator::getGhostStencil, which is over cells on the fine level and the next coarser level, and mapped with PetscGrid::getPetscStencilWithCoarserLevel.
- Coarse side of a refinement boundary: the flux through the coarse face is the area-weighted average of the fine face fluxes that cover it, using the same fine-face stencils as the fine rows. The coarse and fine rows thus see the same flux through the interface, which makes the composite operator conservative. Each fine face adds its flux to the coarse cell across it, through the coarsened fine grids (PetscGrid::getAMRToPetscCoFi), with the weight -1/refRat^SpaceDim relative to the fine row before the row weights, and -1 after them. The coarse cell skips its own faces onto cells covered by the finer level. The coarse row may be on another rank.
The coefficients alpha, beta, a and b are multiplied into the matrix entries, so changing any of them means refilling the matrix. The a- and b-coefficients are held by reference, so the caller can change their values in place; setCoefficients points the operator to other data, and setAlphaAndBeta changes alpha and beta. Neither touches the matrix: fillMatrix is the only function that does. It refills the existing matrix, keeping its preallocation and sparsity pattern, so the AMG preconditioner can keep its interpolation (PCGAMGSetReuseInterpolation) and only recompute its coarse operators.
After any change of alpha, beta, a or b, the caller must call fillMatrix and then rebuild the right-hand side (addBoundaryConditionsToRHS) before solving. The stencils can be reused, but the weights must be redone, and both the matrix and the right-hand side carry them. addBoundaryConditionsToRHS uses the current beta and b, so a right-hand side built after a coefficient change, against a matrix filled before it, gives a matrix and a right-hand side that do not belong together. That is a user error, and it is not detected.
Faces between two valid cells on one level have two-point stencils, which fillMatrix computes as it goes. The other faces have stencils that are expensive to compute, so they are computed once per define and stored without beta and b; fillMatrix then only multiplies them by beta and the b-coefficient on the face. The stored stencils are over PETSc rows, with ghost cells already replaced, and are held per category so that fillMatrix iterates over each category on its own:
- Domain faces: m_domainFluxStencils, with their boundary weights in m_boundaryWeights.
- EB faces: in the EB and jump boundary conditions, see below.
- Fine side of a refinement boundary: m_fineCFFluxStencils, multiplied by the fine-face b.
- Coarse side of a refinement boundary: m_coarCFFluxStencils, one stencil per fine face under the coarse face. Each is multiplied by the b-coefficient on its fine face, which fillMatrix first copies from the fine level into the index space of the coarse level (m_bCoefFiCo).
So far the stencils of the domain faces and of both sides of the refinement boundaries are computed in fillMatrix rather than stored; the holders, and the functions that define them, are placeholders.
Embedded boundaries and interfaces follow this design:
- Rows: every cut cell of each phase is a row. Multi-valued cells are a hard error (PetscGrid aborts on them).
- The flux through the EB face of a cut cell is F = w_B * g + sum_j w_j * phi_j, where the stencil is a PetscStencil over PETSc rows of any phase and any level. The shared primitive, in PetscHelmholtzEBStencils, is the one-sided normal derivative of phi over the cells of the cell's phase, dphi/dn = w_B * phi_B + sum_i w_i * phi_i, from a least-squares fit (LeastSquares::computeDualLevelStencils) over the cell's level and the next finer one. Coarse-fine ghost cells in it are replaced by their interpolation stencils, as for the domain faces, and cells covered by the finer level by the finer cells under them. It searches the half-circle, quadrant and radius neighbourhoods, each from the requested order down to 1, and aborts if none gives a stencil. One order and one weight, set by the solver, apply to all EB face stencils.
- Electrode faces: PetscHelmholtzEBBC, with Dirichlet (g = phi_B) and Neumann (g = dphi/dn) subclasses, and PetscHelmholtzElectrostaticEBBC (Source/Electrostatics), which takes g from the electrodes.
- Interface cells, where both phases have a VoF: PetscHelmholtzJumpBC. The one-sided derivatives of both phases are combined by a closure that eliminates phi_B, so that the flux into each side is a linear form over the rows of both phases plus w_g * g. The closure is the subclass: the natural jump b_1 D_1 + b_2 D_2 = sigma (g = sigma), and the saturation charge jump D_gas = 0 (Source/Electrostatics), for which sigma is an output. A virtual hook computes the jump data from the solution after the solve.
- The operator: kappa * alpha * a on the diagonal, each face flux times its area fraction, and the EB face flux times the boundary area and the b-coefficient on the EB. The flux through a cut face, and through the domain face of a cut cell, is the face-center fluxes of the neighbouring faces interpolated to the face centroid, as in EBHelmholtzOp. The b-coefficient on the EB is a third coefficient in define and setCoefficients.
- The one-sided least-squares stencils are computed once per define and stored in the boundary condition objects (PetscHelmholtzEBStencils). fillMatrix multiplies the electrode fluxes by beta and the b-coefficient on the EB, and fetches the interface fluxes, whose weights depend on the b-coefficients of both phases, with those coefficients. addBoundaryConditionsToRHS adds w_B * g for the electrode faces and w_g * g for the interface faces, and takes sigma as an argument.