29 #ifndef FIELD_INTERPOLATED_P0_IMPL_HH_
30 #define FIELD_INTERPOLATED_P0_IMPL_HH_
44 namespace it = Input::Type;
48 template <
int spacedim,
class Value>
54 template <
int spacedim,
class Value>
63 "Input file with ASCII GMSH file format.")
65 "The values of the Field are read from the $ElementData section with field name given by this key.")
73 template <
int spacedim,
class Value>
80 template <
int spacedim,
class Value>
85 source_mesh_ =
new Mesh();
87 reader_->read_mesh( source_mesh_ );
90 bih_tree_ =
new BIHTree( source_mesh_ );
93 unsigned int data_size = source_mesh_->element.size() * (this->value_.n_rows() * this->value_.n_cols());
94 data_ =
new double[data_size];
95 std::fill(data_, data_ + data_size, 0.0);
97 field_name_ = rec.
val<std::string>(
"field_name");
103 template <
int spacedim,
class Value>
105 ASSERT(source_mesh_,
"Null mesh pointer of elementwise field: %s, did you call init_from_input(Input::Record)?\n", field_name_.c_str());
106 ASSERT(data_,
"Null data pointer.\n");
107 if (reader_ == NULL)
return false;
111 if (time == numeric_limits< double >::infinity())
return false;
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;
122 reader_->read_element_data(search_header, data_, source_mesh_->elements_id_maps(boundary_domain_) );
125 return search_header.
actual;
130 template <
int spacedim,
class Value>
133 ASSERT( elm.
is_elemental(),
"FieldInterpolatedP0 works only for 'elemental' ElementAccessors.\n");
134 if (elm.
idx() != computed_elm_idx_) {
135 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) {
147 searched_elements_.clear();
152 searched_elements_.clear();
153 ((
BIHTree *)bih_tree_)->find_bounding_box(bb, searched_elements_);
157 for (
unsigned int i=0; i < this->value_.n_rows(); i++) {
158 for (
unsigned int j=0; j < this->value_.n_cols(); j++) {
159 this->value_(i,j) = 0.0;
163 double total_measure=0.0, measure;
171 if (ele->dim() == 3) {
177 if ( tetrahedron_.IsInner(point_) ) {
205 if (measure > epsilon) {
206 unsigned int index = this->value_.n_rows() * this->value_.n_cols() * (*it);
207 typename Value::element_type * ele_data_ptr = (
typename Value::element_type *)(data_+index);
208 typename Value::return_type & ret_type_value =
const_cast<typename Value::return_type &
>( Value::from_raw(this->r_value_, ele_data_ptr) );
209 Value tmp_value = Value( ret_type_value );
220 for (
unsigned int i=0; i < this->value_.n_rows(); i++) {
221 for (
unsigned int j=0; j < this->value_.n_cols(); j++) {
222 this->value_(i,j) += tmp_value(i,j) * measure;
225 total_measure += measure;
228 xprintf(
Err,
"Dimension of element in source mesh must be 3!\n");
233 if (total_measure > epsilon) {
234 for (
unsigned int i=0; i < this->value_.n_rows(); i++) {
235 for (
unsigned int j=0; j < this->value_.n_cols(); j++) {
236 this->value_(i,j) /= total_measure;
240 xprintf(
Warn,
"Processed element with idx %d is out of source mesh!\n", elm.
idx());
245 return this->r_value_;
250 template <
int spacedim,
class Value>
254 ASSERT( elm.
is_elemental(),
"FieldInterpolatedP0 works only for 'elemental' ElementAccessors.\n");