v0.9.0
FieldBlas.hpp
Go to the documentation of this file.
1 /** \file FieldBlas.hpp
2  * \brief Field basic algebra
3  * \ingroup mofem_is_managers
4  *
5  * Managing problems, build and partitioning.
6  *
7  */
8 
9 /*
10  * MoFEM is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13  * License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>
17  */
18 
19 #ifndef __FIELD_BLAS_HPP__
20 #define __FIELD_BLAS_HPP__
21 
22 #include "UnknownInterface.hpp"
23 
24 namespace MoFEM {
25 
28 
29 /**
30  * \brief Basic algebra on fields
31  * \ingroup mofem_field_algebra
32  *
33  */
34 struct FieldBlas : public UnknownInterface {
35 
37  UnknownInterface **iface) const;
38 
40  bool dEbug;
41 
42  FieldBlas(const MoFEM::Core &core);
43 
44  /**
45  * \brief Destructor
46  */
47  ~FieldBlas();
48 
49  typedef boost::function<MoFEMErrorCode(double &, const double)>
51 
52  /** \brief filed lambda
53  * \ingroup mofem_field_algebra
54  *
55  * Do calculation on two fields and save result to field fy
56  *
57  * \code
58  struct Axpy {
59  const double aLpha;
60  Axpy(const double alpha) : aLpha(alpha) {}
61  inline MoFEMErrorCode operator(double &fy, double fx) {
62  MoFEMFunctionBeginHot;
63  fy += Alpha * fx;
64  MoFEMFunctionReturnHot(0);
65  }
66  };
67  CHKERR m_fiel.getInterface<FieldBlas>()->fieldLambda(Axpy(aLpha),
68  field_name_x, field_name_y);
69  * \endcode
70  *
71  * \param function f(double &x, double)
72  * \param field_name_x name of field_x
73  * \param field_name_y name of field_y
74  * \param error_if_missing throw error if entity/dof exist in field_x but not
75  * on field_y \param create_if_missing creat dof in field_y from field_x if it
76  * is not database
77  *
78  */
80  const std::string field_name_x,
81  const std::string field_name_y,
82  bool error_if_missing = false,
83  bool creat_if_missing = false);
84 
85  /** \brief axpy fields
86  * \ingroup mofem_field_algebra
87  *
88  * field_y = field_y + alpha*field_x
89  *
90  * \param alpha
91  * \param field_name_x name of field_x
92  * \param field_name_y name of field_y
93  * \param error_if_missing throw error if entity/dof exist in field_x but not
94  * on field_y \param create_if_missing creat dof in field_y from fiedl_x if it
95  * is not database
96  *
97  */
98  MoFEMErrorCode fieldAxpy(const double alpha, const std::string field_name_x,
99  const std::string field_name_y,
100  bool error_if_missing = false,
101  bool creat_if_missing = false);
102 
103  /** \brief copy and scale fields
104  * \ingroup mofem_field_algebra
105  *
106  * field_y = alpha*field_x
107  *
108  * \param alpha
109  * \param field_name_x name of field_x
110  * \param field_name_y name of field_y
111  * \param error_if_missing throw error if entity/dof exist in field_x but not
112  * on field_y \param create_if_missing creat dof in field_y from fiedl_x if it
113  * is not database
114  *
115  */
116  MoFEMErrorCode fieldCopy(const double alpha, const std::string field_name_x,
117  const std::string field_name_y,
118  bool error_if_missing = false,
119  bool creat_if_missing = false);
120 
121  typedef boost::function<MoFEMErrorCode(VectorAdaptor &&field_data,
122  double *xcoord, double *ycoord,
123  double *zcoord)>
125 
126  /** \brief Set DOFs on vertices using user function
127  * \ingroup mofem_field_algebra
128  *
129  * Example:
130  *
131  * \code
132  * auto do_something = [&](VectorAdaptor &field_data, double *x,
133  * double *y, double *z) {
134  * MoFEMFunctionBegin;
135  * field_data[0] = (*x);
136  * field_data[1] = (*y);
137  * field_data[2] = (*z);
138  * MoFEMFunctionReturn(0);
139  * };
140  * CHKERR m_field.getInterface<FieldBlas>()->setVertexDofs(set_distance,
141  * "DISP"); \endcode
142  *
143  * \note Function works both ways, using it coordinates can be set from field.
144  *
145  * \param lambda function evaluating field at points
146  * \param field_name is a field name
147  * \param verts pointer to vertices if null all vertices in the field are
148  * evaluated)
149  *
150  */
152  const std::string field_name,
153  Range *verts = nullptr);
154 
155  /** \brief scale field
156  * \ingroup mofem_field_algebra
157  *
158  * \param val is a set parameter
159  * \field_name is a field name
160  *
161  */
162  MoFEMErrorCode setField(const double val, const EntityType type,
163  const std::string field_name);
164 
165  /** \brief set field
166  * \ingroup mofem_field_algebra
167  *
168  * field_y = val
169  *
170  * \param val
171  * \param entity type
172  * \param field_name
173  *
174  */
175  MoFEMErrorCode setField(const double val, const EntityType type,
176  const Range &ents, const std::string field_name);
177 
178  /** \brief set field
179  * \ingroup mofem_field_algebra
180  *
181  * field_y = val
182  *
183  * \param val
184  * \param field_name
185  *
186  */
187  MoFEMErrorCode setField(const double val, const std::string field_name);
188 
189  /** \brief set field
190  * \ingroup mofem_field_algebra
191  *
192  * field_y = val
193  *
194  * \param val
195  * \param entity type
196  * \param on enties
197  * \param field_name
198  *
199  */
200  MoFEMErrorCode fieldScale(const double alpha, const std::string field_name);
201 };
202 
203 } // namespace MoFEM
204 
205 #endif // __FIELD_BLAS_HPP__
206 
207 /**
208  * \defgroup mofem_field_algebra Field Basic Algebra
209  * \brief Basic algebraic operation on fields
210  *
211  * \ingroup mofem
212  */
MoFEM interface unique ID.
FieldBlas(const MoFEM::Core &core)
Definition: FieldBlas.cpp:34
MoFEMErrorCode setField(const double val, const EntityType type, const std::string field_name)
scale field
Definition: FieldBlas.cpp:243
boost::function< MoFEMErrorCode(double &, const double)> TwoFieldFunction
Definition: FieldBlas.hpp:50
base class for all interface classes
Core (interface) class.
Definition: Core.hpp:50
MoFEM interface.
boost::function< MoFEMErrorCode(VectorAdaptor &&field_data, double *xcoord, double *ycoord, double *zcoord)> VertexCoordsFunction
Definition: FieldBlas.hpp:124
MoFEMErrorCode fieldAxpy(const double alpha, const std::string field_name_x, const std::string field_name_y, bool error_if_missing=false, bool creat_if_missing=false)
axpy fieldsfield_y = field_y + alpha*field_x
Definition: FieldBlas.cpp:135
std::bitset< BITINTERFACEUID_SIZE > BitIntefaceId
Definition: Types.hpp:56
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
MoFEMErrorCode query_interface(const MOFEMuuid &uuid, UnknownInterface **iface) const
Definition: FieldBlas.cpp:22
const MoFEM::Interface & cOre
Definition: FieldBlas.hpp:39
MoFEMErrorCode fieldScale(const double alpha, const std::string field_name)
set fieldfield_y = val
Definition: FieldBlas.cpp:308
~FieldBlas()
Destructor.
Definition: FieldBlas.cpp:36
Basic algebra on fields.
Definition: FieldBlas.hpp:34
MoFEMErrorCode fieldLambda(TwoFieldFunction lambda, const std::string field_name_x, const std::string field_name_y, bool error_if_missing=false, bool creat_if_missing=false)
filed lambdaDo calculation on two fields and save result to field fy
Definition: FieldBlas.cpp:38
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:66
VectorShallowArrayAdaptor< double > VectorAdaptor
Definition: Types.hpp:101
static const MOFEMuuid IDD_MOFEMFieldBlas
Definition: FieldBlas.hpp:26
MoFEMErrorCode fieldCopy(const double alpha, const std::string field_name_x, const std::string field_name_y, bool error_if_missing=false, bool creat_if_missing=false)
copy and scale fieldsfield_y = alpha*field_x
Definition: FieldBlas.cpp:155
MoFEMErrorCode setVertexDofs(VertexCoordsFunction lambda, const std::string field_name, Range *verts=nullptr)
Set DOFs on vertices using user functionExample:
Definition: FieldBlas.cpp:175