22 "result_field_handle",
23 "Handle to the field function that should "
24 "receive the result of the operation.");
28 "List of dependent field handles");
31 std::vector<unsigned int>{},
32 "The components of interest for each "
35 std::vector<unsigned int>{},
36 "The components to write into the result "
40 "Handle to a FunctionDimAToDimB derived"
51 result_field_handle_(params.GetParamValue<size_t>(
"result_field_handle")),
52 dependent_field_handles_(
53 params.GetParamVectorValue<size_t>(
"dependent_field_handles")),
54 function_handle_(params.GetParamValue<size_t>(
"function_handle"))
58 if (user_supplied_params.Has(
"dependent_component_references"))
61 user_supplied_params.GetParamVectorValue<
unsigned int>(
62 "dependent_component_references");
66 "Not each dependent field handle has an associated "
67 "reference component");
72 if (user_supplied_params.Has(
"result_component_references"))
75 user_supplied_params.GetParamVectorValue<
unsigned int>(
76 "result_component_references");
85 primary_ff_ = std::dynamic_pointer_cast<FieldFunctionGridBased>(ff_base_ptr);
88 "Primary field function must be based on "
89 "FieldFunctionGridBased");
93 auto dep_ff_base_ptr =
97 std::dynamic_pointer_cast<FieldFunctionGridBased>(dep_ff_base_ptr);
100 "Dependent field function must be based on "
101 "FieldFunctionGridBased");
106 auto function_base_obj =
110 std::dynamic_pointer_cast<chi_math::FunctionDimAToDimB>(function_base_obj);
116 std::string(
"The function will be called with "
117 "x,y,z,material_id and then each of the "
118 "dependent field function values. ") +
119 "This means the function needs to be callable"
123 "however, it only supports " +
129 std::string(
"The function will return ") +
131 " values however this operation only requires " +
139 typedef unsigned int uint;
140 typedef const int64_t cint64_t;
141 const auto& sdm =
primary_ff_->GetSpatialDiscretization();
142 const auto& uk_man =
primary_ff_->GetUnknownManager();
143 const auto& grid = sdm.Grid();
147 for (
const auto& cell : grid.local_cells)
149 const auto& cell_mapping = sdm.GetCellMapping(cell);
150 const size_t num_nodes = cell_mapping.NumNodes();
152 const auto nodes_xyz = cell_mapping.GetNodeLocations();
154 for (
size_t i = 0; i < num_nodes; ++i)
156 std::vector<double> input_params;
157 const auto& node_i_xyz = nodes_xyz[i];
158 for (
size_t d = 0; d < 3; ++d)
159 input_params.push_back(node_i_xyz[d]);
160 input_params.push_back(
static_cast<double>(cell.material_id_));
162 for (
size_t k = 0; k < num_deps; ++k)
167 input_params.push_back(value);
170 std::vector<double> output_params =
function_ptr_->Evaluate(input_params);
174 "Calling function number of output values not matching");
179 cint64_t dof_map = sdm.MapDOFLocal(cell, i, uk_man, 0, c);
181 primary_ff_->FieldVector()[dof_map] = output_params[k++];
#define ChiLogicalErrorIf(condition, message)
#define ChiInvalidArgumentIf(condition, message)
static std::vector< chi_physics::FieldFunctionPtr > field_function_stack
static std::vector< ChiObjectPtr > object_stack
static std::shared_ptr< T > & GetStackItemPtr(std::vector< std::shared_ptr< T > > &stack, const size_t handle, const std::string &calling_function_name="Unknown")
static chi::InputParameters GetInputParameters()
const std::vector< size_t > dependent_field_handles_
std::vector< unsigned int > result_component_references_
std::vector< std::shared_ptr< const FieldFunction > > dependent_ffs_
const size_t result_field_handle_
std::shared_ptr< const chi_math::FunctionDimAToDimB > function_ptr_
static chi::InputParameters GetInputParameters()
const size_t function_handle_
std::shared_ptr< FieldFunctionGridBased > primary_ff_
std::vector< unsigned int > dependent_field_ref_component_
MultiFieldOperation(const chi::InputParameters ¶ms)
RegisterChiObject(chi_physics::field_operations, FieldCopyOperation)