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()];
272 if (reg.is_boundary() !=
is_bc())
continue;
275 if ( rh.empty())
continue;
277 double last_time_in_history = rh.front().first;
278 unsigned int history_size=rh.size();
279 unsigned int i_history;
280 OLD_ASSERT(time_step.
ge(last_time_in_history),
"Setting field time back in history not fully supported yet!");
283 if ( time_step.
gt(last_time_in_history) ) {
295 i_history=min(i_history, history_size - 1);
296 OLD_ASSERT(i_history >= 0,
"Empty field history.");
299 auto new_ptr = rh.at(i_history).second;
313 template<
int spacedim,
class Value>
316 .error(
"Can not copy to the non-input field.");
320 && this->
shared_->input_list_.size() != 0 )
return;
322 if (
typeid(other) ==
typeid(*this)) {
330 template<
int spacedim,
class Value>
339 template<
int spacedim,
class Value>
342 observe->compute_field_values(*
this);
347 template<
int spacedim,
class Value>
351 for(
Region ® : region_set) {
357 else if (fr != result_all)
370 template<
int spacedim,
class Value>
373 int nrows = Value::NRows_;
374 int ncols = Value::NCols_;
375 string type =
"Integer";
379 return fmt::format(
"{{ \"shape\": [ {}, {} ], \"type\": \"{}\", \"limit\": [ {}, {} ] }}",
380 nrows, ncols, type, this->
limits().first, this->
limits().second);
384 template<
int spacedim,
class Value>
386 OLD_ASSERT(
mesh(),
"Null mesh pointer, set_mesh() has to be called before.\n");
390 if (
shared_->input_list_.size() != 0) {
392 && time.
ge( input_time =
shared_->input_list_[
shared_->list_idx_].val<
double>(
"time") ) ) {
399 if (actual_list_item.
opt_val(
"region", domain_name_array)) {
403 }
else if (actual_list_item.
opt_val(
"rid",
id)) {
407 }
catch (RegionDB::ExcUniqueRegionId &e) {
412 domain.push_back(region);
414 THROW(RegionDB::ExcUnknownRegion() << RegionDB::EI_ID(
id) );
416 THROW(ExcMissingDomain()
422 FieldBasePtr field_instance = (*rit)->create_field(actual_list_item, *
this);
427 field_instance->set_mesh(
mesh() ,
is_bc() );
428 for(
const Region ®: domain) {
429 data_->region_history_[reg.idx()].push_front(
443 template<
int spacedim,
class Value>
451 for(
const Region ® :
mesh()->region_db().get_region_set(
"ALL") )
452 if (reg.is_boundary() ==
is_bc()) {
454 if ( rh.empty() || ! rh[0].second)
463 !=
shared_->no_check_values_.end() )
466 if (
shared_->input_default_ !=
"") {
467 regions_to_init.push_back( reg );
469 xprintf(
UsrErr,
"Missing value of the input field '%s' ('%s') on region ID: %d label: %s.\n",
470 input_name().c_str(),
name().c_str(), reg.id(), reg.label().c_str() );
476 if ( regions_to_init.size() ) {
477 std::string region_list;
487 for(
const Region ®: regions_to_init) {
488 data_->region_history_[reg.idx()]
490 region_list+=
" "+reg.label();
492 WarningOut().fmt(
"Default value '{}' for field '{}' ('{}').\n" 501 template<
int spacedim,
class Value>
507 template<
int spacedim,
class Value>
519 template<
int spacedim,
class Value>
527 template<
int spacedim,
class Value>
532 double time,last_time=0.0;
538 if ( (*rit)->is_active_field_descriptor( (*
it), this->input_name() ) ) {
540 time =
it->val<
double>(
"time");
541 if (time < last_time) {
542 THROW( ExcNonascendingTime()
545 <<
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.