18 #ifndef FIELD_ELEMENTWISE_IMPL_HH_
19 #define FIELD_ELEMENTWISE_IMPL_HH_
30 namespace IT = Input::Type;
35 template <
int spacedim, class Value>
41 "Input file with ASCII GMSH file format.")
43 "The values of the Field are read from the ```$ElementData``` section with field name given by this key.")
48 template <
int spacedim,
class Value>
50 Input::register_class< FieldElementwise<spacedim, Value>,
unsigned int >(
"FieldElementwise") +
55 template <
int spacedim,
class Value>
58 internal_raw_data(true), mesh_(NULL)
66 template <
int spacedim,
class Value>
68 unsigned int n_components)
70 internal_raw_data(false), mesh_(NULL)
79 template <
int spacedim,
class Value>
81 cout << string(reader_file_) << endl;
82 OLD_ASSERT( internal_raw_data,
"Trying to initialize internal FieldElementwise from input.");
87 field_name_ = rec.
val<std::string>(
"field_name");
92 template <
int spacedim,
class Value>
95 OLD_ASSERT( this->value_.n_cols() == ref.n_cols(),
"Size of variable vectors do not match.\n" );
96 OLD_ASSERT( mesh_,
"Null mesh pointer of elementwise field: %s, did you call set_mesh()?\n", field_name_.c_str());
97 OLD_ASSERT( boundary_domain_ ,
"Method set_data_row can be used only for boundary fields.");
98 unsigned int vec_pos = boundary_idx * n_components_;
100 for(
unsigned int row=0; row < ref.n_rows(); row++)
101 for(
unsigned int col=0; col < ref.n_cols(); col++, vec_pos++)
102 vec[vec_pos] = ref(row,col);
107 template <
int spacedim,
class Value>
109 OLD_ASSERT(mesh_,
"Null mesh pointer of elementwise field: %s, did you call set_mesh()?\n", field_name_.c_str());
110 if ( reader_file_ ==
FilePath() )
return false;
117 search_header.
actual=
false;
125 mesh_->elements_id_maps(boundary_domain_), this->component_idx_);
126 return search_header.actual;
131 template <
int spacedim,
class Value>
134 OLD_ASSERT(mesh_ ==
nullptr || mesh_ == mesh,
"Trying to change mesh of the FieldElementwise.");
135 boundary_domain_ = boundary_domain;
138 if (boundary_domain_) {
141 n_entities_=mesh_->n_elements();
146 data_ = std::make_shared<std::vector<typename Value::element_type>>();
147 data_->resize(n_entities_ * n_components_);
157 template <
int spacedim,
class Value>
161 OLD_ASSERT( elm.
is_boundary() == boundary_domain_,
"Trying to get value of FieldElementwise '%s' for wrong ElementAccessor type (boundary/bulk).\n", field_name_.c_str() );
163 unsigned int idx = n_components_*elm.
idx();
166 return Value::from_raw(this->r_value_, (
typename Value::element_type *)(&vec[idx]));
174 template <
int spacedim,
class Value>
179 OLD_ASSERT( elm.
is_boundary() == boundary_domain_,
"Trying to get value of FieldElementwise '%s' for wrong ElementAccessor type (boundary/bulk).\n", field_name_.c_str() );
181 if (boost::is_floating_point< typename Value::element_type>::value) {
182 unsigned int idx = n_components_*elm.
idx();
185 typename Value::return_type
const &ref = Value::from_raw(this->r_value_, (
typename Value::element_type *)(&vec[idx]));
186 for(
unsigned int i=0; i< value_list.size(); i++) {
187 OLD_ASSERT( Value(value_list[i]).n_rows()==this->value_.n_rows(),
188 "value_list[%d] has wrong number of rows: %d; should match number of components: %d\n",
189 i, Value(value_list[i]).n_rows(),this->value_.n_rows());
194 xprintf(
UsrErr,
"FieldElementwise is not implemented for discrete return types.\n");
200 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.
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
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)
#define OLD_ASSERT_EQUAL(a, b)
virtual void set_mesh(const Mesh *mesh, bool boundary_domain)
static ReaderInstances * instance()
Returns singleton instance.
Representation of one time step.
#define FLOW123D_FORCE_LINK_IN_CHILD(x)