18 #ifndef FIELD_IMPL_HH_ 19 #define FIELD_IMPL_HH_ 21 #include <boost/foreach.hpp> 35 template<
int spacedim,
class Value>
41 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
42 this->
add_factory( std::make_shared<FactoryBase>() );
48 template<
int spacedim,
class Value>
55 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
58 this->
add_factory( std::make_shared<FactoryBase>() );
64 template<
int spacedim,
class Value>
70 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
72 this->
name_ = (name==
"") ? input_name : name;
80 template<
int spacedim,
class Value>
94 template<
int spacedim,
class Value>
98 OLD_ASSERT(other.
shared_->mesh_,
"Must call set_mesh before assign to other field.\n");
100 "Assignment between fields with different meshes.\n");
103 if (&other ==
this)
return *
this;
107 shared_->is_fully_initialized_ =
false;
129 template<
int spacedim,
class Value>
136 template<
int spacedim,
class Value>
138 OLD_ASSERT(
false,
"This method can't be used for Field");
146 template<
int spacedim,
class Value>
156 template<
int spacedim,
class Value>
161 THROW(ExcFieldMeshDifference() << EI_Field(
name()) );
169 data_->region_history_.resize(
mesh()->region_db().
size(), init_history );
186 template <
int spacedim,
class Value>
195 template<
int spacedim,
class Value>
203 OLD_ASSERT(
mesh(),
"Null mesh pointer, set_mesh() has to be called before set_field().\n");
204 if (domain.size() == 0)
return;
210 for(
const Region ®: domain) {
213 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",
214 hp.first, region_history[0].first );
215 region_history.push_front(hp);
222 template<
int spacedim,
class Value>
235 template<
int spacedim,
class Value>
238 OLD_ASSERT(
mesh() ,
"NULL mesh pointer of field '%s'. set_mesh must be called before.\n",
name().c_str());
268 for(
const Region ®:
mesh()->region_db().get_region_set(
"ALL") ) {
269 auto rh =
data_->region_history_[reg.idx()];
273 if (reg.is_boundary() ==
is_bc() && !rh.empty() ) {
274 double last_time_in_history = rh.front().first;
275 unsigned int history_size=rh.size();
276 unsigned int i_history;
277 OLD_ASSERT(time_step.
ge(last_time_in_history),
"Setting field time back in history not fully supported yet!");
280 if ( time_step.
gt(last_time_in_history) ) {
292 i_history=min(i_history, history_size - 1);
293 OLD_ASSERT(i_history >= 0,
"Empty field history.");
295 auto new_ptr = rh.at(i_history).second;
310 template<
int spacedim,
class Value>
313 .error(
"Can not copy to the non-input field.");
317 && this->
shared_->input_list_.size() != 0 )
return;
319 if (
typeid(other) ==
typeid(*this)) {
327 template<
int spacedim,
class Value>
336 template<
int spacedim,
class Value>
339 observe->compute_field_values(*
this);
344 template<
int spacedim,
class Value>
348 for(
Region ® : region_set) {
354 else if (fr != result_all)
367 template<
int spacedim,
class Value>
370 int nrows = Value::NRows_;
371 int ncols = Value::NCols_;
372 string type =
"Integer";
376 return fmt::format(
"{{ \"shape\": [ {}, {} ], \"type\": \"{}\", \"limit\": [ {}, {} ] }}",
377 nrows, ncols, type, this->
limits().first, this->
limits().second);
381 template<
int spacedim,
class Value>
383 OLD_ASSERT(
mesh(),
"Null mesh pointer, set_mesh() has to be called before.\n");
387 if (
shared_->input_list_.size() != 0) {
389 && time.
ge( input_time =
shared_->input_list_[
shared_->list_idx_].val<
double>(
"time") ) ) {
396 if (actual_list_item.
opt_val(
"region", domain_name_array)) {
400 }
else if (actual_list_item.
opt_val(
"rid",
id)) {
404 }
catch (RegionDB::ExcUniqueRegionId &e) {
409 domain.push_back(region);
411 THROW(RegionDB::ExcUnknownRegion() << RegionDB::EI_ID(
id) );
413 THROW(ExcMissingDomain()
419 FieldBasePtr field_instance = (*rit)->create_field(actual_list_item, *
this);
424 field_instance->set_mesh(
mesh() ,
is_bc() );
425 for(
const Region ®: domain) {
426 data_->region_history_[reg.idx()].push_front(
439 template<
int spacedim,
class Value>
442 if (
shared_->is_fully_initialized_)
return;
447 for(
const Region ® :
mesh()->region_db().get_region_set(
"ALL") )
448 if (reg.is_boundary() ==
is_bc()) {
450 if ( rh.empty() || ! rh[0].second)
459 !=
shared_->no_check_values_.end() )
462 if (
shared_->input_default_ !=
"") {
463 regions_to_init.push_back( reg );
465 xprintf(
UsrErr,
"Missing value of the input field '%s' ('%s') on region ID: %d label: %s.\n",
466 input_name().c_str(),
name().c_str(), reg.id(), reg.label().c_str() );
472 if ( regions_to_init.size() ) {
473 std::string region_list;
483 for(
const Region ®: regions_to_init) {
484 data_->region_history_[reg.idx()]
486 region_list+=
" "+reg.label();
488 WarningOut().fmt(
"Default value '{}' for field '{}' ('{}').\n" 493 shared_->is_fully_initialized_ =
true;
497 template<
int spacedim,
class Value>
503 template<
int spacedim,
class Value>
515 template<
int spacedim,
class Value>
523 template<
int spacedim,
class Value>
528 double time,last_time=0.0;
534 if ( (*rit)->is_active_field_descriptor( (*
it), this->input_name() ) ) {
536 time =
it->val<
double>(
"time");
537 if (time < last_time) {
538 THROW( ExcNonascendingTime()
541 <<
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
std::string get_value_attribute() const override
Class template representing a field with values dependent on: point, element, and region...
std::string format(CStringRef format_str, ArgList args)
unsigned int component_index_
std::pair< double, double > limits() const
void update_history(const TimeStep &time)
void set_input_list(const Input::Array &list) override
Helper struct stores data for initizalize descentants of FieldAlgorithmBase.
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
FieldCommon & units(const UnitSI &units)
Set basic units of the field.
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 constexpr bool value
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
const UnitSI & units() 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
LimitSide last_limit_side_
std::vector< FieldBasePtr > region_fields_
FieldResult field_result(RegionSet region_set) const override
Indicates special field states.
static std::shared_ptr< FieldAlgorithmBase< spacedim, Value > > function_factory(const Input::AbstractRecord &rec, const struct FieldAlgoBaseInitData &init_data)
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.