FieldInterpolatorCreators.h 4.88 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
30
31
32
33
34
35
36
37
38
39
//======================================================================================================================
//
//  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 FieldInterpolatorCreators.h
//! \ingroup field
//! \author Christoph Rettinger <christoph.rettinger@fau.de>
//
//======================================================================================================================

#pragma once

#include "core/DataTypes.h"
#include "core/Set.h"

#include "blockforest/BlockDataHandling.h"

#include "domain_decomposition/StructuredBlockStorage.h"

namespace walberla {
namespace field {

//**********************************************************************************************************************
/*! FieldInterpolatorCreators
 *
 * \ingroup field
 *
 * Interpolator_T: A field interpolator that has a constructor
40
 *  ( const weak_ptr<StructuredBlockStorage> & blockStorage, const IBlock & block, const BaseField_T & baseField,
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 *    const FlagField_T & flagField, const flag_t & evaluationMask )
 * and getter functions:
 *  template< typename ForwardIterator_T > inline void get( const Vector3<real_t> & position, ForwardIterator_T interpolationResultBegin )
 *  template< typename ForwardIterator_T > inline void get( const real_t & x, const real_t & y, const real_t & z, ForwardIterator_T interpolationResultBegin )
 *
 * See TrilinearFieldInterpolator for an example implementation.
 *
 * A field interpolator is aware of the flag field (FlagField_T) and uses only values that contain flags from a given mask.
 *
 * Field Interpolators can be used to sample the underlying field at certain positions.
 * E.g. the fluid velocity can be interpolated to a desired global position from a velocity field.
 *
 */
//**********************************************************************************************************************
template< typename Interpolator_T, typename FlagField_T >
class InterpolatorHandling : public blockforest::AlwaysInitializeBlockDataHandling< Interpolator_T >
{
public:

60
   InterpolatorHandling( const weak_ptr<StructuredBlockStorage> & blockStorage,
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
                         const ConstBlockDataID & interpolatedFieldID,
                         const ConstBlockDataID & flagFieldID,
                         const Set< FlagUID > & cellsToEvaluate ) :
   blockStorage_( blockStorage ), interpolatedFieldID_( interpolatedFieldID ), flagFieldID_( flagFieldID ), cellsToEvaluate_( cellsToEvaluate )
   {}

   Interpolator_T * initialize( IBlock * const block )
   {
      typedef typename Interpolator_T::BaseField_T InterpolatedField_T;
      typedef typename FlagField_T::flag_t flag_t;
      const InterpolatedField_T * interpolatedField = block->getData< InterpolatedField_T >( interpolatedFieldID_ );
      const FlagField_T * flagField = block->getData< FlagField_T >( flagFieldID_ );

      WALBERLA_ASSERT_NOT_NULLPTR( interpolatedField );
      WALBERLA_ASSERT_NOT_NULLPTR( flagField );

      const flag_t evaluationMask = flagField->getMask( cellsToEvaluate_ );

      return new Interpolator_T( blockStorage_, *block, *interpolatedField, *flagField, evaluationMask );
   }

private:

84
   weak_ptr<StructuredBlockStorage> blockStorage_;
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
   ConstBlockDataID interpolatedFieldID_;
   ConstBlockDataID flagFieldID_;
   Set< FlagUID > cellsToEvaluate_;
   
}; // class InterpolatorHandling



template< typename Interpolator_T, typename FlagField_T  >
inline BlockDataID addFieldInterpolator( const shared_ptr< StructuredBlockStorage > & blocks,
                                         const ConstBlockDataID & interpolatedFieldID,
                                         const ConstBlockDataID & flagFieldID,
                                         const Set< FlagUID > & cellsToEvaluate,
                                         const std::string & identifier = std::string(),
                                         const Set<SUID> & requiredSelectors     = Set<SUID>::emptySet(),
                                         const Set<SUID> & incompatibleSelectors = Set<SUID>::emptySet() )
{
   return blocks->addBlockData( make_shared< InterpolatorHandling< Interpolator_T, FlagField_T > >( blocks, interpolatedFieldID, flagFieldID, cellsToEvaluate ), identifier, requiredSelectors, incompatibleSelectors );
}


} // namespace field
} // namespace walberla