18 #ifndef FIELD_IMPL_HH_ 19 #define FIELD_IMPL_HH_ 21 #include <boost/foreach.hpp> 33 template<
int spacedim,
class Value>
39 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
40 this->
add_factory( std::make_shared<FactoryBase>() );
46 template<
int spacedim,
class Value>
53 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
56 this->
add_factory( std::make_shared<FactoryBase>() );
62 template<
int spacedim,
class Value>
68 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
70 this->
name_ = (name==
"") ? input_name : name;
78 template<
int spacedim,
class Value>
92 template<
int spacedim,
class Value>
96 OLD_ASSERT(other.
shared_->mesh_,
"Must call set_mesh before assign to other field.\n");
98 "Assignment between fields with different meshes.\n");
101 if (&other ==
this)
return *
this;
105 shared_->is_fully_initialized_ =
false;
127 template<
int spacedim,
class Value>
134 template<
int spacedim,
class Value>
136 OLD_ASSERT(
false,
"This method can't be used for Field");
144 template<
int spacedim,
class Value>
154 template<
int spacedim,
class Value>
159 THROW(ExcFieldMeshDifference() << EI_Field(
name()) );
167 data_->region_history_.resize(
mesh()->region_db().
size(), init_history );
184 template <
int spacedim,
class Value>
193 template<
int spacedim,
class Value>
201 OLD_ASSERT(
mesh(),
"Null mesh pointer, set_mesh() has to be called before set_field().\n");
202 if (domain.size() == 0)
return;
208 for(
const Region ®: domain) {
211 OLD_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",
212 hp.first, region_history[0].first );
213 region_history.push_front(hp);
220 template<
int spacedim,
class Value>
232 template<
int spacedim,
class Value>
235 OLD_ASSERT(
mesh() ,
"NULL mesh pointer of field '%s'. set_mesh must be called before.\n",
name().c_str());
265 for(
const Region ®:
mesh()->region_db().get_region_set(
"ALL") ) {
266 auto rh =
data_->region_history_[reg.idx()];
270 if (reg.is_boundary() ==
is_bc() && !rh.empty() ) {
271 double last_time_in_history = rh.front().first;
272 unsigned int history_size=rh.size();
273 unsigned int i_history;
274 OLD_ASSERT(time_step.
ge(last_time_in_history),
"Setting field time back in history not fully supported yet!");
277 if ( time_step.
gt(last_time_in_history) ) {
289 i_history=min(i_history, history_size - 1);
290 OLD_ASSERT(i_history >= 0,
"Empty field history.");
292 auto new_ptr = rh.at(i_history).second;
307 template<
int spacedim,
class Value>
310 other.
name().c_str(), this->
name().c_str());
311 if (
typeid(other) ==
typeid(*this)) {
319 template<
int spacedim,
class Value>
329 template<
int spacedim,
class Value>
333 for(
Region ® : region_set) {
339 else if (fr != result_all)
353 template<
int spacedim,
class Value>
355 OLD_ASSERT(
mesh(),
"Null mesh pointer, set_mesh() has to be called before.\n");
359 if (
shared_->input_list_.size() != 0) {
361 && time.
ge( input_time =
shared_->input_list_[
shared_->list_idx_].val<
double>(
"time") ) ) {
368 if (actual_list_item.
opt_val(
"region", domain_name_array)) {
372 }
else if (actual_list_item.
opt_val(
"rid",
id)) {
376 }
catch (RegionDB::ExcUniqueRegionId &e) {
381 domain.push_back(region);
383 THROW(RegionDB::ExcUnknownRegion() << RegionDB::EI_ID(
id) );
385 THROW(ExcMissingDomain()
391 FieldBasePtr field_instance = (*rit)->create_field(actual_list_item, *
this);
396 field_instance->set_mesh(
mesh() ,
is_bc() );
397 for(
const Region ®: domain) {
398 data_->region_history_[reg.idx()].push_front(
411 template<
int spacedim,
class Value>
414 if (
shared_->is_fully_initialized_)
return;
419 for(
const Region ® :
mesh()->region_db().get_region_set(
"ALL") )
420 if (reg.is_boundary() ==
is_bc()) {
422 if ( rh.empty() || ! rh[0].second)
431 !=
shared_->no_check_values_.end() )
434 if (
shared_->input_default_ !=
"") {
435 regions_to_init.push_back( reg );
437 xprintf(
UsrErr,
"Missing value of the input field '%s' ('%s') on region ID: %d label: %s.\n",
438 input_name().c_str(),
name().c_str(), reg.id(), reg.label().c_str() );
444 if ( regions_to_init.size() ) {
445 std::string region_list;
454 for(
const Region ®: regions_to_init) {
455 data_->region_history_[reg.idx()]
457 region_list+=
" "+reg.label();
459 xprintf(
Warn,
"Using default value '%s' for part of the input field '%s' ('%s').\n" 464 shared_->is_fully_initialized_ =
true;
468 template<
int spacedim,
class Value>
474 template<
int spacedim,
class Value>
484 template<
int spacedim,
class Value>
492 template<
int spacedim,
class Value>
497 double time,last_time=0.0;
503 if ( (*rit)->is_active_field_descriptor( (*
it), this->input_name() ) ) {
505 time =
it->val<
double>(
"time");
506 if (time < last_time) {
507 THROW( ExcNonascendingTime()
510 <<
it->ei_address());
void check_initialized_region_fields_()
Common abstract parent of all Field<...> classes.
virtual bool is_active_field_descriptor(const Input::Record &in_rec, const std::string &input_name)
pair< double, FieldBasePtr > HistoryPoint
Pair: time, pointer to FieldBase instance.
unsigned int size() const
Number of subfields that compose the multi-field.
RegionSet union_set(std::vector< string > set_names) const
Class template representing a field with values dependent on: point, element, and region...
FieldResult field_result(RegionSet region_set) const
Indicates special field states.
unsigned int component_index_
void update_history(const TimeStep &time)
void set_input_list(const Input::Array &list) override
void output(std::shared_ptr< OutputTime > stream) override
const std::string & input_default() const
bool set_time(const TimeStep &time, LimitSide limit_side) override
const RegionDB & region_db() const
virtual FieldBasePtr create_field(Input::Record rec, const FieldCommon &field)
IT::Instance get_input_type() override
virtual void value_list(const std::vector< Point > &point_list, const ElementAccessor< spacedim > &elm, std::vector< typename Value::return_type > &value_list) const
std::shared_ptr< SharedData > data_
static const Input::Type::Instance & get_input_type_instance(const Input::Type::Selection *value_selection=NULL)
std::shared_ptr< SharedData > shared_
OutputTime::DiscreteSpace output_type() const
const std::string & name() const
bool ge(double other_time) const
static constexpr Mask input_copy
A field that is input of its equation and can not read from input, thus must be set by copy...
FieldFlag::Flags & flags()
Region find_id(unsigned int id, unsigned int dim) const
std::vector< string > get_and_check_operands(const Input::Array &operands) const
IT::Array get_multifield_input_type() override
std::shared_ptr< ControlField > no_check_control_field_
#define OLD_ASSERT_LESS(a, b)
virtual Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm) const
static std::shared_ptr< FieldAlgorithmBase< spacedim, Value > > function_factory(const Input::AbstractRecord &rec, unsigned int n_comp=0)
LimitSide last_limit_side_
std::vector< FieldBasePtr > region_fields_
std::shared_ptr< FieldBaseType > FieldBasePtr
std::vector< std::shared_ptr< FactoryBase > > factories_
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.
void set_component_index(unsigned int idx)
bool is_constant(Region reg) override
void add_factory(std::shared_ptr< FactoryBase > factory)
void set_field(const RegionSet &domain, FieldBasePtr field, double time=0.0)
bool gt(double other_time) const
const Mesh * mesh() const
FieldCommon & name(const string &name)
unsigned int n_comp() const
#define OLD_ASSERT_EQUAL(a, b)
void set_mesh(const Mesh &mesh) override
void set_history_changed()
bool is_valid() const
Returns false if the region has undefined/invalid value.
const std::string & input_name() const
void copy_from(const FieldCommon &other) override
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
Representation of one time step..
TimeStatus set_time_result_
Field & operator=(const Field &other)
static const unsigned int history_length_limit_
static constexpr Mask declare_input
The field can be set from input. The key in input field descriptor is declared. (default on) ...
unsigned int idx() const
Returns a global index of the region.