using System; namespace Science.Mathematics.VectorCalculus { public class GaussDivergenceTheorem { private Function.ToLastType vf; private Surface s; private Volume v; public GaussDivergenceTheorem() { } public GaussDivergenceTheorem(Volume V, Function.ToLastType F, Surface D) { v = V; vf = F; s = D; } public Function.ToLastType VectorField { set { vf = value; } } public Surface Boundary { set { s = value; } } public Volume Domain { set { v = value; } } public void Compute() { Function.ToLastType ff = new Function.ToLastType(divF); IntegrationMultiD md = new IntegrationMultiD(ff,v.From,v.To); md.NumberOfCall = nc; md.Compute(); ltgral = md.BestEstimation; lsd = md.StandardDeviation; lchi2 = md.ChiSQUARE; SurfaceIntegral obj = new SurfaceIntegral(vf, s); obj.NumberOfCall = nc; obj.Compute(); tgral = obj.BestEstimation; sd = obj.StandardDeviation; chi2 = obj.ChiSQUARE; } private double divF(double[] x) { Divergence obj = new Divergence(vf,x); obj.Compute(); if (v.IsInVolumeQ(x)) return obj.Result; else return 0.0; } public double LeftHandSideBestEstimation { get { return ltgral; } } public double LeftHandSideStandardDeviation { get { return lsd; } } public double LeftHandSideChiSQUARE { get { return lchi2; } } private double ltgral, lsd, lchi2; private double tgral, sd, chi2; private ulong nc = 100000; public double RightHandSideBestEstimation { get { return tgral; } } public double RightHandSideStandardDeviation { get { return sd; } } public double RightHandSideChiSQUARE { get { return chi2; } } public ulong NumberOfCall { set { nc = value; } } public override string ToString() { string res = ""; res += this.LeftHandSideBestEstimation.ToString() + " +/- " + this.LeftHandSideStandardDeviation.ToString() + " = "; res += this.RightHandSideBestEstimation.ToString() + " +/- " + this.RightHandSideStandardDeviation.ToString(); res += "\r\n"; return res; } } }