-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
field initialization refactor (#890)
- Loading branch information
Showing
3 changed files
with
41 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/core/data/field/initializers/field_user_initializer.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef _PHARE_CORE_DATA_FIELD_INITIAZILIZERS_FIELD_USER_INITIALIZER_HPP_ | ||
#define _PHARE_CORE_DATA_FIELD_INITIAZILIZERS_FIELD_USER_INITIALIZER_HPP_ | ||
|
||
#include "core/utilities/span.hpp" | ||
#include "initializer/data_provider.hpp" | ||
|
||
#include <tuple> | ||
#include <memory> | ||
|
||
namespace PHARE::core | ||
{ | ||
class FieldUserFunctionInitializer | ||
{ | ||
public: | ||
template<typename Field, typename GridLayout> | ||
void static initialize(Field& field, GridLayout const& layout, | ||
initializer::InitFunction<GridLayout::dimension> const& init) | ||
{ | ||
auto const indices = layout.ghostStartToEndIndices(field, /*includeEnd=*/true); | ||
auto const coords = layout.template indexesToCoordVectors</*WithField=*/true>( | ||
indices, field, [](auto& gridLayout, auto& field_, auto const&... args) { | ||
return gridLayout.fieldNodeCoordinates(field_, gridLayout.origin(), args...); | ||
}); | ||
|
||
std::shared_ptr<Span<double>> gridPtr // keep grid data alive | ||
= std::apply([&](auto&... args) { return init(args...); }, coords); | ||
Span<double>& grid = *gridPtr; | ||
|
||
for (std::size_t cell_idx = 0; cell_idx < indices.size(); cell_idx++) | ||
std::apply([&](auto&... args) { field(args...) = grid[cell_idx]; }, indices[cell_idx]); | ||
} | ||
}; | ||
|
||
} // namespace PHARE::core | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters