-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from maslankam/model-refactoring
Next version
- Loading branch information
Showing
57 changed files
with
3,190 additions
and
697 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Model\Model.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
using System; | ||
using Model; | ||
using System.Xml; | ||
using System.Xml.Linq; | ||
|
||
namespace ConsoleApp1 | ||
{ | ||
|
||
|
||
|
||
class Program | ||
{ | ||
private static CelluralAutomaton _automaton; | ||
private static int _spaceSize; | ||
private static int _grainsCount; | ||
private static int _inclusionsCount; | ||
private static int _minRadius; | ||
private static int _maxRadius; | ||
private static ITransitionRule _transition; | ||
private static INeighbourhood _neighbourhood; | ||
private static IBoundaryCondition _boundary; | ||
private static bool _isAutomatonGenerated; | ||
private static bool _isSaved; | ||
|
||
static void Main(string[] args) | ||
{ | ||
|
||
|
||
|
||
ITransitionRule transition = new GrainGrowthRule(); | ||
IBoundaryCondition boundary = new PeriodicBoundary(); | ||
INeighbourhood neighbourhood = new VonNeumanNeighbourhood(boundary); | ||
_automaton = new CelluralAutomaton(500, 40, 30, 1, 5, transition, neighbourhood, boundary); | ||
|
||
_spaceSize = 500; | ||
_grainsCount = 20; | ||
_inclusionsCount = 0; | ||
_minRadius = 1; | ||
_minRadius = 5; | ||
_transition = new GrainGrowthRule(); | ||
_boundary = new AbsorbingBoundary(); | ||
_neighbourhood = new VonNeumanNeighbourhood(_boundary); | ||
|
||
|
||
var doc = new XDocument(new XElement("Document")); | ||
|
||
var widowVariables = new XElement("WindowVariables"); | ||
widowVariables.Add(new XAttribute("SpaceSize", _spaceSize)); | ||
widowVariables.Add(new XAttribute("GrainsCount", _grainsCount)); | ||
widowVariables.Add(new XAttribute("InclusionsCount", _inclusionsCount)); | ||
widowVariables.Add(new XAttribute("MinRadius", _minRadius)); | ||
widowVariables.Add(new XAttribute("MaxRadius", _inclusionsCount)); | ||
widowVariables.Add(new XAttribute("Transition", _transition.GetType())); | ||
widowVariables.Add(new XAttribute("Neighbourhood", _neighbourhood.GetType())); | ||
widowVariables.Add(new XAttribute("Boundary", _boundary.GetType())); | ||
widowVariables.Add(new XAttribute("isGenerated", _isAutomatonGenerated)); | ||
widowVariables.Add(new XAttribute("isSaved", _isSaved)); | ||
doc.Root.Add(widowVariables); | ||
|
||
var grains = new XElement("Grains"); | ||
foreach (var grain in _automaton.Grains) | ||
{ | ||
var grainXmlElement = new XElement("Grain"); | ||
|
||
var id = new XAttribute("Id", grain.Id); | ||
grainXmlElement.Add(id); | ||
|
||
var phase = new XAttribute("P", grain.Phase); | ||
grainXmlElement.Add(phase); | ||
grainXmlElement.Add(new XAttribute("A", grain.Color.A)); | ||
grainXmlElement.Add(new XAttribute("R", grain.Color.R)); | ||
grainXmlElement.Add(new XAttribute("G", grain.Color.G)); | ||
grainXmlElement.Add(new XAttribute("B", grain.Color.B)); | ||
|
||
grains.Add(grainXmlElement); | ||
} | ||
doc.Root.Add(grains); | ||
|
||
var inclusions = new XElement("Inclusions"); | ||
foreach (var inclusion in _automaton.Inclusions) | ||
{ | ||
var inclusionXmlElement = new XElement("Grain"); | ||
|
||
var id = new XAttribute("Id", inclusion.Id); | ||
inclusionXmlElement.Add(id); | ||
|
||
var phase = new XAttribute("P", inclusion.Phase); | ||
inclusionXmlElement.Add(phase); | ||
inclusionXmlElement.Add(new XAttribute("rad", inclusion.Radius)); | ||
inclusionXmlElement.Add(new XAttribute("A", inclusion.Color.A)); | ||
inclusionXmlElement.Add(new XAttribute("R", inclusion.Color.R)); | ||
inclusionXmlElement.Add(new XAttribute("G", inclusion.Color.G)); | ||
inclusionXmlElement.Add(new XAttribute("B", inclusion.Color.B)); | ||
|
||
inclusions.Add(inclusionXmlElement); | ||
} | ||
|
||
doc.Root.Add(inclusions); | ||
|
||
|
||
var cells = new XElement("Cells"); | ||
for (int i = 0; i < _automaton.Space.GetXLength(); i++) | ||
{ | ||
var row = new XElement("Row"); | ||
row.Add(new XAttribute("x", i)); | ||
for (int j = 0; j < _automaton.Space.GetYLength(); j++) | ||
{ | ||
//Console.WriteLine($"{i},{j}"); | ||
var cell = _automaton.Space.GetCell(i, j); | ||
|
||
var c = new XElement("c"); | ||
c.Add(new XAttribute("y", j)); | ||
c.Add(new XAttribute("p", cell?.Phase?.ToString() ?? "")); | ||
c.Add(new XAttribute("i", cell?.MicroelementMembership?.Id.ToString() ?? "")); | ||
|
||
row.Add(c); | ||
} | ||
cells.Add(row); | ||
} | ||
doc.Root.Add(cells); | ||
|
||
//Console.WriteLine("Saving"); | ||
doc.Save(@"C:\Users\mikim\Desktop\Multiscale Modeling\ConsoleApp1\Nowy dokument tekstowy.xml"); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
|
||
namespace Model{ | ||
|
||
|
||
public class AbsorbingBoundary : IBoundaryCondition | ||
{ | ||
public string Name | ||
{ | ||
get | ||
{ | ||
return this.ToString(); | ||
} | ||
} | ||
|
||
// AbsorbingBoundary always return null Cell | ||
/// |nl|nl|nl|nl|nl| | ||
/// |nl|00|01|02|nl| | ||
/// |nl|10|11|12|nl| | ||
/// |nl|20|21|22|nl| | ||
/// |nl|nl|nl|nl|nl| | ||
public Cell GetBoundaryNeighbour(CelluralSpace space, int x, int y, BoundaryDirection direction) { | ||
return null; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return "AbsorbingBoundary"; | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
|
||
namespace Model{ | ||
|
||
public enum BoundaryDirection{ | ||
N, NE, E, SE , S, SW, W, NW | ||
} | ||
|
||
public interface IBoundaryCondition | ||
{ | ||
public Cell GetBoundaryNeighbour(CelluralSpace space, int x, int y, BoundaryDirection direction); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
using System; | ||
|
||
namespace Model | ||
{ | ||
|
||
|
||
public class PeriodicBoundary : IBoundaryCondition | ||
{ | ||
public string Name | ||
{ | ||
get | ||
{ | ||
return this.ToString(); | ||
} | ||
} | ||
|
||
// AbsorbingBoundary always return null Cell | ||
/// y -> | ||
///x |22|20|21|22|20| | ||
///| |02|00|01|02|00| | ||
///v |12|10|11|12|10| | ||
/// |22|20|21|22|20| | ||
/// |02|00|01|02|00| | ||
public Cell GetBoundaryNeighbour(CelluralSpace space, int x, int y, BoundaryDirection direction) | ||
{ | ||
switch (direction) | ||
{ | ||
case BoundaryDirection.N: return space.GetCell( space.GetXLength() - 1, y); | ||
case BoundaryDirection.NE: | ||
{ | ||
if (y == space.GetYLength() - 1) | ||
{ | ||
if(x == 0) | ||
{ | ||
return space.GetCell(space.GetXLength() - 1, 0); | ||
} | ||
else | ||
{ | ||
return space.GetCell(x - 1, 0); | ||
} | ||
} | ||
else | ||
{ | ||
return space.GetCell(space.GetXLength() - 1, y + 1); | ||
} | ||
} | ||
case BoundaryDirection.E: return space.GetCell( x, 0); | ||
case BoundaryDirection.SE: | ||
{ | ||
if (x == space.GetXLength() - 1) | ||
{ | ||
if (y == space.GetYLength() - 1) | ||
{ | ||
return space.GetCell(0, 0); | ||
} | ||
else | ||
{ | ||
return space.GetCell(0, y + 1); | ||
} | ||
} | ||
else | ||
{ | ||
return space.GetCell(x + 1, 0); | ||
} | ||
} | ||
case BoundaryDirection.S: return space.GetCell( 0, y); | ||
case BoundaryDirection.SW: | ||
{ | ||
if (x == space.GetYLength() - 1) | ||
{ | ||
if (y == 0) | ||
{ | ||
return space.GetCell(0, 2); | ||
} | ||
else | ||
{ | ||
return space.GetCell(0, y - 1); | ||
} | ||
} | ||
else | ||
{ | ||
return space.GetCell(x + 1, space.GetYLength() - 1); | ||
} | ||
} | ||
case BoundaryDirection.W: return space.GetCell( x, space.GetYLength() - 1); | ||
case BoundaryDirection.NW: | ||
{ | ||
if (y == 0) | ||
{ | ||
if (x == 0) | ||
{ | ||
return space.GetCell(2, 2); | ||
} | ||
else | ||
{ | ||
return space.GetCell(x - 1, space.GetYLength() - 1); | ||
} | ||
} | ||
else | ||
{ | ||
return space.GetCell(space.GetXLength() - 1, y - 1); | ||
} | ||
} | ||
default: throw new ArgumentException("Wrong direction"); | ||
} | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return "PeriodicBoundary"; | ||
} | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.