OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
GaussianIC Class Reference

Custom field modifier: Gaussian initial condition. More...

Inheritance diagram for GaussianIC:
Collaboration diagram for GaussianIC:

Public Member Functions

void apply (Model &m, double t) override
 Apply the field modification to the model (pure virtual)
 
 GaussianIC (const std::string &field_name, const types::Real3 &center, double amplitude=1.0, double sigma=1.0)
 
std::string get_field_name () const override
 
void apply (Model &model, double t) override
 Apply the field modification to the model (pure virtual)
 
 GaussianIC (Real3 center, double amplitude, double width, double background=0.0)
 
void apply (Model &model, double time) override
 Apply the field modification to the model (pure virtual)
 
- Public Member Functions inherited from pfc::FieldModifier
void set_field_name (const std::string &field_name)
 
const std::string & get_field_name () const
 
virtual const std::string & get_modifier_name () const
 Get the name of the field modifier.
 
virtual ~FieldModifier ()=default
 Destructor for the FieldModifier class.
 

Detailed Description

Custom field modifier: Gaussian initial condition.

Custom initial condition: Gaussian bump in 3D space.

This demonstrates:

  • Deriving from FieldModifier
  • Accessing model geometry (world, fft, inbox)
  • Coordinate-space operations (world::to_coords)
  • Spatial field initialization
Examples
03_simulator_workflow.cpp, and 05_simulator.cpp.

Member Function Documentation

◆ apply() [1/3]

void GaussianIC::apply ( Model model,
double  time 
)
inlineoverridevirtual

Apply the field modification to the model (pure virtual)

This is the main interface method that derived classes must implement to define their modification logic. The method receives full mutable access to the Model and current simulation time, allowing arbitrary modifications.

Implementation Responsibilities:

  • Retrieve field(s) via model.get_real_field() or model.get_complex_field()
  • Access geometry via model.get_world() and model.get_fft()
  • Modify field values according to modifier's purpose
  • Handle MPI parallelism (operate on local subdomain)

Typical Implementation Pattern:

void apply(pfc::Model& model, double time) override {
// 1. Get field to modify
auto& field = model.get_real_field(get_field_name());
// 2. Get geometry information
const auto& world = model.get_world();
const auto& fft = model.get_fft();
auto inbox = pfc::fft::get_inbox(fft);
// 3. Loop over local subdomain
int idx = 0;
for (int k = inbox.low[2]; k <= inbox.high[2]; k++) {
for (int j = inbox.low[1]; j <= inbox.high[1]; j++) {
for (int i = inbox.low[0]; i <= inbox.high[0]; i++) {
// Compute modification based on position and/or time
auto pos = pfc::world::to_coords(world, Int3{i, j, k});
field[idx++] = compute_value(pos, time);
}
}
}
}
void apply(Model &m, double t) override
Apply the field modification to the model (pure virtual)
Definition 05_simulator.cpp:49
The Model class represents the physics model for simulations in OpenPFC.
Definition model.hpp:95
Represents the global simulation domain (the "world").
Definition world.hpp:91
Parameters
modelMutable reference to the Model containing fields to modify
timeCurrent simulation time (useful for time-dependent BCs)
Precondition
Model must have the field specified by get_field_name() registered
Postcondition
Field values are modified according to modifier's logic
Note
For initial conditions, time is typically 0.0
For boundary conditions, time reflects current simulation time
Method is called on every MPI rank; each rank operates on its subdomain
Warning
Ensure modifications maintain physical correctness and don't violate model invariants (e.g., mass conservation if required)
See also
Model::get_real_field() for field access
Model::get_world() for domain geometry
Model::get_fft() for subdomain bounds

Implements pfc::FieldModifier.

Examples
03_simulator_workflow.cpp, and 05_simulator.cpp.

◆ apply() [2/3]

void GaussianIC::apply ( Model model,
double  time 
)
inlineoverridevirtual

