18 #ifndef FIELD_INTERPOLATED_P0_IMPL_HH_
19 #define FIELD_INTERPOLATED_P0_IMPL_HH_
31 namespace it = Input::Type;
37 template <
int spacedim, class Value>
43 "Input file with ASCII GMSH file format.")
45 "The values of the Field are read from the ```$ElementData``` section with field name given by this key.")
51 template <
int spacedim,
class Value>
53 Input::register_class< FieldInterpolatedP0<spacedim, Value>,
unsigned int >(
"FieldInterpolatedP0") +
57 template <
int spacedim,
class Value>
64 template <
int spacedim,
class Value>
69 source_mesh_ =
new Mesh();
74 bih_tree_ =
new BIHTree( source_mesh_ );
77 unsigned int data_size = source_mesh_->element.size() * (this->value_.n_rows() * this->value_.n_cols());
78 data_ = std::make_shared<std::vector<typename Value::element_type>>();
79 data_->resize(data_size);
81 field_name_ = rec.
val<std::string>(
"field_name");
87 template <
int spacedim,
class Value>
89 OLD_ASSERT(source_mesh_,
"Null mesh pointer of elementwise field: %s, did you call init_from_input(Input::Record)?\n", field_name_.c_str());
90 if ( reader_file_ ==
FilePath() )
return false;
97 computed_elm_idx_ = numeric_limits<unsigned int>::max();
100 search_header.
actual =
false;
102 search_header.
n_components = this->value_.n_rows() * this->value_.n_cols();
103 search_header.
n_entities = source_mesh_->element.size();
104 search_header.
time = time.
end();
106 bool boundary_domain_ =
false;
108 source_mesh_->elements_id_maps(boundary_domain_), this->component_idx_);
110 return search_header.actual;
115 template <
int spacedim,
class Value>
119 if (elm.
idx() != computed_elm_idx_ || elm.
is_boundary() != computed_elm_boundary_) {
120 computed_elm_idx_ = elm.
idx();
123 if (elm.
dim() == 3) {
124 xprintf(
Err,
"Dimension of element in target mesh must be 0, 1 or 2! elm.idx() = %d\n", elm.
idx());
130 if (elm.
dim() == 0) {
131 searched_elements_.clear();
136 searched_elements_.clear();
137 ((
BIHTree *)bih_tree_)->find_bounding_box(bb, searched_elements_);
141 for (
unsigned int i=0; i < this->value_.n_rows(); i++) {
142 for (
unsigned int j=0; j < this->value_.n_cols(); j++) {
143 this->value_(i,j) = 0.0;
147 double total_measure=0.0, measure;
155 if (ele->dim() == 3) {
161 if ( tetrahedron_.IsInner(point_) ) {
189 if (measure > epsilon) {
190 unsigned int index = this->value_.n_rows() * this->value_.n_cols() * (*it);
192 typename Value::return_type & ret_type_value =
const_cast<typename Value::return_type &
>( Value::from_raw(this->r_value_, (
typename Value::element_type *)(&vec[index])) );
193 Value tmp_value = Value( ret_type_value );
195 for (
unsigned int i=0; i < this->value_.n_rows(); i++) {
196 for (
unsigned int j=0; j < this->value_.n_cols(); j++) {
197 this->value_(i,j) += tmp_value(i,j) * measure;
200 total_measure += measure;
206 if (total_measure > epsilon) {
207 for (
unsigned int i=0; i < this->value_.n_rows(); i++) {
208 for (
unsigned int j=0; j < this->value_.n_cols(); j++) {
209 this->value_(i,j) /= total_measure;
213 WarningOut().fmt(
"Processed element with idx {} is out of source mesh!\n", elm.
idx());
218 return this->r_value_;
223 template <
int spacedim,
class Value>
const Element * element() const
Bounding box in 3d ambient space.
bool set_time(const TimeStep &time) override
void set_point_from_element(TPoint &p, const Element *ele)
bool is_boundary() const
We need this method after replacing Region by RegionIdx, and movinf RegionDB instance into particular...
virtual void value_list(const std::vector< Point > &point_list, const ElementAccessor< spacedim > &elm, std::vector< typename Value::return_type > &value_list)=0
virtual Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm)
#define ADD_CALLS(n_calls)
Increase number of calls in actual timer.
void set_tetrahedron_from_element(TTetrahedron &te, Element *ele)
virtual void value_list(const std::vector< Point > &point_list, const ElementAccessor< spacedim > &elm, std::vector< typename Value::return_type > &value_list)
bool is_elemental() const
FieldInterpolatedP0(unsigned int n_comp=0)
#define START_TIMER(tag)
Starts a timer with specified tag.
void set_abscissa_from_element(TAbscissa &ab, const Element *ele)
Class for O(log N) lookup for intersections with a set of bounding boxes.
void get_bounding_box(BoundingBox &bounding_box) const
enum Intersections TIntersectionType
Space< spacedim >::Point Point
Dedicated class for storing path to input and output files.
virtual void init_from_input(const Input::Record &rec)
void set_triangle_from_element(TTriangle &tr, const Element *ele)
std::shared_ptr< GmshMeshReader > get_reader(const FilePath &file_path)
#define WarningOut()
Macro defining 'warning' record of log.
#define END_TIMER(tag)
Ends a timer with specified tag.
static ReaderInstances * instance()
Returns singleton instance.
void GetIntersection(const TBisector &, const TBisector &, TPosition &, double &, double &)
Representation of one time step.
#define FLOW123D_FORCE_LINK_IN_CHILD(x)