OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
operations.hpp File Reference

Functional, coordinate-space field operations (header-only) More...

#include <type_traits>
#include "openpfc/core/world.hpp"
#include "openpfc/fft.hpp"
#include "openpfc/model.hpp"
#include "openpfc/types.hpp"
Include dependency graph for operations.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename Fn >
void pfc::field::apply (RealField &field, const World &world, const FFT &fft, Fn &&fn)
 Apply a coordinate-space function over a real field (local inbox)
 
template<typename Fn >
void pfc::field::apply_with_time (RealField &field, const World &world, const FFT &fft, double t, Fn &&fn)
 Apply a space-time function over a real field (local inbox)
 
template<typename Fn >
void pfc::field::apply_inplace (RealField &field, const World &world, const FFT &fft, Fn &&fn)
 Apply a coordinate-space function in-place over a real field (local inbox)
 
template<typename Fn >
void pfc::field::apply_inplace_with_time (RealField &field, const World &world, const FFT &fft, double t, Fn &&fn)
 Apply a space-time function in-place over a real field (local inbox)
 
template<typename Fn >
void pfc::field::apply_inplace (Model &model, std::string_view field_name, Fn &&fn)
 Model overload: apply in-place to a named field.
 
template<typename Fn >
void pfc::field::apply_inplace_with_time (Model &model, std::string_view field_name, double t, Fn &&fn)
 Model overload: apply in-place with time to a named field.
 
template<typename Fn >
void pfc::field::apply (Model &model, std::string_view field_name, Fn &&fn)
 Apply a coordinate-space function to a named model field (local inbox)
 
template<typename Fn >
void pfc::field::apply_with_time (Model &model, std::string_view field_name, double t, Fn &&fn)
 Apply a space-time function to a named model field (local inbox)
 

Detailed Description

Functional, coordinate-space field operations (header-only)

This header provides zero-overhead, template-based helpers to apply user-defined functions over real-space fields using coordinate-space callbacks. It transparently respects the local MPI inbox via FFT layout and avoids boilerplate nested loops in initial/boundary conditions.

Core goals:

  • Work in coordinate space: Fn(Real3) -> double, or Fn(Real3, t)
  • Operate over the local inbox only (distributed-memory friendly)
  • Header-only, zero-cost abstractions
  • Backward compatible: usable directly with Model or raw components

Example:

using namespace pfc;
auto world = world::create(GridSize({64,64,64}));
auto decomp = decomposition::create(world, 1);
auto fft = fft::create(decomp);
std::vector<double> u(fft.size_inbox());
// Set Gaussian pulse
pfc::field::apply(u, world, fft, [](const Real3& x){
const double r2 = (x[0]*x[0]) + (x[1]*x[1]) + (x[2]*x[2]);
return std::exp(-r2/2.0);
});
Grid dimensions (number of grid points per dimension)
Definition strong_types.hpp:176
Represents the global simulation domain (the "world").
Definition world.hpp:91

Function Documentation

◆ apply() [1/2]

template<typename Fn >
void pfc::field::apply ( Model model,
std::string_view  field_name,
Fn &&  fn 
)
inline

Apply a coordinate-space function to a named model field (local inbox)

Convenience overload that retrieves field and world from model.

◆ apply() [2/2]

template<typename Fn >
void pfc::field::apply ( RealField &  field,
const World world,
const FFT fft,
Fn &&  fn 
)
inline

Apply a coordinate-space function over a real field (local inbox)

Template Parameters
FnCallable: double(const Real3&) or double(Real3)
Parameters
fieldReal-valued field storage (local inbox size)
worldGlobal domain descriptor
fftFFT object (provides local inbox extents)
fnCoordinate-space function returning new value

◆ apply_inplace()

template<typename Fn >
void pfc::field::apply_inplace ( RealField &  field,
const World world,
const FFT fft,
Fn &&  fn 
)
inline

Apply a coordinate-space function in-place over a real field (local inbox)

The callable receives both the coordinates and the current field value and must return the updated value. Returning the current value leaves the cell unchanged, enabling partial updates (e.g., boundary bands).

Template Parameters
FnCallable: double(const Real3&, double current)
Parameters
fieldReal-valued field storage (local inbox size)
worldGlobal domain descriptor
fftFFT object (provides local inbox extents)
fnCoordinate-space function returning new value given (x, current)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ apply_inplace_with_time()

template<typename Fn >
void pfc::field::apply_inplace_with_time ( RealField &  field,
const World world,
const FFT fft,
double  t,
Fn &&  fn 
)
inline

Apply a space-time function in-place over a real field (local inbox)

Template Parameters
FnCallable: double(const Real3&, double current, double t)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ apply_with_time()

template<typename Fn >
void pfc::field::apply_with_time ( RealField &  field,
const World world,
const FFT fft,
double  t,
Fn &&  fn 
)
inline

Apply a space-time function over a real field (local inbox)

Template Parameters
FnCallable: double(const Real3&, double) or double(Real3,double)
Parameters
fieldReal-valued field storage (local inbox size)
worldGlobal domain descriptor
fftFFT object (provides local inbox extents)
tSimulation time passed to the function
fnSpace-time function returning new value
Here is the call graph for this function:
Here is the caller graph for this function: