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

Defines the Field<T> structure and related free functions for data storage in OpenPFC. More...

#include "openpfc/core/csys.hpp"
#include "openpfc/core/types.hpp"
#include "openpfc/core/world.hpp"
#include <array>
#include <cassert>
#include <functional>
#include <vector>
Include dependency graph for field.hpp:

Go to the source code of this file.

Classes

struct  pfc::field::Field< T >
 

Typedefs

using pfc::field::World = pfc::world::World< pfc::csys::CartesianTag >
 

Functions

template<typename T >
Field< T > pfc::field::create (const World &world)
 
template<typename T >
const autopfc::field::get_data (const Field< T > &field)
 
template<typename T >
autopfc::field::get_data (Field< T > &field)
 
template<typename T >
const autopfc::field::get_world (const Field< T > &field)
 
template<typename T >
Field< T > pfc::field::create (const World &world, std::vector< T > &&data)
 
template<typename T >
Field< T > pfc::field::create (const World &world, const std::vector< T > &data)
 
template<typename T , typename Func , typename = std::enable_if_t<std::is_invocable_v<Func, Real3>>>
Field< T > pfc::field::create (const World &world, Func &&func)
 
template<typename T , typename Func >
void pfc::field::apply (Field< T > &f, Func &&func)
 
template<typename T >
auto pfc::field::indices (const Field< T > &f)
 

Detailed Description

Defines the Field<T> structure and related free functions for data storage in OpenPFC.

Fields in OpenPFC represent structured data over a local simulation domain. A Field is parameterized by the value type T, and its layout is defined by an immutable MultiIndex<3> and CoordinateSystem, both derived from the local World.

Design Principles

  • Fields are implemented as open struct Field<T> by default.
  • Members such as m_data, m_index, and m_coordsys are publicly accessible but prefixed with m_ to indicate internal use. Users may access these directly but are encouraged to prefer free functions.
  • Field size and layout are fixed upon construction and cannot be resized.
  • Element values are mutable, but the domain shape and coordinate mapping are immutable.
  • All functionality (e.g. data access, coordinate transforms, fill, copy) is provided via free functions in the pfc::field namespace.

Usage Example

auto world = get_subworld(decomposition, rank_id);
auto field = field::create<double>(world);
field::fill(field, [](double x, double y, double z) {
return std::exp(-(x*x + y*y + z*z));
});
double value = field::at(field, {i, j, k});
Real3 pos = to_physical(get_coordsys(field), {i, j, k});

Fields support scalar types like double, but also custom vector or tensor types, e.g., Vec3f32, as long as they are trivially copyable and can be stored in std::vector<T>.

This component is designed to work seamlessly with differential operators, FFTs, and models without ever exposing internal logic unnecessarily.