public ContinuumElement2DFactory(double commonThickness, ElasticMaterial2D commonMaterial,
                                  DynamicMaterial commonDynamicProperties)
 {
     this.commonThickness         = commonThickness;
     this.commonMaterial          = commonMaterial;
     this.commonDynamicProperties = commonDynamicProperties;
 }
        private static PreprocessorModel CreateModel(IReadOnlyList <Node> nodes, IReadOnlyList <CellConnectivity <Node> > elements)
        {
            PreprocessorModel model = PreprocessorModel.Create2DPlaneStress(thickness);

            // Materials properties
            ElasticMaterial2D material = new ElasticMaterial2D(StressState2D.PlaneStress)
            {
                YoungModulus = youngModulus,
                PoissonRatio = poissonRatio
            };
            DynamicMaterial dynamicProperties = new DynamicMaterial(density, 0.05, 0.05, true);

            // Mesh
            model.AddMesh2D(nodes, elements, material, dynamicProperties);

            // Prescribed displacements: all nodes at the bottom
            double             tol = 1E-10;
            IEnumerable <Node> constrainedNodes = nodes.Where(node => Math.Abs(node.Y) <= tol);

            model.ApplyPrescribedDisplacements(constrainedNodes, StructuralDof.TranslationX, 0.0);
            model.ApplyPrescribedDisplacements(constrainedNodes, StructuralDof.TranslationY, 0.0);



            return(model);
        }
		public ContinuumElement3D CreateElement(CellType cellType, IReadOnlyList<Node> nodes,
			ElasticMaterial3D commonMaterial, DynamicMaterial commonDynamicProperties)
		{
			int numGPs = integrationsForStiffness[cellType].IntegrationPoints.Count;
			var materialsAtGaussPoints = new ElasticMaterial3D[numGPs];
			for (int gp = 0; gp < numGPs; ++gp) materialsAtGaussPoints[gp] = commonMaterial.Clone();
			return CreateElement(cellType, nodes, materialsAtGaussPoints, commonDynamicProperties);
		}
Example #4
0
        public void ContinuumElement3DNonLinearVonMisesMaterialDynamicConsistent()
        {
            IList <Node> nodes = new List <Node>();

            // Create Model
            var model = new Model();

            // Create Subdomain
            model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID));

            // Create von Mises Plastic Material
            var solidMaterial = new VonMisesMaterial3D(youngModulus, poissonRatio, yieldStress, plasticModulus);

            // Create Dynamic Material
            var dynamicMaterial = new DynamicMaterial(density, 0, 0, true);

            DefineContinuumElement3DNonLinear(model, solidMaterial, dynamicMaterial);

            BoundaryConditionsNLM(model);

            // Choose linear equation system solver
            var           solverBuilder = new SkylineSolver.Builder();
            SkylineSolver solver        = solverBuilder.BuildSolver(model);

            // Choose the provider of the problem -> here a structural problem
            var provider = new ProblemStructural(model, solver);

            // Choose child analyzer -> Child: NewtonRaphson - LoadControl
            var subdomainUpdaters    = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) };
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(model, solver, provider, increments)
            {
                MaxIterationsPerIncrement     = 50,
                NumIterationsForMatrixRebuild = 1,
                ResidualTolerance             = 1E-06,
            };
            var childAnalyzer = childAnalyzerBuilder.Build();

            // Choose parent analyzer -> Parent: Static
            var parentAnalyzerBuilder = new NewmarkDynamicAnalyzer.Builder(model, solver, provider, childAnalyzer, 1.0, 100.0);

            parentAnalyzerBuilder.SetNewmarkParametersForConstantAcceleration();
            NewmarkDynamicAnalyzer parentAnalyzer = parentAnalyzerBuilder.Build();

            // Request output
            childAnalyzer.LogFactories[subdomainID] = new LinearAnalyzerLogFactory(new int[] { monitorDof });

            // Run the analysis
            parentAnalyzer.Initialize();
            parentAnalyzer.Solve();

            // Check output
            DOFSLog log           = (DOFSLog)childAnalyzer.Logs[subdomainID][0];
            double  computedValue = log.DOFValues[monitorDof];
            double  expectedValue = 1.93737;

            Assert.Equal(expectedValue, computedValue, 2);
        }
Example #5
0
        public void ContinuumElement3DElasticMaterialDynamicConsistent()
        {
            IList <Node> nodes = new List <Node>();

            // Create Model
            var model = new Model();

            // Create Subdomain
            model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID));

            // Create Elastic Material
            var solidMaterial = new ElasticMaterial3D()
            {
                YoungModulus = youngModulus,
                PoissonRatio = poissonRatio,
            };

            // Create Dynamic Material
            var dynamicMaterial = new DynamicMaterial(density, 0, 0, true);

            DefineContinuumElement3DLinear(model, solidMaterial, dynamicMaterial);

            BoundaryConditions(model);

            // Choose linear equation system solver
            var           solverBuilder = new SkylineSolver.Builder();
            SkylineSolver solver        = solverBuilder.BuildSolver(model);

            // Choose the provider of the problem -> here a structural problem
            var provider = new ProblemStructural(model, solver);

            // Choose child analyzer -> Linear
            var childAnalyzer = new LinearAnalyzer(model, solver, provider);

            // Choose parent analyzer -> Parent: Static
            var parentAnalyzerBuilder = new NewmarkDynamicAnalyzer.Builder(model, solver, provider, childAnalyzer, 1.0, 100.0);

            parentAnalyzerBuilder.SetNewmarkParametersForConstantAcceleration();
            NewmarkDynamicAnalyzer parentAnalyzer = parentAnalyzerBuilder.Build();

            // Request output
            childAnalyzer.LogFactories[subdomainID] = new LinearAnalyzerLogFactory(new int[] { monitorDof });

            // Run the analysis
            parentAnalyzer.Initialize();
            parentAnalyzer.Solve();

            // Check output
            DOFSLog log           = (DOFSLog)childAnalyzer.Logs[subdomainID][0];
            double  computedValue = log.DOFValues[monitorDof];
            double  expectedValue = 0.531178; // consistent: 0.531178 // lumped: 0.894201

            Assert.Equal(expectedValue, computedValue, 3);
        }
		public ContinuumElement3D CreateElement(CellType cellType, IReadOnlyList<Node> nodes,
			IReadOnlyList<ElasticMaterial3D> materialsAtGaussPoints, DynamicMaterial commonDynamicProperties)
		{
			//TODO: check if nodes - interpolation and Gauss points - materials match
#if DEBUG
			interpolations[cellType].CheckElementNodes(nodes);
#endif
			return new ContinuumElement3D(nodes, interpolations[cellType],
				integrationsForStiffness[cellType], integrationsForMass[cellType], extrapolations[cellType],
				materialsAtGaussPoints, commonDynamicProperties);
		}
        public ContinuumElement2D CreateElement(CellType cellType, IReadOnlyList <Node> nodes, double thickness,
                                                ElasticMaterial2D material, DynamicMaterial dynamicProperties)
        {
            int numGPs = integrationsForStiffness[cellType].IntegrationPoints.Count;
            var materialsAtGaussPoints = new ElasticMaterial2D[numGPs];

            for (int gp = 0; gp < numGPs; ++gp)
            {
                materialsAtGaussPoints[gp] = material.Clone();
            }
            return(CreateElement(cellType, nodes, thickness, materialsAtGaussPoints, dynamicProperties));
        }
        private static void UpdateNewmarkModel(Dictionary <int, IVector> accelerations, Dictionary <int, IVector> velocities, Dictionary <int, IVector> displacements, IStructuralModel[] modelsToReplace,
                                               ISolver[] solversToReplace, IImplicitIntegrationProvider[] providersToReplace, IChildAnalyzer[] childAnalyzersToReplace)
        {
            double[]         sol0 = Solutions[0][0].CopyToArray();
            double[]         sol1 = Solutions[1][0].CopyToArray();
            var              load = new double[] { sol1[39], sol1[39], sol1[39] };
            IDynamicMaterial commonDynamicMaterialProperties = new DynamicMaterial(.001, 0, 0, true);

            Accelerations              = accelerations;
            Velocities                 = velocities;
            Displacements              = displacements;
            modelsToReplace[0]         = CreateStructuralModel(10e4, 0, commonDynamicMaterialProperties, 0, load).Item1;
            solversToReplace[0]        = builder.BuildSolver(modelsToReplace[0]);
            providersToReplace[0]      = new ProblemStructural(modelsToReplace[0], solversToReplace[0]);
            childAnalyzersToReplace[0] = new LinearAnalyzer(modelsToReplace[0], solversToReplace[0], providersToReplace[0]);
        }
