18 #ifndef MULTI_FIELD_IMPL_HH_
19 #define MULTI_FIELD_IMPL_HH_
37 template<
int spacedim,
class Value>
40 no_check_control_field_(nullptr)
45 this->
set_shape( Value::NRows_, Value::NCols_ );
50 template<
int spacedim,
class Value>
53 sub_fields_(other.sub_fields_),
54 full_input_list_(other.full_input_list_),
55 no_check_control_field_(other.no_check_control_field_)
58 this->
set_shape( Value::NRows_, Value::NCols_ );
63 template<
int spacedim,
class Value>
67 ASSERT_PTR(other.
shared_->mesh_).error(
"Must call set_mesh before assign to other field.\n");
68 ASSERT( !shared_->mesh_ || (shared_->mesh_==other.
shared_->mesh_))
69 .error(
"Assignment between multi fields with different meshes.\n");
70 ASSERT_GT( shared_->comp_names_.size(), 0).error(
"Vector of component names can't be empty!\n");
72 .error(
"Both multi fields must have same size of vectors of component names.\n");
75 if (&other ==
this)
return *
this;
80 shared_->comp_names_ = comp_names;
81 shared_->is_fully_initialized_ =
false;
87 this->multifield_ =
true;
88 this->shape_ = other.
shape_;
94 sub_fields_.reserve( other.
size() );
95 for (
unsigned int i=0; i<other.
size(); ++i) {
97 if (this->shared_->comp_names_[i].length() == 0)
98 THROW( Input::ExcInputMessage() << EI_Message(
"The field " + this->input_name()
99 +
" has set empty name of component.") );
101 sub_fields_[i].name_ = this->shared_->comp_names_[i] +
"_" + name();
105 THROW( ExcMessage() << EI_Message(
"Internal error. Assignment operator can't be used after call setup_component() method.") );
115 template<
int spacedim,
class Value>
125 template<
int spacedim,
class Value>
127 it::Array type =
it::Array( SubFieldBaseType::get_input_type_instance(shared_->input_element_selection_), 1);
132 template<
int spacedim,
class Value>
137 no_check_control_field_=&control_field;
138 shared_->no_check_values_=value_list;
143 template<
int spacedim,
class Value>
148 if (sub_fields_.size() == 0) {
153 set_time_result_ = TimeStatus::constant;
156 if (field.set_time(time, limit_side))
157 set_time_result_ = TimeStatus::changed;
158 is_jump_time_ = is_jump_time_ || field.is_jump_time();
160 return (set_time_result_ == TimeStatus::changed);
165 template<
int spacedim,
class Value>
168 if (shared_->mesh_ && shared_->mesh_ != &mesh) {
169 THROW(ExcFieldMeshDifference() << EI_Field(name()) );
172 shared_->mesh_ = &mesh;
176 template<
int spacedim,
class Value>
179 .error(
"Can not copy to the non-copy field.");
183 && this->shared_->input_list_.size() != 0 )
return;
185 if (
typeid(other) ==
typeid(*this)) {
187 this->operator=(other_field);
189 auto const &other_field =
dynamic_cast< SubFieldType const &
>(other);
190 sub_fields_.resize(1);
191 sub_fields_[0] = other_field;
197 template<
int spacedim,
class Value>
204 for (
unsigned long index=0; index < this->size(); index++) {
205 sub_fields_[index].compute_field_data( type, stream );
213 template<
int spacedim,
class Value>
216 for(
auto &field : sub_fields_) const_all = const_all && field.is_constant(reg);
220 template<
int spacedim,
class Value>
223 ASSERT(
true).error(
"Not used yet. Test it.");
226 for(
auto &field : sub_fields_) {
227 FieldResult sub_result = field.field_result(region_set);
231 result_all = sub_result;
234 else if (sub_result != result_all)
243 template<
int spacedim,
class Value>
246 int nrows = Value::NRows_;
247 int ncols = Value::NCols_;
248 string type =
"Integer";
252 return fmt::format(
"{{ \"subfields\": true, \"shape\": [ {}, {} ], \"type\": \"{}\", \"limit\": [ {}, {} ] }}",
253 nrows, ncols, type, this->limits().first, this->limits().second);
257 template<
int spacedim,
class Value>
259 unsigned int comp_size = this->shared_->comp_names_.size();
260 ASSERT_GT(comp_size, 0).error(
"Vector of component names is empty!\n");
261 ASSERT_PTR(this->shared_->mesh_).error(
"Mesh is not set!\n");
262 ASSERT_EQ(sub_fields_.size(), 0).error(
"Cannot call setup_components() on already existing sub-fields!\n");
264 sub_fields_.reserve( comp_size );
265 for(
unsigned int i_comp=0; i_comp < comp_size; i_comp++)
267 sub_fields_.push_back(
SubFieldType(i_comp, name(), this->full_comp_name(i_comp), is_bc()) );
268 sub_fields_[i_comp].units( units() );
269 if (no_check_control_field_ !=
nullptr && no_check_control_field_->size() == sub_fields_.size())
270 sub_fields_[i_comp].disable_where((*no_check_control_field_)[i_comp], shared_->no_check_values_);
271 sub_fields_[i_comp].set_mesh( *(shared_->mesh_) );
273 sub_fields_[i_comp].input_selection(shared_->input_element_selection_);
274 sub_fields_[i_comp].add_factory( std::make_shared<MultiFieldFactory>(i_comp) );
276 if (this->shared_->input_default_!=
"") {
277 sub_fields_[i_comp].shared_->input_default_ = this->shared_->input_default_;
280 sub_fields_[i_comp].flags_ = this->flags_;
281 sub_fields_[i_comp].set_input_list(this->full_input_list_, *tg_);
282 sub_fields_[i_comp].set_default_fieldset( *(this->shared_->default_fieldset_) );
287 template<
int spacedim,
class Value>
289 unsigned int comp_size = this->shared_->comp_names_.size();
290 ASSERT_GT(comp_size, 0).error(
"Vector of component names is empty!\n");
291 ASSERT_PTR(this->shared_->mesh_).error(
"Mesh is not set!\n");
292 ASSERT_EQ(sub_fields_.size(), comp_size).error(
"Component number mismatch!\n");
294 for(
unsigned int i_comp=0; i_comp < comp_size; i_comp++)
295 sub_fields_[i_comp].name_ = this->full_comp_name(i_comp);
300 template<
int spacedim,
class Value>
309 if (
it->opt_val(this->input_name(), mf_array) ) {
310 unsigned int comp_size = this->shared_->comp_names_.
size();
311 if (mf_array.
size() != 1 && mf_array.
size() != comp_size)
312 THROW( Exc_InvalidMultiFieldSize() << EI_MultiFieldName(this->input_name())
313 << EI_Size(mf_array.
size()) << EI_ExpectedSize(comp_size) <<
list.ei_address() );
317 this->full_input_list_ =
list;
321 list.copy_to(shared_->input_list_);
348 template<
int spacedim,
class Value>
355 unsigned int position = 0;
357 if (multifield_arr.
size() > 1)
358 while (
index_ != position) {
364 field_algo_base->set_component_idx(
index_);
365 return field_algo_base;
373 template<
int spacedim,
class Value>
379 template<
int spacedim,
class Value>
381 ASSERT_PERMANENT(
false).error(
"Set dependency of MultiField should be performed by individual components!\n");
387 template<
int spacedim,
class Value>
390 ASSERT_PERMANENT(
false).error(
"Cache reallocate of MultiField should be performed by individual components!\n");
394 template<
int spacedim,
class Value>
396 FMT_UNUSED unsigned int region_patch_idx)
const {
397 ASSERT_PERMANENT(
false).error(
"Cache update of MultiField should be performed by individual components!\n");
401 template<
int spacedim,
class Value>
407 unsigned int comp_size = this->
shared_->comp_names_.size();
408 ASSERT_GT(comp_size, 0).error(
"Vector of component names is empty!\n");
413 for(
unsigned int i_comp=0; i_comp < comp_size; i_comp++)
423 template<
int spacedim,
class Value>
429 ASSERT_EQ(this->
shared_->comp_names_.size(), 1).error(
"Size of component names vector must be 1!\n");