14 for (
int ii = 0; ii < n.size(); ++ii)
15 ret -=
m_b[ii] * n[ii];
28 for (
int ii = 0; ii < n.size(); ++ii)
34 std::vector<double> ret = nid;
36 for (
int ii = 0; ii < nid.size(); ++ii)
37 denom +=
m_b[ii] * nid[ii];
38 for (
int ii = 0; ii < nid.size(); ++ii)
39 ret[ii] = nid[ii] / denom;
47 std::map<std::pair<double,double>,
int> MapEV;
49 for (
int i = 0; i <
m_N; ++i) {
50 std::pair<double, double> param = std::make_pair(
m_b[i],
m_dbdT[i]);
51 if (MapEV.count(param) == 0) {
63 for (
int j = 0; j < n.size(); ++j)
64 ret -=
m_b[j][i] * n[j];
76 for (
int j = 0; j < n.size(); ++j)
77 ret -=
m_dbdT[j][i] * n[j];
82 std::vector<double> ret = nid;
85 MatrixXd densMatrix(NN, NN);
86 VectorXd solVector(NN), xVector(NN);
88 for (
int i = 0; i < NN; ++i)
89 for (
int j = 0; j < NN; ++j) {
90 densMatrix(i, j) =
m_b[j][i] * nid[i];
91 if (i == j) densMatrix(i, j) += 1.;
94 PartialPivLU<MatrixXd> decomp(densMatrix);
96 for (
int i = 0; i < NN; ++i) xVector[i] = nid[i];
97 solVector = decomp.solve(xVector);
99 for (
int i = 0; i < NN; ++i) ret[i] = solVector[i];
108 std::map<std::vector<double>,
int> MapEV;
110 for (
int i = 0; i <
m_N; ++i) {
111 std::vector<double> param(0);
112 for (
int j = 0; j <
m_N; ++j)
113 param.push_back(
m_b[i][j]);
114 for (
int j = 0; j <
m_N; ++j)
115 param.push_back(
m_b[j][i]);
116 for (
int j = 0; j <
m_N; ++j)
117 param.push_back(
m_dbdT[i][j]);
118 for (
int j = 0; j <
m_N; ++j)
119 param.push_back(
m_dbdT[j][i]);
121 if (MapEV.count(param) == 0) {
166 for (
int i = 0; i <
m_N; ++i)
174 double etaid =
GetEta(nid);
177 std::vector<double> ret(
m_N, 0.);
178 for (
int i = 0; i <
m_N; ++i)
179 ret[i] = fval * nid[i];
193 std::map<std::pair<double, double>,
int> MapEV;
195 for (
int i = 0; i <
m_N; ++i) {
196 std::pair<double, double> param = std::make_pair(
m_b[i],
m_dbdT[i]);
197 if (MapEV.count(param) == 0) {
209 for (
int i = 0; i < n.size(); ++i)
210 ret +=
m_b[i] * n[i];
217 std::vector<double> ret(
m_N, 0.);
219 std::vector<double> dens(m_EVM->m_N, 0.);
220 for (
int i = 0; i < m_EVM->m_N; ++i) {
222 if (m_componentsMode)
223 ti = m_EVM->ComponentIndices()[i];
224 dens[i] = x[ti] * m_ntil->operator[](i);
226 m_EVM->SetDensities(dens);
228 for (
int i = 0; i <
m_N; ++i) {
230 if (m_componentsMode)
231 fi = m_EVM->ComponentIndicesFrom()[i];
232 ret[i] = x[i] - m_EVM->f(fi);
241 std::vector<double> ret(N * N);
243 std::vector<double> dens(m_EVM->m_N, 0.);
244 for (
int i = 0; i < m_EVM->m_N; ++i) {
246 if (m_componentsMode)
247 ti = m_EVM->ComponentIndices()[i];
248 dens[i] = x[ti] * m_ntil->operator[](i);
250 m_EVM->SetDensities(dens);
252 std::vector<double> ntilcomp(N, 0.);
253 for (
int i = 0; i < m_EVM->m_N; ++i) {
255 if (m_componentsMode)
256 ti = m_EVM->ComponentIndices()[i];
257 ntilcomp[ti] = m_ntil->operator[](i);
260 for (
int i = 0; i < N; ++i) {
262 if (m_componentsMode)
263 fi = m_EVM->ComponentIndicesFrom()[i];
264 for (
int j = 0; j < N; ++j) {
266 if (m_componentsMode)
267 fj = m_EVM->ComponentIndicesFrom()[j];
270 ret[i * N + j] += 1.;
271 ret[i * N + j] += -m_EVM->df(fi, fj) * ntilcomp[j];
285 std::vector<double> ret(
m_N, 0.);
287 ret = broydn.
Solve(ret, &crit);
288 for (
int i = 0; i <
m_N; ++i)
300 std::vector<double> ret(
m_N, 0.);
302 bool converged =
false;
315 sol = broydn2.
Solve(sol1, &crit);
323 sol = broydn3.
Solve(sol0, &crit);
331 for (
int iter = 0; iter < 10000; ++iter) {
335 if (std::abs(residual[c]) > maxres) maxres = std::abs(residual[c]);
336 if (maxres < 1.0E-10) {
342 double sol_new = sol[c] - residual[c];
343 if (sol_new < 0.) sol_new = 0.;
344 if (sol_new > 1.) sol_new = 1.;
345 sol[c] = alpha * sol_new + (1. - alpha) * sol[c];
355 for (
int i = 0; i <
m_N; ++i)
386 std::map<std::vector<double>,
int> MapEV;
388 for (
int i = 0; i <
m_N; ++i) {
389 std::vector<double> param(0);
390 for (
int j = 0; j <
m_N; ++j)
391 param.push_back(
m_b[i][j]);
392 for (
int j = 0; j <
m_N; ++j)
393 param.push_back(
m_b[j][i]);
394 for (
int j = 0; j <
m_N; ++j)
395 param.push_back(
m_dbdT[i][j]);
396 for (
int j = 0; j <
m_N; ++j)
397 param.push_back(
m_dbdT[j][i]);
399 if (MapEV.count(param) == 0) {
423 for (
int j = 0; j < n.size(); ++j)
424 ret +=
m_b[j][i] * n[j];
470 for (
int j = 0; j <
m_N; ++j)
486 for (
int i = 0; i < nid.size(); ++i)
492 double etaid =
m_b[ti][ti] * nids_comp[ic] / 4.;
496 std::vector<double> ret(
m_N, 0.);
497 for (
int i = 0; i < nid.size(); ++i) {
523 for (
int i = 0; i < n.size(); ++i)
530 for (
int i =
m_N - 1; i >= 0; --i) {
585 return m_evmodels[tind]->df(3, eta) * (
m_b[tind] / 4.) * (
m_b[tind] / 4.) * (
m_b[tind] / 4.);
599 return m_evmodels[tind]->df(4, eta) * (
m_b[tind] / 4.) * (
m_b[tind] / 4.) * (
m_b[tind] / 4.) * (
m_b[tind] / 4.);
612 for (
int i = 0; i < nid.size(); ++i)
617 double etaid =
m_b[ic] * nids_comp[ic] / 4.;
621 std::vector<double> ret(
m_N, 0.);
622 for (
int i = 0; i < nid.size(); ++i) {
Sub-class where it is determined whether the required accuracy is achieved in the Broyden's method.
int m_N
The number of equations.
Class implementing the Broyden method to solve a system of non-linear equations.
virtual std::vector< double > Solve(const std::vector< double > &x0, BroydenSolutionCriterium *solcrit=NULL, int max_iterations=MAX_ITERS)
int MaxIterations() const
virtual ~ExcludedVolumeModelComponents()
Destructor for the ExcludedVolumeModelComponents class.
virtual double d2f(int i, int j, int k) const
Calculates the second derivative of the suppression factor.
virtual double d4f(int i, int j, int k, int l, int m) const
Calculates the fourth derivative of the suppression factor.
virtual double d3f(int i, int j, int k, int l) const
Calculates the third derivative of the suppression factor.
virtual void SetDensities(const std::vector< double > &n)
Sets the densities of particle species.
virtual void ComputeComponents()
Computes the components based on the excluded volume parameters.
virtual double dfdT(int i) const
Calculates the temperature derivative of the suppression factor.
std::vector< double > m_b
virtual std::vector< double > nsol(const std::vector< double > &nid)
Solves for the actual densities given the ideal gas densities.
virtual double f(int i) const
Calculates the suppression factor for species i.
std::vector< ExcludedVolumeModelBase * > m_evmodels
std::vector< double > m_densities_components
std::vector< double > m_dbdT
virtual double df(int i, int j) const
Calculates the first derivative of the suppression factor.
ExcludedVolumeModelBase * m_evmodelsingle
std::vector< std::vector< double > > m_dbdT
bool m_componentsDisconnected
virtual double d3f(int i, int j, int k, int l) const
Calculates the third derivative of the suppression factor.
virtual double d2f(int i, int j, int k) const
Calculates the second derivative of the suppression factor.
virtual void SetDensities(const std::vector< double > &n)
Sets the densities of particle species.
virtual std::vector< double > nsol(const std::vector< double > &nid)
Solves for the actual densities given the ideal gas densities.
virtual double dfdT(int i) const
Calculates the temperature derivative of the suppression factor.
double GetEta(int i, const std::vector< double > &n) const
Calculates the eta parameter for the given densities and species index.
virtual double df(int i, int j) const
Calculates the first derivative of the suppression factor.
virtual double d4f(int i, int j, int k, int l, int m) const
Calculates the fourth derivative of the suppression factor.
std::vector< std::vector< double > > m_b
virtual void ComputeComponents()
Computes the components based on the excluded volume parameters.
std::vector< double > m_etas
virtual double f(int i) const
Calculates the suppression factor for species i.
virtual ~ExcludedVolumeModelCrosstermsGeneralized()
Destructor for the ExcludedVolumeModelCrosstermsGeneralized class.
std::vector< std::vector< double > > m_b
virtual double df(int i, int j) const
Calculates the first derivative of the suppression factor.
virtual void ComputeComponents()
Computes the components based on the excluded volume parameters.
virtual std::vector< double > nsol(const std::vector< double > &nid)
Solves for the actual densities given the ideal gas densities.
std::vector< std::vector< double > > m_dbdT
virtual double dfdT(int i) const
Calculates the temperature derivative of the suppression factor.
virtual double f(int i) const
Calculates the suppression factor for species i.
virtual ~ExcludedVolumeModelDiagonalGeneralized()
Destructor for the ExcludedVolumeModelDiagonalGeneralized class.
ExcludedVolumeModelBase * m_evmodelsingle
virtual double f(int i) const
Calculates the suppression factor for species i.
virtual double df(int i, int j) const
Calculates the first derivative of the suppression factor.
virtual double d2f(int i, int j, int k) const
Calculates the second derivative of the suppression factor.
double GetEta(const std::vector< double > &n) const
Calculates the eta parameter for the given densities.
virtual double dfdT(int i) const
Calculates the temperature derivative of the suppression factor.
std::vector< double > m_dbdT
virtual void ComputeComponents()
Computes the components based on the excluded volume parameters.
std::vector< double > m_b
virtual std::vector< double > nsol(const std::vector< double > &nid)
Solves for the actual densities given the ideal gas densities.
virtual double d3f(int i, int j, int k, int l) const
Calculates the third derivative of the suppression factor.
virtual double d4f(int i, int j, int k, int l, int m) const
Calculates the fourth derivative of the suppression factor.
virtual void SetDensities(const std::vector< double > &n)
Sets the densities of particle species.
std::vector< double > m_dbdT
std::vector< double > m_b
virtual void ComputeComponents()
Computes the components based on the excluded volume parameters.
virtual double f(int i) const
Calculates the suppression factor for species i.
virtual double df(int i, int j) const
Calculates the first derivative of the suppression factor.
virtual double dfdT(int i) const
Calculates the temperature derivative of the suppression factor.
virtual std::vector< double > nsol(const std::vector< double > &nid)
Solves for the actual densities given the ideal gas densities.
std::vector< double > Equations(const std::vector< double > &x)
Calculates the equations for Broyden's method.
std::vector< double > Jacobian(const std::vector< double > &x)
Calculates the Jacobian matrix for Broyden's method.
std::vector< int > m_componentsFrom
virtual std::vector< double > nsolBroydenComponents(const std::vector< double > &ntil)
Solves for the actual densities using Broyden's method, considering components.
std::vector< double > m_densities
std::vector< double > m_previousSolComponents
Cached previous Broyden solution (per component) for use as initial guess.
std::vector< int > m_components
virtual const std::vector< int > & ComponentIndices() const
Gets the component indices.
virtual void ComputeComponents()
Computes the components based on the excluded volume parameters.
bool m_hasPreviousSolComponents
virtual void SetDensities(const std::vector< double > &n)
Sets the densities of particle species.
virtual std::vector< double > nsolBroyden(const std::vector< double > &ntil)
Solves for the actual densities using Broyden's method.
The main namespace where all classes and functions of the Thermal-FIST library reside.