4 for (std::set<std::size_t>::const_iterator itisgi = unique_groups.begin(); itisgi != unique_groups.end(); ++itisgi) {
5 for (std::set<std::size_t>::const_iterator itjsgi = unique_groups.begin(); itjsgi != unique_groups.end(); ++itjsgi) {
6 if (*itjsgi >= *itisgi) {
9 int mgi1 =
static_cast<int>(m_sgi_to_mgi.find(*itisgi)->second);
10 int mgi2 =
static_cast<int>(m_sgi_to_mgi.find(*itjsgi)->second);
14 interaction.insert(m_pair);
19 interaction.insert(m_pair);
27 if (parameter ==
"aij") {
28 this->interaction[std::pair<int, int>(
static_cast<int>(mgi1),
static_cast<int>(mgi2))].a_ij = value;
29 }
else if (parameter ==
"bij") {
30 this->interaction[std::pair<int, int>(
static_cast<int>(mgi1),
static_cast<int>(mgi2))].b_ij = value;
31 }
else if (parameter ==
"cij") {
32 this->interaction[std::pair<int, int>(
static_cast<int>(mgi1),
static_cast<int>(mgi2))].c_ij = value;
39 this->interaction.find(std::pair<int, int>(
static_cast<int>(mgi1),
static_cast<int>(mgi2)));
40 if (it == this->interaction.end()) {
43 if (parameter ==
"aij") {
44 return it->second.a_ij;
45 }
else if (parameter ==
"bij") {
46 return it->second.b_ij;
47 }
else if (parameter ==
"cij") {
48 return it->second.c_ij;
61 this->mole_fractions = z;
62 if (this->N != z.size()) {
66 std::map<std::size_t, double>&Xg = m_Xg, &thetag = m_thetag;
72 for (std::size_t i = 0; i < this->mole_fractions.size(); ++i) {
73 X_summer += this->mole_fractions[i] * pure_data[i].group_count;
76 for (std::set<std::size_t>::iterator itsgi = unique_groups.begin(); itsgi != unique_groups.end(); ++itsgi) {
79 for (std::size_t i = 0; i < this->mole_fractions.size(); ++i) {
80 X += this->mole_fractions[i] * group_count(i, *itsgi);
82 Xg.insert(std::pair<std::size_t, double>(*itsgi,
X));
85 for (std::map<std::size_t, double>::iterator it = Xg.begin(); it != Xg.end(); ++it) {
86 it->second /= X_summer;
89 double theta_summer = 0;
90 for (std::set<std::size_t>::iterator itsgi = unique_groups.begin(); itsgi != unique_groups.end(); ++itsgi) {
91 double cont = Xg.find(*itsgi)->second * m_Q.find(*itsgi)->second;
93 thetag.insert(std::pair<std::size_t, double>(*itsgi, cont));
96 for (std::map<std::size_t, double>::iterator it = thetag.begin(); it != thetag.end(); ++it) {
97 it->second /= theta_summer;
104 if (this->interaction.size() == 0) {
107 std::size_t mgi1 = m_sgi_to_mgi.find(sgi1)->second;
108 std::size_t mgi2 = m_sgi_to_mgi.find(sgi2)->second;
113 this->interaction.find(std::pair<int, int>(
static_cast<int>(mgi1),
static_cast<int>(mgi2)));
114 if (it != this->interaction.end()) {
115 return exp(-(it->second.a_ij / this->m_T + it->second.b_ij + it->second.c_ij * this->m_T));
118 format(
"Could not match mgi[%d]-mgi[%d] interaction in UNIFAC",
static_cast<int>(mgi1),
static_cast<int>(mgi2)));
125 for (std::vector<UNIFACLibrary::ComponentGroup>::const_iterator it = c.
groups.begin(); it != c.
groups.end(); ++it) {
126 if (it->group.sgi == sgi) {
134 return pure_data[i].theta.find(sgi)->second;
145 if (this->mole_fractions.empty()) {
150 for (std::set<std::size_t>::iterator itk = unique_groups.begin(); itk != unique_groups.end(); ++itk) {
151 for (std::set<std::size_t>::iterator itm = unique_groups.begin(); itm != unique_groups.end(); ++itm) {
152 Psi_[std::pair<std::size_t, std::size_t>(*itk, *itm)] = Psi(*itk, *itm);
156 for (std::size_t i = 0; i < this->mole_fractions.size(); ++i) {
158 for (std::size_t k = 0; k < c.
groups.size(); ++k) {
159 double Q = c.
groups[k].group.Q_k;
160 int sgik = c.
groups[k].group.sgi;
162 for (std::size_t m = 0; m < c.
groups.size(); ++m) {
163 int sgim = c.
groups[m].group.sgi;
164 sum1 += theta_pure(i, sgim) * Psi_.find(std::pair<std::size_t, std::size_t>(sgim, sgik))->second;
166 double s = 1 - log(sum1);
167 for (std::size_t m = 0; m < c.
groups.size(); ++m) {
168 int sgim = c.
groups[m].group.sgi;
170 for (std::size_t n = 0; n < c.
groups.size(); ++n) {
171 int sgin = c.
groups[n].group.sgi;
172 sum2 += theta_pure(i, sgin) * Psi_.find(std::pair<std::size_t, std::size_t>(sgin, sgim))->second;
174 s -= theta_pure(i, sgim) * Psi_.find(std::pair<std::size_t, std::size_t>(sgik, sgim))->second / sum2;
176 pure_data[i].lnGamma[sgik] = Q * s;
181 std::map<std::size_t, double>&thetag = m_thetag, &lnGammag = m_lnGammag;
184 for (std::set<std::size_t>::iterator itksgi = unique_groups.begin(); itksgi != unique_groups.end(); ++itksgi) {
186 for (std::set<std::size_t>::iterator itmsgi = unique_groups.begin(); itmsgi != unique_groups.end(); ++itmsgi) {
187 sum1 += thetag.find(*itmsgi)->second * Psi_.find(std::pair<std::size_t, std::size_t>(*itmsgi, *itksgi))->second;
189 double s = 1 - log(sum1);
190 for (std::set<std::size_t>::iterator itmsgi = unique_groups.begin(); itmsgi != unique_groups.end(); ++itmsgi) {
192 for (std::set<std::size_t>::iterator itnsgi = unique_groups.begin(); itnsgi != unique_groups.end(); ++itnsgi) {
193 sum3 += thetag.find(*itnsgi)->second * Psi_.find(std::pair<std::size_t, std::size_t>(*itnsgi, *itmsgi))->second;
195 s -= thetag.find(*itmsgi)->second * Psi_.find(std::pair<std::size_t, std::size_t>(*itksgi, *itmsgi))->second / sum3;
197 lnGammag.insert(std::pair<std::size_t, double>(*itksgi, m_Q.find(*itksgi)->second * s));
204 set_temperature(T_r / tau);
206 for (std::set<std::size_t>::const_iterator itsgi = unique_groups.begin(); itsgi != unique_groups.end(); ++itsgi) {
207 std::size_t count = group_count(i, *itsgi);
209 summer += count * (m_lnGammag.find(*itsgi)->second - pure_data[i].lnGamma.find(*itsgi)->second);
215 double dtau = 0.01 * tau;
216 return (ln_gamma_R(tau + dtau, i, itau - 1) - ln_gamma_R(tau - dtau, i, itau - 1)) / (2 * dtau);
220 if (this->N != z.size()) {
223 std::vector<double> r(N), q(N), l(N), phi(N), theta(N), ln_Gamma_C(N);
224 double summerzr = 0, summerzq = 0, summerzl = 0;
225 for (std::size_t i = 0; i < N; ++i) {
226 double summerr = 0, summerq = 0;
228 for (std::size_t j = 0; j < c.
groups.size(); ++j) {
235 summerzr += z[i] * r[i];
236 summerzq += z[i] * q[i];
238 for (std::size_t i = 0; i < N; ++i) {
239 phi[i] = z[i] * r[i] / summerzr;
240 theta[i] = z[i] * q[i] / summerzq;
241 l[i] = 10.0 / 2.0 * (r[i] - q[i]) - (r[i] - 1);
242 summerzl += z[i] * l[i];
244 for (std::size_t i = 0; i < N; ++i) {
245 ln_Gamma_C[i] = log(phi[i] / z[i]) + 10.0 / 2.0 * q[i] * log(theta[i] / phi[i]) + l[i] - phi[i] / z[i] * summerzl;
246 gamma[i] = exp(ln_gamma_R(tau, i, 0) + ln_Gamma_C[i]);
252 components.push_back(comp);
253 for (std::vector<UNIFACLibrary::ComponentGroup>::const_iterator it = comp.
groups.begin(); it != comp.
groups.end(); ++it) {
254 m_sgi_to_mgi.insert(std::pair<std::size_t, std::size_t>(it->group.sgi, it->group.mgi));
260 N = identifiers.size();
261 if (identifier_type ==
"name") {
263 for (std::vector<std::string>::const_iterator it = identifiers.begin(); it != identifiers.end(); ++it) {
278 unique_groups.clear();
280 for (std::size_t i = 0; i < N; ++i) {
285 for (std::size_t j = 0; j < c.
groups.size(); ++j) {
287 double x =
static_cast<double>(cg.
count);
289 cd.
X.insert(std::pair<int, double>(cg.
group.
sgi, x));
290 cd.
theta.insert(std::pair<int, double>(cg.
group.
sgi, theta));
297 for (std::map<std::size_t, double>::iterator it = cd.
X.begin(); it != cd.
X.end(); ++it) {
302 for (std::map<std::size_t, double>::iterator it = cd.
theta.begin(); it != cd.
theta.end(); ++it) {
303 it->second /= summerxq;
306 pure_data.push_back(cd);
312 for (std::size_t i = 0; i < N; ++i) {
313 for (std::size_t j = 0; j < components[i].groups.size(); ++j) {
314 if (components[i].groups[j].group.sgi == sgi) {
315 components[i].groups[j].group.Q_k = value;
326 for (std::size_t i = 0; i < N; ++i) {
327 for (std::size_t j = 0; j < components[i].groups.size(); ++j) {
328 if (components[i].groups[j].group.sgi == sgi) {
329 return components[i].groups[j].group.Q_k;