18 #ifndef FIELD_IMPL_HH_ 19 #define FIELD_IMPL_HH_ 21 #include <boost/foreach.hpp> 34 template<
int spacedim,
class Value>
40 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
41 this->
add_factory( std::make_shared<FactoryBase>() );
47 template<
int spacedim,
class Value>
54 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
57 this->
add_factory( std::make_shared<FactoryBase>() );
63 template<
int spacedim,
class Value>
69 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
71 this->
name_ = (name==
"") ? input_name : name;
79 template<
int spacedim,
class Value>
93 template<
int spacedim,
class Value>
97 OLD_ASSERT(other.
shared_->mesh_,
"Must call set_mesh before assign to other field.\n");
99 "Assignment between fields with different meshes.\n");
102 if (&other ==
this)
return *
this;
106 shared_->is_fully_initialized_ =
false;
128 template<
int spacedim,
class Value>
135 template<
int spacedim,
class Value>
137 OLD_ASSERT(
false,
"This method can't be used for Field");
145 template<
int spacedim,
class Value>
155 template<
int spacedim,
class Value>
160 THROW(ExcFieldMeshDifference() << EI_Field(
name()) );
168 data_->region_history_.resize(
mesh()->region_db().
size(), init_history );
185 template <
int spacedim,
class Value>
194 template<
int spacedim,
class Value>
202 OLD_ASSERT(
mesh(),
"Null mesh pointer, set_mesh() has to be called before set_field().\n");
203 if (domain.size() == 0)
return;
209 for(
const Region ®: domain) {
212 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",
213 hp.first, region_history[0].first );
214 region_history.push_front(hp);
221 template<
int spacedim,
class Value>
233 template<
int spacedim,
class Value>
236 OLD_ASSERT(
mesh() ,
"NULL mesh pointer of field '%s'. set_mesh must be called before.\n",
name().c_str());
266 for(
const Region ®:
mesh()->region_db().get_region_set(
"ALL") ) {
267 auto rh =
data_->region_history_[reg.idx()];
271 if (reg.is_boundary() ==
is_bc() && !rh.empty() ) {
272 double last_time_in_history = rh.front().first;
273 unsigned int history_size=rh.size();
274 unsigned int i_history;
275 OLD_ASSERT(time_step.
ge(last_time_in_history),
"Setting field time back in history not fully supported yet!");
278 if ( time_step.
gt(last_time_in_history) ) {
290 i_history=min(i_history, history_size - 1);
291 OLD_ASSERT(i_history >= 0,
"Empty field history.");
293 auto new_ptr = rh.at(i_history).second;
308 template<
int spacedim,
class Value>
311 .error(
"Can not copy to the non-input field.");
315 && this->
shared_->input_list_.size() != 0 )
return;
317 if (
typeid(other) ==
typeid(*this)) {
325 template<
int spacedim,
class Value>
334 template<
int spacedim,
class Value>
337 observe->compute_field_values(*
this);
342 template<
int spacedim,
class Value>
346 for(
Region ® : region_set) {
352 else if (fr != result_all)
366 template<
int spacedim,
class Value>
368 OLD_ASSERT(
mesh(),
"Null mesh pointer, set_mesh() has to be called before.\n");
372 if (
shared_->input_list_.size() != 0) {
374 && time.
ge( input_time =
shared_->input_list_[
shared_->list_idx_].val<
double>(
"time") ) ) {
381 if (actual_list_item.
opt_val(
"region", domain_name_array)) {
385 }
else if (actual_list_item.
opt_val(
"rid",
id)) {
389 }
catch (RegionDB::ExcUniqueRegionId &e) {
394 domain.push_back(region);
396 THROW(RegionDB::ExcUnknownRegion() << RegionDB::EI_ID(
id) );
398 THROW(ExcMissingDomain()
404 FieldBasePtr field_instance = (*rit)->create_field(actual_list_item, *
this);
409 field_instance->set_mesh(
mesh() ,
is_bc() );
410 for(
const Region ®: domain) {
411 data_->region_history_[reg.idx()].push_front(
424 template<
int spacedim,
class Value>
427 if (
shared_->is_fully_initialized_)
return;
432 for(
const Region ® :
mesh()->region_db().get_region_set(
"ALL") )
433 if (reg.is_boundary() ==
is_bc()) {
435 if ( rh.empty() || ! rh[0].second)
444 !=
shared_->no_check_values_.end() )
447 if (
shared_->input_default_ !=
"") {
448 regions_to_init.push_back( reg );
450 xprintf(
UsrErr,
"Missing value of the input field '%s' ('%s') on region ID: %d label: %s.\n",
451 input_name().c_str(),
name().c_str(), reg.id(), reg.label().c_str() );
457 if ( regions_to_init.size() ) {
458 std::string region_list;
467 for(
const Region ®: regions_to_init) {
468 data_->region_history_[reg.idx()]
470 region_list+=
" "+reg.label();
472 WarningOut().fmt(
"Using default value '{}' for part of the input field '{}' ('{}').\n" 477 shared_->is_fully_initialized_ =
true;
481 template<
int spacedim,
class Value>
487 template<
int spacedim,
class Value>
497 template<
int spacedim,
class Value>
505 template<
int spacedim,
class Value>
510 double time,last_time=0.0;
516 if ( (*rit)->is_active_field_descriptor( (*
it), this->input_name() ) ) {
518 time =
it->val<
double>(
"time");
519 if (time < last_time) {
520 THROW( ExcNonascendingTime()
523 <<
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.
static const Input::Type::Instance & get_input_type_instance(Input::Type::Selection value_selection=Input::Type::Selection())
RegionSet union_set(std::vector< string > set_names) const
FieldResult field_result(RegionSet region_set) const override
Indicates special field states.
Class template representing a field with values dependent on: point, element, and region...
unsigned int component_index_
void update_history(const TimeStep &time)
void set_input_list(const Input::Array &list) override
void observe_output(std::shared_ptr< Observe > observe) 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
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
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_
constexpr bool match(Mask mask) const
std::shared_ptr< SharedData > shared_
OutputTime::DiscreteSpace output_type() const
const std::string & name() const
bool ge(double other_time) const
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
#define WarningOut()
Macro defining 'warning' record of log.
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
static constexpr Mask equation_input
The field is data parameter of the owning equation. (default on)
#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.