test_boxfvgeometry.cc 4.93 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*****************************************************************************
 *   See the file COPYING for full copying permissions.                      *
 *                                                                           *
 *   This program is free software: you can redistribute it and/or modify    *
 *   it under the terms of the GNU General Public License as published by    *
 *   the Free Software Foundation, either version 2 of the License, or       *
 *   (at your option) any later version.                                     *
 *                                                                           *
 *   This program is distributed in the hope that it will be useful,         *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
 *   GNU General Public License for more details.                            *
 *                                                                           *
 *   You should have received a copy of the GNU General Public License       *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
 *****************************************************************************/
/*!
 * \file
 * \brief Test for finite volume element geometry, sub control volume, and sub
          control volume faces
 */
#include <config.h>

#include <iostream>
#include <utility>

#include <dune/common/test/iteratortest.hh>
30
#include <dune/common/fvector.hh>
31
32
33
#include <dune/grid/utility/structuredgridfactory.hh>
#include <dune/grid/yaspgrid.hh>

34
#include <dumux/discretization/box/fvgridgeometry.hh>
35

36
37
38
#ifndef DOXYGEN
namespace Dumux {
namespace Detail {
39
40
41
42
43
44
template<class T>
class NoopFunctor {
public:
  NoopFunctor() {}
  void operator()(const T& t){}
};
45
46
47
} // end namespace Detail
} // end namespace Dumux
#endif
48
49
50

int main (int argc, char *argv[]) try
{
51
52
    using namespace Dumux;

53
54
55
56
57
    // maybe initialize mpi
    Dune::MPIHelper::instance(argc, argv);

    std::cout << "Checking the FVGeometries, SCVs and SCV faces" << std::endl;

58
    using Grid = Dune::YaspGrid<3>;
59

60
    constexpr int dim = Grid::dimension;
61

62
63
    using FVGridGeometry = BoxFVGridGeometry<double, typename Grid::LeafGridView, ENABLE_CACHING>;
    using FVElementGeometry = typename FVGridGeometry::LocalView;
64
65
    using SubControlVolume = typename FVElementGeometry::SubControlVolume;
    using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
66
    using GlobalPosition = typename SubControlVolume::GlobalPosition;
67
68
69
70
71
72
73
74

    // make a grid
    GlobalPosition lower(0.0);
    GlobalPosition upper(1.0);
    std::array<unsigned int, dim> els{{1, 1, 1}};
    std::shared_ptr<Grid> grid = Dune::StructuredGridFactory<Grid>::createCubeGrid(lower, upper, els);
    auto leafGridView = grid->leafGridView();

Timo Koch's avatar
Timo Koch committed
75
76
    FVGridGeometry fvGridGeometry(leafGridView);
    fvGridGeometry.update();
77
78
79
80

    // iterate over elements. For every element get fv geometry and loop over scvs and scvfaces
    for (const auto& element : elements(leafGridView))
    {
Timo Koch's avatar
Timo Koch committed
81
        auto eIdx = fvGridGeometry.elementMapper().index(element);
82
        std::cout << std::endl << "Checking fvGeometry of element " << eIdx << std::endl;
Timo Koch's avatar
Timo Koch committed
83
        auto fvGeometry = localView(fvGridGeometry);
84
85
86
        fvGeometry.bind(element);

        auto range = scvs(fvGeometry);
87
        Detail::NoopFunctor<SubControlVolume> op;
88
89
90
91
92
        if(0 != testForwardIterator(range.begin(), range.end(), op))
            DUNE_THROW(Dune::Exception, "Iterator does not fulfill the forward iterator concept");

        for (auto&& scv : scvs(fvGeometry))
        {
93
            std::cout << "-- scv " << scv.localDofIndex() << " center at: " << scv.center() << " , volume: " << scv.volume()  << std::endl;
94
95
96
        }

        auto range2 = scvfs(fvGeometry);
97
        Detail::NoopFunctor<SubControlVolumeFace> op2;
98
99
100
        if(0 != testForwardIterator(range2.begin(), range2.end(), op2))
            DUNE_THROW(Dune::Exception, "Iterator does not fulfill the forward iterator concept");

101
        std::size_t boundaryCount = 0;
102
103
104
        for (auto&& scvf : scvfs(fvGeometry))
        {
            std::cout << "-- scvf " << scvf.index() << " ip at: " << scvf.ipGlobal() << " normal: " << scvf.unitOuterNormal();
105
106
107
108
109
            if (scvf.boundary())
            {
                ++boundaryCount;
                std::cout << " (on boundary).";
            }
110
111
            std::cout << std::endl;
        }
112
113
114
115

        if ((boundaryCount>0) != fvGeometry.hasBoundaryScvf())
            DUNE_THROW(Dune::InvalidStateException, "fvGeometry.hasBoundaryScvf() reports " << fvGeometry.hasBoundaryScvf()
                            << " but the number of boundary scvfs is " << boundaryCount);
116
117
118
119
120
    }
}
// //////////////////////////////////
//   Error handler
// /////////////////////////////////
121
catch (Dune::Exception &e) {
122
123
124
125

    std::cout << e << std::endl;
    return 1;
}