Example #9
0
        private static void UpdateNewmarkModel(Dictionary <int, IVector> accelerations, Dictionary <int, IVector> velocities, Dictionary <int, IVector> displacements, IStructuralModel[] modelsToReplace,
                                               ISolver[] solversToReplace, IImplicitIntegrationProvider[] providersToReplace, IChildAnalyzer[] childAnalyzersToReplace)
        {
            //double[] disp = displacements[0].CopyToArray();
            //Displacements = Vector.CreateFromArray(disp);
            IDynamicMaterial commonDynamicMaterialProperties = new DynamicMaterial(.001, 0, 0, true);

            //modelsToReplace[0] = CreateModel1(1, 1, new DynamicMaterial(.001, 0, 0, true), 0, new double[] { 0, 0, 200 }, lambdag).Item1;
            ReplaceLambdaGInModel(modelsToReplace[0], lambdag);
            solversToReplace[0]   = builder.BuildSolver(modelsToReplace[0]);
            providersToReplace[0] = new ProblemStructural(modelsToReplace[0], solversToReplace[0]);
            var increments           = 2;
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(modelsToReplace[0], solversToReplace[0], (INonLinearProvider)providersToReplace[0], increments);

            childAnalyzersToReplace[0] = childAnalyzerBuilder.Build();
        }
Example #10
0
        /// <summary>
        /// 测试加载一个动态的可以设置参数的材质
        /// </summary>
        private void TestDynamicMaterial()
        {
            var mesh = Actor.GetComponent <StaticMeshComponent>();

            if (mesh == null)
            {
                Log.Error("[MaterialTest] mesh is null");
            }

            mesh.SetScalarParameter("ChooseType", 0.0f);

            var mat = mesh.GetMaterial(2);

            if (mat == null)
            {
                Log.Error("[MaterialTest] get mat is null");
            }

            var m = Resource.LoadMaterial("Resources/UI/选人/Material__72");

            if (m == null)
            {
                Log.Error("[MaterialTest] load mat is null");
            }

            var dm = DynamicMaterial.Create(m, Actor);

            if (dm == null)
            {
                Log.Error("[MaterialTest] create DynamicMaterial is null");
            }

            var tex = Resource.LoadTexture("Resources/Textures/Ground4");

            if (tex == null)
            {
                Log.Error("[MaterialTest] LoadTexture is null");
                return;
            }

            mesh.SetMaterial(2, dm);
            dm.SetTextureParameter("Texture", tex);
        }
        public ContinuumElement2D(double thickness, IReadOnlyList <Node> nodes, IIsoparametricInterpolation2D interpolation,
                                  IQuadrature2D quadratureForStiffness, IQuadrature2D quadratureForConsistentMass,
                                  IGaussPointExtrapolation2D gaussPointExtrapolation,
                                  IReadOnlyList <ElasticMaterial2D> materialsAtGaussPoints, DynamicMaterial dynamicProperties)
        {
            this.dynamicProperties       = dynamicProperties;
            this.materialsAtGaussPoints  = materialsAtGaussPoints;
            this.GaussPointExtrapolation = gaussPointExtrapolation;
            this.Nodes         = nodes;
            this.Interpolation = interpolation;
            this.QuadratureForConsistentMass = quadratureForConsistentMass;
            this.QuadratureForStiffness      = quadratureForStiffness;
            this.Thickness = thickness;

            dofTypes = new IDofType[nodes.Count][];
            for (int i = 0; i < nodes.Count; ++i)
            {
                dofTypes[i] = new IDofType[] { StructuralDof.TranslationX, StructuralDof.TranslationY };
            }
        }
Example #12
0
        /// <summary>
        /// 测试加载一个动态的可以设置参数的材质
        /// </summary>
        private void TestDynamicMaterial()
        {
            var mesh = Actor.GetComponent <StaticMeshComponent>();

            if (mesh == null)
            {
                return;
            }
            var mat = mesh.GetMaterial(0);

            if (mat == null)
            {
                return;
            }

            var m = Resource.LoadMaterial("/Resources/Materials/NewMaterial");

            if (m == null)
            {
                return;
            }

            var dm = DynamicMaterial.Create(m, Actor);

            if (dm == null)
            {
                return;
            }

            var tex = Resource.LoadTexture("/Resources/Textures/Ground4");

            if (tex == null)
            {
                Log.Debug("tex != null.");
                return;
            }

            mesh.SetMaterial(0, dm);
            dm.SetTextureParameter("MainTex", tex);
        }
Example #13
0
    public DynamicMaterialSystem()
    {
        foreach (GameObject go in _dynGO)
        {
            DynamicMaterial dynMat = go.GetComponent <DynamicMaterial>();

            if (dynMat.type == EDynMat.HEALTH)
            {
                WithHealth healthComp = go.GetComponent <WithHealth>();
                healthComp.maxHealth = healthComp.health;
                dynMat.percentage    = healthComp.health / healthComp.maxHealth;
            }
            else if (dynMat.type == EDynMat.FREEZE)
            {
                Frozen comp = go.GetComponent <Frozen>();
                dynMat.percentage = 0;
                if (comp)
                {
                    dynMat.percentage = comp.remainingTime / comp.totalTime;
                }
            }
            else if (dynMat.type == EDynMat.B_Cell)
            {
                BCell comp = go.GetComponent <BCell>();
                if (comp)
                {
                    dynMat.percentage = comp.cooldown / comp.delay;
                }
            }

            foreach (Material mat in go.GetComponent <Renderer>().materials)
            {
                if (mat.name.Contains(dynMat.materialName) || go.GetComponent <Renderer>().materials.Length == 1)
                {
                    mat.color = dynMat.startingColor;
                }
            }
        }
    }
        private static void UpdateNewmarkModel(Dictionary <int, IVector> accelerations, Dictionary <int, IVector> velocities, Dictionary <int, IVector> displacements, IStructuralModel[] modelsToReplace,
                                               ISolver[] solversToReplace, IImplicitIntegrationProvider[] providersToReplace, IChildAnalyzer[] childAnalyzersToReplace)
        {
            double[] sol0 = Solutions[0][0].CopyToArray();
            //double[] sol1 = Solutions[1][0].CopyToArray();
            //var load = new double[] { sol1[39], sol1[39], sol1[39] };
            IDynamicMaterial commonDynamicMaterialProperties = new DynamicMaterial(.001, 0, 0, true);

            Accelerations = accelerations;
            Velocities    = velocities;
            Displacements = displacements;
            //modelsToReplace[0] = CreateStructuralModel(3e4, 0, commonDynamicMaterialProperties, 0, new double[] { 1000, 0, 0 }, lambdag).Item1;
            ReplaceLambdaGInModel(modelsToReplace[0], 1);
            solversToReplace[0]   = structuralBuilder.BuildSolver(modelsToReplace[0]);
            providersToReplace[0] = new ProblemStructural(modelsToReplace[0], solversToReplace[0]);
            solversToReplace[0].HandleMatrixWillBeSet();
            //childAnalyzersToReplace[0] = new LinearAnalyzer(modelsToReplace[0], solversToReplace[0], providersToReplace[0]);
            var increments           = 2;
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(modelsToReplace[0], solversToReplace[0], (INonLinearProvider)providersToReplace[0], increments);

            childAnalyzersToReplace[0] = childAnalyzerBuilder.Build();
        }
