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>() );
55 this->
set_shape( Value::NRows_, Value::NCols_ );
59 template<
int spacedim,
class Value>
66 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
69 this->
add_factory( std::make_shared<FactoryBase>() );
75 this->
set_shape( Value::NRows_, Value::NCols_ );
80 template<
int spacedim,
class Value>
87 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
89 this->
name_ = (name==
"") ? input_name : name;
98 this->
set_shape( Value::NRows_, Value::NCols_ );
102 template<
int spacedim,
class Value>
114 this->
set_shape( Value::NRows_, Value::NCols_ );
118 template<
int spacedim,
class Value>
122 ASSERT(other.
shared_->mesh_).error(
"Must call set_mesh before assign to other field.\n");
126 if (&other ==
this)
return *
this;
130 shared_->is_fully_initialized_ =
false;
154 template<
int spacedim,
class Value>
161 template<
int spacedim,
class Value>
168 template<
int spacedim,
class Value>
175 template<
int spacedim,
class Value>
182 template<
int spacedim,
class Value>
183 typename Value::return_type
186 return Value::get_from_array( this->
value_cache_, i_cache_point );
191 template<
int spacedim,
class Value>
198 template<
int spacedim,
class Value>
200 ASSERT(
false).error(
"This method can't be used for Field");
208 template<
int spacedim,
class Value>
218 template<
int spacedim,
class Value>
223 THROW(ExcFieldMeshDifference() << EI_Field(
name()) );
231 data_->region_history_.resize(
mesh()->region_db().size(), init_history );
248 template <
int spacedim,
class Value>
253 return ( region_field && region_field->is_constant_in_space() );
257 template<
int spacedim,
class Value>
263 ASSERT_PTR(field).error(
"Null field pointer.\n");
265 ASSERT_PTR(
mesh() ).error(
"Null mesh pointer, set_mesh() has to be called before set().\n");
269 for (
auto set_name : region_set_names) {
271 if (domain.size() == 0)
continue;
274 for(
const Region ®: domain) {
277 ASSERT( region_history.size() == 0 || region_history[0].first < hp.first)(hp.first)(region_history[0].first)
278 .error(
"Can not insert smaller time then last time in field's history.\n");
279 region_history.push_front(hp);
287 template<
int spacedim,
class Value>
299 template<
int spacedim,
class Value>
302 ASSERT_PTR(
mesh() )(
name() ).error(
"NULL mesh pointer of field with given name. set_mesh must be called before.\n");
332 for(
const Region ®:
mesh()->region_db().get_region_set(
"ALL") ) {
333 auto rh =
data_->region_history_[reg.idx()];
336 if (reg.is_boundary() !=
is_bc())
continue;
339 if ( rh.empty())
continue;
341 double last_time_in_history = rh.front().first;
342 unsigned int history_size=rh.size();
343 unsigned int i_history;
344 ASSERT( time_step.
ge(last_time_in_history) ).error(
"Setting field time back in history not fully supported yet!");
347 if ( time_step.
gt(last_time_in_history) ) {
359 i_history=min(i_history, history_size - 1);
360 ASSERT(i_history >= 0).error(
"Empty field history.");
363 auto new_ptr = rh.at(i_history).second;
377 template<
int spacedim,
class Value>
380 .error(
"Can not copy to the non-input field.");
384 && this->
shared_->input_list_.size() != 0 )
return;
386 if (
typeid(other) ==
typeid(*this)) {
394 template<
int spacedim,
class Value>
407 template<
int spacedim,
class Value>
410 typedef typename Value::element_type ElemType;
412 if (observe->point_ds()->size() == 0)
return;
415 (
unsigned int)Value::NRows_, (
unsigned int)Value::NCols_);
417 unsigned int loc_point_time_index, ele_index;
419 loc_point_time_index = op_acc.loc_point_time_index();
420 ele_index = op_acc.observe_point().element_idx();
421 const Value &obs_value =
422 Value( const_cast<typename Value::return_type &>(
423 this->
value(op_acc.observe_point().global_coords(),
425 ASSERT_EQ(output_data.
n_comp(), obs_value.n_rows()*obs_value.n_cols()).error();
426 output_data.
store_value(loc_point_time_index, obs_value.mem_ptr());
432 template<
int spacedim,
class Value>
436 for(
Region ® : region_set) {
442 else if (fr != result_all)
455 template<
int spacedim,
class Value>
458 int nrows = Value::NRows_;
459 int ncols = Value::NCols_;
460 string type =
"Integer";
464 return fmt::format(
"{{ \"shape\": [ {}, {} ], \"type\": \"{}\", \"limit\": [ {}, {} ] }}",
465 nrows, ncols, type, this->
limits().first, this->
limits().second);
469 template<
int spacedim,
class Value>
471 ASSERT_PTR(
mesh() ).error(
"Null mesh pointer, set_mesh() has to be called before.\n");
475 if (
shared_->input_list_.size() != 0) {
484 if (actual_list_item.
opt_val(
"region", domain_name_array)) {
488 }
else if (actual_list_item.
opt_val(
"rid",
id)) {
492 }
catch (RegionDB::ExcUniqueRegionId &e) {
497 domain.push_back(region);
499 THROW(RegionDB::ExcUnknownRegion() << RegionDB::EI_ID(
id) );
501 THROW(ExcMissingDomain()
507 FieldBasePtr field_instance = (*rit)->create_field(actual_list_item, *
this);
512 field_instance->set_mesh(
mesh() ,
is_bc() );
513 for(
const Region ®: domain) {
518 if(
data_->region_history_[reg.idx()].size() == 0
519 ||
data_->region_history_[reg.idx()].back().first < input_time)
521 data_->region_history_[reg.idx()].push_front(
527 data_->region_history_[reg.idx()].back() =
540 template<
int spacedim,
class Value>
548 for(
const Region ® :
mesh()->region_db().get_region_set(
"ALL") )
549 if (reg.is_boundary() ==
is_bc()) {
551 if ( rh.empty() || ! rh[0].second)
560 !=
shared_->no_check_values_.end() )
563 if (
shared_->input_default_ !=
"") {
564 regions_to_init.push_back( reg );
567 << EI_RegId(reg.id()) << EI_RegLabel(reg.label()) );
573 if ( regions_to_init.size() ) {
574 std::string region_list;
584 for(
const Region ®: regions_to_init) {
585 data_->region_history_[reg.idx()]
587 region_list+=
" "+reg.label();
596 template<
int spacedim,
class Value>
602 template<
int spacedim,
class Value>
614 template<
int spacedim,
class Value>
622 template<
int spacedim,
class Value>
627 double time,last_time=0.0;
633 if ( (*rit)->is_active_field_descriptor( (*
it), this->input_name() ) ) {
636 if (time < last_time) {
637 THROW( ExcNonascendingTime()
640 <<
it->ei_address());
653 template<
int spacedim,
class Value>
655 typedef typename Value::element_type ElemType;
658 (
unsigned int)Value::NRows_, (
unsigned int)Value::NCols_);
662 if( ! output_data_base->is_dummy()){
667 }
catch(
const std::bad_cast& e){
672 stream->update_time(this->
time());
676 template<
int spacedim,
class Value>
678 std::shared_ptr<OutputTime> stream,
681 std::shared_ptr<OutputMeshBase> output_mesh = stream->get_output_mesh_ptr();
688 unsigned int node_index = 0;
689 for(
const auto & ele : *output_mesh )
692 for(
unsigned int i=0; i < ele.n_nodes(); i++)
694 const Value &node_value =
695 Value( const_cast<typename Value::return_type &>(
696 this->
value(vertices[i],
699 ASSERT_EQ(data_cache->n_comp(), node_value.n_rows()*node_value.n_cols()).error();
700 data_cache->store_value(node_index, node_value.mem_ptr() );
707 for(
const auto & ele : *output_mesh )
709 unsigned int ele_index = ele.idx();
710 const Value &ele_value =
711 Value( const_cast<typename Value::return_type &>(
712 this->
value(ele.centre(),
716 ASSERT_EQ(data_cache->n_comp(), ele_value.n_rows()*ele_value.n_cols()).error();
717 data_cache->store_value(ele_index, ele_value.mem_ptr() );
722 std::shared_ptr< FieldFE<spacedim, Value> > field_fe_ptr = this->
get_field_fe();
725 auto native_output_data_base = stream->prepare_compute_data<
double>(this->
name(), space_type,
726 (
unsigned int)Value::NRows_, (
unsigned int)Value::NCols_);
729 field_fe_ptr->native_data_to_cache(*native_output_data);
731 WarningOut().fmt(
"Field '{}' of native data space type is not of type FieldFE. Output will be skipped.\n", this->
name());
742 template<
int spacedim,
class Value>
745 ASSERT(!this->
shared_->bc_).error(
"FieldFE output of native data is supported only for bulk fields!");
747 std::shared_ptr< FieldFE<spacedim, Value> > field_fe_ptr;
764 template<
int spacedim,
class Value>
772 template<
int spacedim,
class Value>
780 template<
int spacedim,
class Value>
787 template<
int spacedim,
class Value>
804 template<
int spacedim,
class Value>
void check_initialized_region_fields_()
Classes for auxiliary output mesh.
Common abstract parent of all Field<...> classes.
Container for various descendants of FieldCommonBase.
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.
RegionSet get_region_set(const std::string &set_name) 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...
unsigned int eval_point_idx() const
Return index in EvalPoints object.
Value::return_type get_value(const FieldValueCache< typename Value::element_type > &field_cache, unsigned int elem_patch_idx, unsigned int eval_points_idx) const
Return value of evaluation point given by idx of element in patch and local point idx in EvalPoints f...
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
std::string get_value_attribute() const override
static unsigned int get()
Return number of stored elements.
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
void cache_reallocate(const ElementCacheMap &cache_map, unsigned int region_idx) const override
Implements FieldCommon::cache_allocate.
Class template representing a field with values dependent on: point, element, and region...
std::string format(CStringRef format_str, ArgList args)
FieldValueCache< double > * value_cache() override
Implements FieldCommon::value_cache.
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...
void field_output(std::shared_ptr< OutputTime > stream) override
Value::return_type operator[](unsigned int i_cache_point) const
Return item of value_cache_ given by i_cache_point.
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::vector< const FieldCommon * > set_dependency(FieldSet &field_set, unsigned int i_reg) const override
Point accessor allow iterate over quadrature points of given side defined in local element coordinate...
unsigned int region_idx_from_chunk_position(unsigned int chunk_pos) const
Return begin position of region chunk specified by position in map.
std::shared_ptr< SharedData > data_
static constexpr bool value
std::vector< uint > shape_
constexpr bool match(Mask mask) const
std::shared_ptr< SharedData > shared_
void set(FieldBasePtr field, double time, std::vector< std::string > region_set_names={"ALL"})
unsigned int eval_point_idx() const
Return index in EvalPoints object.
std::shared_ptr< FieldFE< spacedim, Value > > get_field_fe()
const std::string & name() const
bool ge(double other_time) const
void cache_update(ElementCacheMap &cache_map, unsigned int region_patch_idx) const override
Implements FieldCommon::cache_update.
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
const ElementCacheMap * elm_cache_map() const
LimitSide last_limit_side_
void set_shape(uint n_rows, uint n_cols)
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.
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_
unsigned int eval_point_idx() const
Return index in EvalPoints object.
Point accessor allow iterate over quadrature points of given side defined in local element coordinate...
#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)
#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 compute_field_data(OutputTime::DiscreteSpace space_type, std::shared_ptr< OutputTime > stream)
#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_
void set_input_list(const Input::Array &list, const TimeGovernor &tg) override
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual)
unsigned int elem_patch_idx() const
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)
Return appropriate value to BulkPoint in FieldValueCache.
FieldValueCache< typename Value::element_type > value_cache_
unsigned int idx() const
Returns a global index of the region.