28 #ifndef EWOMS_FV_BASE_ELEMENT_CONTEXT_HH
29 #define EWOMS_FV_BASE_ELEMENT_CONTEXT_HH
35 #include <opm/common/Unused.hpp>
36 #include <opm/common/ErrorMacros.hpp>
37 #include <opm/common/Exceptions.hpp>
39 #include <dune/common/fvector.hh>
51 template<
class TypeTag>
54 typedef typename GET_PROP_TYPE(TypeTag, ElementContext) Implementation;
56 typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
57 typedef typename GET_PROP_TYPE(TypeTag, PrimaryVariables) PrimaryVariables;
58 typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
59 typedef typename GET_PROP_TYPE(TypeTag, ExtensiveQuantities) ExtensiveQuantities;
62 enum { timeDiscHistorySize =
GET_PROP_VALUE(TypeTag, TimeDiscHistorySize) };
66 PrimaryVariables priVars[timeDiscHistorySize];
69 typedef std::vector<DofStore_> DofVarsVector;
70 typedef std::vector<ExtensiveQuantities> ExtensiveQuantitiesVector;
73 typedef typename GET_PROP_TYPE(TypeTag, Problem) Problem;
74 typedef typename GET_PROP_TYPE(TypeTag, Model) Model;
75 typedef typename GET_PROP_TYPE(TypeTag, Stencil) Stencil;
76 typedef typename GET_PROP_TYPE(TypeTag, GradientCalculator) GradientCalculator;
77 typedef typename GET_PROP_TYPE(TypeTag, SolutionVector) SolutionVector;
79 typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
80 typedef typename GridView::template Codim<0>::Entity Element;
82 static const unsigned dim = GridView::dimension;
85 typedef typename GridView::ctype CoordScalar;
86 typedef Dune::FieldVector<CoordScalar, dim> GlobalPosition;
97 , stencil_(gridView_, simulator.
model().dofMapper() )
101 enableStorageCache_ =
EWOMS_GET_PARAM(TypeTag,
bool, EnableStorageCache);
106 static void *
operator new(
size_t size) {
110 static void operator delete(
void *ptr) {
111 Ewoms::aligned_free(ptr);
123 asImp_().updateStencil(elem);
124 asImp_().updateAllIntensiveQuantities();
125 asImp_().updateAllExtensiveQuantities();
142 stencil_.update(elem);
145 dofVars_.resize(stencil_.numDof());
146 extensiveQuantities_.resize(stencil_.numInteriorFaces());
161 stencil_.updatePrimaryTopology(elem);
163 dofVars_.resize(stencil_.numPrimaryDof());
178 stencil_.updateTopology(elem);
187 if (!enableStorageCache_) {
190 for (
unsigned timeIdx = 0; timeIdx < timeDiscHistorySize; ++ timeIdx)
191 asImp_().updateIntensiveQuantities(timeIdx);
197 asImp_().updateIntensiveQuantities(0);
229 { asImp_().updateSingleIntQuants_(priVars, dofIdx, timeIdx); }
236 { asImp_().updateExtensiveQuantities(0); }
247 gradientCalculator_.prepare(asImp_(), timeIdx);
249 for (
unsigned fluxIdx = 0; fluxIdx <
numInteriorFaces(timeIdx); fluxIdx++) {
250 extensiveQuantities_[fluxIdx].update(asImp_(),
264 { focusDofIdx_ = dofIdx; }
272 {
return focusDofIdx_; }
278 {
return *simulatorPtr_; }
284 {
return simulatorPtr_->
problem(); }
290 {
return simulatorPtr_->
model(); }
296 {
return gridView_; }
302 {
return *elemPtr_; }
308 {
return stencil(timeIdx).numDof(); }
314 {
return stencil(timeIdx).numPrimaryDof(); }
321 {
return stencil(timeIdx).numInteriorFaces(); }
328 {
return stencil(timeIdx).numBoundaryFaces(); }
336 const Stencil&
stencil(
unsigned timeIdx OPM_UNUSED)
const
347 const GlobalPosition&
pos(
unsigned dofIdx,
unsigned timeIdx OPM_UNUSED)
const
348 {
return stencil_.subControlVolume(dofIdx).globalPos(); }
359 {
return stencil(timeIdx).globalSpaceIndex(dofIdx); }
371 Scalar
dofVolume(
unsigned dofIdx,
unsigned timeIdx)
const
372 {
return stencil(timeIdx).subControlVolume(dofIdx).volume(); }
392 {
return element().hasBoundaryIntersections(); }
407 assert(0 <= dofIdx && dofIdx <
numDof(timeIdx));
409 if (enableStorageCache_ && timeIdx != 0)
410 OPM_THROW(std::logic_error,
411 "If caching of the storage term is enabled, only the intensive quantities "
412 "for the most-recent substep (i.e. time index 0) are available!");
415 return dofVars_[dofIdx].intensiveQuantities[timeIdx];
428 assert(0 <= dofIdx && dofIdx <
numDof(timeIdx));
429 return dofVars_[dofIdx].thermodynamicHint[timeIdx];
436 assert(0 <= dofIdx && dofIdx <
numDof(timeIdx));
437 return dofVars_[dofIdx].intensiveQuantities[timeIdx];
450 assert(0 <= dofIdx && dofIdx <
numDof(timeIdx));
451 return dofVars_[dofIdx].priVars[timeIdx];
456 const PrimaryVariables&
primaryVars(
unsigned dofIdx,
unsigned timeIdx)
const
458 assert(0 <= dofIdx && dofIdx <
numDof(timeIdx));
459 return dofVars_[dofIdx].priVars[timeIdx];
469 {
return stashedDofIdx_ != -1; }
478 {
return stashedDofIdx_; }
487 assert(0 <= dofIdx && dofIdx <
numDof(0));
489 intensiveQuantitiesStashed_ = dofVars_[dofIdx].intensiveQuantities[0];
490 priVarsStashed_ = dofVars_[dofIdx].priVars[0];
491 stashedDofIdx_ =
static_cast<int>(dofIdx);
501 dofVars_[dofIdx].priVars[0] = priVarsStashed_;
502 dofVars_[dofIdx].intensiveQuantities[0] = intensiveQuantitiesStashed_;
511 {
return gradientCalculator_; }
522 {
return extensiveQuantities_[fluxIdx]; }
531 {
return enableStorageCache_; }
537 { enableStorageCache_ = yesno; }
540 Implementation& asImp_()
541 {
return *
static_cast<Implementation*
>(
this); }
543 const Implementation& asImp_()
const
544 {
return *
static_cast<const Implementation*
>(
this); }
555 const SolutionVector& globalSol =
model().solution(timeIdx);
558 for (
unsigned dofIdx = 0; dofIdx <
numDof; dofIdx++) {
560 const PrimaryVariables& dofSol = globalSol[globalIdx];
561 dofVars_[dofIdx].priVars[timeIdx] = dofSol;
563 dofVars_[dofIdx].thermodynamicHint[timeIdx] =
564 model().thermodynamicHint(globalIdx, timeIdx);
566 const auto *cachedIntQuants =
model().cachedIntensiveQuantities(globalIdx, timeIdx);
567 if (cachedIntQuants) {
568 dofVars_[dofIdx].intensiveQuantities[timeIdx] = *cachedIntQuants;
571 updateSingleIntQuants_(dofSol, dofIdx, timeIdx);
579 void updateSingleIntQuants_(
const PrimaryVariables& priVars,
unsigned dofIdx,
unsigned timeIdx)
582 if (enableStorageCache_ && timeIdx != 0)
583 OPM_THROW(std::logic_error,
584 "If caching of the storage term is enabled, only the intensive quantities "
585 "for the most-recent substep (i.e. time index 0) are available!");
588 dofVars_[dofIdx].priVars[timeIdx] = priVars;
589 dofVars_[dofIdx].intensiveQuantities[timeIdx].update(asImp_(), dofIdx, timeIdx);
592 IntensiveQuantities intensiveQuantitiesStashed_;
593 PrimaryVariables priVarsStashed_;
595 GradientCalculator gradientCalculator_;
597 std::vector<DofStore_, Ewoms::aligned_allocator<DofStore_, alignof(DofStore_)> > dofVars_;
598 std::vector<ExtensiveQuantities, Ewoms::aligned_allocator<ExtensiveQuantities, alignof(ExtensiveQuantities)> > extensiveQuantities_;
600 const Simulator *simulatorPtr_;
601 const Element *elemPtr_;
602 const GridView gridView_;
607 bool enableStorageCache_;
This is a stand-alone version of boost::alignment::aligned_allocator from Boost 1.58.
unsigned globalSpaceIndex(unsigned dofIdx, unsigned timeIdx) const
Return the global spatial index for a sub-control volume.
Definition: fvbaseelementcontext.hh:358
Scalar dofTotalVolume(unsigned dofIdx, unsigned timeIdx) const
Return the total volume associated with a degree of freedom.
Definition: fvbaseelementcontext.hh:384
void updateStencilTopology(const Element &elem)
Update the topological part of the stencil, but nothing else.
Definition: fvbaseelementcontext.hh:172
void updateAllIntensiveQuantities()
Compute the intensive quantities of all sub-control volumes of the current element for all time indic...
Definition: fvbaseelementcontext.hh:185
void setEnableStorageCache(bool yesno)
Specifies if the cache for the storage term ought to be used for this context.
Definition: fvbaseelementcontext.hh:536
void updatePrimaryIntensiveQuantities(unsigned timeIdx)
Compute the intensive quantities of all sub-control volumes of the current element for a single time ...
Definition: fvbaseelementcontext.hh:215
Model & model()
Return the physical model used in the simulation.
Definition: simulator.hh:189
const GridView & gridView() const
Return a reference to the grid view.
Definition: fvbaseelementcontext.hh:295
#define GET_PROP_VALUE(TypeTag, PropTagName)
Access the value attribute of a property for a type tag.
Definition: propertysystem.hh:469
void updateAll(const Element &elem)
Construct all volume and extensive quantities of an element from scratch.
Definition: fvbaseelementcontext.hh:121
void stashIntensiveQuantities(unsigned dofIdx)
Stash the intensive quantities for a degree of freedom on internal memory.
Definition: fvbaseelementcontext.hh:485
bool enableStorageCache() const
Returns true iff the cache for the storage term ought to be used for this context.
Definition: fvbaseelementcontext.hh:530
Problem & problem()
Return the object which specifies the pysical setup of the simulation.
Definition: simulator.hh:202
int stashedDofIdx() const
Return the (local) index of the DOF for which the primary variables were stashed. ...
Definition: fvbaseelementcontext.hh:477
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:228
size_t numPrimaryDof(unsigned timeIdx) const
Return the number of primary degrees of freedom of the current element.
Definition: fvbaseelementcontext.hh:313
bool onBoundary() const
Returns whether the current element is on the domain's boundary.
Definition: fvbaseelementcontext.hh:391
unsigned focusDofIndex() const
Returns the degree of freedom on which the simulator is currently "focused" on.
Definition: fvbaseelementcontext.hh:271
void updateIntensiveQuantities_(unsigned timeIdx, size_t numDof)
Update the first 'n' intensive quantities objects from the primary variables.
Definition: fvbaseelementcontext.hh:552
Declare the properties used by the infrastructure code of the finite volume discretizations.
const Simulator & simulator() const
Return a reference to the simulator.
Definition: fvbaseelementcontext.hh:277
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:320
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:404
#define EWOMS_GET_PARAM(TypeTag, ParamType, ParamName)
Retrieve a runtime parameter.
Definition: parametersystem.hh:99
bool haveStashedIntensiveQuantities() const
Returns true if no intensive quanties are stashed.
Definition: fvbaseelementcontext.hh:468
const GlobalPosition & pos(unsigned dofIdx, unsigned timeIdx OPM_UNUSED) const
Return the position of a local entities in global coordinates.
Definition: fvbaseelementcontext.hh:347
const Model & model() const
Return a reference to the model.
Definition: fvbaseelementcontext.hh:289
FvBaseElementContext(const Simulator &simulator)
The constructor.
Definition: fvbaseelementcontext.hh:95
This class stores an array of IntensiveQuantities objects, one intensive quantities object for each o...
Definition: fvbaseelementcontext.hh:52
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:434
const PrimaryVariables & primaryVars(unsigned dofIdx, unsigned timeIdx) const
Return the primary variables for a given local index.
Definition: fvbaseelementcontext.hh:456
size_t numBoundaryFaces(unsigned timeIdx) const
Return the number of boundary faces which need to be considered for the flux apporixmation.
Definition: fvbaseelementcontext.hh:327
void updateIntensiveQuantities(unsigned timeIdx)
Compute the intensive quantities of all sub-control volumes of the current element for a single time ...
Definition: fvbaseelementcontext.hh:206
const GradientCalculator & gradientCalculator() const
Return a reference to the gradient calculation class of the chosen spatial discretization.
Definition: fvbaseelementcontext.hh:510
PrimaryVariables & primaryVars(unsigned dofIdx, unsigned timeIdx)
Return the primary variables for a given local index.
Definition: fvbaseelementcontext.hh:448
void updateExtensiveQuantities(unsigned timeIdx)
Compute the extensive quantities of all sub-control volume faces of the current element for a single ...
Definition: fvbaseelementcontext.hh:245
void restoreIntensiveQuantities(unsigned dofIdx)
Restores the intensive quantities for a degree of freedom from internal memory.
Definition: fvbaseelementcontext.hh:499
const Element & element() const
Return the current element.
Definition: fvbaseelementcontext.hh:301
const IntensiveQuantities * thermodynamicHint(unsigned dofIdx, unsigned timeIdx) const
Return the thermodynamic hint for a given local index.
Definition: fvbaseelementcontext.hh:426
const Stencil & stencil(unsigned timeIdx OPM_UNUSED) const
Return the current finite element geometry.
Definition: fvbaseelementcontext.hh:336
size_t numDof(unsigned timeIdx) const
Return the number of sub-control volumes of the current element.
Definition: fvbaseelementcontext.hh:307
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:75
void updateStencil(const Element &elem)
Compute the finite volume geometry for an element.
Definition: fvbaseelementcontext.hh:134
void updatePrimaryStencil(const Element &elem)
Update the primary topological part of the stencil, but nothing else.
Definition: fvbaseelementcontext.hh:155
void setFocusDofIndex(unsigned dofIdx)
Sets the degree of freedom on which the simulator is currently "focused" on.
Definition: fvbaseelementcontext.hh:263
const Problem & problem() const
Return a reference to the problem.
Definition: fvbaseelementcontext.hh:283
void updateAllExtensiveQuantities()
Compute the extensive quantities of all sub-control volume faces of the current element for all time ...
Definition: fvbaseelementcontext.hh:235
Scalar dofVolume(unsigned dofIdx, unsigned timeIdx) const
Return the element-local volume associated with a degree of freedom.
Definition: fvbaseelementcontext.hh:371
const ExtensiveQuantities & extensiveQuantities(unsigned fluxIdx, unsigned timeIdx OPM_UNUSED) const
Return a reference to the extensive quantities of a sub-control volume face.
Definition: fvbaseelementcontext.hh:521