Subversion Repositories wimsdev

Rev

Rev 17747 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 17747 Rev 17770
Line 301... Line 301...
301
    if(ch>0) o << "+"; else o << "-";
301
    if(ch>0) o << "+"; else o << "-";
302
  }
302
  }
303
  // the aqueous type is the default, so: no _(aq)
303
  // the aqueous type is the default, so: no _(aq)
304
  // to have this suffix, on must make the type to aqueous_explicit
304
  // to have this suffix, on must make the type to aqueous_explicit
305
  if (!iswater() && !iselectron() && t != aqueous) o << "_"  << moltypeStr[t];
305
  if (!iswater() && !iselectron() && t != aqueous) o << "_"  << moltypeStr[t];
-
 
306
}
-
 
307
 
-
 
308
/**
-
 
309
 * Affiche le coefficient stœchimétrique
-
 
310
 * @param o un flux de sortie
-
 
311
 * @param sign plus ou moins un selon que c'est un produit ou un réactif.
-
 
312
 **/
-
 
313
void Molec::printcoeff(std::ostream & o, int sign)const{
-
 
314
  o << nb * sign;
306
}
315
}
307
 
316
 
308
void Molec::coeff( fraction f){
317
void Molec::coeff( fraction f){
309
  nb.i *= f.i;
318
  nb.i *= f.i;
310
  nb.d *= f.d;
319
  nb.d *= f.d;
Line 325... Line 334...
325
      if(fabs(1.0*ch)!=1) o << fabs(1.0*ch);
334
      if(fabs(1.0*ch)!=1) o << fabs(1.0*ch);
326
      if(ch>0) o << "+}"; else o << "-}";
335
      if(ch>0) o << "+}"; else o << "-}";
327
    }
336
    }
328
    if (t != aqueous) o << "_{" << moltypeStr[t] << "}";
337
    if (t != aqueous) o << "_{" << moltypeStr[t] << "}";
329
    o  <<"]";
338
    o  <<"]";
330
    if (nb!=1) {
339
    if (nb!=1) {
331
      o << "^{";
340
      o << "^{";
332
      printNombre(o);
341
      printNombre(o);
333
      o << "}";
342
      o << "}";
334
    }
343
    }
335
    return 1;
344
    return 1;
336
  case gas :
345
  case gas :
337
    o << prefix << "P_{" << *al << "}";
346
    o << prefix << "P_{" << *al << "}";
338
    if (nb!=1) {
347
    if (nb!=1) {
339
      o << "^{";
348
      o << "^{";
340
      printNombre(o);
349
      printNombre(o);
341
      o << "}";
350
      o << "}";
342
    }
351
    }
343
    return 1;
352
    return 1;
344
  }
353
  }
345
  return 0;
354
  return 0;
346
}
355
}
347
 
356
 
Line 357... Line 366...
357
    }
366
    }
358
  case aqueous :
367
  case aqueous :
359
  case aqueous_explicit :
368
  case aqueous_explicit :
360
    if(wantedlatex){
369
    if(wantedlatex){
361
      o <<  "[" << *al;
370
      o <<  "[" << *al;
362
    }else{
371
    }else{
363
      o << "["; al->printnorm(o);
372
      o << "["; al->printnorm(o);
364
    }
373
    }
365
    if (ch){
374
    if (ch){
366
      if(wantedlatex){
375
      if(wantedlatex){
367
        o << "^{";
376
        o << "^{";
Line 371... Line 380...
371
      if(fabs(1.0*ch)!=1) o << fabs(1.0*ch);
380
      if(fabs(1.0*ch)!=1) o << fabs(1.0*ch);
372
      if(wantedlatex){
381
      if(wantedlatex){
373
        if(ch>0) o << "+}"; else o << "-}";
382
        if(ch>0) o << "+}"; else o << "-}";
374
      }else{
383
      }else{
375
        if(ch>0) o << "+"; else o << "-";
384
        if(ch>0) o << "+"; else o << "-";
376
      }
385
      }
377
    }
386
    }
378
    o  <<"]";
387
    o  <<"]";
379
    if (nb!=1) {
388
    if (nb!=1) {
380
      if(wantedlatex){
389
      if(wantedlatex){
381
        o << "^{";
390
        o << "^{";
382
        if (nb.d==1){
391
        if (nb.d==1){
383
          o << nb.i ;
392
          o << nb.i ;
384
        }
393
        }
385
        else {
394
        else {
386
          o << "\\frac{" << nb.i << "}{" << nb.d << "}";
395
          o << "\\frac{" << nb.i << "}{" << nb.d << "}";
387
        }
396
        }
388
        o << "}";
397
        o << "}";
389
      }else{
398
      }else{
390
        o << "^" << nb;
399
        o << "^" << nb;
391
      }
400
      }
392
    }
401
    }
393
    return true;
402
    return true;
394
  case gas :
403
  case gas :
395
    if(wantedlatex){
404
    if(wantedlatex){
Line 412... Line 421...
412
      }
421
      }
413
    }
422
    }
414
    return true;
423
    return true;
415
  }
424
  }
416
  return false;
425
  return false;
417
}
426
}
418
 
427
 
