28#ifndef EWOMS_FV_BASE_ELEMENT_CONTEXT_HH
29#define EWOMS_FV_BASE_ELEMENT_CONTEXT_HH
33#include <dune/common/fvector.hh>
50template<
class TypeTag>
64 IntensiveQuantities intensiveQuantities[timeDiscHistorySize];
65 const PrimaryVariables* priVars[timeDiscHistorySize];
66 const IntensiveQuantities *thermodynamicHint[timeDiscHistorySize];
68 using DofVarsVector = std::vector<DofStore_>;
69 using ExtensiveQuantitiesVector = std::vector<ExtensiveQuantities>;
79 using Element =
typename GridView::template Codim<0>::Entity;
81 static const unsigned dimWorld = GridView::dimensionworld;
84 using CoordScalar =
typename GridView::ctype;
85 using GlobalPosition = Dune::FieldVector<CoordScalar, dimWorld>;
100 enableStorageCache_ = Parameters::Get<Parameters::EnableStorageCache>();
105 static void *
operator new(
size_t size)
108 static void operator delete(
void *
ptr)
109 { aligned_free(
ptr); }
120 asImp_().updateStencil(
elem);
121 asImp_().updateAllIntensiveQuantities();
122 asImp_().updateAllExtensiveQuantities();
139 stencil_.update(
elem);
142 dofVars_.resize(stencil_.numDof());
143 extensiveQuantities_.resize(stencil_.numInteriorFaces());
158 stencil_.updatePrimaryTopology(
elem);
160 dofVars_.resize(stencil_.numPrimaryDof());
175 stencil_.updateTopology(
elem);
184 if (!enableStorageCache_) {
188 asImp_().updateIntensiveQuantities(
timeIdx);
194 asImp_().updateIntensiveQuantities(0);
226 { asImp_().updateSingleIntQuants_(priVars,
dofIdx,
timeIdx); }
233 { asImp_().updateExtensiveQuantities(0); }
244 gradientCalculator_.prepare(asImp_(),
timeIdx);
247 extensiveQuantities_[
fluxIdx].update(asImp_(),
261 { focusDofIdx_ =
dofIdx; }
269 {
return focusDofIdx_; }
277 {
return this->
model().linearizer().getLinearizationType(); }
283 {
return *simulatorPtr_; }
289 {
return simulatorPtr_->problem(); }
295 {
return simulatorPtr_->model(); }
301 {
return gridView_; }
307 {
return *elemPtr_; }
353 {
return stencil_.subControlVolume(
dofIdx).globalPos(); }
397 {
return element().hasBoundaryIntersections(); }
414 if (enableStorageCache_ &&
timeIdx != 0 &&
problem().recycleFirstIterationStorage())
415 throw std::logic_error(
"If caching of the storage term is enabled, only the intensive quantities "
416 "for the most-recent substep (i.e. time index 0) are available!");
465 {
return stashedDofIdx_ != -1; }
474 {
return stashedDofIdx_; }
485 intensiveQuantitiesStashed_ = dofVars_[
dofIdx].intensiveQuantities[0];
486 priVarsStashed_ = *dofVars_[
dofIdx].priVars[0];
487 stashedDofIdx_ =
static_cast<int>(
dofIdx);
497 dofVars_[
dofIdx].priVars[0] = &priVarsStashed_;
498 dofVars_[
dofIdx].intensiveQuantities[0] = intensiveQuantitiesStashed_;
507 {
return gradientCalculator_; }
518 {
return extensiveQuantities_[
fluxIdx]; }
527 {
return enableStorageCache_; }
533 { enableStorageCache_ =
yesno; }
536 Implementation& asImp_()
537 {
return *
static_cast<Implementation*
>(
this); }
539 const Implementation& asImp_()
const
540 {
return *
static_cast<const Implementation*
>(
this); }
575 void updateSingleIntQuants_(
const PrimaryVariables& priVars,
unsigned dofIdx,
unsigned timeIdx)
578 if (enableStorageCache_ &&
timeIdx != 0 &&
problem().recycleFirstIterationStorage())
579 throw std::logic_error(
"If caching of the storage term is enabled, only the intensive quantities "
580 "for the most-recent substep (i.e. time index 0) are available!");
587 IntensiveQuantities intensiveQuantitiesStashed_;
588 PrimaryVariables priVarsStashed_;
590 GradientCalculator gradientCalculator_;
592 std::vector<DofStore_, aligned_allocator<DofStore_,
alignof(DofStore_)> > dofVars_;
593 std::vector<ExtensiveQuantities, aligned_allocator<ExtensiveQuantities,
alignof(ExtensiveQuantities)> > extensiveQuantities_;
595 const Simulator *simulatorPtr_;
596 const Element *elemPtr_;
597 const GridView gridView_;
602 bool enableStorageCache_;
This is a stand-alone version of boost::alignment::aligned_allocator from Boost 1....
This class stores an array of IntensiveQuantities objects, one intensive quantities object for each o...
Definition fvbaseelementcontext.hh:52
int stashedDofIdx() const
Return the (local) index of the DOF for which the primary variables were stashed.
Definition fvbaseelementcontext.hh:473
size_t numPrimaryDof(unsigned timeIdx) const
Return the number of primary degrees of freedom of the current element.
Definition fvbaseelementcontext.hh:318
bool enableStorageCache() const
Returns true iff the cache for the storage term ought to be used for this context.
Definition fvbaseelementcontext.hh:526
void updateAllExtensiveQuantities()
Compute the extensive quantities of all sub-control volume faces of the current element for all time ...
Definition fvbaseelementcontext.hh:232
const IntensiveQuantities * thermodynamicHint(unsigned dofIdx, unsigned timeIdx) const
Return the thermodynamic hint for a given local index.
Definition fvbaseelementcontext.hh:430
void updateAllIntensiveQuantities()
Compute the intensive quantities of all sub-control volumes of the current element for all time indic...
Definition fvbaseelementcontext.hh:182
const Stencil & stencil(unsigned) const
Return the current finite element geometry.
Definition fvbaseelementcontext.hh:341
void updateIntensiveQuantities_(unsigned timeIdx, size_t numDof)
Update the first 'n' intensive quantities objects from the primary variables.
Definition fvbaseelementcontext.hh:548
FvBaseElementContext(const Simulator &simulator)
The constructor.
Definition fvbaseelementcontext.hh:94
void setEnableStorageCache(bool yesno)
Specifies if the cache for the storage term ought to be used for this context.
Definition fvbaseelementcontext.hh:532
size_t numDof(unsigned timeIdx) const
Return the number of sub-control volumes of the current element.
Definition fvbaseelementcontext.hh:312
void updateStencilTopology(const Element &elem)
Update the topological part of the stencil, but nothing else.
Definition fvbaseelementcontext.hh:169
decltype(auto) pos(unsigned dofIdx, unsigned) const
Return the position of a local entities in global coordinates.
Definition fvbaseelementcontext.hh:352
const Element & element() const
Return the current element.
Definition fvbaseelementcontext.hh:306
unsigned globalSpaceIndex(unsigned dofIdx, unsigned timeIdx) const
Return the global spatial index for a sub-control volume.
Definition fvbaseelementcontext.hh:363
LinearizationType linearizationType() const
Returns the linearization type.
Definition fvbaseelementcontext.hh:276
void updateAll(const Element &elem)
Construct all volume and extensive quantities of an element from scratch.
Definition fvbaseelementcontext.hh:118
void updatePrimaryIntensiveQuantities(unsigned timeIdx)
Compute the intensive quantities of all sub-control volumes of the current element for a single time ...
Definition fvbaseelementcontext.hh:212
void updateIntensiveQuantities(unsigned timeIdx)
Compute the intensive quantities of all sub-control volumes of the current element for a single time ...
Definition fvbaseelementcontext.hh:203
Scalar dofTotalVolume(unsigned dofIdx, unsigned timeIdx) const
Return the total volume associated with a degree of freedom.
Definition fvbaseelementcontext.hh:389
size_t numInteriorFaces(unsigned timeIdx) const
Return the number of non-boundary faces which need to be considered for the flux apporixmation.
Definition fvbaseelementcontext.hh:325
void stashIntensiveQuantities(unsigned dofIdx)
Stash the intensive quantities for a degree of freedom on internal memory.
Definition fvbaseelementcontext.hh:481
bool haveStashedIntensiveQuantities() const
Returns true if no intensive quanties are stashed.
Definition fvbaseelementcontext.hh:464
bool onBoundary() const
Returns whether the current element is on the domain's boundary.
Definition fvbaseelementcontext.hh:396
void updateStencil(const Element &elem)
Compute the finite volume geometry for an element.
Definition fvbaseelementcontext.hh:131
IntensiveQuantities & intensiveQuantities(unsigned dofIdx, unsigned timeIdx)
Return a reference to the intensive quantities of a sub-control volume at a given time.
Definition fvbaseelementcontext.hh:438
const IntensiveQuantities & intensiveQuantities(unsigned dofIdx, unsigned timeIdx) const
Return a reference to the intensive quantities of a sub-control volume at a given time.
Definition fvbaseelementcontext.hh:409
const PrimaryVariables & primaryVars(unsigned dofIdx, unsigned timeIdx) const
Return the primary variables for a given local index.
Definition fvbaseelementcontext.hh:452
const GradientCalculator & gradientCalculator() const
Return a reference to the gradient calculation class of the chosen spatial discretization.
Definition fvbaseelementcontext.hh:506
const Simulator & simulator() const
Return a reference to the simulator.
Definition fvbaseelementcontext.hh:282
const Problem & problem() const
Return a reference to the problem.
Definition fvbaseelementcontext.hh:288
void updateExtensiveQuantities(unsigned timeIdx)
Compute the extensive quantities of all sub-control volume faces of the current element for a single ...
Definition fvbaseelementcontext.hh:242
const GridView & gridView() const
Return a reference to the grid view.
Definition fvbaseelementcontext.hh:300
Scalar dofVolume(unsigned dofIdx, unsigned timeIdx) const
Return the element-local volume associated with a degree of freedom.
Definition fvbaseelementcontext.hh:376
size_t numBoundaryFaces(unsigned timeIdx) const
Return the number of boundary faces which need to be considered for the flux apporixmation.
Definition fvbaseelementcontext.hh:332
const ExtensiveQuantities & extensiveQuantities(unsigned fluxIdx, unsigned) const
Return a reference to the extensive quantities of a sub-control volume face.
Definition fvbaseelementcontext.hh:517
void updatePrimaryStencil(const Element &elem)
Update the primary topological part of the stencil, but nothing else.
Definition fvbaseelementcontext.hh:152
void setFocusDofIndex(unsigned dofIdx)
Sets the degree of freedom on which the simulator is currently "focused" on.
Definition fvbaseelementcontext.hh:260
unsigned focusDofIndex() const
Returns the degree of freedom on which the simulator is currently "focused" on.
Definition fvbaseelementcontext.hh:268
void restoreIntensiveQuantities(unsigned dofIdx)
Restores the intensive quantities for a degree of freedom from internal memory.
Definition fvbaseelementcontext.hh:495
void updateIntensiveQuantities(const PrimaryVariables &priVars, unsigned dofIdx, unsigned timeIdx)
Compute the intensive quantities of a single sub-control volume of the current element for a single t...
Definition fvbaseelementcontext.hh:225
const Model & model() const
Return a reference to the model.
Definition fvbaseelementcontext.hh:294
Declare the properties used by the infrastructure code of the finite volume discretizations.
Declare the properties used by the infrastructure code of the finite volume discretizations.
The common code for the linearizers of non-linear systems of equations.
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilboundaryratevector.hh:37
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition propertysystem.hh:235
Definition linearizationtype.hh:35