コード例 #1
0
 NeighborhoodManager()
 {
     CurrentNeighborhoods = new List <Neighborhood>();
     CurrentNeighborhoods.Add(ImplementedNeighborhood[0]);
     RandomThresholdList = new List <double>();
     Boundary            = BoundaryConditions.Fixed;
 }
コード例 #2
0
        public GrainGrowthCellularAutomatonViewModel()
        {
            CellNeighborhoods.Add(CellNeighborhoodTypeModel.VonNeumann);
            CellNeighborhoods.Add(CellNeighborhoodTypeModel.Moore);
            CellNeighborhoods.Add(CellNeighborhoodTypeModel.RandomPentagonal);
            CellNeighborhoods.Add(CellNeighborhoodTypeModel.LeftHexagonal);
            CellNeighborhoods.Add(CellNeighborhoodTypeModel.RightHexagonal);
            CellNeighborhoods.Add(CellNeighborhoodTypeModel.RandomHexagonal);
            CellNeighborhoods.Add(CellNeighborhoodTypeModel.Radial);
            CellNeighborhoods.Add(CellNeighborhoodTypeModel.RadialWithCenterOfMass);

            BoundaryConditions.Add(BoundaryConditionModel.Absorbing);
            BoundaryConditions.Add(BoundaryConditionModel.Periodic);

            NucleationMethods.Add(NucleationMethodModel.Uniform);
            NucleationMethods.Add(NucleationMethodModel.Random);
            NucleationMethods.Add(NucleationMethodModel.RandomWithRadius);

            evolverAndDrawerDispatcherTimer          = new DispatcherTimer();
            evolverAndDrawerDispatcherTimer.Interval = TimeSpan.FromMilliseconds(timeInterval);
            evolverAndDrawerDispatcherTimer.Tick    += EvolverAndDrawer_Tick;

            cancellationTokenSource = new CancellationTokenSource();
            cancellationToken       = cancellationTokenSource.Token;
            ThreadPool.SetMinThreads(1, 1);
            ThreadPool.SetMaxThreads(1, 1);

            CreateGrainCellGridPreview();
            RunDrawerTask();
        }
        public ElementaryCellularAutomatonViewModel()
        {
            CellGridImageViewModel = new CellGridImageViewModel();

            BoundaryConditions.Add(BoundaryConditionModel.Absorbing);
            BoundaryConditions.Add(BoundaryConditionModel.CounterAbsorbing);
            BoundaryConditions.Add(BoundaryConditionModel.Periodic);
        }
 public LinearFemAnalysis2DUniformHardcoded(int numElementsX, int numElementsY, ElasticMaterial2D material,
                                            BoundaryConditions bc)
 {
     this.numElementsX = numElementsX;
     this.numElementsY = numElementsY;
     this.NumElements  = numElementsX * numElementsY;
     this.material     = material;
     this.bc           = bc;
 }
コード例 #5
0
        /// <summary>
        /// Assigns initial conditions for the reaction vessel.
        /// </summary>
        private void SetInitialConditions()
        {
            this.SetBoundaryConditions(BoundaryConditions.RVBC_Uniform);

            this._boundaryConditionsPrev = this._boundaryConditions;

            for (int i = 1; i < vesselWidth - 1; i++)
            {
                for (int j = 1; j < vesselHeight - 1; j++)
                {
                    reaction[indexA, i, j] = initialXa;
                    reaction[indexB, i, j] = initialXb;
                    reaction[indexC, i, j] = initialXc;
                }
            }
        }
コード例 #6
0
        private void SetBoundaryConditions(BoundaryConditions boundary)
        {
            lock (this.reaction.SyncRoot)
            {
                for (int i = 0; i < vesselWidth; i++)
                {
                    this.SetBoundaryCondition(i, 0, boundary);
                    this.SetBoundaryCondition(i, vesselHeight - 1, boundary);
                }

                for (int j = 0; j < vesselHeight; j++)
                {
                    this.SetBoundaryCondition(0, j, boundary);
                    this.SetBoundaryCondition(vesselWidth - 1, j, boundary);
                }
            }
        }
コード例 #7
0
        GridController(int sizeX, int sizeY, int boundaryCondition, bool drawGrid = false, int zoom = 1)
        {
            //GRID
            CurrentGrid  = new Grid(sizeX, sizeY);
            NextStepGrid = new Grid(sizeX, sizeY);

            Zoom     = zoom;
            DrawGrid = drawGrid;

            //RULES
            AliveRule = new List <int>();
            DeadRule  = new List <int>();

            //GRID OPTIONS
            BoundaryCondition = (BoundaryConditions)boundaryCondition;
            //.SetNeighborhood(new List<int>() { neighborhoodType });
            Iteration = 0;
        }
コード例 #8
0
        /// <summary>
        /// Create a point load on all
        /// analytical column end points.
        /// </summary>
        void CreatePointLoadOnColumnEnd(Document doc)
        {
            // Find all AM column instances in the document

            FilteredElementCollector columns
                = new FilteredElementCollector(doc)
                  .OfCategory(BuiltInCategory.OST_ColumnAnalytical)
                  .WhereElementIsNotElementType();

            foreach (AnalyticalModel am in columns)
            {
                Curve curve = am.GetCurve();

                AnalyticalModelSelector selector
                    = new AnalyticalModelSelector(curve);

                selector.CurveSelector
                    = AnalyticalCurveSelector.EndPoint;

                Reference endPointRef
                    = am.GetReference(selector);

                using (Transaction tx = new Transaction(doc))
                {
                    tx.Start("NewPointBoundaryConditions");

                    BoundaryConditions newPointBC
                        = doc.Create.NewPointBoundaryConditions(
                              endPointRef,
                              TranslationRotationValue.Fixed, 0,
                              TranslationRotationValue.Spring, 1.0,
                              TranslationRotationValue.Fixed, 0,
                              TranslationRotationValue.Fixed, 0,
                              TranslationRotationValue.Fixed, 0,
                              TranslationRotationValue.Fixed, 0);

                    newPointBC.SetOrientTo(
                        BoundaryConditionsOrientTo
                        .HostLocalCoordinateSystem);

                    tx.Commit();
                }
            }
        }
