-
What to Use?
Hello,
I need to create a math engine that presents the results in real-time. There will be approximately 100 different formulas that need to be re-calculated continously.
Can someone point me in the right direction?
Do I write this in a Module, or a Database?
Is SQL the answer?
Thanks,
Ken
-
i'd say go with ASP.net, I've heard lots of good things, except for the framework
-
no, i suggest you use sql...more efficient for me in general, i find
-
I'm not sure why you would use a database?!
What are you trying to do that I'm missing? Are you trying to continuously serve results to a web page, or hundreds of clients?
Or, are you just trying to write a math library in .net?
-
What I'd like to do is have the results of several calculations available for use. In my mind's eye, the results would reside in "Pigeon Holes" and could be accessed by any number of routines at any time.
I'm not certain which is the best approach.
Thanks,
Ken
-
There's a bunch of ways you could do this.
You could make a class that supports the dictionary interface. You could then pass through the parameters and the class could generate all or some of the results. You could then poll the class for the desired results.
You could also create a list of delegate functions that are called whenever the results must be updated.
I'm not sure that helped. What kind of formulas are these? How long does it take to caculate these formulas?
-
Here's some example formulas.
Slurry Rate - Value to be displayed
Proppant Rate - Value to be displayed
Proppant Displacement Rate - Value to be displayed
Clean Rate - Value that may be result of another calculation, or a sensor input
Concentration- Value that may be result of another calculation, or a sensor input
Proppant True Density - Value that user inputs
Formula 1:
Slurry Rate = Clean Rate + ((Concentration * Clean Rate) / Proppant True Density)
Formula 2:
Proppant Rate = (Slurry Rate-(Slurry Rate/(1 + (Concentration / Proppant True Density))))*Proppant True Density
Formula 3:
Proppant Displacement Rate = Slurry Rate-(slurry Rate/(1+Concentration/Proppant True Density))
These few formulas are only one of several ways the required result may be calculated.
The user also has the ability to enter a formula of his own creation.
Ken
-
The formulas don't seem like they will require tons of processing power. I would just create a few classes to encapsulate the analysis and have at it. You may want to group some analyses into single methods, like ones that use the results from others. This way you don't have to recalculate the result each time its needed for another formula (i.e. as Slurry rate is used by formula 2 and 3)
The logical organization of the formulas used will do more for the speed of execution than some other fancy design construct.
Does that help? I would probably make a class like:
public class Analysis
{
public class Results1
{
public double Formula1() { ... }
public double Formula2() { ... }
...
}
public class Results2
{
public double Formula9() { ... }
public double Formula10() { ... }
...
}
public class UserFormulas { ... }
}
-
Scott,
Would you suggest writing this under VB.Net or C# ?
Also, all the values need to be recalculated at least 3 times per second.
Ken
-
VB.NET or C# will execute with the same speed, but I prefer C# for its syntax.
I will write a small example for you when I've got the chance. What would you like to do with the results? Are you graphing them? Anyway, stick tight. I will try to put something together for you soon.
-
Actually, the data will be used in several ways.
1. Data plotted on a graph.
2. Data recorded in a data file for futher analysis.
3. Displayed as a meter reading.
4. Used in deriving other type of data.
5. Used as reference and feedback signals to control circuits/software.
** Anyone interested in writing a stand-alone real time graphing print routine for the HP Inkjet Series printer?
Ken
-
Ken,
After doing this, I feel kind of silly. There's just not that much too it. But, I hope that it shows you what you are looking for.
Please let me know if you have any questions. The example comprises three classes, including the main one.
Code:
using System;
namespace MyFormulas
{
/// <summary>
/// FormulasTest console application
/// </summary>
class FormulasTest
{
/// <summary>
/// The main entry point for console the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Analysis myAnalysis = new Analysis() ;
DateTime StartTime ;
DateTime EndTime ;
StartTime = DateTime.Now;
// Simple test of the analysis routine
for (int i=0; i < 300 ; i++ )
{
myAnalysis.Group1.Analyze( 50, 50, 90 );
Console.WriteLine( "*Slurry Rate: {0}\n Proppant Rate: {1}\n Proppant Displacement Rate {2}\n",
myAnalysis.Group1.SlurryRate,
myAnalysis.Group1.ProppantRate,
myAnalysis.Group1.ProppantDisplacementRate );
}
EndTime = DateTime.Now;
Console.WriteLine( "Execution time: " + (EndTime - StartTime) );
Console.WriteLine( "Hit return to continue" );
Console.Read();
}
}
public class Analysis
{
private FormulasGroup1 m_FormulasGroup1 = new FormulasGroup1();
// Property returns the private formula group (allows organization: Analysis.Group1...)
public FormulasGroup1 Group1
{
get { return m_FormulasGroup1 ; }
}
}
public class FormulasGroup1
{
private double m_CleanRate;
private double m_Concentration;
private double m_ProppantTrueDensity;
private double m_SlurryRate;
private double m_ProppantRate;
private double m_ProppantDisplacementRate;
public FormulasGroup1(){}
// Analysis function performs the work
public void Analyze(double CleanRate, double Concentration,
double ProppantTrueDensity)
{
// Save values for other function calls ( if needed )
m_CleanRate = CleanRate ;
m_Concentration = Concentration ;
m_ProppantTrueDensity = ProppantTrueDensity ;
m_SlurryRate = CleanRate + ((Concentration * CleanRate) / ProppantTrueDensity) ;
m_ProppantRate = (SlurryRate - (SlurryRate / (1 + (Concentration / ProppantTrueDensity)))) * ProppantTrueDensity ;
m_ProppantDisplacementRate = SlurryRate - (SlurryRate / (1 + Concentration / ProppantTrueDensity)) ;
return ;
}
// Properties for returning values
public double SlurryRate
{
get { return m_SlurryRate; }
}
public double ProppantRate
{
get { return m_ProppantRate; }
}
public double ProppantDisplacementRate
{
get { return m_ProppantDisplacementRate; }
}
}
}
-
Scott,
Thanks again for your assistance.
The program I'm writing is in VB.Net.
How/what do I need to do to use this code (reference?).
What would be the syntax for using the routines.
Thanks,
Ken
-
What you would need to do would be to build a private assembly with the C# code. You can then reference this assembly from VB.NET. You can look in the Main subroutine to understand the syntax for using the class.