setField
¶
Header: "NeoFOAM/fields/fieldFreeFunctions.hpp"
Description¶
The function setField
sets the entire field with a given field or a subfield with a given field if a range is defined.
Definition¶
-
template<typename ValueType>
void NeoFOAM::setField(Field<ValueType> &a, const std::span<const std::type_identity_t<ValueType>> b, std::pair<size_t, size_t> range = {0, 0})¶ Set the field with a span of values using a specific executor.
- Parameters:
a – The field to set.
b – The span of values to set the field with.
range – The range to set the field in. If not provided, the whole field is set.
Example¶
// or any other executor CPUExecutor, SerialExecutor
NeoFOAM::Executor = NeoFOAM::GPUExecutor{};
NeoFOAM::Field<NeoFOAM::scalar> fieldA(exec, 2);
NeoFOAM::Field<NeoFOAM::scalar> fieldB(exec, 2, 1.0);
NeoFOAM::Field<NeoFOAM::scalar> fieldC(exec, 2, 2.0);
// Note if the executor does not match the program will exit with a segfault
NeoFOAM::setField(field, fieldB.span());
// only set the last element of the field
NeoFOAM::map(field, fieldC.span(), {1, 2});
// copy to host
auto hostField = field.copyToHost();
for (auto i = 0; i < field.size(); ++i)
{
std::cout << hostField[i] << std::endl;
}
// prints:
// 1.0
// 2.0