Example #15
0
    // Use to process your families.
    protected override void onProcess(int familiesUpdateCount)
    {
        foreach (GameObject go in _dynGO)
        {
            DynamicMaterial dynMat = go.GetComponent <DynamicMaterial>();

            if (dynMat.type == EDynMat.HEALTH)
            {
                WithHealth healthComp = go.GetComponent <WithHealth>();
                dynMat.percentage = healthComp.health / healthComp.maxHealth;
            }
            else if (dynMat.type == EDynMat.FREEZE)
            {
                Frozen comp = go.GetComponent <Frozen>();
                dynMat.percentage = 0;
                if (comp)
                {
                    dynMat.percentage = comp.remainingTime / comp.totalTime;
                }
            }
            else if (dynMat.type == EDynMat.B_Cell)
            {
                BCell comp = go.GetComponent <BCell>();
                if (comp)
                {
                    dynMat.percentage = comp.cooldown / comp.delay;
                }
            }

            foreach (Material mat in go.GetComponent <Renderer>().materials)
            {
                if (mat.name.Contains(dynMat.materialName) || go.GetComponent <Renderer>().materials.Length == 1)
                {
                    mat.color = Color.Lerp(dynMat.endingColor, dynMat.startingColor, dynMat.percentage);
                }
            }
        }
    }
        /// <summary>
        /// Adds a whole mesh, which is defined by its nodes and elements, to the model.
        /// </summary>
        /// <param name="nodes">The nodes of the mesh.</param>
        /// <param name="elements">The elements of the mesh.</param>
        /// <param name="material">The common material of all elements in the mesh.</param>
        /// <param name="dynamicProperties">Optional material properties for dynamic analysis. Common for all elements in the
        ///     mesh.</param>
        public void AddMesh2D(IReadOnlyList <Node> nodes, IReadOnlyList <CellConnectivity <Node> > elements,
                              IFiniteElementMaterial material, DynamicMaterial dynamicProperties = null)
        {
            if (Dimensions == ProblemDimensions.ThreeDimensional)
            {
                throw new InvalidOperationException(
                          "This method can be used only for 2D problems (plane strain or plane stress)");
            }

            // Nodes
            int numNodesCurrent = model.NodesDictionary.Count;

            for (int i = 0; i < nodes.Count; ++i)
            {
                model.NodesDictionary.Add(numNodesCurrent + i, nodes[i]);
            }

            // Elements
            int numElementsCurrent   = model.Elements.Count;
            int numElementsSubdomain = model.Subdomains[0].Elements.Count;
            var factory = new ContinuumElement2DFactory(thickness, (ElasticMaterial2D)material, dynamicProperties); //TODO: extend the factory to other materials

            for (int i = 0; i < elements.Count; ++i)
            {
                ContinuumElement2D element = factory.CreateElement(elements[i].CellType, elements[i].Vertices);
                var elementWrapper         = new Element()
                {
                    ID = numElementsCurrent + i, ElementType = element
                };
                foreach (Node node in element.Nodes)
                {
                    elementWrapper.AddNode(node);
                }
                model.ElementsDictionary.Add(numElementsCurrent + i, elementWrapper);
                model.SubdomainsDictionary[0].Elements.Add(elementWrapper); //TODO: let the user decide which subdomain it will be added to.
            }
        }
        public static void WriteStiffnessOfContinuum3DStructure()
        {
            //    _____ ____
            //   /    /    /|
            //  /____/____/ |
            //  |    |    | |
            //  |____|____|/|
            //  |    |    | /
            //  |____|____|/
            //

            // Model with 1 subdomain
            var model = new Model();

            model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID));

            // Material
            var material = new ElasticMaterial3D()
            {
                YoungModulus = 2.1E7,
                PoissonRatio = 0.3
            };
            var dynamicProperties = new DynamicMaterial(1.0, 0.0, 0.0, true);

            // Generate mesh
            double lengthX       = 2.0;
            double lengthY       = 2.4;
            double lengthZ       = 2.2;
            var    meshGenerator = new UniformMeshGenerator3D <Node>(0.0, 0.0, 0.0, lengthX, lengthY, lengthZ, 10, 10, 10);

            (IReadOnlyList <Node> vertices, IReadOnlyList <CellConnectivity <Node> > cells) =
                meshGenerator.CreateMesh((id, x, y, z) => new Node(id: id, x: x, y:  y, z: z));

            // Add nodes to the model
            for (int n = 0; n < vertices.Count; ++n)
            {
                model.NodesDictionary.Add(n, vertices[n]);
            }

            // Add Quad4 elements to the model
            var factory = new ContinuumElement3DFactory(material, dynamicProperties);

            for (int e = 0; e < cells.Count; ++e)
            {
                ContinuumElement3D element = factory.CreateElement(cells[e].CellType, cells[e].Vertices);
                var elementWrapper         = new Element()
                {
                    ID = e, ElementType = element
                };
                foreach (Node node in element.Nodes)
                {
                    elementWrapper.AddNode(node);
                }
                model.ElementsDictionary.Add(e, elementWrapper);
                model.SubdomainsDictionary[subdomainID].Elements.Add(elementWrapper);
            }

            // Solver
            var           solverBuilder = new SkylineSolver.Builder();
            SkylineSolver solver        = solverBuilder.BuildSolver(model);

            // Structural problem provider
            var provider = new ProblemStructural(model, solver);

            // Linear static analysis
            var childAnalyzer  = new LinearAnalyzer(model, solver, provider);
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

            // Run the analysis to build the stiffness matrix
            parentAnalyzer.Initialize();
            parentAnalyzer.BuildMatrices();

            // Print the stiffness matrix
            //var writer = new MatlabWriter();
            var writer = new RawArraysWriter();

            writer.WriteToMultipleFiles((SkylineMatrix)solver.LinearSystems[subdomainID].Matrix,
                                        outputDirectory + @"\hexa8_10x10x10_stiffness.txt");
        }
Example #18
0
            public CantileverBeam BuildWithQuad4Elements(int numElementsAlongLength, int numElementsAlongHeight)
            {
                // Material and section properties
                double thickness = Width;
                var    material  = new ElasticMaterial2D(StressState2D.PlaneStress)
                {
                    YoungModulus = this.YoungModulus,
                    PoissonRatio = this.PoissonRatio
                };
                var dynamicProperties = new DynamicMaterial(1.0, 0.0, 0.0);

                // Model with 1 subdomain
                var model = new Model();

                model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID));

                // Generate mesh
                var meshGenerator = new UniformMeshGenerator2D <Node>(0.0, 0.0, Length, Height,
                                                                      numElementsAlongLength, numElementsAlongHeight);

                (IReadOnlyList <Node> vertices, IReadOnlyList <CellConnectivity <Node> > cells) =
                    meshGenerator.CreateMesh((id, x, y, z) => new Node(id: id, x: x, y:  y, z: z));

                // Add nodes to the model
                for (int n = 0; n < vertices.Count; ++n)
                {
                    model.NodesDictionary.Add(n, vertices[n]);
                }

                // Add Quad4 elements to the model
                var factory = new ContinuumElement2DFactory(thickness, material, dynamicProperties);

                for (int e = 0; e < cells.Count; ++e)
                {
                    ContinuumElement2D element = factory.CreateElement(cells[e].CellType, cells[e].Vertices);
                    var elementWrapper         = new Element()
                    {
                        ID = e, ElementType = element
                    };
                    foreach (Node node in element.Nodes)
                    {
                        elementWrapper.AddNode(node);
                    }
                    model.ElementsDictionary.Add(e, elementWrapper);
                    model.SubdomainsDictionary[subdomainID].Elements.Add(elementWrapper);
                }

                // Clamp boundary condition at one end
                double tol = 1E-10; //TODO: this should be chosen w.r.t. the element size along X

                foreach (var node in model.Nodes.Where(node => Math.Abs(node.X) <= tol))
                {
                    node.Constraints.Add(new Constraint()
                    {
                        DOF = StructuralDof.TranslationX, Amount = 0.0
                    });
                    node.Constraints.Add(new Constraint()
                    {
                        DOF = StructuralDof.TranslationY, Amount = 0.0
                    });
                }

                // Apply concentrated load at the other end
                Node[] loadedNodes = model.Nodes.Where(node => Math.Abs(node.X - Length) <= tol).ToArray();
                foreach (var node in loadedNodes)
                {
                    model.Loads.Add(new Load()
                    {
                        Amount = EndPointLoad / loadedNodes.Length, Node = node, DOF = StructuralDof.TranslationY
                    });
                }

                return(new CantileverBeam(Length, Height, Width, EndPointLoad, YoungModulus, model, loadedNodes));
            }
