chombo-discharge
Loading...
Searching...
No Matches
CD_EBStateRedistribution.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#ifndef CD_EBSTATEREDISTRIBUTION_H
14#define CD_EBSTATEREDISTRIBUTION_H
15
16// Std includes
17#include <vector>
18
19// Chombo includes
20#include <EBLevelGrid.H>
21#include <ProblemDomain.H>
22#include <RealVect.H>
23#include <LevelData.H>
24#include <FArrayBox.H>
25#include <BaseFab.H>
26#include <LayoutData.H>
27#include <RefCountedPtr.H>
28#include <BaseIVFAB.H>
29#include <Copier.H>
30
31// Our includes
32#include <CD_EBRedistribution.H>
34#include <CD_NamespaceHeader.H>
35
82{
83public:
88
93 static constexpr int s_numGhost = 2;
94
111 EBStateRedistribution(const Vector<RefCountedPtr<EBLevelGrid>>& a_eblg,
112 const Vector<RefCountedPtr<EBLevelGrid>>& a_eblgCoFi,
113 const Vector<int>& a_refinementRatios,
114 const int a_finestLevel,
115 const int a_order,
116 const Real a_targetVolFrac,
117 const Vector<RefCountedPtr<EBMassRedistribution>>& a_massRedistribution,
118 const Vector<RefCountedPtr<LevelData<BaseFab<bool>>>>& a_coveredByFiner,
119 const Vector<RefCountedPtr<LevelData<BaseFab<bool>>>>& a_coarseFineGhost) noexcept;
120
124 virtual ~EBStateRedistribution() noexcept;
125
133 void
134 redistribute(EBAMRCellData& a_divG, const EBAMRCellData& a_phi, const Real a_dt) noexcept override;
135
136protected:
140 static constexpr int s_numOffsets = D_TERM(3, *3, *3);
141
145 static constexpr int s_trackerComps = D_TERM(2, *2, *2);
146
150 static constexpr int s_outside = 0;
151
155 static constexpr int s_valid = 1;
156
160 static constexpr int s_covered = 2;
161
165 static constexpr int s_ghost = 3;
166
171
176
181
185 Vector<RefCountedPtr<EBLevelGrid>> m_eblg;
186
190 Vector<RefCountedPtr<EBLevelGrid>> m_eblgCoFi;
191
195 Vector<RefCountedPtr<LevelData<BaseFab<bool>>>> m_coveredByFiner;
196
200 Vector<RefCountedPtr<LevelData<BaseFab<bool>>>> m_coarseFineGhost;
201
206
211
216 Vector<RefCountedPtr<LevelData<BaseFab<int>>>> m_tracker;
217
221 Vector<RefCountedPtr<LevelData<BaseFab<int>>>> m_numNbhd;
222
226 Vector<RefCountedPtr<LevelData<FArrayBox>>> m_alpha;
227
231 Vector<RefCountedPtr<LevelData<FArrayBox>>> m_nbhdVol;
232
236 Vector<RefCountedPtr<LevelData<FArrayBox>>> m_nbhdCentroid;
237
242 Vector<RefCountedPtr<LevelData<BaseFab<int>>>> m_connected;
243
247 Vector<RefCountedPtr<LayoutData<bool>>> m_activeBox;
248
252 Vector<RefCountedPtr<LevelData<FArrayBox>>> m_nbhdAverage;
253
257 Vector<RefCountedPtr<LevelData<FArrayBox>>> m_slopes;
258
262 Vector<RefCountedPtr<LevelData<FArrayBox>>> m_syncMass;
263
268 Vector<RefCountedPtr<LevelData<FArrayBox>>> m_state;
269
275 Vector<RefCountedPtr<LevelData<FArrayBox>>> m_ghostMass;
276
280 Vector<Copier> m_ghostCopier;
281
285 Vector<Copier> m_coarseCopier;
286
290 Vector<RefCountedPtr<LevelData<BaseIVFAB<Real>>>> m_massDiff;
291
297 static IntVect
298 offset(const int a_index) noexcept;
299
305 static int
306 offsetIndex(const IntVect& a_offset) noexcept;
307
315 static Real
316 volumeFraction(const EBISBox& a_ebisbox, const ProblemDomain& a_domain, const IntVect& a_iv) noexcept;
317
326 static RealVect
327 cellCentroid(const EBISBox& a_ebisbox, const ProblemDomain& a_domain, const IntVect& a_iv) noexcept;
328
339 static int
340 cellType(const BaseFab<bool>& a_coveredByFiner,
341 const BaseFab<bool>& a_coarseFineGhost,
342 const ProblemDomain& a_domain,
343 const IntVect& a_iv) noexcept;
344
349 void
350 defineLevel(const int a_level) noexcept;
351
362 void
363 mergeNeighbours(std::vector<IntVect>& a_offsets,
364 const IntVect& a_iv,
365 const RealVect& a_normal,
366 const EBISBox& a_ebisbox,
367 const BaseFab<bool>& a_coveredByFiner,
368 const BaseFab<bool>& a_coarseFineGhost,
369 const ProblemDomain& a_domain) const noexcept;
370
383 RealVect
384 computeSlope(const IntVect& a_iv,
385 const FArrayBox& a_average,
386 const FArrayBox& a_centroid,
387 const EBISBox& a_ebisbox,
388 const BaseFab<bool>& a_coveredByFiner,
389 const BaseFab<bool>& a_coarseFineGhost,
390 const ProblemDomain& a_domain,
391 const int a_connected) const noexcept;
392
399 void
400 synchronize(EBAMRCellData& a_divG, const Real a_dt) noexcept;
401};
402
403#include <CD_NamespaceFooter.H>
404
405#endif
Declaration of a class which can perform redistribution in an EB-AMR context.
Declaration of an abstract interface for the cut-cell stabilization of explicit finite-volume updates...
Redistribution of mass from cut cells to their neighbouring cells, as in Chombo's flux redistribution...
Definition CD_EBMassRedistribution.H:50
EBRedistribution() noexcept
Default constructor.
Definition CD_EBRedistribution.cpp:20
void mergeNeighbours(std::vector< IntVect > &a_offsets, const IntVect &a_iv, const RealVect &a_normal, const EBISBox &a_ebisbox, const BaseFab< bool > &a_coveredByFiner, const BaseFab< bool > &a_coarseFineGhost, const ProblemDomain &a_domain) const noexcept
Find the neighbours that a small cut cell merges with.
Definition CD_EBStateRedistribution.cpp:555
Vector< RefCountedPtr< LevelData< FArrayBox > > > m_nbhdAverage
Scratch: neighbourhood averages Q.
Definition CD_EBStateRedistribution.H:252
static RealVect cellCentroid(const EBISBox &a_ebisbox, const ProblemDomain &a_domain, const IntVect &a_iv) noexcept
Get the centroid of a cell from the EB geometry.
Definition CD_EBStateRedistribution.cpp:157
static IntVect offset(const int a_index) noexcept
Get the cell offset that an index into the 3^D block stands for.
Definition CD_EBStateRedistribution.cpp:119
Vector< RefCountedPtr< EBLevelGrid > > m_eblgCoFi
Coarsening of the grids: entry l is the coarsening of the grids on level l + 1.
Definition CD_EBStateRedistribution.H:190
Vector< RefCountedPtr< LevelData< FArrayBox > > > m_nbhdVol
Volume of the neighbourhood of each cell.
Definition CD_EBStateRedistribution.H:231
static constexpr int s_valid
Cell type: valid cell of the level.
Definition CD_EBStateRedistribution.H:155
RealVect computeSlope(const IntVect &a_iv, const FArrayBox &a_average, const FArrayBox &a_centroid, const EBISBox &a_ebisbox, const BaseFab< bool > &a_coveredByFiner, const BaseFab< bool > &a_coarseFineGhost, const ProblemDomain &a_domain, const int a_connected) const noexcept
Compute the limited slope of the neighbourhood average at a merged cell.
Definition CD_EBStateRedistribution.cpp:742
Vector< RefCountedPtr< LevelData< FArrayBox > > > m_alpha
Weights. Component 0 is alpha_0 of the cell, component 1 is alpha_1 of the neighbourhood of the cell.
Definition CD_EBStateRedistribution.H:226
Vector< RefCountedPtr< LevelData< FArrayBox > > > m_nbhdCentroid
Centroid of the neighbourhood of each cell, relative to the cell centre in units of the cell size.
Definition CD_EBStateRedistribution.H:236
Vector< RefCountedPtr< LevelData< BaseFab< bool > > > > m_coveredByFiner
Cells covered by the finer level, with s_numGhost ghost cells.
Definition CD_EBStateRedistribution.H:195
static constexpr int s_numOffsets
Number of cells in the 3^D block around a cell, which indexes the neighbour offsets.
Definition CD_EBStateRedistribution.H:140
Vector< RefCountedPtr< LevelData< FArrayBox > > > m_ghostMass
Scratch on the coarsening of the grids of a level, with one ghost cell, for data of the coarser level...
Definition CD_EBStateRedistribution.H:275
Vector< RefCountedPtr< EBLevelGrid > > m_eblg
Grids on each level.
Definition CD_EBStateRedistribution.H:185
Vector< RefCountedPtr< LevelData< FArrayBox > > > m_state
Scratch: the provisional state U = phi - dt*D. In the ghost cells it is U of the coarse cell under th...
Definition CD_EBStateRedistribution.H:268
Vector< RefCountedPtr< LevelData< BaseFab< bool > > > > m_coarseFineGhost
Cells inside the domain but outside the grids of the level, with s_numGhost ghost cells.
Definition CD_EBStateRedistribution.H:200
Vector< Copier > m_coarseCopier
Copiers from the coarser level to m_ghostMass of a level, ghost cells included.
Definition CD_EBStateRedistribution.H:285
void redistribute(EBAMRCellData &a_divG, const EBAMRCellData &a_phi, const Real a_dt) noexcept override
Turn kappa*D into the right-hand side of the update stabilized by state redistribution.
Definition CD_EBStateRedistribution.cpp:921
virtual ~EBStateRedistribution() noexcept
Destructor.
Definition CD_EBStateRedistribution.cpp:113
Vector< Copier > m_ghostCopier
Copiers that add m_ghostMass of a level, ghost cells included, to m_syncMass of the coarser level.
Definition CD_EBStateRedistribution.H:280
Real m_targetVolFrac
Target volume fraction.
Definition CD_EBStateRedistribution.H:180
void synchronize(EBAMRCellData &a_divG, const Real a_dt) noexcept
Add the corrections on refinement boundaries to the right-hand side.
Definition CD_EBStateRedistribution.cpp:1388
static int offsetIndex(const IntVect &a_offset) noexcept
Get the index into the 3^D block of a cell offset.
Definition CD_EBStateRedistribution.cpp:185
int m_order
Order of the reconstruction: 0 or 2.
Definition CD_EBStateRedistribution.H:175
Vector< RefCountedPtr< LevelData< BaseFab< int > > > > m_connected
Neighbours in the 3^D block around each merged cell that are connected to it, as a bit mask over the ...
Definition CD_EBStateRedistribution.H:242
Vector< RefCountedPtr< LevelData< BaseIVFAB< Real > > > > m_massDiff
Scratch: the parts of the corrections that are redistributed with the mass redistribution,...
Definition CD_EBStateRedistribution.H:290
Vector< RefCountedPtr< LayoutData< bool > > > m_activeBox
Per box, true if the box has a cell whose state is changed by the redistribution.
Definition CD_EBStateRedistribution.H:247
int m_finestLevel
Finest grid level.
Definition CD_EBStateRedistribution.H:170
Vector< RefCountedPtr< EBMassRedistribution > > m_massRedistribution
Mass redistribution operators on each level, which redistribute the corrections on refinement boundar...
Definition CD_EBStateRedistribution.H:210
static Real volumeFraction(const EBISBox &a_ebisbox, const ProblemDomain &a_domain, const IntVect &a_iv) noexcept
Get the volume fraction of a cell from the EB geometry.
Definition CD_EBStateRedistribution.cpp:136
Vector< RefCountedPtr< LevelData< BaseFab< int > > > > m_numNbhd
Number of neighbourhoods that each cell is in, its own included.
Definition CD_EBStateRedistribution.H:221
Vector< RefCountedPtr< LevelData< FArrayBox > > > m_syncMass
Scratch: corrections of the valid cells, as mass in units of the cell volume of the level.
Definition CD_EBStateRedistribution.H:262
Vector< RefCountedPtr< LevelData< FArrayBox > > > m_slopes
Scratch: limited slopes of the merged neighbourhoods.
Definition CD_EBStateRedistribution.H:257
void defineLevel(const int a_level) noexcept
Build the neighbourhood data on one level.
Definition CD_EBStateRedistribution.cpp:201
EBStateRedistribution()=delete
Disallowed weak construction.
static constexpr int s_outside
Cell type: outside the domain, or not reachable.
Definition CD_EBStateRedistribution.H:150
static constexpr int s_ghost
Cell type: inside the domain but outside the grids of the level, over a valid cell of the coarser lev...
Definition CD_EBStateRedistribution.H:165
Vector< int > m_refinementRatios
Refinement ratios between levels.
Definition CD_EBStateRedistribution.H:205
static constexpr int s_numGhost
Number of ghost cells of the neighbourhood data and of the cell masks. Also the number of ghost cells...
Definition CD_EBStateRedistribution.H:93
Vector< RefCountedPtr< LevelData< BaseFab< int > > > > m_tracker
Neighbourhoods. Component 0 is the number of merged neighbours of the cell, components 1,...
Definition CD_EBStateRedistribution.H:216
static constexpr int s_trackerComps
Number of components of the tracker: the number of merged neighbours, and up to 2^D - 1 neighbours.
Definition CD_EBStateRedistribution.H:145
static constexpr int s_covered
Cell type: covered by the finer level.
Definition CD_EBStateRedistribution.H:160
static int cellType(const BaseFab< bool > &a_coveredByFiner, const BaseFab< bool > &a_coarseFineGhost, const ProblemDomain &a_domain, const IntVect &a_iv) noexcept
Get the type of a cell.
Definition CD_EBStateRedistribution.cpp:169