Chi-Tech
fieldfunction.cc
Go to the documentation of this file.
1#include "fieldfunction.h"
2
4
5namespace chi_physics
6{
7
8// ##################################################################
9/**Returns required input parameters.*/
11{
13
14 params.AddRequiredParameter<std::string>(
15 "name", "Named to be associated with this field function");
16
18 "unknown_type",
19 "Scalar",
20 "The type of the variable for this field function");
21
23 "num_components",
24 1,
25 "The number of components to attach to the variable. "
26 "Only effective when \"type\" is VectorN.");
27
28 //=============== Constrain values
29 using namespace chi_data_types;
31 "unknown_type",
32 AllowableRangeList::New({"Scalar", "Vector2", "Vector3", "VectorN"}));
33
34 params.ConstrainParameterRange("num_components",
35 AllowableRangeLowLimit::New(1));
36
37 return params;
38}
39
40// ##################################################################
41/**ObjectMaker based constructor.*/
43 : ChiObject(params),
44 text_name_(params.GetParamValue<std::string>("name")),
45 unknown_((params.GetParamValue<std::string>("unknown_type") == "Scalar")
46 ? chi_math::Unknown(chi_math::UnknownType::SCALAR)
47 : (params.GetParamValue<std::string>("unknown_type") == "Vector2")
48 ? chi_math::Unknown(chi_math::UnknownType::VECTOR_2)
49 : (params.GetParamValue<std::string>("unknown_type") == "Vector3")
50 ? chi_math::Unknown(chi_math::UnknownType::VECTOR_2)
51 : (params.GetParamValue<std::string>("unknown_type") == "VectorN")
52 ? chi_math::Unknown(
53 chi_math::UnknownType::VECTOR_N,
54 params.GetParamValue<unsigned int>("num_components"))
55 : chi_math::Unknown(chi_math::UnknownType::SCALAR)),
56 unknown_manager_({unknown_})
57{
58}
59
60// ##################################################################
61/**Conventional constructor.*/
62FieldFunction::FieldFunction(const std::string& text_name,
63 chi_math::Unknown unknown)
64 : text_name_(text_name),
65 unknown_(std::move(unknown)),
66 unknown_manager_({unknown_})
67{
68}
69
70// ##################################################################
71/**Stack change to `chi::field_function_stack.*/
72void FieldFunction::PushOntoStack(std::shared_ptr<ChiObject>& new_object)
73{
74 auto ff_ptr = std::dynamic_pointer_cast<FieldFunction>(new_object);
75
76 ChiLogicalErrorIf(not ff_ptr,
77 "Bad trouble when casting object to field function");
78
79 Chi::field_function_stack.push_back(ff_ptr);
80 new_object->SetStackID(Chi::field_function_stack.size() - 1);
81}
82
83} // namespace chi_physics
#define ChiLogicalErrorIf(condition, message)
static std::vector< chi_physics::FieldFunctionPtr > field_function_stack
Definition: chi_runtime.h:92
static chi::InputParameters GetInputParameters()
Definition: ChiObject.cc:4
void AddRequiredParameter(const std::string &name, const std::string &doc_string)
void ConstrainParameterRange(const std::string &param_name, AllowableRangePtr allowable_range)
void AddOptionalParameter(const std::string &name, T value, const std::string &doc_string)
void PushOntoStack(std::shared_ptr< ChiObject > &new_object) override
Overrides the stack placement so that FieldFunctions go to the field function stack.
static chi::InputParameters GetInputParameters()
FieldFunction(const chi::InputParameters &params)
chi_math::Unknown unknown_
Definition: fieldfunction.h:20