30#if defined(__CUDACC__)
37#include <blockforest/communication/UniformBufferedScheme.h>
38#include <domain_decomposition/BlockDataID.h>
39#include <field/AddToStorage.h>
40#include <field/GhostLayerField.h>
41#include <field/vtk/VTKWriter.h>
42#include <stencil/D3Q27.h>
43#include <waLBerlaDefinitions.h>
44#if defined(__CUDACC__)
45#include <gpu/AddGPUFieldToStorage.h>
46#include <gpu/FieldAccessor.h>
47#include <gpu/FieldIndexing.h>
48#include <gpu/GPUField.h>
49#include <gpu/HostFieldAllocator.h>
50#include <gpu/Kernel.h>
51#include <gpu/communication/UniformGPUScheme.h>
55#pragma clang diagnostic push
56#pragma clang diagnostic ignored "-Wfloat-conversion"
57#pragma clang diagnostic ignored "-Wimplicit-float-conversion"
58#elif defined(__GNUC__) or defined(__GNUG__)
59#pragma GCC diagnostic push
60#pragma GCC diagnostic ignored "-Wfloat-conversion"
64#pragma clang diagnostic pop
65#elif defined(__GNUC__) or defined(__GNUG__)
66#pragma GCC diagnostic pop
83template <
typename FloatType, lbmpy::Arch Architecture>
86 template <
typename T> FloatType FloatType_c(T t) {
87 return numeric_cast<FloatType>(t);
91 template <
typename FT, lbmpy::Arch AT = lbmpy::Arch::CPU>
struct FieldTrait {
95#if defined(__CUDACC__)
105 BlockDataID m_potential_field_id;
112#if defined(__CUDACC__)
114 m_potential_field_id = gpu::addGPUFieldToStorage<PotentialField>(
115 blocks,
"potential field", 1u, field::fzyx,
117 for (
auto &
block : *blocks) {
119 block.template getData<PotentialField>(m_potential_field_id);
125 m_potential_field_id = field::addToStorage<PotentialField>(
126 blocks,
"potential field", FloatType{0}, field::fzyx,
133 [[nodiscard]]
bool is_gpu() const noexcept
override {
138 return std::is_same_v<FloatType, double>;
142 return static_cast<std::size_t
>(m_potential_field_id);
145 [[nodiscard]] std::optional<double>
147 bool consider_ghosts =
false)
override {
153 auto const potential_field =
154 bc->block->template getData<PotentialField>(m_potential_field_id);
165 auto potential_field =
166 bc->block->template getData<PotentialField>(m_potential_field_id);
172 [[nodiscard]] std::vector<double>
175 std::vector<double> out;
177 uint_t values_size{0u};
180 if (
auto const ci =
get_interval(lattice, lower_corner, upper_corner)) {
181 out = std::vector<double>(ci->numCells());
182 for (
auto &
block : *lattice.get_blocks()) {
183 auto const block_offset = lattice.get_block_corner(
block,
true);
185 lattice, lower_corner, upper_corner, block_offset,
block)) {
186 auto const potential_field =
187 block.template getData<PotentialField>(m_potential_field_id);
189 assert(values.size() == bci->numCells());
191 values_size += bci->numCells();
193 auto kernel = [&values, &out](
unsigned const block_index,
194 unsigned const local_index,
196 out[local_index] = double_c(values[block_index]);
202 assert(values_size == ci->numCells());
209 std::vector<double>
const &
potential)
override {
211 if (
auto const ci =
get_interval(lattice, lower_corner, upper_corner)) {
212 assert(
potential.size() == ci->numCells());
213 for (
auto &
block : *lattice.get_blocks()) {
214 auto const block_offset = lattice.get_block_corner(
block,
true);
216 lattice, lower_corner, upper_corner, block_offset,
block)) {
217 auto potential_field =
218 block.template getData<PotentialField>(m_potential_field_id);
219 std::vector<FloatType> values(bci->numCells());
221 auto kernel = [&values, &
potential](
unsigned const block_index,
222 unsigned const local_index,
224 values[block_index] =
225 numeric_cast<FloatType>(
potential[local_index]);
243 for (
auto const &vtk_handle :
m_vtk_auto | std::views::values) {
244 if (vtk_handle->enabled) {
245 vtk::writeFiles(vtk_handle->ptr)();
246 vtk_handle->execution_count++;
252 template <
typename VecType, u
int_t F_SIZE_ARG,
typename OutputType>
253 class VTKWriter :
public vtk::BlockCellDataWriter<OutputType, F_SIZE_ARG> {
255 VTKWriter(ConstBlockDataID
const &block_id, std::string
const &
id,
256 FloatType unit_conversion)
257 : vtk::BlockCellDataWriter<OutputType, F_SIZE_ARG>(id),
261 void configure()
override { WALBERLA_ASSERT_NOT_NULLPTR(this->block_); }
264 cell_idx_t
const z) {
265 return (
static_cast<std::size_t
>(x) *
m_dims[2] *
m_dims[1] +
266 static_cast<std::size_t
>(y) *
m_dims[2] +
267 static_cast<std::size_t
>(z)) *
281 template <
typename OutputType =
float>
283 :
public VTKWriter<std::vector<FloatType>, 1u, OutputType> {
287 using Base::evaluate;
290 OutputType
evaluate(cell_idx_t
const x, cell_idx_t
const y,
291 cell_idx_t
const z, cell_idx_t
const)
override {
292 WALBERLA_ASSERT(!this->
m_content.empty());
301 int flag_observables)
override {
303 auto const unit_conversion = FloatType_c(units.at(
"potential"));
305 WALBERLA_ASSERT_NOT_NULLPTR(blocks);
306 auto potential_writer = make_shared<PotentialVTKWriter<float>>(
307 m_potential_field_id,
"potential", unit_conversion);
308 auto before_function = [
this, blocks, potential_writer]() {
309 for (
auto &
block : *blocks) {
310 auto *potential_field =
311 block.template getData<PotentialField>(m_potential_field_id);
312 auto const bci = potential_field->xyzSize();
313 potential_writer->set_content(
315 potential_writer->set_dims(Vector3<uint_t>(
316 uint_c(bci.xSize()), uint_c(bci.ySize()), uint_c(bci.zSize())));
319 vtk_obj.addBeforeFunction(std::move(before_function));
320 vtk_obj.addCellDataWriter(potential_writer);
Vector implementation and trait types for boost qvm interoperability.
std::map< std::string, std::shared_ptr< VTKHandle > > m_vtk_auto
VTK writers that are executed automatically.
std::unordered_map< std::string, double > units_map
auto get_ghost_layers() const
OutputType evaluate(cell_idx_t const x, cell_idx_t const y, cell_idx_t const z, cell_idx_t const) override
VTKWriter(ConstBlockDataID const &block_id, std::string const &id, FloatType unit_conversion)
void configure() override
void set_content(VecType content)
std::size_t get_first_index(cell_idx_t const x, cell_idx_t const y, cell_idx_t const z)
void set_dims(Vector3< uint_t > dims)
bool is_double_precision() const noexcept override
~PoissonSolverNone() override=default
bool is_gpu() const noexcept override
std::size_t get_potential_field_id() const noexcept override
void set_slice_potential(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner, std::vector< double > const &potential) override
std::vector< double > get_slice_potential(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const override
PoissonSolverNone(std::shared_ptr< LatticeWalberla > lattice)
void reset_charge_field() override
void integrate_vtk_writers() override
void add_charge_to_field(std::size_t id, double valency) override
FieldTrait< FloatType, Architecture >::PotentialField PotentialField
bool set_node_potential(Utils::Vector3i const &node, double potential) override
void setup_fft(bool) override
std::optional< double > get_node_potential(Utils::Vector3i const &node, bool consider_ghosts=false) override
void register_vtk_field_writers(walberla::vtk::VTKOutput &vtk_obj, LatticeModel::units_map const &units, int flag_observables) override
void ghost_communication() override
LatticeWalberla const & get_lattice() const noexcept override
static double * block(double *p, std::size_t index, std::size_t size)
void initialize(GhostLayerField< double, 1u > *scalar_field, double const &value)
void set(GhostLayerField< double, 1u > *scalar_field, double const &value, Cell const &cell)
auto get(GhostLayerField< double, 1u > const *scalar_field, Cell const &cell)
\file PackInfoPdfDoublePrecision.cpp \author pystencils
void copy_block_buffer(CellInterval const &bci, CellInterval const &ci, Utils::Vector3i const &block_offset, Utils::Vector3i const &lower_corner, auto &&kernel)
Synchronize data between a sliced block and a container.
std::optional< BlockAndCell > get_block_and_cell(::LatticeWalberla const &lattice, signed_integral_vector auto const &node, bool consider_ghost_layers)
std::optional< walberla::cell::CellInterval > get_block_interval(::LatticeWalberla const &lattice, Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner, Utils::Vector3i const &block_offset, IBlock const &block)
std::optional< walberla::cell::CellInterval > get_interval(::LatticeWalberla const &lattice, Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner)
field::GhostLayerField< FT, 1u > PotentialField