v0.13.2
Loading...
Searching...
No Matches
SeriesMultiIndices.cpp
Go to the documentation of this file.
1/** \file SeriesMultiIndices.cpp
2 * \brief Data structures for time series and load series storage,
3 */
4
5
6namespace MoFEM {
7
8FieldSeries::FieldSeries(moab::Interface &moab, const EntityHandle _meshset)
9 : meshset(_meshset), tagName(NULL), tagNameSize(0), record_begin(false),
10 record_end(false) {
11
12 Tag th_SeriesName;
13 rval = moab.tag_get_handle("_SeriesName", th_SeriesName);
15 rval = moab.tag_get_by_ptr(th_SeriesName, &meshset, 1,
16 (const void **)&tagName, &tagNameSize);
18
19 const int def_val_len = 0;
20
21 // time
22 std::string Tag_SeriesTime = "_SeriesTime_" + getName();
23 double def_time = 0;
24 rval = moab.tag_get_handle(Tag_SeriesTime.c_str(), 1, MB_TYPE_DOUBLE,
25 th_SeriesTime, MB_TAG_CREAT | MB_TAG_SPARSE,
26 &def_time);
28
29 // handles
30 std::string Tag_DataHandles_SeriesName = "_SeriesDataHandles_" + getName();
31 rval = moab.tag_get_handle(
32 Tag_DataHandles_SeriesName.c_str(), def_val_len, MB_TYPE_HANDLE,
33 th_SeriesDataHandles, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN, NULL);
35
36 // uids
37 std::string Tag_DataUIDs_SeriesName = "_SeriesDataUIDs_" + getName();
38 rval = moab.tag_get_handle(
39 Tag_DataUIDs_SeriesName.c_str(), def_val_len, MB_TYPE_OPAQUE,
41 MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_BYTES | MB_TAG_VARLEN, NULL);
43
44 // data
45 std::string Tag_Data_SeriesName = "_SeriesData_" + getName();
46 rval = moab.tag_get_handle(
47 Tag_Data_SeriesName.c_str(), def_val_len, MB_TYPE_OPAQUE, th_SeriesData,
48 MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_BYTES | MB_TAG_VARLEN, NULL);
50}
51
53 int &nb_steps) const {
55 CHKERR moab.num_contained_meshsets(meshset, &nb_steps);
57}
58
60 const FieldData val) {
62 if (!record_begin) {
63 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
64 "you neet to set recording");
65 }
66 handles.push_back(ent);
67 uids.push_back(uid);
68 data.push_back(val);
70}
71
74 if (record_begin) {
75 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
76 "recording already begin");
77 }
78 record_begin = true;
80}
81
84 if (!record_begin) {
85 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
86 "recording not begin it can not be ended");
87 }
88 record_begin = false;
89 record_end = true;
90 ia.push_back(uids.size());
91 time.push_back(t);
93}
94
95MoFEMErrorCode FieldSeries::read(moab::Interface &moab) {
97
98 if (record_begin) {
99 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
100 "all series data will be lost");
101 }
102 if (record_end) {
103 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
104 "all series data will be lost");
105 }
106
107 std::vector<EntityHandle> contained;
108 CHKERR moab.get_contained_meshsets(meshset, contained);
109 ia.resize(0);
110 time.resize(0);
111 handles.resize(0);
112 uids.resize(0);
113 data.resize(0);
114 ia.push_back(0);
115
116 for (unsigned int mm = 0; mm < contained.size(); mm++) {
117 // time
118 {
119 double t;
120 CHKERR moab.tag_set_data(th_SeriesTime, &meshset, 1, &t);
121 time.push_back(t);
122 }
123 // handles
124 {
125 const EntityHandle *tag_data;
126 int tag_size;
127 CHKERR moab.tag_get_by_ptr(th_SeriesDataHandles, &meshset, 1,
128 (const void **)&tag_data, &tag_size);
129 handles.insert(handles.end(), tag_data, &tag_data[tag_size]);
130 }
131 // uids
132 {
133 const ShortId *tag_data;
134 int tag_size;
135 CHKERR moab.tag_get_by_ptr(th_SeriesDataUIDs, &meshset, 1,
136 (const void **)&tag_data, &tag_size);
137 int nb = tag_size / sizeof(ShortId);
138 uids.insert(uids.end(), tag_data, &tag_data[nb]);
139 }
140 if (handles.size() != uids.size()) {
141 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "data inconsistency");
142 }
143 // data
144 {
145 const FieldData *tag_data;
146 int tag_size;
147 CHKERR moab.tag_get_by_ptr(th_SeriesData, &meshset, 1,
148 (const void **)&tag_data, &tag_size);
149 int nb = tag_size / sizeof(FieldData);
150 data.insert(data.end(), tag_data, &tag_data[nb]);
151 }
152 if (data.size() != uids.size()) {
153 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "data inconsistency");
154 }
155 ia.push_back(data.size());
156 }
157
159}
160
161MoFEMErrorCode FieldSeries::save(moab::Interface &moab) const {
163
164 if (record_begin) {
165 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "switch off recording");
166 }
167 if (!record_end) {
168 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "finish recording");
169 }
170
171 std::vector<EntityHandle> contained;
172 CHKERR moab.get_contained_meshsets(meshset, contained);
173 unsigned int nb_contained = contained.size();
174 if (nb_contained < ia.size() - 1) {
175 contained.resize(ia.size());
176 }
177 for (unsigned int mm = ia.size() - 1; mm < nb_contained; mm++) {
178 CHKERR moab.remove_entities(meshset, &contained[mm], 1);
179 CHKERR moab.delete_entities(&contained[mm], 1);
180 }
181 for (unsigned int mm = nb_contained; mm < ia.size() - 1; mm++) {
182 EntityHandle new_meshset;
183 CHKERR moab.create_meshset(MESHSET_SET, new_meshset);
184 CHKERR moab.add_entities(meshset, &new_meshset, 1);
185 }
186 contained.resize(0);
187 CHKERR moab.get_contained_meshsets(meshset, contained);
188 if (contained.size() != ia.size() - 1) {
189 SETERRQ2(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
190 "data inconsistency nb_contained != ia.size()-1 %d!=%d",
191 contained.size(), ia.size() - 1);
192 }
193
194 // time
195 for (unsigned int ii = 1; ii < ia.size(); ii++) {
196 CHKERR moab.tag_set_data(th_SeriesTime, &contained[ii - 1], 1,
197 &time[ii - 1]);
198 }
199
200 // handles
201 for (unsigned int ii = 1; ii < ia.size(); ii++) {
202 void const *tag_data[] = {&handles[ia[ii - 1]]};
203 int tag_sizes[] = {(ia[ii] - ia[ii - 1])};
204 CHKERR moab.tag_set_by_ptr(th_SeriesDataHandles, &contained[ii - 1], 1,
205 tag_data, tag_sizes);
206 }
207 // uids
208 for (unsigned int ii = 1; ii < ia.size(); ii++) {
209 void const *tag_data[] = {&uids[ia[ii - 1]]};
210 int tag_sizes[] = {(ia[ii] - ia[ii - 1]) * (int)sizeof(ShortId)};
211 CHKERR moab.tag_set_by_ptr(th_SeriesDataUIDs, &contained[ii - 1], 1,
212 tag_data, tag_sizes);
213 }
214
215 // data
216 for (unsigned int ii = 1; ii < ia.size(); ii++) {
217 void const *tag_data[] = {&data[ia[ii - 1]]};
218 int tag_sizes[] = {(ia[ii] - ia[ii - 1]) * (int)sizeof(FieldData)};
219 CHKERR moab.tag_set_by_ptr(th_SeriesData, &contained[ii - 1], 1, tag_data,
220 tag_sizes);
221 }
222
224}
225
227 const FieldSeries *_FieldSeries_ptr,
228 const int _step_number)
229 : interface_FieldSeries<FieldSeries>(_FieldSeries_ptr),
230 step_number(_step_number) {
231
232 ierr = get_time_init(moab);
233 CHKERRABORT(PETSC_COMM_WORLD, ierr);
234}
235
237 DofEntity_multiIndex &dofsField) const {
239
240 std::vector<EntityHandle> contained;
241 CHKERR moab.get_contained_meshsets(ptr->meshset, contained);
242 if (contained.size() <= (unsigned int)step_number) {
243 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "data inconsistency");
244 }
245
246 EntityHandle *handles_ptr;
247 int handles_size;
248 CHKERR moab.tag_get_by_ptr(ptr->th_SeriesDataHandles, &contained[step_number],
249 1, (const void **)&handles_ptr, &handles_size);
250
251 ShortId *uids_ptr;
252 int uids_size;
253 CHKERR moab.tag_get_by_ptr(ptr->th_SeriesDataUIDs, &contained[step_number], 1,
254 (const void **)&uids_ptr, &uids_size);
255 uids_size /= sizeof(ShortId);
256
257 if (handles_size != uids_size) {
258 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "data inconsistency");
259 }
260
261 FieldData *data_ptr;
262 int data_size;
263 CHKERR moab.tag_get_by_ptr(ptr->th_SeriesData, &contained[step_number], 1,
264 (const void **)&data_ptr, &data_size);
265 data_size /= sizeof(FieldData);
266
267 if (data_size != uids_size) {
268 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "data inconsistency");
269 }
270
271 typedef multi_index_container<
272 boost::shared_ptr<DofEntity>,
273 indexed_by<
274
275 hashed_non_unique<
276 tag<Composite_Ent_and_ShortId_mi_tag>,
277 composite_key<
278 DofEntity,
279 const_mem_fun<DofEntity, EntityHandle, &DofEntity::getEnt>,
280 const_mem_fun<DofEntity, ShortId,
282
283 >>
284 DofEntity_multiIndex_short_uid_view;
285
286 DofEntity_multiIndex_short_uid_view short_uid_view;
287 short_uid_view.insert(dofsField.begin(), dofsField.end());
288
289 for (int ii = 0; ii < uids_size; ii++) {
290 EntityHandle ent = handles_ptr[ii];
291 ShortId uid = uids_ptr[ii];
292 FieldData val = data_ptr[ii];
293
294 auto dit = short_uid_view.find(boost::make_tuple(ent, uid));
295 if (dit != short_uid_view.end()) {
296 (*dit)->getFieldData() = val;
297 } else {
298 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND,
299 "data inconsistency, getting data series, dof on ENTITY and "
300 "ShortId can't be found");
301 }
302 }
303
305}
306
309
310 std::vector<EntityHandle> contained;
311 CHKERR moab.get_contained_meshsets(ptr->meshset, contained);
312 if (contained.size() <= (unsigned int)step_number) {
313 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "data inconsistency");
314 }
315 double *time_ptr;
316 int size;
317 CHKERR moab.tag_get_by_ptr(ptr->th_SeriesTime, &contained[step_number], 1,
318 (const void **)&time_ptr, &size);
319 time = *time_ptr;
321}
322
323std::ostream &operator<<(std::ostream &os, const FieldSeries &e) {
324 os << "name " << e.getName() << " meshset " << e.getMeshset();
325 return os;
326}
327
328std::ostream &operator<<(std::ostream &os, const FieldSeriesStep &e) {
329 os << *(e.get_FieldSeries_ptr()) << " step number " << e.step_number
330 << " time " << e.get_time();
331 return os;
332}
333
334} // namespace MoFEM
#define MOAB_THROW(err)
Check error code of MoAB function and throw MoFEM exception.
Definition: definitions.h:541
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
@ MOFEM_NOT_FOUND
Definition: definitions.h:33
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
#define CHKERR
Inline error check.
Definition: definitions.h:535
multi_index_container< boost::shared_ptr< DofEntity >, indexed_by< ordered_unique< tag< Unique_mi_tag >, const_mem_fun< DofEntity, UId, &DofEntity::getLocalUniqueId > >, ordered_non_unique< tag< Ent_mi_tag >, const_mem_fun< DofEntity, EntityHandle, &DofEntity::getEnt > > > > DofEntity_multiIndex
MultiIndex container keeps DofEntity.
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Exceptions.hpp:76
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
Definition: Exceptions.hpp:74
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
double FieldData
Field data type.
Definition: Types.hpp:25
int ShortId
Unique Id in the field.
Definition: Types.hpp:32
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
std::ostream & operator<<(std::ostream &os, const EntitiesFieldData::EntData &e)
constexpr double t
plate stiffness
Definition: plate.cpp:59
keeps information about DOF on the entity
ShortId getNonNonuniqueShortId() const
get short uid it is unique in combination with entity handle
Structure for recording (time) series.
std::vector< ShortId > uids
MoFEMErrorCode end(double time=0)
std::string getName() const
get series name
MoFEMErrorCode push_dofs(const EntityHandle ent, const ShortId uid, const FieldData val)
std::vector< FieldData > data
MoFEMErrorCode get_nb_steps(Interface &moab, int &nb_setps) const
const void * tagName
tag keeps name of the series
EntityHandle getMeshset() const
get meshset
MoFEMErrorCode read(Interface &moab)
std::vector< int > ia
std::vector< EntityHandle > handles
std::vector< double > time
MoFEMErrorCode save(Interface &moab) const
MoFEMErrorCode begin()
FieldSeries(Interface &moab, const EntityHandle _meshset)
int tagNameSize
number of bits necessary to keep field series
Structure for keeping time and step.
MoFEMErrorCode get(Interface &moab, DofEntity_multiIndex &dofsField) const
FieldSeriesStep(Interface &moab, const FieldSeries *_FieldSeries_ptr, const int _step_number)
MoFEMErrorCode get_time_init(Interface &moab)
const FieldSeries * get_FieldSeries_ptr() const