8 #ifndef FIELD_ELEMENTWISE_IMPL_HH_
9 #define FIELD_ELEMENTWISE_IMPL_HH_
22 template <
int spacedim,
class Value>
27 template <
int spacedim,
class Value>
36 "Input file with ASCII GMSH file format.")
38 "The values of the Field are read from the \\$ElementData section with field name given by this key.")
46 template <
int spacedim,
class Value>
49 internal_raw_data(true), mesh_(NULL)
57 template <
int spacedim,
class Value>
59 unsigned int n_components)
61 internal_raw_data(false), mesh_(NULL)
70 template <
int spacedim,
class Value>
72 cout << string(reader_file_) << endl;
73 ASSERT( internal_raw_data,
"Trying to initialize internal FieldElementwise from input.");
74 ASSERT( reader_file_ ==
FilePath(),
"Multiple call of init_from_input.\n");
78 field_name_ = rec.
val<std::string>(
"field_name");
83 template <
int spacedim,
class Value>
86 ASSERT( this->value_.n_cols() == ref.n_cols(),
"Size of variable vectors do not match.\n" );
87 ASSERT( mesh_,
"Null mesh pointer of elementwise field: %s, did you call set_mesh()?\n", field_name_.c_str());
88 ASSERT( boundary_domain_ ,
"Method set_data_row can be used only for boundary fields.");
89 unsigned int vec_pos = boundary_idx * n_components_;
91 for(
unsigned int row=0; row < ref.n_rows(); row++)
92 for(
unsigned int col=0; col < ref.n_cols(); col++, vec_pos++)
93 vec[vec_pos] = ref(row,col);
98 template <
int spacedim,
class Value>
100 ASSERT(mesh_,
"Null mesh pointer of elementwise field: %s, did you call set_mesh()?\n", field_name_.c_str());
101 if ( reader_file_ ==
FilePath() )
return false;
108 search_header.
actual=
false;
116 mesh_->elements_id_maps(boundary_domain_), this->component_idx_);
117 return search_header.actual;
122 template <
int spacedim,
class Value>
125 ASSERT(mesh_ ==
nullptr || mesh_ == mesh,
"Trying to change mesh of the FieldElementwise.");
126 boundary_domain_ = boundary_domain;
129 if (boundary_domain_) {
132 n_entities_=mesh_->n_elements();
137 data_ = std::make_shared<std::vector<typename Value::element_type>>();
138 data_->resize(n_entities_ * n_components_);
148 template <
int spacedim,
class Value>
151 ASSERT( elm.
is_elemental(),
"FieldElementwise works only for 'elemental' ElementAccessors.\n");
152 ASSERT( elm.
is_boundary() == boundary_domain_,
"Trying to get value of FieldElementwise '%s' for wrong ElementAccessor type (boundary/bulk).\n", field_name_.c_str() );
154 unsigned int idx = n_components_*elm.
idx();
157 return Value::from_raw(this->r_value_, (
typename Value::element_type *)(&vec[idx]));
165 template <
int spacedim,
class Value>
169 ASSERT( elm.
is_elemental(),
"FieldElementwise works only for 'elemental' ElementAccessors.\n");
170 ASSERT( elm.
is_boundary() == boundary_domain_,
"Trying to get value of FieldElementwise '%s' for wrong ElementAccessor type (boundary/bulk).\n", field_name_.c_str() );
172 if (boost::is_floating_point< typename Value::element_type>::value) {
173 unsigned int idx = n_components_*elm.
idx();
176 typename Value::return_type
const &ref = Value::from_raw(this->r_value_, (
typename Value::element_type *)(&vec[idx]));
177 for(
unsigned int i=0; i< value_list.size(); i++) {
178 ASSERT( Value(value_list[i]).n_rows()==this->value_.n_rows(),
179 "value_list[%d] has wrong number of rows: %d; should match number of components: %d\n",
180 i, Value(value_list[i]).n_rows(),this->value_.n_rows());
185 xprintf(
UsrErr,
"FieldElementwise is not implemented for discrete return types.\n");
191 template <
int spacedim,
class Value>
std::shared_ptr< std::vector< typename Value::element_type > > data_
Raw buffer of n_entities rows each containing Value::size() doubles.
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...
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
bool set_time(const TimeStep &time) override
#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)
std::shared_ptr< GmshMeshReader > get_reader(const FilePath &file_path)
virtual void set_mesh(const Mesh *mesh, bool boundary_domain)
static ReaderInstances * instance()
Returns singleton instance.
Representation of one time step.