29 #ifndef FIELD_INTERPOLATED_P0_IMPL_HH_
30 #define FIELD_INTERPOLATED_P0_IMPL_HH_
46 template <
int spacedim,
class Value>
52 template <
int spacedim,
class Value>
61 "Input file with ASCII GMSH file format.")
63 "The values of the Field are read from the \\$ElementData section with field name given by this key.")
71 template <
int spacedim,
class Value>
78 template <
int spacedim,
class Value>
83 source_mesh_ =
new Mesh();
88 bih_tree_ =
new BIHTree( source_mesh_ );
91 unsigned int data_size = source_mesh_->element.size() * (this->value_.n_rows() * this->value_.n_cols());
92 data_ = std::make_shared<std::vector<typename Value::element_type>>();
93 data_->resize(data_size);
95 field_name_ = rec.
val<std::string>(
"field_name");
101 template <
int spacedim,
class Value>
103 ASSERT(source_mesh_,
"Null mesh pointer of elementwise field: %s, did you call init_from_input(Input::Record)?\n", field_name_.c_str());
104 if ( reader_file_ ==
FilePath() )
return false;
111 computed_elm_idx_ = numeric_limits<unsigned int>::max();
114 search_header.
actual =
false;
116 search_header.
n_components = this->value_.n_rows() * this->value_.n_cols();
117 search_header.
n_entities = source_mesh_->element.size();
118 search_header.
time = time.
end();
120 bool boundary_domain_ =
false;
122 source_mesh_->elements_id_maps(boundary_domain_), this->component_idx_);
124 return search_header.actual;
129 template <
int spacedim,
class Value>
132 ASSERT( elm.
is_elemental(),
"FieldInterpolatedP0 works only for 'elemental' ElementAccessors.\n");
133 if (elm.
idx() != computed_elm_idx_ || elm.
is_boundary() != computed_elm_boundary_) {
134 computed_elm_idx_ = elm.
idx();
137 if (elm.
dim() == 3) {
138 xprintf(
Err,
"Dimension of element in target mesh must be 0, 1 or 2! elm.idx() = %d\n", elm.
idx());
144 if (elm.
dim() == 0) {
145 searched_elements_.clear();
150 searched_elements_.clear();
151 ((
BIHTree *)bih_tree_)->find_bounding_box(bb, searched_elements_);
155 for (
unsigned int i=0; i < this->value_.n_rows(); i++) {
156 for (
unsigned int j=0; j < this->value_.n_cols(); j++) {
157 this->value_(i,j) = 0.0;
161 double total_measure=0.0, measure;
169 if (ele->dim() == 3) {
175 if ( tetrahedron_.IsInner(point_) ) {
203 if (measure > epsilon) {
204 unsigned int index = this->value_.n_rows() * this->value_.n_cols() * (*it);
206 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])) );
207 Value tmp_value = Value( ret_type_value );
209 for (
unsigned int i=0; i < this->value_.n_rows(); i++) {
210 for (
unsigned int j=0; j < this->value_.n_cols(); j++) {
211 this->value_(i,j) += tmp_value(i,j) * measure;
214 total_measure += measure;
217 xprintf(
Err,
"Dimension of element in source mesh must be 3!\n");
222 if (total_measure > epsilon) {
223 for (
unsigned int i=0; i < this->value_.n_rows(); i++) {
224 for (
unsigned int j=0; j < this->value_.n_cols(); j++) {
225 this->value_(i,j) /= total_measure;
229 xprintf(
Warn,
"Processed element with idx %d is out of source mesh!\n", elm.
idx());
234 return this->r_value_;
239 template <
int spacedim,
class Value>
243 ASSERT( elm.
is_elemental(),
"FieldInterpolatedP0 works only for 'elemental' ElementAccessors.\n");
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)
static Input::Type::Record get_input_type(Input::Type::AbstractRecord &a_type, const typename Value::ElementInputType *eit)
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 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.