TransFlow  0.1.0
A transient pipeline flow simulation library
Solver Class Reference

The Solver class combines GoverningEquationSolver and BatchTracking to advance the governing equations forward in time, and advect the gas composition. More...

#include <solver.hpp>

Public Member Functions

virtual ~Solver ()
 Declared to avoid the inline compiler-generated default destructor.
 
 Solver (const arma::uword nGridPoints, const Config &config)
 Construct from Config. More...
 
 Solver (const arma::uword nGridPoints, const std::string &energyEquation="InternalEnergy", const arma::vec &relaxationFactors={1, 1, 2/3.0}, const std::string &toleranceType="relative", const arma::vec &tolerances={0.001, 0.001, 0.001}, const bool bruteForce=false, const arma::uword maxIterations=200)
 Construct from number of grid points and string to select discretizer. More...
 
virtual Pipeline solve (const arma::uword dt, const Pipeline &current, const TimeStep &boundaryConditions, const Physics &physics) const
 Solve the governing equations. More...
 
virtual Pipeline solve (const arma::uword dt, const Pipeline &current, const BoundaryConditions &boundaryConditions, const Physics &physics) const
 Solve the governing equations. More...
 
Pipeline solveWithIterations (const arma::uword dt, const Pipeline &current, const BoundaryConditions &boundaryConditions, const Physics &physics) const
 Solve the governing equations. More...
 
void enableBruteForce ()
 Enable brute force solver, which always does m_maxIterations iterations.
 
void setMaxIterations (const arma::uword maxIterations)
 Set max iterations.
 
arma::uword nIterations () const
 Return the number of iterations performed during previous solution attempt.
 
const arma::vec & relaxationFactors () const
 Get (const ref) relaxation factors.
 
const std::string & toleranceType () const
 Get (const ref) tolerance type.
 
const arma::vec & tolerances () const
 Get (const ref) tolerances.
 
const GoverningEquationSolverBasegoverningEquationSolver () const
 Get (const ref) GoverningEquationSolver.
 

Static Public Member Functions

static arma::uword differencesWithinTolerance (const Pipeline &guess, const Pipeline &previous, const arma::vec &tolerances, const std::string &toleranceType, const arma::vec &relaxationFactors)
 Check if differences between an old and a new state are within tolerances. This will either compare relative or absolute differences. More...
 

Private Member Functions

std::unique_ptr< GoverningEquationSolverBasemakeGoverningEquationSolver (const arma::uword nGridPoints, const Config &config)
 Private method for making GoverningEquationSolverBase instance from Config and nGridPoints. More...
 
std::unique_ptr< GoverningEquationSolverBasemakeGoverningEquationSolver (const arma::uword nGridPoints, const std::string &discretizer)
 Private method for making GoverningEquationSolverBase from string and nGridPoints. More...
 

Private Attributes

arma::vec m_relaxationFactor
 Relaxation factors for each property (flow, pressure and temperature).
 
std::string m_toleranceType
 
arma::vec m_tolerances
 Convergence tolerances for each property (flow, pressure and temperature).
 
bool m_bruteForce
 
arma::uword m_maxIterations
 
arma::uword m_nIterations = 0
 
std::unique_ptr< GoverningEquationSolverBasem_governingEquationSolver
 GoverningEquationSolver instance used for solving the governing equations.
 
std::unique_ptr< BatchTrackingm_compositionSolver
 BatchTracking instance used to advect composition in the pipeline.
 

Detailed Description

The Solver class combines GoverningEquationSolver and BatchTracking to advance the governing equations forward in time, and advect the gas composition.

It operates on Pipeline instances, and returns a copy of the input, with updated flow, pressure, temperature, and composition (if batch tracking is enabled).

Constructor & Destructor Documentation

◆ Solver() [1/2]

Solver::Solver ( const arma::uword  nGridPoints,
const Config config 
)

Construct from Config.

Parameters
nGridPointsNumber of grid points
configConfig instance

◆ Solver() [2/2]

Solver::Solver ( const arma::uword  nGridPoints,
const std::string &  energyEquation = "InternalEnergy",
const arma::vec &  relaxationFactors = {1, 1, 2/3.0},
const std::string &  toleranceType = "relative",
const arma::vec &  tolerances = {0.001, 0.001, 0.001},
const bool  bruteForce = false,
const arma::uword  maxIterations = 200 
)
explicit

