v0.14.0
record_series_atom.cpp
Go to the documentation of this file.
1 
2 
3 #include <MoFEM.hpp>
4 
5 namespace bio = boost::iostreams;
6 using bio::stream;
7 using bio::tee_device;
8 
9 using namespace MoFEM;
10 
11 static char help[] = "...\n\n";
12 
13 int main(int argc, char *argv[]) {
14 
15  MoFEM::Core::Initialize(&argc, &argv, PETSC_NULL, help);
16 
17  try {
18 
19  moab::Core mb_instance;
20  moab::Interface &moab = mb_instance;
21  int rank;
22  MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
23 
24  // Reade parameters from line command
25  PetscBool flg = PETSC_TRUE;
26  char mesh_file_name[255];
27 #if PETSC_VERSION_GE(3, 6, 4)
28  CHKERR PetscOptionsGetString(PETSC_NULL, "", "-my_file", mesh_file_name,
29  255, &flg);
30 #else
31  CHKERR PetscOptionsGetString(PETSC_NULL, PETSC_NULL, "-my_file",
32  mesh_file_name, 255, &flg);
33 #endif
34  if (flg != PETSC_TRUE) {
35  SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR -my_file (MESH FILE NEEDED)");
36  }
37  PetscInt order = 3;
38 #if PETSC_VERSION_GE(3, 6, 4)
39  CHKERR PetscOptionsGetInt(PETSC_NULL, "", "-my_order", &order, &flg);
40 #else
41  CHKERR PetscOptionsGetInt(PETSC_NULL, PETSC_NULL, "-my_order", &order,
42  &flg);
43 #endif
44 
45  // Read mesh to MOAB
46  const char *option;
47  option = ""; //"PARALLEL=BCAST;";//;DEBUG_IO";
48  CHKERR moab.load_file(mesh_file_name, 0, option);
49 
50  // Create MoFEM
51  // Starting from one MoFEM::CoreTmp<1> for testing purposes
52  MoFEM::CoreTmp<0> core(moab);
53  MoFEM::Interface &m_field = core;
54 
55  // stl::bitset see for more details
56  auto bit_level0 = BitRefLevel().set(0);
57  CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
58  0, 3, BitRefLevel().set(0));
59 
60  /***/
61  // Define problem
62 
63  // Fields
64  CHKERR m_field.add_field("FIELD_A", H1, AINSWORTH_LEGENDRE_BASE, 3);
65  CHKERR m_field.add_field("FIELD_B", H1, AINSWORTH_LEGENDRE_BASE, 3);
66 
67  CHKERR m_field.add_ents_to_field_by_type(0, MBTET, "FIELD_A");
68  CHKERR m_field.add_ents_to_field_by_type(0, MBTET, "FIELD_B");
69 
70  CHKERR m_field.set_field_order(0, MBTET, "FIELD_A", order);
71  CHKERR m_field.set_field_order(0, MBTRI, "FIELD_A", order);
72  CHKERR m_field.set_field_order(0, MBEDGE, "FIELD_A", order);
73  CHKERR m_field.set_field_order(0, MBVERTEX, "FIELD_A", 1);
74 
75  CHKERR m_field.set_field_order(0, MBTET, "FIELD_B", order);
76  CHKERR m_field.set_field_order(0, MBTRI, "FIELD_B", order);
77  CHKERR m_field.set_field_order(0, MBEDGE, "FIELD_B", order);
78  CHKERR m_field.set_field_order(0, MBVERTEX, "FIELD_B", 1);
79 
80  // build field
81  CHKERR m_field.build_fields();
82 
83  CHKERR m_field.getInterface<FieldBlas>()->setField(0, MBVERTEX, "FIELD_B");
84  CHKERR m_field.getInterface<FieldBlas>()->setField(1, MBVERTEX, "FIELD_A");
85 
86  SeriesRecorder *recorder_ptr;
87  CHKERR m_field.getInterface(recorder_ptr);
88 
89  CHKERR recorder_ptr->add_series_recorder("TEST_SERIES1");
90  CHKERR recorder_ptr->add_series_recorder("TEST_SERIES2");
91 
92  // initialize
93  CHKERR recorder_ptr->initialize_series_recorder("TEST_SERIES1");
94 
95  CHKERR recorder_ptr->record_begin("TEST_SERIES1");
96  CHKERR recorder_ptr->record_field("TEST_SERIES1", "FIELD_B", bit_level0,
97  bit_level0);
98  CHKERR recorder_ptr->record_end("TEST_SERIES1", 1);
99 
100  CHKERR m_field.getInterface<FieldBlas>()->fieldAxpy(1., "FIELD_A",
101  "FIELD_B");
102  CHKERR recorder_ptr->record_begin("TEST_SERIES1");
103  CHKERR recorder_ptr->record_field("TEST_SERIES1", "FIELD_B", bit_level0,
104  bit_level0);
105 
106  CHKERR recorder_ptr->initialize_series_recorder("TEST_SERIES2");
107  CHKERR recorder_ptr->record_begin("TEST_SERIES2");
108  CHKERR recorder_ptr->record_field("TEST_SERIES2", "FIELD_A", bit_level0,
109  bit_level0);
110  CHKERR recorder_ptr->record_field("TEST_SERIES2", "FIELD_B", bit_level0,
111  bit_level0);
112  CHKERR recorder_ptr->record_end("TEST_SERIES2", 1);
113  CHKERR recorder_ptr->finalize_series_recorder("TEST_SERIES2");
114 
115  CHKERR recorder_ptr->record_end("TEST_SERIES1", 2);
116 
117  // finalize
118  CHKERR recorder_ptr->finalize_series_recorder("TEST_SERIES1");
119  CHKERR recorder_ptr->print_series_steps();
120 
121  CHKERR m_field.getInterface<FieldBlas>()->fieldScale(2, "FIELD_A");
122 
123  // Setting MoFEM::CoreTmp<-1> for testing purposes
124  MoFEM::CoreTmp<-1> core2(moab);
125  MoFEM::Interface &m_field2 = core2;
126 
127  // build field
128  CHKERR m_field2.build_fields();
129 
130  typedef tee_device<std::ostream, std::ofstream> TeeDevice;
131  typedef stream<TeeDevice> TeeStream;
132  std::ofstream ofs("record_series_atom.txt");
133  TeeDevice my_tee(std::cout, ofs);
134  TeeStream my_split(my_tee);
135 
136  SeriesRecorder *recorder2_ptr;
137  CHKERR m_field2.getInterface(recorder2_ptr);
138  CHKERR recorder2_ptr->print_series_steps();
139 
140  my_split << "TEST_SERIES1" << std::endl;
141  for (_IT_SERIES_STEPS_BY_NAME_FOR_LOOP_(recorder2_ptr, "TEST_SERIES1",
142  sit)) {
143 
144  CHKERR recorder2_ptr->load_series_data("TEST_SERIES1",
145  sit->get_step_number());
146 
147  my_split << "next step:\n";
148  my_split << *sit << std::endl;
149 
150  {
152  for (_IT_GET_DOFS_FIELD_BY_NAME_FOR_LOOP_(m_field2, "FIELD_B", dof)) {
153  dofs_view.insert(*dof);
154  }
155  for (DofEntity_multiIndex_uid_view::iterator dit = dofs_view.begin();
156  dit != dofs_view.end(); dit++) {
157  my_split << **dit << endl;
158  }
159  }
160  }
161 
162  my_split << "TEST_SERIES2" << std::endl;
163  for (_IT_SERIES_STEPS_BY_NAME_FOR_LOOP_(recorder2_ptr, "TEST_SERIES2",
164  sit)) {
165 
166  CHKERR recorder2_ptr->load_series_data("TEST_SERIES2",
167  sit->get_step_number());
168 
169  my_split << "next step:\n";
170  {
172  for (_IT_GET_DOFS_FIELD_BY_NAME_FOR_LOOP_(m_field2, "FIELD_A", dof)) {
173  dofs_view.insert(*dof);
174  }
175  for (DofEntity_multiIndex_uid_view::iterator dit = dofs_view.begin();
176  dit != dofs_view.end(); dit++) {
177  my_split << **dit << endl;
178  }
179  }
180  {
182  for (_IT_GET_DOFS_FIELD_BY_NAME_FOR_LOOP_(m_field2, "FIELD_B", dof)) {
183  dofs_view.insert(*dof);
184  }
185  for (DofEntity_multiIndex_uid_view::iterator dit = dofs_view.begin();
186  dit != dofs_view.end(); dit++) {
187  my_split << **dit << endl;
188  }
189  }
190  }
191  }
192  CATCH_ERRORS;
193 
195  return 0;
196 }
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Definition: UnknownInterface.hpp:93
TeeStream
stream< TeeDevice > TeeStream
Definition: forces_and_sources_testing_contact_prism_element.cpp:10
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
H1
@ H1
continuous field
Definition: definitions.h:85
MoFEM::SeriesRecorder::record_field
virtual MoFEMErrorCode record_field(const std::string &serie_name, const std::string &field_name, const BitRefLevel &bit, const BitRefLevel &mask)
Definition: SeriesRecorder.cpp:181
MoFEM::SeriesRecorder
Definition: SeriesRecorder.hpp:25
MoFEM.hpp
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
MoFEM::CoreInterface::add_ents_to_field_by_type
virtual MoFEMErrorCode add_ents_to_field_by_type(const Range &ents, const EntityType type, const std::string &name, int verb=DEFAULT_VERBOSITY)=0
Add entities to field meshset.
MoFEM::DofEntity_multiIndex_uid_view
multi_index_container< boost::shared_ptr< DofEntity >, indexed_by< ordered_unique< const_mem_fun< DofEntity, UId, &DofEntity::getLocalUniqueId > > > > DofEntity_multiIndex_uid_view
multi-index view on DofEntity by uid
Definition: DofsMultiIndices.hpp:337
order
constexpr int order
Definition: dg_projection.cpp:18
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
TeeDevice
tee_device< std::ostream, std::ofstream > TeeDevice
Definition: forces_and_sources_testing_contact_prism_element.cpp:9
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1975
MoFEM::SeriesRecorder::add_series_recorder
virtual MoFEMErrorCode add_series_recorder(const std::string &series_name)
Definition: SeriesRecorder.cpp:90
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
MoFEM::SeriesRecorder::print_series_steps
virtual MoFEMErrorCode print_series_steps()
Definition: SeriesRecorder.cpp:286
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
MoFEM::SeriesRecorder::record_begin
virtual MoFEMErrorCode record_begin(const std::string &serie_name)
Definition: SeriesRecorder.cpp:218
MoFEM::CoreTmp
Definition: Core.hpp:36
MoFEM::CoreInterface::add_field
virtual MoFEMErrorCode add_field(const std::string &name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add field.
MoFEM::SeriesRecorder::finalize_series_recorder
virtual MoFEMErrorCode finalize_series_recorder(const std::string &serie_name)
Definition: SeriesRecorder.cpp:264
MoFEM::SeriesRecorder::load_series_data
virtual MoFEMErrorCode load_series_data(const std::string &serie_name, const int step_number)
Definition: SeriesRecorder.cpp:309
_IT_SERIES_STEPS_BY_NAME_FOR_LOOP_
#define _IT_SERIES_STEPS_BY_NAME_FOR_LOOP_(RECORDER, NAME, IT)
loop over recorded series step
Definition: SeriesRecorder.hpp:205
help
static char help[]
Definition: record_series_atom.cpp:11
mesh_file_name
char mesh_file_name[255]
Definition: mesh_smoothing.cpp:23
MoFEM::CoreTmp< 0 >::Initialize
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:72
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:372
_IT_GET_DOFS_FIELD_BY_NAME_FOR_LOOP_
#define _IT_GET_DOFS_FIELD_BY_NAME_FOR_LOOP_(MFIELD, NAME, IT)
Definition: Interface.hpp:1843
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1102
AINSWORTH_LEGENDRE_BASE
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:60
MoFEM::PetscOptionsGetString
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
Definition: DeprecatedPetsc.hpp:172
MoFEM::CoreInterface::build_fields
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
MoFEM::BitRefManager
Managing BitRefLevels.
Definition: BitRefManager.hpp:21
MoFEM::Types::BitRefLevel
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:40
MoFEM::SeriesRecorder::initialize_series_recorder
virtual MoFEMErrorCode initialize_series_recorder(const std::string &serie_name)
Definition: SeriesRecorder.cpp:246
MoFEM::CoreInterface::set_field_order
virtual MoFEMErrorCode set_field_order(const EntityHandle meshset, const EntityType type, const std::string &name, const ApproximationOrder order, int verb=DEFAULT_VERBOSITY)=0
Set order approximation of the entities in the field.
MoFEM::PetscOptionsGetInt
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
Definition: DeprecatedPetsc.hpp:142
MoFEM::FieldBlas
Basic algebra on fields.
Definition: FieldBlas.hpp:21
MoFEM::SeriesRecorder::record_end
virtual MoFEMErrorCode record_end(const std::string &serie_name, double time=0)
Definition: SeriesRecorder.cpp:231
main
int main(int argc, char *argv[])
Definition: record_series_atom.cpp:13