18 #ifndef MULTI_FIELD_IMPL_HH_
19 #define MULTI_FIELD_IMPL_HH_
37 template<
int spacedim,
class Value>
40 no_check_control_field_(nullptr)
44 this->
set_shape( Value::NRows_, Value::NCols_ );
49 template<
int spacedim,
class Value>
52 sub_fields_(other.sub_fields_),
53 full_input_list_(other.full_input_list_),
54 no_check_control_field_(other.no_check_control_field_)
57 this->
set_shape( Value::NRows_, Value::NCols_ );
62 template<
int spacedim,
class Value>
66 ASSERT_PTR(other.
shared_->mesh_).error(
"Must call set_mesh before assign to other field.\n");
67 ASSERT( !shared_->mesh_ || (shared_->mesh_==other.
shared_->mesh_))
68 .error(
"Assignment between multi fields with different meshes.\n");
69 ASSERT_GT( shared_->comp_names_.size(), 0).error(
"Vector of component names can't be empty!\n");
71 .error(
"Both multi fields must have same size of vectors of component names.\n");
74 if (&other ==
this)
return *
this;
79 shared_->comp_names_ = comp_names;
80 shared_->is_fully_initialized_ =
false;
86 this->multifield_ =
true;
87 this->shape_ = other.
shape_;
93 sub_fields_.reserve( other.
size() );
94 for (
unsigned int i=0; i<other.
size(); ++i) {
96 if (this->shared_->comp_names_[i].length() == 0)
97 THROW( Input::ExcInputMessage() << EI_Message(
"The field " + this->input_name()
98 +
" has set empty name of component.") );
100 sub_fields_[i].name_ = this->shared_->comp_names_[i] +
"_" + name();
104 THROW( ExcMessage() << EI_Message(
"Internal error. Assignment operator can't be used after call setup_component() method.") );
114 template<
int spacedim,
class Value>
124 template<
int spacedim,
class Value>
126 it::Array type =
it::Array( SubFieldBaseType::get_input_type_instance(shared_->input_element_selection_), 1);
131 template<
int spacedim,
class Value>
136 no_check_control_field_=&control_field;
137 shared_->no_check_values_=value_list;
142 template<
int spacedim,
class Value>
147 if (sub_fields_.size() == 0) {
152 set_time_result_ = TimeStatus::constant;
155 if (field.set_time(time, limit_side))
156 set_time_result_ = TimeStatus::changed;
157 is_jump_time_ = is_jump_time_ || field.is_jump_time();
159 return (set_time_result_ == TimeStatus::changed);
164 template<
int spacedim,
class Value>
167 if (shared_->mesh_ && shared_->mesh_ != &mesh) {
168 THROW(ExcFieldMeshDifference() << EI_Field(name()) );
171 shared_->mesh_ = &mesh;
175 template<
int spacedim,
class Value>
178 .error(
"Can not copy to the non-copy field.");
182 && this->shared_->input_list_.size() != 0 )
return;
184 if (
typeid(other) ==
typeid(*this)) {
186 this->operator=(other_field);
187 }
else if (
typeid(other) ==
typeid(SubFieldType)) {
188 auto const &other_field =
dynamic_cast< SubFieldType
const &
>(other);
189 sub_fields_.resize(1);
190 sub_fields_[0] = other_field;
196 template<
int spacedim,
class Value>
201 for (
unsigned long index=0; index < this->size(); index++) {
202 sub_fields_[index].compute_field_data( type, stream );
209 template<
int spacedim,
class Value>
212 for(
auto &field : sub_fields_) const_all = const_all && field.is_constant(reg);
216 template<
int spacedim,
class Value>
219 ASSERT(
true).error(
"Not used yet. Test it.");
222 for(
auto &field : sub_fields_) {
223 FieldResult sub_result = field.field_result(region_set);
227 result_all = sub_result;
230 else if (sub_result != result_all)
239 template<
int spacedim,
class Value>
242 int nrows = Value::NRows_;
243 int ncols = Value::NCols_;
244 string type =
"Integer";
248 return fmt::format(
"{{ \"subfields\": true, \"shape\": [ {}, {} ], \"type\": \"{}\", \"limit\": [ {}, {} ] }}",
249 nrows, ncols, type, this->limits().first, this->limits().second);
253 template<
int spacedim,
class Value>
255 unsigned int comp_size = this->shared_->comp_names_.size();
256 ASSERT_GT(comp_size, 0).error(
"Vector of component names is empty!\n");
257 ASSERT_PTR(this->shared_->mesh_).error(
"Mesh is not set!\n");
259 sub_fields_.reserve( comp_size );
260 for(
unsigned int i_comp=0; i_comp < comp_size; i_comp++)
262 sub_fields_.push_back(
SubFieldType(i_comp, name(), this->full_comp_name(i_comp)) );
263 sub_fields_[i_comp].units( units() );
264 if (no_check_control_field_ !=
nullptr && no_check_control_field_->size() == sub_fields_.size())
265 sub_fields_[i_comp].disable_where((*no_check_control_field_)[i_comp], shared_->no_check_values_);
266 sub_fields_[i_comp].set_mesh( *(shared_->mesh_) );
268 sub_fields_[i_comp].input_selection(shared_->input_element_selection_);
269 sub_fields_[i_comp].add_factory( std::make_shared<MultiFieldFactory>(i_comp) );
271 if (this->shared_->input_default_!=
"") {
272 sub_fields_[i_comp].shared_->input_default_ = this->shared_->input_default_;
275 sub_fields_[i_comp].flags_ = this->flags_;
276 sub_fields_[i_comp].set_input_list(this->full_input_list_, *tg_);
277 sub_fields_[i_comp].set_default_fieldset( *(this->shared_->default_fieldset_) );
283 template<
int spacedim,
class Value>
292 if (
it->opt_val(this->input_name(), mf_array) ) {
293 unsigned int comp_size = this->shared_->comp_names_.
size();
294 if (mf_array.
size() != 1 && mf_array.
size() != comp_size)
295 THROW( Exc_InvalidMultiFieldSize() << EI_MultiFieldName(this->input_name())
296 << EI_Size(mf_array.
size()) << EI_ExpectedSize(comp_size) <<
list.ei_address() );
300 this->full_input_list_ =
list;
304 list.copy_to(shared_->input_list_);
309 template<
int spacedim,
class Value>
316 unsigned int position = 0;
318 if (multifield_arr.
size() > 1)
319 while (
index_ != position) {
325 field_algo_base->set_component_idx(
index_);
326 return field_algo_base;
334 template<
int spacedim,
class Value>
340 template<
int spacedim,
class Value>
342 ASSERT_PERMANENT(
false).error(
"Set dependency of MultiField should be performed by individual components!\n");
348 template<
int spacedim,
class Value>
351 ASSERT_PERMANENT(
false).error(
"Cache reallocate of MultiField should be performed by individual components!\n");
355 template<
int spacedim,
class Value>
357 FMT_UNUSED unsigned int region_patch_idx)
const {
358 ASSERT_PERMANENT(
false).error(
"Cache update of MultiField should be performed by individual components!\n");
362 template<
int spacedim,
class Value>
368 unsigned int comp_size = this->
shared_->comp_names_.size();
369 ASSERT_GT(comp_size, 0).error(
"Vector of component names is empty!\n");
373 sub_fields_.reserve( comp_size );
374 for(
unsigned int i_comp=0; i_comp < comp_size; i_comp++)
379 sub_fields_[i_comp].set(field_vec[i_comp],
time, region_set_names);
384 template<
int spacedim,
class Value>
390 ASSERT_EQ(this->
shared_->comp_names_.size(), 1).error(
"Size of component names vector must be 1!\n");
393 sub_fields_.reserve(1);
397 sub_fields_[0].set(field,
time, region_set_names);
#define ASSERT_PERMANENT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
#define ASSERT_LT(a, b)
Definition of comparative assert macro (Less Than) only for debug mode.
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual) only for debug mode.
#define ASSERT_GT(a, b)
Definition of comparative assert macro (Greater Than) only for debug mode.
#define ASSERT_PTR(ptr)
Definition of assert macro checking non-null pointer (PTR) only for debug mode.
Directing class of FieldValueCache.
static std::shared_ptr< FieldAlgorithmBase< spacedim, Value > > function_factory(const Input::AbstractRecord &rec, const struct FieldAlgoBaseInitData &init_data)
Common abstract parent of all Field<...> classes.
std::shared_ptr< SharedData > shared_
TimeStatus set_time_result_
unsigned int component_index_
const std::string & input_name() const
FieldFlag::Flags flags_
Field flags. Default setting is "an equation input field, that can read from user input,...
const std::string & name() const
LimitSide last_limit_side_
std::vector< uint > shape_
FieldCommon & name(const string &name)
std::pair< double, double > limits() const
FieldFlag::Flags get_flags() const
void set_shape(uint n_rows, uint n_cols)
FieldCommon & units(const UnitSI &units)
Set basic units of the field.
unsigned int n_comp() const
static constexpr Mask declare_input
The field can be set from input. The key in input field descriptor is declared. (default on)
static constexpr Mask equation_input
The field is data parameter of the owning equation. (default on)
Class template representing a field with values dependent on: point, element, and region.
std::shared_ptr< FieldBaseType > FieldBasePtr
virtual Field< spacedim, Value >::FieldBasePtr create_field(Input::Record rec, const FieldCommon &field)
bool is_active_field_descriptor(const Input::Record &in_rec, const std::string &input_name) override
Class for representation of a vector of fields of the same physical quantity.
std::string get_value_attribute() const override
Input::Array full_input_list_
Full list of input field descriptors from which the subfields of MultiField are set.
void copy_from(const FieldCommon &other) override
std::vector< const FieldCommon * > set_dependency(unsigned int i_reg) const override
void field_output(std::shared_ptr< OutputTime > stream, OutputTime::DiscreteSpace type) override
bool set_time(const TimeStep &time, LimitSide limit_side) override
MultiField & operator=(const MultiField &other)
void cache_update(ElementCacheMap &cache_map, unsigned int region_patch_idx) const override
Implements FieldCommon::cache_update.
unsigned int size() const
Number of subfields that compose the multi-field.
IT::Instance get_input_type() override
auto disable_where(const MultiField< spacedim, typename FieldValue< spacedim >::Enum > &control_field, const vector< FieldEnum > &value_list) -> MultiField &
std::vector< SubFieldType > sub_fields_
Subfields (items) of MultiField.
Field< spacedim, Value > SubFieldType
void set_input_list(const Input::Array &list, const TimeGovernor &tg) override
void cache_reallocate(const ElementCacheMap &cache_map, unsigned int region_idx) const override
Implements FieldCommon::cache_reallocate.
IT::Array get_multifield_input_type() override
void set_mesh(const Mesh &mesh) override
const MultiField< spacedim, typename FieldValue< spacedim >::Enum > * no_check_control_field_
void set(std::vector< typename Field< spacedim, Value >::FieldBasePtr > field_vec, double time, std::vector< std::string > region_set_names={"ALL"})
FieldResult field_result(RegionSet region_set) const override
Indicates special field states.
bool is_constant(Region reg) override
static const unsigned int N_DISCRETE_SPACES
Basic time management functionality for unsteady (and steady) solvers (class Equation).
Representation of one time step..
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
static constexpr bool value
std::string format(CStringRef format_str, ArgList args)
Helper struct stores data for initizalize descentants of FieldAlgorithmBase.