Flow123d  JS_before_hm-2074-g7860a8b45
field.impl.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file field.impl.hh
15  * @brief
16  */
17 
18 #ifndef FIELD_IMPL_HH_
19 #define FIELD_IMPL_HH_
20 
21 #include "field.hh"
22 #include "field_algo_base.impl.hh"
23 #include "field_fe.hh"
24 #include "fields/eval_subset.hh"
25 #include "fields/eval_points.hh"
27 #include "fields/field_set.hh"
28 #include "mesh/region.hh"
30 #include "input/accessors.hh"
31 #include "io/observe.hh"
32 #include "io/output_mesh.hh"
33 #include "io/output_element.hh"
34 
35 
36 /******************************************************************************************
37  * Implementation of Field<...>
38  */
39 
40 template<int spacedim, class Value>
42 : data_(std::make_shared<SharedData>()),
43  value_cache_( FieldValueCache<typename Value::element_type>(Value::NRows_, Value::NCols_) )
44 {
45  // n_comp is nonzero only for variable size vectors Vector, VectorEnum, ..
46  // this invariant is kept also by n_comp setter
47  shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
48  this->add_factory( std::make_shared<FactoryBase>() );
49 
50  unsigned int cache_size = 1.1 * CacheMapElementNumber::get();
51  value_cache_.reinit(cache_size);
52  value_cache_.resize(cache_size);
53 
54  this->multifield_ = false;
55  this->set_shape( Value::NRows_, Value::NCols_ );
56 }
57 
58 
59 template<int spacedim, class Value>
60 Field<spacedim,Value>::Field(const string &name, bool bc)
61 : data_(std::make_shared<SharedData>()),
62  value_cache_( FieldValueCache<typename Value::element_type>(Value::NRows_, Value::NCols_) )
63 {
64  // n_comp is nonzero only for variable size vectors Vector, VectorEnum, ..
65  // this invariant is kept also by n_comp setter
66  shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
67  shared_->bc_=bc;
68  this->name( name );
69  this->add_factory( std::make_shared<FactoryBase>() );
70  unsigned int cache_size = 1.1 * CacheMapElementNumber::get();
71  value_cache_.reinit(cache_size);
72  value_cache_.resize(cache_size);
73 
74  this->multifield_ = false;
75  this->set_shape( Value::NRows_, Value::NCols_ );
76 }
77 
78 
79 
80 template<int spacedim, class Value>
81 Field<spacedim,Value>::Field(unsigned int component_index, string input_name, string name, bool bc)
82 : data_(std::make_shared<SharedData>()),
83  value_cache_( FieldValueCache<typename Value::element_type>(Value::NRows_, Value::NCols_) )
84 {
85  // n_comp is nonzero only for variable size vectors Vector, VectorEnum, ..
86  // this invariant is kept also by n_comp setter
87  shared_->n_comp_ = (Value::NRows_ ? 0 : 1);
88  this->set_component_index(component_index);
89  this->name_ = (name=="") ? input_name : name;
90  this->shared_->input_name_ = input_name;
91  shared_->bc_ = bc;
92 
93  unsigned int cache_size = 1.1 * CacheMapElementNumber::get();
94  value_cache_.reinit(cache_size);
95  value_cache_.resize(cache_size);
96 
97  this->multifield_ = false;
98  this->set_shape( Value::NRows_, Value::NCols_ );
99 }
100 
101 
102 template<int spacedim, class Value>
104 : FieldCommon(other),
105  data_(other.data_),
106  region_fields_(other.region_fields_),
107  factories_(other.factories_),
108  value_cache_(other.value_cache_)
109 {
110  if (other.no_check_control_field_)
111  no_check_control_field_ = make_shared<ControlField>(*other.no_check_control_field_);
112 
113  this->multifield_ = false;
114  this->set_shape( Value::NRows_, Value::NCols_ );
115 }
116 
117 
118 template<int spacedim, class Value>
120 {
121  //ASSERT( flags().match(FieldFlag::input_copy) )(this->name())(other.name()).error("Try to assign to non-copy field from the field.");
122  ASSERT(other.shared_->mesh_).error("Must call set_mesh before assign to other field.\n");
123  ASSERT( !shared_->mesh_ || (shared_->mesh_==other.shared_->mesh_) ).error("Assignment between fields with different meshes.\n");
124 
125  // check for self assignement
126  if (&other == this) return *this;
127 
128  // class members derived from FieldCommon
129  shared_ = other.shared_;
130  shared_->is_fully_initialized_ = false;
131  set_time_result_ = other.set_time_result_;
132  last_time_ = other.last_time_;
133  last_limit_side_ = other.last_limit_side_;
134  is_jump_time_ = other.is_jump_time_;
135  component_index_ = other.component_index_;
136  this->multifield_ = false;
137 
138  // class members of Field class
139  data_ = other.data_;
140  factories_ = other.factories_;
141  region_fields_ = other.region_fields_;
142  value_cache_ = other.value_cache_;
143  this->shape_ = other.shape_;
144 
145  if (other.no_check_control_field_) {
146  no_check_control_field_ = make_shared<ControlField>(*other.no_check_control_field_);
147  }
148 
149  return *this;
150 }
151 
152 
153 
154 template<int spacedim, class Value>
155 typename Value::return_type Field<spacedim,Value>::operator() (BulkPoint &p) {
156  return p.elm_cache_map()->get_value<Value>(value_cache_, p.elem_patch_idx(), p.eval_point_idx());
157 }
158 
159 
160 
161 template<int spacedim, class Value>
162 typename Value::return_type Field<spacedim,Value>::operator() (SidePoint &p) {
163  return p.elm_cache_map()->get_value<Value>(value_cache_, p.elem_patch_idx(), p.eval_point_idx());
164 }
165 
166 
167 
168 template<int spacedim, class Value>
169 typename Value::return_type
170 Field<spacedim,Value>::operator[] (unsigned int i_cache_point) const
171 {
172  return Value::get_from_array( this->value_cache_, i_cache_point );
173 }
174 
175 
176 
177 template<int spacedim, class Value>
179  return FieldBaseType::get_input_type_instance(shared_->input_element_selection_);
180 }
181 
182 
183 
184 template<int spacedim, class Value>
186  ASSERT(false).error("This method can't be used for Field");
187 
188  it::Array arr = it::Array( it::Integer() );
189  return arr;
190 }
191 
192 
193 
194 template<int spacedim, class Value>
196  const Field<spacedim, typename FieldValue<spacedim>::Enum > &control_field,
197  const vector<FieldEnum> &value_list) -> Field &
198 {
199  no_check_control_field_=std::make_shared<ControlField>(control_field);
200  shared_->no_check_values_=value_list;
201  return *this;
202 }
203 
204 template<int spacedim, class Value>
205 void Field<spacedim,Value>::set_mesh(const Mesh &in_mesh) {
206  // since we allow copy of fields before set_mesh is called
207  // we have to check that all copies set the same mesh
208  if (shared_->mesh_ && shared_->mesh_ != &in_mesh) {
209  THROW(ExcFieldMeshDifference() << EI_Field(name()) );
210  }
211 
212  shared_->mesh_ = &in_mesh;
213 
214  // initialize table if it is empty, we assume that the RegionDB is closed at this moment
215  region_fields_.resize( mesh()->region_db().size() );
216  RegionHistory init_history(history_length_limit_); // capacity
217  data_->region_history_.resize( mesh()->region_db().size(), init_history );
218 
219  if (no_check_control_field_) no_check_control_field_->set_mesh(in_mesh);
220 }
221 
222 
223 /*
224 template<int spacedim, class Value>
225 std::shared_ptr< typename Field<spacedim,Value>::FieldBaseType >
226 Field<spacedim,Value>::operator[] (Region reg)
227 {
228  ASSERT_LT(reg.idx(), this->region_fields_.size());
229  return this->region_fields_[reg.idx()];
230 }
231 */
232 
233 
234 template <int spacedim, class Value>
236  ASSERT(this->set_time_result_ != TimeStatus::unknown).error("Unknown time status.\n");
237  ASSERT_LT(reg.idx(), this->region_fields_.size());
238  FieldBasePtr region_field = this->region_fields_[reg.idx()];
239  return ( region_field && region_field->is_constant_in_space() );
240 }
241 
242 
243 template<int spacedim, class Value>
245  FieldBasePtr field,
246  double time,
247  std::vector<std::string> region_set_names)
248 {
249  ASSERT_PTR(field).error("Null field pointer.\n");
250 
251  ASSERT_PTR( mesh() ).error("Null mesh pointer, set_mesh() has to be called before set().\n");
252  ASSERT_EQ( field->n_comp() , shared_->n_comp_);
253  field->set_mesh( mesh() , is_bc() );
254 
255  for (auto set_name : region_set_names) {
256  RegionSet domain = mesh()->region_db().get_region_set(set_name);
257  if (domain.size() == 0) continue;
258 
259  HistoryPoint hp = HistoryPoint(time, field);
260  for(const Region &reg: domain) {
261  RegionHistory &region_history = data_->region_history_[reg.idx()];
262  // insert hp into descending time sequence
263  ASSERT( region_history.size() == 0 || region_history[0].first < hp.first)(hp.first)(region_history[0].first)
264  .error("Can not insert smaller time then last time in field's history.\n");
265  region_history.push_front(hp);
266  }
267  }
268  set_history_changed();
269 }
270 
271 
272 
273 template<int spacedim, class Value>
275  const Input::AbstractRecord &a_rec,
276  double time,
277  std::vector<std::string> region_set_names)
278 {
279  FieldAlgoBaseInitData init_data(input_name(), n_comp(), units(), limits(), flags());
280  set(FieldBaseType::function_factory(a_rec, init_data), time, region_set_names);
281 }
282 
283 
284 
285 template<int spacedim, class Value>
286 bool Field<spacedim, Value>::set_time(const TimeStep &time_step, LimitSide limit_side)
287 {
288  ASSERT_PTR( mesh() )( name() ).error("NULL mesh pointer of field with given name. set_mesh must be called before.\n");
289 
290  // Skip setting time if the new time is equal to current time of the field
291  // and if either the field is continuous in that time or the current limit side is same as the new one.
292  if (time_step.end() == last_time_) {
293  if ( ! is_jump_time() ||
294  limit_side == last_limit_side_) {
295  last_limit_side_ = limit_side;
296  return changed();
297  }
298  }
299 
300  last_time_=time_step.end();
301  last_limit_side_ = limit_side;
302 
303  // possibly update our control field
304  if (no_check_control_field_) {
305  no_check_control_field_->set_time(time_step, limit_side);
306  }
307 
308  set_time_result_ = TimeStatus::constant;
309 
310  // read all descriptors satisfying time.ge(input_time)
311  update_history(time_step);
312  check_initialized_region_fields_();
313 
314  //
315  is_jump_time_=false;
316  // set time_step on all regions
317  // for regions that match type of the field domain
318  for(const Region &reg: mesh()->region_db().get_region_set("ALL") ) {
319  auto rh = data_->region_history_[reg.idx()];
320 
321  // skip regions with no matching BC flag
322  if (reg.is_boundary() != is_bc()) continue;
323 
324  // Check regions with empty history, possibly set default.
325  if ( rh.empty()) continue;
326 
327  double last_time_in_history = rh.front().first;
328  unsigned int history_size=rh.size();
329  unsigned int i_history;
330  ASSERT( time_step.ge(last_time_in_history) ).error("Setting field time back in history not fully supported yet!");
331 
332  // set history index
333  if ( time_step.gt(last_time_in_history) ) {
334  // in smooth time_step
335  i_history=0;
336  } else {
337  // time_step .eq. input_time; i.e. jump time
338  is_jump_time_=true;
339  if (limit_side == LimitSide::right) {
340  i_history=0;
341  } else {
342  i_history=1;
343  }
344  }
345  i_history=min(i_history, history_size - 1);
346  ASSERT(i_history >= 0).error("Empty field history.");
347  // possibly update field pointer
348 
349  auto new_ptr = rh.at(i_history).second;
350  if (new_ptr != region_fields_[reg.idx()]) {
351  region_fields_[reg.idx()]=new_ptr;
352  set_time_result_ = TimeStatus::changed;
353  }
354  // let FieldBase implementation set the time
355  if ( new_ptr->set_time(time_step) ) set_time_result_ = TimeStatus::changed;
356 
357  }
358 
359  return changed();
360 }
361 
362 
363 template<int spacedim, class Value>
365  ASSERT( flags().match(FieldFlag::equation_input))(other.name().c_str())(this->name().c_str())
366  .error("Can not copy to the non-input field.");
367 
368  // do not use copy if the field have its own input
369  if ( flags().match(FieldFlag::declare_input)
370  && this->shared_->input_list_.size() != 0 ) return;
371 
372  if (typeid(other) == typeid(*this)) {
373  auto const &other_field = dynamic_cast< Field<spacedim, Value> const &>(other);
374  this->operator=(other_field);
375  }
376 }
377 
378 
379 
380 template<int spacedim, class Value>
381 void Field<spacedim, Value>::field_output(std::shared_ptr<OutputTime> stream, OutputTime::DiscreteSpace type)
382 {
383  // currently we cannot output boundary fields
384  if (!is_bc()) {
385  ASSERT_LT( type, OutputTime::N_DISCRETE_SPACES ).error();
386  this->compute_field_data( type, stream);
387  }
388 }
389 
390 
391 template<int spacedim, class Value>
392 void Field<spacedim, Value>::observe_output(std::shared_ptr<Observe> observe)
393 {
394  typedef typename Value::element_type ElemType;
395 
396  if (observe->point_ds()->size() == 0) return;
397 
398  ElementDataCache<ElemType> &output_data = observe->prepare_compute_data<ElemType>(this->name(), this->time(),
399  (unsigned int)Value::NRows_, (unsigned int)Value::NCols_);
400 
401  unsigned int loc_point_time_index, ele_index;
402  for(ObservePointAccessor op_acc : observe->local_range()) {
403  loc_point_time_index = op_acc.loc_point_time_index();
404  ele_index = op_acc.observe_point().element_idx();
405  const Value &obs_value =
406  Value( const_cast<typename Value::return_type &>(
407  this->value(op_acc.observe_point().global_coords(),
408  ElementAccessor<spacedim>(this->mesh(), ele_index)) ));
409  ASSERT_EQ(output_data.n_comp(), obs_value.n_rows()*obs_value.n_cols()).error();
410  output_data.store_value(loc_point_time_index, obs_value.mem_ptr());
411  }
412 }
413 
414 
415 
416 template<int spacedim, class Value>
418 
419  FieldResult result_all = result_none;
420  for(Region &reg : region_set) {
421  auto f = region_fields_[reg.idx()];
422  if (f) {
423  FieldResult fr = f->field_result();
424  if (result_all == result_none) // first region
425  result_all = fr;
426  else if (fr != result_all)
427  result_all = result_other; // if results from individual regions are different
428  } else return result_none; // if field is undefined on any region of the region set
429  }
430 
431  if (result_all == result_constant && region_set.size() > 1)
432  return result_other; // constant result for individual regions could be non-constant on the whole region set
433 
434  return result_all;
435 
436 }
437 
438 
439 template<int spacedim, class Value>
441 {
442  int nrows = Value::NRows_;
443  int ncols = Value::NCols_;
444  string type = "Integer";
446  type = "Double";
447 
448  return fmt::format("{{ \"shape\": [ {}, {} ], \"type\": \"{}\", \"limit\": [ {}, {} ] }}",
449  nrows, ncols, type, this->limits().first, this->limits().second);
450 }
451 
452 
453 template<int spacedim, class Value>
455  ASSERT_PTR( mesh() ).error("Null mesh pointer, set_mesh() has to be called before.\n");
456 
457  // read input up to given time
458  double input_time;
459  if (shared_->input_list_.size() != 0) {
460  while( shared_->list_idx_ < shared_->input_list_.size()
461  && time.ge( input_time = time.read_time( shared_->input_list_[shared_->list_idx_].find<Input::Tuple>("time") ) ) ) {
462 
463  const Input::Record & actual_list_item = shared_->input_list_[shared_->list_idx_];
464  // get domain specification
465  RegionSet domain;
466  Input::Array domain_name_array;
467  unsigned int id;
468  if (actual_list_item.opt_val("region", domain_name_array)) {
469  std::vector<string> domain_names = mesh()->region_db().get_and_check_operands(domain_name_array);
470  domain = mesh()->region_db().union_set(domain_names);
471 
472  } else if (actual_list_item.opt_val("rid", id)) {
473  Region region;
474  try {
475  region = mesh()->region_db().find_id(id);
476  } catch (RegionDB::ExcUniqueRegionId &e) {
477  e << actual_list_item.ei_address();
478  throw;
479  }
480  if (region.is_valid())
481  domain.push_back(region);
482  else
483  THROW(RegionDB::ExcUnknownRegion() << RegionDB::EI_ID(id) );
484  } else {
485  THROW(ExcMissingDomain()
486  << actual_list_item.ei_address() );
487  }
488 
489  // get field instance
490  for(auto rit = factories_.rbegin() ; rit != factories_.rend(); ++rit) {
491  FieldBasePtr field_instance = (*rit)->create_field(actual_list_item, *this);
492  if (field_instance) // skip descriptors without related keys
493  {
494  // add to history
495  ASSERT_EQ( field_instance->n_comp() , shared_->n_comp_);
496  field_instance->set_mesh( mesh() , is_bc() );
497  for(const Region &reg: domain) {
498  // if region history is empty, add new field
499  // or if region history is not empty and the input_time is higher, add new field
500  // otherwise (region history is not empty and the input_time is the same),
501  // rewrite the region field
502  if( data_->region_history_[reg.idx()].size() == 0
503  || data_->region_history_[reg.idx()].back().first < input_time)
504  {
505  data_->region_history_[reg.idx()].push_front(
506  HistoryPoint(input_time, field_instance));
507  //DebugOut() << "Update history" << print_var(this->name()) << print_var(reg.label()) << print_var(input_time);
508  }
509  else
510  {
511  data_->region_history_[reg.idx()].back() =
512  HistoryPoint(input_time, field_instance);
513  }
514  }
515  break;
516  }
517  }
518 
519  ++shared_->list_idx_;
520  }
521  }
522 }
523 
524 template<int spacedim, class Value>
526  ASSERT_PTR(mesh()).error("Null mesh pointer.");
527  //if (shared_->is_fully_initialized_) return;
528 
529  // check there are no empty field pointers, collect regions to be initialized from default value
530  RegionSet regions_to_init; // empty vector
531 
532  for(const Region &reg : mesh()->region_db().get_region_set("ALL") )
533  if (reg.is_boundary() == is_bc()) { // for regions that match type of the field domain
534  RegionHistory &rh = data_->region_history_[reg.idx()];
535  if ( rh.empty() || ! rh[0].second) // empty region history
536  {
537  // test if check is turned on and control field is FieldConst
538  if (no_check_control_field_ && no_check_control_field_->is_constant(reg) ) {
539  // get constant enum value
540  auto elm = ElementAccessor<spacedim>(mesh(), reg);
541  FieldEnum value = no_check_control_field_->value(elm.centre(),elm);
542  // check that the value is in the disable list
543  if ( std::find(shared_->no_check_values_.begin(), shared_->no_check_values_.end(), value)
544  != shared_->no_check_values_.end() )
545  continue; // the field is not needed on this region
546  }
547  if (shared_->input_default_ != "") { // try to use default
548  regions_to_init.push_back( reg );
549  } else {
550  THROW( ExcMissingFieldValue() << EI_FieldInputName(input_name()) << EI_FieldName(name())
551  << EI_RegId(reg.id()) << EI_RegLabel(reg.label()) );
552  }
553  }
554  }
555 
556  // possibly set from default value
557  if ( regions_to_init.size() ) {
558  std::string region_list;
559  // has to deal with fact that reader can not deal with input consisting of simple values
560  string default_input=input_default();
561  auto input_type = get_input_type().make_instance().first;
562  Input::ReaderToStorage reader( default_input, *input_type, Input::FileFormat::format_JSON );
563 
564  auto a_rec = reader.get_root_interface<Input::AbstractRecord>();
565  FieldAlgoBaseInitData init_data(input_name(), n_comp(), units(), limits(), flags());
566  auto field_ptr = FieldBaseType::function_factory( a_rec , init_data );
567  field_ptr->set_mesh( mesh(), is_bc() );
568  for(const Region &reg: regions_to_init) {
569  data_->region_history_[reg.idx()]
570  .push_front(HistoryPoint( 0.0, field_ptr) );
571  region_list+=" "+reg.label();
572  }
573  FieldCommon::messages_data_.push_back( MessageData(input_default(), name(), region_list) );
574 
575  }
576  //shared_->is_fully_initialized_ = true;
577 }
578 
579 
580 template<int spacedim, class Value>
581 void Field<spacedim,Value>::add_factory(const std::shared_ptr<FactoryBase> factory) {
582  factories_.push_back( factory );
583 }
584 
585 
586 template<int spacedim, class Value>
588  Input::AbstractRecord field_record;
589  if (rec.opt_val(field.input_name(), field_record)) {
590  FieldAlgoBaseInitData init_data(field.input_name(), field.n_comp(), field.units(), field.limits(), field.get_flags());
591  return FieldBaseType::function_factory(field_record, init_data );
592  }
593  else
594  return FieldBasePtr();
595 }
596 
597 
598 template<int spacedim, class Value>
600  return in_rec.find<Input::AbstractRecord>(input_name);
601 }
602 
603 
604 
605 
606 template<int spacedim, class Value>
608  if (! flags().match(FieldFlag::declare_input)) return;
609 
610  // check that times forms ascending sequence
611  double time,last_time=0.0;
612 
614  it != list.end();
615  ++it) {
616  for(auto rit = factories_.rbegin() ; rit != factories_.rend(); ++rit) {
617  if ( (*rit)->is_active_field_descriptor( (*it), this->input_name() ) ) {
618  shared_->input_list_.push_back( Input::Record( *it ) );
619  time = tg.read_time( it->find<Input::Tuple>("time") );
620  if (time < last_time) {
621  THROW( ExcNonascendingTime()
622  << EI_Time(time)
623  << EI_Field(input_name())
624  << it->ei_address());
625  }
626  last_time = time;
627 
628  break;
629  }
630  }
631  }
632 
633 }
634 
635 
636 
637 template<int spacedim, class Value>
638 void Field<spacedim,Value>::set_output_data_cache(OutputTime::DiscreteSpace space_type, std::shared_ptr<OutputTime> stream) {
639  typedef typename Value::element_type ElemType;
640 
641  auto output_cache_base = stream->prepare_compute_data<ElemType>(this->name(), space_type,
642  (unsigned int)Value::NRows_, (unsigned int)Value::NCols_);
643  output_data_cache_ = std::dynamic_pointer_cast<ElementDataCache<ElemType>>(output_cache_base);
644 }
645 
646 
647 template<int spacedim, class Value>
648 void Field<spacedim,Value>::compute_field_data(OutputTime::DiscreteSpace space_type, std::shared_ptr<OutputTime> stream) {
649  std::shared_ptr<OutputMeshBase> output_mesh = stream->get_output_mesh_ptr();
650  ASSERT(output_mesh);
651 
653 
654  /* Copy data to array */
655  std::shared_ptr< FieldFE<spacedim, Value> > field_fe_ptr = this->get_field_fe();
656 
657  if (field_fe_ptr) {
658  auto native_output_data_base = stream->prepare_compute_data<double>(this->name(), space_type,
659  (unsigned int)Value::NRows_, (unsigned int)Value::NCols_,
660  typeid(field_fe_ptr->get_dofhandler()->ds()->fe()[0_d].get()).name(), // should be used better solution of fe_type setting
661  // e.g. method 'name()' of FiniteElement and descendants
662  field_fe_ptr->get_dofhandler()->max_elem_dofs());
663  // try casting actual ElementDataCache
664  auto native_output_data = std::dynamic_pointer_cast<ElementDataCache<double>>(native_output_data_base);
665  field_fe_ptr->native_data_to_cache(*native_output_data);
666  } else {
667  WarningOut().fmt("Field '{}' of native data space type is not of type FieldFE. Output will be skipped.\n", this->name());
668  }
669 
670  /* Set the last time */
671  stream->update_time(this->time());
672 
673 }
674 
675 
676 template<int spacedim, class Value>
678 {
679  for (unsigned int i=0; i<offsets.size(); ++i) {
680  if (offsets[i] == -1) continue; // skip empty value
681  auto ret_value = Value::get_from_array(this->value_cache_, i);
682  const Value &ele_value = Value( ret_value );
683  output_data_cache_->store_value(offsets[i], ele_value.mem_ptr() );
684  }
685 }
686 
687 
688 template<int spacedim, class Value>
689 std::shared_ptr< FieldFE<spacedim, Value> > Field<spacedim,Value>::get_field_fe() {
690  ASSERT_EQ_DBG(this->mesh()->region_db().size(), region_fields_.size()).error();
691  ASSERT(!this->shared_->bc_).error("FieldFE output of native data is supported only for bulk fields!");
692 
693  std::shared_ptr< FieldFE<spacedim, Value> > field_fe_ptr;
694 
695  bool is_fe = (region_fields_.size()>0); // indicate if FieldFE is defined on all bulk regions
696  is_fe = is_fe && region_fields_[1] && (typeid(*region_fields_[1]) == typeid(FieldFE<spacedim, Value>));
697  for (unsigned int i=3; i<2*this->mesh()->region_db().bulk_size(); i+=2)
698  if (!region_fields_[i] || (region_fields_[i] != region_fields_[1])) {
699  is_fe = false;
700  break;
701  }
702  if (is_fe) {
703  field_fe_ptr = std::dynamic_pointer_cast< FieldFE<spacedim, Value> >( region_fields_[1] );
704  }
705 
706  return field_fe_ptr;
707 }
708 
709 
710 template<int spacedim, class Value>
711 void Field<spacedim, Value>::cache_reallocate(const ElementCacheMap &cache_map, unsigned int region_idx) const {
712  // Call cache_reinit of FieldAlgoBase descendant on appropriate region
713  if (region_fields_[region_idx] != nullptr)
714  region_fields_[region_idx]->cache_reinit(cache_map);
715 }
716 
717 
718 template<int spacedim, class Value>
719 void Field<spacedim, Value>::cache_update(ElementCacheMap &cache_map, unsigned int region_patch_idx) const {
720  unsigned int region_idx = cache_map.region_idx_from_chunk_position(region_patch_idx);
721  if (region_fields_[region_idx] != nullptr) // skips bounadry regions for bulk fields and vice versa
722  region_fields_[region_idx]->cache_update(value_cache_, cache_map, region_patch_idx);
723 }
724 
725 
726 template<int spacedim, class Value>
728  if (region_fields_[i_reg] != nullptr) return region_fields_[i_reg]->set_dependency(field_set);
729  else return std::vector<const FieldCommon *>();
730 }
731 
732 
733 template<int spacedim, class Value>
735  return &value_cache_;
736 }
737 
738 
739 template<>
741  return nullptr;
742 }
743 
744 template<>
746  return nullptr;
747 }
748 
749 
750 template<int spacedim, class Value>
752  return &value_cache_;
753 }
754 
755 
756 template<>
758  return nullptr;
759 }
760 
761 template<>
763  return nullptr;
764 }
765 
766 
767 
768 
769 #endif /* FIELD_IMPL_HH_ */
FieldCommon::units
FieldCommon & units(const UnitSI &units)
Set basic units of the field.
Definition: field_common.hh:152
result_none
@ result_none
Definition: field_algo_base.hh:71
LimitSide::right
@ right
FieldCommon::shared_
std::shared_ptr< SharedData > shared_
Definition: field_common.hh:656
BulkPoint::elem_patch_idx
unsigned int elem_patch_idx() const
Definition: eval_subset.hh:79
Field::cache_reallocate
void cache_reallocate(const ElementCacheMap &cache_map, unsigned int region_idx) const override
Implements FieldCommon::cache_allocate.
Definition: field.impl.hh:711
CacheMapElementNumber::get
static unsigned int get()
Return number of stored elements.
Definition: field_value_cache.hh:93
reader_to_storage.hh
FieldCommon::last_limit_side_
LimitSide last_limit_side_
Definition: field_common.hh:679
Field::value_cache
FieldValueCache< double > * value_cache() override
Implements FieldCommon::value_cache.
Definition: field.impl.hh:734
eval_subset.hh
BulkPoint::elm_cache_map
const ElementCacheMap * elm_cache_map() const
Definition: eval_subset.hh:73
Field::fill_data_value
void fill_data_value(const std::vector< int > &offsets) override
Implements FieldCommon::fill_data_value.
Definition: field.impl.hh:677
Input::ReaderToStorage
Reader for (slightly) modified input files.
Definition: reader_to_storage.hh:96
Field::compute_field_data
void compute_field_data(OutputTime::DiscreteSpace space_type, std::shared_ptr< OutputTime > stream)
Definition: field.impl.hh:648
Field< spacedim, FieldValue< 3 >::TensorFixed >::HistoryPoint
pair< double, FieldBasePtr > HistoryPoint
Pair: time, pointer to FieldBase instance.
Definition: field.hh:381
FieldCommon::last_time_
double last_time_
Definition: field_common.hh:678
Field::set_time
bool set_time(const TimeStep &time, LimitSide limit_side) override
Definition: field.impl.hh:286
MeshBase::region_db
const RegionDB & region_db() const
Definition: mesh.h:171
FieldCommon::flags
FieldFlag::Flags & flags()
Definition: field_common.hh:289
Field::value_cache_
FieldValueCache< typename Value::element_type > value_cache_
Definition: field.hh:423
ElementDataCache
Definition: element_data_cache.hh:44
ASSERT
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
Definition: asserts.hh:347
FieldCommon::set_shape
void set_shape(uint n_rows, uint n_cols)
Definition: field_common.hh:556
FieldCommon::messages_data_
static std::vector< MessageData > messages_data_
Vector of data of initialization messages.
Definition: field_common.hh:712
Field::check_initialized_region_fields_
void check_initialized_region_fields_()
Definition: field.impl.hh:525
FieldCommon::set_component_index
void set_component_index(unsigned int idx)
Definition: field_common.hh:457
Input::Type::Integer
Class for declaration of the integral input data.
Definition: type_base.hh:483
Field::Field
Field()
Definition: field.impl.hh:41
Field::set_dependency
std::vector< const FieldCommon * > set_dependency(FieldSet &field_set, unsigned int i_reg) const override
Definition: field.impl.hh:727
ElementCacheMap
Directing class of FieldValueCache.
Definition: field_value_cache.hh:151
FieldEnum
unsigned int FieldEnum
Definition: field_values.hh:56
eval_points.hh
value
static constexpr bool value
Definition: json.hpp:87
Field::observe_output
void observe_output(std::shared_ptr< Observe > observe) override
Definition: field.impl.hh:392
ElementDataCacheBase::n_comp
unsigned int n_comp() const
Definition: element_data_cache_base.hh:145
RegionIdx::is_valid
bool is_valid() const
Returns false if the region has undefined/invalid value.
Definition: region.hh:78
FieldResult
FieldResult
Definition: field_algo_base.hh:70
field_set.hh
FieldCommon::mesh
const Mesh * mesh() const
Definition: field_common.hh:286
BulkPoint
Base point accessor class.
Definition: eval_subset.hh:55
Field::output_data_cache_
std::shared_ptr< ElementDataCache< typename Value::element_type > > output_data_cache_
ElementDataCache used during field output, object is shared with OutputTime.
Definition: field.hh:426
result_other
@ result_other
Definition: field_algo_base.hh:72
THROW
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
Definition: exceptions.hh:53
std::vector< FieldEnum >
ElementAccessor
Definition: dh_cell_accessor.hh:32
TimeStep::gt
bool gt(double other_time) const
Definition: time_governor.hh:167
ASSERT_EQ_DBG
#define ASSERT_EQ_DBG(a, b)
Definition of comparative assert macro (EQual) only for debug mode.
Definition: asserts.hh:332
SidePoint
General point a+ side_begin_ + ccessor allow iterate over quadrature points of given side defined in ...
Definition: eval_subset.hh:116
Field::get_input_type
IT::Instance get_input_type() override
Definition: field.impl.hh:178
field_fe.hh
RegionIdx::idx
unsigned int idx() const
Returns a global index of the region.
Definition: region.hh:82
Field::get_field_fe
std::shared_ptr< FieldFE< spacedim, Value > > get_field_fe()
Definition: field.impl.hh:689
TimeStep::read_time
double read_time(Input::Iterator< Input::Tuple > time_it, double default_time=std::numeric_limits< double >::quiet_NaN()) const
Definition: time_governor.cc:259
fmt::format
std::string format(CStringRef format_str, ArgList args)
Definition: format.h:3141
Field::get_value_attribute
std::string get_value_attribute() const override
Definition: field.impl.hh:440
Field::cache_update
void cache_update(ElementCacheMap &cache_map, unsigned int region_patch_idx) const override
Implements FieldCommon::cache_update.
Definition: field.impl.hh:719
ASSERT_LT
#define ASSERT_LT(a, b)
Definition of comparative assert macro (Less Than)
Definition: asserts.hh:296
result_constant
@ result_constant
Definition: field_algo_base.hh:73
FieldCommon::shape_
std::vector< uint > shape_
Definition: field_common.hh:531
Region
Definition: region.hh:146
Input::Iterator
Definition: accessors.hh:143
SidePoint::eval_point_idx
unsigned int eval_point_idx() const
Return index in EvalPoints object.
Definition: eval_subset.hh:135
Field::update_history
void update_history(const TimeStep &time)
Definition: field.impl.hh:454
TimeStep::end
double end() const
Definition: time_governor.hh:161
ObservePointAccessor
Point accessor allow iterate over local Observe points.
Definition: observe.hh:325
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
FieldCommon::multifield_
bool multifield_
Definition: field_common.hh:701
RegionDB::bulk_size
unsigned int bulk_size() const
Definition: region.cc:268
FieldAlgoBaseInitData
Helper struct stores data for initizalize descentants of FieldAlgorithmBase.
Definition: field_algo_base.hh:81
Field::operator[]
Value::return_type operator[](unsigned int i_cache_point) const
Return item of value_cache_ given by i_cache_point.
Definition: field.impl.hh:170
accessors.hh
Field::set
void set(FieldBasePtr field, double time, std::vector< std::string > region_set_names={"ALL"})
Definition: field.impl.hh:244
TimeStep
Representation of one time step..
Definition: time_governor.hh:123
TimeGovernor
Basic time management functionality for unsteady (and steady) solvers (class Equation).
Definition: time_governor.hh:310
Field::field_result
FieldResult field_result(RegionSet region_set) const override
Indicates special field states.
Definition: field.impl.hh:417
Input::AbstractRecord
Accessor to the polymorphic input data of a type given by an AbstracRecord object.
Definition: accessors.hh:458
FieldCommon
Common abstract parent of all Field<...> classes.
Definition: field_common.hh:76
Field::data_
std::shared_ptr< SharedData > data_
Definition: field.hh:395
Input::Record::ei_address
EI_Address ei_address() const
Definition: accessors.cc:178
Field::field_output
void field_output(std::shared_ptr< OutputTime > stream, OutputTime::DiscreteSpace type) override
Definition: field.impl.hh:381
ASSERT_EQ
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual)
Definition: asserts.hh:328
Field::factories_
std::vector< std::shared_ptr< FactoryBase > > factories_
Definition: field.hh:412
Input::Record::opt_val
bool opt_val(const string &key, Ret &value) const
Definition: accessors_impl.hh:107
Input::format_JSON
@ format_JSON
Definition: reader_to_storage.hh:60
Input::Type::Instance
Helper class that stores data of generic types.
Definition: type_generic.hh:89
Input::ReaderToStorage::get_root_interface
T get_root_interface() const
Returns the root accessor.
Definition: reader_to_storage.cc:150
LimitSide
LimitSide
Definition: field_common.hh:63
Field::get_multifield_input_type
IT::Array get_multifield_input_type() override
Definition: field.impl.hh:185
Field::region_fields_
std::vector< FieldBasePtr > region_fields_
Definition: field.hh:410
FieldSet
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:159
BulkPoint::eval_point_idx
unsigned int eval_point_idx() const
Return index in EvalPoints object.
Definition: eval_subset.hh:84
field_algo_base.impl.hh
Field< spacedim, FieldValue< 3 >::TensorFixed >::RegionHistory
boost::circular_buffer< HistoryPoint > RegionHistory
Nearest history of one region.
Definition: field.hh:383
Input::Record::find
Iterator< Ret > find(const string &key) const
Definition: accessors_impl.hh:91
FieldValue_
Definition: field_values.hh:248
Field::add_factory
void add_factory(std::shared_ptr< FactoryBase > factory)
Definition: field.impl.hh:581
Input::Type
Definition: balance.hh:41
Value
@ Value
Definition: finite_element.hh:43
observe.hh
Field< spacedim, FieldValue< 3 >::TensorFixed >::FieldBasePtr
std::shared_ptr< FieldBaseType > FieldBasePtr
Definition: field.hh:97
FieldFE
Definition: field.hh:61
Mesh
Definition: mesh.h:355
Field::no_check_control_field_
std::shared_ptr< ControlField > no_check_control_field_
Definition: field.hh:405
TimeGovernor::read_time
double read_time(Input::Iterator< Input::Tuple > time_it, double default_time=std::numeric_limits< double >::quiet_NaN()) const
Definition: time_governor.cc:790
Input::Type::Array
Class for declaration of inputs sequences.
Definition: type_base.hh:339
Field::set_mesh
void set_mesh(const Mesh &mesh) override
Definition: field.impl.hh:205
ElementCacheMap::region_idx_from_chunk_position
unsigned int region_idx_from_chunk_position(unsigned int chunk_pos) const
Return begin position of region chunk specified by position in map.
Definition: field_value_cache.hh:269
Input::Array
Accessor to input data conforming to declared Array.
Definition: accessors.hh:566
WarningOut
#define WarningOut()
Macro defining 'warning' record of log.
Definition: logger.hh:278
Input::Tuple
Accessor to the data with type Type::Tuple.
Definition: accessors.hh:411
std
Definition: doxy_dummy_defs.hh:5
field_value_cache.hh
FieldFlag::equation_input
static constexpr Mask equation_input
The field is data parameter of the owning equation. (default on)
Definition: field_flag.hh:33
FieldCommon::get_flags
FieldFlag::Flags get_flags() const
Definition: field_common.hh:292
output_mesh.hh
Classes for auxiliary output mesh.
Field::FactoryBase::is_active_field_descriptor
virtual bool is_active_field_descriptor(const Input::Record &in_rec, const std::string &input_name)
Definition: field.impl.hh:599
region.hh
Armor::Array
Definition: armor.hh:597
FieldFlag::declare_input
static constexpr Mask declare_input
The field can be set from input. The key in input field descriptor is declared. (default on)
Definition: field_flag.hh:35
FieldCommon::SharedData
Definition: field_common.hh:570
Field::set_input_list
void set_input_list(const Input::Array &list, const TimeGovernor &tg) override
Definition: field.impl.hh:607
FieldCommon::name
const std::string & name() const
Definition: field_common.hh:245
FieldCommon::n_comp
unsigned int n_comp() const
Definition: field_common.hh:271
Field::is_constant
bool is_constant(Region reg) override
Definition: field.impl.hh:235
OutputTime::DiscreteSpace
DiscreteSpace
Definition: output_time.hh:108
FieldCommon::is_jump_time_
bool is_jump_time_
Definition: field_common.hh:685
FieldCommon::input_name
const std::string & input_name() const
Definition: field_common.hh:242
FieldCommon::limits
std::pair< double, double > limits() const
Definition: field_common.hh:260
Field
Class template representing a field with values dependent on: point, element, and region.
Definition: field.hh:93
std::list
Definition: doxy_dummy_defs.hh:9
TimeStep::ge
bool ge(double other_time) const
Definition: time_governor.hh:173
Field::disable_where
auto disable_where(const Field< spacedim, typename FieldValue< spacedim >::Enum > &control_field, const vector< FieldEnum > &value_list) -> Field &
Definition: field.impl.hh:195
ASSERT_PTR
#define ASSERT_PTR(ptr)
Definition of assert macro checking non-null pointer (PTR)
Definition: asserts.hh:336
Field::FactoryBase::create_field
virtual FieldBasePtr create_field(Input::Record rec, const FieldCommon &field)
Definition: field.impl.hh:587
OutputTime::N_DISCRETE_SPACES
static const unsigned int N_DISCRETE_SPACES
Definition: output_time.hh:107
output_element.hh
Class OutputElement and its iterator OutputElementIterator on the output mesh.
Field::operator()
Value::return_type operator()(BulkPoint &p)
Return appropriate value to BulkPoint in FieldValueCache.
Definition: field.impl.hh:155
Field::copy_from
void copy_from(const FieldCommon &other) override
Definition: field.impl.hh:364
FieldCommon::time
double time() const
Definition: field_common.hh:299
ElementCacheMap::get_value
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...
Definition: field_value_cache.hh:280
ElementDataCache::store_value
void store_value(unsigned int idx, const T *value)
Definition: element_data_cache.cc:222
Field::set_output_data_cache
void set_output_data_cache(OutputTime::DiscreteSpace space_type, std::shared_ptr< OutputTime > stream) override
Definition: field.impl.hh:638
FieldAlgorithmBase::function_factory
static std::shared_ptr< FieldAlgorithmBase< spacedim, Value > > function_factory(const Input::AbstractRecord &rec, const struct FieldAlgoBaseInitData &init_data)
Definition: field_algo_base.impl.hh:101
field.hh
FieldCommon::MessageData
Store data of one initialization message.
Definition: field_common.hh:98
FieldCommon::set_time_result_
TimeStatus set_time_result_
Definition: field_common.hh:672
FieldCommon::name_
std::string name_
Definition: field_common.hh:651
OutputTime::NATIVE_DATA
@ NATIVE_DATA
Definition: output_time.hh:112
FieldCommon::component_index_
unsigned int component_index_
Definition: field_common.hh:695
FieldCommon::name
FieldCommon & name(const string &name)
Definition: field_common.hh:120
Field::operator=
Field & operator=(const Field &other)
Definition: field.impl.hh:119