OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
pfc::FieldModifier Class Referenceabstract
Inheritance diagram for pfc::FieldModifier:

Public Member Functions

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 void apply (Model &model, double time)=0
 Apply the field modification to the model (pure virtual)
 
virtual ~FieldModifier ()=default
 Destructor for the FieldModifier class.
 

Detailed Description

Constructor & Destructor Documentation

◆ ~FieldModifier()

virtual pfc::FieldModifier::~FieldModifier ( )
virtualdefault

Destructor for the FieldModifier class.

The destructor is declared as default, allowing proper destruction of derived classes.

Member Function Documentation

◆ apply()

virtual void pfc::FieldModifier::apply ( Model model,
double  time 
)
pure virtual

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);
}
}
}
}
virtual void apply(Model &model, double time)=0
Apply the field modification to the model (pure virtual)
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

Implemented in MyIC, GaussianIC, pfc::Constant, pfc::FixedBC, pfc::MovingBC, pfc::FileReader, pfc::RandomSeeds, pfc::SeedGrid, pfc::SingleSeed, GaussianIC, GaussianIC, DirichletBC, and OscillatingBC.

Examples
Accessing, and Space-time.

◆ get_modifier_name()

virtual const std::string & pfc::FieldModifier::get_modifier_name ( ) const
inlinevirtual

Get the name of the field modifier.

This function is responsible for getting the name of the field modifier.

Returns
The modifier name.

Reimplemented in DirichletBC, OscillatingBC, pfc::FixedBC, and pfc::MovingBC.


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