Construct from number of grid points and string to select discretizer.

Parameters
nGridPointsNumber of grid points.
energyEquationType of energy equation ("InternalEnergy" or "Enthalpy")
relaxationFactorsRelaxation factors, typically around 1.
toleranceTypeTolerance type ("absolute" or "relative")
tolerancesConvergence criteria
bruteForceWill always do maxIterations iterations and not check for convergence
maxIterationsThe maximum number of iterations to perform

Member Function Documentation

◆ differencesWithinTolerance()

static arma::uword Solver::differencesWithinTolerance ( const Pipeline guess,
const Pipeline previous,
const arma::vec &  tolerances,
const std::string &  toleranceType,
const arma::vec &  relaxationFactors 
)
static

Check if differences between an old and a new state are within tolerances. This will either compare relative or absolute differences.

This is used to see if the iteration over solution of the governing equations have converged, by comparing differences between the two last iterations.

In the case of relative differences, we can run into issues if we have zero flow, so this is handled explicitly (temperature and pressure is never expected to reach zero in well-behaved simulations).

Parameters
guess
previous
tolerances
toleranceType
relaxationFactors
Returns

◆ makeGoverningEquationSolver() [1/2]

std::unique_ptr<GoverningEquationSolverBase> Solver::makeGoverningEquationSolver ( const arma::uword  nGridPoints,
const Config config 
)
private

Private method for making GoverningEquationSolverBase instance from Config and nGridPoints.

Parameters
configConfig instance
nGridPointsNumber of grid points
Returns
unique_ptr to GoverningEquationSolverBase

◆ makeGoverningEquationSolver() [2/2]

std::unique_ptr<GoverningEquationSolverBase> Solver::makeGoverningEquationSolver ( const arma::uword  nGridPoints,
const std::string &  discretizer 
)
private

Private method for making GoverningEquationSolverBase from string and nGridPoints.

Parameters
discretizerDiscretizer type ("InternalEnergy" or "Enthalpy")
nGridPointsNumber of grid points
Returns
unique_ptr to GoverningEquationSolverBase

◆ solve() [1/2]

virtual Pipeline Solver::solve ( const arma::uword  dt,
const Pipeline current,
const BoundaryConditions boundaryConditions,
const Physics physics 
) const
virtual

Solve the governing equations.

See also
solveWithIterations()
Parameters
dtTime step [s]
currentCurrent pipeline state
boundaryConditionsBoundary conditions
physicsPhysics instance to update derived properties and heat transfer
Returns
Copy of current with updated properties.

◆ solve() [2/2]

virtual Pipeline Solver::solve ( const arma::uword  dt,
const Pipeline current,
const TimeStep boundaryConditions,
const Physics physics 
) const
virtual

Solve the governing equations.

See also
solveWithIterations()
Parameters
dtTime step [s]
currentCurrent pipeline state
boundaryConditionsBoundary conditions with time stamp
physicsPhysics instance to update derived properties and heat transfer
Returns
Copy of current with updated properties.

◆ solveWithIterations()

Pipeline Solver::solveWithIterations ( const arma::uword  dt,
const Pipeline current,
const BoundaryConditions boundaryConditions,
const Physics physics 
) const

Solve the governing equations.

TODO: Some more documentation here

Parameters
dtTime step [s]
currentPipeline state
boundaryConditionsBoundary conditions
physicsPhysics instance to update derived properties and heat transfer
Returns
Copy of current with updated properties.

Member Data Documentation

◆ m_bruteForce

bool Solver::m_bruteForce
private

If we should use brute-force solving, which means not checking for convergence, but always performing m_maxIterations iterations.

◆ m_maxIterations

arma::uword Solver::m_maxIterations
private

The maximum number of iterations to perform, or (if m_bruteForce is true) the exact number of iterations to perform.

◆ m_nIterations

arma::uword Solver::m_nIterations = 0
mutableprivate

The number of iterations performed during the previous solution attempt. This is mutable, and is updated in Solver::solve().

◆ m_toleranceType

std::string Solver::m_toleranceType
private

What kind of tolerance to use when checking convergence ("relative" or "absolute").


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