Show
Ignore:
Timestamp:
05/11/08 12:53:42 (6 months ago)
Author:
rjrw
Message:

Change molecule structure to class

Make molecular column table easier to navigate (after Nick Abel's
suggestion).

Location:
branches/newmole/source
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • branches/newmole/source/molcol.cpp

    r2028 r2042  
    4747                /*  print the molecular column densities */ 
    4848                int j=0; 
     49                long heavy=-1, lastheavy=0; 
    4950                for( i=0; i < mole.num_calc; i++ ) 
    5051                { 
    5152                        if(mole.list[i]->location == NULL) 
    5253                        { 
     54                                lastheavy = heavy; 
     55                                heavy = mole.list[i]->heavyElem(); 
     56                                if(j == 8 || heavy != lastheavy) 
     57                                { 
     58                                        fprintf( ioMEAN, "\n" ); 
     59                                        if (heavy != lastheavy) 
     60                                        { 
     61                                                fprintf ( ioMEAN, "==== %-2.2s compounds ====\n",element_list[heavy]->label); 
     62                                        } 
     63                                        j = 0; 
     64                                } 
    5365                                fprintf( ioMEAN, "   %-6.6s:", mole.list[i]->label ); 
    5466                                fprintf( ioMEAN, "%7.3f",log10(MAX2(SMALLFLOAT,mole.list[i]->column ))); 
    5567                                j++;  
    56                                 fixit();  /* Separate elemental chem more clearly -- would need to refactor mole.nElem */ 
    57                                 if( j == 8 ) 
    58                                 { 
    59                                         fprintf( ioMEAN, "\n" ); 
    60                                         j = 0; 
    61                                 } 
    6268                        } 
    6369                } 
  • branches/newmole/source/mole.h

    r2028 r2042  
    77/* mole.h */ 
    88 
     9enum {CHARS_SPECIES=7}; 
    910enum mole_state {MOLE_NULL, MOLE_PASSIVE, MOLE_ACTIVE}; 
     11 
     12/* Structure containing molecule data, initially only CO */ 
     13class molecule { 
     14public: 
     15        /* Species physical data */ 
     16        char    label[CHARS_SPECIES];      /** name */ 
     17        int     nElem[LIMELM];  /** number of each element in molecule */ 
     18        int     charge;         /** Charge on species/number of e- liberated by formation */ 
     19        bool    lgExcit;        /** Is species excited (e.g. H2*) */ 
     20        bool    lgGas_Phase;    /** Solid or gas phase? */ 
     21        int     n_nuclei;       /** total number of nuclei */ 
     22        realnum *location;      /** Location of density in non-molecule code, NULL if none exists */ 
     23        realnum form_enthalpy;  /** formation enthalpy for the molecule (at 0K), in units of KJ/mol */ 
     24        realnum mole_mass;      /** Mass of molecule */ 
     25 
     26        /* Parameters as computational object */ 
     27        enum mole_state state; 
     28        int index, groupnum; 
     29 
     30        /* Current zone data */ 
     31        double  den;       /** density (cm-3) */ 
     32        realnum column;    /** total column density in this iteration */ 
     33        int     nElemLim;  /** atomic number MINUS ONE of element for which is closest to limiting molecule density */ 
     34        realnum xFracLim;  /** The fraction of that element in this species */ 
     35 
     36        /* Historical solution data */ 
     37        realnum column_old;   /** total column density in previous iteration */ 
     38 
     39        long heavyElem(void) const 
     40        { 
     41                for (long nelem=LIMELM-1;nelem>=ipHYDROGEN;nelem--) 
     42                { 
     43                        if (0 != nElem[nelem]) 
     44                        { 
     45                                return nelem; 
     46                        } 
     47                } 
     48                return -1; 
     49        } 
     50};  
    1051 
    1152/**mole_drive main driver for chemical equilibrium routines */ 
     
    2970extern double mole_findrate(const char buf[]); 
    3071 
    31 extern struct molecule *findspecies(const char buf[]); 
     72extern molecule *findspecies(const char buf[]); 
    3273 
    3374/** \verbatim >>chng 03 feb 09, rm ipH3P_hev, since not used, and decrement NUM_HEAVY_MOLEC to 17  
     
    120161        realnum ***xMoleChTrRate;/***[LIMELM][LIMELM+1][LIMELM+1];*/ 
    121162 
    122         valarray<struct molecule *> list; 
     163        valarray<molecule *> list; 
    123164 
    124165        valarray<struct molezone> zone; 
     
    131172        double src, snk; 
    132173}; 
    133  
    134 enum {CHARS_SPECIES=7}; 
    135 /* Structure containing molecule data, initially only CO */ 
    136  
    137 struct molecule { 
    138         /* Species physical data */ 
    139         char    label[CHARS_SPECIES];      /** name */ 
    140         int     nElem[LIMELM];  /** number of each element in molecule */ 
    141         int     charge;         /** Charge on species/number of e- liberated by formation */ 
    142         bool    lgExcit;        /** Is species excited (e.g. H2*) */ 
    143         bool    lgGas_Phase;    /** Solid or gas phase? */ 
    144         int     n_nuclei;       /** total number of nuclei */ 
    145         realnum *location;      /** Location of density in non-molecule code, NULL if none exists */ 
    146         realnum form_enthalpy;  /** formation enthalpy for the molecule (at 0K), in units of KJ/mol */ 
    147         realnum mole_mass;      /** Mass of molecule */ 
    148  
    149         /* Parameters as computational object */ 
    150         enum mole_state state; 
    151         int index, groupnum; 
    152  
    153         /* Current zone data */ 
    154         double  den;       /** density (cm-3) */ 
    155         realnum column;    /** total column density in this iteration */ 
    156         int     nElemLim;  /** atomic number MINUS ONE of element for which is closest to limiting molecule density */ 
    157         realnum xFracLim;  /** The fraction of that element in this species */ 
    158  
    159         /* Historical solution data */ 
    160         realnum column_old;   /** total column density in previous iteration */ 
    161 };  
    162174 
    163175extern void mole_punch(FILE *punit, const char speciesname[],  
  • branches/newmole/source/mole_eval_balance.cpp

    r2031 r2042  
    3535        double rate_tot, rate_deriv[MAXREACTANTS], rated, rk; 
    3636        char debug_name[] = ""; /* Insert name of species to print largest rates for, e.g. "CH4" */ 
    37         struct molecule *sp; 
    38         const struct molecule *debug_species = findspecies(debug_name); 
     37        molecule *sp; 
     38        const molecule *debug_species = findspecies(debug_name); 
    3939        double snkx=0.,srcx=0.; 
    4040 
  • branches/newmole/source/mole_reactions.cpp

    r2027 r2042  
    450450{ 
    451451        struct mole_reaction_s *rate; 
    452         struct molecule    *sp; 
     452        molecule    *sp; 
    453453        ratefunc func; 
    454454        mole_reaction_i p; 
     
    558558                 required (look for references to "reactants[0]" for examples) */ 
    559559        qsort((void *)rate->reactants,(size_t)rate->nreactants, 
    560                                 sizeof(struct molecule *),mole_cmp); 
     560                                sizeof(molecule *),mole_cmp); 
    561561        qsort((void *)rate->products,(size_t)rate->nproducts, 
    562                                 sizeof(struct molecule *),mole_cmp); 
     562                                sizeof(molecule *),mole_cmp); 
    563563 
    564564        ASSERT(lgReactBalance(rate)); /* Verify rate conserves particles and charge */ 
     
    16831683class formula_species { 
    16841684public: 
    1685         struct molecule *reactants[MAXREACTANTS], *products[MAXPRODUCTS]; 
     1685        molecule *reactants[MAXREACTANTS], *products[MAXPRODUCTS]; 
    16861686}; 
    16871687 
     
    17671767    } 
    17681768  } 
    1769         qsort((void *)r->l.reactants,(size_t)i,sizeof(struct molecule *), 
     1769        qsort((void *)r->l.reactants,(size_t)i,sizeof(molecule *), 
    17701770                                mole_cmp); 
    17711771 
     
    17871787    } 
    17881788  } 
    1789         qsort((void *)r->l.products,(size_t)i,sizeof(struct molecule *), 
     1789        qsort((void *)r->l.products,(size_t)i,sizeof(molecule *), 
    17901790                                mole_cmp); 
    17911791 
     
    29332933        double ratev, ratevi; 
    29342934        struct mole_reaction_s *rate; 
    2935         struct molecule *sp; 
     2935        molecule *sp; 
    29362936 
    29372937        DEBUG_ENTRY("mole_sink_rate()"); 
     
    29902990        double ratev, ratevi; 
    29912991        struct mole_reaction_s *rate; 
    2992         struct molecule *sp, *ph; 
     2992        molecule *sp, *ph; 
    29932993 
    29942994        DEBUG_ENTRY("mole_dissoc_rate()"); 
     
    30443044        double ratev, ratevi; 
    30453045        struct mole_reaction_s *rate; 
    3046         struct molecule *sp; 
     3046        molecule *sp; 
    30473047 
    30483048        DEBUG_ENTRY("mole_source_rate()"); 
     
    31403140        double ratevi; 
    31413141        struct mole_reaction_s *rate; 
    3142         struct molecule *sp; 
     3142        molecule *sp; 
    31433143 
    31443144        DEBUG_ENTRY("mole_punch()"); 
  • branches/newmole/source/mole_species.cpp

    r2027 r2042  
    5050#include <functional> 
    5151 
    52 class MoleCmp : public binary_function<const struct molecule *,const struct molecule *,bool> 
     52class MoleCmp : public binary_function<const molecule *,const molecule *,bool> 
    5353{ 
    5454public: 
    55         bool operator()(const struct molecule *mol1, const struct molecule *mol2) const 
     55        bool operator()(const molecule *mol1, const molecule *mol2) const 
    5656        { 
    5757                for (long nelem=LIMELM-1; nelem >= ipHYDROGEN; nelem--)  
    5858                { 
    5959                        if (mol1->nElem[nelem] > mol2->nElem[nelem]) 
     60                        { 
    6061                                return false; 
     62                        } 
    6163                        else if (mol1->nElem[nelem] < mol2->nElem[nelem]) 
     64                        { 
    6265                                return true;             
     66                        } 
    6367                }  
    6468                return strcmp(mol1->label,mol2->label) < 0; 
     
    7478        long int i, 
    7579                nelem; 
    76         struct molecule *sp; 
     80        molecule *sp; 
    7781        static realnum one=1.0; 
    7882        static bool lgmole_Init_called=false; 
     
    411415#include <string.h> 
    412416#include <ctype.h> 
    413 STATIC struct molecule *newspecies( 
     417STATIC molecule *newspecies( 
    414418        const char label[7],  
    415419        enum spectype type,  
     
    421425        char mylab[7], thisel[3], *s; 
    422426        long int i, n, nelem, nel; 
    423         struct molecule *mol; 
     427        molecule *mol; 
    424428        struct chem_element_s *el; 
    425429 
    426430        DEBUG_ENTRY("newspecies()"); 
    427431 
    428         mol = (struct molecule *) MALLOC(sizeof(struct molecule)); 
     432        mol = (molecule *) MALLOC(sizeof(molecule)); 
    429433 
    430434        for( nelem=ipHYDROGEN; nelem<LIMELM; ++nelem ) 
     
    568572        return mol; 
    569573} 
    570 STATIC bool isactive(struct molecule *p) 
     574STATIC bool isactive(molecule *p) 
    571575{ 
    572576        DEBUG_ENTRY("isactive()"); 
    573577        return p->state == MOLE_ACTIVE; 
    574578} 
    575 STATIC bool ispassive(struct molecule *p) 
     579STATIC bool ispassive(molecule *p) 
    576580{ 
    577581 
     
    580584} 
    581585 
    582 struct molecule *findspecies(const char buf[]) 
     586molecule *findspecies(const char buf[]) 
    583587{ 
    584588        molecule_i p; 
     
    745749{ 
    746750        long int nelem; 
    747         struct molecule *mol1=*(struct molecule **)m1, *mol2=*(struct molecule **)m2; 
     751        molecule *mol1=*(molecule **)m1, *mol2=*(molecule **)m2; 
    748752 
    749753        for (nelem=LIMELM-1; nelem >= ipHYDROGEN; nelem--)  
     
    844848                return; 
    845849        } 
    846         groupspecies = (struct molecule **) MALLOC(mole.num_calc*sizeof(struct molecule *)); 
     850        groupspecies = (molecule **) MALLOC(mole.num_calc*sizeof(molecule *)); 
    847851        for (i=0,j=0;i<mole.num_calc;i++)  
    848852        { 
     
    862866        } 
    863867        mole.num_compacted = j; 
    864         groupspecies = (struct molecule **) REALLOC((void *)groupspecies, 
    865                 mole.num_calc*sizeof(struct molecule *)); 
     868        groupspecies = (molecule **) REALLOC((void *)groupspecies, 
     869                mole.num_calc*sizeof(molecule *)); 
    866870 
    867871        for (i=0;i<mole.num_calc;i++)  
  • branches/newmole/source/nemala2.cpp

    r2023 r2042  
    4343                if( lgSpeciesMolecule[i] ) 
    4444                { 
    45                         struct molecule *SpeciesCurrent; 
     45                        molecule *SpeciesCurrent; 
    4646                        /** \todo       0       this pointer should be cached one time, and the species 
    4747                         * removed from the list if it is not computed */