コード例 #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="growthLength">The length by which the crack grows in each iteration.</param>
 private HolesBenchmark(string meshPath, double growthLength, BoundaryConditions bc, double jIntegralRadiusOverElementSize,
                        double tipEnrichmentRadius, string leftLsmPlotDirectory, string rightLsmPlotDirectory, string subdomainPlotDirectory,
                        string leftPropagationPath, string rightPropagationPath, bool writePropagation,
                        int maxIterations, double heavisideTol)
 {
     this.meshPath     = meshPath;
     this.growthLength = growthLength;
     this.bc           = bc;
     this.jIntegralRadiusOverElementSize = jIntegralRadiusOverElementSize;
     this.tipEnrichmentRadius            = tipEnrichmentRadius;
     this.leftLsmPlotDirectory           = leftLsmPlotDirectory;
     this.rightLsmPlotDirectory          = rightLsmPlotDirectory;
     this.subdomainPlotDirectory         = subdomainPlotDirectory;
     this.leftPropagationPath            = leftPropagationPath;
     this.rightPropagationPath           = rightPropagationPath;
     this.writePropagation = writePropagation;
     this.maxIterations    = maxIterations;
     this.heavisideTol     = heavisideTol;
 }
コード例 #10
0
        public TopologySimp99Lines(int nelx, int nely, double volfrac, double penal, double rmin,
                                   BoundaryConditions bc, PassiveElements passive, OptimAlgorithm alg)
        {
            this.nelx    = nelx;
            this.nely    = nely;
            this.volfrac = volfrac;
            this.penal   = penal;
            this.rmin    = rmin;

            if (bc == BoundaryConditions.MbbBeam)
            {
                feAnalysis = FEAnalysisHalfMbbBeam;
            }
            else if (bc == BoundaryConditions.ShortCantilever)
            {
                feAnalysis = FEAnalysisCantilever;
            }
            else if (bc == BoundaryConditions.Cantilever2LoadCases)
            {
                feAnalysis = FEAnalysisCantilever2LoadCases;
            }

            if (passive == PassiveElements.No)
            {
                applyPassiveElements = NoPassiveElements;
            }
            else if (passive == PassiveElements.HoleInCantilever)
            {
                applyPassiveElements = PassiveElementsForHoleInCantilever;
            }

            if (alg == OptimAlgorithm.OC)
            {
                optimAlgorithm = OptimalityCriteriaUpdate;
            }
            else if (alg == OptimAlgorithm.MMA)
            {
                optimAlgorithm = MethodMovingAsymptotesUpdate;
            }
        }
コード例 #11
0
        public LifeLikeCellularAutomatonViewModel()
        {
            CellNeighborhoods.Add(CellNeighborhoodTypeModel.Moore);
            CellNeighborhoods.Add(CellNeighborhoodTypeModel.VonNeumann);

            birthVonNeumannRulesSafe = new BindableCollection <NumberOfCellsForRulesModel>(vonNeumannRule.Birth.ToList());
            birthMooreRulesSafe      = new BindableCollection <NumberOfCellsForRulesModel>(mooreRule.Birth.ToList());

            survivalVonNeumannRulesSafe = new BindableCollection <NumberOfCellsForRulesModel>(vonNeumannRule.Survival.ToList());
            survivalMooreRulesSafe      = new BindableCollection <NumberOfCellsForRulesModel>(mooreRule.Survival.ToList());

            birthRules    = birthMooreRulesSafe;
            survivalRules = survivalMooreRulesSafe;

            birthRules[3].Chosen    = true;
            SurvivalRules[2].Chosen = true;
            SurvivalRules[3].Chosen = true;

            SelectedBirthRule    = birthRules[0];
            SelectedSurvivalRule = survivalRules[0];

            BoundaryConditions.Add(BoundaryConditionModel.Absorbing);
            BoundaryConditions.Add(BoundaryConditionModel.CounterAbsorbing);
            BoundaryConditions.Add(BoundaryConditionModel.Periodic);

            evolverAndDrawerDispatcherTimer          = new DispatcherTimer();
            evolverAndDrawerDispatcherTimer.Interval = TimeSpan.FromMilliseconds(timeIntervalInMilliseconds);
            evolverAndDrawerDispatcherTimer.Tick    += EvolverAndDrawer_Tick;

            cancellationTokenSource = new CancellationTokenSource();
            cancellationToken       = cancellationTokenSource.Token;
            ThreadPool.SetMinThreads(1, 1);
            ThreadPool.SetMaxThreads(1, 1);

            cellGrid = new CellGrid2DModel(columnCount, rowCount, selectedCellNeighborhood, mooreRule, SelectedBoundaryCondition);
            RunDrawerTask();
        }
コード例 #12
0
        private static NeigbhourhoodType getNeigbhourhoodType(Neighbourhood neighbourhoodType, BoundaryConditions boundaryConditionsType)
        {
            switch (boundaryConditionsType)
            {
            case BoundaryConditions.Normal:
                switch (neighbourhoodType)
                {
                case Neighbourhood.Moore:
                    return(NeigbhourhoodType.Moore);

                case Neighbourhood.VonNoyman:
                    return(NeigbhourhoodType.VonNoyman);

                case Neighbourhood.RandomPentagonal:
                    return(NeigbhourhoodType.PentagonalRandom);

                case Neighbourhood.RandomHexagonal:
                    return(NeigbhourhoodType.HexagonalRandom);

                default:
                    return(NeigbhourhoodType.Moore);
                }

            case BoundaryConditions.Periodic:
                switch (neighbourhoodType)
                {
                case Neighbourhood.Moore:
                    return(NeigbhourhoodType.MoorePeriodic);

                case Neighbourhood.VonNoyman:
                    return(NeigbhourhoodType.VonNoymanPeriodic);

                case Neighbourhood.RandomPentagonal:
                    return(NeigbhourhoodType.PentagonalRandomPeriodic);

                case Neighbourhood.RandomHexagonal:
                    return(NeigbhourhoodType.HexagonalRandomPeriodic);

                default:
                    return(NeigbhourhoodType.MoorePeriodic);
                }

            default:
                return(NeigbhourhoodType.Moore);
            }
        }
