August 23rd, 2013, 12:59 AM

Multidimensional simultaneous equation search
I am working on a project that calculates thermodynamic properties of water and steam. I am looking for a fast search algorithm that can solve two function of two variables for specific values. All the thermodynamic properties are function of temperature and density.
P = fp(T,d)
H=fh(T,d)
Given P and H, I need to find values for T and d that yield P and H.
Andy
August 24th, 2013, 01:03 PM

Do you have to write the program yourself?
If so, in what language are you going to write it?
If you do a search for "multidimensional rootfinder", many results are returned. Perhaps one of these can help.
Otherwise, couldn't you use a standard package like MATLAB, Maple, Octave, etc.?
August 25th, 2013, 12:00 AM

Thanks for the term "multidimensional rootfinder". I am terrible at remembering terms. Searched for that but the top hits didn't yield useful results. The functions are thermodynamic properties of water and steam. I am writing a steam properties plugin for a simulation package using C++. I am using the IAPWS95 formulations. They take temperature and density as arguments. They use the Helmholtz free energy equation, it's first and second order derivatives. it really shouldn't be all that hard. The functions define curves in the temperature density plain. Just need to find the intersection. There two parts to the formulations. The real gas part and the residual part. They are coded as methods of a C++ class along with their mono state property functions. There is a saturation state where boiling occurs and both the gas and liquid state coexist. I have a StatePoint class that has two of the mono state class items. So when the StatePoint is with in the saturated region both the liquid and gas phases are represented by the two Phi variables. It gets fairly complicated. Say I am looking for a State_Point given pressure and entropy. that point could be in the gas, liquid or the saturation mixture region. The formula only work for liquid and gas regions. The actual state of a mixture has to be calculated from the region boundaries at the pressure and temperature. The temperature that water boils at depends on it's pressure or vise versa. At the boiling point you have two densities. That of the liquid state and that of the vapor/gas state. During a search I have to avoid directly calculating a state with the density in the saturation mix region. I have to check and calculate the boundaries.
Code:
/* Reduced Holtzman/
**
** Input: Receprical Reduced Temperature: rT and Reduced Specific Density: rD
**
** Output Reduced Holtzman
*/
long double Phi::Phir() {
if (!(fPhir&flags)) {
int i;
PhirSetup();
xPhir = n[54] * Dltab55 * W55 * rD;
xPhir += n[55] * Dltab56 * W56 * rD;
for (i=0; i<7; i++) xPhir += n[i] * rVpR[d[i]] * rTpR[t[i]];
for (i=7; i<51; i++) xPhir += n[i] * rVpR[d[i]] * (rTpR)[t[i]] * expl(rVpR[c[i7]] );
for (i=51; i<54; i++)
xPhir += n[i] * rVpR[3] * rTpR[t[i]] * expl(20.0*dm1Sq  Bata[i51]*tm[i51]);
flags = fPhir; }
return xPhir;
}
Dltab55, Dltab56, W55, W56 are exponential terms calculated by PhirSetup(); I have done a lot in getting the calculation speed up. Their values is cashed in the class and only recalculated when necessary. The temperature or density input signal changes. Temperature and density dependency are independent. Powers of temperature and density are precalculated in the rTpR and rDpR arrays.
Code:
void Phi::PhirSetup(){
tm[0] = (rT  Ys[0]) * (rT  Ys[0]);
tm[1] = (rT  Ys[1]) * (rT  Ys[1]);
tm[2] = (rT  Ys[2]) * (rT  Ys[2]);
W52 = expl(C52*dm1Sq  D52*tm[0]);
W53 = expl(C53*dm1Sq  D53*tm[1]);
W54 = expl(C54*dm1Sq  D54*tm[2]);
W55 = expl(C55*dm1Sq  D55*tm1Sq);
W56 = expl(C56*dm1Sq  D56*tm1Sq);
Thta = 0.32*powl(dm1Sq,1.0/0.6)  tm1; //= (1rT) + A[i]*((rD1)^2)^(1/(2*Bata[i]))
Dlta = Thta*Thta + 0.2*powl(dm1Sq,3.5) + 1E300; //= Thta^2 + B[i]*((rD1)^2)^a[i]. B[i]=0.2, a[i]=3.5
Dltab55 = powl(Dlta,0.85); //= Dlta^b[i]
Dltab56 = powl(Dlta,0.95);
}
The above calculates the residual Helmholtz(t,d) value. There are five other Helmholtz function for it's first and second order derivatives. Temperature and density are the inputs to these functions. Enthalpy, pressure, and entropy are properties I would like to use to determine a StatePoint. it's simple when one of the inputs is temperature or density (specific volume = 1/density). I have function that find the density when pressure and temperature are given. I have functions that solve for the saturation line given a single property of pressure, temperature or entropy. that is the boiling point where water boils and changes into steam. These are called state points. Except for a saturation state it takes two properties to determine a state point. I have the single property searches working and now am down to the double search problem. I have extended the IAPWS formulations providing derivatives for rate of temperature change with respect density along a constant property path. The path can be entropy or enthalpy allowing simulation of isentropic and isenthalpic thermodynamic processes.
Anyway if you can think of any other name this type of search might be called let me know.
My programming background is in computer languages and operating systems. I am retired now. I started collage as a Math major and got hooked on computers. Wound up working on and writing operating systems and compilers. I have an interest in steam automobiles and thus this program. I hope to be able to simulate the thermodynamic processes.
The Plugin is for VisSim. VisSim is actually a graphical programming language. It could be thought of as digital simulations of an analog computer. Connecting functional blocks together. You are placing and wiring these blocks graphically. I actually got to play with a real analog computer in collage electronics class. VisSim does not clame to be an analog computer simulator. That is just my observation. It actually does a lot more then the old analog computers. It has boolean blocks for example. I once had a book on search algorithms but was lost. It was probably in one of my Knuth books. I lost a lot of my library during a move when our washing machine flooded the garage where my books weren't unpacked setting on the floor in boxes.
Note. I use ^ for exponentiations in my code comments.
Andy