Rev 10 | Rev 110 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 10 | Rev 104 | ||
---|---|---|---|
Line -... | Line 1... | ||
- | 1 | // -*- coding: utf-8 -*- |
|
1 | #include "chemeq.h" |
2 | #include "chemeq.h" |
2 | #include <math.h> |
3 | #include <math.h> |
3 | #include <sstream> |
4 | #include <sstream> |
- | 5 | #include <stdlib.h> |
|
4 | 6 | ||
5 | atome lesatomes[] ={ |
7 | atome lesatomes[] ={ |
6 | {-1, "e"}, |
8 | {-1, "e"}, |
7 | {1, "H"}, |
9 | {1, "H"}, |
8 | {2, "He"}, |
10 | {2, "He"}, |
Line 139... | Line 141... | ||
139 | } |
141 | } |
140 | 142 | ||
141 | double AtomeListe::weight(fraction mult)const{ |
143 | double AtomeListe::weight(fraction mult)const{ |
142 | const AtomeListe * al; |
144 | const AtomeListe * al; |
143 | double w=0.0; |
145 | double w=0.0; |
144 | if(Zed!=0 && Zed!=-1 ){ /* cas où ce n'est pas un groupe ou un électron */ |
146 | if(Zed!=0 && Zed!=-1 ){ /* cas où ce n'est pas un groupe ou un électron */ |
145 | w=mendelweight(symb)*nb*mult.i/mult.d; |
147 | w=mendelweight(symb)*nb*mult.i/mult.d; |
146 | //debug(); std::cout << std::endl; |
- | |
147 | } |
148 | } |
148 | else if (Zed==0){ /* cas d'un groupe */ |
149 | else if (Zed==0){ /* cas d'un groupe */ |
149 | if (group) w+=group->weight(mult*nb); |
150 | if (group) w+=group->weight(mult*nb); |
150 | } |
151 | } |
151 | if (suiv) w+=suiv->weight(mult); |
152 | if (suiv) w+=suiv->weight(mult); |
152 | return w; |
153 | return w; |
153 | } |
154 | } |
154 | 155 | ||
155 | void AtomeListe::compte(Compteur &c, fraction mult)const{ |
156 | void AtomeListe::compte(Compteur &c, fraction mult)const{ |
156 | const AtomeListe * al; |
157 | const AtomeListe * al; |
157 | if(Zed!=0 && Zed!=-1 ){ /* cas où ce n'est pas un groupe ou un électron */ |
158 | if(Zed!=0 && Zed!=-1 ){ /* cas où ce n'est pas un groupe ou un électron */ |
158 | std::string key(symb); |
159 | std::string key(symb); |
159 | c[key] +=1.0*nb*mult.i/mult.d; |
160 | c[key] +=1.0*nb*mult.i/mult.d; |
160 | } |
161 | } |
161 | else if (Zed==0){ /* cas d'un groupe */ |
162 | else if (Zed==0){ /* cas d'un groupe */ |
162 | if (group) group->compte(c,mult*nb); |
163 | if (group) group->compte(c,mult*nb); |
163 | } |
164 | } |
164 | if (suiv) suiv->compte(c,mult); |
165 | if (suiv) suiv->compte(c,mult); |
165 | } |
166 | } |
166 | 167 | ||
167 | void AtomeListe::numerote(int n){ |
168 | void AtomeListe::numerote(int n){ |
168 | if(Zed!=0){ /* cas où ce n'est pas un groupe */ |
169 | if(Zed!=0){ /* cas où ce n'est pas un groupe */ |
169 | no = n; |
170 | no = n; |
170 | } |
171 | } |
171 | else if (Zed==0){ /* cas d'un groupe */ |
172 | else if (Zed==0){ /* cas d'un groupe */ |
172 | no = n; |
173 | no = n; |
173 | if (group) group->numerote(); |
174 | if (group) group->numerote(); |
Line 175... | Line 176... | ||
175 | if (suiv) suiv->numerote(n+1); |
176 | if (suiv) suiv->numerote(n+1); |
176 | } |
177 | } |
177 | 178 | ||
178 | AtomeListe * AtomeListe::triage(AtomeListe * al){ |
179 | AtomeListe * AtomeListe::triage(AtomeListe * al){ |
179 | AtomeListe * al1; |
180 | AtomeListe * al1; |
180 | if(al->Z()!=0){ /* cas où ce n'est pas un groupe */ |
181 | if(al->Z()!=0){ /* cas où ce n'est pas un groupe */ |
181 | if (al->suiv){ |
182 | if (al->suiv){ |
182 | al->suiv = triage(al->suiv); |
183 | al->suiv = triage(al->suiv); |
183 | } |
184 | } |
184 | while (al->suiv && al->suiv->Zed!=0 && |
185 | while (al->suiv && al->suiv->Zed!=0 && |
185 | strcmp(al->symbole(), al->suiv->symbole()) > 1){ |
186 | strcmp(al->symbole(), al->suiv->symbole()) > 1){ |
Line 194... | Line 195... | ||
194 | 195 | ||
195 | bool operator == (const AtomeListe & a1, const AtomeListe & a2){ |
196 | bool operator == (const AtomeListe & a1, const AtomeListe & a2){ |
196 | std::stringstream s1, s2; |
197 | std::stringstream s1, s2; |
197 | a1.printnorm(s1); |
198 | a1.printnorm(s1); |
198 | a2.printnorm(s2); |
199 | a2.printnorm(s2); |
199 | return s1 |
200 | return s1.str() == s2.str(); |
200 | } |
201 | } |
201 | 202 | ||
202 | void AtomeListe::printcount(std::ostream & o, const fraction& n, int multiple=1) const{ |
203 | void AtomeListe::printcount(std::ostream & o, const fraction& n, int multiple=1) const{ |
203 | if(Zed!=0){ /* cas où ce n'est pas un groupe */ |
204 | if(Zed!=0){ /* cas où ce n'est pas un groupe */ |
204 | o << symb; |
205 | o << symb; |
205 | o << ':' << n << '*' << multiple*nb; |
206 | o << ':' << n << '*' << multiple*nb; |
206 | } |
207 | } |
207 | else{ /* cas d'un groupe */ |
208 | else{ /* cas d'un groupe */ |
208 | if (group) group->printcount(o,n,nb); |
209 | if (group) group->printcount(o,n,nb); |
Line 210... | Line 211... | ||
210 | if (suiv) {o << ' '; suiv->printcount(o,n,multiple);} |
211 | if (suiv) {o << ' '; suiv->printcount(o,n,multiple);} |
211 | } |
212 | } |
212 | 213 | ||
213 | void AtomeListe::printnorm(std::ostream & o) const{ |
214 | void AtomeListe::printnorm(std::ostream & o) const{ |
214 | if (sqbr) o << "["; |
215 | if (sqbr) o << "["; |
215 | if(Zed!=0){ /* cas où ce n'est pas un groupe */ |
216 | if(Zed!=0){ /* cas où ce n'est pas un groupe */ |
216 | o << symb; |
217 | o << symb; |
217 | if (nb!=1) o << nb; |
218 | if (nb!=1) o << nb; |
218 | } |
219 | } |
219 | else{ /* cas d'un groupe */ |
220 | else{ /* cas d'un groupe */ |
220 | o << "("; |
221 | o << "("; |
Line 230... | Line 231... | ||
230 | const AtomeListe * al; |
231 | const AtomeListe * al; |
231 | if (l.sq()) o << "["; |
232 | if (l.sq()) o << "["; |
232 | if(l.Z()>0 || l.Z()<-1){ |
233 | if(l.Z()>0 || l.Z()<-1){ |
233 | o << l.symbole(); |
234 | o << l.symbole(); |
234 | } |
235 | } |
235 | else if (l.Z()==-1){ // cas de l'électron |
236 | else if (l.Z()==-1){ // cas de l'électron |
236 | o << "e"; |
237 | o << "e"; |
237 | } |
238 | } |
238 | else{ // cas des groupes parenthésés |
239 | else{ // cas des groupes parenthésés |
239 | o << "("; |
240 | o << "("; |
240 | if((al=l.groupe())) o << *al; |
241 | if((al=l.groupe())) o << *al; |
241 | o << ")"; |
242 | o << ")"; |
242 | } |
243 | } |
243 | if((n=l.getmolecularite())>1) o << "_{" << n << "}"; |
244 | if((n=l.getmolecularite())>1) o << "_{" << n << "}"; |
244 | if((al=l.suivant())) o << *al; |
245 | if((al=l.suivant())) o << *al; |
245 | if (l.sq()) o << "]"; |
246 | if (l.sq()) o << "]"; |
246 | return o; |
247 | return o; |
247 | } |
248 | } |
248 | 249 | ||
249 | char* moltypeStr[] = { "aq", "g", "s" }; |
250 | const char* moltypeStr[] = { "aq", "g", "s" }; |
250 | 251 | ||
251 | bool operator == (const Molec & m1, const Molec & m2){ |
252 | bool operator == (const Molec & m1, const Molec & m2){ |
252 | return *(m1.al) == *(m2.al) && m1.ch == m2.ch; |
253 | return *(m1.al) == *(m2.al) && m1.ch == m2.ch; |
253 | } |
254 | } |
254 | 255 | ||
Line 304... | Line 305... | ||
304 | nb.i *= f.i; |
305 | nb.i *= f.i; |
305 | nb.d *= f.d; |
306 | nb.d *= f.d; |
306 | nb.simplifie(); |
307 | nb.simplifie(); |
307 | } |
308 | } |
308 | 309 | ||
309 | bool Molec::printNernst(std::ostream & o, char * prefix){ |
310 | bool Molec::printNernst(std::ostream & o, const char * prefix){ |
310 | switch(t){ |
311 | switch(t){ |
311 | case sol : return 0; |
312 | case sol : return 0; |
312 | case aqueous : |
313 | case aqueous : |
313 | if (iswater() || iselectron()) return 0; |
314 | if (iswater() || iselectron()) return 0; |
314 | o << prefix << "[" << *al; |
315 | o << prefix << "[" << *al; |
Line 348... | Line 349... | ||
348 | } |
349 | } |
349 | 350 | ||
350 | fraction Molec::nbelectron()const{ |
351 | fraction Molec::nbelectron()const{ |
351 | if (iselectron()) return nb; |
352 | if (iselectron()) return nb; |
352 | else return fraction(0); |
353 | else return fraction(0); |
- | 354 | } |
|
- | 355 | ||
- | 356 | void Molec::add(fraction f){ |
|
- | 357 | nb = nb+f; |
|
- | 358 | } |
|
- | 359 | ||
- | 360 | void Molec::sub(fraction f){ |
|
- | 361 | nb = nb-f; |
|
353 | } |
362 | } |
354 | 363 | ||
355 | void Molec::printNombre(std::ostream & o)const{ |
364 | void Molec::printNombre(std::ostream & o)const{ |
356 | if (nb.d==1){ |
365 | if (nb.d==1){ |
357 | o << nb.i << "\\,"; |
366 | o << nb.i << "\\,"; |
358 | } |
367 | } |
359 | else { |
368 | else { |
360 | o << "\\frac{" << nb.i << "}{" << nb.d << "}\\,"; |
369 | o << "\\frac{" << nb.i << "}{" << nb.d << "}\\,"; |
361 | } |
370 | } |
362 | } |
371 | } |
363 | 372 | ||
364 | std::ostream & operator << (std::ostream & o, const Molec & m){ |
373 | std::ostream & operator << (std::ostream & o, const Molec & m){ |
365 | if (m.nombre() != 1) m.printNombre(o); |
374 | if (m.nombre() != 1) m.printNombre(o); |
366 | o << m.liste(); |
375 | o << m.liste(); |
367 | if (m.charge()){ |
376 | if (m.charge()){ |
368 | o << "^{"; |
377 | o << "^{"; |
369 | if(fabs(1.0*m.charge())!=1) o << fabs(1.0*m.charge()); |
378 | if(fabs(1.0*m.charge())!=1) o << fabs(1.0*m.charge()); |
370 | if(m.charge()>0) o << "+}"; else o << "-}"; |
379 | if(m.charge()>0) o << "+}"; else o << "-}"; |
371 | } |
380 | } |
372 | if (m.typage() != aqueous) o << "_{" << moltypeStr[m.typage()] << "}"; |
381 | if (m.typage() != aqueous) o << "_{" << moltypeStr[m.typage()] << "}"; |
373 | return o; |
382 | return o; |
- | 383 | } |
|
- | 384 | ||
- | 385 | int Membre::findMol(const Molec * m){ |
|
- | 386 | // returns the index of a molecule with the same atomlist if any |
|
- | 387 | // else returns -1. |
|
- | 388 | int result=-1; |
|
- | 389 | for(int i=0; i<size(); i++){ |
|
- | 390 | if ((*this)[i]->eqMol(m)) result=i; |
|
- | 391 | } |
|
- | 392 | return result; |
|
- | 393 | } |
|
- | 394 | ||
- | 395 | void Membre::addMol(const Molec * m){ |
|
- | 396 | int i = findMol(m); |
|
- | 397 | if (i < 0){ |
|
- | 398 | push_back(new Molec(*m)); |
|
- | 399 | } else { |
|
- | 400 | (*this)[i]->add(m->nombre()); |
|
- | 401 | } |
|
- | 402 | } |
|
- | 403 | ||
- | 404 | void Membre::addMembre(const Membre * m){ |
|
- | 405 | for(int i=0; i<m->size(); i++){ |
|
- | 406 | addMol((*m)[i]); |
|
- | 407 | } |
|
- | 408 | } |
|
- | 409 | ||
- | 410 | void Membre::eraseNull(){ |
|
- | 411 | Membre m(*this); |
|
- | 412 | clear(); |
|
- | 413 | for(int i=0; i < m.size();i++){ |
|
- | 414 | if (m[i]->nombre().i>0) push_back(m[i]); |
|
- | 415 | } |
|
374 | } |
416 | } |
375 | 417 | ||
376 | void Membre::compte(Compteur & c)const{ |
418 | void Membre::compte(Compteur & c)const{ |
377 | for(int i =0; i < size(); i++){ |
419 | for(int i =0; i < size(); i++){ |
378 | operator [] (i)->compte(c); |
420 | operator [] (i)->compte(c); |
Line 432... | Line 474... | ||
432 | 474 | ||
433 | void Membre::printweight(std::ostream & o) const{ |
475 | void Membre::printweight(std::ostream & o) const{ |
434 | for(int i=0; i < size(); i++){ |
476 | for(int i=0; i < size(); i++){ |
435 | o << operator[](i)->weight(); |
477 | o << operator[](i)->weight(); |
436 | if (i < size()-1) o << " "; |
478 | if (i < size()-1) o << " "; |
437 | } |
479 | } |
438 | } |
480 | } |
439 | 481 | ||
440 | void Membre::coeff( fraction f){ |
482 | void Membre::coeff( fraction f){ |
441 | for (int i=0; i<size(); i++) operator[](i)->coeff(f); |
483 | for (int i=0; i<size(); i++) operator[](i)->coeff(f); |
442 | } |
484 | } |
Line 451... | Line 493... | ||
451 | return result; |
493 | return result; |
452 | } |
494 | } |
453 | 495 | ||
454 | bool Membre::redox()const{ |
496 | bool Membre::redox()const{ |
455 | for (int i=0; i<size(); i++){ |
497 | for (int i=0; i<size(); i++){ |
456 | if ((*this)[i]->iselectron()) /* c'est un électron */ return 1; |
498 | if ((*this)[i]->iselectron()) /* c'est un électron */ return 1; |
457 | } |
499 | } |
458 | return 0; |
500 | return 0; |
459 | } |
501 | } |
460 | 502 | ||
461 | fraction Membre::nbelectron()const{ |
503 | fraction Membre::nbelectron()const{ |
Line 465... | Line 507... | ||
465 | return result; |
507 | return result; |
466 | } |
508 | } |
467 | 509 | ||
468 | void Membre::printNernst(std::ostream & o){ |
510 | void Membre::printNernst(std::ostream & o){ |
469 | bool printed = 0; |
511 | bool printed = 0; |
470 | char * prefix=""; |
512 | const char * prefix=""; |
471 | for (int i=0; i<size(); i++) { |
513 | for (int i=0; i<size(); i++) { |
472 | if (i>0) prefix="\\,"; |
514 | if (i>0) prefix="\\,"; |
473 | if (operator[](i)->printNernst(o, prefix)){ |
515 | if (operator[](i)->printNernst(o, prefix)){ |
474 | printed = 1; |
516 | printed = 1; |
475 | } |
517 | } |
Line 485... | Line 527... | ||
485 | return o; |
527 | return o; |
486 | } |
528 | } |
487 | 529 | ||
488 | Membre operator & (Membre & m1, Membre & m2){ |
530 | Membre operator & (Membre & m1, Membre & m2){ |
489 | Membre result; |
531 | Membre result; |
- | 532 | result.printnorm(std::cout); |
|
490 | fraction min(1); |
533 | fraction min(1); |
491 | for(Membre::iterator i = m1.begin(); i < m1.end(); i++){ |
534 | for(Membre::iterator i = m1.begin(); i < m1.end(); i++){ |
492 | for(Membre::iterator j = m2.begin(); j < m2.end(); j++){ |
535 | for(Membre::iterator j = m2.begin(); j < m2.end(); j++){ |
493 | if (**i == **j){ |
536 | if (**i == **j){ |
494 | Molec *m = new Molec(**i); |
537 | Molec *m = new Molec(**i); |
Line 515... | Line 558... | ||
515 | diff=(*i)->nb - (*j)->nb; |
558 | diff=(*i)->nb - (*j)->nb; |
516 | m->nb=diff; |
559 | m->nb=diff; |
517 | } |
560 | } |
518 | } |
561 | } |
519 | result.push_back(m); |
562 | result.push_back(m); |
520 | } |
563 | } |
521 | return result; |
564 | return result; |
- | 565 | } |
|
- | 566 | ||
- | 567 | bool Chemeq::valdefined()const{ |
|
- | 568 | return val > MINVAL; |
|
- | 569 | } |
|
- | 570 | ||
- | 571 | void Chemeq::addChemeq(const Chemeq * c){ |
|
- | 572 | if (valdefined() && c->valdefined()){ |
|
- | 573 | long double e1=enthalpy(), e2=c->enthalpy(); |
|
- | 574 | fraction n1=nbelectron(), n2=c->nbelectron(); |
|
- | 575 | long double e = e1+e2; |
|
- | 576 | fraction n=n1+n2; |
|
- | 577 | if (n.i==0) val=expl(-e/R/T0); |
|
- | 578 | else val=-e*n.d/n.i/Faraday; |
|
- | 579 | } else { |
|
- | 580 | val=MINVAL; |
|
- | 581 | } |
|
- | 582 | gauche->addMembre(c->gauche); |
|
- | 583 | droit->addMembre(c->droit); |
|
- | 584 | simplifie(true); |
|
- | 585 | } |
|
- | 586 | ||
- | 587 | void Chemeq::subChemeq(const Chemeq * c){ |
|
- | 588 | if (valdefined() && c->valdefined()){ |
|
- | 589 | long double e1=enthalpy(), e2=c->enthalpy(); |
|
- | 590 | fraction n1=nbelectron(), n2=c->nbelectron(); |
|
- | 591 | long double e = e1-e2; |
|
- | 592 | fraction n=n1-n2; |
|
- | 593 | if (n.i==0) { |
|
- | 594 | val=expl(-e/R/T0); |
|
- | 595 | } else{ |
|
- | 596 | val=-e*n.d/n.i/Faraday; |
|
- | 597 | } |
|
- | 598 | } else { |
|
- | 599 | val=MINVAL; |
|
- | 600 | } |
|
- | 601 | gauche->addMembre(c->droit); |
|
- | 602 | droit->addMembre(c->gauche); |
|
- | 603 | simplifie(true); |
|
- | 604 | } |
|
- | 605 | ||
- | 606 | long double Chemeq::enthalpy() const{ |
|
- | 607 | fraction n=nbelectron(); |
|
- | 608 | if (redox()){ |
|
- | 609 | return -val*n.i/n.d*Faraday; |
|
- | 610 | } else { |
|
- | 611 | return -R*T0*logl(val); |
|
- | 612 | } |
|
- | 613 | } |
|
- | 614 | ||
- | 615 | void Chemeq::simplifie(bool tri=false){ |
|
- | 616 | Membre communs(*gauche & *droit); |
|
- | 617 | if (communs.size()>0){ |
|
- | 618 | Membre * g, *d; |
|
- | 619 | g= new Membre(*gauche - communs); |
|
- | 620 | d= new Membre(*droit - communs); |
|
- | 621 | delete gauche; |
|
- | 622 | delete droit; |
|
- | 623 | gauche=g; |
|
- | 624 | droit =d; |
|
- | 625 | } |
|
- | 626 | gauche->eraseNull(); |
|
- | 627 | droit->eraseNull(); |
|
- | 628 | if (tri){ |
|
- | 629 | numerote(); |
|
- | 630 | triage(); |
|
- | 631 | } |
|
522 | } |
632 | } |
523 | 633 | ||
524 | void Chemeq::printnorm(std::ostream & o){ |
634 | void Chemeq::printnorm(std::ostream & o){ |
525 | gauche->printnorm(o); |
635 | gauche->printnorm(o); |
526 | o << " -> "; |
636 | o << " -> "; |
527 | droit->printnorm(o); |
637 | droit->printnorm(o); |
528 | if (val> |
638 | if (val>MINVAL){ |
529 | o << " ("; |
639 | o << " ("; |
530 | if (cste!=std::string("")) o << cste << " = "; |
640 | if (cste!=std::string("")) o << cste << " = "; |
531 | o << val; |
641 | o << val; |
532 | if (redox()) o << " V"; |
642 | if (redox()) o << " V"; |
533 | o << ")"; |
643 | o << ")"; |
Line 571... | Line 681... | ||
571 | void Chemeq::coeff1(){ |
681 | void Chemeq::coeff1(){ |
572 | fraction mult = gauche->operator[](0)->nombre(); |
682 | fraction mult = gauche->operator[](0)->nombre(); |
573 | mult.inverse(); |
683 | mult.inverse(); |
574 | gauche->coeff(mult); |
684 | gauche->coeff(mult); |
575 | droit->coeff(mult); |
685 | droit->coeff(mult); |
576 | Membre communs(*gauche & *droit); |
- | |
577 |
|
686 | simplifie(); |
578 |
|
687 | if (!redox()){ |
579 | g= new Membre(*gauche - communs); |
- | |
580 | d= new Membre(*droit - communs); |
- | |
581 |
|
688 | val = val*mult.i/mult.d; |
582 | delete droit; |
- | |
583 | gauche=g; |
- | |
584 | droit =d; |
- | |
585 | } |
689 | } |
- | 690 | } |
|
- | 691 | ||
- | 692 | void Chemeq::multiply(int num, int den){ |
|
- | 693 | fraction mult(num,den); |
|
- | 694 | gauche->coeff(mult); |
|
- | 695 | droit->coeff(mult); |
|
- | 696 | simplifie(); |
|
586 | if (!redox()){ |
697 | if (!redox()){ |
587 | val = val*mult.i/mult.d; |
698 | val = val*mult.i/mult.d; |
588 | } |
699 | } |
589 | } |
700 | } |
590 | 701 | ||
Line 603... | Line 714... | ||
603 | o << "}"; |
714 | o << "}"; |
604 | } |
715 | } |
605 | else { |
716 | else { |
606 | droit->printNernst(o); |
717 | droit->printNernst(o); |
607 | } |
718 | } |
608 | if (val > |
719 | if (val > MINVAL) { |
609 | o << "\\,=\\,"; |
720 | o << "\\,=\\,"; |
610 | if (cste!=std::string("")) o << cste << "\\,=\\,"; |
721 | if (cste!=std::string("")) o << cste << "\\,=\\,"; |
611 | o << |
722 | o << valeur_latex(); |
612 | } |
723 | } |
613 | else{ |
724 | else{ |
614 | o << "\\,=\\,K"; |
725 | o << "\\,=\\,K"; |
615 | } |
726 | } |
616 | } |
727 | } |
617 | else{ /* c'est une réaction redox */ |
728 | else{ /* c'est une réaction redox */ |
618 | o << "E\\,=\\,"; |
729 | o << "E\\,=\\,"; |
619 | if (val > |
730 | if (val > MINVAL) { |
620 | o << val; |
731 | o << val; |
621 | } |
732 | } |
622 | else{ |
733 | else{ |
623 | o << "E_{0}"; |
734 | o << "E_{0}"; |
624 | } |
735 | } |
625 | o << "\\,+\\,\\frac{R\\,T}{"; |
736 | o << "\\,+\\,\\frac{R\\,T}{"; |
626 | o << gauche->nbelectron()+droit->nbelectron() << "\\,F}"; |
737 | o << gauche->nbelectron()+droit->nbelectron() << "\\,F}"; |
627 | o << "\\log"; |
738 | o << "\\log"; |
628 | if (gauche->redox()){ /* c'est une réduction */ |
739 | if (gauche->redox()){ /* c'est une réduction */ |
629 | ga=gauche; dr=droit; |
740 | ga=gauche; dr=droit; |
630 | } |
741 | } |
631 | else{ /* c'est une oxydation */ |
742 | else{ /* c'est une oxydation */ |
632 | ga=droit; dr=gauche; |
743 | ga=droit; dr=gauche; |
633 | } |
744 | } |
Line 642... | Line 753... | ||
642 | o << "("; |
753 | o << "("; |
643 | ga->printNernst(o); |
754 | ga->printNernst(o); |
644 | o << ")"; |
755 | o << ")"; |
645 | } |
756 | } |
646 | } |
757 | } |
- | 758 | } |
|
- | 759 | ||
- | 760 | std::string Chemeq::valeur_latex()const{ |
|
- | 761 | std::ostringstream so; |
|
- | 762 | so << val; |
|
- | 763 | std::string s(so.str()); |
|
- | 764 | std::string::size_type epos=s.find('e',0); |
|
- | 765 | if (epos!=std::string::npos){ |
|
- | 766 | s.erase(epos,1); |
|
- | 767 | s.insert(epos,"\\times 10^{"); |
|
- | 768 | s=s+"}"; |
|
- | 769 | } |
|
- | 770 | return (std::string) s; |
|
647 | } |
771 | } |
648 | 772 | ||
649 | std::ostream & operator << (std::ostream & o, const Chemeq & c){ |
773 | std::ostream & operator << (std::ostream & o, const Chemeq & c){ |
650 | o << *c.membregauche() << "\\,\\rightarrow\\," << *c.membredroit(); |
774 | o << *c.membregauche() << "\\,\\rightarrow\\," << *c.membredroit(); |
651 | if (c.valeur() > |
775 | if (c.valeur() > MINVAL) { |
652 | o << "\\,("; |
776 | o << "\\,("; |
653 | if (c.constante()!=std::string("")) o << c.constante() << "\\,=\\,"; |
777 | if (c.constante()!=std::string("")) o << c.constante() << "\\,=\\,"; |
654 | o << c. |
778 | o << c.valeur_latex(); |
655 | if (c.redox()) o << " V"; |
779 | if (c.redox()) o << " V"; |
656 | o << ")"; |
780 | o << ")"; |
657 | } |
781 | } |
658 | return o; |
782 | return o; |
659 | } |
783 | } |
Line 691... | Line 815... | ||
691 | 815 | ||
692 | fraction operator - (fraction f, fraction g){ |
816 | fraction operator - (fraction f, fraction g){ |
693 | fraction result = fraction(f.i*g.d-g.i*f.d, f.d*g.d); |
817 | fraction result = fraction(f.i*g.d-g.i*f.d, f.d*g.d); |
694 | result.simplifie(); |
818 | result.simplifie(); |
695 | return result; |
819 | return result; |
- | 820 | } |
|
- | 821 | ||
- | 822 | const fraction & minFraction(const fraction& f1, const fraction &f2){ |
|
- | 823 | if (f1.i*f2.d > f2.i*f1.d) return f1; |
|
- | 824 | else return f2; |
|
696 | } |
825 | } |
697 | 826 | ||
698 | void fraction::simplifie(){ |
827 | void fraction::simplifie(){ |
699 | int maxprem = 23; |
828 | int maxprem = 23; |
700 | int premiers[]={2,3,5,7,11,13,17,19,23,29}; |
829 | int premiers[]={2,3,5,7,11,13,17,19,23,29}; |