Пример #1
0
        private static void TestMbbBeam(ILinearFemAnalysis fem, IDensityFilter filter)
        {
            // Parameters
            double volumeFraction = 0.5, penalty = 3.0;

            // Define the optimization
            var materialInterpolation = new PowerLawMaterialInterpolation(youngModulus, penalty, 1E-3);
            var simp   = new TopologySimpLinear2D(fem, optimAlgorithmBuilder, filter, materialInterpolation, volumeFraction);
            var logger = new ObjectiveFunctionLogger();

            simp.Logger = logger;

            // Run the optimization
            simp.Initialize();
            (double compliance, Vector densities) = simp.Optimize();

            // Check the history of the compliance (objective function)
            var expectedCompliances = Vector.CreateFromArray(TopologySimp99LinesTests.ComplianceHistoryForMbbBeam);

            Assert.True(expectedCompliances.Equals(
                            Vector.CreateFromArray(logger.ObjectiveFunctionValues.ToArray()),
                            1E-10));

            // Check the optimum element densities (design variables).
            string densitiesPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName
                                   + @"\Resources\topology99lines_MBBbeam_densities.txt";
            var    reader            = new FullMatrixReader(false, ',');
            Vector densitiesExpected = reader.ReadFile(densitiesPath).Reshape(false);

            Assert.True(densitiesExpected.Equals(densities, 1E-8));
        }
Пример #2
0
        private static void TestCantileverBeamWith2LoadCasesHardCoded()
        {
            // Parameters
            int    numElementsX = 30, numElementsY = 30;
            double filterAreaRadius = 1.2, volumeFraction = 0.4, penalty = 3.0;

            // Define the optimization
            var material = new ElasticMaterial2D(StressState2D.PlaneStress)
            {
                YoungModulus = youngModulus, PoissonRatio = 0.3
            };
            var fem = new LinearFemAnalysis2DUniformHardcoded(numElementsX, numElementsY, material,
                                                              LinearFemAnalysis2DUniformHardcoded.BoundaryConditions.Cantilever2LoadCases);
            var filter = new MeshIndependentSensitivityFilter2DUniform(numElementsX, numElementsY, filterAreaRadius);
            var materialInterpolation = new PowerLawMaterialInterpolation(youngModulus, penalty, 1E-3);
            var simp   = new TopologySimpLinear2D(fem, optimAlgorithmBuilder, filter, materialInterpolation, volumeFraction);
            var logger = new ObjectiveFunctionLogger();

            simp.Logger = logger;

            // Run the optimization
            simp.Initialize();
            (double compliance, Vector densities) = simp.Optimize();

            // Check the history of the compliance (objective function)
            var expectedCompliances = Vector.CreateFromArray(
                TopologySimp99LinesTests.ComplianceHistoryForCantileverWith2LoadCases);

            Assert.True(expectedCompliances.Equals(
                            Vector.CreateFromArray(logger.ObjectiveFunctionValues.ToArray()),
                            1E-11));

            // Check the optimum element densities (design variables).
            string densitiesPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName
                                   + @"\Resources\topology99lines_cantilever_loadcases_densities.txt";
            var    reader            = new FullMatrixReader(false, ',');
            Vector densitiesExpected = reader.ReadFile(densitiesPath).Reshape(false);

            Assert.True(densitiesExpected.Equals(densities, 1E-11));
        }
        private static void TestCantileverBeam()
        {
            // Run the optimization
            var simp = new TopologySimp99Lines(32, 20, 0.4, 3.0, 1.2, TopologySimp99Lines.BoundaryConditions.ShortCantilever,
                                               TopologySimp99Lines.PassiveElements.No, TopologySimp99Lines.OptimAlgorithm.OC);

            (double compliance, Matrix densities, ObjectiveFunctionLogger logger) = simp.TopologyOptimization();

            // Check the history of the compliance (objective function)
            var expectedCompliances = Vector.CreateFromArray(ComplianceHistoryForCantilever);

            Assert.True(expectedCompliances.Equals(
                            Vector.CreateFromArray(logger.ObjectiveFunctionValues.ToArray()),
                            1E-11));

            // Check the optimum element densities (design variables).
            string densitiesPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName
                                   + @"\Resources\topology99lines_shortcantilever_densities.txt";
            var    reader            = new FullMatrixReader(false, ',');
            Matrix densitiesExpected = reader.ReadFile(densitiesPath);

            Assert.True(densitiesExpected.Equals(densities, 1E-10));
        }