コード例 #13
0
        public override List <Point> GetNeighborhood(int CellX, int CellY, int SizeX, int SizeY, BoundaryConditions condition)
        {
            List <Point> cellNeighborIndexes = new List <Point>();

            cellNeighborIndexes.Add(new Point(CellX - 1, CellY - 1));
            cellNeighborIndexes.Add(new Point(CellX - 1, CellY));
            cellNeighborIndexes.Add(new Point(CellX, CellY - 1));
            cellNeighborIndexes.Add(new Point(CellX, CellY + 1));
            cellNeighborIndexes.Add(new Point(CellX + 1, CellY));
            cellNeighborIndexes.Add(new Point(CellX + 1, CellY + 1));

            CheckForBoundaryCondition(cellNeighborIndexes, SizeX, SizeY, condition);
            return(cellNeighborIndexes);
        }
コード例 #14
0
        internal List <Point> GetNeighborhoodRandomMultiple(int x, int y, int sizeX, int sizeY, BoundaryConditions boundaryCondition)
        {
            var    val = new Random().NextDouble();
            double sum = 0.0;

            for (int i = 0; i < RandomThresholdList.Count; i++)
            {
                sum += RandomThresholdList[i];
                if (val <= sum)
                {
                    return(CurrentNeighborhoods[i].GetNeighborhood(x, y, sizeX, sizeY, boundaryCondition));
                }
            }
            return(new List <Point>());
        }
コード例 #15
0
 internal List <Point> GetNeighborhoodRandomNone(int x, int y, int sizeX, int sizeY, BoundaryConditions boundaryCondition)
 {
     return(CurrentNeighborhoods[0].GetNeighborhood(x, y, sizeX, sizeY, boundaryCondition));
 }
コード例 #16
0
        private void SetBoundaryCondition(int i, int j, BoundaryConditions boundary)
        {
            switch (boundary)
            {
            case BoundaryConditions.RVBC_Uniform:
            {
                reaction[indexA, i, j] = initialXa;
                reaction[indexB, i, j] = initialXb;
                reaction[indexC, i, j] = initialXc;

                break;
            }

            case BoundaryConditions.RVBC_XGradient:
            {
                double d = (double)j / (double)vesselHeight;

                reaction[indexA, i, j] = d;
                reaction[indexB, i, j] = 1 - d;
                reaction[indexC, i, j] = minConcentration;

                break;
            }

            case BoundaryConditions.RVBC_YGradient:
            {
                double d = (double)i / (double)vesselWidth;

                reaction[indexA, i, j] = d;
                reaction[indexB, i, j] = 1 - d;
                reaction[indexC, i, j] = minConcentration;

                break;
            }

            case BoundaryConditions.RVBC_XSine:
            {
                double freq = 2.0;
                double d    = Math.Abs(Math.Sin(freq * (double)j * (Math.PI / 180)));

                reaction[indexA, i, j] = 1 - d;
                reaction[indexB, i, j] = d;     // 1 - d;
                reaction[indexC, i, j] = minConcentration;

                break;
            }

            case BoundaryConditions.RVBC_YSine:
            {
                double freq = 2.0;
                double d    = Math.Abs(Math.Sin(freq * (double)i * (Math.PI / 180)));

                reaction[indexA, i, j] = 1 - d;
                reaction[indexB, i, j] = d;     // 1 - d;
                reaction[indexC, i, j] = minConcentration;

                break;
            }

            default:
            {
                break;
            }
            }
        }
