12 #include <unordered_set> 30 return IT::Record(
"ObservePoint",
"Specification of the observation point. The actual observe element and the observe point on it is determined as follows:\n\n" 31 "1. Find an initial element containing the initial point. If no such element exists we report the error.\n" 32 "2. Use BFS starting from the inital element to find the 'observe element'. The observe element is the closest element " 33 "3. Find the closest projection of the inital point on the observe element and snap this projection according to the 'snap_dim'.\n")
37 "Default name have the form 'obs_<id>', where 'id' " 38 "is the rank of the point on the input."),
39 "Optional point name. Has to be unique. Any string that is valid YAML key in record without any quoting can be used however" 40 "using just alpha-numerical characters and underscore instead of the space is recommended. " 43 "Initial point for the observe point search.")
45 "The dimension of the sub-element to which center we snap. For value 4 no snapping is done. " 46 "For values 0 up to 3 the element containing the initial point is found and then the observe" 47 "point is snapped to the nearest center of the sub-element of the given dimension. " 48 "E.g. for dimension 2 we snap to the nearest center of the face of the initial element." 51 "The region of the initial element for snapping. Without snapping we make a projection to the initial element.")
53 "Maximum number of levels of the breadth first search used to find the observe element from the initial element. Value zero means to search only the initial element itself.")
62 :
distance_(numeric_limits<double>::infinity())
67 name_ = in_rec.
val<
string>(
"name", default_label );
84 double dist = arma::norm(global_coords -
input_point_, 2);
97 return distance_ < numeric_limits<double>::infinity();
102 template <
int ele_dim>
107 double min_dist = 2.0;
108 arma::vec min_center;
112 if ( dist < min_dist) {
125 case 1: snap_to_subelement<1>();
break;
126 case 2: snap_to_subelement<2>();
break;
127 case 3: snap_to_subelement<3>();
break;
128 default:
ASSERT(
false).error(
"Clipping supported only for dim=1,2,3.");
137 if (region_set.size() == 0)
143 std::unordered_set<unsigned int> closed_elements(1023);
147 process_list.swap(candidate_list);
148 candidate_list.clear();
150 unsigned int min_dist_idx=0;
151 double min_dist=numeric_limits<double>::max();
152 for (
unsigned int i_candidate=0; i_candidate<process_list.size(); ++i_candidate) {
153 unsigned int i_elm=process_list[i_candidate];
170 projection[elm.
dim()] = 1.0;
171 arma::vec global_coord = map*projection;
175 closed_elements.insert(i_elm);
177 for (
unsigned int n=0; n < elm.
n_nodes(); n++) {
179 candidate_list.push_back(i_node_ele);
183 double distance = fabs(projection.min());
184 if (distance < min_dist) {
186 min_dist_idx = i_candidate;
193 if (candidate_list.size() == 0) {
195 unsigned int i_elm=process_list[min_dist_idx];
203 projection[elm.
dim()] = 1.0;
204 arma::vec global_coord = map*projection;
208 WarningOut().fmt(
"Failed to find the element containing the initial observe point ({}).\n" 211 closed_elements.insert(i_elm);
213 for (
unsigned int n=0; n < elm.
n_nodes(); n++) {
215 candidate_list.push_back(i_node_ele);
221 for(
unsigned int i_level=0; i_level <
max_levels_; i_level++) {
223 process_list.swap(candidate_list);
224 candidate_list.clear();
225 for(
unsigned int i_elm : process_list) {
226 if (closed_elements.find(i_elm) != closed_elements.end())
continue;
235 point_on_element[elm.
dim()] = 1.0;
236 arma::vec global_coord = map*point_on_element;
240 for (
unsigned int n=0; n < elm.
n_nodes(); n++) {
242 candidate_list.push_back(i_node_ele);
256 out << setw(indent_spaces) <<
"" <<
"- name: " <<
name_ << endl;
258 out << setw(indent_spaces) <<
"" <<
" snap_dim: " <<
snap_dim_ << endl;
259 out << setw(indent_spaces) <<
"" <<
" snap_region: " <<
snap_region_name_ << endl;
268 observe_values_time_(numeric_limits<double>::signaling_NaN()),
269 observe_name_(observe_name),
270 precision_(precision)
288 if (
points_.size() == 0)
return;
294 }
INPUT_CATCH(FilePath::ExcFileOpen, FilePath::EI_Address_String, in_array)
304 template<
int spacedim,
class Value>
307 if (
points_.size() == 0)
return;
310 double field_time = field.
time();
324 unsigned int i_data=0;
326 unsigned int ele_index = o_point.element_idx_;
327 const Value &obs_value =
328 Value( const_cast<typename Value::return_type &>(
329 field.
value(o_point.global_coords_,
338 #define INSTANCE_DIM(dim) \ 339 template void Observe::compute_field_values(Field<dim, FieldValue<0>::Enum> &); \ 340 template void Observe::compute_field_values(Field<dim, FieldValue<0>::Integer> &); \ 341 template void Observe::compute_field_values(Field<dim, FieldValue<0>::Scalar> &); \ 342 template void Observe::compute_field_values(Field<dim, FieldValue<dim>::VectorFixed> &); \ 343 template void Observe::compute_field_values(Field<dim, FieldValue<dim>::TensorFixed> &); 351 unsigned int indent = 2;
363 if (
points_.size() == 0)
return;
381 unsigned int indent = 2;
384 observe_file_ << setw(indent) <<
"" <<
" " << field_data.second->field_name <<
": ";
std::vector< ObservePoint > points_
Full information about observe points.
arma::vec project_point(const arma::vec3 &point, const arma::mat &map) const
OutputDataFieldMap observe_field_values_
Stored field values.
unsigned int n_nodes() const
std::ofstream observe_file_
Output file stream.
vector< vector< unsigned int > > node_elements
arma::vec3 input_point_
Input coordinates of the initial position of the observation point.
arma::mat element_map() const
Class template representing a field with values dependent on: point, element, and region...
static const Input::Type::Record & get_input_type()
bool have_observe_element()
RegionSet get_region_set(const string &set_name) const
void output(ostream &out, unsigned int indent_spaces, unsigned int precision)
Observe(string observe_name, Mesh &mesh, Input::Array in_array, unsigned int precision)
static const double epsilon
stabilization parameter
std::string time_unit_str_
String representation of the time unit.
const RegionDB & region_db() const
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
This class is used for storing data that are copied from field.
std::string to_string(const T &value)
std::string observe_name_
arma::vec clip_to_element(arma::vec &barycentric)
Input::Record in_rec_
Index in the input array.
void open_stream(Stream &stream) const
Global macros to enhance readability and debugging, general constants.
unsigned int precision_
Precision of float output.
void find_observe_point(Mesh &mesh)
void snap_to_subelement()
std::string name_
Observation point name.
std::vector< unsigned int > observed_element_indices_
Elements of the o_points.
Class for O(log N) lookup for intersections with a set of bounding boxes.
unsigned int index(const T *pointer) const
virtual Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm) const
double observe_values_time_
Common evaluation time of the fields for single time frame.
void find_point(const Space< 3 >::Point &point, std::vector< unsigned int > &result_list) const
const BIHTree & get_bih_tree()
Dedicated class for storing path to input and output files.
void compute_field_values(Field< spacedim, Value > &field)
arma::vec3 global_coords_
Global coordinates of the observation point.
arma::vec local_coords_
Local (barycentric) coordinates on the element.
void update_projection(unsigned int i_elm, arma::vec local_coords, arma::vec3 global_coords)
double time_unit_seconds_
Time unit in seconds.
bool is_in_region_set(const RegionSet &set) const
#define WarningOut()
Macro defining 'warning' record of log.
FieldCommon & name(const string &name)
unsigned int element_idx_
Final element of the observe point. The index in the mesh.
#define INSTANCE_DIM(dim)
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
~Observe()
Destructor, must close the file.
NodeVector node_vector
Vector of nodes of the mesh.
void store_value(unsigned int idx, const Value &value)
void output_time_frame(double time)
ElementVector element
Vector of elements of the mesh.