22 "Handle to the field function that should "
23 "receive the result of the operation.");
27 "Handle to the field function that should "
32 std::vector<size_t>{},
33 "List of component numbers that need to "
34 "be written to. If this parameter is supplied then"
35 "\"from_components\" also need to be specified (and vice versa) and they "
36 "need to be the same length. If neither are supplied, all components are "
41 std::vector<size_t>{},
42 "List of component numbers that need to "
43 "read from. If this parameter is supplied then"
44 "\"to_components\" also need to be specified (and vice versa) and they "
45 "need to be the same length. If neither are supplied, all components are "
56 to_field_handle_(params.GetParamValue<size_t>(
"to")),
57 from_field_handle_(params.GetParamValue<size_t>(
"from"))
64 to_ff_ = std::dynamic_pointer_cast<FieldFunctionGridBased>(to_base_ptr);
67 "\"to\" field function must be based on "
68 "FieldFunctionGridBased");
75 from_ff_ = std::dynamic_pointer_cast<FieldFunctionGridBased>(from_base_ptr);
78 "\"to\" field function must be based on "
79 "FieldFunctionGridBased");
86 if (user_supplied_params.Has(
"to_components") and
87 (not user_supplied_params.Has(
"from_components")))
89 "\"from_components\" must also be specified");
91 if (user_supplied_params.Has(
"from_components") and
92 (not user_supplied_params.Has(
"to_components")))
94 "\"to_components\" must also be specified");
96 if (user_supplied_params.Has(
"to_components") and
97 user_supplied_params.Has(
"from_components"))
100 user_supplied_params.GetParamVectorValue<
size_t>(
"to_components");
102 user_supplied_params.GetParamVectorValue<
size_t>(
"from_components");
105 "\"to_components\" and \"from_components\" must have "
106 "the same number of entries");
111 to_ff_->GetUnknownManager().GetTotalUnknownStructureSize() !=
112 from_ff_->GetUnknownManager().GetTotalUnknownStructureSize(),
113 "The number of components of the unknowns in the field functions are"
116 const size_t num_comps =
117 to_ff_->GetUnknownManager().GetTotalUnknownStructureSize();
120 for (
size_t c = 0; c < num_comps; ++c)
129 std::addressof(
from_ff_->GetSpatialDiscretization().Grid()),
130 "Currently the two field functions must operate on the "
136 typedef const int64_t cint64_t;
137 const auto& sdm =
to_ff_->GetSpatialDiscretization();
138 const auto& uk_man =
to_ff_->GetUnknownManager();
139 const auto& grid = sdm.Grid();
143 for (
const auto& cell : grid.local_cells)
145 const auto& cell_mapping = sdm.GetCellMapping(cell);
146 const size_t num_nodes = cell_mapping.NumNodes();
148 const auto nodes_xyz = cell_mapping.GetNodeLocations();
150 for (
size_t i = 0; i < num_nodes; ++i)
152 for (
size_t c = 0; c < num_comps; ++c)
157 const double value =
from_ff_->Evaluate(cell, nodes_xyz[i], cfrom);
159 cint64_t dof_map = sdm.MapDOFLocal(cell, i, uk_man, 0, cto);
161 to_ff_->FieldVector()[dof_map] = value;
#define ChiLogicalErrorIf(condition, message)
#define ChiInvalidArgumentIf(condition, message)
#define ChiInvalidArgument(message)
static std::vector< chi_physics::FieldFunctionPtr > field_function_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")
std::shared_ptr< const FieldFunctionGridBased > from_ff_
const size_t to_field_handle_
std::vector< size_t > from_components_
FieldCopyOperation(const chi::InputParameters ¶ms)
std::shared_ptr< FieldFunctionGridBased > to_ff_
std::vector< size_t > to_components_
static chi::InputParameters GetInputParameters()
const size_t from_field_handle_
static chi::InputParameters GetInputParameters()
RegisterChiObject(chi_physics::field_operations, FieldCopyOperation)