コード例 #17
0
        public static List <SpeckleObject> ToSpeckle(this BoundaryConditions myRestraint)
        {
            var points = new List <XYZ>();

            var restraintType = myRestraint.GetBoundaryConditionsType();

            if (restraintType == BoundaryConditionsType.Point)
            {
                var point = myRestraint.Point;
                points.Add(point);
            }
            else if (restraintType == BoundaryConditionsType.Line)
            {
                var curve = myRestraint.GetCurve();
                points.Add(curve.GetEndPoint(0));
                points.Add(curve.GetEndPoint(1));
            }
            else if (restraintType == BoundaryConditionsType.Area)
            {
                var loops = myRestraint.GetLoops();
                foreach (var loop in loops)
                {
                    foreach (var curve in loop)
                    {
                        points.Add(curve.GetEndPoint(0));
                        points.Add(curve.GetEndPoint(1));
                    }
                }
                points = points.Distinct().ToList();
            }

            var coordinateSystem = myRestraint.GetDegreesOfFreedomCoordinateSystem();
            var axis             = new StructuralAxis(
                new StructuralVectorThree(new double[] { coordinateSystem.BasisX.X, coordinateSystem.BasisX.Y, coordinateSystem.BasisX.Z }),
                new StructuralVectorThree(new double[] { coordinateSystem.BasisY.X, coordinateSystem.BasisY.Y, coordinateSystem.BasisY.Z }),
                new StructuralVectorThree(new double[] { coordinateSystem.BasisZ.X, coordinateSystem.BasisZ.Y, coordinateSystem.BasisZ.Z })
                );

            var restraint = new StructuralVectorBoolSix(new bool[6]);
            var stiffness = new StructuralVectorSix(new double[6]);

            var listOfParams = new BuiltInParameter[] {
                BuiltInParameter.BOUNDARY_DIRECTION_X,
                BuiltInParameter.BOUNDARY_DIRECTION_Y,
                BuiltInParameter.BOUNDARY_DIRECTION_Z,
                BuiltInParameter.BOUNDARY_DIRECTION_ROT_X,
                BuiltInParameter.BOUNDARY_DIRECTION_ROT_Y,
                BuiltInParameter.BOUNDARY_DIRECTION_ROT_Z
            };

            var listOfSpringParams = new BuiltInParameter[] {
                BuiltInParameter.BOUNDARY_RESTRAINT_X,
                BuiltInParameter.BOUNDARY_RESTRAINT_Y,
                BuiltInParameter.BOUNDARY_RESTRAINT_Z,
                BuiltInParameter.BOUNDARY_RESTRAINT_ROT_X,
                BuiltInParameter.BOUNDARY_RESTRAINT_ROT_Y,
                BuiltInParameter.BOUNDARY_RESTRAINT_ROT_Z,
            };

            for (var i = 0; i < 6; i++)
            {
                switch (myRestraint.get_Parameter(listOfParams[i]).AsInteger())
                {
                case 0:
                    restraint.Value[i] = true;
                    break;

                case 1:
                    restraint.Value[i] = false;
                    break;

                case 2:
                    stiffness.Value[i] = myRestraint.get_Parameter(listOfSpringParams[i]).AsDouble();
                    break;
                }
            }
            restraint.GenerateHash();
            stiffness.GenerateHash();

            var myNodes = new List <SpeckleObject>();

            foreach (var point in points)
            {
                var myPoint = (SpeckleCoreGeometryClasses.SpecklePoint)SpeckleCore.Converter.Serialise(point);
                var myNode  = new StructuralNode();
                myNode.basePoint = myPoint;
                myNode.Axis      = axis;
                myNode.Restraint = restraint;
                myNode.Stiffness = stiffness;
                myNodes.Add(myNode);
            }

            return(myNodes);
        }
コード例 #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="app"></param>
        /// <param name="element"></param>
        /// <returns></returns>
        public static Revit.Element CloneElement(Application app, Revit.Element element)
        {
            Opening opening = element as Opening;

            if (opening != null)
            {
                return(CloneElement(app, opening));
            }

            BoundaryConditions boundaryConditions = element as BoundaryConditions;

            if (boundaryConditions != null)
            {
                return(CloneElement(app, boundaryConditions));
            }

            AreaLoad areaLoad = element as AreaLoad;

            if (areaLoad != null)
            {
                return(CloneElement(app, areaLoad));
            }

            AreaReinforcement areaReinforcement = element as AreaReinforcement;

            if (areaReinforcement != null)
            {
                return(CloneElement(app, areaReinforcement));
            }

            BeamSystem beamSystem = element as BeamSystem;

            if (beamSystem != null)
            {
                return(CloneElement(app, beamSystem));
            }

            Dimension dimension = element as Dimension;

            if (dimension != null)
            {
                return(CloneElement(app, dimension));
            }

            FamilyInstance familyInstance = element as FamilyInstance;

            if (familyInstance != null)
            {
                return(CloneElement(app, familyInstance));
            }

            Floor floor = element as Floor;

            if (floor != null)
            {
                return(CloneElement(app, floor));
            }

            Grid grid = element as Grid;

            if (grid != null)
            {
                return(CloneElement(app, grid));
            }

            Group group = element as Group;

            if (group != null)
            {
                return(CloneElement(app, group));
            }

            Level level = element as Level;

            if (floor != null)
            {
                return(CloneElement(app, floor));
            }

            LineLoad lineLoad = element as LineLoad;

            if (lineLoad != null)
            {
                return(CloneElement(app, lineLoad));
            }

            LoadCase loadCase = element as LoadCase;

            if (loadCase != null)
            {
                return(CloneElement(app, loadCase));
            }

            LoadCombination loadCombination = element as LoadCombination;

            if (loadCombination != null)
            {
                return(CloneElement(app, loadCombination));
            }

            LoadNature loadNature = element as LoadNature;

            if (loadNature != null)
            {
                return(CloneElement(app, loadNature));
            }

            LoadUsage loadUsage = element as LoadUsage;

            if (loadUsage != null)
            {
                return(CloneElement(app, loadUsage));
            }

            ModelCurve modelCurve = element as ModelCurve;

            if (modelCurve != null)
            {
                return(CloneElement(app, modelCurve));
            }

            PointLoad pointLoad = element as PointLoad;

            if (pointLoad != null)
            {
                return(CloneElement(app, pointLoad));
            }

            Rebar rebar = element as Rebar;

            if (rebar != null)
            {
                return(CloneElement(app, rebar));
            }

            ReferencePlane referencePlane = element as ReferencePlane;

            if (referencePlane != null)
            {
                return(CloneElement(app, referencePlane));
            }

            Room room = element as Room;

            if (room != null)
            {
                return(CloneElement(app, room));
            }

            RoomTag roomTag = element as RoomTag;

            if (roomTag != null)
            {
                return(CloneElement(app, roomTag));
            }

            SketchPlane sketchPlane = element as SketchPlane;

            if (sketchPlane != null)
            {
                return(CloneElement(app, sketchPlane));
            }

            View3D view3D = element as View3D;

            if (view3D != null)
            {
                return(CloneElement(app, view3D));
            }

            ViewDrafting viewDrafting = element as ViewDrafting;

            if (viewDrafting != null)
            {
                return(CloneElement(app, viewDrafting));
            }

            ViewSection viewSection = element as ViewSection;

            if (viewSection != null)
            {
                return(CloneElement(app, viewSection));
            }

            ViewSheet viewSheet = element as ViewSheet;

            if (viewSheet != null)
            {
                return(CloneElement(app, viewSheet));
            }

            Wall wall = element as Wall;

            if (wall != null)
            {
                return(CloneElement(app, wall));
            }

            // this element has not yet been exposed in the Creation Document class
            //Debug.Assert(false);

            return(null);
        }
