Rev 13121 | Rev 17747 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 13121 | Rev 13325 | ||
---|---|---|---|
Line 138... | Line 138... | ||
138 | std::ostream & operator << (std::ostream & o, const Compteur & c){ |
138 | std::ostream & operator << (std::ostream & o, const Compteur & c){ |
139 | return c.operator << (o); |
139 | return c.operator << (o); |
140 | } |
140 | } |
141 | 141 | ||
142 | double AtomeListe::weight(fraction mult)const{ |
142 | double AtomeListe::weight(fraction mult)const{ |
143 |
|
143 | // const AtomeListe * al; |
144 | double w=0.0; |
144 | double w=0.0; |
145 | if(Zed!=0 && Zed!=-1 ){ /* cas où ce n'est pas un groupe ou un électron */ |
145 | if(Zed!=0 && Zed!=-1 ){ /* cas où ce n'est pas un groupe ou un électron */ |
146 | w=mendelweight(symb)*nb*mult.i/mult.d; |
146 | w=mendelweight(symb)*nb*mult.i/mult.d; |
147 | } |
147 | } |
148 | else if (Zed==0){ /* cas d'un groupe */ |
148 | else if (Zed==0){ /* cas d'un groupe */ |
Line 151... | Line 151... | ||
151 | if (suiv) w+=suiv->weight(mult); |
151 | if (suiv) w+=suiv->weight(mult); |
152 | return w; |
152 | return w; |
153 | } |
153 | } |
154 | 154 | ||
155 | void AtomeListe::compte(Compteur &c, fraction mult)const{ |
155 | void AtomeListe::compte(Compteur &c, fraction mult)const{ |
156 |
|
156 | // const AtomeListe * al; |
157 | if(Zed!=0 && Zed!=-1 ){ /* cas où ce n'est pas un groupe ou un électron */ |
157 | if(Zed!=0 && Zed!=-1 ){ /* cas où ce n'est pas un groupe ou un électron */ |
158 | std::string key(symb); |
158 | std::string key(symb); |
159 | c[key] +=1.0*nb*mult.i/mult.d; |
159 | c[key] +=1.0*nb*mult.i/mult.d; |
160 | } |
160 | } |
161 | else if (Zed==0){ /* cas d'un groupe */ |
161 | else if (Zed==0){ /* cas d'un groupe */ |
Line 163... | Line 163... | ||
163 | } |
163 | } |
164 | if (suiv) suiv->compte(c,mult); |
164 | if (suiv) suiv->compte(c,mult); |
165 | } |
165 | } |
166 | 166 | ||
167 | void AtomeListe::numerote(int n){ |
167 | void AtomeListe::numerote(int n){ |
168 | if(Zed!=0){ /* cas où ce n'est pas un groupe */ |
168 | if(Zed!=0){ /* cas où ce n'est pas un groupe */ |
169 | no = n; |
169 | no = n; |
170 | } |
170 | } |
171 | else if (Zed==0){ /* cas d'un groupe */ |
171 | else if (Zed==0){ /* cas d'un groupe */ |
172 | no = n; |
172 | no = n; |
173 | if (group) group->numerote(); |
173 | if (group) group->numerote(); |
174 | } |
174 | } |
175 | if (suiv) suiv->numerote(n+1); |
175 | if (suiv) suiv->numerote(n+1); |
176 | } |
176 | } |
177 | 177 | ||
178 | AtomeListe * AtomeListe::triage(AtomeListe * al){ |
178 | AtomeListe * AtomeListe::triage(AtomeListe * al){ |
179 | AtomeListe * al1; |
179 | AtomeListe * al1; |
180 | if(al->Z()!=0){ /* cas où ce n'est pas un groupe */ |
180 | if(al->Z()!=0){ /* cas où ce n'est pas un groupe */ |
181 | if (al->suiv){ |
181 | if (al->suiv){ |
182 | al->suiv = triage(al->suiv); |
182 | al->suiv = triage(al->suiv); |
183 | } |
183 | } |
184 | while (al->suiv && al->suiv->Zed!=0 && |
184 | while (al->suiv && al->suiv->Zed!=0 && |
185 | strcmp(al->symbole(), al->suiv->symbole()) > 1){ |
185 | strcmp(al->symbole(), al->suiv->symbole()) > 1){ |
186 | al1=al; al=al->suiv; al1->suiv=al->suiv; al->suiv=triage(al1); |
186 | al1=al; al=al->suiv; al1->suiv=al->suiv; al->suiv=triage(al1); |
187 | } |
187 | } |
188 | } |
188 | } |
189 | else{ /* cas d'un groupe */ |
189 | else{ /* cas d'un groupe */ |
190 | if (al->groupe()) al->groupe(triage(al->groupe())); |
190 | if (al->groupe()) al->groupe(triage(al->groupe())); |
191 | } |
191 | } |
192 | return al; |
192 | return al; |
193 | } |
193 | } |
194 | 194 | ||
195 | bool AtomeListe::isEqual(const AtomeListe & a2) const { |
195 | bool AtomeListe::isEqual(const AtomeListe & a2) const { |
196 | std::stringstream s1, s2; |
196 | std::stringstream s1, s2; |
197 | printnorm(s1); |
197 | printnorm(s1); |
198 | a2.printnorm(s2); |
198 | a2.printnorm(s2); |
199 | return s1.str() == s2.str(); |
199 | return s1.str() == s2.str(); |
Line 261... | Line 261... | ||
261 | if (t != aqueous) o << moltypeStr[t]; |
261 | if (t != aqueous) o << moltypeStr[t]; |
262 | return std::string (o.str()); |
262 | return std::string (o.str()); |
263 | } |
263 | } |
264 | 264 | ||
265 | bool Molec::printcount(std::ostream & o, bool first) const{ |
265 | bool Molec::printcount(std::ostream & o, bool first) const{ |
266 | if (!first) o << ", "; |
266 | if (!first) o << ", "; |
267 | first=false; |
267 | first=false; |
268 | printnorm(o); |
268 | printnorm(o); |
269 | o << '|'; |
269 | o << '|'; |
270 | al-> printcount(o,nb); |
270 | al-> printcount(o,nb); |
271 | return first; |
271 | return first; |
272 | } |
272 | } |
273 | 273 | ||
274 | bool Molec::printelec(std::ostream & o, bool first) const{ |
274 | bool Molec::printelec(std::ostream & o, bool first) const{ |
Line 306... | Line 306... | ||
306 | nb.simplifie(); |
306 | nb.simplifie(); |
307 | } |
307 | } |
308 | 308 | ||
309 | bool Molec::printNernst(std::ostream & o, const char * prefix){ |
309 | bool Molec::printNernst(std::ostream & o, const char * prefix){ |
310 | switch(t){ |
310 | switch(t){ |
- | 311 | case sol : |
|
- | 312 | case liquid: |
|
311 |
|
313 | return 0; |
312 | case aqueous : |
314 | case aqueous : |
- | 315 | case aqueous_explicit: |
|
313 | if (iswater() || iselectron()) return 0; |
316 | if (iswater() || iselectron()) return 0; |
314 | o << prefix << "[" << *al; |
317 | o << prefix << "[" << *al; |
315 | if (ch){ |
318 | if (ch){ |
316 | o << "^{"; |
319 | o << "^{"; |
317 | if(fabs(1.0*ch)!=1) o << fabs(1.0*ch); |
320 | if(fabs(1.0*ch)!=1) o << fabs(1.0*ch); |
Line 332... | Line 335... | ||
332 | printNombre(o); |
335 | printNombre(o); |
333 | o << "}"; |
336 | o << "}"; |
334 | } |
337 | } |
335 | return 1; |
338 | return 1; |
336 | } |
339 | } |
- | 340 | return 0; |
|
337 | } |
341 | } |
338 | 342 | ||
339 | bool Molec::printNernstWIMS(std::ostream & o, bool wantedlatex){ |
343 | bool Molec::printNernstWIMS(std::ostream & o, bool wantedlatex){ |
340 | if (iswater() || iselectron()) { |
344 | if (iswater() || iselectron()) { |
341 | return false; |
345 | return false; |
342 | } |
346 | } |
343 | switch(t){ |
347 | switch(t){ |
344 | case sol : |
348 | case sol : |
- | 349 | case liquid : |
|
- | 350 | { |
|
345 | return false; |
351 | return false; |
346 | } |
352 | } |
347 | case aqueous : |
353 | case aqueous : |
- | 354 | case aqueous_explicit : |
|
348 | if(wantedlatex){ |
355 | if(wantedlatex){ |
349 | o << "[" << *al; |
356 | o << "[" << *al; |
350 | }else{ |
357 | }else{ |
351 | o << "["; al->printnorm(o); |
358 | o << "["; al->printnorm(o); |
352 | } |
359 | } |
Line 451... | Line 458... | ||
451 | 458 | ||
452 | int Membre::findMol(const Molec * m){ |
459 | int Membre::findMol(const Molec * m){ |
453 | // returns the index of a molecule with the same atomlist if any |
460 | // returns the index of a molecule with the same atomlist if any |
454 | // else returns -1. |
461 | // else returns -1. |
455 | int result=-1; |
462 | int result=-1; |
456 | for(int i=0; i<size(); i++){ |
463 | for(unsigned int i=0; i<size(); i++){ |
457 | if ((*this)[i]->eqMol(m)) result=i; |
464 | if ((*this)[i]->eqMol(m)) result=i; |
458 | } |
465 | } |
459 | return result; |
466 | return result; |
460 | } |
467 | } |
461 | 468 | ||
Line 467... | Line 474... | ||
467 | (*this)[i]->add(m->nombre()); |
474 | (*this)[i]->add(m->nombre()); |
468 | } |
475 | } |
469 | } |
476 | } |
470 | 477 | ||
471 | void Membre::addMembre(const Membre * m){ |
478 | void Membre::addMembre(const Membre * m){ |
472 | for(int i=0; i<m->size(); i++){ |
479 | for(unsigned int i=0; i<m->size(); i++){ |
473 | addMol((*m)[i]); |
480 | addMol((*m)[i]); |
474 | } |
481 | } |
475 | } |
482 | } |
476 | 483 | ||
477 | void Membre::eraseNull(){ |
484 | void Membre::eraseNull(){ |
478 | Membre m(*this); |
485 | Membre m(*this); |
479 | clear(); |
486 | clear(); |
480 | for(int i=0; i < m.size();i++){ |
487 | for(unsigned int i=0; i < m.size();i++){ |
481 | if (m[i]->nombre().i>0) push_back(m[i]); |
488 | if (m[i]->nombre().i>0) push_back(m[i]); |
482 | } |
489 | } |
483 | } |
490 | } |
484 | 491 | ||
485 | void Membre::compte(Compteur & c)const{ |
492 | void Membre::compte(Compteur & c)const{ |
486 | for(int i =0; i < size(); i++){ |
493 | for(unsigned int i =0; i < size(); i++){ |
487 | operator [] (i)->compte(c); |
494 | operator [] (i)->compte(c); |
488 | } |
495 | } |
489 | } |
496 | } |
490 | 497 | ||
491 | void Membre::numerote(){ |
498 | void Membre::numerote(){ |
492 | for (int i=0; i < size(); i++){ |
499 | for (unsigned int i=0; i < size(); i++){ |
493 | operator [](i)->numero(i); |
500 | operator [](i)->numero(i); |
494 | operator [](i)->liste().numerote(); |
501 | operator [](i)->liste().numerote(); |
495 | } |
502 | } |
496 | } |
503 | } |
497 | 504 | ||
498 | void Membre::triage(){ |
505 | void Membre::triage(){ |
499 | int i,j; |
506 | unsigned int i,j; |
500 | for (i=0; i < size(); i++){ |
507 | for (i=0; i < size(); i++){ |
501 | operator [](i)->triage(); |
508 | operator [](i)->triage(); |
502 | } |
509 | } |
503 | for (i=0; i < size(); i++){ |
510 | for (i=0; i < size(); i++){ |
504 | for (j=i+1; j < size(); j++){ |
511 | for (j=i+1; j < size(); j++){ |
Line 511... | Line 518... | ||
511 | } |
518 | } |
512 | } |
519 | } |
513 | 520 | ||
514 | void Membre::printcount(std::ostream & o) const{ |
521 | void Membre::printcount(std::ostream & o) const{ |
515 | bool first=true; |
522 | bool first=true; |
516 | for(int i=0; i < size(); i++){ |
523 | for(unsigned int i=0; i < size(); i++){ |
517 | first=operator[](i)->printcount(o,first); |
524 | first=operator[](i)->printcount(o,first); |
518 | } |
525 | } |
519 | } |
526 | } |
520 | 527 | ||
521 | void Membre::printelec(std::ostream & o) const{ |
528 | void Membre::printelec(std::ostream & o) const{ |
522 | bool first=true; |
529 | bool first=true; |
523 | for(int i=0; i < size(); i++){ |
530 | for(unsigned int i=0; i < size(); i++){ |
524 | first=operator[](i)->printelec(o,first); |
531 | first=operator[](i)->printelec(o,first); |
525 | } |
532 | } |
526 | } |
533 | } |
527 | 534 | ||
528 | void Membre::printspecies(std::ostream & o) const{ |
535 | void Membre::printspecies(std::ostream & o) const{ |
529 | bool first=true; |
536 | bool first=true; |
530 | for(int i=0; i < size(); i++){ |
537 | for(unsigned int i=0; i < size(); i++){ |
531 | first=operator[](i)->printspecies(o,first); |
538 | first=operator[](i)->printspecies(o,first); |
532 | } |
539 | } |
533 | } |
540 | } |
534 | 541 | ||
535 | void Membre::printnorm(std::ostream & o) const{ |
542 | void Membre::printnorm(std::ostream & o) const{ |
536 | for(int i=0; i < size(); i++){ |
543 | for(unsigned int i=0; i < size(); i++){ |
537 | operator[](i)->printnorm(o); |
544 | operator[](i)->printnorm(o); |
538 | if (i < size()-1) o << " + "; |
545 | if (i < size()-1) o << " + "; |
539 | } |
546 | } |
540 | } |
547 | } |
541 | 548 | ||
542 | void Membre::printweight(std::ostream & o) const{ |
549 | void Membre::printweight(std::ostream & o) const{ |
543 | for(int i=0; i < size(); i++){ |
550 | for(unsigned int i=0; i < size(); i++){ |
544 | o << operator[](i)->weight(); |
551 | o << operator[](i)->weight(); |
545 | if (i < size()-1) o << " "; |
552 | if (i < size()-1) o << " "; |
546 | } |
553 | } |
547 | } |
554 | } |
548 | 555 | ||
549 | void Membre::coeff( fraction f){ |
556 | void Membre::coeff( fraction f){ |
550 | for (int i=0; i<size(); i++) operator[](i)->coeff(f); |
557 | for (unsigned int i=0; i<size(); i++) operator[](i)->coeff(f); |
551 | } |
558 | } |
552 | 559 | ||
553 | int Membre::printableNernst(){ |
560 | int Membre::printableNernst(){ |
554 | int result=0; |
561 | int result=0; |
555 | for (int i=0; i<size(); i++) { |
562 | for (unsigned int i=0; i<size(); i++) { |
556 | if (operator[](i)->typage() != sol && |
563 | if (operator[](i)->typage() != sol && |
557 | !operator[](i)->iswater() && |
564 | !operator[](i)->iswater() && |
558 | !operator[](i)->iselectron()) result =1; |
565 | !operator[](i)->iselectron()) result =1; |
559 | } |
566 | } |
560 | return result; |
567 | return result; |
561 | } |
568 | } |
562 | 569 | ||
563 | bool Membre::redox()const{ |
570 | bool Membre::redox()const{ |
564 | for (int i=0; i<size(); i++){ |
571 | for (unsigned int i=0; i<size(); i++){ |
565 | if ((*this)[i]->iselectron()) /* c'est un électron */ return 1; |
572 | if ((*this)[i]->iselectron()) /* c'est un électron */ return 1; |
566 | } |
573 | } |
567 | return 0; |
574 | return 0; |
568 | } |
575 | } |
569 | 576 | ||
570 | fraction Membre::nbelectron()const{ |
577 | fraction Membre::nbelectron()const{ |
571 | fraction result(0); |
578 | fraction result(0); |
572 | 579 | ||
573 | for(int i = 0; i<size(); i++) result=result+(*this)[i]->nbelectron(); |
580 | for(unsigned int i = 0; i<size(); i++) result=result+(*this)[i]->nbelectron(); |
574 | return result; |
581 | return result; |
575 | } |
582 | } |
576 | 583 | ||
577 | void Membre::printNernst(std::ostream & o){ |
584 | void Membre::printNernst(std::ostream & o){ |
578 | bool printed = 0; |
585 | bool printed = 0; |
579 | const char * prefix=""; |
586 | const char * prefix=""; |
580 | for (int i=0; i<size(); i++) { |
587 | for (unsigned int i=0; i<size(); i++) { |
581 | if (i>0) prefix="\\,"; |
588 | if (i>0) prefix="\\,"; |
582 | if (operator[](i)->printNernst(o, prefix)){ |
589 | if (operator[](i)->printNernst(o, prefix)){ |
583 | printed = 1; |
590 | printed = 1; |
584 | } |
591 | } |
585 | } |
592 | } |
Line 587... | Line 594... | ||
587 | } |
594 | } |
588 | 595 | ||
589 | void Membre::printNernstWIMS(std::ostream & o, bool wantedlatex){ |
596 | void Membre::printNernstWIMS(std::ostream & o, bool wantedlatex){ |
590 | bool printed = false; |
597 | bool printed = false; |
591 | bool addcomma = false; |
598 | bool addcomma = false; |
592 | for (int i=0; i<size(); i++) { |
599 | for (unsigned int i=0; i<size(); i++) { |
593 | std::ostringstream w; |
600 | std::ostringstream w; |
594 | if (operator[](i)->printNernstWIMS(w,wantedlatex)){ |
601 | if (operator[](i)->printNernstWIMS(w,wantedlatex)){ |
595 | if (addcomma) o << ", "; |
602 | if (addcomma) o << ", "; |
596 | o << w.str(); |
603 | o << w.str(); |
597 | printed = true; |
604 | printed = true; |
Line 602... | Line 609... | ||
602 | } |
609 | } |
603 | if (!printed) o << "1"; |
610 | if (!printed) o << "1"; |
604 | } |
611 | } |
605 | 612 | ||
606 | std::ostream & operator << (std::ostream & o, const Membre & m){ |
613 | std::ostream & operator << (std::ostream & o, const Membre & m){ |
607 | for(int i=0; i < m.size()-1; i++){ |
614 | for(unsigned int i=0; i < m.size()-1; i++){ |
608 | o << *m[i] << "\\,+\\,"; |
615 | o << *m[i] << "\\,+\\,"; |
609 | } |
616 | } |
610 | o << *m[m.size()-1]; |
617 | o << *m[m.size()-1]; |
611 | return o; |
618 | return o; |
612 | } |
619 | } |