8 #ifndef FIELD_ELEMENTWISE_IMPL_HH_
9 #define FIELD_ELEMENTWISE_IMPL_HH_
19 namespace IT = Input::Type;
21 template <
int spacedim,
class Value>
26 template <
int spacedim,
class Value>
35 "Input file with ASCII GMSH file format.")
37 "The values of the Field are read from the $ElementData section with field name given by this key.")
45 template <
int spacedim,
class Value>
48 internal_raw_data(true), data_(NULL), reader_(NULL), mesh_(NULL)
56 template <
int spacedim,
class Value>
58 :
FieldBase<spacedim, Value>(n_components),
59 internal_raw_data(false), data_size_(size), data_(data_ptr), reader_(NULL), mesh_(NULL)
66 template <
int spacedim,
class Value>
68 ASSERT( internal_raw_data,
"Trying to initialize internal FieldElementwise from input.");
70 ASSERT( reader_ == NULL,
"Multiple call of init_from_input.\n");
73 field_name_ = rec.
val<std::string>(
"field_name");
78 template <
int spacedim,
class Value>
81 ASSERT( this->value_.n_cols() == ref.n_cols(),
"Size of variable vectors do not match.\n" );
82 ASSERT( mesh_,
"Null mesh pointer of elementwise field: %s, did you call set_mesh()?\n", field_name_.c_str());
83 ASSERT( boundary_domain_ ,
"Method set_data_row can be used only for boundary fields.");
84 typename Value::element_type *ptr=(
typename Value::element_type *) ( data_+(boundary_idx)*n_components_);
85 for(
unsigned int row=0; row < ref.n_rows(); row++)
86 for(
unsigned int col=0; col < ref.n_cols(); col++, ptr++)
91 template <
int spacedim,
class Value>
93 ASSERT(mesh_,
"Null mesh pointer of elementwise field: %s, did you call set_mesh()?\n", field_name_.c_str());
94 ASSERT(data_,
"Null data pointer.\n");
95 if (reader_ == NULL)
return false;
99 if (time == numeric_limits< double >::infinity())
return false;
102 search_header.
actual=
false;
106 search_header.
time=time;
109 reader_->read_element_data(search_header, data_, mesh_->elements_id_maps(boundary_domain_) );
110 return search_header.
actual;
115 template <
int spacedim,
class Value>
118 ASSERT(mesh_ ==
nullptr || mesh_ == mesh,
"Trying to change mesh of the FieldElementwise.");
119 boundary_domain_ = boundary_domain;
122 if (boundary_domain_) {
125 n_entities_=mesh_->n_elements();
130 data_size_ = n_entities_ * n_components_;
131 data_ =
new double[data_size_];
132 std::fill(data_, data_ + data_size_, 0.0);
142 template <
int spacedim,
class Value>
145 ASSERT( elm.
is_elemental(),
"FieldElementwise works only for 'elemental' ElementAccessors.\n");
146 ASSERT( elm.
is_boundary() == boundary_domain_,
"Trying to get value of FieldElementwise '%s' for wrong ElementAccessor type (boundary/bulk).\n", field_name_.c_str() );
148 unsigned int idx = n_components_*elm.
idx();
150 return Value::from_raw(this->r_value_, (
typename Value::element_type *)(data_+idx));
158 template <
int spacedim,
class Value>
162 ASSERT( elm.
is_elemental(),
"FieldElementwise works only for 'elemental' ElementAccessors.\n");
163 ASSERT( elm.
is_boundary() == boundary_domain_,
"Trying to get value of FieldElementwise '%s' for wrong ElementAccessor type (boundary/bulk).\n", field_name_.c_str() );
165 if (boost::is_floating_point< typename Value::element_type>::value) {
166 unsigned int idx = n_components_*elm.
idx();
168 typename Value::return_type
const &ref = Value::from_raw(this->r_value_, (
typename Value::element_type *)(data_+idx));
169 for(
unsigned int i=0; i< value_list.size(); i++) value_list[i] = ref;
171 xprintf(
UsrErr,
"FieldElementwise is not implemented for discrete return types.\n");
177 template <
int spacedim,
class Value>
179 if (internal_raw_data && data_ != NULL)
delete [] data_;
180 if (reader_ != NULL)
delete reader_;