You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
3.1 KiB
82 lines
3.1 KiB
using System;
|
|
using System.Collections.ObjectModel;
|
|
|
|
namespace MODELING_DEF_DES_MI_VI.Models.Spreads
|
|
{
|
|
public class NormalSpread : BaseSpread
|
|
{
|
|
public double Mu { get; set; }
|
|
public double Sigma { get; set; }
|
|
private MaterialModel Material { get; set; }
|
|
|
|
public double GaussFunction (double x, double sigma, double mu)
|
|
{
|
|
double part1 = 1.0/ (sigma * Math.Sqrt(2 * 3.14));
|
|
double part2 = Math.Exp(-Math.Pow(x - mu, 2) / (2.0 * Math.Pow(sigma, 2)));
|
|
return part1 * part2;
|
|
}
|
|
|
|
public double GaussFunctionByHeight(Point3D c)
|
|
=> GaussFunction(c.Z, Sigma, Mu);
|
|
|
|
public override ObservableCollection<Pore> GetSpread()
|
|
{
|
|
var r = new Random();
|
|
var id = 0;
|
|
GetOptimalRadius();
|
|
var result = new ObservableCollection<Pore>();
|
|
for (int i = 0; i <= Material.NumberOfPores; i++)
|
|
for (int j = 0; j <= Material.NumberOfPores; j++)
|
|
for (int k = 0; k <= Material.NumberOfPores; k++)
|
|
{
|
|
var c = new Point3D()
|
|
{
|
|
X = (double) i / Material.NumberOfPores * Material.Width,
|
|
Y = (double) j / Material.NumberOfPores * Material.Depth,
|
|
Z = (double) k / Material.NumberOfPores * Material.Height,
|
|
};
|
|
var randomDouble = r.NextDouble();
|
|
var gaussResult = GaussFunctionByHeight(c);
|
|
if (randomDouble < gaussResult)
|
|
{
|
|
var randomRadius
|
|
= r.NextDouble()
|
|
* (Material.MaxRadius - Material.MinRadius)
|
|
+ Material.MinRadius;
|
|
result.Add(new Pore() { Point = c, Radius = randomRadius, Id = id });
|
|
id++;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private double GetOptimalRadius()
|
|
{
|
|
var m = Material;
|
|
var volume = m.Height * m.Width * m.Depth;
|
|
return Math.Round(Math.Pow((3.0 / 4.0) * volume / (3.14 * Math.Pow(m.NumberOfPores, 3)), 1.0 / 3.0), 3);
|
|
}
|
|
|
|
public override void LoadRecommendParams()
|
|
{
|
|
if (Material.Width == 0 || Material.Height == 0 || Material.Depth == 0)
|
|
{
|
|
Material.Width = 10;
|
|
Material.Height = 10;
|
|
Material.Depth = 10;
|
|
Material.NumberOfPores = 20;
|
|
}
|
|
Sigma = 4;
|
|
Mu = Material.Height - Material.Height / 4;
|
|
var r = GetOptimalRadius();
|
|
Material.MinRadius = r / 2;
|
|
Material.MaxRadius = 3 * r / 2;
|
|
}
|
|
|
|
public NormalSpread(MaterialModel material)
|
|
=> Material = material;
|
|
|
|
public override string ToString()
|
|
=> "Нормальное распределение";
|
|
}
|
|
}
|
|
|