setVector

Header: "NeoN/fields/fieldFreeFunctions.hpp"

Description

The function setVector 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 NeoN::setVector(Vector<ValueType> &a, const View<const std::type_identity_t<ValueType>> b, std::pair<size_t, size_t> range = {0, 0})

Set the field with a view of values using a specific executor.

Parameters:
  • a – The field to set.

  • b – The view 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
NeoN::Executor = NeoN::GPUExecutor{};

NeoN::Vector<NeoN::scalar> fieldA(exec, 2);
NeoN::Vector<NeoN::scalar> fieldB(exec, 2, 1.0);
NeoN::Vector<NeoN::scalar> fieldC(exec, 2, 2.0);
// Note if the executor does not match the program will exit with a segfault
NeoN::setVector(field, fieldB.view());
// only set the last element of the field
NeoN::map(field, fieldC.view(), {1, 2});
// copy to host
auto hostVector = field.copyToHost();
for (auto i = 0; i < field.size(); ++i)
{
    std::cout << hostVector[i] << std::endl;
}
// prints:
// 1.0
// 2.0