29 #ifndef FIELD_INTERPOLATED_P0_IMPL_HH_
30 #define FIELD_INTERPOLATED_P0_IMPL_HH_
44 namespace it = Input::Type;
57 template <
int spacedim,
class Value>
62 template <
int spacedim,
class Value>
71 "Input file with ASCII GMSH file format.")
73 "The values of the Field are read from the $ElementData section with field name given by this key.")
80 template <
int spacedim,
class Value>
88 template <
int spacedim,
class Value>
93 source_mesh_ =
new Mesh();
95 reader_->read_mesh( source_mesh_ );
98 bih_tree_ =
new BIHTree( source_mesh_ );
101 unsigned int data_size = source_mesh_->element.size() * (this->value_.n_rows() * this->value_.n_cols());
102 data_ =
new double[data_size];
103 std::fill(data_, data_ + data_size, 0.0);
105 field_name_ = rec.
val<std::string>(
"field_name");
129 template <
int spacedim,
class Value>
131 ASSERT(( ele->
dim() == 3 ),
"Dimension of element must be 3!\n");
141 template <
int spacedim,
class Value>
143 ASSERT(( ele->
dim() == 2 ),
"Dimension of element must be 2!\n");
152 template <
int spacedim,
class Value>
154 ASSERT(( ele->
dim() == 1 ),
"Dimension of element must be 1!\n");
162 template <
int spacedim,
class Value>
164 ASSERT(( ele->
dim() == 0 ),
"Dimension of element must be 0!\n");
171 template <
int spacedim,
class Value>
173 ASSERT(source_mesh_,
"Null mesh pointer of elementwise field: %s, did you call init_from_input(Input::Record)?\n", field_name_.c_str());
174 ASSERT(data_,
"Null data pointer.\n");
175 if (reader_ == NULL)
return false;
179 if (time == numeric_limits< double >::infinity())
return false;
182 search_header.
actual =
false;
184 search_header.
n_components = this->value_.n_rows() * this->value_.n_cols();
185 search_header.
n_entities = source_mesh_->element.size();
186 search_header.
time = time;
188 bool boundary_domain_ =
false;
190 reader_->read_element_data(search_header, data_, source_mesh_->elements_id_maps(boundary_domain_) );
193 return search_header.
actual;
198 template <
int spacedim,
class Value>
201 ASSERT( elm.
is_elemental(),
"FieldInterpolatedP0 works only for 'elemental' ElementAccessors.\n");
202 if (elm.
idx() != computed_elm_idx_) {
203 computed_elm_idx_ = elm.
idx();
205 if (elm.
dim() == 3) {
206 xprintf(
Err,
"Dimension of element in target mesh must be 0, 1 or 2! elm.idx() = %d\n", elm.
idx());
212 if (elm.
dim() == 0) {
215 searched_elements_.clear();
220 searched_elements_.clear();
221 ((
BIHTree *)bih_tree_)->find_bounding_box(bb, searched_elements_);
225 for (
unsigned int i=0; i < this->value_.n_rows(); i++) {
226 for (
unsigned int j=0; j < this->value_.n_cols(); j++) {
227 this->value_(i,j) = 0.0;
231 double total_measure=0.0, measure;
239 if (ele->dim() == 3) {
240 create_tetrahedron(ele, tetrahedron_);
244 create_point(elm.
element(), point_);
245 if ( tetrahedron_.IsInner(point_) ) {
253 create_abscissa(elm.
element(), abscissa_);
261 create_triangle(elm.
element(), triangle_);
273 if (measure > epsilon) {
274 unsigned int index = this->value_.n_rows() * this->value_.n_cols() * (*it);
275 typename Value::element_type * ele_data_ptr = (
typename Value::element_type *)(data_+index);
276 typename Value::return_type & ret_type_value =
const_cast<typename Value::return_type &
>( Value::from_raw(this->r_value_, ele_data_ptr) );
277 Value tmp_value = Value( ret_type_value );
288 for (
unsigned int i=0; i < this->value_.n_rows(); i++) {
289 for (
unsigned int j=0; j < this->value_.n_cols(); j++) {
290 this->value_(i,j) += tmp_value(i,j) * measure;
293 total_measure += measure;
296 xprintf(
Err,
"Dimension of element in source mesh must be 3!\n");
301 if (total_measure > epsilon) {
302 for (
unsigned int i=0; i < this->value_.n_rows(); i++) {
303 for (
unsigned int j=0; j < this->value_.n_cols(); j++) {
304 this->value_(i,j) /= total_measure;
308 xprintf(
Warn,
"Processed element with idx %d is out of source mesh!\n", elm.
idx());
313 return this->r_value_;
318 template <
int spacedim,
class Value>
322 ASSERT( elm.
is_elemental(),
"FieldInterpolatedP0 works only for 'elemental' ElementAccessors.\n");