OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
pfc::DiscreteField< T, D > Class Template Reference

Public Types

using FunctionND = std::function< T(std::array< double, D >)>
 
using Function1D = std::function< T(double)>
 
using Function2D = std::function< T(double, double)>
 
using Function3D = std::function< T(double, double, double)>
 

Public Member Functions

 DiscreteField (const std::array< int, D > &dimensions, const std::array< int, D > &offsets, const std::array< double, D > &origin, const std::array< double, D > &discretization)
 
const std::array< double, D > & get_origin () const
 Constructs a DiscreteField from an Decomposition object.
 
const std::array< double, D > & get_discretization () const
 
const std::array< double, D > & get_coords_low () const
 
const std::array< double, D > & get_coords_high () const
 
Array< T, D > & get_array ()
 
const Array< T, D > & get_array () const
 
const MultiIndex< D > & get_index ()
 
const MultiIndex< D > & get_index () const
 
std::vector< T > & get_data ()
 
T & operator[] (const std::array< int, D > &indices)
 Returns the element at the specified index.
 
T & operator[] (size_t idx)
 Returns the element at the specified index.
 
std::array< double, D > map_indices_to_coordinates (const std::array< int, D > &indices) const
 Maps indices to coordinates in the field.
 
std::array< int, D > map_coordinates_to_indices (const std::array< double, D > &coordinates) const
 Maps coordinates to indices in the field.
 
bool inbounds (const std::array< double, D > &coords)
 Checks if the given coordinates are within the bounds of the field.
 
T & interpolate (const std::array< double, D > &coordinates)
 Interpolate field value at physical coordinates (nearest-neighbor)
 
void apply (FunctionND &&func)
 Applies the given function to each element of the field.
 
void apply (Function1D &&func)
 Applies the given 1D function to each element of the field.
 
void apply (Function2D &&func)
 Applies the given 2D function to each element of the field.
 
void apply (Function3D &&func)
 
 operator std::vector< T > & ()
 Convert DiscreteField<T, D> to std::vector<T>
 
 operator std::vector< T > & () const
 
const std::array< int, D > & get_size () const
 Get the size of the field.
 
const std::array< int, D > & get_offset () const
 
void set_data (const std::vector< T > &data)
 

Friends

std::ostream & operator<< (std::ostream &os, const DiscreteField< T, D > &field)
 Outputs the discrete field to the specified output stream.
 

Detailed Description

template<typename T, size_t D>
class pfc::DiscreteField< T, D >
Examples
Using.

Member Function Documentation

◆ apply() [1/3]

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

Applies the given 1D function to each element of the field.

The function must be invocable with (double) and return a type convertible toT.

Template Parameters
Function1DThe type of the 1D function.
Parameters
funcThe 1D function to apply.
Here is the call graph for this function:

◆ apply() [2/3]

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

Applies the given 2D function to each element of the field.

The function must be invocable with (double, double) and return a type convertible toT.

Template Parameters
Function2DThe type of the 2D function.
Parameters
funcThe 2D function to apply.
Here is the call graph for this function:

◆ apply() [3/3]

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

Applies the given function to each element of the field.

The function must be invocable with std::array<double, D> and return a type convertible to T.

Template Parameters
FunctionNDThe type of the function.
Parameters
funcThe function to apply.
Here is the call graph for this function:

◆ get_origin()

template<typename T , size_t D>
const std::array< double, D > & pfc::DiscreteField< T, D >::get_origin ( ) const
inline

Constructs a DiscreteField from an Decomposition object.

Parameters
decompThe Decomposition object.

◆ get_size()

template<typename T , size_t D>
const std::array< int, D > & pfc::DiscreteField< T, D >::get_size ( ) const
inline

Get the size of the field.

Returns
const std::array<int, D>&

◆ inbounds()

template<typename T , size_t D>
bool pfc::DiscreteField< T, D >::inbounds ( const std::array< double, D > &  coords)
inline

Checks if the given coordinates are within the bounds of the field.

Parameters
coordsThe coordinates to check.
Returns
True if the coordinates are within the bounds, false otherwise.

◆ interpolate()

template<typename T , size_t D>
T & pfc::DiscreteField< T, D >::interpolate ( const std::array< double, D > &  coordinates)
inline

Interpolate field value at physical coordinates (nearest-neighbor)

Deprecated:
Use pfc::interpolate(field, coords) free function instead. This member function is deprecated and will be removed in v2.0. The free function version provides better consistency with OpenPFC's design philosophy and enables ADL-based extension.

Migration:

// Old (deprecated):
double value = field.interpolate({x, y, z});
// New (preferred):
double value = pfc::interpolate(field, {x, y, z});
Represents the global simulation domain (the "world").
Definition world.hpp:91
Parameters
coordinatesPhysical coordinates [x, y, z] to interpolate at
Returns
Reference to the field value at the nearest grid point
See also
pfc::interpolate(DiscreteField&, const std::array<double,D>&)
Here is the call graph for this function:

◆ map_coordinates_to_indices()

template<typename T , size_t D>
std::array< int, D > pfc::DiscreteField< T, D >::map_coordinates_to_indices ( const std::array< double, D > &  coordinates) const
inline

Maps coordinates to indices in the field.

Parameters
coordinatesThe coordinates to map.
Returns
The corresponding indices.
Here is the caller graph for this function:

◆ map_indices_to_coordinates()

template<typename T , size_t D>
std::array< double, D > pfc::DiscreteField< T, D >::map_indices_to_coordinates ( const std::array< int, D > &  indices) const
inline

Maps indices to coordinates in the field.

Parameters
indicesThe indices to map.
Returns
The corresponding coordinates.
Here is the caller graph for this function:

◆ operator std::vector< T > &()

template<typename T , size_t D>
pfc::DiscreteField< T, D >::operator std::vector< T > & ( )
inline

Convert DiscreteField<T, D> to std::vector<T>

Returns
A reference to the underlying data.

◆ operator[]() [1/2]

template<typename T , size_t D>
T & pfc::DiscreteField< T, D >::operator[] ( const std::array< int, D > &  indices)
inline

Returns the element at the specified index.

Parameters
indicesmulti-dimensional indices
Returns
T&

◆ operator[]() [2/2]

template<typename T , size_t D>
T & pfc::DiscreteField< T, D >::operator[] ( size_t  idx)
inline

Returns the element at the specified index.

Parameters
idx
Returns
T&

Friends And Related Symbol Documentation

◆ operator<<

template<typename T , size_t D>
std::ostream & operator<< ( std::ostream &  os,
const DiscreteField< T, D > &  field 
)
friend

Outputs the discrete field to the specified output stream.

Parameters
osThe output stream.
fieldThe discrete field to output.
Returns
Reference to the output stream.

The documentation for this class was generated from the following file: