Example #1
0
        public tempprops getparams(double temp)
        {
            int ind1, ind2;

            //Find the temperature in the list
            for (ind1 = 0; ind1 < properties.Count && properties[ind1].temp < temp; ind1++)
            {
                ;
            }
            //Find the indices which we interpolate with
            if (ind1 == properties.Count)
            {
                ind2  = ind1 - 1;
                ind1 -= 2;
            }
            else if (ind1 == 0)
            {
                ind2 = 1;
            }
            else if (ind1 == properties.Count - 1)
            {
                ind2 = ind1 - 1;
            }
            else
            {
                ind2 = ind1;
                ind1--;
            }
            tempprops prop = properties[ind1].interpolate(properties[ind2], temp);

            //No real point of the following
            //properties.Insert(ind2, prop);
            return(prop);
        }
Example #2
0
            public tempprops interpolate(tempprops bound, double temp)
            {
                tempprops t    = new tempprops();
                double    rinc = bound.resist - resist;
                double    sinc = bound.spheat - spheat;

                rinc    /= bound.temp - this.temp;
                sinc    /= bound.temp - this.temp;
                t.resist = rinc * (temp - this.temp) + resist;
                t.spheat = sinc * (temp - this.temp) + spheat;
                t.temp   = temp;
                return(t);
            }
Example #3
0
        //Returns false when done simulating
        public bool simstep()
        {
            tempprops prop       = getparams(temp);
            double    resistance = prop.resist * length / area * 0.001;
            double    current    = volts / resistance;
            double    heat       = current * volts;

            outf.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8}",
                           time, temp, charge, volts, current, resistance, prop.resist, heat * TIME_STEP, prop.spheat);
            temp   += heat * TIME_STEP / prop.spheat / mass;
            charge -= current * TIME_STEP;
            volts   = charge / farads;
            time   += TIME_STEP;
            return((heat > MIN_HEAT) && (MAX_TEMP > 0 ? (temp < MAX_TEMP) : true));
        }
Example #4
0
        public void simulate()
        {
            double heat;

            temp = INITIAL_TEMP;
            time = 0.0;
            outf.WriteLine("Time (s),Temperature (K),Charge (C),Voltage (V),Current (A),Resistance (Ohm),Resistivity (uOhm*cm),Heat (J),Specific Heat (J/kg/K)");
            do
            {
                tempprops prop       = getparams(temp);
                double    resistance = prop.resist * length / area * 0.00001;
                double    current    = volts / resistance;
                heat = current * volts;
                outf.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8}",
                               time, temp, charge, volts, current, resistance, prop.resist, heat * TIME_STEP, prop.spheat);
                temp   += heat * TIME_STEP / prop.spheat / mass;
                charge -= current * TIME_STEP;
                volts   = charge / farads;
                time   += TIME_STEP;
            } while (heat > MIN_HEAT && temp < MAX_TEMP);
            outf.Close();
        }
Example #5
0
 public tempprops interpolate(tempprops bound, double temp)
 {
     tempprops t = new tempprops();
     double rinc = bound.resist - resist;
     double sinc = bound.spheat - spheat;
     rinc /= bound.temp - this.temp;
     sinc /= bound.temp - this.temp;
     t.resist = rinc * (temp - this.temp) + resist;
     t.spheat = sinc * (temp - this.temp) + spheat;
     t.temp = temp;
     return t;
 }
Example #6
0
        private void parseinf()
        {
            int index = 0;

            while (!inf.EndOfStream)
            {
                tempprops temp;
                string[]  line = inf.ReadLine().Split(',');
                temp.temp   = double.Parse(line[0]);
                temp.resist = double.Parse(line[1]);
                temp.spheat = double.Parse(line[2]);
                properties.Insert(index, temp);
                index++;
            }
            //Interpolate the front of the list for specific heats
            if (properties[0].spheat == 0)
            {
                //Find the first non-zero element
                for (index = 0; index < properties.Count && properties[index].spheat == 0; index++)
                {
                    ;
                }
                int first = index;
                //Find the second non-zero element
                for (index++; index < properties.Count && properties[index].spheat == 0; index++)
                {
                    ;
                }
                int       second = index;
                tempprops lhs    = properties[first];
                tempprops rhs    = properties[second];
                for (index = second - 1; index >= 0; index--)
                {
                    tempprops buf = lhs.interpolate(rhs, properties[index].temp);
                    if (properties[index].spheat != 0)
                    {
                        buf.spheat = properties[index].spheat;
                    }
                    properties[index] = buf;
                }
            }
            //Interpolate the back of the specific heats
            if (properties[properties.Count - 1].spheat == 0)
            {
                //Find the last non-zero element
                for (index = properties.Count - 1; index > 0 && properties[index].spheat == 0; index--)
                {
                    ;
                }
                int last = index;
                //Find the previous non-zero element
                for (index--; index > 0 && properties[index].spheat == 0; index--)
                {
                    ;
                }
                int       second = index;
                tempprops lhs    = properties[second];
                tempprops rhs    = properties[last];
                //Interpolate over all the zeros!
                for (index = second + 1; index < properties.Count; index++)
                {
                    tempprops buf = lhs.interpolate(rhs, properties[index].temp);
                    if (properties[index].spheat != 0)
                    {
                        buf.spheat = properties[index].spheat;
                    }
                    properties[index] = buf;
                }
            }
            //Interpolate everything else
            for (index = 0; index < properties.Count; index++)
            {
                if (properties[index].spheat == 0)
                {
                    int prvind, nextind;
                    prvind = index - 1;
                    //It's safe to assume we won't hit the end of the list because we already interpolated those values
                    for (nextind = index + 1; properties[nextind].spheat == 0; nextind++)
                    {
                        ;
                    }
                    tempprops lhs = properties[prvind];
                    tempprops rhs = properties[nextind];
                    for (; index < nextind; index++)
                    {
                        tempprops buf = lhs.interpolate(rhs, properties[index].temp);
                        if (properties[index].spheat != 0)
                        {
                            buf.spheat = properties[index].spheat;
                        }
                        properties[index] = buf;
                    }
                }
            }
        }