Example #19
0
    public void ReceiveByClientPortal_StartPlayCountDown(float second)
    {
        if(!readyStartPlay)
        {
            readyStartPlay = true;
            if(OnLoadSuccess != null)
            {
                OnLoadSuccess();
            }
        }
        this.processState = PlayGameController.ProcessState.STARTPLAYCOUNTDOWN;
        this.startPlayCountDown = second;
        if(PlayerPrefs.GetString("GameType", "Single") == "Network")
        {
            if(second == 0)
            {
                AudioSource.PlayClipAtPoint(start2Audio, Camera.main.transform.position);
            }
            else
            {
                AudioSource.PlayClipAtPoint(start1Audio, Camera.main.transform.position);
            }
        }
        isGameInitialized = true;

        if(!isCountDownAnimaitonStarted) {
            if(countDownBat == null) {
                countDownBat = Camera.main.GetComponentInChildren<CountDownBat>();
            }

        //			countDownBat.SetStartFlyIn();
            isCountDownAnimaitonStarted = true;
        }

        if(dynamicMaterial == null) {
            dynamicMaterial = Camera.main.GetComponentInChildren<DynamicMaterial>();
        }
        //		dynamicMaterial.SetCountdownRender((int)this.startPlayCountDown);
        //		if(!isOpenMapCamera)
        //		{
        //			LittleMap mapCamera = FindObjectOfType(typeof(LittleMap)) as LittleMap;
        //			mapCamera.SetCars();
        //			isOpenMapCamera = true;
        //		}
    }
        private static void BuildCantileverModel(Model model, double load_value)
        {
            //xrhsimopoiithike to  ParadeigmataElegxwnBuilder.HexaCantileverBuilder(Model model, double load_value)
            // allagh tou element kai tou material

            //ElasticMaterial3DTemp material1 = new ElasticMaterial3DTemp()
            //{
            //    YoungModulus = 1353000,
            //    PoissonRatio = 0.3,
            //};


            //VonMisesMaterial3D material1 = new VonMisesMaterial3D(1353000, 0.30, 1353000, 0.15);
            var material1 = new ElasticMaterial3D()
            {
                PoissonRatio = 0.3, YoungModulus = 1353000
            };

            double[,] nodeData = new double[, ] {
                { -0.2500000000000000, 0.2500000000000000, -1.0000000000000000 },
                { 0.2500000000000000, 0.2500000000000000, -1.0000000000000000 },
                { 0.2500000000000000, -0.2500000000000000, -1.0000000000000000 },
                { -0.2500000000000000, -0.2500000000000000, -1.0000000000000000 },
                { -0.2500000000000000, 0.2500000000000000, 1.0000000000000000 },
                { 0.2500000000000000, 0.2500000000000000, 1.0000000000000000 },
                { 0.2500000000000000, -0.2500000000000000, 1.0000000000000000 },
                { -0.2500000000000000, -0.2500000000000000, 1.0000000000000000 },
                { -0.2500000000000000, 0.2500000000000000, 0.0000000000000000 },
                { 0.2500000000000000, 0.2500000000000000, 0.0000000000000000 },
                { 0.2500000000000000, -0.2500000000000000, 0.0000000000000000 },
                { -0.2500000000000000, -0.2500000000000000, 0.0000000000000000 },
                { 0.0000000000000000, 0.2500000000000000, -1.0000000000000000 },
                { 0.2500000000000000, 0.0000000000000000, -1.0000000000000000 },
                { 0.0000000000000000, -0.2500000000000000, -1.0000000000000000 },
                { -0.2500000000000000, 0.0000000000000000, -1.0000000000000000 },
                { 0.0000000000000000, 0.2500000000000000, 1.0000000000000000 },
                { 0.2500000000000000, 0.0000000000000000, 1.0000000000000000 },
                { 0.0000000000000000, -0.2500000000000000, 1.0000000000000000 },
                { -0.2500000000000000, 0.0000000000000000, 1.0000000000000000 },
                { 0.0000000000000000, 0.2500000000000000, 0.0000000000000000 },
                { 0.2500000000000000, 0.0000000000000000, 0.0000000000000000 },
                { 0.0000000000000000, -0.2500000000000000, 0.0000000000000000 },
                { -0.2500000000000000, 0.0000000000000000, 0.0000000000000000 },
                { -0.2500000000000000, 0.2500000000000000, -0.5000000000000000 },
                { 0.2500000000000000, 0.2500000000000000, -0.5000000000000000 },
                { 0.2500000000000000, -0.2500000000000000, -0.5000000000000000 },
                { -0.2500000000000000, -0.2500000000000000, -0.5000000000000000 },
                { -0.2500000000000000, 0.2500000000000000, 0.5000000000000000 },
                { 0.2500000000000000, 0.2500000000000000, 0.5000000000000000 },
                { 0.2500000000000000, -0.2500000000000000, 0.5000000000000000 },
                { -0.2500000000000000, -0.2500000000000000, 0.5000000000000000 },
                { 0.0000000000000000, 0.0000000000000000, -1.0000000000000000 },
                { -0.1250000000000000, 0.1250000000000000, -1.0000000000000000 },
                { 0.1250000000000000, 0.1250000000000000, -1.0000000000000000 },
                { 0.1250000000000000, -0.1250000000000000, -1.0000000000000000 },
                { -0.1250000000000000, -0.1250000000000000, -1.0000000000000000 },
                { 0.0000000000000000, 0.0000000000000000, 1.0000000000000000 },
                { -0.1250000000000000, 0.1250000000000000, 1.0000000000000000 },
                { 0.1250000000000000, 0.1250000000000000, 1.0000000000000000 },
                { 0.1250000000000000, -0.1250000000000000, 1.0000000000000000 },
                { -0.1250000000000000, -0.1250000000000000, 1.0000000000000000 },
                { 0.0000000000000000, 0.0000000000000000, 0.0000000000000000 },
                { -0.1250000000000000, 0.1250000000000000, 0.0000000000000000 },
                { 0.1250000000000000, 0.1250000000000000, 0.0000000000000000 },
                { 0.1250000000000000, -0.1250000000000000, 0.0000000000000000 },
                { -0.1250000000000000, -0.1250000000000000, 0.0000000000000000 },
                { 0.0000000000000000, 0.2500000000000000, -0.5000000000000000 },
                { 0.1250000000000000, 0.2500000000000000, -0.7500000000000000 },
                { -0.1250000000000000, 0.2500000000000000, -0.7500000000000000 },
                { -0.1250000000000000, 0.2500000000000000, -0.2500000000000000 },
                { 0.1250000000000000, 0.2500000000000000, -0.2500000000000000 },
                { 0.2500000000000000, 0.0000000000000000, -0.5000000000000000 },
                { 0.2500000000000000, -0.1250000000000000, -0.7500000000000000 },
                { 0.2500000000000000, 0.1250000000000000, -0.7500000000000000 },
                { 0.2500000000000000, 0.1250000000000000, -0.2500000000000000 },
                { 0.2500000000000000, -0.1250000000000000, -0.2500000000000000 },
                { 0.0000000000000000, -0.2500000000000000, -0.5000000000000000 },
                { -0.1250000000000000, -0.2500000000000000, -0.7500000000000000 },
                { 0.1250000000000000, -0.2500000000000000, -0.7500000000000000 },
                { 0.1250000000000000, -0.2500000000000000, -0.2500000000000000 },
                { -0.1250000000000000, -0.2500000000000000, -0.2500000000000000 },
                { -0.2500000000000000, 0.0000000000000000, -0.5000000000000000 },
                { -0.2500000000000000, 0.1250000000000000, -0.7500000000000000 },
                { -0.2500000000000000, -0.1250000000000000, -0.7500000000000000 },
                { -0.2500000000000000, -0.1250000000000000, -0.2500000000000000 },
                { -0.2500000000000000, 0.1250000000000000, -0.2500000000000000 },
                { 0.0000000000000000, 0.2500000000000000, 0.5000000000000000 },
                { 0.1250000000000000, 0.2500000000000000, 0.2500000000000000 },
                { -0.1250000000000000, 0.2500000000000000, 0.2500000000000000 },
                { -0.1250000000000000, 0.2500000000000000, 0.7500000000000000 },
                { 0.1250000000000000, 0.2500000000000000, 0.7500000000000000 },
                { 0.2500000000000000, 0.0000000000000000, 0.5000000000000000 },
                { 0.2500000000000000, -0.1250000000000000, 0.2500000000000000 },
                { 0.2500000000000000, 0.1250000000000000, 0.2500000000000000 },
                { 0.2500000000000000, 0.1250000000000000, 0.7500000000000000 },
                { 0.2500000000000000, -0.1250000000000000, 0.7500000000000000 },
                { 0.0000000000000000, -0.2500000000000000, 0.5000000000000000 },
                { -0.1250000000000000, -0.2500000000000000, 0.2500000000000000 },
                { 0.1250000000000000, -0.2500000000000000, 0.2500000000000000 },
                { 0.1250000000000000, -0.2500000000000000, 0.7500000000000000 },
                { -0.1250000000000000, -0.2500000000000000, 0.7500000000000000 },
                { -0.2500000000000000, 0.0000000000000000, 0.5000000000000000 },
                { -0.2500000000000000, 0.1250000000000000, 0.2500000000000000 },
                { -0.2500000000000000, -0.1250000000000000, 0.2500000000000000 },
                { -0.2500000000000000, -0.1250000000000000, 0.7500000000000000 },
                { -0.2500000000000000, 0.1250000000000000, 0.7500000000000000 },
                { 0.0000000000000000, 0.0000000000000000, -0.5000000000000000 },
                { -0.1250000000000000, 0.1250000000000000, -0.7500000000000000 },
                { 0.1250000000000000, 0.1250000000000000, -0.7500000000000000 },
                { 0.1250000000000000, -0.1250000000000000, -0.7500000000000000 },
                { -0.1250000000000000, -0.1250000000000000, -0.7500000000000000 },
                { -0.1250000000000000, 0.1250000000000000, -0.2500000000000000 },
                { 0.1250000000000000, 0.1250000000000000, -0.2500000000000000 },
                { 0.1250000000000000, -0.1250000000000000, -0.2500000000000000 },
                { -0.1250000000000000, -0.1250000000000000, -0.2500000000000000 },
                { 0.0000000000000000, 0.0000000000000000, -0.7500000000000000 },
                { 0.0000000000000000, 0.1250000000000000, -0.5000000000000000 },
                { 0.1250000000000000, 0.0000000000000000, -0.5000000000000000 },
                { 0.0000000000000000, -0.1250000000000000, -0.5000000000000000 },
                { -0.1250000000000000, 0.0000000000000000, -0.5000000000000000 },
                { 0.0000000000000000, 0.0000000000000000, -0.2500000000000000 },
                { 0.0000000000000000, 0.0000000000000000, 0.5000000000000000 },
                { -0.1250000000000000, 0.1250000000000000, 0.2500000000000000 },
                { 0.1250000000000000, 0.1250000000000000, 0.2500000000000000 },
                { 0.1250000000000000, -0.1250000000000000, 0.2500000000000000 },
                { -0.1250000000000000, -0.1250000000000000, 0.2500000000000000 },
                { -0.1250000000000000, 0.1250000000000000, 0.7500000000000000 },
                { 0.1250000000000000, 0.1250000000000000, 0.7500000000000000 },
                { 0.1250000000000000, -0.1250000000000000, 0.7500000000000000 },
                { -0.1250000000000000, -0.1250000000000000, 0.7500000000000000 },
                { 0.0000000000000000, 0.0000000000000000, 0.2500000000000000 },
                { 0.0000000000000000, 0.1250000000000000, 0.5000000000000000 },
                { 0.1250000000000000, 0.0000000000000000, 0.5000000000000000 },
                { 0.0000000000000000, -0.1250000000000000, 0.5000000000000000 },
                { -0.1250000000000000, 0.0000000000000000, 0.5000000000000000 },
                { 0.0000000000000000, 0.0000000000000000, 0.7500000000000000 },
            };

            //int[] take_msolve_nodes_from_adina_tade_nodes = new int[] { 2, 1, 3, 0, 5, 7, 8, 6, 9, 4 };

            int[,] elementData = new int[, ] {
                { 33, 2, 1, 88, 35, 13, 34, 90, 89, 97 },
                { 33, 3, 2, 88, 36, 14, 35, 91, 90, 97 },
                { 33, 4, 3, 88, 37, 15, 36, 92, 91, 97 },
                { 33, 1, 4, 88, 34, 16, 37, 89, 92, 97 },
                { 48, 1, 2, 88, 50, 13, 49, 89, 90, 98 },
                { 48, 2, 10, 88, 49, 26, 52, 90, 94, 98 },
                { 48, 10, 9, 88, 52, 21, 51, 94, 93, 98 },
                { 48, 9, 1, 88, 51, 25, 50, 93, 89, 98 },
                { 53, 2, 3, 88, 55, 14, 54, 90, 91, 99 },
                { 53, 3, 11, 88, 54, 27, 57, 91, 95, 99 },
                { 53, 11, 10, 88, 57, 22, 56, 95, 94, 99 },
                { 53, 10, 2, 88, 56, 26, 55, 94, 90, 99 },
                { 58, 3, 4, 88, 60, 15, 59, 91, 92, 100 },
                { 58, 11, 3, 88, 61, 27, 60, 95, 91, 100 },
                { 58, 12, 11, 88, 62, 23, 61, 96, 95, 100 },
                { 58, 4, 12, 88, 59, 28, 62, 92, 96, 100 },
                { 63, 4, 1, 88, 65, 16, 64, 92, 89, 101 },
                { 63, 12, 4, 88, 66, 28, 65, 96, 92, 101 },
                { 63, 9, 12, 88, 67, 24, 66, 93, 96, 101 },
                { 63, 1, 9, 88, 64, 25, 67, 89, 93, 101 },
                { 43, 9, 10, 88, 44, 21, 45, 93, 94, 102 },
                { 43, 10, 11, 88, 45, 22, 46, 94, 95, 102 },
                { 43, 11, 12, 88, 46, 23, 47, 95, 96, 102 },
                { 43, 12, 9, 88, 47, 24, 44, 96, 93, 102 },
                { 43, 10, 9, 103, 45, 21, 44, 105, 104, 112 },
                { 43, 11, 10, 103, 46, 22, 45, 106, 105, 112 },
                { 43, 12, 11, 103, 47, 23, 46, 107, 106, 112 },
                { 43, 9, 12, 103, 44, 24, 47, 104, 107, 112 },
                { 68, 9, 10, 103, 70, 21, 69, 104, 105, 113 },
                { 68, 10, 6, 103, 69, 30, 72, 105, 109, 113 },
                { 68, 6, 5, 103, 72, 17, 71, 109, 108, 113 },
                { 68, 5, 9, 103, 71, 29, 70, 108, 104, 113 },
                { 73, 10, 11, 103, 75, 22, 74, 105, 106, 114 },
                { 73, 11, 7, 103, 74, 31, 77, 106, 110, 114 },
                { 73, 7, 6, 103, 77, 18, 76, 110, 109, 114 },
                { 73, 6, 10, 103, 76, 30, 75, 109, 105, 114 },
                { 78, 11, 12, 103, 80, 23, 79, 106, 107, 115 },
                { 78, 7, 11, 103, 81, 31, 80, 110, 106, 115 },
                { 78, 8, 7, 103, 82, 19, 81, 111, 110, 115 },
                { 78, 12, 8, 103, 79, 32, 82, 107, 111, 115 },
                { 83, 12, 9, 103, 85, 24, 84, 107, 104, 116 },
                { 83, 8, 12, 103, 86, 32, 85, 111, 107, 116 },
                { 83, 5, 8, 103, 87, 20, 86, 108, 111, 116 },
                { 83, 9, 5, 103, 84, 29, 87, 104, 108, 116 },
                { 38, 5, 6, 103, 39, 17, 40, 108, 109, 117 },
                { 38, 6, 7, 103, 40, 18, 41, 109, 110, 117 },
                { 38, 7, 8, 103, 41, 19, 42, 110, 111, 117 },
                { 38, 8, 5, 103, 42, 20, 39, 111, 108, 117 },
            };

            // orismos shmeiwn
            for (int nNode = 0; nNode < nodeData.GetLength(0); nNode++)
            {
                model.NodesDictionary.Add(nNode + 1, new Node(id: nNode + 1, x: nodeData[nNode, 0], y:  nodeData[nNode, 1], z: nodeData[nNode, 2]));
            }

            // orismos elements
            Element e1;
            var     adinaOrder  = new AdinaElementLocalNodeOrdering();
            int     subdomainID = Tet10ContinuumNonLinearCantilever.subdomainID;

            for (int nElement = 0; nElement < elementData.GetLength(0); nElement++)
            {
                DynamicMaterial DynamicMaterial = new DynamicMaterial(1, 0, 0);
                //Dictionary<int,Node3D >
                List <Node> nodeSet = new List <Node>(10);
                for (int j = 0; j < 10; j++)
                {
                    int nodeID = elementData[nElement, j];
                    nodeSet.Add((Node)model.NodesDictionary[nodeID]);
                }

                var factory = new ContinuumElement3DFactory(material1, DynamicMaterial);

                var nodeSet1 = adinaOrder.ReorderNodes(nodeSet, CellType.Tet10);
                e1 = new Element()
                {
                    ID          = nElement + 1,
                    ElementType = factory.CreateNonLinearElement(CellType.Tet10, nodeSet1, material1, DynamicMaterial)
                };

                for (int j = 0; j < 10; j++)
                {
                    int LocalNode = adinaOrder.GetNodeForLocalMsolveNode(j, CellType.Tet10);
                    e1.NodesDictionary.Add(elementData[nElement, LocalNode], model.NodesDictionary[elementData[nElement, LocalNode]]);
                }

                model.ElementsDictionary.Add(e1.ID, e1);
                model.SubdomainsDictionary[subdomainID].Elements.Add(e1);
            }

            int[] constrainedIds = new int[] { 1, 2, 3, 4, 13, 14, 15, 16, 33, 34, 35, 36, 37 };

            for (int k1 = 0; k1 < constrainedIds.Length; k1++)
            {
                int k = constrainedIds[k1];
                model.NodesDictionary[k].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationX
                });
                model.NodesDictionary[k].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationY
                });
                model.NodesDictionary[k].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationZ
                });
            }

            // fortish korufhs
            Load load1;

            for (int k = 5; k < 9; k++)
            {
                load1 = new Load()
                {
                    Node   = model.NodesDictionary[k],
                    DOF    = StructuralDof.TranslationX,
                    Amount = 1 * load_value
                };
                model.Loads.Add(load1);
            }
        }
		public ContinuumElement3DFactory(ElasticMaterial3D commonMaterial, DynamicMaterial commonDynamicProperties)
		{
			this.commonDynamicProperties = commonDynamicProperties;
			this.commonMaterial = commonMaterial;
		}
        private static void BuildCantileverModel(Model model, double load_value)
        {
            //xrhsimopoiithike to  ParadeigmataElegxwnBuilder.HexaCantileverBuilder(Model model, double load_value)
            // allagh tou element kai tou material

            //ElasticMaterial3DTemp material1 = new ElasticMaterial3DTemp()
            //{
            //    YoungModulus = 1353000,
            //    PoissonRatio = 0.3,
            //};


            //VonMisesMaterial3D material1 = new VonMisesMaterial3D(1353000, 0.30, 1353000, 0.15);
            var material1 = new ElasticMaterial3D()
            {
                PoissonRatio = 0.3, YoungModulus = 1353000
            };

            double[,] nodeData = new double[, ] {
                { -0.250000, -0.250000, -1.000000 },
                { 0.250000, -0.250000, -1.000000 },
                { -0.250000, 0.250000, -1.000000 },
                { 0.250000, 0.250000, -1.000000 },
                { -0.250000, -0.250000, -0.500000 },
                { 0.250000, -0.250000, -0.500000 },
                { -0.250000, 0.250000, -0.500000 },
                { 0.250000, 0.250000, -0.500000 },
                { -0.250000, -0.250000, 0.000000 },
                { 0.250000, -0.250000, 0.000000 },
                { -0.250000, 0.250000, 0.000000 },
                { 0.250000, 0.250000, 0.000000 },
                { -0.250000, -0.250000, 0.500000 },
                { 0.250000, -0.250000, 0.500000 },
                { -0.250000, 0.250000, 0.500000 },
                { 0.250000, 0.250000, 0.500000 },
                { -0.250000, -0.250000, 1.000000 },
                { 0.250000, -0.250000, 1.000000 },
                { -0.250000, 0.250000, 1.000000 },
                { 0.250000, 0.250000, 1.000000 }
            };

            int[,] elementData = new int[, ] {
                { 1, 8, 7, 5, 6, 4, 3, 1, 2 },
                { 2, 12, 11, 9, 10, 8, 7, 5, 6 },
                { 3, 16, 15, 13, 14, 12, 11, 9, 10 },
                { 4, 20, 19, 17, 18, 16, 15, 13, 14 },
            };

            // orismos shmeiwn
            double correction = 10;// +20;

            for (int nNode = 0; nNode < nodeData.GetLength(0); nNode++)
            {
                model.NodesDictionary.Add(nNode + 1, new Node(nNode + 1, nodeData[nNode, 0] + correction, nodeData[nNode, 1] + correction, nodeData[nNode, 2] + correction));
            }

            // orismos elements
            Element e1;
            int     subdomainID = Hexa8Continuum3DLinearCantilever.subdomainID;

            int[] ContinuumHexa8NodesNumbering = new int[8] {
                7, 8, 5, 6, 3, 4, 1, 2
            };                                                                      // { 2, 3, 7, 6, 1, 4, 8, 5 };
            for (int nElement = 0; nElement < elementData.GetLength(0); nElement++)
            {
                DynamicMaterial DynamicMaterial = new DynamicMaterial(1, 0, 0);
                //Dictionary<int,Node3D >
                List <Node> nodeSet = new List <Node>(8);
                for (int j = 0; j < 8; j++)
                {
                    int nodeID = elementData[nElement, j + 1];
                    nodeSet.Add((Node)model.NodesDictionary[nodeID]);
                }


                var factory = new ContinuumElement3DFactory(material1, DynamicMaterial);

                //e1 = factory.CreateElement(CellType3D.Hexa8, nodeSet);
                e1 = new Element()
                {
                    ID          = nElement + 1,
                    ElementType = factory.CreateElement(CellType.Hexa8, nodeSet)  // dixws to e. exoume sfalma enw sto beambuilding oxi//edw kaleitai me ena orisma to Hexa8
                };
                for (int j = 0; j < 8; j++)
                {
                    int nodeID = elementData[nElement, j + 1];
                    e1.NodesDictionary.Add(nodeID, model.NodesDictionary[nodeID]);
                }
                model.ElementsDictionary.Add(e1.ID, e1);
                model.SubdomainsDictionary[subdomainID].Elements.Add(e1);
            }

            // constraint vashh opou z=-1
            for (int k = 1; k < 5; k++)
            {
                model.NodesDictionary[k].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationX
                });
                model.NodesDictionary[k].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationY
                });
                model.NodesDictionary[k].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationZ
                });
            }

            // fortish korufhs
            Load load1;

            for (int k = 17; k < 21; k++)
            {
                load1 = new Load()
                {
                    Node   = model.NodesDictionary[k],
                    DOF    = StructuralDof.TranslationX,
                    Amount = 1 * load_value
                };
                model.Loads.Add(load1);
            }
        }