419
bool Molec::iswater()const{
428
bool Molec::iswater()const{
420
  if (t != aqueous) return 0;
429
  if (t != aqueous) return 0;
421
  if (signature()==std::string("\\mathrm{H}_{2}\\mathrm{O}") ||
430
  if (signature()==std::string("\\mathrm{H}_{2}\\mathrm{O}") ||
422
      signature()==std::string("\\mathrm{O}\\mathrm{H}_{2}")) return 1;
431
      signature()==std::string("\\mathrm{O}\\mathrm{H}_{2}")) return 1;
Line 444... Line 453...
444
  if (nb.d==1){
453
  if (nb.d==1){
445
    o << nb.i << "\\,";
454
    o << nb.i << "\\,";
446
  }
455
  }
447
  else {
456
  else {
448
    o << "\\frac{" << nb.i << "}{" << nb.d << "}\\,";
457
    o << "\\frac{" << nb.i << "}{" << nb.d << "}\\,";
449
  }
458
  }
450
}
459
}
451
 
460
 
452
std::ostream & operator << (std::ostream & o, const Molec & m){
461
std::ostream & operator << (std::ostream & o, const Molec & m){
453
  if (m.nombre() != 1) m.printNombre(o);
462
  if (m.nombre() != 1) m.printNombre(o);
454
  o << m.liste();
463
  o << m.liste();
455
  if (m.charge()){
464
  if (m.charge()){
Line 465... Line 474...
465
  // returns the index of a molecule with the same atomlist if any
474
  // returns the index of a molecule with the same atomlist if any
466
  // else returns -1.
475
  // else returns -1.
467
  int result=-1;
476
  int result=-1;
468
  for(unsigned int i=0; i<size(); i++){
477
  for(unsigned int i=0; i<size(); i++){
469
    if ((*this)[i]->eqMol(m)) result=i;
478
    if ((*this)[i]->eqMol(m)) result=i;
470
  }
479
  }
471
  return result;
480
  return result;
472
}
481
}
473
 
482
 
474
void Membre::addMol(const Molec * m){
483
void Membre::addMol(const Molec * m){
475
  int i = findMol(m);
484
  int i = findMol(m);
476
  if (i < 0){
485
  if (i < 0){
477
    push_back(new Molec(*m));
486
    push_back(new Molec(*m));
Line 553... Line 562...
553
 
562
 
554
void Membre::printnorm(std::ostream & o) const{
563
void Membre::printnorm(std::ostream & o) const{
555
  for(unsigned int i=0; i < size(); i++){
564
  for(unsigned int i=0; i < size(); i++){
556
    operator[](i)->printnorm(o);
565
    operator[](i)->printnorm(o);
557
    if (i < size()-1) o << " + ";
566
    if (i < size()-1) o << " + ";
-
 
567
  }
-
 
568
}
-
 
569
 
-
 
570
/**
-
 
571
 * affiche les coefficients stœchiométriques d'un membre d'équation
-
 
572
 * @param o un flux de sortie
-
 
573
 * @param sign la valeur plus ou moins un selon que les réactifs sont produits
-
 
574
 *             ou consommés.
-
 
575
 **/
-
 
576
void Membre::printcoeff(std::ostream & o, int sign) const{
-
 
577
  for(unsigned int i=0; i < size(); i++){
-
 
578
    operator[](i)->printcoeff(o, sign);
-
 
579
    if (i < size()-1) o << ",";
558
  }
580
  }
559
}
581
}
560
 
582
 
561
void Membre::printweight(std::ostream & o) const{
583
void Membre::printweight(std::ostream & o) const{
562
  for(unsigned int i=0; i < size(); i++){
584
  for(unsigned int i=0; i < size(); i++){
Line 632... Line 654...
632
 
654
 
633
Membre operator & (Membre & m1, Membre & m2){
655
Membre operator & (Membre & m1, Membre & m2){
634
  Membre result;
656
  Membre result;
635
  //result.printnorm(std::cout);
657
  //result.printnorm(std::cout);
636
  fraction min(1);
658
  fraction min(1);
637
  for(Membre::iterator i = m1.begin(); i < m1.end(); i++){
659
  for(Membre::iterator i = m1.begin(); i < m1.end(); i++){
638
    for(Membre::iterator j = m2.begin(); j < m2.end(); j++){
660
    for(Membre::iterator j = m2.begin(); j < m2.end(); j++){
639
      if ((*i)->eqMol(*j)){
661
      if ((*i)->eqMol(*j)){
640
        Molec *m = new Molec(**i);
662
        Molec *m = new Molec(**i);
641
        if ((*i)->nb > (*j)->nb){
663
        if ((*i)->nb > (*j)->nb){
642
          min=(*j)->nb;
664
          min=(*j)->nb;
Line 743... Line 765...
743
    if (cste!=std::string("")) o << cste << " = ";
765
    if (cste!=std::string("")) o << cste << " = ";
744
    o << val;
766
    o << val;
745
    if (redox()) o << " V";
767
    if (redox()) o << " V";
746
    o << ")";
768
    o << ")";
747
  }
769
  }
-
 
770
}
-
 
771
 
-
 
772
/**
-
 
773
 * Affiche les coefficients stœchiométriques
-
 
774
 **/
-
 
775
void Chemeq::printcoeff(std::ostream & o) const {
-
 
776
  gauche->printcoeff(o, -1);
-
 
777
  o << ";";
-
 
778
  droit->printcoeff(o, 1);
748
}
779
}
749
 
780
 
750
void Chemeq::printcount(std::ostream & o) const {
781
void Chemeq::printcount(std::ostream & o) const {
751
  gauche->printcount(o);
782
  gauche->printcount(o);
752
  o << "; ";
783
  o << "; ";