18 #ifndef FIELD_IMPL_HH_ 19 #define FIELD_IMPL_HH_ 21 #include <boost/foreach.hpp> 38 template<
int spacedim,
class Value>
44 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
45 this->
add_factory( std::make_shared<FactoryBase>() );
51 template<
int spacedim,
class Value>
58 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
61 this->
add_factory( std::make_shared<FactoryBase>() );
67 template<
int spacedim,
class Value>
73 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
75 this->
name_ = (name==
"") ? input_name : name;
83 template<
int spacedim,
class Value>
97 template<
int spacedim,
class Value>
101 OLD_ASSERT(other.
shared_->mesh_,
"Must call set_mesh before assign to other field.\n");
103 "Assignment between fields with different meshes.\n");
106 if (&other ==
this)
return *
this;
110 shared_->is_fully_initialized_ =
false;
132 template<
int spacedim,
class Value>
139 template<
int spacedim,
class Value>
141 OLD_ASSERT(
false,
"This method can't be used for Field");
149 template<
int spacedim,
class Value>
159 template<
int spacedim,
class Value>
164 THROW(ExcFieldMeshDifference() << EI_Field(
name()) );
172 data_->region_history_.resize(
mesh()->region_db().
size(), init_history );
189 template <
int spacedim,
class Value>
198 template<
int spacedim,
class Value>
206 OLD_ASSERT(
mesh(),
"Null mesh pointer, set_mesh() has to be called before set_field().\n");
207 if (domain.size() == 0)
return;
213 for(
const Region ®: domain) {
216 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",
217 hp.first, region_history[0].first );
218 region_history.push_front(hp);
225 template<
int spacedim,
class Value>
238 template<
int spacedim,
class Value>
241 OLD_ASSERT(
mesh() ,
"NULL mesh pointer of field '%s'. set_mesh must be called before.\n",
name().c_str());
271 for(
const Region ®:
mesh()->region_db().get_region_set(
"ALL") ) {
272 auto rh =
data_->region_history_[reg.idx()];
275 if (reg.is_boundary() !=
is_bc())
continue;
278 if ( rh.empty())
continue;
280 double last_time_in_history = rh.front().first;
281 unsigned int history_size=rh.size();
282 unsigned int i_history;
283 OLD_ASSERT(time_step.
ge(last_time_in_history),
"Setting field time back in history not fully supported yet!");
286 if ( time_step.
gt(last_time_in_history) ) {
298 i_history=min(i_history, history_size - 1);
299 OLD_ASSERT(i_history >= 0,
"Empty field history.");
302 auto new_ptr = rh.at(i_history).second;
316 template<
int spacedim,
class Value>
319 .error(
"Can not copy to the non-input field.");
323 && this->
shared_->input_list_.size() != 0 )
return;
325 if (
typeid(other) ==
typeid(*this)) {
333 template<
int spacedim,
class Value>
346 template<
int spacedim,
class Value>
349 typedef typename Value::element_type ElemType;
351 if (observe->points().size() == 0)
return;
354 (
unsigned int)Value::NRows_, (
unsigned int)Value::NCols_);
356 unsigned int i_data=0;
358 unsigned int ele_index = o_point.element_idx();
359 const Value &obs_value =
360 Value( const_cast<typename Value::return_type &>(
361 this->
value(o_point.global_coords(),
363 ASSERT_EQ(output_data.
n_elem(), obs_value.n_rows()*obs_value.n_cols()).error();
364 output_data.
store_value(i_data, obs_value.mem_ptr());
371 template<
int spacedim,
class Value>
375 for(
Region ® : region_set) {
381 else if (fr != result_all)
394 template<
int spacedim,
class Value>
397 int nrows = Value::NRows_;
398 int ncols = Value::NCols_;
399 string type =
"Integer";
403 return fmt::format(
"{{ \"shape\": [ {}, {} ], \"type\": \"{}\", \"limit\": [ {}, {} ] }}",
404 nrows, ncols, type, this->
limits().first, this->
limits().second);
408 template<
int spacedim,
class Value>
410 OLD_ASSERT(
mesh(),
"Null mesh pointer, set_mesh() has to be called before.\n");
414 if (
shared_->input_list_.size() != 0) {
416 && time.
ge( input_time =
shared_->input_list_[
shared_->list_idx_].val<
double>(
"time") ) ) {
423 if (actual_list_item.
opt_val(
"region", domain_name_array)) {
427 }
else if (actual_list_item.
opt_val(
"rid",
id)) {
431 }
catch (RegionDB::ExcUniqueRegionId &e) {
436 domain.push_back(region);
438 THROW(RegionDB::ExcUnknownRegion() << RegionDB::EI_ID(
id) );
440 THROW(ExcMissingDomain()
446 FieldBasePtr field_instance = (*rit)->create_field(actual_list_item, *
this);
451 field_instance->set_mesh(
mesh() ,
is_bc() );
452 for(
const Region ®: domain) {
453 data_->region_history_[reg.idx()].push_front(
467 template<
int spacedim,
class Value>
475 for(
const Region ® :
mesh()->region_db().get_region_set(
"ALL") )
476 if (reg.is_boundary() ==
is_bc()) {
478 if ( rh.empty() || ! rh[0].second)
487 !=
shared_->no_check_values_.end() )
490 if (
shared_->input_default_ !=
"") {
491 regions_to_init.push_back( reg );
493 xprintf(
UsrErr,
"Missing value of the input field '%s' ('%s') on region ID: %d label: %s.\n",
494 input_name().c_str(),
name().c_str(), reg.id(), reg.label().c_str() );
500 if ( regions_to_init.size() ) {
501 std::string region_list;
511 for(
const Region ®: regions_to_init) {
512 data_->region_history_[reg.idx()]
514 region_list+=
" "+reg.label();
523 template<
int spacedim,
class Value>
529 template<
int spacedim,
class Value>
541 template<
int spacedim,
class Value>
549 template<
int spacedim,
class Value>
554 double time,last_time=0.0;
560 if ( (*rit)->is_active_field_descriptor( (*
it), this->input_name() ) ) {
562 time =
it->val<
double>(
"time");
563 if (time < last_time) {
564 THROW( ExcNonascendingTime()
567 <<
it->ei_address());
580 template<
int spacedim,
class Value>
582 typedef typename Value::element_type ElemType;
584 std::shared_ptr<OutputMeshBase> output_mesh = stream->get_output_mesh_ptr();
586 if ( !output_mesh ) {
592 (
unsigned int)Value::NRows_, (
unsigned int)Value::NCols_);
599 for(
unsigned int idx=0; idx < output_data.
n_values(); idx++)
600 output_data.
zero(idx);
602 for(
const auto & ele : *output_mesh )
605 for(
unsigned int i=0; i < ele.n_nodes(); i++)
607 unsigned int node_index = ele.node_index(i);
608 const Value &node_value =
609 Value( const_cast<typename Value::return_type &>(
610 this->
value(vertices[i],
613 output_data.
add(node_index, node_value.mem_ptr() );
619 for(
unsigned int idx=0; idx < output_data.
n_values(); idx++)
624 for(
const auto & ele : *output_mesh )
627 for(
unsigned int i=0; i < ele.n_nodes(); i++)
629 unsigned int node_index = ele.node_index(i);
630 const Value &node_value =
631 Value( const_cast<typename Value::return_type &>(
632 this->
value(vertices[i],
635 ASSERT_EQ(output_data.
n_elem(), node_value.n_rows()*node_value.n_cols()).error();
636 output_data.
store_value(node_index, node_value.mem_ptr() );
642 for(
const auto & ele : *output_mesh )
644 unsigned int ele_index = ele.idx();
645 const Value &ele_value =
646 Value( const_cast<typename Value::return_type &>(
647 this->
value(ele.centre(),
651 ASSERT_EQ(output_data.
n_elem(), ele_value.n_rows()*ele_value.n_cols()).error();
652 output_data.
store_value(ele_index, ele_value.mem_ptr() );
657 std::shared_ptr< FieldFE<spacedim, Value> > field_fe_ptr = this->
get_field_fe();
661 (
unsigned int)Value::NRows_, (
unsigned int)Value::NCols_);
662 field_fe_ptr->fill_data_to_cache(native_output_data);
664 WarningOut().fmt(
"Field '{}' of native data space type is not of type FieldFE. Output will be skipped.\n", this->
name());
675 stream->update_time(this->
time());
680 template<
int spacedim,
class Value>
683 ASSERT(!this->
shared_->bc_).error(
"FieldFE output of native data is supported only for bulk fields!");
685 std::shared_ptr< FieldFE<spacedim, Value> > field_fe_ptr;
void check_initialized_region_fields_()
Classes for auxiliary output mesh.
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.
#define ASSERT_EQ_DBG(a, b)
Definition of comparative assert macro (EQual) only for debug mode.
unsigned int size() const
Number of subfields that compose the multi-field.
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
RegionSet union_set(std::vector< string > set_names) const
std::string get_value_attribute() const override
OutputTime::DiscreteSpace get_output_type() const
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)
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
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
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_
void add(unsigned int idx, const T *value)
std::shared_ptr< FieldFE< spacedim, Value > > get_field_fe()
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
void zero(unsigned int idx)
std::shared_ptr< ControlField > no_check_control_field_
#define OLD_ASSERT_LESS(a, b)
static const unsigned int N_DISCRETE_SPACES
virtual Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm) const
NumCompValueType n_elem()
LimitSide last_limit_side_
std::vector< FieldBasePtr > region_fields_
void normalize(unsigned int idx, unsigned int divisor)
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 &
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
#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)
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_
#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) ...
unsigned int idx() const
Returns a global index of the region.