Example #23
0
        private static void TestCantileverBeamGeneral()
        {
            // Define the materials
            double thickness = 1.0;
            var    material  = new ElasticMaterial2D(StressState2D.PlaneStress)
            {
                YoungModulus = youngModulus, PoissonRatio = 0.3
            };
            var dynamicProperties = new DynamicMaterial(1.0, 0.0, 0.0, true);

            // Model with 1 subdomain
            var model = new Model();

            model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID));

            // Generate mesh
            int    numElementsX = 32, numElementsY = 20;
            double lengthX = numElementsX;
            double depthY  = numElementsY;
            var    mesher  = new UniformMeshGenerator2D <Node>(0, 0, lengthX, depthY, numElementsX, numElementsY);

            (IReadOnlyList <Node> nodes, IReadOnlyList <CellConnectivity <Node> > connectivity) =
                mesher.CreateMesh((id, x, y, z) => new Node(id: id, x: x, y:  y, z: z));

            // Add nodes to the model
            for (int n = 0; n < nodes.Count; ++n)
            {
                model.NodesDictionary.Add(n, nodes[n]);
            }

            // Add Quad4 elements to the model
            var factory = new ContinuumElement2DFactory(thickness, material, dynamicProperties);

            for (int e = 0; e < connectivity.Count; ++e)
            {
                ContinuumElement2D element = factory.CreateElement(connectivity[e].CellType, connectivity[e].Vertices);
                var elementWrapper         = new Element()
                {
                    ID = e, ElementType = element
                };
                foreach (Node node in element.Nodes)
                {
                    elementWrapper.AddNode(node);
                }
                model.ElementsDictionary.Add(e, elementWrapper);
                model.SubdomainsDictionary[subdomainID].Elements.Add(elementWrapper);
            }

            // Clamp boundary condition at left edge
            double tol = 1E-10; //TODO: this should be chosen w.r.t. the element size along X

            foreach (var node in model.Nodes.Where(node => Math.Abs(node.X) <= tol))
            {
                node.Constraints.Add(new Constraint()
                {
                    DOF = StructuralDof.TranslationX, Amount = 0.0
                });
                node.Constraints.Add(new Constraint()
                {
                    DOF = StructuralDof.TranslationY, Amount = 0.0
                });
            }

            // Apply concentrated load at the bottom right corner
            double load       = 1.0;
            var    cornerNode = model.Nodes.Where(
                node => (Math.Abs(node.X - lengthX) <= tol) && (Math.Abs(node.Y - depthY) <= tol));

            Assert.True(cornerNode.Count() == 1);
            model.Loads.Add(new Load()
            {
                Amount = load, Node = cornerNode.First(), DOF = StructuralDof.TranslationY
            });

            // Define the solver
            SkylineSolver solver = (new SkylineSolver.Builder()).BuildSolver(model);

            // Define the fem analysis and the filter
            double filterAreaRadius = 1.2;
            var    fem    = new LinearFemAnalysis2DGeneral(model, solver);
            var    filter = new ProximityDensityFilter2D(model, filterAreaRadius);

            // Run the test
            TestCantileverBeam(fem, filter);
        }
