ScalarFieldFromBody.h 6.77 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
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
//======================================================================================================================
//
//  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 ScalarFieldFromBody.h
//! \ingroup geometry
//! \author Michael Kuron <mkuron@icp.uni-stuttgart.de>
//
//======================================================================================================================

#pragma once

#include "geometry/initializer/Initializer.h"
#include "domain_decomposition/StructuredBlockStorage.h"
#include "core/math/Parser.h"


namespace walberla {
namespace geometry {
namespace initializer {



   //*******************************************************************************************************************
   /*! Initializes a scalar field from a geometric body
   *
   * Currently supported are Sphere, Ellipsoid and Box (= AABB)
   *
   * Examples:
   * \verbatim
       <InitializerUID> {
            initialFill : drop;
            someArbitraryId {
               shape sphere;
               add;                  // add to the current value in the field
               value 1.0;
               midpoint < 3,4,5>;
               radius 4;
               id 0;                 // If given a vector of scalar fields, which one of them to operate on.
                                     // Should be zero (the default value) if given a scalar field directly.
            }
            object2 {
               shape box;
               add;
               value -3.14;
               min <1,2,3>;
               max <3,4,5>;
            }
            object3_ellipse {
               set;                  // overwrite the current value in the field
               value 0;
               shape ellipsoid;
               midpoint < 3,4,2>;
               axis1    <1,0,0>;
               axis2    <0,1,0>;
               radii    <1,1,4>;
            }
       }
     \endverbatim
   *
   * \ingroup geometry
   *
   */
   //*******************************************************************************************************************
   template <typename Field_T>
   class ScalarFieldFromBody : public Initializer
   {
   public:
80
      using Value_T = typename Field_T::value_type;
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
      
      /*************************************************************************************************************//**
      * Constructor
      *
      * \param scalarFieldID    the scalar field to initialize,
                                or a vector of scalar fields to initialize based on the id specified with the body
      *
      *****************************************************************************************************************/
      ScalarFieldFromBody( StructuredBlockStorage & structuredBlockStorage, BlockDataID scalarFieldID )
         : ScalarFieldFromBody(structuredBlockStorage, std::vector<BlockDataID>(1, scalarFieldID))
      {}
      ScalarFieldFromBody( StructuredBlockStorage & structuredBlockStorage, std::vector<BlockDataID> scalarFieldID );



      /*************************************************************************************************************//**
      * Interface implementation for Initializer - sets a body on a scalar field with options from configuration file
      *
      *****************************************************************************************************************/
Sebastian Eibl's avatar
Sebastian Eibl committed
100
      void init( BlockStorage & blockStorage, const Config::BlockHandle & blockHandle ) override;
101
102
103
104
105
106
107
108
109
110
111
112



      /*************************************************************************************************************//**
      * Sets a body on the scalar field
      *
      * \param body       The body object - has to implement either overlapFraction(...), or contains(...)
      *                   see BodyOverlapFunctions for detailed body concept
      * \param value      The value to set on the matched cells in the field.
      * \param addOrSet   If true, the value is added to scalar field
      *                   If false, the value is set on the scalar field.
      * \param id         If operating on a vector of fields, which field to treat. Zero otherwise.
Jean-Noël Grad's avatar
Jean-Noël Grad committed
113
      *
114
115
116
117
118
119
120
      *  Supported bodies are Sphere, Ellipsoid, AABB.
      *  To add a new supported body implement concept defined in BodyOverlapFunctions.h, and
      *  add an explicit template instantiation in ScalarFieldFromBody.cpp for the new body.
      *
      *****************************************************************************************************************/
      template<typename Body>
      void init( const Body & body, Value_T value, bool addOrSet, std::vector<BlockDataID>::size_type id = 0 );
Jean-Noël Grad's avatar
Jean-Noël Grad committed
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
      /*************************************************************************************************************//**
      * Sets a body on the scalar field
      *
      * \param body       The body object - has to implement either overlapFraction(...), or contains(...)
      *                   see BodyOverlapFunctions for detailed body concept
      * \param parser     A function parser which will have the variables x,y,z bound before it is evaluated
      * \param addOrSet   If true, the value is added to scalar field
      *                   If false, the value is set on the scalar field.
      * \param id         If operating on a vector of fields, which field to treat. Zero otherwise.
      *
      *  Supported bodies are Sphere, Ellipsoid, AABB.
      *  To add a new supported body implement concept defined in BodyOverlapFunctions.h, and
      *  add an explicit template instantiation in ScalarFieldFromBody.cpp for the new body.
      *
      *****************************************************************************************************************/
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
      template<typename Body>
      void init( const Body & body, math::FunctionParser & parser, bool addOrSet, std::vector<BlockDataID>::size_type id = 0 );


   protected:

      StructuredBlockStorage & structuredBlockStorage_;
      std::vector<BlockDataID> scalarFieldID_;

      std::string              addKeyword_;
      std::string              setKeyword_;
   };




} // namespace initializer
} // namespace geometry
} // namespace walberla

#include "ScalarFieldFromBody.impl.h"