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);
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");
374 for(
unsigned int i_comp=0; i_comp < comp_size; i_comp++)
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");