Example #24
0
        private static IVectorView[] SolveModelsWithNewmark(Model[] models, IModelReader[] modelReaders)
        {
            Vector[] initialValues = new Vector[models.Length];
            var      value0        = new Dictionary <int, double[]>();

            for (int i = 0; i < models.Length; i++)
            {
                double[] v0 = new double[models[i].Nodes.Count];
                value0.Add(i, v0);
            }
            foreach (Node node in models[0].Nodes)
            {
                value0[0][node.ID] = 1;
            }

            DenseMatrixSolver[] solvers = new DenseMatrixSolver[models.Length];
            IConvectionDiffusionIntegrationProvider[] providers = new IConvectionDiffusionIntegrationProvider[models.Length];
            IChildAnalyzer[] childAnalyzers = new IChildAnalyzer[models.Length];
            for (int i = 0; i < models.Length; i++)
            {
                initialValues[i] = Vector.CreateFromArray(value0[i]);
                //var builder = new DenseMatrixSolver.Builder();
                builder.IsMatrixPositiveDefinite = false;
                solvers[i]        = builder.BuildSolver(models[i]);
                providers[i]      = new ProblemConvectionDiffusion2(models[i], solvers[i]);
                childAnalyzers[i] = new LinearAnalyzer(models[i], solvers[i], providers[i]);
            }

            const double timestep       = .1;
            const double time           = 3;
            var          parentAnalyzer = new ConvectionDiffusionImplicitDynamicAnalyzerMultiModel(UpdateModels, models, solvers,
                                                                                                   providers, childAnalyzers, timestep, time, initialTemperature: initialValues);

            parentAnalyzer.Initialize();

            //var structuralModel = CreateStructuralModel(10.5e3, 0, new DynamicMaterial(.001, 0, 0, true), 0, new double[] { 0, 0, 25000 }, lambdag).Item1; // new Model();
            DynamicMaterial[] dynamicMaterials = new DynamicMaterial[] { new DynamicMaterial(1000, 0, 0, true) };
            var structuralModel    = CreateStructuralModel(new double[] { 1 }, new double[] { 1 }, dynamicMaterials, 0, new double[] { 0, 0, 2500 }, lambdag).Item1; // new Model();
            var structuralSolver   = structuralBuilder.BuildSolver(structuralModel);
            var structuralProvider = new ProblemStructural(structuralModel, structuralSolver);
            //var structuralChildAnalyzer = new LinearAnalyzer(structuralModel, structuralSolver, structuralProvider);
            var increments = 2;
            var structuralChildAnalyzerBuilder = new LoadControlAnalyzer.Builder(structuralModel, structuralSolver, structuralProvider, increments);

            structuralChildAnalyzerBuilder.ResidualTolerance             = 1E-6;
            structuralChildAnalyzerBuilder.MaxIterationsPerIncrement     = 50;
            structuralChildAnalyzerBuilder.NumIterationsForMatrixRebuild = 1;
            //childAnalyzerBuilder.SubdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) }; // This is the default
            LoadControlAnalyzer structuralChildAnalyzer = structuralChildAnalyzerBuilder.Build();
            var structuralParentAnalyzer = new NewmarkDynamicAnalyzer(UpdateNewmarkModel, structuralModel, structuralSolver,
                                                                      structuralProvider, structuralChildAnalyzer, timestep, time, 0.25, 0.5);

            structuralParentAnalyzer.Initialize();

            for (int i = 0; i < time / timestep; i++)
            {
                parentAnalyzer.SolveTimestep(i);
                structuralParentAnalyzer.SolveTimestep(i);
            }

            return(solvers.Select(x => x.LinearSystems[subdomainID].Solution).ToArray());
        }
        private static void SolveDynamicLinearWall()
        {
            // Some values
            string workingDirectory = @"C:\Users\Serafeim\Desktop\Presentation";
            double thickness        = 0.1;
            double youngModulus     = 2E6;
            double poissonRatio     = 0.3;

            // Initialize model
            PreprocessorModel model = PreprocessorModel.Create2DPlaneStress(thickness);

            // Materials
            ElasticMaterial2D material = new ElasticMaterial2D(StressState2D.PlaneStress)
            {
                YoungModulus = youngModulus,
                PoissonRatio = poissonRatio
            };
            DynamicMaterial dynamicProperties = new DynamicMaterial(25, 0.05, 0.05, true);

            // Read mesh from GMSH file
            string meshPath = workingDirectory + "\\wall.msh";
            IReadOnlyList <Node> nodes;
            IReadOnlyList <CellConnectivity <Node> > elements;

            using (var reader = new GmshReader <Node>(meshPath))
            {
                (nodes, elements) = reader.CreateMesh((id, x, y, z) => new Node(id: id, x: x, y:  y, z: z));
            }
            model.AddMesh2D(nodes, elements, material, dynamicProperties);

            // Prescribed displacements
            double             tol = 1E-10;
            IEnumerable <Node> constrainedNodes = nodes.Where(node => Math.Abs(node.Y) <= tol);

            model.ApplyPrescribedDisplacements(constrainedNodes, StructuralDof.TranslationX, 0.0);
            model.ApplyPrescribedDisplacements(constrainedNodes, StructuralDof.TranslationY, 0.0);

            // Loads
            string accelerogramPath = workingDirectory + "\\elcentro_NS.txt";
            Dictionary <IDofType, double> magnifications = new Dictionary <IDofType, double>
            {
                { StructuralDof.TranslationX, 1.0 }
            };

            model.SetGroundMotion(accelerogramPath, magnifications, 0.02, 53.74);

            // Define output
            OutputRequests output = new OutputRequests(workingDirectory + "\\Plots");

            output.Displacements    = true;
            output.Strains          = true;
            output.Stresses         = true;
            output.StressesVonMises = true;

            // Set up the simulation procedure
            Job job = new Job(model);

            job.Procedure           = Job.ProcedureOptions.DynamicImplicit;
            job.Integrator          = Job.IntegratorOptions.Linear;
            job.Solver              = Job.SolverOptions.DirectSkyline;
            job.FieldOutputRequests = output;

            // Run the simulation
            job.Submit();
        }
        private static void BuildCantileverModel(Model model, double load_value)
        {
            //xrhsimopoiithike to  ParadeigmataElegxwnBuilder.HexaCantileverBuilder(Model model, double load_value)
            // allagh tou element kai tou material

            //IContinuumMaterial3DTemp material1 = new IContinuumMaterial3DTemp()
            //{
            //    YoungModulus = 1353000,
            //    PoissonRatio = 0.3,
            //};


            //VonMisesMaterial3D material1 = new VonMisesMaterial3D(1353000, 0.30, 1353000, 0.15);
            var material1 = new ElasticMaterial3D()
            {
                PoissonRatio = 0.3, YoungModulus = 1353000
            };

            double[,] nodeData = new double[, ] {
                { -0.250000, -0.250000, -1.000000 },
                { 0.250000, -0.250000, -1.000000 },
                { -0.250000, 0.250000, -1.000000 },
                { 0.250000, 0.250000, -1.000000 },
                { -0.250000, -0.250000, -0.500000 },
                { 0.250000, -0.250000, -0.500000 },
                { -0.250000, 0.250000, -0.500000 },
                { 0.250000, 0.250000, -0.500000 },
                { -0.250000, -0.250000, 0.000000 },
                { 0.250000, -0.250000, 0.000000 },
                { -0.250000, 0.250000, 0.000000 },
                { 0.250000, 0.250000, 0.000000 },
                { -0.250000, -0.250000, 0.500000 },
                { 0.250000, -0.250000, 0.500000 },
                { -0.250000, 0.250000, 0.500000 },
                { 0.250000, 0.250000, 0.500000 },
                { -0.250000, -0.250000, 1.000000 },
                { 0.250000, -0.250000, 1.000000 },
                { -0.250000, 0.250000, 1.000000 },
                { 0.250000, 0.250000, 1.000000 }
            };

            int[,] elementData = new int[, ] {
                { 1, 8, 7, 5, 6, 4, 3, 1, 2 },
                { 2, 12, 11, 9, 10, 8, 7, 5, 6 },
                { 3, 16, 15, 13, 14, 12, 11, 9, 10 },
                { 4, 20, 19, 17, 18, 16, 15, 13, 14 },
            };

            // orismos shmeiwn
            for (int nNode = 0; nNode < nodeData.GetLength(0); nNode++)
            {
                model.NodesDictionary.Add(nNode + 1, new Node(id: nNode + 1, x: nodeData[nNode, 0], y: nodeData[nNode, 1], z: nodeData[nNode, 2]));
            }

            // orismos elements
            Element         e1;
            DynamicMaterial DynamicMaterial = new DynamicMaterial(1, 0, 0);
            var             factory         = new ContinuumElement3DFactory(material1, DynamicMaterial);

            int subdomainID = Hexa8NonLinearCantilever.subdomainID;

            for (int nElement = 0; nElement < elementData.GetLength(0); nElement++)
            {
                List <Node> nodeSet = new List <Node>(8);
                for (int j = 0; j < 8; j++)
                {
                    int nodeID = elementData[nElement, j + 1];
                    nodeSet.Add((Node)model.NodesDictionary[nodeID]);
                }
                e1 = new Element()
                {
                    ID = nElement + 1,
                    ElementType                      //= factory.CreateNonLinearElement(CellType.Hexa8, nodeSet, material1, DynamicMaterial)
                    //nnew Hexa8NonLinear(material1, GaussLegendre3D.GetQuadratureWithOrder(3, 3, 3)) // dixws to e. exoume sfalma enw sto beambuilding oxi//edw kaleitai me ena orisma to Hexa8
                        = new ContinuumElement3DNonLinear(nodeSet, material1, GaussLegendre3D.GetQuadratureWithOrder(3, 3, 3), InterpolationHexa8.UniqueInstance),
                };
                for (int j = 0; j < 8; j++)
                {
                    e1.NodesDictionary.Add(elementData[nElement, j + 1], model.NodesDictionary[elementData[nElement, j + 1]]);
                }
                model.ElementsDictionary.Add(e1.ID, e1);
                model.SubdomainsDictionary[subdomainID].Elements.Add(e1);
            }

            // constraint vashh opou z=-1
            for (int k = 1; k < 5; k++)
            {
                model.NodesDictionary[k].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationX
                });
                model.NodesDictionary[k].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationY
                });
                model.NodesDictionary[k].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationZ
                });
            }

            // fortish korufhs
            Load load1;

            for (int k = 17; k < 21; k++)
            {
                load1 = new Load()
                {
                    Node   = model.NodesDictionary[k],
                    DOF    = StructuralDof.TranslationX,
                    Amount = 1 * load_value
                };
                model.Loads.Add(load1);
            }
        }
