Flow123d
JS_before_hm-2087-gb06a8f5d8
|
Go to the documentation of this file.
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>
69 .error(
"Assignment between multi fields with different meshes.\n");
70 ASSERT_GT_DBG( 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>
117 ASSERT(
false).error(
"This method can't be used for MultiField");
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 );
212 template<
int spacedim,
class Value>
215 for(
auto &field : sub_fields_) field.observe_output(observe);
221 template<
int spacedim,
class Value>
224 for(
auto &field : sub_fields_) const_all = const_all && field.is_constant(reg);
228 template<
int spacedim,
class Value>
231 ASSERT_DBG(
true).error(
"Not used yet. Test it.");
234 for(
auto &field : sub_fields_) {
235 FieldResult sub_result = field.field_result(region_set);
239 result_all = sub_result;
242 else if (sub_result != result_all)
251 template<
int spacedim,
class Value>
254 int nrows = Value::NRows_;
255 int ncols = Value::NCols_;
256 string type =
"Integer";
260 return fmt::format(
"{{ \"subfields\": true, \"shape\": [ {}, {} ], \"type\": \"{}\", \"limit\": [ {}, {} ] }}",
261 nrows, ncols, type, this->limits().first, this->limits().second);
265 template<
int spacedim,
class Value>
267 unsigned int comp_size = this->shared_->comp_names_.size();
268 ASSERT_GT(comp_size, 0).error(
"Vector of component names is empty!\n");
269 ASSERT_PTR(this->shared_->mesh_).error(
"Mesh is not set!\n");
271 sub_fields_.reserve( comp_size );
272 for(
unsigned int i_comp=0; i_comp < comp_size; i_comp++)
274 sub_fields_.push_back(
SubFieldType(i_comp, name(), this->full_comp_name(i_comp), is_bc()) );
275 sub_fields_[i_comp].units( units() );
276 if (no_check_control_field_ !=
nullptr && no_check_control_field_->size() == sub_fields_.size())
277 sub_fields_[i_comp].disable_where((*no_check_control_field_)[i_comp], shared_->no_check_values_);
278 sub_fields_[i_comp].set_mesh( *(shared_->mesh_) );
280 sub_fields_[i_comp].input_selection(shared_->input_element_selection_);
281 sub_fields_[i_comp].add_factory( std::make_shared<MultiFieldFactory>(i_comp) );
283 if (this->shared_->input_default_!=
"") {
284 sub_fields_[i_comp].shared_->input_default_ = this->shared_->input_default_;
287 sub_fields_[i_comp].flags_ = this->flags_;
288 sub_fields_[i_comp].set_input_list(this->full_input_list_, *tg_);
294 template<
int spacedim,
class Value>
303 if (
it->opt_val(this->input_name(), mf_array) ) {
304 unsigned int comp_size = this->shared_->comp_names_.
size();
305 if (mf_array.
size() != 1 && mf_array.
size() != comp_size)
306 THROW( Exc_InvalidMultiFieldSize() << EI_MultiFieldName(this->input_name())
307 << EI_Size(mf_array.
size()) << EI_ExpectedSize(comp_size) <<
list.ei_address() );
311 this->full_input_list_ =
list;
315 list.copy_to(shared_->input_list_);
342 template<
int spacedim,
class Value>
349 unsigned int position = 0;
351 if (multifield_arr.
size() > 1)
352 while (
index_ != position) {
358 field_algo_base->set_component_idx(
index_);
359 return field_algo_base;
367 template<
int spacedim,
class Value>
373 template<
int spacedim,
class Value>
375 ASSERT(
false).error(
"Set dependency of MultiField should be performed by individual components!\n");
381 template<
int spacedim,
class Value>
384 ASSERT(
false).error(
"Cache reallocate of MultiField should be performed by individual components!\n");
388 template<
int spacedim,
class Value>
390 FMT_UNUSED unsigned int region_patch_idx)
const {
391 ASSERT(
false).error(
"Cache update of MultiField should be performed by individual components!\n");
395 template<
int spacedim,
class Value>
401 unsigned int comp_size = this->
shared_->comp_names_.size();
402 ASSERT_GT_DBG(comp_size, 0).error(
"Vector of component names is empty!\n");
407 for(
unsigned int i_comp=0; i_comp < comp_size; i_comp++)
417 template<
int spacedim,
class Value>
423 ASSERT_EQ_DBG(this->
shared_->comp_names_.size(), 1).error(
"Size of component names vector must be 1!\n");
FieldCommon & units(const UnitSI &units)
Set basic units of the field.
std::shared_ptr< SharedData > shared_
void cache_reallocate(const ElementCacheMap &cache_map, unsigned int region_idx) const override
Implements FieldCommon::cache_reallocate.
LimitSide last_limit_side_
#define ASSERT_GT(a, b)
Definition of comparative assert macro (Greater Than)
void set_mesh(const Mesh &mesh) override
Field< spacedim, Value > SubFieldType
auto disable_where(const MultiField< spacedim, typename FieldValue< spacedim >::Enum > &control_field, const vector< FieldEnum > &value_list) -> MultiField &
#define ASSERT_GT_DBG(a, b)
Definition of comparative assert macro (Greater Than) only for debug mode.
std::vector< const FieldCommon * > set_dependency(FieldSet &field_set, unsigned int i_reg) const override
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
void set_shape(uint n_rows, uint n_cols)
void set(std::vector< typename Field< spacedim, Value >::FieldBasePtr > field_vec, double time, std::vector< std::string > region_set_names={"ALL"})
bool is_constant(Region reg) override
Directing class of FieldValueCache.
static constexpr bool value
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
std::string get_value_attribute() const override
virtual Field< spacedim, Value >::FieldBasePtr create_field(Input::Record rec, const FieldCommon &field)
#define ASSERT_EQ_DBG(a, b)
Definition of comparative assert macro (EQual) only for debug mode.
IT::Instance get_input_type() override
FieldFlag::Flags flags_
Field flags. Default setting is "an equation input field, that can read from user input,...
void field_output(std::shared_ptr< OutputTime > stream, OutputTime::DiscreteSpace type) override
std::string format(CStringRef format_str, ArgList args)
Input::Array full_input_list_
Full list of input field descriptors from which the subfields of MultiField are set.
bool is_active_field_descriptor(const Input::Record &in_rec, const std::string &input_name) override
#define ASSERT_LT(a, b)
Definition of comparative assert macro (Less Than)
#define ASSERT_PTR_DBG(ptr)
Definition of assert macro checking non-null pointer (PTR) only for debug mode.
std::vector< uint > shape_
void cache_update(ElementCacheMap &cache_map, unsigned int region_patch_idx) const override
Implements FieldCommon::cache_update.
void copy_from(const FieldCommon &other) override
unsigned int size() const
Number of subfields that compose the multi-field.
Helper struct stores data for initizalize descentants of FieldAlgorithmBase.
bool set_time(const TimeStep &time, LimitSide limit_side) override
void set_input_list(const Input::Array &list, const TimeGovernor &tg) override
Representation of one time step..
Basic time management functionality for unsteady (and steady) solvers (class Equation).
Common abstract parent of all Field<...> classes.
MultiField & operator=(const MultiField &other)
Container for various descendants of FieldCommonBase.
FieldResult field_result(RegionSet region_set) const override
Indicates special field states.
std::shared_ptr< FieldBaseType > FieldBasePtr
Class for representation of a vector of fields of the same physical quantity.
IT::Array get_multifield_input_type() override
std::vector< SubFieldType > sub_fields_
Subfields (items) of MultiField.
static constexpr Mask equation_input
The field is data parameter of the owning equation. (default on)
FieldFlag::Flags get_flags() const
static constexpr Mask declare_input
The field can be set from input. The key in input field descriptor is declared. (default on)
const std::string & name() const
unsigned int n_comp() const
const std::string & input_name() const
std::pair< double, double > limits() const
const MultiField< spacedim, typename FieldValue< spacedim >::Enum > * no_check_control_field_
void observe_output(std::shared_ptr< Observe > observe) override
#define ASSERT_PTR(ptr)
Definition of assert macro checking non-null pointer (PTR)
static const unsigned int N_DISCRETE_SPACES
static std::shared_ptr< FieldAlgorithmBase< spacedim, Value > > function_factory(const Input::AbstractRecord &rec, const struct FieldAlgoBaseInitData &init_data)
TimeStatus set_time_result_
unsigned int component_index_
FieldCommon & name(const string &name)
MultiField(bool bc=false)