29 #ifndef FIELD_INTERPOLATED_P0_IMPL_HH_
30 #define FIELD_INTERPOLATED_P0_IMPL_HH_
41 namespace it = Input::Type;
45 template <
int spacedim,
class Value>
51 template <
int spacedim,
class Value>
60 "Input file with ASCII GMSH file format.")
62 "The values of the Field are read from the \\$ElementData section with field name given by this key.")
70 template <
int spacedim,
class Value>
77 template <
int spacedim,
class Value>
82 source_mesh_ =
new Mesh();
84 reader_->read_mesh( source_mesh_ );
87 bih_tree_ =
new BIHTree( source_mesh_ );
90 unsigned int data_size = source_mesh_->element.size() * (this->value_.n_rows() * this->value_.n_cols());
91 data_ =
new double[data_size];
92 std::fill(data_, data_ + data_size, 0.0);
94 field_name_ = rec.
val<std::string>(
"field_name");
100 template <
int spacedim,
class Value>
102 ASSERT(source_mesh_,
"Null mesh pointer of elementwise field: %s, did you call init_from_input(Input::Record)?\n", field_name_.c_str());
103 ASSERT(data_,
"Null data pointer.\n");
104 if (reader_ == NULL)
return false;
108 if (time == numeric_limits< double >::infinity())
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;
120 bool boundary_domain_ =
false;
121 reader_->read_element_data(search_header, data_, source_mesh_->elements_id_maps(boundary_domain_) );
123 return search_header.
actual;
128 template <
int spacedim,
class Value>
131 ASSERT( elm.
is_elemental(),
"FieldInterpolatedP0 works only for 'elemental' ElementAccessors.\n");
132 if (elm.
idx() != computed_elm_idx_ || elm.
is_boundary() != computed_elm_boundary_) {
133 computed_elm_idx_ = elm.
idx();
136 if (elm.
dim() == 3) {
137 xprintf(
Err,
"Dimension of element in target mesh must be 0, 1 or 2! elm.idx() = %d\n", elm.
idx());
143 if (elm.
dim() == 0) {
144 searched_elements_.clear();
149 searched_elements_.clear();
150 ((
BIHTree *)bih_tree_)->find_bounding_box(bb, searched_elements_);
154 for (
unsigned int i=0; i < this->value_.n_rows(); i++) {
155 for (
unsigned int j=0; j < this->value_.n_cols(); j++) {
156 this->value_(i,j) = 0.0;
160 double total_measure=0.0, measure;
168 if (ele->dim() == 3) {
174 if ( tetrahedron_.IsInner(point_) ) {
202 if (measure > epsilon) {
203 unsigned int index = this->value_.n_rows() * this->value_.n_cols() * (*it);
204 typename Value::element_type * ele_data_ptr = (
typename Value::element_type *)(data_+index);
205 typename Value::return_type & ret_type_value =
const_cast<typename Value::return_type &
>( Value::from_raw(this->r_value_, ele_data_ptr) );
206 Value tmp_value = Value( ret_type_value );
208 for (
unsigned int i=0; i < this->value_.n_rows(); i++) {
209 for (
unsigned int j=0; j < this->value_.n_cols(); j++) {
210 this->value_(i,j) += tmp_value(i,j) * measure;
213 total_measure += measure;
216 xprintf(
Err,
"Dimension of element in source mesh must be 3!\n");
221 if (total_measure > epsilon) {
222 for (
unsigned int i=0; i < this->value_.n_rows(); i++) {
223 for (
unsigned int j=0; j < this->value_.n_cols(); j++) {
224 this->value_(i,j) /= total_measure;
228 xprintf(
Warn,
"Processed element with idx %d is out of source mesh!\n", elm.
idx());
233 return this->r_value_;
238 template <
int spacedim,
class Value>
242 ASSERT( elm.
is_elemental(),
"FieldInterpolatedP0 works only for 'elemental' ElementAccessors.\n");
const Element * element() const
Bounding box in 3d ambient space.
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)
#define END_TIMER(tag)
Ends a timer with specified tag.
virtual bool set_time(double time)
void GetIntersection(const TBisector &, const TBisector &, TPosition &, double &, double &)