Apply the field modification to the model (pure virtual)

This is the main interface method that derived classes must implement to define their modification logic. The method receives full mutable access to the Model and current simulation time, allowing arbitrary modifications.

Implementation Responsibilities:

  • Retrieve field(s) via model.get_real_field() or model.get_complex_field()
  • Access geometry via model.get_world() and model.get_fft()
  • Modify field values according to modifier's purpose
  • Handle MPI parallelism (operate on local subdomain)

Typical Implementation Pattern:

void apply(pfc::Model& model, double time) override {
// 1. Get field to modify
auto& field = model.get_real_field(get_field_name());
// 2. Get geometry information
const auto& world = model.get_world();
const auto& fft = model.get_fft();
auto inbox = pfc::fft::get_inbox(fft);
// 3. Loop over local subdomain
int idx = 0;
for (int k = inbox.low[2]; k <= inbox.high[2]; k++) {
for (int j = inbox.low[1]; j <= inbox.high[1]; j++) {
for (int i = inbox.low[0]; i <= inbox.high[0]; i++) {
// Compute modification based on position and/or time
auto pos = pfc::world::to_coords(world, Int3{i, j, k});
field[idx++] = compute_value(pos, time);
}
}
}
}
Parameters
modelMutable reference to the Model containing fields to modify
timeCurrent simulation time (useful for time-dependent BCs)
Precondition
Model must have the field specified by get_field_name() registered
Postcondition
Field values are modified according to modifier's logic
Note
For initial conditions, time is typically 0.0
For boundary conditions, time reflects current simulation time
Method is called on every MPI rank; each rank operates on its subdomain
Warning
Ensure modifications maintain physical correctness and don't violate model invariants (e.g., mass conservation if required)
See also
Model::get_real_field() for field access
Model::get_world() for domain geometry
Model::get_fft() for subdomain bounds

Implements pfc::FieldModifier.

◆ apply() [3/3]

void GaussianIC::apply ( Model model,
double  time 
)
inlineoverridevirtual

Apply the field modification to the model (pure virtual)

This is the main interface method that derived classes must implement to define their modification logic. The method receives full mutable access to the Model and current simulation time, allowing arbitrary modifications.

Implementation Responsibilities:

  • Retrieve field(s) via model.get_real_field() or model.get_complex_field()
  • Access geometry via model.get_world() and model.get_fft()
  • Modify field values according to modifier's purpose
  • Handle MPI parallelism (operate on local subdomain)

Typical Implementation Pattern:

void apply(pfc::Model& model, double time) override {
// 1. Get field to modify
auto& field = model.get_real_field(get_field_name());
// 2. Get geometry information
const auto& world = model.get_world();
const auto& fft = model.get_fft();
auto inbox = pfc::fft::get_inbox(fft);
// 3. Loop over local subdomain
int idx = 0;
for (int k = inbox.low[2]; k <= inbox.high[2]; k++) {
for (int j = inbox.low[1]; j <= inbox.high[1]; j++) {
for (int i = inbox.low[0]; i <= inbox.high[0]; i++) {
// Compute modification based on position and/or time
auto pos = pfc::world::to_coords(world, Int3{i, j, k});
field[idx++] = compute_value(pos, time);
}
}
}
}
Parameters
modelMutable reference to the Model containing fields to modify
timeCurrent simulation time (useful for time-dependent BCs)
Precondition
Model must have the field specified by get_field_name() registered
Postcondition
Field values are modified according to modifier's logic
Note
For initial conditions, time is typically 0.0
For boundary conditions, time reflects current simulation time
Method is called on every MPI rank; each rank operates on its subdomain
Warning
Ensure modifications maintain physical correctness and don't violate model invariants (e.g., mass conservation if required)
See also
Model::get_real_field() for field access
Model::get_world() for domain geometry
Model::get_fft() for subdomain bounds

Implements pfc::FieldModifier.


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