Flow123d  intersections_paper-476-gbe68821
observe.hh
Go to the documentation of this file.
1  /*
2  * observe.hh
3  *
4  * Created on: Jun 28, 2016
5  * Author: jb
6  */
7 
8 #ifndef SRC_IO_OBSERVE_HH_
9 #define SRC_IO_OBSERVE_HH_
10 
11 #include <string>
12 
13 #include "input/input_type.hh"
14 #include "fields/field.hh"
15 #include "io/output_data.hh"
16 #include "tools/time_governor.hh"
17 #include "system/exceptions.hh"
18 #include <armadillo>
19 
20 
21 
22 /**
23  * Helper class stores base data of ObservePoint and allows to evaluate
24  * the nearest point to input_point_.
25  */
27 public:
28  /// Constructor
30  : distance_(numeric_limits<double>::infinity()) {};
31 
32  /// Final element of the observe point. The index in the mesh.
33  unsigned int element_idx_;
34 
35  /// Global coordinates of the observation point.
37 
38  /// Local (barycentric) coordinates on the element.
39  arma::vec local_coords_;
40 
41  /// Distance of found projection from the initial point.
42  /// If we find more candidates we pass in the closest one.
43  double distance_;
44 
45 };
46 
47 
48 /**
49  * Class representing single observe point, used internally by the class Observe.
50  * Members: input_pos_, snap_dim_, snap_region_name_ are set in constructor. Should be checked before passed in.
51  * Members: element_idx_, global_coords_, local_coords_ are derived, set in Observe::find_observe_points.
52  */
53 class ObservePoint {
54 public:
55  DECLARE_INPUT_EXCEPTION(ExcNoInitialPoint,
56  << "Failed to find the element containing the initial observe point.\n");
57  TYPEDEF_ERR_INFO(EI_RegionName, std::string);
58  DECLARE_INPUT_EXCEPTION(ExcNoObserveElement,
59  << "Failed to find the observe element with snap region: " << EI_RegionName::qval
60  << " close to the initial observe point. Change maximal distance of observe element." << "\n");
61 
62  static const Input::Type::Record & get_input_type();
63 
64 protected:
65  /**
66  * Default constructor just for testing.
67  */
68  ObservePoint();
69 
70  /**
71  * Constructor. Read from input.
72  */
73  ObservePoint(Input::Record in_rec, Mesh &mesh, unsigned int point_idx);
74 
75  /**
76  * Returns true if we have already found any observe element.
77  */
78  bool have_observe_element();
79 
80  /**
81  * Snap to the center of closest subelement with dimension snap_dim_.
82  * This makes final adjustment of global_coords_ and local_coords_.
83  */
84  void snap(Mesh &mesh);
85 
86 
87  /**
88  * Find the observe element and the definitive observe point.
89  *
90  * Algorithm:
91  * 1. find element containing the point (initial element)
92  * 2. check initial element for region match possibly set it as (observe element)
93  * 3. add neighbours into processing_list for the next level
94  * 4. while we have no observe element: pass through the processing list of the current level
95  * 5. if element match the region, project and clip the init point, update observe element.
96  * 6. snapping on the observe element
97  *
98  */
99  void find_observe_point(Mesh &mesh);
100 
101  /**
102  * Output the observe point information into a YAML formated stream, indent by
103  * given number of spaces + "- ".
104  */
105  void output(ostream &out, unsigned int indent_spaces, unsigned int precision);
106 
107  /// Project point to given element by dimension of this element.
108  ObservePointData point_projection(unsigned int i_elm, Element &elm);
109 
110  /// Index in the input array.
112 
113  /// Observation point name.
114  std::string name_;
115 
116  /**
117  * Snap to the center of the object of given dimension.
118  * Value 4 and greater means no snapping.
119  */
120  unsigned int snap_dim_;
121 
122  /**
123  * Region of the snapping element.
124  */
126 
127  /**
128  * Maximal distance of observe element from input point.
129  */
131 
132  /// Input coordinates of the initial position of the observation point.
134 
135  /// Helper object stored projection data
137 
138  /// Only Observe should use this class directly.
139  friend class Observe;
140 
141 };
142 
143 
144 /**
145  * This class takes care about the observe points in the output stream, storing observe values of the fields and
146  * their output in the YAML format.
147  */
148 
149 class Observe {
150 public:
151 
152  /**
153  * Construct the observation object.
154  *
155  * observe_name - base name of the output file, the equation name.
156  * mesh - the mesh used for search for the observe points
157  * in_array - the array of observe points
158  */
159  Observe(string observe_name, Mesh &mesh, Input::Array in_array, unsigned int precision);
160 
161  /// Destructor, must close the file.
162  ~Observe();
163 
164 
165  /**
166  * Evaluates and store values of the given field in the observe points.
167  */
168  template<int spacedim, class Value>
169  void compute_field_values(Field<spacedim, Value> &field);
170 
171  /**
172  * Provides a vector of element indices on which the observation values are evaluated.
173  * This can be used to evaluate derived fields only on these elements in the times not selected to
174  * full output.
175  */
177  { return observed_element_indices_;}
178 
179  /**
180  * Output file header.
181  */
182  void output_header();
183 
184  /**
185  * Write field values to the output file. Using the YAML format.
186  */
187  void output_time_frame(double time);
188 
189 
190 
191 protected:
192  // MPI rank.
193  int rank_;
194 
195  // Mesh used for search of points.
197 
198  /// Full information about observe points.
200  /// Elements of the o_points.
202 
203  typedef std::shared_ptr<OutputDataBase> OutputDataPtr;
205 
206  /// Stored field values.
207  OutputDataFieldMap observe_field_values_;
208 
209 
210  /// Common evaluation time of the fields for single time frame.
212 
213  // Name of the observation stream. Base for the output filename.
214  std::string observe_name_;
215 
216  /// Output file stream.
217  std::ofstream observe_file_;
218 
219  /// String representation of the time unit.
220  std::string time_unit_str_;
221  /// Time unit in seconds.
223  /// Precision of float output
224  unsigned int precision_;
225 
226  // Warn for no observe fields only once.
227  bool no_fields_warning=false;
228 
229 };
230 
231 
232 
233 #endif /* SRC_IO_OBSERVE_HH_ */
std::vector< ObservePoint > points_
Full information about observe points.
Definition: observe.hh:199
double max_search_radius_
Definition: observe.hh:130
OutputDataFieldMap observe_field_values_
Stored field values.
Definition: observe.hh:207
std::ofstream observe_file_
Output file stream.
Definition: observe.hh:217
Accessor to input data conforming to declared Array.
Definition: accessors.hh:561
arma::vec3 input_point_
Input coordinates of the initial position of the observation point.
Definition: observe.hh:133
ObservePointData()
Constructor.
Definition: observe.hh:29
Class template representing a field with values dependent on: point, element, and region...
Definition: field.hh:62
Definition: mesh.h:95
unsigned int element_idx_
Final element of the observe point. The index in the mesh.
Definition: observe.hh:30
std::string time_unit_str_
String representation of the time unit.
Definition: observe.hh:220
int rank_
Definition: observe.hh:193
Mesh * mesh_
Definition: observe.hh:196
std::string observe_name_
Definition: observe.hh:214
arma::vec local_coords_
Local (barycentric) coordinates on the element.
Definition: observe.hh:39
Basic time management class.
Input::Record in_rec_
Index in the input array.
Definition: observe.hh:111
arma::vec3 global_coords_
Global coordinates of the observation point.
Definition: observe.hh:36
unsigned int precision_
Precision of float output.
Definition: observe.hh:224
std::string name_
Observation point name.
Definition: observe.hh:114
Accessor to the data with type Type::Record.
Definition: accessors.hh:286
std::vector< unsigned int > observed_element_indices_
Elements of the o_points.
Definition: observe.hh:201
double distance_
Definition: observe.hh:43
#define TYPEDEF_ERR_INFO(EI_Type, Type)
Macro to simplify declaration of error_info types.
Definition: exceptions.hh:186
double observe_values_time_
Common evaluation time of the fields for single time frame.
Definition: observe.hh:211
unsigned int snap_dim_
Definition: observe.hh:120
const std::vector< unsigned int > & observed_elements() const
Definition: observe.hh:176
ObservePointData observe_data_
Helper object stored projection data.
Definition: observe.hh:136
#define DECLARE_INPUT_EXCEPTION(ExcName, Format)
Macro for simple definition of input exceptions.
double time_unit_seconds_
Time unit in seconds.
Definition: observe.hh:222
std::map< string, OutputDataPtr > OutputDataFieldMap
Definition: observe.hh:204
string snap_region_name_
Definition: observe.hh:125
Record type proxy class.
Definition: type_record.hh:177
std::shared_ptr< OutputDataBase > OutputDataPtr
Definition: observe.hh:203