basevanguard.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18
19 Consult the COPYING file in the top-level source directory of this
20 module for the precise wording of the license and the list of
21 copyright holders.
22*/
27#ifndef EWOMS_BASE_VANGUARD_HH
28#define EWOMS_BASE_VANGUARD_HH
29
32
33#include <dune/common/version.hh>
34
35#if HAVE_DUNE_FEM
36#include <dune/fem/space/common/dofmanager.hh>
37#include <cassert>
38#include <type_traits>
39#endif
40
41#include <memory>
42
43namespace Opm {
44
48template <class TypeTag>
50{
54 using Implementation = GetPropType<TypeTag, Properties::Vanguard>;
55
56#if HAVE_DUNE_FEM
58#endif
59
60public:
61 explicit BaseVanguard(Simulator& simulator)
62 : simulator_(simulator)
63 {}
64
65 BaseVanguard(const BaseVanguard&) = delete;
66
70 const GridView& gridView() const
71 { return *gridView_; }
72
73#if HAVE_DUNE_FEM
77 const GridPart& gridPart() const
78 { return *gridPart_; }
79
83 GridPart& gridPart()
84 { return *gridPart_; }
85#endif
86
93 int gridSequenceNumber () const
94 {
95#if HAVE_DUNE_FEM
96 using FemDofManager = Dune::Fem::DofManager< Grid >;
97 return FemDofManager::instance(asImp_().grid()).sequence();
98#else
99 return 0; // return the same sequence number >= 0 means the grid never changes
100#endif
101 }
102
103
109 {
110 asImp_().grid().loadBalance();
112 }
113
117 void addLgrs()
118 {
119 if(&asImp_() != this) { // this check prevents an infinite-recursion warning
120 asImp_().addLgrs();
122 }
123 }
124
125protected:
126 // this method should be called after the grid has been allocated
128 {
130 }
131
133 {
134#if HAVE_DUNE_FEM
135 if constexpr (std::is_same_v<GridView,
136 typename GetPropType<TypeTag,
137 Properties::GridPart>::GridViewType>)
138 {
139 gridPart_ = std::make_unique<GridPart>(asImp_().grid());
140 gridView_ = std::make_unique<GridView>(static_cast<GridView>(*gridPart_));
141 assert(gridView_->size(0) == asImp_().grid().leafGridView().size(0));
142 } else
143#endif
144 {
145 gridView_ = std::make_unique<GridView>(asImp_().grid().leafGridView());
146 }
147 }
148
149private:
150 Implementation& asImp_()
151 { return *static_cast<Implementation*>(this); }
152
153 const Implementation& asImp_() const
154 { return *static_cast<const Implementation*>(this); }
155
156 Simulator& simulator_;
157#if HAVE_DUNE_FEM
158 std::unique_ptr<GridPart> gridPart_;
159#endif
160 std::unique_ptr<GridView> gridView_;
161};
162
163} // namespace Opm
164
165#endif
Defines a type tags and some fundamental properties all models.
Provides the base class for most (all?) simulator vanguards.
Definition: basevanguard.hh:50
void addLgrs()
Add LGRs to the grid, if any. Only supported for CpGrid - for now.
Definition: basevanguard.hh:117
void updateGridView_()
Definition: basevanguard.hh:132
int gridSequenceNumber() const
Returns the number of times the grid has been changed since its creation.
Definition: basevanguard.hh:93
const GridView & gridView() const
Returns a reference to the grid view to be used.
Definition: basevanguard.hh:70
void finalizeInit_()
Definition: basevanguard.hh:127
BaseVanguard(Simulator &simulator)
Definition: basevanguard.hh:61
BaseVanguard(const BaseVanguard &)=delete
void loadBalance()
Distribute the grid (and attached data) over all processes.
Definition: basevanguard.hh:108
Definition: blackoilboundaryratevector.hh:39
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:233
This file provides the infrastructure to retrieve run-time parameters.