Newer
Older
//======================================================================================================================
//
// This file is part of waLBerla. waLBerla 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 3 of
// the License, or (at your option) any later version.
//
// waLBerla 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 waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
//
//! \file BoundarySetterFlagFieldSpecialization.h
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//! \ingroup geometry
//! \author Martin Bauer <martin.bauer@fau.de>
//
//======================================================================================================================
#pragma once
#include "core/Abort.h"
#include "core/DataTypes.h"
#include "core/config/Config.h"
#include "field/FlagFunctions.h"
#include "field/FlagField.h"
#include "domain_decomposition/IBlock.h"
#include "domain_decomposition/StructuredBlockStorage.h"
#include "BoundarySetter.h"
namespace walberla {
namespace geometry {
namespace initializer {
/*
* Specialization for FlagFields to make all initializers also work with pure FlagFields instead of
* boundary handlings
*/
template< typename Flag_T >
class BoundarySetter< FlagField<Flag_T> >
{
public:
//** Setup ************************************************************************************************
/*! \name Setup */
//@{
void setConfigBlock( const Config::BlockHandle & blockHandle,
const std::set<std::string> & subblocksToIgnore = std::set<std::string> () );
void setBoundaryConfigBlock( const BoundaryUID & boundaryUID, const Config::BlockHandle & blockHandle );
void setBoundaryConfig( const BoundaryUID & boundaryUID, const shared_ptr<BoundaryConfiguration> & conf );
void setFlagUID( const FlagUID & flag );
//@}
//****************************************************************************************************************
//** Setting Boundaries ***********************************************************************************
/*! \name Setting Boundaries */
//@{
void configure( IBlock & block, BlockDataID boundaryHandlingID );
void set( cell_idx_t x, cell_idx_t y, cell_idx_t z );
void set( const CellInterval & ci );
template<typename CellIterator>
void set( const CellIterator & begin, const CellIterator & end );
FlagField<Flag_T> * getFlagField() const { return flagField_; }
//@}
//****************************************************************************************************************
static const FlagField<Flag_T> * getFlagField(const IBlock & block, ConstBlockDataID bdId) {
return block.getData<FlagField< Flag_T > >(bdId);
}
private:
FlagUID flagUID_;
FlagField<Flag_T> * flagField_;
Flag_T flag_;
};
template<typename Flag_T>
void BoundarySetter<FlagField<Flag_T> >::setConfigBlock( const Config::BlockHandle & blockHandle,
const std::set<std::string> & subblocksToIgnore )
{
// Check that either there is one sub-block with boundary information or a flag parameter
Config::Blocks boundaryConfigBlocks;
blockHandle.getBlocks ( boundaryConfigBlocks );
for( auto blockHandleIt = boundaryConfigBlocks.begin(); blockHandleIt != boundaryConfigBlocks.end(); )
{
std::string key = blockHandleIt->getKey();
if ( subblocksToIgnore.find( key ) != subblocksToIgnore.end() )
boundaryConfigBlocks.erase( blockHandleIt );
else
++blockHandleIt;
}
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
WALBERLA_ABORT_NO_DEBUG_INFO( "No boundary setup blocks are allowed when configuring a flag field"
<< blockHandle.getKey() );
}
const bool hasFlagParameter = blockHandle.isDefined( "flag" );
if( !hasFlagParameter ) {
WALBERLA_ABORT_NO_DEBUG_INFO( "Geometry Block \"" << blockHandle.getKey() << ": missing flag parameter " );
}
flagUID_ = FlagUID( blockHandle.getParameter<std::string>("flag") );
}
template<typename Flag_T>
void BoundarySetter<FlagField<Flag_T> >::setBoundaryConfigBlock( const BoundaryUID & boundaryUID, const Config::BlockHandle & blockHandle )
{
WALBERLA_ABORT("Passed boundary information to an initializer that sets up a pure flag field only");
}
template<typename Flag_T>
void BoundarySetter<FlagField<Flag_T>>::setBoundaryConfig( const BoundaryUID & boundaryUID, const shared_ptr<BoundaryConfiguration> & conf )
{
WALBERLA_ABORT("Passed boundary information to an initializer that sets up a pure flag field only");
}
template<typename Flag_T>
void BoundarySetter<FlagField<Flag_T>>::setFlagUID( const FlagUID & flag )
{
flagUID_ = flag;
}
template<typename Flag_T>
void BoundarySetter<FlagField<Flag_T>>::configure( IBlock & block, BlockDataID flagFieldID )
{
flagField_ = block.getData< FlagField<Flag_T> >( flagFieldID );
flag_ = flagField_->getOrRegisterFlag( flagUID_ );
}
template<typename Flag_T>
void BoundarySetter<FlagField<Flag_T>>::set( cell_idx_t x, cell_idx_t y, cell_idx_t z )
{
//Check if no flag is set yet to avoid multiple flags per cell on initialization
if(flagField_->get(x,y,z) == Flag_T(0))
flagField_->addFlag( x, y, z, flag_ );
}
template<typename Flag_T>
void BoundarySetter<FlagField<Flag_T>>::set( const CellInterval & ci )
{
for( auto it = flagField_->beginSliceXYZ(ci); it != flagField_->end(); ++it ) {
//Check if no flag is set yet to avoid multiple flags per cell on initialization
if(*it == Flag_T(0))
field::addFlag(it, flag_);
}
}
template<typename Flag_T>
template< typename CellIterator >
void BoundarySetter<FlagField<Flag_T> >::set( const CellIterator & begin, const CellIterator & end )
{
for(auto it = begin; it != end; ++it) {
//Check if no flag is set yet to avoid multiple flags per cell on initialization
if(flagField_->get(it->x(),it->y(),it->z()) == Flag_T(0))
flagField_->addFlag(it->x(), it->y(), it->z(), flag_);
}
}
} // namespace initializer
} // namespace geometry
} // namespace walberla