コード例 #19
0
 public abstract List <Point> GetNeighborhood(int CellX, int CellY, int SizeX, int SizeY, BoundaryConditions condition);
コード例 #20
0
 public void setBoundaryConditionType(BoundaryConditions type)
 {
     _boundoryConditionType = type;
 }
コード例 #21
0
 public void SetBoundaryConditions (BoundaryConditions bnd, double b1, double b2)
 {
   // check boundary conditions argument
   if (bnd == BoundaryConditions.Supply1stDerivative || bnd == BoundaryConditions.FiniteDifferences) 
   {
     boundary = bnd;
     r1 = b1;
     r2 = b2;
   } 
   else 
     throw new ArgumentException("Only Supply1stDerivative or FiniteDifferences boundary conditions");
 }
コード例 #22
0
 public ExponentialSpline()
 {
   boundary = BoundaryConditions.FiniteDifferences;
   sigma= 1.0;
 }
コード例 #23
0
 public RationalCubicSpline()
 {
   boundary=BoundaryConditions.Natural;
   p=0.0;
 }
コード例 #24
0
        /// <summary>
        /// Assigns initial conditions for the reaction vessel.
        /// </summary>
        private void SetInitialConditions()
        {
            this.SetBoundaryConditions(BoundaryConditions.RVBC_Uniform);

            this._boundaryConditionsPrev = this._boundaryConditions;

            for (int i = 1; i < vesselWidth - 1; i++)
            {
                for (int j = 1; j < vesselHeight - 1; j++)
                {
                    reaction[indexA, i, j] = initialXa;
                    reaction[indexB, i, j] = initialXb;
                    reaction[indexC, i, j] = initialXc;
                }
            }
        }
コード例 #25
0
        protected void CheckForBoundaryCondition(List <Point> cellNeighborIndexes, int SizeX, int SizeY, BoundaryConditions boundary)
        {
            Func <int, int, int> lessThanZero;
            Func <int, int, int> moreThanSize;


            if (boundary == BoundaryConditions.Periodic)
            {
                lessThanZero = PeriodicLessThanZero;
                moreThanSize = PeriodicMoreThanZero;
            }
            else if (boundary == BoundaryConditions.Reflective)
            {
                lessThanZero = ReflectiveLessThanZero;
                moreThanSize = ReflectiveMoreThanZero;
            }
            else
            {
                lessThanZero = FixedLessThanZero;
                moreThanSize = FixedMoreThanZero;
            }
            foreach (Point p in cellNeighborIndexes)
            {
                if (p.X < 0)
                {
                    p.X = lessThanZero(p.X, SizeX);
                }
                else if (p.X >= SizeX)
                {
                    p.X = moreThanSize(p.X, SizeX);
                }

                if (p.Y < 0)
                {
                    p.Y = lessThanZero(p.Y, SizeY);
                }
                else if (p.Y >= SizeY)
                {
                    p.Y = moreThanSize(p.Y, SizeY);
                }
            }
        }
コード例 #26
0
        ////////////////////////////////////////////////////////////////////////////////
        #region Public Methods

        /// <summary>
        /// Computes one frame of the reaction.
        /// </summary>
        /// <returns>An array containing the reaction products for the next frame. </returns>
        public unsafe double[, ,] ComputeReaction()
        {
            Debug.Assert(CheckInvariant(), "ComputeReaction: CheckInvariant failed");

            double Xa;
            double Xb;
            double Xc;
            double c;
            double d;
            double f;
            double g0;
            double feedbackFromC;
            double feedbackFromB;

            iteration++;

            // If boundary conditions have changed since the previous frame, update them.
            if (this._boundaryConditionsPrev != this._boundaryConditions)
            {
                this.SetBoundaryConditions(this._boundaryConditions);

                this._boundaryConditionsPrev = this._boundaryConditions;
            }

            // Copy boundary values to the out buffer.
            for (int i = 0; i < vesselWidth; i++)
            {
                reactionOut[indexA, i, 0] = reaction[indexA, i, 0];
                reactionOut[indexB, i, 0] = reaction[indexB, i, 0];
                reactionOut[indexC, i, 0] = reaction[indexC, i, 0];

                reactionOut[indexA, i, vesselHeight - 1] = reaction[indexA, i, vesselHeight - 1];
                reactionOut[indexB, i, vesselHeight - 1] = reaction[indexB, i, vesselHeight - 1];
                reactionOut[indexC, i, vesselHeight - 1] = reaction[indexC, i, vesselHeight - 1];
            }

            for (int j = 0; j < vesselHeight; j++)
            {
                reactionOut[indexA, 0, j] = reaction[indexA, 0, j];
                reactionOut[indexB, 0, j] = reaction[indexB, 0, j];
                reactionOut[indexC, 0, j] = reaction[indexC, 0, j];

                reactionOut[indexA, vesselWidth - 1, j] = reaction[indexA, vesselWidth - 1, j];
                reactionOut[indexB, vesselWidth - 1, j] = reaction[indexB, vesselWidth - 1, j];
                reactionOut[indexC, vesselWidth - 1, j] = reaction[indexC, vesselWidth - 1, j];
            }

            // Traverse the grid and compute concentrations for
            // all three reactants. This implements the Gontar model.
            for (int i = 1; i < vesselWidth - 1; i++)
            {
                for (int j = 1; j < vesselHeight - 1; j++)
                {
                    try
                    {
                        // Compute concentrations at cell (i,j).
                        feedbackFromC = Math.Exp(-W1 / weight(indexC, i, j));
                        feedbackFromB = Math.Exp(-W2 * weight(indexB, i, j));
                        g0            = (K1 * K2 * feedbackFromC * feedbackFromB) / (1.0 + K1 * feedbackFromC);

                        // Compute concentrations at cell (i,j).
                        //c = -W1 / weight(2, i, j);
                        //f = -W2 * weight(1, i, j);
                        //e_to_c = Math.Exp(c);
                        //e_to_f = Math.Exp(f);
                        //d = 1.0 + K1 * e_to_c;
                        //g0 = (K1 * K2 * e_to_c * e_to_f) / d;

                        Xc = b * (g0 / (g0 + 1));
                        if (Xc <= minConcentration)
                        {
                            Xc = minConcentration;
                        }

                        Xb = (K1 * feedbackFromC / (1 + K1 * feedbackFromC)) * (b - Xc);
                        if (Xb <= minConcentration)
                        {
                            Xb = minConcentration;
                        }

                        Xa = b - Xb - Xc;
                        if (Xa <= minConcentration)
                        {
                            Xa = minConcentration;
                        }


                        if (Xa > b)
                        {
                            Xa = b;
                        }

                        if (Xb > b)
                        {
                            Xb = b;
                        }

                        if (Xc > b)
                        {
                            Xc = b;
                        }

                        reactionOut[indexA, i, j] = Xa;
                        reactionOut[indexB, i, j] = Xb;
                        reactionOut[indexC, i, j] = Xc;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("caught exception: ", ex.ToString());
                    }
                }
            }

            int ubi = reaction.GetUpperBound(1) + 1;
            int ubj = reaction.GetUpperBound(2) + 1;

            // Copy the out buffer to the in buffer.
            fixed(double *pOutBuff = reactionOut, pInBuff = reaction)
            {
                uint buffSize = (uint)(3 * ubi * ubj * sizeof(double));

                uint count = buffSize;

                double *ps = pOutBuff;
                double *pd = pInBuff;

                lock (reactionOut.SyncRoot)
                {
                    try
                    {
                        CopyMemory((void *)pd, (void *)ps, count);
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex.Message);
                    }
                }
            }

            // Raise the IterationCompleted event.
            IterationCompletedEventArgs e = new IterationCompletedEventArgs(this.iteration);

            OnInterationCompleted(e);

            return(reactionOut);
        }
