18 #ifndef FIELD_IMPL_HH_ 19 #define FIELD_IMPL_HH_ 21 #include <boost/foreach.hpp> 42 template<
int spacedim,
class Value>
49 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
50 this->
add_factory( std::make_shared<FactoryBase>() );
56 template<
int spacedim,
class Value>
63 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
66 this->
add_factory( std::make_shared<FactoryBase>() );
72 template<
int spacedim,
class Value>
79 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
81 this->
name_ = (name==
"") ? input_name : name;
89 template<
int spacedim,
class Value>
104 template<
int spacedim,
class Value>
108 ASSERT(other.
shared_->mesh_).error(
"Must call set_mesh before assign to other field.\n");
112 if (&other ==
this)
return *
this;
116 shared_->is_fully_initialized_ =
false;
139 template<
int spacedim,
class Value>
146 template<
int spacedim,
class Value>
153 template<
int spacedim,
class Value>
154 typename arma::Mat<typename Value::element_type>::template fixed<Value::NRows_, Value::NCols_>
157 return this->
value_cache().
data().template mat<Value::NRows_, Value::NCols_>(i_cache_point);
162 template<
int spacedim,
class Value>
169 template<
int spacedim,
class Value>
171 ASSERT(
false).error(
"This method can't be used for Field");
179 template<
int spacedim,
class Value>
189 template<
int spacedim,
class Value>
194 THROW(ExcFieldMeshDifference() << EI_Field(
name()) );
202 data_->region_history_.resize(
mesh()->region_db().size(), init_history );
219 template <
int spacedim,
class Value>
224 return ( region_field && region_field->is_constant_in_space() );
228 template<
int spacedim,
class Value>
234 ASSERT_PTR(field).error(
"Null field pointer.\n");
236 ASSERT_PTR(
mesh() ).error(
"Null mesh pointer, set_mesh() has to be called before set_field().\n");
237 if (domain.size() == 0)
return;
243 for(
const Region ®: domain) {
246 ASSERT( region_history.size() == 0 || region_history[0].first < hp.first)(hp.first)(region_history[0].first)
247 .error(
"Can not insert smaller time then last time in field's history.\n");
248 region_history.push_front(hp);
255 template<
int spacedim,
class Value>
268 template<
int spacedim,
class Value>
271 ASSERT_PTR(
mesh() )(
name() ).error(
"NULL mesh pointer of field with given name. set_mesh must be called before.\n");
301 for(
const Region ®:
mesh()->region_db().get_region_set(
"ALL") ) {
302 auto rh =
data_->region_history_[reg.idx()];
305 if (reg.is_boundary() !=
is_bc())
continue;
308 if ( rh.empty())
continue;
310 double last_time_in_history = rh.front().first;
311 unsigned int history_size=rh.size();
312 unsigned int i_history;
313 ASSERT( time_step.
ge(last_time_in_history) ).error(
"Setting field time back in history not fully supported yet!");
316 if ( time_step.
gt(last_time_in_history) ) {
328 i_history=min(i_history, history_size - 1);
329 ASSERT(i_history >= 0).error(
"Empty field history.");
332 auto new_ptr = rh.at(i_history).second;
346 template<
int spacedim,
class Value>
349 .error(
"Can not copy to the non-input field.");
353 && this->
shared_->input_list_.size() != 0 )
return;
355 if (
typeid(other) ==
typeid(*this)) {
363 template<
int spacedim,
class Value>
376 template<
int spacedim,
class Value>
379 typedef typename Value::element_type ElemType;
381 if (observe->point_ds()->size() == 0)
return;
384 (
unsigned int)Value::NRows_, (
unsigned int)Value::NCols_);
386 unsigned int loc_point_time_index, ele_index;
388 loc_point_time_index = op_acc.loc_point_time_index();
389 ele_index = op_acc.observe_point().element_idx();
390 const Value &obs_value =
391 Value( const_cast<typename Value::return_type &>(
392 this->
value(op_acc.observe_point().global_coords(),
394 ASSERT_EQ(output_data.
n_comp(), obs_value.n_rows()*obs_value.n_cols()).error();
395 output_data.
store_value(loc_point_time_index, obs_value.mem_ptr());
401 template<
int spacedim,
class Value>
405 for(
Region ® : region_set) {
411 else if (fr != result_all)
424 template<
int spacedim,
class Value>
427 int nrows = Value::NRows_;
428 int ncols = Value::NCols_;
429 string type =
"Integer";
433 return fmt::format(
"{{ \"shape\": [ {}, {} ], \"type\": \"{}\", \"limit\": [ {}, {} ] }}",
434 nrows, ncols, type, this->
limits().first, this->
limits().second);
438 template<
int spacedim,
class Value>
440 ASSERT_PTR(
mesh() ).error(
"Null mesh pointer, set_mesh() has to be called before.\n");
444 if (
shared_->input_list_.size() != 0) {
453 if (actual_list_item.
opt_val(
"region", domain_name_array)) {
457 }
else if (actual_list_item.
opt_val(
"rid",
id)) {
461 }
catch (RegionDB::ExcUniqueRegionId &e) {
466 domain.push_back(region);
468 THROW(RegionDB::ExcUnknownRegion() << RegionDB::EI_ID(
id) );
470 THROW(ExcMissingDomain()
476 FieldBasePtr field_instance = (*rit)->create_field(actual_list_item, *
this);
481 field_instance->set_mesh(
mesh() ,
is_bc() );
482 for(
const Region ®: domain) {
487 if(
data_->region_history_[reg.idx()].size() == 0
488 ||
data_->region_history_[reg.idx()].back().first < input_time)
490 data_->region_history_[reg.idx()].push_front(
496 data_->region_history_[reg.idx()].back() =
509 template<
int spacedim,
class Value>
517 for(
const Region ® :
mesh()->region_db().get_region_set(
"ALL") )
518 if (reg.is_boundary() ==
is_bc()) {
520 if ( rh.empty() || ! rh[0].second)
529 !=
shared_->no_check_values_.end() )
532 if (
shared_->input_default_ !=
"") {
533 regions_to_init.push_back( reg );
535 xprintf(
UsrErr,
"Missing value of the input field '%s' ('%s') on region ID: %d label: %s.\n",
536 input_name().c_str(),
name().c_str(), reg.id(), reg.label().c_str() );
542 if ( regions_to_init.size() ) {
543 std::string region_list;
553 for(
const Region ®: regions_to_init) {
554 data_->region_history_[reg.idx()]
556 region_list+=
" "+reg.label();
565 template<
int spacedim,
class Value>
571 template<
int spacedim,
class Value>
583 template<
int spacedim,
class Value>
591 template<
int spacedim,
class Value>
596 double time,last_time=0.0;
602 if ( (*rit)->is_active_field_descriptor( (*
it), this->input_name() ) ) {
605 if (time < last_time) {
606 THROW( ExcNonascendingTime()
609 <<
it->ei_address());
622 template<
int spacedim,
class Value>
624 typedef typename Value::element_type ElemType;
626 std::shared_ptr<OutputMeshBase> output_mesh = stream->get_output_mesh_ptr();
631 (
unsigned int)Value::NRows_, (
unsigned int)Value::NCols_);
637 unsigned int node_index = 0;
638 for(
const auto & ele : *output_mesh )
641 for(
unsigned int i=0; i < ele.n_nodes(); i++)
643 const Value &node_value =
644 Value( const_cast<typename Value::return_type &>(
645 this->
value(vertices[i],
648 ASSERT_EQ(output_data.
n_comp(), node_value.n_rows()*node_value.n_cols()).error();
649 output_data.
store_value(node_index, node_value.mem_ptr() );
656 for(
const auto & ele : *output_mesh )
658 unsigned int ele_index = ele.idx();
659 const Value &ele_value =
660 Value( const_cast<typename Value::return_type &>(
661 this->
value(ele.centre(),
665 ASSERT_EQ(output_data.
n_comp(), ele_value.n_rows()*ele_value.n_cols()).error();
666 output_data.
store_value(ele_index, ele_value.mem_ptr() );
671 std::shared_ptr< FieldFE<spacedim, Value> > field_fe_ptr = this->
get_field_fe();
675 (
unsigned int)Value::NRows_, (
unsigned int)Value::NCols_);
676 field_fe_ptr->native_data_to_cache(native_output_data);
678 WarningOut().fmt(
"Field '{}' of native data space type is not of type FieldFE. Output will be skipped.\n", this->
name());
689 stream->update_time(this->
time());
694 template<
int spacedim,
class Value>
697 ASSERT(!this->
shared_->bc_).error(
"FieldFE output of native data is supported only for bulk fields!");
699 std::shared_ptr< FieldFE<spacedim, Value> > field_fe_ptr;
716 template<
int spacedim,
class Value>
722 template<
int spacedim,
class Value>
727 std::unordered_map<unsigned int, unsigned int>::iterator reg_elm_it;
728 for (reg_elm_it=update_cache_data.region_cache_indices_range_.begin(); reg_elm_it!=update_cache_data.region_cache_indices_range_.end(); ++reg_elm_it) {
void check_initialized_region_fields_()
Classes for auxiliary output mesh.
void cache_update(ElementCacheMap &cache_map) override
Implements FieldCommon::cache_update.
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.
const ElementCacheMap * elm_cache_map() const
#define ASSERT_EQ_DBG(a, b)
Definition of comparative assert macro (EQual) only for debug mode.
Point accessor allow iterate over bulk quadrature points defined in local element coordinates...
Point accessor allow iterate over quadrature points of given side defined in local element coordinate...
FieldFlag::Flags get_flags() const
static const Input::Type::Instance & get_input_type_instance(Input::Type::Selection value_selection=Input::Type::Selection())
unsigned int bulk_size() const
const UpdateCacheHelper & update_cache_data() const
Return update cache data helper.
std::string get_value_attribute() const override
OutputTime::DiscreteSpace get_output_type() const
DHCellAccessor dh_cell() const
Return DH cell accessor.
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
Store data of one initialization message.
void store_value(unsigned int idx, const T *value)
Directing class of FieldValueCache.
void update_history(const TimeStep &time)
Helper struct stores data for initizalize descentants of FieldAlgorithmBase.
void observe_output(std::shared_ptr< Observe > observe) override
unsigned int eval_point_idx() const
Return index in EvalPoints object.
RegionSet union_set(std::vector< std::string > set_names) const
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...
Class holds precomputed field values of selected element set.
void field_output(std::shared_ptr< OutputTime > stream) override
Basic time management functionality for unsteady (and steady) solvers (class Equation).
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.
std::shared_ptr< SharedData > data_
static constexpr bool value
arma::Mat< typename Value::element_type >::template fixed< Value::NRows_, Value::NCols_ > operator[](unsigned int i_cache_point) const
Return item of value_cache_ given by i_cache_point.
constexpr bool match(Mask mask) const
std::shared_ptr< SharedData > shared_
DHCellSide dh_cell_side() const
Return DH cell accessor.
unsigned int eval_point_idx() const
Return index in EvalPoints object.
std::shared_ptr< FieldFE< spacedim, Value > > get_field_fe()
const Armor::Array< elm_type > & data() const
Return data vector.
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< std::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_
static const unsigned int N_DISCRETE_SPACES
virtual Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm) const
LimitSide last_limit_side_
virtual void value_list(const Armor::array &point_list, const ElementAccessor< spacedim > &elm, std::vector< typename Value::return_type > &value_list) const
double read_time(Input::Iterator< Input::Tuple > time_it, double default_time=std::numeric_limits< double >::quiet_NaN()) const
std::vector< FieldBasePtr > region_fields_
double read_time(Input::Iterator< Input::Tuple > time_it, double default_time=std::numeric_limits< double >::quiet_NaN()) const
FieldResult field_result(RegionSet region_set) const override
Indicates special field states.
const ElementCacheMap * elm_cache_map() const
const DHCellAccessor & cell() const
Return DHCellAccessor appropriate to the side.
static std::shared_ptr< FieldAlgorithmBase< spacedim, Value > > function_factory(const Input::AbstractRecord &rec, const struct FieldAlgoBaseInitData &init_data)
std::shared_ptr< FieldBaseType > FieldBasePtr
static constexpr unsigned int n_cached_elements
Number of cached elements which values are stored in cache.
std::vector< std::shared_ptr< FactoryBase > > factories_
#define ASSERT_PTR(ptr)
Definition of assert macro checking non-null pointer (PTR)
auto disable_where(const Field< spacedim, typename FieldValue< spacedim >::Enum > &control_field, const vector< FieldEnum > &value_list) -> Field &
static std::vector< MessageData > messages_data_
Vector of data of initialization messages.
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)
#define ASSERT_LT(a, b)
Definition of comparative assert macro (Less Than)
Class OutputElement and its iterator OutputElementIterator on the output mesh.
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
void set_mesh(const Mesh &mesh) override
void set_history_changed()
Point accessor allow iterate over local Observe points.
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
unsigned int n_comp() const
static constexpr Mask equation_input
The field is data parameter of the owning equation. (default on)
void cache_allocate(std::shared_ptr< EvalPoints > eval_points) override
Implements FieldCommon::cache_allocate.
const FieldValueCache< typename Value::element_type > & value_cache() const
returns reference to FieldValueCache.
void compute_field_data(OutputTime::DiscreteSpace space_type, std::shared_ptr< OutputTime > stream)
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
void init(std::shared_ptr< EvalPoints > eval_points, unsigned int n_cache_elements)
Initialize cache.
Representation of one time step..
TimeStatus set_time_result_
Field & operator=(const Field &other)
static const unsigned int history_length_limit_
void set_input_list(const Input::Array &list, const TimeGovernor &tg) override
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual)
static constexpr Mask declare_input
The field can be set from input. The key in input field descriptor is declared. (default on) ...
Value::return_type operator()(BulkPoint &p)
FieldValueCache< typename Value::element_type > value_cache_
unsigned int idx() const
Returns a global index of the region.