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>
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++) {
170 ASSERT( Value(value_list[i]).n_rows()==this->value_.n_rows(),
171 "value_list[%d] has wrong number of rows: %d; should match number of components: %d\n",
172 i, Value(value_list[i]).n_rows(),this->value_.n_rows());
177 xprintf(
UsrErr,
"FieldElementwise is not implemented for discrete return types.\n");
183 template <
int spacedim,
class Value>
185 if (internal_raw_data && data_ != NULL)
delete [] data_;
186 if (reader_ != NULL)
delete reader_;
static Input::Type::Record get_input_type(Input::Type::AbstractRecord &a_type, const typename Value::ElementInputType *eit)
virtual ~FieldElementwise()
virtual void init_from_input(const Input::Record &rec)
bool is_boundary() const
We need this method after replacing Region by RegionIdx, and movinf RegionDB instance into particular...
virtual bool set_time(double time)
void set_data_row(unsigned int boundary_idx, typename Value::return_type &value)
unsigned int size() const
Returns size of the container. This is independent of the allocated space.
bool is_elemental() const
#define ASSERT_EQUAL(a, b)
FieldElementwise(unsigned int n_comp=0)
ElementVector bc_elements
Space< spacedim >::Point Point
virtual void value_list(const std::vector< Point > &point_list, const ElementAccessor< spacedim > &elm, std::vector< typename Value::return_type > &value_list)
Dedicated class for storing path to input and output files.
unsigned int n_components_
Size of Value.
Value value_
Last value, prevents passing large values (vectors) by value.
virtual Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm)
virtual void set_mesh(const Mesh *mesh, bool boundary_domain)