コード例 #27
0
        override public List <Point> GetNeighborhood(int CellX, int CellY, int SizeX, int SizeY, BoundaryConditions condition)
        {
            Random       r = new Random();
            List <Point> cellNeighborIndexes = new List <Point>();

            switch (r.Next(0, 3))
            {
            case 0:
                cellNeighborIndexes.Add(new Point(CellX, CellY - 1));
                cellNeighborIndexes.Add(new Point(CellX, CellY + 1));
                cellNeighborIndexes.Add(new Point(CellX + 1, CellY - 1));
                cellNeighborIndexes.Add(new Point(CellX + 1, CellY));
                cellNeighborIndexes.Add(new Point(CellX + 1, CellY + 1));
                break;

            case 1:
                cellNeighborIndexes.Add(new Point(CellX - 1, CellY - 1));
                cellNeighborIndexes.Add(new Point(CellX - 1, CellY));
                cellNeighborIndexes.Add(new Point(CellX, CellY - 1));
                cellNeighborIndexes.Add(new Point(CellX + 1, CellY - 1));
                cellNeighborIndexes.Add(new Point(CellX + 1, CellY));
                break;

            case 2:
                cellNeighborIndexes.Add(new Point(CellX - 1, CellY));
                cellNeighborIndexes.Add(new Point(CellX - 1, CellY + 1));
                cellNeighborIndexes.Add(new Point(CellX, CellY + 1));
                cellNeighborIndexes.Add(new Point(CellX + 1, CellY));
                cellNeighborIndexes.Add(new Point(CellX + 1, CellY + 1));
                break;

            case 3:
                cellNeighborIndexes.Add(new Point(CellX - 1, CellY - 1));
                cellNeighborIndexes.Add(new Point(CellX - 1, CellY));
                cellNeighborIndexes.Add(new Point(CellX - 1, CellY + 1));
                cellNeighborIndexes.Add(new Point(CellX, CellY - 1));
                cellNeighborIndexes.Add(new Point(CellX, CellY + 1));
                break;
            }

            CheckForBoundaryCondition(cellNeighborIndexes, SizeX, SizeY, condition);
            return(cellNeighborIndexes);
        }
コード例 #28
0
        public static SeedGrowth Create(int domainWidth, int domainHeight, Neighbourhood neighbourhoodType, BoundaryConditions boundaryConditionsType)
        {
            SeedGrowth sd = new SeedGrowth(domainWidth, domainHeight);

            sd.setNeighbourhoodType(getNeigbhourhoodType(neighbourhoodType, boundaryConditionsType));
            return(sd);
        }
コード例 #29
0
        private void Stream( ArrayList data, BoundaryConditions bndCnd )
        {
            data.Add( new Snoop.Data.ClassSeparator( typeof( BoundaryConditions ) ) );

              data.Add( new Snoop.Data.Object( "Associated load", bndCnd.Document.GetElement( bndCnd.AssociatedLoadId ) ) );
              data.Add( new Snoop.Data.Object( "Host element", bndCnd.HostElement ) );
              data.Add( new Snoop.Data.Xyz( "Point", bndCnd.Point ) );

              data.Add( new Snoop.Data.CategorySeparator( "Curves" ) );
              data.Add( new Snoop.Data.Int( "Number of curves", bndCnd.GetLoops().Count ) );
              for( int i = 0; i < bndCnd.GetLoops().Count; i++ )
              {
            data.Add( new Snoop.Data.Object( string.Format( "Curve [{0:d}]", i ), bndCnd.GetLoops()[i] ) );
              }
        }
コード例 #30
0
 internal List <Point> GetNeighborhood(int x, int y, int sizeX, int sizeY, BoundaryConditions boundaryCondition)
 {
     return(GetNeighborhoodFunction(x, y, sizeX, sizeY, boundaryCondition));
 }
