18 #ifndef FIELD_IMPL_HH_ 19 #define FIELD_IMPL_HH_ 40 template<
int spacedim,
class Value>
47 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
48 this->
add_factory( std::make_shared<FactoryBase>() );
54 template<
int spacedim,
class Value>
61 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
64 this->
add_factory( std::make_shared<FactoryBase>() );
70 template<
int spacedim,
class Value>
77 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
79 this->
name_ = (name==
"") ? input_name : name;
87 template<
int spacedim,
class Value>
102 template<
int spacedim,
class Value>
106 ASSERT(other.
shared_->mesh_).error(
"Must call set_mesh before assign to other field.\n");
110 if (&other ==
this)
return *
this;
114 shared_->is_fully_initialized_ =
false;
137 template<
int spacedim,
class Value>
144 template<
int spacedim,
class Value>
151 template<
int spacedim,
class Value>
152 typename arma::Mat<typename Value::element_type>::template fixed<Value::NRows_, Value::NCols_>
155 return this->
value_cache().
data().template mat<Value::NRows_, Value::NCols_>(i_cache_point);
160 template<
int spacedim,
class Value>
167 template<
int spacedim,
class Value>
169 ASSERT(
false).error(
"This method can't be used for Field");
177 template<
int spacedim,
class Value>
187 template<
int spacedim,
class Value>
192 THROW(ExcFieldMeshDifference() << EI_Field(
name()) );
200 data_->region_history_.resize(
mesh()->region_db().size(), init_history );
217 template <
int spacedim,
class Value>
222 return ( region_field && region_field->is_constant_in_space() );
226 template<
int spacedim,
class Value>
232 ASSERT_PTR(field).error(
"Null field pointer.\n");
234 ASSERT_PTR(
mesh() ).error(
"Null mesh pointer, set_mesh() has to be called before set_field().\n");
235 if (domain.size() == 0)
return;
241 for(
const Region ®: domain) {
244 ASSERT( region_history.size() == 0 || region_history[0].first < hp.first)(hp.first)(region_history[0].first)
245 .error(
"Can not insert smaller time then last time in field's history.\n");
246 region_history.push_front(hp);
253 template<
int spacedim,
class Value>
266 template<
int spacedim,
class Value>
269 ASSERT_PTR(
mesh() )(
name() ).error(
"NULL mesh pointer of field with given name. set_mesh must be called before.\n");
299 for(
const Region ®:
mesh()->region_db().get_region_set(
"ALL") ) {
300 auto rh =
data_->region_history_[reg.idx()];
303 if (reg.is_boundary() !=
is_bc())
continue;
306 if ( rh.empty())
continue;
308 double last_time_in_history = rh.front().first;
309 unsigned int history_size=rh.size();
310 unsigned int i_history;
311 ASSERT( time_step.
ge(last_time_in_history) ).error(
"Setting field time back in history not fully supported yet!");
314 if ( time_step.
gt(last_time_in_history) ) {
326 i_history=min(i_history, history_size - 1);
327 ASSERT(i_history >= 0).error(
"Empty field history.");
330 auto new_ptr = rh.at(i_history).second;
344 template<
int spacedim,
class Value>
347 .error(
"Can not copy to the non-input field.");
351 && this->
shared_->input_list_.size() != 0 )
return;
353 if (
typeid(other) ==
typeid(*this)) {
361 template<
int spacedim,
class Value>
374 template<
int spacedim,
class Value>
377 typedef typename Value::element_type ElemType;
379 if (observe->point_ds()->size() == 0)
return;
382 (
unsigned int)Value::NRows_, (
unsigned int)Value::NCols_);
384 unsigned int loc_point_time_index, ele_index;
386 loc_point_time_index = op_acc.loc_point_time_index();
387 ele_index = op_acc.observe_point().element_idx();
388 const Value &obs_value =
389 Value( const_cast<typename Value::return_type &>(
390 this->
value(op_acc.observe_point().global_coords(),
392 ASSERT_EQ(output_data.
n_comp(), obs_value.n_rows()*obs_value.n_cols()).error();
393 output_data.
store_value(loc_point_time_index, obs_value.mem_ptr());
399 template<
int spacedim,
class Value>
403 for(
Region ® : region_set) {
409 else if (fr != result_all)
422 template<
int spacedim,
class Value>
425 int nrows = Value::NRows_;
426 int ncols = Value::NCols_;
427 string type =
"Integer";
431 return fmt::format(
"{{ \"shape\": [ {}, {} ], \"type\": \"{}\", \"limit\": [ {}, {} ] }}",
432 nrows, ncols, type, this->
limits().first, this->
limits().second);
436 template<
int spacedim,
class Value>
438 ASSERT_PTR(
mesh() ).error(
"Null mesh pointer, set_mesh() has to be called before.\n");
442 if (
shared_->input_list_.size() != 0) {
451 if (actual_list_item.
opt_val(
"region", domain_name_array)) {
455 }
else if (actual_list_item.
opt_val(
"rid",
id)) {
459 }
catch (RegionDB::ExcUniqueRegionId &e) {
464 domain.push_back(region);
466 THROW(RegionDB::ExcUnknownRegion() << RegionDB::EI_ID(
id) );
468 THROW(ExcMissingDomain()
474 FieldBasePtr field_instance = (*rit)->create_field(actual_list_item, *
this);
479 field_instance->set_mesh(
mesh() ,
is_bc() );
480 for(
const Region ®: domain) {
485 if(
data_->region_history_[reg.idx()].size() == 0
486 ||
data_->region_history_[reg.idx()].back().first < input_time)
488 data_->region_history_[reg.idx()].push_front(
494 data_->region_history_[reg.idx()].back() =
507 template<
int spacedim,
class Value>
515 for(
const Region ® :
mesh()->region_db().get_region_set(
"ALL") )
516 if (reg.is_boundary() ==
is_bc()) {
518 if ( rh.empty() || ! rh[0].second)
527 !=
shared_->no_check_values_.end() )
530 if (
shared_->input_default_ !=
"") {
531 regions_to_init.push_back( reg );
533 xprintf(
UsrErr,
"Missing value of the input field '%s' ('%s') on region ID: %d label: %s.\n",
534 input_name().c_str(),
name().c_str(), reg.id(), reg.label().c_str() );
540 if ( regions_to_init.size() ) {
541 std::string region_list;
551 for(
const Region ®: regions_to_init) {
552 data_->region_history_[reg.idx()]
554 region_list+=
" "+reg.label();
563 template<
int spacedim,
class Value>
569 template<
int spacedim,
class Value>
581 template<
int spacedim,
class Value>
589 template<
int spacedim,
class Value>
594 double time,last_time=0.0;
600 if ( (*rit)->is_active_field_descriptor( (*
it), this->input_name() ) ) {
603 if (time < last_time) {
604 THROW( ExcNonascendingTime()
607 <<
it->ei_address());
620 template<
int spacedim,
class Value>
622 typedef typename Value::element_type ElemType;
625 (
unsigned int)Value::NRows_, (
unsigned int)Value::NCols_);
629 if( ! output_data_base->is_dummy()){
634 }
catch(
const std::bad_cast& e){
639 stream->update_time(this->
time());
643 template<
int spacedim,
class Value>
645 std::shared_ptr<OutputTime> stream,
648 std::shared_ptr<OutputMeshBase> output_mesh = stream->get_output_mesh_ptr();
655 unsigned int node_index = 0;
656 for(
const auto & ele : *output_mesh )
659 for(
unsigned int i=0; i < ele.n_nodes(); i++)
661 const Value &node_value =
662 Value( const_cast<typename Value::return_type &>(
663 this->
value(vertices[i],
666 ASSERT_EQ(data_cache->n_comp(), node_value.n_rows()*node_value.n_cols()).error();
667 data_cache->store_value(node_index, node_value.mem_ptr() );
674 for(
const auto & ele : *output_mesh )
676 unsigned int ele_index = ele.idx();
677 const Value &ele_value =
678 Value( const_cast<typename Value::return_type &>(
679 this->
value(ele.centre(),
683 ASSERT_EQ(data_cache->n_comp(), ele_value.n_rows()*ele_value.n_cols()).error();
684 data_cache->store_value(ele_index, ele_value.mem_ptr() );
689 std::shared_ptr< FieldFE<spacedim, Value> > field_fe_ptr = this->
get_field_fe();
692 auto native_output_data_base = stream->prepare_compute_data<
double>(this->
name(), space_type,
693 (
unsigned int)Value::NRows_, (
unsigned int)Value::NCols_);
696 field_fe_ptr->native_data_to_cache(*native_output_data);
698 WarningOut().fmt(
"Field '{}' of native data space type is not of type FieldFE. Output will be skipped.\n", this->
name());
709 template<
int spacedim,
class Value>
712 ASSERT(!this->
shared_->bc_).error(
"FieldFE output of native data is supported only for bulk fields!");
714 std::shared_ptr< FieldFE<spacedim, Value> > field_fe_ptr;
731 template<
int spacedim,
class Value>
737 template<
int spacedim,
class Value>
742 std::unordered_map<unsigned int, unsigned int>::iterator reg_elm_it;
743 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
void fill_data_cache(OutputTime::DiscreteSpace space_type, std::shared_ptr< OutputTime > stream, std::shared_ptr< ElementDataCache< typename Value::element_type >> data_cache)
Fills acutally the data cache with field values, used in compute_field_data.
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)
std::shared_ptr< ElementDataCacheBase > OutputDataPtr
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.