3.3.0
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
sequential/variableclassadaptive.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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program 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 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
19#ifndef DUMUX_VARIABLECLASS_ADAPTIVE_HH
20#define DUMUX_VARIABLECLASS_ADAPTIVE_HH
21
22#include <dune/grid/common/partitionset.hh>
23#include <dune/grid/utility/persistentcontainer.hh>
25#include "variableclass.hh"
26
32namespace Dumux
33{
38
45template<class TypeTag>
47{
48private:
50
54 using AdaptedValues = typename CellData::AdaptedValues;
55
56 using Grid = typename GridView::Grid;
57 using LevelGridView = typename Grid::LevelGridView;
58 using PersistentContainer = Dune::PersistentContainer<Grid, AdaptedValues>;
59
60private:
61 const Grid& grid_;
62 PersistentContainer adaptationMap_;
63
64public:
66
73 ParentType(gridView), grid_(gridView.grid()), adaptationMap_(grid_, 0)
74 {}
75
76
88 void storePrimVars(const Problem& problem)
89 {
90 adaptationMap_.resize();
91
92 // loop over all levels of the grid
93 for (int level = grid_.maxLevel(); level >= 0; level--)
94 {
95 //get grid view on level grid
96 LevelGridView levelView = grid_.levelGridView(level);
97
98 for (const auto& element : elements(levelView))
99 {
100 //get your map entry
101 AdaptedValues &adaptedValues = adaptationMap_[element];
102
103 // put your value in the map
104 if (element.isLeaf())
105 {
106 // get index
107 int indexI = this->index(element);
108
109 CellData& cellData = this->cellData(indexI);
110
111 cellData.storeAdaptionValues(adaptedValues, element);
112
113 adaptedValues.count = 1;
114 }
115 //Average in father
116 if (element.level() > 0)
117 {
118 auto father = element.father();
119 AdaptedValues& adaptedValuesFather = adaptationMap_[father];
120 adaptedValuesFather.count += 1;
121 CellData::storeAdaptionValues(adaptedValues, adaptedValuesFather, father);
122 }
123 }
124 }
125 }
126
140 void reconstructPrimVars(const Problem& problem)
141 {
142 adaptationMap_.resize();
143
144 for (int level = 0; level <= grid_.maxLevel(); level++)
145 {
146 LevelGridView levelView = grid_.levelGridView(level);
147
148 for (const auto& element : elements(levelView))
149 {
150 // only treat non-ghosts, ghost data is communicated afterwards
151 if (element.partitionType() == Dune::GhostEntity)
152 continue;
153
154 if (!element.isNew())
155 {
156 //entry is in map, write in leaf
157 if (element.isLeaf())
158 {
159 AdaptedValues &adaptedValues = adaptationMap_[element];
160 int newIdxI = this->index(element);
161
162 CellData& cellData = this->cellData(newIdxI);
163
164 cellData.setAdaptionValues(adaptedValues, element);
165 }
166 }
167 else
168 {
169 // value is not in map, interpolate from father element
170 if (element.level() > 0)
171 {
172 // create new entry: reconstruct from adaptationMap_[father] to a new
173 // adaptationMap_[son]
174 CellData::reconstructAdaptionValues(adaptationMap_, element.father(), element, problem);
175
176 // access new son
177 AdaptedValues& adaptedValues = adaptationMap_[element];
178 adaptedValues.count = 1;
179
180 // if we are on leaf, store reconstructed values of son in CellData object
181 if (element.isLeaf())
182 {
183 // acess new CellData object
184 int newIdxI = this->index(element);
185 CellData& cellData = this->cellData(newIdxI);
186
187 cellData.setAdaptionValues(adaptedValues, element);
188 }
189 }
190 }
191 }
192
193 }
194 // reset entries in restrictionmap
195 adaptationMap_.resize( typename PersistentContainer::Value() );
196 adaptationMap_.shrinkToFit();
197 adaptationMap_.fill( typename PersistentContainer::Value() );
198
199#if HAVE_MPI
200 // communicate ghost data
202 using ElementMapper = typename SolutionTypes::ElementMapper;
203 using DataHandle = VectorCommDataHandleEqual<ElementMapper, std::vector<CellData>, 0/*elementCodim*/>;
204 DataHandle dataHandle(problem.elementMapper(), this->cellDataGlobal());
205 problem.gridView().template communicate<DataHandle>(dataHandle,
206 Dune::InteriorBorder_All_Interface,
207 Dune::ForwardCommunication);
208#endif
209 }
210
211};
212}
213#endif
Contains a class to exchange entries of a vector.
Base class holding the variables for sequential models.
Definition: adapt.hh:29
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type GetProp
get the type of a property (equivalent to old macro GET_PROP(...))
Definition: propertysystem.hh:140
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:149
A data handle class to exchange entries of a vector.
Definition: vectorcommdatahandle.hh:78
Base class holding the variables and discretized data for sequential models.
Definition: variableclass.hh:49
CellData & cellData(const int idx)
Return the cell data of a specific cell.
Definition: variableclass.hh:121
int index(const Element &element) const
Get index of element (codim 0 entity)
Definition: variableclass.hh:140
const GridView & gridView() const
Return gridView.
Definition: variableclass.hh:156
Base class holding the variables and discretized data for sequential models.
Definition: sequential/variableclassadaptive.hh:47
void storePrimVars(const Problem &problem)
Definition: sequential/variableclassadaptive.hh:88
void reconstructPrimVars(const Problem &problem)
Definition: sequential/variableclassadaptive.hh:140
VariableClassAdaptive(const GridView &gridView)
Constructs an adaptive VariableClass object.
Definition: sequential/variableclassadaptive.hh:72