コード例 #31
0
 protected void CheckForBoundaryCondition(List <Point> cellNeighborIndexes, int SizeX, int SizeY, BoundaryConditions boundary)
 {
     if (boundary == BoundaryConditions.Periodic)
     {
         BoundaryConditionTest(cellNeighborIndexes, SizeX, SizeY, PeriodicLessThanZero, PeriodicMoreThanZero);
     }
     else if (boundary == BoundaryConditions.Reflective)
     {
         BoundaryConditionTest(cellNeighborIndexes, SizeX, SizeY, ReflectiveLessThanZero, ReflectiveMoreThanZero);
     }
     else
     {
         for (int i = cellNeighborIndexes.Count - 1; i >= 0; i--)
         {
             Point p = cellNeighborIndexes[i];
             if (p.X < 0 || p.X >= SizeX || p.Y < 0 || p.Y >= SizeY)
             {
                 cellNeighborIndexes.RemoveAt(i);
             }
         }
     }
 }
コード例 #32
0
        internal List <Point> GetNeighborhoodRandomToggle(int x, int y, int sizeX, int sizeY, BoundaryConditions boundaryCondition)
        {
            var val = new Random().NextDouble();

            return(val >= RandomThresholdList[0] ? CurrentNeighborhoods[0].GetNeighborhood(x, y, sizeX, sizeY, boundaryCondition) : new List <Point>());
        }
コード例 #33
0
        override public List <Point> GetNeighborhood(int CellX, int CellY, int SizeX, int SizeY, BoundaryConditions condition)
        {
            Random       r = new Random();
            List <Point> cellNeighborIndexes = new List <Point>();

            if (r.NextDouble() > 0.5)
            {
                cellNeighborIndexes.Add(new Point(CellX - 1, CellY - 1));
                cellNeighborIndexes.Add(new Point(CellX - 1, CellY));
                cellNeighborIndexes.Add(new Point(CellX, CellY - 1));
                cellNeighborIndexes.Add(new Point(CellX, CellY + 1));
                cellNeighborIndexes.Add(new Point(CellX + 1, CellY));
                cellNeighborIndexes.Add(new Point(CellX + 1, CellY + 1));
            }
            else
            {
                cellNeighborIndexes.Add(new Point(CellX - 1, CellY));
                cellNeighborIndexes.Add(new Point(CellX - 1, CellY + 1));
                cellNeighborIndexes.Add(new Point(CellX, CellY - 1));
                cellNeighborIndexes.Add(new Point(CellX, CellY + 1));
                cellNeighborIndexes.Add(new Point(CellX + 1, CellY - 1));
                cellNeighborIndexes.Add(new Point(CellX + 1, CellY));
            }

            CheckForBoundaryCondition(cellNeighborIndexes, SizeX, SizeY, condition);
            return(cellNeighborIndexes);
        }
コード例 #34
0
        internal List <Point> GetNeighborhoodRandomDirection(int x, int y, int sizeX, int sizeY, BoundaryConditions boundaryCondition)
        {
            Random r = new Random();

            return(CurrentNeighborhoods[0].GetNeighborhood(x, y, sizeX, sizeY, boundaryCondition).Where((v, i) => RandomThresholdList[i] <= r.NextDouble()).ToList());
        }
コード例 #35
0
        /// <summary>
        /// Computes one frame of the reaction.
        /// </summary>
        /// <returns>An array containing the reaction products for the next frame. </returns>
        public unsafe double[, ,] ComputeReaction()
        {
            Debug.Assert(CheckInvariant(), "ComputeReaction: CheckInvariant failed");

            double Xa;
            double Xb;
            double Xc;
            double c;
            double d;
            double f;
            double g0;
            double feedbackFromC;
            double feedbackFromB;

            iteration++;

            // If boundary conditions have changed since the previous frame, update them.
            if (this._boundaryConditionsPrev != this._boundaryConditions)
            {
                this.SetBoundaryConditions(this._boundaryConditions);

                this._boundaryConditionsPrev = this._boundaryConditions;
            }

            // Copy boundary values to the out buffer.
            for (int i = 0; i < vesselWidth; i++)
            {
                reactionOut[indexA, i, 0] = reaction[indexA, i, 0];
                reactionOut[indexB, i, 0] = reaction[indexB, i, 0];
                reactionOut[indexC, i, 0] = reaction[indexC, i, 0];

                reactionOut[indexA, i, vesselHeight - 1] = reaction[indexA, i, vesselHeight - 1];
                reactionOut[indexB, i, vesselHeight - 1] = reaction[indexB, i, vesselHeight - 1];
                reactionOut[indexC, i, vesselHeight - 1] = reaction[indexC, i, vesselHeight - 1];
            }

            for (int j = 0; j < vesselHeight; j++)
            {
                reactionOut[indexA, 0, j] = reaction[indexA, 0, j];
                reactionOut[indexB, 0, j] = reaction[indexB, 0, j];
                reactionOut[indexC, 0, j] = reaction[indexC, 0, j];

                reactionOut[indexA, vesselWidth - 1, j] = reaction[indexA, vesselWidth - 1, j];
                reactionOut[indexB, vesselWidth - 1, j] = reaction[indexB, vesselWidth - 1, j];
                reactionOut[indexC, vesselWidth - 1, j] = reaction[indexC, vesselWidth - 1, j];
            }

            // Traverse the grid and compute concentrations for
            // all three reactants. This implements the Gontar model.
            for (int i = 1; i < vesselWidth - 1; i++)
            {
                for (int j = 1; j < vesselHeight - 1; j++)
                {
                    try
                    {
                        // Compute concentrations at cell (i,j).
                        feedbackFromC = Math.Exp( -W1 / weight( indexC, i, j ) );
                        feedbackFromB = Math.Exp( -W2 * weight( indexB, i, j ) );
                        g0 = ( K1 * K2 * feedbackFromC * feedbackFromB ) / ( 1.0 + K1 * feedbackFromC );

                        // Compute concentrations at cell (i,j).
                        //c = -W1 / weight(2, i, j);
                        //f = -W2 * weight(1, i, j);
                        //e_to_c = Math.Exp(c);
                        //e_to_f = Math.Exp(f);
                        //d = 1.0 + K1 * e_to_c;
                        //g0 = (K1 * K2 * e_to_c * e_to_f) / d;

                        Xc = b * (g0 / (g0 + 1));
                        if (Xc <= minConcentration) Xc = minConcentration;

                        Xb = (K1 * feedbackFromC / (1 + K1 * feedbackFromC)) * (b - Xc);
                        if (Xb <= minConcentration) Xb = minConcentration;

                        Xa = b - Xb - Xc;
                        if (Xa <= minConcentration) Xa = minConcentration;

                        if (Xa > b) Xa = b;

                        if (Xb > b) Xb = b;

                        if (Xc > b) Xc = b;

                        reactionOut[indexA, i, j] = Xa;
                        reactionOut[indexB, i, j] = Xb;
                        reactionOut[indexC, i, j] = Xc;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("caught exception: ", ex.ToString());
                    }

                }
            }

            int ubi = reaction.GetUpperBound(1) + 1;
            int ubj = reaction.GetUpperBound(2) + 1;

            // Copy the out buffer to the in buffer.
            fixed (double* pOutBuff = reactionOut, pInBuff = reaction)
            {
                uint buffSize = (uint)(3 * ubi * ubj * sizeof(double));

                uint count = buffSize;

                double* ps = pOutBuff;
                double* pd = pInBuff;

                lock (reactionOut.SyncRoot)
                {
                    try
                    {
                        CopyMemory((void*)pd, (void*)ps, count);
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex.Message);
                    }
                }
            }

            // Raise the IterationCompleted event.
            IterationCompletedEventArgs e = new IterationCompletedEventArgs(this.iteration);
            OnInterationCompleted(e);

            return reactionOut;
        }
