Flow123d
release_3.0.0-973-g92f55e826
|
Go to the documentation of this file.
12 #include <unordered_set>
41 template<
unsigned int dim>
67 if (snap_dim <= dim) {
68 double min_dist = 2.0;
72 double dist = arma::norm(center - observe_data.
local_coords_, 2);
73 if ( dist < min_dist) {
112 return IT::Record(
"ObservePoint",
"Specification of the observation point.\n"
113 "The actual observation element and the observation point on it is determined as follows:\n\n"
114 "1. Find an initial element containing the initial point. If no such element exists, we report an error.\n"
115 "2. Use BFS (Breadth-first search) starting from the inital element to find the 'observe element'. The observe element is the closest element.\n"
116 "3. Find the closest projection of the inital point on the observe element and snap this projection according to the ``snap_dim``.\n")
120 "Default name have the form 'obs_<id>', where 'id' "
121 "is the rank of the point on the input."),
122 "Optional point name, which has to be unique.\n"
123 "Any string that is a valid YAML key in record without any quoting can be used, however, "
124 "using just alpha-numerical characters, and underscore instead of the space, is recommended."
127 "Initial point for the observe point search.")
129 "The dimension of the sub-element to which center we snap. For value 4 no snapping is done. "
130 "For values 0 up to 3 the element containing the initial point is found and then the observe"
131 "point is snapped to the nearest center of the sub-element of the given dimension. "
132 "E.g. for dimension 2 we snap to the nearest center of the face of the initial element."
135 "The region of the initial element for snapping. Without snapping we make a projection to the initial element.")
137 IT::Default::read_time(
"Maximal distance of observe point from Mesh relative to its size (bounding box). "),
138 "Global value is define in Mesh by the key global_snap_radius.")
150 string default_label = string(
"obs_") +
std::to_string(point_idx);
151 name_ = in_rec.
val<
string>(
"name", default_label );
162 double max_mesh_size = arma::max(main_box.max() - main_box.min());
196 default:
ASSERT(
false).error(
"Clipping supported only for dim=1,2,3.");
204 if (region_set.size() == 0)
210 std::unordered_set<unsigned int> closed_elements(1023);
211 std::priority_queue< ObservePointData, std::vector<ObservePointData>,
CompareByDist > candidate_queue;
215 bih_tree.
find_point(projected_point, candidate_list,
true);
217 for (
unsigned int i_candidate=0; i_candidate<candidate_list.size(); ++i_candidate) {
218 unsigned int i_elm=candidate_list[i_candidate];
224 candidate_queue.push(observe_data);
225 closed_elements.insert(i_elm);
228 while (!candidate_queue.empty())
230 auto candidate_data = candidate_queue.top();
231 candidate_queue.pop();
233 unsigned int i_elm=candidate_data.element_idx_;
249 for (
unsigned int n=0; n < elm->
n_nodes(); n++)
251 if (closed_elements.find(i_node_ele) == closed_elements.end()) {
255 candidate_queue.push(observe_data);
256 closed_elements.insert(i_node_ele);
268 if (dist > 2*elm_norm)
269 WarningOut().fmt(
"Observe point ({}) is too distant from the mesh.\n",
name_);
277 out << setw(indent_spaces) <<
"" <<
"- name: " <<
name_ << endl;
279 out << setw(indent_spaces) <<
"" <<
" snap_dim: " <<
snap_dim_ << endl;
280 out << setw(indent_spaces) <<
"" <<
" snap_region: " <<
snap_region_name_ << endl;
307 ASSERT(
false).error(
"Invalid element dimension!");
324 : observe_name_(observe_name),
325 precision_(precision),
332 unsigned int global_point_idx=0, local_point_idx=0;
359 if (
points_.size() == 0)
return;
368 }
INPUT_CATCH(FilePath::ExcFileOpen, FilePath::EI_Address_String, in_array)
382 template <
typename T>
395 = std::make_shared< ElementDataCache<T> >(field_name, n_rows * n_cols,
point_ds_->
lsize());
402 #define OBSERVE_PREPARE_COMPUTE_DATA(TYPE) \
403 template ElementDataCache<TYPE> & Observe::prepare_compute_data<TYPE>(std::string field_name, double field_time, \
404 unsigned int n_rows, unsigned int n_cols)
412 unsigned int indent = 2;
429 auto serial_data = field_data.second->gather(
point_ds_, &(local_to_global[0]));
430 if (
rank_==0) field_data.second = serial_data;
434 unsigned int indent = 2;
435 DebugOut() <<
"Observe::output_time_frame WRITE\n";
439 observe_file_ << setw(indent) <<
"" <<
" " << field_data.second->field_input_name() <<
": ";
453 if (
points_.size() == 0)
return;
Distribution * get_el_ds() const
friend class ObservePointAccessor
unsigned int precision_
Precision of float output.
unsigned int lsize(int proc) const
get local size
unsigned int myp() const
get my processor
std::string to_string(const T &value)
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
LongIdx local_idx_
Local index on actual process of the observe point.
Distribution * point_ds_
Parallel distribution of observe points.
bool operator()(const ObservePointData &lhs, const ObservePointData &rhs) const
ProjectionHandler()
Constructor.
Dedicated class for storing path to input and output files.
Range< ObservePointAccessor > local_range() const
Returns local range of observe points.
Class for O(log N) lookup for intersections with a set of bounding boxes.
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
std::vector< double > observe_values_time_
Common evaluation time of the fields for single time frame.
double convert_unit_from(std::string actual_unit) const
Convert and check user-defined unit.
void open_stream(Stream &stream) const
#define OBSERVE_PREPARE_COMPUTE_DATA(TYPE)
Bounding box in 3d ambient space.
bool have_observe_element()
bool is_in_region_set(const RegionSet &set) const
static const Input::Type::Record & get_input_type()
BoundingBox bounding_box() const
void find_point(const Space< 3 >::Point &point, std::vector< unsigned int > &result_list, bool full_list=false) const
void flush_values()
Effectively writes the data into the observe stream.
BaryPoint project_real_to_unit(const RealPoint &point, const ElementMap &map) const
const BIHTree & get_bih_tree()
Getter for BIH. Creates and compute BIH at first call.
const BoundingBox & tree_box() const
unsigned int proc_
Actual process of the observe point.
void output(ostream &out, unsigned int indent_spaces, unsigned int precision)
double time_unit_seconds_
Time unit in seconds.
ElementMap element_map(ElementAccessor< 3 > elm) const
std::string time_unit_str_
String representation of the time unit.
Class for representation SI units of Fields.
const RegionDB & region_db() const
RegionSet get_region_set(const std::string &set_name) const
std::ofstream observe_file_
Output file stream.
unsigned int proc() const
ObservePointData projection(arma::vec3 input_point, unsigned int i_elm, ElementAccessor< 3 > elm)
void output_time_frame(bool flush)
void snap_to_subelement(ObservePointData &observe_data, ElementAccessor< 3 > elm, unsigned int snap_dim)
std::vector< unsigned int > observed_element_indices_
Elements of the o_points.
NodeAccessor< 3 > node_accessor(unsigned int ni) const
~Observe()
Destructor, must close the file.
BaryPoint clip_to_element(BaryPoint &barycentric)
ElementDataCache< T > & prepare_compute_data(std::string field_name, double field_time, unsigned int n_rows, unsigned int n_cols)
arma::vec local_coords_
Local (barycentric) coordinates on the element.
Global macros to enhance readability and debugging, general constants.
static const unsigned int max_observe_value_time
Maximal size of observe values times vector.
#define WarningOut()
Macro defining 'warning' record of log.
MappingP1< dim, 3 > mapping_
Mapping object.
#define ASSERT_LE(a, b)
Definition of comparative assert macro (Less or Equal)
OutputDataFieldMap observe_field_values_
Stored field values.
Observe(string observe_name, Mesh &mesh, Input::Array in_array, unsigned int precision, std::string unit_str)
ObservePointData point_projection(unsigned int i_elm, ElementAccessor< 3 > elm)
Project point to given element by dimension of this element.
ObservePointData observe_data_
Helper object stored projection data.
std::vector< LongIdx > point_4_loc_
Index set assigning to local point index its global index.
std::string observe_name_
unsigned int element_idx_
Final element of the observe point. The index in the mesh.
const Point & max() const
double max_search_radius_
Class MappingP1 implements the affine transformation of the unit cell onto the actual cell.
static BaryPoint local_to_bary(const LocalPoint &lp)
Converts from local to barycentric coordinates.
const vector< vector< unsigned int > > & node_elements()
double global_snap_radius() const
Maximal distance of observe point from Mesh relative to its size.
unsigned int observe_time_idx_
Index of actual (last) time in observe_values_time_ vector.
#define DebugOut()
Macro defining 'debug' record of log.
std::vector< ObservePoint > points_
Full information about observe points.
LongIdx global_idx_
Global index of the observe point.
arma::vec3 global_coords_
Global coordinates of the observation point.
Input::Record in_rec_
Index in the input array.
virtual ElementAccessor< 3 > element_accessor(unsigned int idx) const
Create and return ElementAccessor to element of given idx.
Point project_point(const Point &point) const
const Point & min() const
void find_observe_point(Mesh &mesh)
std::string name_
Observation point name.
unsigned int n_nodes() const
arma::vec3 input_point_
Input coordinates of the initial position of the observation point.
arma::vec::fixed< spacedim > centre() const
Computes the barycenter.