18 #ifndef FIELD_IMPL_HH_ 19 #define FIELD_IMPL_HH_ 21 #include <boost/foreach.hpp> 37 template<
int spacedim,
class Value>
43 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
44 this->
add_factory( std::make_shared<FactoryBase>() );
50 template<
int spacedim,
class Value>
57 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
60 this->
add_factory( std::make_shared<FactoryBase>() );
66 template<
int spacedim,
class Value>
72 shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
74 this->
name_ = (name==
"") ? input_name : name;
82 template<
int spacedim,
class Value>
96 template<
int spacedim,
class Value>
100 OLD_ASSERT(other.
shared_->mesh_,
"Must call set_mesh before assign to other field.\n");
102 "Assignment between fields with different meshes.\n");
105 if (&other ==
this)
return *
this;
109 shared_->is_fully_initialized_ =
false;
131 template<
int spacedim,
class Value>
138 template<
int spacedim,
class Value>
140 OLD_ASSERT(
false,
"This method can't be used for Field");
148 template<
int spacedim,
class Value>
158 template<
int spacedim,
class Value>
163 THROW(ExcFieldMeshDifference() << EI_Field(
name()) );
171 data_->region_history_.resize(
mesh()->region_db().
size(), init_history );
188 template <
int spacedim,
class Value>
197 template<
int spacedim,
class Value>
205 OLD_ASSERT(
mesh(),
"Null mesh pointer, set_mesh() has to be called before set_field().\n");
206 if (domain.size() == 0)
return;
212 for(
const Region ®: domain) {
215 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",
216 hp.first, region_history[0].first );
217 region_history.push_front(hp);
224 template<
int spacedim,
class Value>
237 template<
int spacedim,
class Value>
240 OLD_ASSERT(
mesh() ,
"NULL mesh pointer of field '%s'. set_mesh must be called before.\n",
name().c_str());
270 for(
const Region ®:
mesh()->region_db().get_region_set(
"ALL") ) {
271 auto rh =
data_->region_history_[reg.idx()];
274 if (reg.is_boundary() !=
is_bc())
continue;
277 if ( rh.empty())
continue;
279 double last_time_in_history = rh.front().first;
280 unsigned int history_size=rh.size();
281 unsigned int i_history;
282 OLD_ASSERT(time_step.
ge(last_time_in_history),
"Setting field time back in history not fully supported yet!");
285 if ( time_step.
gt(last_time_in_history) ) {
297 i_history=min(i_history, history_size - 1);
298 OLD_ASSERT(i_history >= 0,
"Empty field history.");
301 auto new_ptr = rh.at(i_history).second;
315 template<
int spacedim,
class Value>
318 .error(
"Can not copy to the non-input field.");
322 && this->
shared_->input_list_.size() != 0 )
return;
324 if (
typeid(other) ==
typeid(*this)) {
332 template<
int spacedim,
class Value>
343 if (flags & (1 << ids))
349 template<
int spacedim,
class Value>
352 typedef typename Value::element_type ElemType;
354 if (observe->points().size() == 0)
return;
357 (
unsigned int)Value::NRows_, (
unsigned int)Value::NCols_);
359 unsigned int i_data=0;
361 unsigned int ele_index = o_point.element_idx();
362 const Value &obs_value =
363 Value( const_cast<typename Value::return_type &>(
364 this->
value(o_point.global_coords(),
366 ASSERT_EQ(output_data.
n_elem(), obs_value.n_rows()*obs_value.n_cols()).error();
367 output_data.
store_value(i_data, obs_value.mem_ptr());
374 template<
int spacedim,
class Value>
378 for(
Region ® : region_set) {
384 else if (fr != result_all)
397 template<
int spacedim,
class Value>
400 int nrows = Value::NRows_;
401 int ncols = Value::NCols_;
402 string type =
"Integer";
406 return fmt::format(
"{{ \"shape\": [ {}, {} ], \"type\": \"{}\", \"limit\": [ {}, {} ] }}",
407 nrows, ncols, type, this->
limits().first, this->
limits().second);
411 template<
int spacedim,
class Value>
413 OLD_ASSERT(
mesh(),
"Null mesh pointer, set_mesh() has to be called before.\n");
417 if (
shared_->input_list_.size() != 0) {
419 && time.
ge( input_time =
shared_->input_list_[
shared_->list_idx_].val<
double>(
"time") ) ) {
426 if (actual_list_item.
opt_val(
"region", domain_name_array)) {
430 }
else if (actual_list_item.
opt_val(
"rid",
id)) {
434 }
catch (RegionDB::ExcUniqueRegionId &e) {
439 domain.push_back(region);
441 THROW(RegionDB::ExcUnknownRegion() << RegionDB::EI_ID(
id) );
443 THROW(ExcMissingDomain()
449 FieldBasePtr field_instance = (*rit)->create_field(actual_list_item, *
this);
454 field_instance->set_mesh(
mesh() ,
is_bc() );
455 for(
const Region ®: domain) {
460 if(
data_->region_history_[reg.idx()].size() == 0
461 ||
data_->region_history_[reg.idx()].back().first < input_time)
463 data_->region_history_[reg.idx()].push_front(
469 data_->region_history_[reg.idx()].back() =
482 template<
int spacedim,
class Value>
490 for(
const Region ® :
mesh()->region_db().get_region_set(
"ALL") )
491 if (reg.is_boundary() ==
is_bc()) {
493 if ( rh.empty() || ! rh[0].second)
502 !=
shared_->no_check_values_.end() )
505 if (
shared_->input_default_ !=
"") {
506 regions_to_init.push_back( reg );
508 xprintf(
UsrErr,
"Missing value of the input field '%s' ('%s') on region ID: %d label: %s.\n",
509 input_name().c_str(),
name().c_str(), reg.id(), reg.label().c_str() );
515 if ( regions_to_init.size() ) {
516 std::string region_list;
526 for(
const Region ®: regions_to_init) {
527 data_->region_history_[reg.idx()]
529 region_list+=
" "+reg.label();
538 template<
int spacedim,
class Value>
544 template<
int spacedim,
class Value>
556 template<
int spacedim,
class Value>
564 template<
int spacedim,
class Value>
569 double time,last_time=0.0;
575 if ( (*rit)->is_active_field_descriptor( (*
it), this->input_name() ) ) {
577 time =
it->val<
double>(
"time");
578 if (time < last_time) {
579 THROW( ExcNonascendingTime()
582 <<
it->ei_address());
595 template<
int spacedim,
class Value>
597 typedef typename Value::element_type ElemType;
600 if( stream->get_rank() != 0) {
606 (
unsigned int)Value::NRows_, (
unsigned int)Value::NCols_);
614 for(
unsigned int idx=0; idx < output_data.
n_values(); idx++)
615 output_data.
zero(idx);
617 std::shared_ptr<OutputMesh> output_mesh = std::dynamic_pointer_cast<
OutputMesh>( stream->get_output_mesh_ptr() );
618 for(
const auto & ele : *output_mesh )
621 for(
unsigned int i=0; i < ele.n_nodes(); i++)
623 unsigned int node_index = ele.node_index(i);
624 const Value &node_value =
625 Value( const_cast<typename Value::return_type &>(
626 this->
value(vertices[i],
629 output_data.
add(node_index, node_value.mem_ptr() );
635 for(
unsigned int idx=0; idx < output_data.
n_values(); idx++)
640 std::shared_ptr<OutputMeshDiscontinuous> output_mesh_disc
642 for(
const auto & ele : *output_mesh_disc )
645 for(
unsigned int i=0; i < ele.n_nodes(); i++)
647 unsigned int node_index = ele.node_index(i);
648 const Value &node_value =
649 Value( const_cast<typename Value::return_type &>(
650 this->
value(vertices[i],
653 ASSERT_EQ(output_data.
n_elem(), node_value.n_rows()*node_value.n_cols()).error();
654 output_data.
store_value(node_index, node_value.mem_ptr() );
660 std::shared_ptr<OutputMesh> output_mesh = std::dynamic_pointer_cast<
OutputMesh>( stream->get_output_mesh_ptr() );
661 for(
const auto & ele : *output_mesh )
663 unsigned int ele_index = ele.idx();
664 const Value &ele_value =
665 Value( const_cast<typename Value::return_type &>(
666 this->
value(ele.centre(),
670 ASSERT_EQ(output_data.
n_elem(), ele_value.n_rows()*ele_value.n_cols()).error();
671 output_data.
store_value(ele_index, ele_value.mem_ptr() );
678 stream->update_time(this->
time());
Class represents output mesh with continuous elements.
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.
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
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)
unsigned int DiscreteSpaceFlags
OutputTime::DiscreteSpace output_type() const
Class represents output mesh with discontinuous elements.
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
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.