コード例 #36
0
 public void SetBoundaryCondition(int boundaryCondition)
 {
     BoundaryCondition = (BoundaryConditions)boundaryCondition;
 }
コード例 #37
0
        private void SetBoundaryCondition(int i, int j, BoundaryConditions boundary)
        {
            switch (boundary)
            {
                case BoundaryConditions.RVBC_Uniform:
                {
                    reaction[indexA, i, j] = initialXa;
                    reaction[indexB, i, j] = initialXb;
                    reaction[indexC, i, j] = initialXc;

                    break;
                }
                case BoundaryConditions.RVBC_XGradient:
                {
                    double d = (double)j / (double)vesselHeight;

                    reaction[indexA, i, j] = d;
                    reaction[indexB, i, j] = 1 - d;
                    reaction[indexC, i, j] = minConcentration;

                    break;
                }
                case BoundaryConditions.RVBC_YGradient:
                {
                    double d = (double)i / (double)vesselWidth;

                    reaction[indexA, i, j] = d;
                    reaction[indexB, i, j] = 1 - d;
                    reaction[indexC, i, j] = minConcentration;

                    break;
                }

                case BoundaryConditions.RVBC_XSine:
                {
                    double freq = 2.0;
                    double d = Math.Abs(Math.Sin(freq * (double)j * (Math.PI / 180)));

                    reaction[indexA, i, j] = 1 - d;
                    reaction[indexB, i, j] = d; // 1 - d;
                    reaction[indexC, i, j] = minConcentration;

                    break;
                }
                case BoundaryConditions.RVBC_YSine:
                {
                    double freq = 2.0;
                    double d = Math.Abs(Math.Sin(freq * (double)i * (Math.PI / 180)));

                    reaction[indexA, i, j] = 1 - d;
                    reaction[indexB, i, j] = d; // 1 - d;
                    reaction[indexC, i, j] = minConcentration;

                    break;
                }

                default:
                {
                    break;
                }
            }
        }
コード例 #38
0
        private void SetBoundaryConditions(BoundaryConditions boundary)
        {
            lock (this.reaction.SyncRoot)
            {
                for (int i = 0; i < vesselWidth; i++)
                {
                    this.SetBoundaryCondition(i, 0, boundary);
                    this.SetBoundaryCondition(i, vesselHeight - 1, boundary);
                }

                for (int j = 0; j < vesselHeight; j++)
                {
                    this.SetBoundaryCondition(0, j, boundary);
                    this.SetBoundaryCondition(vesselWidth - 1, j, boundary);
                }
            }
        }
コード例 #39
0
 /// <summary>
 /// Sets the boundary conditions.
 /// </summary>
 /// <param name="bnd"> The boundary condition. See remarks for the possible values.</param>
 /// <param name="b1"></param>
 /// <param name="b2"></param>
 /// <remarks>
 /// <code>
 ///      Natural 
 ///          natural boundaries, that means the 2nd derivatives are zero 
 ///          at both boundaries. This is the default value.
 ///
 ///      FiniteDifferences
 ///          use  finite difference approximation for 1st derivatives.
 ///
 ///      Supply1stDerivative
 ///          user supplied values for 1st derivatives are given in b1 and b2
 ///          i.e. f'(x_lo) in b1
 ///               f'(x_hi) in b2
 ///
 ///      Supply2ndDerivative 
 ///          user supplied values for 2nd derivatives are given in b1 and b2
 ///          i.e. f''(x_lo) in b1
 ///               f''(x_hi) in b2
 ///
 ///      Periodic 
 ///          periodic boundary conditions for periodic curves or functions.
 ///          NOT YET IMPLEMENTED IN THIS VERSION.
 /// </code>
 /// </remarks>
 public void SetBoundaryConditions(
   BoundaryConditions bnd, 
   double b1, 
   double b2)
 {
   boundary = bnd;
   r1 = b1;
   r2 = b2;
 }