v0.15.0
Loading...
Searching...
No Matches
FormsIntegrators.cpp
Go to the documentation of this file.
1/** \file FormsIntegrators.cpp
2
3\brief Implementation of Elements on Entities for Forces and Sources
4
5*/
6
7
8
9namespace MoFEM {
10
11//! [Storage and set boundary conditions]
12
13
15
16OpSetBc::OpSetBc(std::string field_name, bool yes_set,
17 boost::shared_ptr<std::vector<unsigned char>> boundary_marker)
20 yesSet(yes_set), boundaryMarker(boundary_marker) {}
21
22MoFEMErrorCode OpSetBc::doWork(int side, EntityType type,
25 if (boundaryMarker) {
26 if (!data.getIndices().empty())
27 if (!data.getFieldEntities().empty()) {
28 if (auto e_ptr = data.getFieldEntities()[0]) {
29 auto indices = data.getIndices();
30 for (int r = 0; r != data.getIndices().size(); ++r) {
31 const auto loc_index = data.getLocalIndices()[r];
32 if (loc_index >= 0) {
33 if (yesSet) {
34 if ((*boundaryMarker)[loc_index]) {
35 indices[r] = -1;
36 }
37 } else {
38 if (!(*boundaryMarker)[loc_index]) {
39 indices[r] = -1;
40 }
41 }
42 }
43 }
44 EssentialBcStorage::feStorage[e_ptr->getName()].push_back(
45 boost::make_shared<EssentialBcStorage>(indices));
46 e_ptr->getWeakStoragePtr() =
47 EssentialBcStorage::feStorage[e_ptr->getName()].back();
48 }
49 }
50 }
52}
53
57
64
65/**
66 * @brief Set values to vector in operator
67 *
68 * @param V
69 * @param data
70 * @param ptr
71 * @param iora
72 * @return MoFEMErrorCode
73 */
74template <>
77 const double *ptr, InsertMode iora) {
78
79#ifndef NDEBUG
80 if (!V)
81 CHK_THROW_MESSAGE(MOFEM_INVALID_DATA, "Pointer to PETSc vector is null in "
82 "VecSetValues<EssentialBcStorage>");
83#endif
84
85 if (!data.getFieldEntities().empty()) {
86 if (auto e_ptr = data.getFieldEntities()[0]) {
87 if (auto stored_data_ptr =
88 e_ptr->getSharedStoragePtr<EssentialBcStorage>()) {
90 VecSetOption(V, VEC_IGNORE_NEGATIVE_INDICES, PETSC_TRUE),
91 "In VecSetValues<EssentialBcStorage> failed to set option "
92 "VEC_IGNORE_NEGATIVE_INDICES");
93 return ::VecSetValues(V, stored_data_ptr->entityIndices.size(),
94 &*stored_data_ptr->entityIndices.begin(), ptr,
95 iora);
96 }
97 }
98 }
99 // If no storage is found, use the indices from data
100 return ::VecSetValues(V, data.getIndices().size(),
101 &*data.getIndices().begin(), ptr, iora);
102}
103
104/**
105 * @brief Set values to matrix in operator
106 *
107 * @param M
108 * @param row_data
109 * @param col_data
110 * @param ptr
111 * @param iora
112 * @return MoFEMErrorCode
113 */
114template <>
117 const EntitiesFieldData::EntData &row_data,
118 const EntitiesFieldData::EntData &col_data,
119 const double *ptr, InsertMode iora) {
120
121#ifndef NDEBUG
122 if (!M)
125 "Pointer to PETSc matrix is null in MatSetValues<EssentialBcStorage>");
126#endif
127
128 if (!row_data.getFieldEntities().empty()) {
129 if (auto e_ptr = row_data.getFieldEntities()[0]) {
130 if (auto stored_data_ptr =
131 e_ptr->getSharedStoragePtr<EssentialBcStorage>()) {
132 return ::MatSetValues(M, stored_data_ptr->entityIndices.size(),
133 &*stored_data_ptr->entityIndices.begin(),
134 col_data.getIndices().size(),
135 &*col_data.getIndices().begin(), ptr, iora);
136 }
137 }
138 }
139 return ::MatSetValues(
140 M, row_data.getIndices().size(), &*row_data.getIndices().begin(),
141 col_data.getIndices().size(), &*col_data.getIndices().begin(), ptr, iora);
142}
143
144//! [Storage and set boundary conditions
145
146
147}
ForcesAndSourcesCore::UserDataOperator UserDataOperator
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_INVALID_DATA
Definition definitions.h:36
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
MoFEMErrorCode VecSetValues< EssentialBcStorage >(Vec V, const EntitiesFieldData::EntData &data, const double *ptr, InsertMode iora)
Set values to vector in operator.
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
MoFEMErrorCode MatSetValues< EssentialBcStorage >(Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const double *ptr, InsertMode iora)
Set values to matrix in operator.
constexpr auto field_name
Data on single entity (This is passed as argument to DataOperator::doWork)
const VectorFieldEntities & getFieldEntities() const
get field entities
const VectorInt & getLocalIndices() const
get local indices of dofs on entity
const VectorInt & getIndices() const
Get global indices of dofs on entity.
[Storage and set boundary conditions]
static HashVectorStorage feStorage
[Storage and set boundary conditions]
map< std::string, std::vector< boost::shared_ptr< EssentialBcStorage > > > HashVectorStorage
Store modifed indices by field.
structure to get information form mofem into EntitiesFieldData
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
OpSetBc(std::string field_name, bool yes_set, boost::shared_ptr< std::vector< unsigned char > > boundary_marker)
boost::shared_ptr< std::vector< unsigned char > > boundaryMarker
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
OpUnSetBc(std::string field_name)