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

Discrete field representation with physical coordinate mapping. More...

#include "array.hpp"
#include "constants.hpp"
#include "openpfc/core/world.hpp"
#include "utils/show.hpp"
#include <array>
#include <cmath>
#include <cstddef>
#include <functional>
#include <ostream>
Include dependency graph for discrete_field.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  pfc::DiscreteField< T, D >
 

Functions

template<typename T , size_t D>
T & pfc::interpolate (DiscreteField< T, D > &field, const std::array< double, D > &coordinates)
 
template<typename T , size_t D>
const T & pfc::interpolate (const DiscreteField< T, D > &field, const std::array< double, D > &coordinates)
 
template<typename T , size_t D, typename Function >
void pfc::apply (DiscreteField< T, D > &field, Function &&func)
 Apply function to discrete field.
 
template<typename T , size_t D>
void pfc::show (DiscreteField< T, D > &field)
 

Detailed Description

Discrete field representation with physical coordinate mapping.

This file defines the DiscreteField template class, which represents a discretized field with:

  • N-dimensional array storage (via Array<T, D>)
  • Physical coordinate system (origin, discretization, bounds)
  • Interpolation capabilities (nearest-neighbor)
  • Coordinate ↔ index transformations
  • Field operations (apply functions to all points)

DiscreteField bridges the gap between:

  • Discrete grid indices (integer coordinates)
  • Physical space coordinates (real-valued positions)

Typical usage:

// Create 3D field with 64³ points
{64, 64, 64}, // dimensions
{0, 0, 0}, // offset
{0.0, 0.0, 0.0}, // origin
{1.0, 1.0, 1.0} // discretization (spacing)
);
// Apply function to all points
field.apply([](double x, double y, double z) {
return std::sin(x) * std::cos(y);
});
// Interpolate at physical coordinates (using free function - preferred)
double value = pfc::interpolate(field, {0.5, 1.2, 0.8});
Represents the global simulation domain (the "world").
Definition world.hpp:91

This file is part of the Utilities module, providing convenient field manipulation for initial conditions, post-processing, and analysis.

See also
array.hpp for underlying storage implementation
core/world.hpp for coordinate system abstraction
initial_conditions/ for usage examples in ICs
Author
OpenPFC Contributors
Date
2025

Function Documentation

◆ apply()

template<typename T , size_t D, typename Function >
void pfc::apply ( DiscreteField< T, D > &  field,
Function &&  func 
)

Apply function to discrete field.

Parameters
fieldThe discrete field.
funcThe function to apply.