v0.14.0
NormsOperators.cpp
Go to the documentation of this file.
1 /** \file NormsOperators.cpp
2 
3 \brief User data operators for calculating norms and differences between
4 fields
5 
6 */
7 
8 namespace MoFEM {
9 
11  boost::shared_ptr<VectorDouble> data_ptr, SmartPetscObj<Vec> data_vec,
12  const int index, boost::shared_ptr<VectorDouble> diff_data_ptr)
15  dataPtr(data_ptr), dataVec(data_vec), iNdex(index),
16  diffDataPtr(diff_data_ptr) {
17  if (!dataPtr)
18  THROW_MESSAGE("Pointer is not set");
19  if (!diffDataPtr)
21 }
22 
26 
27  // calculate the difference between data pointers and save them in diffDataPtr
28  if (dataPtr != diffDataPtr)
29  *diffDataPtr -= *dataPtr;
30 
31  // get number of integration points
32  const auto nb_integration_points = getGaussPts().size2();
33  // get element volume
34  const double vol = getMeasure();
35  // get integration weights
36  auto t_w = getFTensor0IntegrationWeight();
37  // get values
38  auto t_data = getFTensor0FromVec(*dataPtr);
39  // initialise double to store norm values
40  double norm_on_element = 0.;
41  // loop over integration points
42  for (int gg = 0; gg != nb_integration_points; gg++) {
43  // add to element norm
44  norm_on_element += t_w * t_data * t_data;
45  // move to another integration weight
46  ++t_w;
47  // move to another data values
48  ++t_data;
49  }
50  // scale with volume of the element
51  norm_on_element *= vol;
52  // add to dataVec at iNdex position
53  CHKERR VecSetValue(dataVec, iNdex, norm_on_element, ADD_VALUES);
54 
56 }
57 
58 template <int DIM>
60  boost::shared_ptr<MatrixDouble> data_ptr, SmartPetscObj<Vec> data_vec,
61  const int index, boost::shared_ptr<MatrixDouble> diff_data_ptr)
64  dataPtr(data_ptr), dataVec(data_vec), iNdex(index),
65  diffDataPtr(diff_data_ptr) {
66  if (!dataPtr)
67  THROW_MESSAGE("Pointer is not set");
68  if (!diffDataPtr)
70 }
71 
72 template <int DIM>
77 
78  // calculate the difference between data pointers and save them in diffDataPtr
79  if (dataPtr != diffDataPtr)
80  *diffDataPtr -= *dataPtr;
81 
82  // Declare FTensor index
84  // get number of integration points
85  const auto nb_integration_points = getGaussPts().size2();
86  // get element volume
87  const double vol = getMeasure();
88  // get integration weights
89  auto t_w = getFTensor0IntegrationWeight();
90  // get vector values
91  auto t_data = getFTensor1FromMat<DIM>(*diffDataPtr);
92  // initialise double to store norm values
93  double norm_on_element = 0.;
94  // loop over integration points
95  for (int gg = 0; gg != nb_integration_points; ++gg) {
96  // add to element norm
97  norm_on_element += t_w * (t_data(i) * t_data(i));
98  // move to another integration weight
99  ++t_w;
100  // move to another data values
101  ++t_data;
102  }
103  // scale with volume of the element
104  norm_on_element *= vol;
105  // add to dataVec at iNdex position
106  CHKERR VecSetValue(dataVec, iNdex, norm_on_element, ADD_VALUES);
107 
109 }
110 
111 template <int DIM_1, int DIM_2>
113  boost::shared_ptr<MatrixDouble> data_ptr, SmartPetscObj<Vec> data_vec,
114  const int index, boost::shared_ptr<MatrixDouble> diff_data_ptr)
117  dataPtr(data_ptr), dataVec(data_vec), iNdex(index),
118  diffDataPtr(diff_data_ptr) {
119  if (!dataPtr)
120  THROW_MESSAGE("Pointer is not set");
121  if (!diffDataPtr)
123 }
124 
125 template <int DIM_1, int DIM_2>
130 
131  // calculate the difference between data pointers and save them in diffDataPtr
132  if (dataPtr != diffDataPtr)
133  *diffDataPtr -= *dataPtr;
134 
135  // Declare FTensor index
138  // get number of integration points
139  const auto nb_integration_points = getGaussPts().size2();
140  // get element volume
141  const double vol = getMeasure();
142  // get integration weights
143  auto t_w = getFTensor0IntegrationWeight();
144  // get vector values
145  auto t_data = getFTensor2FromMat<DIM_1, DIM_2>(*dataPtr);
146  // initialise double to store norm values
147  double norm_on_element = 0.;
148  // loop over integration points
149  for (int gg = 0; gg != nb_integration_points; gg++) {
150  // add to element norm
151  norm_on_element += t_w * (t_data(i, j) * t_data(i, j));
152  // move to another integration weight
153  ++t_w;
154  // move to another data values
155  ++t_data;
156  }
157  // scale with volume of the element
158  norm_on_element *= vol;
159  // add to dataVec at iNdex position
160  CHKERR VecSetValue(dataVec, iNdex, norm_on_element, ADD_VALUES);
161 
163 }
164 
165 template struct OpCalcNormL2Tensor1<2>;
166 template struct OpCalcNormL2Tensor1<3>;
167 template struct MoFEM::OpCalcNormL2Tensor2<2, 2>;
168 template struct MoFEM::OpCalcNormL2Tensor2<3, 3>;
169 
170 } // namespace MoFEM
NOSPACE
@ NOSPACE
Definition: definitions.h:83
MoFEM::EntitiesFieldData::EntData
Data on single entity (This is passed as argument to DataOperator::doWork)
Definition: EntitiesFieldData.hpp:127
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
THROW_MESSAGE
#define THROW_MESSAGE(msg)
Throw MoFEM exception.
Definition: definitions.h:561
MoFEM::OpCalcNormL2Tensor2::OpCalcNormL2Tensor2
OpCalcNormL2Tensor2(boost::shared_ptr< MatrixDouble > data_ptr, SmartPetscObj< Vec > data_vec, const int index, boost::shared_ptr< MatrixDouble > diff_data_ptr=nullptr)
Definition: NormsOperators.cpp:112
MoFEM::ForcesAndSourcesCore::UserDataOperator::getFTensor0IntegrationWeight
auto getFTensor0IntegrationWeight()
Get integration weights.
Definition: ForcesAndSourcesCore.hpp:1239
MoFEM::ForcesAndSourcesCore::UserDataOperator::getMeasure
double getMeasure() const
get measure of element
Definition: ForcesAndSourcesCore.hpp:1274
MoFEM::OpCalcNormL2Tensor2::dataPtr
boost::shared_ptr< MatrixDouble > dataPtr
Definition: NormsOperators.hpp:86
MoFEM::ForcesAndSourcesCore::UserDataOperator::getGaussPts
MatrixDouble & getGaussPts()
matrix of integration (Gauss) points for Volume Element
Definition: ForcesAndSourcesCore.hpp:1235
MoFEM::OpCalcNormL2Tensor1::dataPtr
boost::shared_ptr< MatrixDouble > dataPtr
Definition: NormsOperators.hpp:59
MoFEM::OpCalcNormL2Tensor2
Get norm of input MatrixDouble for Tensor2.
Definition: NormsOperators.hpp:69
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
MoFEM::ForcesAndSourcesCore::UserDataOperator
Definition: ForcesAndSourcesCore.hpp:549
convert.type
type
Definition: convert.py:64
MoFEM::getFTensor0FromVec
static auto getFTensor0FromVec(ublas::vector< T, A > &data)
Get tensor rank 0 (scalar) form data vector.
Definition: Templates.hpp:135
MoFEM::OpCalcNormL2Tensor0::OpCalcNormL2Tensor0
OpCalcNormL2Tensor0(boost::shared_ptr< VectorDouble > data_ptr, SmartPetscObj< Vec > data_vec, const int index, boost::shared_ptr< VectorDouble > diff_data_ptr=nullptr)
Definition: NormsOperators.cpp:10
MoFEM::OpCalcNormL2Tensor2::doWork
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
calculate values of scalar field at integration points
Definition: NormsOperators.cpp:127
MoFEM::OpCalcNormL2Tensor0::dataPtr
boost::shared_ptr< VectorDouble > dataPtr
Definition: NormsOperators.hpp:32
MoFEM::OpCalcNormL2Tensor1
Get norm of input MatrixDouble for Tensor1.
Definition: NormsOperators.hpp:42
MoFEM::OpCalcNormL2Tensor2::diffDataPtr
boost::shared_ptr< MatrixDouble > diffDataPtr
Definition: NormsOperators.hpp:87
MoFEM::OpCalcNormL2Tensor0::iNdex
const int iNdex
Definition: NormsOperators.hpp:35
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
MoFEM::OpCalcNormL2Tensor0::dataVec
SmartPetscObj< Vec > dataVec
Definition: NormsOperators.hpp:34
FTensor::Index< 'i', DIM >
MoFEM::ForcesAndSourcesCore
structure to get information form mofem into EntitiesFieldData
Definition: ForcesAndSourcesCore.hpp:22
MoFEM::OpCalcNormL2Tensor1::OpCalcNormL2Tensor1
OpCalcNormL2Tensor1(boost::shared_ptr< MatrixDouble > data_ptr, SmartPetscObj< Vec > data_vec, const int index, boost::shared_ptr< MatrixDouble > diff_data_ptr=nullptr)
Definition: NormsOperators.cpp:59
j
FTensor::Index< 'j', 3 > j
Definition: matrix_function.cpp:19
MoFEM::OpCalcNormL2Tensor1::doWork
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
calculate values of scalar field at integration points
Definition: NormsOperators.cpp:74
MoFEM::SmartPetscObj< Vec >
MoFEM::OpCalcNormL2Tensor0::diffDataPtr
boost::shared_ptr< VectorDouble > diffDataPtr
Definition: NormsOperators.hpp:33
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
MoFEM::OpCalcNormL2Tensor1::diffDataPtr
boost::shared_ptr< MatrixDouble > diffDataPtr
Definition: NormsOperators.hpp:60
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
MoFEM::OpCalcNormL2Tensor0::doWork
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
calculate values of scalar field at integration points
Definition: NormsOperators.cpp:23