Flow123d  master-3768d5dec
field_common.cc
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_common.cc
15  * @brief
16  */
17 
18 #include <iomanip> // for operator<<, setw, setfill, left
19 #include "fields/field_common.hh"
20 #include "input/accessors_impl.hh" // for Record::val
21 #include "input/attribute_lib.hh" // for Attribute
22 #include "input/storage.hh" // for ExcStorageTypeMismatch
23 #include "tools/time_marks.hh" // for TimeMark, TimeMark::Type, TimeMarks
24 
25 
26 /****************************************************************************
27  * Implementation of FieldCommon
28  */
29 
30 
32 : shared_( std::make_shared<SharedData>() ),
33  set_time_result_(TimeStatus::unknown),
34  is_jump_time_(true),
35  component_index_(std::numeric_limits<unsigned int>::max())
36 {
37  shared_->bc_=false;
38  shared_->input_default_="";
39  shared_->n_comp_ = 0;
40  shared_->mesh_ = nullptr;
41  shared_->is_fully_initialized_=false;
42 }
43 
44 
45 
47 : name_(other.name_),
48  shared_(other.shared_),
49  set_time_result_(other.set_time_result_),
50  last_time_(other.last_time_),
51  last_limit_side_(other.last_limit_side_),
52  is_jump_time_(other.is_jump_time_),
53  component_index_(other.component_index_)
54 {
56 }
57 
58 
59 
61  return IT::Record(record_name, field_descriptor_record_description(record_name))
62  .declare_key("region", IT::Array( IT::String(), 1 ), "Labels of the regions where to set fields. ")
63  .declare_key("rid", IT::Integer(0), "ID of the region where to set fields.",
65  "\"Specification of the region by its ID is obsolete, will be removed in release 3.0.\\n"
66  "Use region label declared in the Mesh record or default label 'region_<ID>'.\""} })
67  .declare_key("time", TimeGovernor::get_input_time_type(), IT::Default("0.0"),
68  "Apply field setting in this record after this time.\n"
69  "These times have to form an increasing sequence.")
70  .close();
71 }
72 
73 const std::string FieldCommon::field_descriptor_record_description(const string& record_name) {
74  return "Record to set fields of the equation.\n"
75  "The fields are set only on the domain specified by one of the keys: 'region', 'rid'\n"
76  "and after the time given by the key 'time'. The field setting can be overridden by\n"
77  " any " + record_name + " record that comes later in the boundary data array.";
78 }
79 
80 
81 
83  if (! flags().match(FieldFlag::declare_input)) return;
84 
85  // pass through field descriptors containing key matching field name.
87  double time;
88  for( auto &item : shared_->input_list_) {
89  time = tg.read_time( item.find<Input::Tuple>("time") ); // default time=0
90  TimeGovernor::marks().add( TimeMark(time, mark_type | TimeGovernor::marks().type_input() ));
91  }
92 }
93 
94 
95 
96 bool FieldCommon::print_message_table(ostream& stream, std::string equation_name) {
97  if (FieldCommon::messages_data_.size() == 0) return false;
98 
99  stream << endl << "Used default values of Fields for equation " << equation_name << ":" << endl;
100  stream << std::setfill('-') << setw(100) << "" << endl;
101  stream << std::setfill(' ') << " Field name" << setw(21) << "" << "Default value" << setw(7) << "" << "Apply on regions" << endl;
103  stringstream ss;
104  stream << " " << std::left << setw(30) << it->field_name_ << "" << " "
105  << setw(18) << it->default_value_ << "" << " " << it->region_list_ << endl;
106  }
107  stream << std::setfill('-') << setw(100) << "" << endl << endl;
108 
110  return true;
111 }
112 
113 
114 
116 
117 
118 
FieldCommon::shared_
std::shared_ptr< SharedData > shared_
Definition: field_common.hh:657
FieldCommon::flags
FieldFlag::Flags & flags()
Definition: field_common.hh:289
FieldCommon::messages_data_
static std::vector< MessageData > messages_data_
Vector of data of initialization messages.
Definition: field_common.hh:714
TimeGovernor::equation_fixed_mark_type
TimeMark::Type equation_fixed_mark_type() const
Definition: time_governor.hh:481
Input::Type::Integer
Class for declaration of the integral input data.
Definition: type_base.hh:483
FieldCommon::TimeStatus
TimeStatus
Definition: field_common.hh:662
std::vector
Definition: doxy_dummy_defs.hh:7
FieldCommon::flags_
FieldFlag::Flags flags_
Field flags. Default setting is "an equation input field, that can read from user input,...
Definition: field_common.hh:711
FieldCommon::FieldCommon
FieldCommon()
Definition: field_common.cc:31
storage.hh
FieldCommon::field_descriptor_record
static IT::Record field_descriptor_record(const string &record_name)
Definition: field_common.cc:60
Input::Type::Default
Class Input::Type::Default specifies default value of keys of a Input::Type::Record.
Definition: type_record.hh:61
TimeMark
Class used for marking specified times at which some events occur.
Definition: time_marks.hh:45
attribute_lib.hh
TimeGovernor
Basic time management functionality for unsteady (and steady) solvers (class Equation).
Definition: time_governor.hh:317
TimeMark::Type
Definition: time_marks.hh:60
FieldCommon
Common abstract parent of all Field<...> classes.
Definition: field_common.hh:76
FieldCommon::print_message_table
static bool print_message_table(ostream &stream, std::string equation_name)
Definition: field_common.cc:96
FieldCommon::field_descriptor_record_description
static const std::string field_descriptor_record_description(const string &record_name)
Definition: field_common.cc:73
Input::Type::Record::declare_key
Record & declare_key(const string &key, std::shared_ptr< TypeBase > type, const Default &default_value, const string &description, TypeBase::attribute_map key_attributes=TypeBase::attribute_map())
Declares a new key of the Record.
Definition: type_record.cc:503
TimeMarks::add
TimeMark add(const TimeMark &mark)
Definition: time_marks.cc:81
FieldCommon::~FieldCommon
virtual ~FieldCommon()
Definition: field_common.cc:119
FieldFlag::input_copy
static constexpr Mask input_copy
Definition: field_flag.hh:44
Input::Type
Definition: balance.hh:41
Input::Type::Record
Record type proxy class.
Definition: type_record.hh:182
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:793
Input::Type::Array
Class for declaration of inputs sequences.
Definition: type_base.hh:339
accessors_impl.hh
TimeGovernor::marks
static TimeMarks & marks()
Definition: time_governor.hh:338
Input::Type::String
Class for declaration of the input data that are in string format.
Definition: type_base.hh:582
Input::Tuple
Accessor to the data with type Type::Tuple.
Definition: accessors.hh:411
std
Definition: doxy_dummy_defs.hh:5
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:571
TimeGovernor::get_input_time_type
static const Input::Type::Tuple & get_input_time_type(double lower_bound=-std::numeric_limits< double >::max(), double upper_bound=std::numeric_limits< double >::max())
Definition: time_governor.cc:47
time_marks.hh
FieldCommon::mark_input_times
void mark_input_times(const TimeGovernor &tg)
Definition: field_common.cc:82
FlagArray::add
FlagArray & add(Mask mask)
Definition: flag_array.hh:170
Input::Type::Attribute::obsolete
static string obsolete()
Definition: attribute_lib.hh:72
FieldCommon::time
double time() const
Definition: field_common.hh:299
field_common.hh