FaceDoFFunction.hpp 8.03 KB
Newer Older
1
/*
Marcus Mohr's avatar
Marcus Mohr committed
2
 * Copyright (c) 2017-2021 Daniel Drzisga, Dominik Thoennes, Marcus Mohr, Nils Kohl.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 *
 * This file is part of HyTeG
 * (see https://i10git.cs.fau.de/hyteg/hyteg).
 *
 * 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 3 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/>.
 */
Dominik Test2's avatar
Dominik Test2 committed
20
21
#pragma once

22
#include "hyteg/boundary/BoundaryConditions.hpp"
23
24
#include "hyteg/functions/Function.hpp"
#include "hyteg/functions/FunctionProperties.hpp"
25
26
#include "hyteg/p1functionspace/P1Function.hpp"

27
28
29
30
31
32
#include "FaceDoFDataHandling.hpp"
#include "FaceDoFMacroEdge.hpp"
#include "FaceDoFMacroFace.hpp"
#include "FaceDoFMacroVertex.hpp"
#include "FaceDoFMemory.hpp"
#include "FaceDoFPackInfo.hpp"
33

34
namespace hyteg {
Dominik Test2's avatar
Dominik Test2 committed
35

36
template < typename ValueType >
37
class FaceDoFFunction : public Function< FaceDoFFunction< ValueType > >
38
{
39
 public:
40
41
42
43
44
   typedef ValueType valueType;

   template < typename VType >
   using FunctionType = FaceDoFFunction< VType >;

45
46
47
48
   FaceDoFFunction( const std::string&                         name,
                    const std::shared_ptr< PrimitiveStorage >& storage,
                    uint_t                                     minLevel,
                    uint_t                                     maxLevel );
49

50
   FaceDoFFunction( const std::string&                         name,
51
52
53
54
                    const std::shared_ptr< PrimitiveStorage >& storage,
                    uint_t                                     minLevel,
                    uint_t                                     maxLevel,
                    BoundaryCondition                          boundaryCondition );
55

56
   void interpolate( const std::function< ValueType( const Point3D& ) >& expr, uint_t level, DoFType flag = All ) const;
57

58
   void interpolate( ValueType constant, uint_t level, DoFType flag = All ) const;
Marcus Mohr's avatar
Marcus Mohr committed
59

60
61
62
63
   void interpolate( const std::function< ValueType( const Point3D&, const std::vector< ValueType >& ) >& expr,
                     const std::vector< std::reference_wrapper< const FaceDoFFunction< ValueType > > >&   srcFunctions,
                     uint_t                                                                               level,
                     DoFType                                                                              flag = All ) const;
64

65
66
67
   void interpolate( const std::vector< std::function< ValueType( const hyteg::Point3D& ) > >& expr,
                     uint_t                                                                    level,
                     DoFType                                                                   flag = All ) const;
68

69
   void assign( const std::vector< ValueType >&                                                    scalars,
70
                const std::vector< std::reference_wrapper< const FaceDoFFunction< ValueType > > >& functions,
71
72
                uint_t                                                                             level,
                DoFType                                                                            flag = All ) const;
73

74
   void add( ValueType scalar, uint_t level, DoFType flag = All ) const;
75

76
77
78
79
   void add( const std::vector< ValueType >&                                                    scalars,
             const std::vector< std::reference_wrapper< const FaceDoFFunction< ValueType > > >& functions,
             uint_t                                                                             level,
             DoFType                                                                            flag = All ) const;
80

81
   void enumerate( uint_t level, ValueType offset );
82

83
   void enumerate( uint_t level );
84

85
86
87
   ValueType getMaxValue( uint_t level, DoFType flag = All );
   ValueType getMinValue( uint_t level, DoFType flag = All );
   ValueType getMaxMagnitude( uint_t level, DoFType flag = All );
88
89
90
91
92
93
94

   const PrimitiveDataID< FunctionMemory< ValueType >, Vertex >& getVertexDataID() const { return vertexDataID_; }

   const PrimitiveDataID< FunctionMemory< ValueType >, Edge >& getEdgeDataID() const { return edgeDataID_; }

   const PrimitiveDataID< FunctionMemory< ValueType >, Face >& getFaceDataID() const { return faceDataID_; }

95
   BoundaryCondition getBoundaryCondition() const { return boundaryCondition_; }
96
97

   template < typename SenderType, typename ReceiverType >
98
   void startCommunication( const uint_t& level ) const
99
100
101
102
103
   {
      communicators_.at( level )->template startCommunication< SenderType, ReceiverType >();
   }

   template < typename SenderType, typename ReceiverType >
104
   void endCommunication( const uint_t& level ) const
105
106
107
108
   {
      communicators_.at( level )->template endCommunication< SenderType, ReceiverType >();
   }

Marcus Mohr's avatar
Marcus Mohr committed
109
   template < typename SenderType, typename ReceiverType >
110
   void communicate( const uint_t& level ) const
Marcus Mohr's avatar
Marcus Mohr committed
111
112
113
114
   {
      startCommunication< SenderType, ReceiverType >( level );
      endCommunication< SenderType, ReceiverType >( level );
   }
115

116
   void setLocalCommunicationMode( const communication::BufferedCommunicator::LocalCommunicationMode& localCommunicationMode )
117
118
119
120
121
122
123
   {
      for ( auto& communicator : communicators_ )
      {
         communicator.second->setLocalCommunicationMode( localCommunicationMode );
      }
   }

Marcus Mohr's avatar
Marcus Mohr committed
124
125
126
127
128
129
130
131
132
133
134
   /// Compute the product of several functions in an elementwise fashion
   ///
   /// The method takes as input a collection of functions. These are multiplied together in an elementwise fashion.
   /// The latter is to be understood not in a FE context, but in the sense of element-wise operators in matrix/array
   /// oriented languages, i.e. the product is a function of the same type as the inputs and its DoFs are formed as
   /// product of the corresponding DoFs of the input functions. The result is stored in the function object on which
   /// the method is invoked, overwritting its contents. It is safe, if the destination function is part of the product.
   ///
   /// \param functions  the functions forming the product
   /// \param level      level on which the multiplication should be computed
   /// \param flag       marks those primitives which are partaking in the computation of the product
135
136
137
   void multElementwise( const std::vector< std::reference_wrapper< const FaceDoFFunction< ValueType > > >& functions,
                         uint_t                                                                             level,
                         DoFType                                                                            flag = All ) const;
Marcus Mohr's avatar
Marcus Mohr committed
138

139
   void copyFrom( const FaceDoFFunction< ValueType >& other, const uint_t& level ) const;
140

141
142
143
144
   void copyFrom( const FaceDoFFunction< ValueType >&            other,
                  const uint_t&                                  level,
                  const std::map< PrimitiveID::IDType, uint_t >& localPrimitiveIDsToRank,
                  const std::map< PrimitiveID::IDType, uint_t >& otherPrimitiveIDsToRank ) const;
145

146
   void setBoundaryCondition( BoundaryCondition bc ) { boundaryCondition_ = std::move( bc ); }
Marcus Mohr's avatar
Marcus Mohr committed
147

148
   ValueType dotLocal( const FaceDoFFunction< ValueType >& secondOp, uint_t level, DoFType flag ) const;
Marcus Mohr's avatar
Marcus Mohr committed
149

150
   ValueType dotGlobal( const FaceDoFFunction< ValueType >& secondOp, uint_t level, DoFType flag ) const;
151

152
   void swap( const FaceDoFFunction< ValueType >& other, const uint_t& level, const DoFType& flag = All ) const;
Marcus Mohr's avatar
Marcus Mohr committed
153

154
 private:
155
   using Function< FaceDoFFunction< ValueType > >::communicators_;
156
157
158
159
160
161

   PrimitiveDataID< FunctionMemory< ValueType >, Vertex > vertexDataID_;
   PrimitiveDataID< FunctionMemory< ValueType >, Edge >   edgeDataID_;
   PrimitiveDataID< FunctionMemory< ValueType >, Face >   faceDataID_;

   BoundaryCondition boundaryCondition_;
Dominik Test2's avatar
Dominik Test2 committed
162
};
Dominik Thoennes's avatar
Dominik Thoennes committed
163

164
} // namespace hyteg