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();
149 for(
unsigned int i_elm : process_list) {
155 if (projection.min() >=0.0) {
163 projection[elm.
dim()] = 1.0;
164 arma::vec global_coord = map*projection;
168 closed_elements.insert(i_elm);
170 for (
unsigned int n=0; n < elm.
n_nodes(); n++) {
172 candidate_list.push_back(i_node_ele);
180 for(
unsigned int i_level=0; i_level <
max_levels_; i_level++) {
182 process_list.swap(candidate_list);
183 candidate_list.clear();
184 for(
unsigned int i_elm : process_list) {
185 if (closed_elements.find(i_elm) != closed_elements.end())
continue;
194 point_on_element[elm.
dim()] = 1.0;
195 arma::vec global_coord = map*point_on_element;
199 for (
unsigned int n=0; n < elm.
n_nodes(); n++) {
201 candidate_list.push_back(i_node_ele);
215 out << setw(indent_spaces) <<
"" <<
"- name: " <<
name_ << endl;
217 out << setw(indent_spaces) <<
"" <<
" snap_dim: " <<
snap_dim_ << endl;
218 out << setw(indent_spaces) <<
"" <<
" snap_region: " <<
snap_region_name_ << endl;
227 observe_values_time_(numeric_limits<double>::signaling_NaN()),
228 precision_(precision)
246 if (
points_.size() == 0)
return;
260 template<
int spacedim,
class Value>
263 if (
points_.size() == 0)
return;
265 double field_time = field.
time();
279 unsigned int i_data=0;
281 unsigned int ele_index = o_point.element_idx_;
282 const Value &obs_value =
283 Value( const_cast<typename Value::return_type &>(
284 field.
value(o_point.global_coords_,
293 #define INSTANCE_DIM(dim) \ 294 template void Observe::compute_field_values(Field<dim, FieldValue<0>::Enum> &); \ 295 template void Observe::compute_field_values(Field<dim, FieldValue<0>::Integer> &); \ 296 template void Observe::compute_field_values(Field<dim, FieldValue<0>::Scalar> &); \ 297 template void Observe::compute_field_values(Field<dim, FieldValue<dim>::VectorFixed> &); \ 298 template void Observe::compute_field_values(Field<dim, FieldValue<dim>::TensorFixed> &); 306 unsigned int indent = 2;
307 observe_file_ <<
"# Observation file: " << observe_name << endl;
318 if (
points_.size() == 0)
return;
321 unsigned int indent = 2;
324 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)
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)
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_
Time of fields when the observe values were computed.
void find_point(const Space< 3 >::Point &point, std::vector< unsigned int > &result_list) const
void output_header(string observe_name)
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
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.