11 #include <boost/foreach.hpp>
22 template<
int spacedim,
class Value>
24 : read_field_descriptor_hook( &read_field_descriptor ),
30 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
34 template<
int spacedim,
class Value>
36 : read_field_descriptor_hook( &read_field_descriptor ),
42 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
49 template<
int spacedim,
class Value>
52 read_field_descriptor_hook( other.read_field_descriptor_hook ),
65 template<
int spacedim,
class Value>
68 ASSERT( flags().match(
FieldFlag::input_copy ) ,
"Try to assign to non-copy field '%s' from the field '%s'.", this->name().c_str(), other.
name().c_str());
69 ASSERT(other.
shared_->mesh_,
"Must call set_mesh before assign to other field.\n");
70 ASSERT( !shared_->mesh_ || (shared_->mesh_==other.
shared_->mesh_),
71 "Assignment between fields with different meshes.\n");
74 if (&other ==
this)
return *
this;
77 shared_->is_fully_initialized_ =
false;
89 this->set_mesh( *(shared_->mesh_) );
97 template<
int spacedim,
class Value>
107 if (is_enum_valued) {
108 ar_list.push_back(make_input_tree());
109 return ar_list.back();
111 return FieldBaseType::input_type;
118 template <
class FieldBaseType>
122 "NULL pointer to selection in Field::get_input_type(), while Value==FieldEnum.\n");
123 return FieldBaseType::get_input_type(sel);
127 template <
class FieldBaseType>
130 return FieldBaseType::get_input_type(
nullptr);
137 template<
int spacedim,
class Value>
140 "Can not use make_input_tree() for non-enum valued fields, use get_inout_type() instead.\n" );
141 return get_input_type_resolution<FieldBaseType>(
142 shared_->input_element_selection_ ,
143 boost::is_same<typename Value::element_type, FieldEnum>());
148 template<
int spacedim,
class Value>
153 no_check_control_field_=std::make_shared<ControlField>(control_field);
154 shared_->no_check_values_=value_list;
158 template<
int spacedim,
class Value>
162 if (shared_->mesh_ && shared_->mesh_ != &in_mesh) {
163 THROW(ExcFieldMeshDifference() << EI_Field(name()) );
166 shared_->mesh_ = &in_mesh;
169 region_fields_.resize( mesh()->region_db().size() );
171 data_->region_history_.resize( mesh()->region_db().size(), init_history );
173 if (no_check_control_field_) no_check_control_field_->set_mesh(in_mesh);
188 template <
int spacedim,
class Value>
204 template<
int spacedim,
class Value>
210 ASSERT(field,
"Null field pointer.\n");
214 ASSERT( mesh(),
"Null mesh pointer, set_mesh() has to be called before set_field().\n");
215 if (domain.size() == 0)
return;
218 field->set_mesh( mesh() , is_bc() );
221 for(
const Region ®: domain) {
222 RegionHistory ®ion_history = data_->region_history_[reg.idx()];
224 ASSERT( region_history.size() == 0 || region_history[0].first < hp.first,
"Can not insert smaller time %g then last time %g in field's history.\n",
225 hp.first, region_history[0].first );
226 region_history.push_front(hp);
228 set_history_changed();
233 template<
int spacedim,
class Value>
239 set_field(domain, FieldBaseType::function_factory(a_rec, n_comp()), time);
244 template<
int spacedim,
class Value>
248 if (rec.opt_val(field.input_name(), field_record))
249 return FieldBaseType::function_factory(field_record, field.n_comp() );
257 template<
int spacedim,
class Value>
260 ASSERT( mesh() ,
"NULL mesh pointer of field '%s'. set_mesh must be called before.\n",name().c_str());
261 ASSERT( limit_side_ !=
LimitSide::unknown,
"Must set limit side on field '%s' before calling set_time.\n",name().c_str());
264 if (time.
t() == last_time_)
return changed();
268 if (no_check_control_field_) {
269 no_check_control_field_->set_limit_side(limit_side_);
270 no_check_control_field_->set_time(time);
273 set_time_result_ = TimeStatus::constant;
276 update_history(time);
277 check_initialized_region_fields_();
281 for(
const Region ®: mesh()->region_db().get_region_set(
"ALL") ) {
282 auto rh = data_->region_history_[reg.idx()];
286 if (reg.is_boundary() == is_bc() && !rh.empty() ) {
287 double last_time_in_history = rh.front().first;
288 unsigned int history_size=rh.size();
289 unsigned int i_history;
291 if ( time.
gt(last_time_in_history) ) {
302 i_history=min(i_history, history_size - 1);
303 ASSERT(i_history >= 0,
"Empty field history.");
305 auto new_ptr = rh.at(i_history).second;
306 if (new_ptr != region_fields_[reg.idx()]) {
307 region_fields_[reg.idx()]=new_ptr;
308 set_time_result_ = TimeStatus::changed;
312 if ( new_ptr->set_time(time.
t()) ) set_time_result_ = TimeStatus::changed;
323 template<
int spacedim,
class Value>
326 other.
name().c_str(), this->name().c_str());
327 if (
typeid(other) ==
typeid(*this)) {
329 this->operator=(other_field);
335 template<
int spacedim,
class Value>
345 template<
int spacedim,
class Value>
347 auto f = region_fields_[elm.
region().
idx()];
348 if (f)
return f->field_result();
354 template<
int spacedim,
class Value>
356 ASSERT( mesh(),
"Null mesh pointer, set_mesh() has to be called before.\n");
360 if (shared_->input_list_.size() != 0) {
361 while( shared_->list_it_ != shared_->input_list_.end()
362 && time.
ge( input_time = shared_->list_it_->val<
double>(
"time") ) ) {
366 std::string domain_name;
368 if (shared_->list_it_->opt_val(
"r_set", domain_name)) {
369 domain = mesh()->region_db().get_region_set(domain_name);
371 }
else if (shared_->list_it_->opt_val(
"region", domain_name)) {
373 Region region = mesh()->region_db().find_label(domain_name);
375 domain.push_back(region);
377 xprintf(
Warn,
"Unknown region with label: '%s'\n", domain_name.c_str());
379 }
else if (shared_->list_it_->opt_val(
"rid",
id)) {
381 Region region = mesh()->region_db().find_id(
id);
383 domain.push_back(region);
385 xprintf(
Warn,
"Unknown region with id: '%d'\n",
id);
387 THROW(ExcMissingDomain()
388 << shared_->list_it_->ei_address() );
391 if (domain.size() == 0) {
396 FieldBasePtr field_instance = read_field_descriptor_hook(*(shared_->list_it_), *
this);
401 field_instance->set_mesh( mesh() , is_bc() );
402 for(
const Region ®: domain) {
403 data_->region_history_[reg.idx()].push_front(
413 template<
int spacedim,
class Value>
415 ASSERT(mesh(),
"Null mesh pointer.");
416 if (shared_->is_fully_initialized_)
return;
421 for(
const Region ® : mesh()->region_db().get_region_set(
"ALL") )
422 if (reg.is_boundary() == is_bc()) {
424 if ( rh.empty() || ! rh[0].second)
427 if (no_check_control_field_ && no_check_control_field_->is_constant(reg) ) {
430 FieldEnum value = no_check_control_field_->value(elm.centre(),elm);
432 if ( std::find(shared_->no_check_values_.begin(), shared_->no_check_values_.end(), value)
433 != shared_->no_check_values_.end() )
436 if (shared_->input_default_ !=
"") {
437 regions_to_init.push_back( reg );
439 xprintf(
UsrErr,
"Missing value of the input field '%s' ('%s') on region ID: %d label: %s.\n",
440 input_name().c_str(), name().c_str(), reg.id(), reg.label().c_str() );
446 if ( regions_to_init.size() ) {
447 xprintf(
Warn,
"Using default value '%s' for part of the input field '%s' ('%s').\n",
448 input_default().c_str(), input_name().c_str(), name().c_str());
451 string default_input=input_default();
452 auto input_type = get_input_type();
456 auto field_ptr = FieldBaseType::function_factory( a_rec , n_comp() );
457 field_ptr->set_mesh( mesh(), is_bc() );
458 for(
const Region ®: regions_to_init) {
459 data_->region_history_[reg.idx()]
463 shared_->is_fully_initialized_;
479 template<
int spacedim,
class Value>
486 template<
int spacedim,
class Value>
488 sub_fields_.resize( names.size() );
490 for(
unsigned int i_comp=0; i_comp < size(); i_comp++)
492 sub_fields_[i_comp].units( units() );
494 if (sub_names_[i_comp].length() == 0)
495 sub_fields_[i_comp].name( name() );
497 sub_fields_[i_comp].name( sub_names_[i_comp] +
"_" + name());
503 #pragma GCC diagnostic push
504 #pragma GCC diagnostic ignored "-Wreturn-type"
505 template<
int spacedim,
class Value>
508 #pragma GCC diagnostic pop
511 template<
int spacedim,
class Value>
515 field.set_limit_side(side);
519 template<
int spacedim,
class Value>
525 if (field.set_time(time))
533 template<
int spacedim,
class Value>
535 shared_->mesh_ = &mesh;
536 for(
unsigned int i_comp=0; i_comp < size(); i_comp++)
537 sub_fields_[i_comp].set_mesh(mesh);
541 template<
int spacedim,
class Value>
543 if (
typeid(other) ==
typeid(*
this)) {
545 this->operator=(other_field);
547 auto const &other_field =
dynamic_cast< SubFieldType const &
>(other);
548 sub_fields_.resize(1);
549 sub_fields_[0] = other_field;
555 template<
int spacedim,
class Value>
567 template<
int spacedim,
class Value>
569 bool const_all=
false;
570 for(
auto field : sub_fields_) const_all = const_all || field.is_constant(reg);
void check_initialized_region_fields_()
Common abstract parent of all Field<...> classes.
pair< double, FieldBasePtr > HistoryPoint
Pair: time, pointer to FieldBase instance.
void init(const vector< string > &names)
void output(OutputTime *stream) override
void set_limit_side(LimitSide side) override
void update_history(const TimeGovernor &time)
FieldBasePtr(* read_field_descriptor_hook)(Input::Record rec, const FieldCommon &field)
IT::AbstractRecord make_input_tree()
-------— end helper function template
void copy_from(const FieldCommon &other) override
Class template representing a field with values dependent on: point, element, and region...
void register_data(const DiscreteSpace type, MultiField< spacedim, Value > &multi_field)
Generic method for registering output data stored in MultiField.
bool ge(double other_time) const
Basic time management functionality for unsteady (and steady) solvers (class Equation).
std::shared_ptr< SharedData > data_
FieldResult field_result(ElementAccessor< spacedim > &elm) const
IT::AbstractRecord & get_input_type() override
std::shared_ptr< SharedData > shared_
const std::string & name() const
static constexpr Mask input_copy
A field that is input of its equation and cna not read from input, thus muzt be set by copy...
#define ASSERT_EQUAL(a, b)
#define ASSERT_LESS(a, b)
std::shared_ptr< ControlField > no_check_control_field_
IT::AbstractRecord & get_input_type() override
The class for outputing data during time.
IT::AbstractRecord get_input_type_resolution(const Input::Type::Selection *sel, const boost::true_type &)
-------— Helper function template for make_input_tree method
FieldResult
Result type have sense only for larger Value types like vectors and tensors.
std::shared_ptr< FieldBaseType > FieldBasePtr
bool is_constant(Region reg) override
auto disable_where(const Field< spacedim, typename FieldValue< spacedim >::Enum > &control_field, const vector< FieldEnum > &value_list) -> Field &
boost::circular_buffer< HistoryPoint > RegionHistory
Nearest history of one region.
bool is_constant(Region reg) override
void set_field(const RegionSet &domain, FieldBasePtr field, double time=0.0)
bool set_time(const TimeGovernor &time) override
bool set_time(const TimeGovernor &time) override
FieldCommon & name(const string &name)
void set_mesh(const Mesh &mesh) override
static FieldBasePtr read_field_descriptor(Input::Record rec, const FieldCommon &field)
void output(OutputTime *stream) override
Class for representation of a vector of fields of the same physical quantity.
bool is_valid() const
Returns false if the region has undefined/invalid value.
void copy_from(const FieldCommon &other) override
bool gt(double other_time) const
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
void set_mesh(const Mesh &mesh) override
Field & operator=(const Field &other)
unsigned int idx() const
Returns a global index of the region.