PhaseField

class PhaseField : public minim::NewPotential<PhaseField>

Multi-component phase field potential on a structured grid.

System size

int nFluid = 1

The number of fluid components.

double resolution = 1

The grid resolution.

PhaseField &setNFluid(int nFluid)

Set the number of fluid components.

PhaseField &setGridSize(vector<int> gridSize)

Set the size of the grid along each dimension.

PhaseField &setResolution(double resolution)

Set the grid resolution.

Fluid interfaces

Order: 1-2, 1-3, …, 1-N, 2-3 (continue to (N-1)-N for N-comp).

vector<double> interfaceSize

The diffuse interface size of each fluid pair.

vector<double> surfaceTension = {1}

The surface tension of each fluid pair.

PhaseField &setInterfaceSize(double interfaceSize)

Set the interface size for all fluid pairs.

PhaseField &setInterfaceSize(vector<double> interfaceSize)

Set the interface size of each fluid pair.

PhaseField &setSurfaceTension(double surfaceTension)

Set the surface tension for all fluid pairs.

PhaseField &setSurfaceTension(vector<double> surfaceTension)

Set the surface tension of each fluid pair.

PhaseField &setSurfaceTension(std::function<vector<double>(int, int, int)> surfaceTensionFn)

Set the surface tension via a function of the two fluid types.

Density constraint

int densityConstraint = 0

The density constraint method: 0 for hard constraint (default).

double densityConst = 1

The strength of the soft density constraint.

PhaseField &setDensityConstraint(std::string method)

Set the density constraint method (“hard” or “soft”).

Volume and pressure constraints

bool volumeFixed = false

Whether the total fluid volume is fixed.

double volConst = 0.01

The strength of the volume constraint.

vector<double> pressure

The target pressure of each fluid.

vector<double> volume

The target volume of each fluid.

PhaseField &setPressure(vector<double> pressure)

Set the target pressure of each fluid.

PhaseField &setVolume(vector<double> volume, double volConst = 0.01)

Set the target volume of each fluid.

PhaseField &setVolumeFixed(bool volumeFixed, double volConst = 0.01)

Set whether the total fluid volume is fixed.

Solid nodes

vector<char> solid

Which grid nodes are solid.

vector<double> contactAngle

The wall contact angle of each fluid pair.

PhaseField &setSolid(vector<char> solid)

Set which grid nodes are solid.

PhaseField &setSolid(std::function<bool(int, int, int)> solidFn)

Set which grid nodes are solid via a function of the grid indices.

PhaseField &setContactAngle(double contactAngle)

Set the wall contact angle for all fluid pairs.

PhaseField &setContactAngle(vector<double> contactAngle)

Set the wall contact angle of each fluid pair.

PhaseField &setContactAngle(std::function<double(int, int, int)> contactAngleFn)

Set the wall contact angle via a function of the grid indices and fluid pair.

External force

vector<vector<double>> force

An external force applied to the fluids.

PhaseField &setForce(vector<double> force, vector<int> iFluid = {})

Set an external force on the given fluid (default: all).

Diffuse solid method

PhaseField &setFixFluid(int iFluid, bool fix = true)

Set whether the given fluid is fixed in place.

PhaseField &setConfinement(vector<double> strength)

Set the confinement strength of each fluid.

vector<double> diffuseSolid(vector<char> solid, int iFluid = 0, bool twoStep = false)

Compute a diffuse representation of the solid, usable as initial coordinates.

static vector<double> diffuseSolid(vector<char> solid, PhaseField potential, int iFluid = 0, bool twoStep = false)

Compute a diffuse representation of the solid using the given potential’s grid.

static vector<double> diffuseSolid(vector<char> solid, vector<int> gridSize, int nFluid = 2, int iFluid = 0, bool twoStep = false)

Compute a diffuse representation of the solid using the given grid.

Overrides

virtual void init(const vector<double> &coords) override

Initialise the potential with the coordinates of a new state.

virtual void initLocal(const vector<double> &coords, const Communicator &comm) override

Initialise the potential with local (distributed) data.

Take care using this, if the potential is cloned any distributed parameters will be copied as they are.

virtual void energyGradient(const vector<double> &coords, const Communicator &comm, double *e, vector<double> *g) const override

Compute the energy and gradient of the given coordinates.

Parameters:
  • coords – The coordinates to compute the energy and gradient of.

  • comm – The communicator, used for distributed calculations.

  • e – Output: the total energy.

  • g – Output: the gradient of the total energy.

std::map<std::string, vector<double>> energyComponents(const vector<double> &coords, const Communicator &comm) const

Compute the named components of the energy, e.g. for analysis.