Example #27
0
            public static void HostElementsBuilder(Model model)
            {
                // Nodes Geometry
                model.NodesDictionary.Add(1, new Node(id: 1, x: 10.00, y: 2.50, z: 2.50));
                model.NodesDictionary.Add(2, new Node(id: 2, x: 0.00, y: 2.50, z: 2.50));
                model.NodesDictionary.Add(3, new Node(id: 3, x: 0.00, y: -2.50, z: 2.50));
                model.NodesDictionary.Add(4, new Node(id: 4, x: 10.00, y: -2.50, z: 2.50));
                model.NodesDictionary.Add(5, new Node(id: 5, x: 10.00, y: 2.50, z: -2.50));
                model.NodesDictionary.Add(6, new Node(id: 6, x: 0.00, y: 2.50, z: -2.50));
                model.NodesDictionary.Add(7, new Node(id: 7, x: 0.00, y: -2.50, z: -2.50));
                model.NodesDictionary.Add(8, new Node(id: 8, x: 10.00, y: -2.50, z: -2.50));

                // Boundary Conditions
                model.NodesDictionary[2].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationX
                });
                model.NodesDictionary[2].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationY
                });
                model.NodesDictionary[2].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationZ
                });
                model.NodesDictionary[3].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationX
                });
                model.NodesDictionary[3].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationY
                });
                model.NodesDictionary[3].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationZ
                });
                model.NodesDictionary[6].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationX
                });
                model.NodesDictionary[6].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationY
                });
                model.NodesDictionary[6].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationZ
                });
                model.NodesDictionary[7].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationX
                });
                model.NodesDictionary[7].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationY
                });
                model.NodesDictionary[7].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationZ
                });

                // Create Material
                var solidMaterial = new ElasticMaterial3D()
                {
                    YoungModulus = 3.76,
                    PoissonRatio = 0.3779,
                };

                DynamicMaterial DynamicMaterial = new DynamicMaterial(1, 0, 0);
                var             factory         = new ContinuumElement3DFactory(solidMaterial, DynamicMaterial);
                // Hexa8NL element definition
                List <Node> nodeSet = new List <Node>(8);

                for (int j = 1; j < 9; j++)
                {
                    nodeSet.Add((Node)model.NodesDictionary[j]);
                }
                var hexa8NLelement = new Element()
                {
                    ID          = 1,
                    ElementType = // factory.CreateNonLinearElement(CellType.Hexa8, nodeSet, solidMaterial, DynamicMaterial)
                                  new Hexa8NonLinear(solidMaterial, GaussLegendre3D.GetQuadratureWithOrder(3, 3, 3))
                                  // = new ContinummElement3DNonLinear(nodeSet, solidMaterial, GaussLegendre3D.GetQuadratureWithOrder(3, 3, 3), ISAAR.MSolve.FEM.Interpolation.InterpolationHexa8.UniqueInstance)
                };

                // Add nodes to the created element
                hexa8NLelement.AddNode(model.NodesDictionary[1]);
                hexa8NLelement.AddNode(model.NodesDictionary[2]);
                hexa8NLelement.AddNode(model.NodesDictionary[3]);
                hexa8NLelement.AddNode(model.NodesDictionary[4]);
                hexa8NLelement.AddNode(model.NodesDictionary[5]);
                hexa8NLelement.AddNode(model.NodesDictionary[6]);
                hexa8NLelement.AddNode(model.NodesDictionary[7]);
                hexa8NLelement.AddNode(model.NodesDictionary[8]);

                // Add Hexa element to the element and subdomains dictionary of the model
                model.ElementsDictionary.Add(hexa8NLelement.ID, hexa8NLelement);
                model.SubdomainsDictionary[1].Elements.Add(hexa8NLelement);

                // Add nodal load values at the top nodes of the model
                model.Loads.Add(new Load()
                {
                    Amount = 25, Node = model.NodesDictionary[1], DOF = StructuralDof.TranslationZ
                });
                model.Loads.Add(new Load()
                {
                    Amount = 25, Node = model.NodesDictionary[4], DOF = StructuralDof.TranslationZ
                });
                model.Loads.Add(new Load()
                {
                    Amount = 25, Node = model.NodesDictionary[5], DOF = StructuralDof.TranslationZ
                });
                model.Loads.Add(new Load()
                {
                    Amount = 25, Node = model.NodesDictionary[8], DOF = StructuralDof.TranslationZ
                });
            }
Example #28
0
 public ContinuumElement3DNonLinear CreateNonLinearElement(CellType cellType, IReadOnlyList <Node> nodes,
                                                           IContinuumMaterial3D commonMaterial, DynamicMaterial commonDynamicProperties)
 {
     return(new ContinuumElement3DNonLinear(nodes, commonMaterial, integrationsForStiffness[cellType], interpolations[cellType]));
 }