// Smart getters public bool GetCorrectValue(int i, int j, BoundaryConditionType boundaryConditionType = BoundaryConditionType.Periodic) { switch (boundaryConditionType) { case BoundaryConditionType.Periodic: if (i < 0) { i = (this.cells.GetLength(0) + i) % this.cells.GetLength(0); } if (i >= this.cells.GetLength(0)) { i = i % this.cells.GetLength(0); } if (j < 0) { j = (this.cells.GetLength(1) + j) % this.cells.GetLength(1); } if (j >= this.cells.GetLength(1)) { j = j % this.cells.GetLength(1); } break; case BoundaryConditionType.NonPeriodic: if (i < 0 || i >= this.cells.GetLength(0) || j < 0 || j >= this.cells.GetLength(1)) { return(false); } break; } return(this.cells[i, j].GetStatus()); }
public BoundaryCondition(BoundaryConditionType type, Func value, int[] vertexes, double beta = 0) { Type = type; Value = value; Vertexes = vertexes; Beta = beta; }
private int CheckConditions(int[,] conditions, Cell cell = null, BoundaryConditionType boundaryConditionType = BoundaryConditionType.Periodic) { Dictionary <int, int> grainIds = new Dictionary <int, int>(); if (cell != null && cell.GetStatus()) { grainIds.Add(cell.GetGrainId(), 1); } for (int i = 0; i < conditions.GetLength(0); i++) { if (this.GetCorrectValue(conditions[i, 0], conditions[i, 1], boundaryConditionType)) { int grainId = this.GetCorrectGridElement(conditions[i, 0], conditions[i, 1], boundaryConditionType).GetGrainId(); if (grainIds.ContainsKey(grainId)) { grainIds[grainId]++; } else { grainIds.Add(grainId, 1); } } } return(this.GetBestGrainId(grainIds)); }
public void SetAllBoundaryConditionTypes(BoundaryConditionType type) { positive_x = type; positive_y = type; negative_x = type; negative_y = type; }
public Cell GetCorrectGridElement(int i, int j, BoundaryConditionType boundaryConditionType = BoundaryConditionType.Periodic) { switch (boundaryConditionType) { case BoundaryConditionType.Periodic: if (i < 0) { i = (this.cells.GetLength(0) + i) % this.cells.GetLength(0); } if (i >= this.cells.GetLength(0)) { i = i % this.cells.GetLength(0); } if (j < 0) { j = (this.cells.GetLength(1) + j) % this.cells.GetLength(1); } if (j >= this.cells.GetLength(1)) { j = j % this.cells.GetLength(1); } break; case BoundaryConditionType.NonPeriodic: if (i < 0 || i >= this.cells.GetLength(0) || j < 0 || j >= this.cells.GetLength(1)) { return(null); } break; } return(this.cells[i, j]); }
public BoundaryCondition(BoundaryConditionType BoundaryConditionType, int degree, double[] boundaryVector, BoundaryConditionValueType boundaryConditionValueType) { this.BoundaryConditionType = BoundaryConditionType; this.degree = degree; this.boundaryConditionValueType = boundaryConditionValueType; CreateBoundaryConditionVector(degree, boundaryVector); }
public void SetBoundaryConditionType(Direction indicator, BoundaryConditionType type) { switch (indicator) { case Direction.Positive_X: { positive_x = type; break; } case Direction.Negative_X: { negative_x = type; break; } case Direction.Positive_Y: { positive_y = type; break; } case Direction.Negative_Y: { negative_y = type; break; } } }
public BoundaryCondition(string name = "BC-1", BoundaryConditionType type = BoundaryConditionType.PINNED, NodeSet nset = null) { //Name = "BC-1"; //Type = "Displacement/Rotation"; Name = name; Type = type; Set = nset; }
public BoundaryConditions(RBounds2D _bounds, int _xcount, int _ycount, BoundaryConditionType _type) { xcount = _xcount; ycount = _ycount; positive_x_vals = new double[xcount]; positive_y_vals = new double[xcount]; negative_x_vals = new double[ycount]; negative_y_vals = new double[ycount]; bounds = _bounds; SetAllBoundaryConditionTypes(_type); }
public static BoundaryCondition Parse(string type_str, Func value, string vertexes_str, string beta_str = null) { BoundaryConditionType type = (BoundaryConditionType)int.Parse(type_str); int[] vertexes = vertexes_str.Split(' ').Select(v => int.Parse(v)).ToArray(); double beta = 0; if (beta_str != null) { beta = double.Parse(beta_str); } return(new BoundaryCondition(type, value, vertexes, beta)); }
private void BoundaryCondition_SelectedIndexChanged(object sender, EventArgs e) { switch (boundaryCondition.Text) { case "periodic": this.boundaryConditionType = BoundaryConditionType.Periodic; break; case "setfalse": this.boundaryConditionType = BoundaryConditionType.NonPeriodic; break; } }
public int CountNeighbourhoods(int i, int j, BoundaryConditionType boundaryConditionTyoe = BoundaryConditionType.Periodic) { int counted = 0; counted += this.GetCorrectValue(i - 1, j - 1, boundaryConditionTyoe) ? 1 : 0; counted += this.GetCorrectValue(i - 1, j, boundaryConditionTyoe) ? 1 : 0; counted += this.GetCorrectValue(i - 1, j + 1, boundaryConditionTyoe) ? 1 : 0; counted += this.GetCorrectValue(i, j - 1, boundaryConditionTyoe) ? 1 : 0; counted += this.GetCorrectValue(i, j + 1, boundaryConditionTyoe) ? 1 : 0; counted += this.GetCorrectValue(i + 1, j - 1, boundaryConditionTyoe) ? 1 : 0; counted += this.GetCorrectValue(i + 1, j, boundaryConditionTyoe) ? 1 : 0; counted += this.GetCorrectValue(i + 1, j + 1, boundaryConditionTyoe) ? 1 : 0; return(counted); }
public BoundaryCondition(BoundaryConditionType BoundaryConditionType, int degree, string expression, BoundaryConditionValueType boundaryConditionValueType, TimeIntervalBoundaryConditionHelper timeIntervalValueBoundaryConditionHelper, RobinBoundaryConditionHelper robinBoundaryConditionHelper) { this.BoundaryConditionType = BoundaryConditionType; this.degree = degree; this.boundaryConditionValueType = boundaryConditionValueType; this.robinBoundaryConditionHelper = robinBoundaryConditionHelper; this.timeIntervalValueBoundaryConditionHelper = timeIntervalValueBoundaryConditionHelper; if (expression != string.Empty) { var engine = new CalculationEngine(); this.BoundaryValueExpression = engine.Build(expression); } CreateBoundaryConditionVector(degree, new double[] { }); }
public bool CheckNeighbourhoods(int i, int j, AlgorithmMode algorithmMode, BoundaryConditionType boundaryConditionType = BoundaryConditionType.Periodic) { Dictionary <int, int> grainIds = new Dictionary <int, int>(); int grainId = -1; switch (algorithmMode) { case AlgorithmMode.TheGameOfLife: grainId = this.CheckConditions(this.GetAlgorithmConditions(i, j, algorithmMode), this.GetCorrectGridElement(i, j), boundaryConditionType); if (this.CountNeighbourhoods(i, j, boundaryConditionType) == 3 || (this.GetCorrectValue(i, j, boundaryConditionType) && this.CountNeighbourhoods(i, j, boundaryConditionType) == 2)) { grainId = this.CheckConditions(this.GetAlgorithmConditions(i, j, algorithmMode), this.GetCorrectGridElement(i, j), boundaryConditionType); if (grainId == -1) { return(false); } this.GetCorrectGridElement(i, j, boundaryConditionType).SetGrainId(grainId); return(true); } return(false); case AlgorithmMode.GrainGrowthPegRandom: algorithmMode = new Random().Next(0, 2) == 1 ? AlgorithmMode.GrainGrowthPegLeft : AlgorithmMode.GrainGrowthPegRight; break; case AlgorithmMode.GrainGrowthHexRandom: algorithmMode = new Random().Next(0, 2) == 1 ? AlgorithmMode.GrainGrowthHexLeft : AlgorithmMode.GrainGrowthHexRight; break; } // all grain growth algorithms grainId = this.CheckConditions(this.GetAlgorithmConditions(i, j, algorithmMode), this.GetCorrectGridElement(i, j), boundaryConditionType); if (grainId == -1) { return(false); } this.GetCorrectGridElement(i, j, boundaryConditionType).SetGrainId(grainId); return(true); }
// Cells operations public void RecalculateCells(BoundaryConditionType boundaryConditionType = BoundaryConditionType.Periodic, AlgorithmMode algorithMode = AlgorithmMode.TheGameOfLife) { int[] gridSize = this.GetGridSize(); Grid newGrid = new Grid(gridSize[0], gridSize[1]); for (int i = 0; i < gridSize[0]; i++) { for (int j = 0; j < gridSize[1]; j++) { newGrid.SetCorrectGridElement(i, j, this.CheckNeighbourhoods(i, j, algorithMode, boundaryConditionType)); newGrid.GetCorrectGridElement(i, j, boundaryConditionType).SetGrainId(this.GetCorrectGridElement(i, j, boundaryConditionType).GetGrainId()); } } this.cells = newGrid.cells; }
private string ConditionTypeToString(BoundaryConditionType type) { switch (type) { case BoundaryConditionType.Dirichlet: { return("dirichlet"); } case BoundaryConditionType.Neumann: { return("neumann"); } default: { throw new Exception("Error: Invalid type."); } } }
public BoundaryConditions(NCGrid_Distribution boundary_of, BoundaryConditionType _type) { bounds = boundary_of.Bounds; SetAllBoundaryConditionTypes(_type); xcount = boundary_of.Xcount; ycount = boundary_of.Ycount; positive_x_vals = new double[xcount]; positive_y_vals = new double[xcount]; negative_x_vals = new double[ycount]; negative_y_vals = new double[ycount]; for (int i = 0; i < xcount; i++) { positive_x_vals[i] = boundary_of[i, ycount - 1].Value; negative_x_vals[i] = boundary_of[i, 0].Value; } for (int j = 0; j < ycount; j++) { positive_y_vals[j] = boundary_of[xcount - 1, j].Value; negative_y_vals[j] = boundary_of[0, j].Value; } }
public BoundaryConditions(string title, bool using_full_path) { string path = bc_repo + "//" + title + ".bc"; if (using_full_path) { path = title; } string[] contents = File.ReadAllLines(path); bounds = RBounds2D.fromstring(contents[0]); if (!(int.TryParse(contents[1].Split(':')[1], out xcount) && int.TryParse(contents[1].Split(':')[3], out ycount))) { throw new Exception("Error: Improper file format."); } int px_offset = 3; int nx_offset = px_offset + 1 + xcount; int py_offset = nx_offset + 1 + xcount; int ny_offset = py_offset + 1 + ycount; int terminal = ny_offset + 1 + ycount; positive_x_vals = new double[xcount]; positive_y_vals = new double[xcount]; negative_x_vals = new double[ycount]; negative_y_vals = new double[ycount]; positive_x = ConditionTypeFromString(contents[px_offset - 1].Split(':')[1]); negative_x = ConditionTypeFromString(contents[nx_offset - 1].Split(':')[1]); positive_y = ConditionTypeFromString(contents[py_offset - 1].Split(':')[1]); negative_y = ConditionTypeFromString(contents[ny_offset - 1].Split(':')[1]); for (int i = px_offset; i < nx_offset - 1; i++) { double z; if (!double.TryParse(contents[i], out z)) { throw new Exception("Error: Improper file format"); } positive_x_vals[i - px_offset] = z; } for (int i = nx_offset; i < py_offset - 1; i++) { double z; if (!double.TryParse(contents[i], out z)) { throw new Exception("Error: Improper file format"); } negative_x_vals[i - nx_offset] = z; } for (int i = py_offset; i < ny_offset - 1; i++) { double z; if (!double.TryParse(contents[i], out z)) { throw new Exception("Error: Improper file format"); } positive_y_vals[i - py_offset] = z; } for (int i = ny_offset; i < terminal - 1; i++) { double z; if (!double.TryParse(contents[i], out z)) { throw new Exception("Error: Improper file format"); } negative_y_vals[i - ny_offset] = z; } }
public BoundaryCondition(BoundaryConditionLocation location, BoundaryConditionType type, Func <double, double> value) { Value = value; Location = location; Type = type; }
/// <summary> /// default-implementation /// </summary> public double InnerEdgeForm(ref CommonParams inp, double[] uA, double[] uB, double[,] Grad_uA, double[,] Grad_uB, double vA, double vB, double[] Grad_vA, double[] Grad_vB) { int dim = inp.Normal.Dim; double _penalty = m_PenaltyFunc(m_penalty, inp.jCellIn); // Particle parameters // ===================== if (inp.X.IsNullOrEmpty()) { throw new Exception("X is null or empty"); } if (m_GetParticleParams == null) { throw new Exception("m_GetParticleParams is null or empty"); } if (inp.X.Abs() < 0) { throw new ArithmeticException("invalid length of position vector"); } FSI_ParameterAtIB coupling = m_GetParticleParams(inp.X); if (coupling == null) { throw new Exception("coupling is null or empty"); } Vector orientation = new Vector(Math.Cos(coupling.Angle()), Math.Sin(coupling.Angle())); Vector orientationNormal = new Vector(-Math.Sin(coupling.Angle()), Math.Cos(coupling.Angle())); Vector activeStressVector = orientationNormal * inp.Normal > 0 ? new Vector(-coupling.ActiveStress() * inp.Normal[1], coupling.ActiveStress() * inp.Normal[0]) : new Vector(coupling.ActiveStress() * inp.Normal[1], -coupling.ActiveStress() * inp.Normal[0]); BoundaryConditionType bcType = orientation * inp.Normal <= 0 || coupling.ActiveStress() == 0 ? BoundaryConditionType.passive : BoundaryConditionType.active; Debug.Assert(ArgumentOrdering.Count == dim); Debug.Assert(Grad_uA.GetLength(0) == ArgumentOrdering.Count); Debug.Assert(Grad_uB.GetLength(0) == ArgumentOrdering.Count); Debug.Assert(Grad_uA.GetLength(1) == dim); Debug.Assert(Grad_uB.GetLength(1) == dim); // Gradient of u and v // ===================== double Grad_uA_xN = 0, Grad_vA_xN = 0; for (int d = 0; d < dim; d++) { Grad_uA_xN += Grad_uA[component, d] * inp.Normal[d]; Grad_vA_xN += Grad_vA[d] * inp.Normal[d]; } double returnValue = 0.0; // 3D for IBM_Solver // ===================== if (dim == 3) { returnValue -= Grad_uA_xN * (vA); // consistency term returnValue -= Grad_vA_xN * (uA[component] - 0); // symmetry term returnValue += _penalty * (uA[component] - 0) * (vA); // penalty term Debug.Assert(!(double.IsInfinity(returnValue) || double.IsNaN(returnValue))); return(returnValue * muA); } // 2D // ===================== Vector uAFict = coupling.VelocityAtPointOnLevelSet(); switch (bcType) { case BoundaryConditionType.passive: { for (int d = 0; d < dim; d++) { returnValue -= muA * Grad_uA[component, d] * vA * inp.Normal[d]; returnValue -= muA * Grad_vA[d] * (uA[component] - uAFict[component]) * inp.Normal[d]; } returnValue += muA * (uA[component] - uAFict[component]) * vA * _penalty; break; } case BoundaryConditionType.active: { // normal direction, solid wall for (int dN = 0; dN < dim; dN++) { for (int dD = 0; dD < dim; dD++) { // consistency term returnValue -= muA * (inp.Normal[dN] * Grad_uA[dN, dD] * inp.Normal[dD]) * vA * inp.Normal[component]; // symmetry term returnValue -= muA * (Grad_vA[dD] * inp.Normal[dD]) * (inp.Normal[dN] * uA[dN] - inp.Normal[dN] * uAFict[dN]) * inp.Normal[component]; } // penalty term returnValue += muA * inp.Normal[dN] * (uA[dN] - uAFict[dN]) * inp.Normal[component] * vA * _penalty; } // tangential direction, active part double[,] P = new double[dim, dim]; for (int d1 = 0; d1 < dim; d1++) { for (int d2 = 0; d2 < dim; d2++) { if (d1 == d2) { P[d1, d2] = 1 - inp.Normal[d1] * inp.Normal[d2]; } else { P[d1, d2] = inp.Normal[d1] * inp.Normal[d2]; } } } for (int d1 = 0; d1 < dim; d1++) { for (int d2 = 0; d2 < dim; d2++) { returnValue -= P[d1, d2] * activeStressVector[d2] * (P[d1, component] * vA); } } break; } } Debug.Assert(!(double.IsInfinity(returnValue) || double.IsNaN(returnValue))); return(returnValue); }
public BoundaryCondition(BoundaryConditionLocation location, BoundaryConditionType type) : this(location, type, x => 0) { }