public async Task <ActionResult <FiniteElementResponse> > CalculateVibration(
            [FromServices] ICalculateRectangularBeamWithPiezoelectricVibration calculateVibration,
            [FromBody] BeamWithPiezoelectricRequest <RectangularProfile> request)
        {
            FiniteElementResponse response = await calculateVibration.Process(request).ConfigureAwait(false);

            return(response.BuildHttpResponse());
        }
        /// <summary>
        /// This method creates the path to save the file with the maximum values for each angular frequency.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="input"></param>
        /// <returns>The path to save the file with the maximum values for each angular frequency.</returns>
        public override Task <string> CreateMaxValuesPath(BeamWithPiezoelectricRequest <TProfile> request, FiniteElementMethodInput input)
        {
            string previousPath = Path.GetDirectoryName(Directory.GetCurrentDirectory());

            string fileUri = Path.Combine(
                previousPath,
                $"Solutions/FiniteElement/BeamWithPiezoelectric/MaxValues/{request.NumericalMethod}");

            string fileName = $"MaxValues_{request.AnalysisType}_{Regex.Replace(request.PiezoelectricPosition, @"\s", "")}_{request.Profile.GetType().Name}_w0={Math.Round(request.InitialAngularFrequency, 2)}_wf={Math.Round(request.FinalAngularFrequency, 2)}_nEl={request.NumberOfElements}.csv";

            string path = Path.Combine(fileUri, fileName);

            Directory.CreateDirectory(fileUri);

            return(Task.FromResult(path));
        }
Beispiel #3
0
        public CalculateRectangularBeamWithPiezoelectricVibrationTest()
        {
            this._precision = 1e-16;

            this._beamProfile = new RectangularProfile
            {
                Height = 3e-3,
                Width  = 25e-3
            };

            this._piezoelectricProfile = new RectangularProfile
            {
                Height = 0.267e-3,
                Width  = 25e-3
            };

            this._numberOfPiezoelectricsPerElement = 2;
            // Area and Moment of Inertia to piezoelectric were calculate manualy.
            this._piezoelectricArea            = this._numberOfPiezoelectricsPerElement * 6.675E-6;
            this._piezoelectricMomentOfInertia = 3.5701411E-11;

            this._arrayOperation    = new ArrayOperation();
            this._auxiliarOperation = new AuxiliarOperation();

            this._newmarkMethod = new NewmarkMethod(
                this._arrayOperation,
                this._auxiliarOperation);

            this._mappingResolver  = new MappingResolver();
            this._profileValidator = new RectangularProfileValidator();

            this._calculateGeometricProperty = new GeometricProperty();

            this._piezoelectricProfileMapper = new PiezoelectricRectangularProfileMapper(
                this._arrayOperation,
                this._calculateGeometricProperty);

            this._profileMapper = new RectangularProfileMapper(
                this._arrayOperation,
                this._calculateGeometricProperty);

            this._mainMatrix = new RectangularBeamWithPiezoelectricMainMatrix(this._arrayOperation);

            this._operation = new CalculateRectangularBeamWithPiezoelectricVibration(
                this._newmarkMethod,
                this._mappingResolver,
                this._profileValidator,
                this._auxiliarOperation,
                this._profileMapper,
                this._piezoelectricProfileMapper,
                this._mainMatrix,
                this._arrayOperation);

            this._methodParameter = new NewmarkMethodParameter
            {
                InitialTime             = 0,
                PeriodDivision          = 100,
                NumberOfPeriods         = 30,
                InitialAngularFrequency = 0.5
            };

            this._request = new BeamWithPiezoelectricRequest <RectangularProfile>
            {
                Author   = "Teste",
                BeamData = new PiezoelectricRequestData <RectangularProfile>
                {
                    DielectricConstant        = 7.33e-9,
                    DielectricPermissiveness  = 30.705,
                    ElasticityConstant        = 1.076e11,
                    ElectricalCharges         = new List <ElectricalCharge>(),
                    ElementsWithPiezoelectric = new uint[] { 2 },
                    FirstFastening            = "Pinned",
                    Forces = new List <Force> {
                        new Force
                        {
                            NodePosition = 1,
                            Value        = 100
                        }
                    },
                    LastFastening             = "Pinned",
                    Length                    = elementLength * numberOfElements,
                    Material                  = "Steel4130",
                    NumberOfElements          = numberOfElements,
                    PiezoelectricConstant     = 190e-12,
                    PiezoelectricPosition     = "Up and down",
                    PiezoelectricProfile      = this._piezoelectricProfile,
                    PiezoelectricSpecificMass = 7650,
                    PiezoelectricYoungModulus = 63e9,
                    Profile                   = this._beamProfile
                },
                MethodParameterData = this._methodParameter
            };

            this._beamWithPiezoelectic = new BeamWithPiezoelectric <RectangularProfile>()
            {
                DielectricConstant       = 7.33e-9,
                DielectricPermissiveness = 30.705,
                ElasticityConstant       = 1.076e11,
                ElectricalCharge         = new double[piezoelectricDegreesFreedomMaximum] {
                    0, 0, 0
                },
                ElementsWithPiezoelectric = new uint[numberOfElementsWithPiezoelectrics] {
                    2
                },
                FirstFastening = new Pinned(),
                Forces         = new double[degreesFreedomMaximum] {
                    0, 0, 100, 0, 0, 0
                },
                GeometricProperty = new GeometricProperty
                {
                    // Beam profile: height = 3e-3, width = 25e-3.
                    Area = new double[numberOfElements] {
                        7.5E-05, 7.5E-05
                    },
                    MomentOfInertia = new double[numberOfElements] {
                        5.625E-11, 5.625E-11
                    }
                },
                LastFastening    = new Pinned(),
                Length           = elementLength * numberOfElements,
                Material         = new Steel4130(),
                NumberOfElements = numberOfElements,
                NumberOfPiezoelectricPerElements = this._numberOfPiezoelectricsPerElement,
                PiezoelectricConstant            = 190e-12,
                PiezoelectricGeometricProperty   = new GeometricProperty
                {
                    // Piezoelectric profile:  height = 0.267e-3, width = 25e-3.
                    Area = new double[numberOfElements] {
                        0, this._piezoelectricArea
                    },
                    MomentOfInertia = new double[numberOfElements] {
                        0, this._piezoelectricMomentOfInertia
                    }
                },
                PiezoelectricProfile      = this._piezoelectricProfile,
                PiezoelectricSpecificMass = 7650,
                Profile = this._beamProfile,
                PiezoelectricYoungModulus = 63e9
            };

            this._equivalentForce = new double[numberOfBoundaryConditionsTrue] {
                0, 100, 0, 0, 0, 0
            };

            this._mass = new double[numberOfBoundaryConditionsTrue, numberOfBoundaryConditionsTrue]
            {
                { 0.000700893, 0.0045558, -0.00052567, 0, 0, 0 },
                { 0.0045558, 0.237645, 0.00133738, -0.00534608, 0, 0 },
                { -0.00052567, 0.00133738, 0.00152337, -0.000616855, 0, 0 },
                { 0, -0.00534608, -0.000616855, 0.000822473, 0, 0 },
                { 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0 }
            };

            this._stiffness = new double[numberOfBoundaryConditionsTrue, numberOfBoundaryConditionsTrue]
            {
                { 90, -270, 45, 0, 0, 0 },
                { -270, 2528.78, 92.1953, 362.195, 0, 0 },
                { 45, 92.1953, 210.732, 60.3659, 1.60557e-07, -1.60557e-07 },
                { 0, 362.195, 60.3659, 120.732, -1.60557e-07, 1.60557e-07 },
                { 0, 0, 1.60557e-07, -1.60557e-07, -6.8633e-07, 6.8633e-07 },
                { 0, 0, -1.60557e-07, 1.60557e-07, 6.8633e-07, -6.8633e-07 }
            };

            this._damping = new double[numberOfBoundaryConditionsTrue, numberOfBoundaryConditionsTrue]
            {
                { 9e-05, -0.00027, 4.5e-05, 0, 0, 0 },
                { -0.00027, 0.00252878, 9.21953e-05, 0.000362195, 0, 0 },
                { 4.5e-05, 9.21953e-05, 0.000210732, 6.03659e-05, 1.60557e-13, -1.60557e-13 },
                { 0, 0.000362195, 6.03659e-05, 0.000120732, -1.60557e-13, 1.60557e-13 },
                { 0, 0, 1.60557e-13, -1.60557e-13, -6.8633e-13, 6.8633e-13 },
                { 0, 0, -1.60557e-13, 1.60557e-13, 6.8633e-13, -6.8633e-13 }
            };

            this._newmarkMethodInput = new NewmarkMethodInput
            {
                Parameter = this._methodParameter,
                NumberOfTrueBoundaryConditions = numberOfBoundaryConditionsTrue,
                Force     = this._equivalentForce,
                Mass      = this._mass,
                Stiffness = this._stiffness,
                Damping   = this._damping
            };
        }
        /// <summary>
        /// This method creates a new instance of class <see cref="BeamWithPiezoelectric{TProfile}"/>.
        /// This is a step to create the input fot finite element analysis.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="degreesOfFreedom"></param>
        /// <returns>A new instance of class <see cref="BeamWithPiezoelectric{TProfile}"/>.</returns>
        public override async Task <BeamWithPiezoelectric <TProfile> > BuildBeam(BeamWithPiezoelectricRequest <TProfile> request, uint degreesOfFreedom)
        {
            GeometricProperty geometricProperty = new GeometricProperty();
            GeometricProperty piezoelectricGeometricProperty = new GeometricProperty();

            uint numberOfPiezoelectricPerElements = PiezoelectricPositionFactory.Create(request.PiezoelectricPosition);

            uint[] elementsWithPiezoelectric = request.ElementsWithPiezoelectric ?? this.CreateVectorWithAllElements(request.NumberOfElements);

            // Calculating beam geometric properties.
            if (request.Profile.Area != null && request.Profile.MomentOfInertia != null)
            {
                geometricProperty.Area = await ArrayFactory.CreateVectorAsync(request.Profile.Area.Value, request.NumberOfElements).ConfigureAwait(false);

                geometricProperty.MomentOfInertia = await ArrayFactory.CreateVectorAsync(request.Profile.MomentOfInertia.Value, request.NumberOfElements).ConfigureAwait(false);
            }
            else
            {
                geometricProperty.Area = await this._geometricProperty.CalculateArea(request.Profile, request.NumberOfElements).ConfigureAwait(false);

                geometricProperty.MomentOfInertia = await this._geometricProperty.CalculateMomentOfInertia(request.Profile, request.NumberOfElements).ConfigureAwait(false);
            }

            // Calculating piezoelectric geometric properties.
            if (request.PiezoelectricProfile.Area != null && request.PiezoelectricProfile.MomentOfInertia != null)
            {
                double area            = request.PiezoelectricProfile.Area.Value * numberOfPiezoelectricPerElements;
                double momentOfInertia = request.PiezoelectricProfile.MomentOfInertia.Value * numberOfPiezoelectricPerElements;

                piezoelectricGeometricProperty.Area = await ArrayFactory.CreateVectorAsync(area, request.NumberOfElements, elementsWithPiezoelectric).ConfigureAwait(false);

                piezoelectricGeometricProperty.MomentOfInertia = await ArrayFactory.CreateVectorAsync(momentOfInertia, request.NumberOfElements, elementsWithPiezoelectric).ConfigureAwait(false);
            }
            else
            {
                piezoelectricGeometricProperty.Area = await this._geometricProperty.CalculatePiezoelectricArea(request.PiezoelectricProfile, request.NumberOfElements, elementsWithPiezoelectric, numberOfPiezoelectricPerElements).ConfigureAwait(false);

                piezoelectricGeometricProperty.MomentOfInertia = await this._geometricProperty.CalculatePiezoelectricMomentOfInertia(request.PiezoelectricProfile, request.Profile, request.NumberOfElements, elementsWithPiezoelectric, numberOfPiezoelectricPerElements).ConfigureAwait(false);
            }

            var beam = new BeamWithPiezoelectric <TProfile>()
            {
                DielectricConstant        = request.DielectricConstant,
                DielectricPermissiveness  = request.DielectricPermissiveness,
                ElasticityConstant        = request.ElasticityConstant,
                ElectricalCharge          = new double[request.NumberOfElements + 1],
                ElementsWithPiezoelectric = elementsWithPiezoelectric,
                Fastenings        = await this._mappingResolver.BuildFastenings(request.Fastenings).ConfigureAwait(false),
                Forces            = await this._mappingResolver.BuildForceVector(request.Forces, degreesOfFreedom).ConfigureAwait(false),
                GeometricProperty = geometricProperty,
                Length            = request.Length,
                Material          = MaterialFactory.Create(request.Material),
                NumberOfElements  = request.NumberOfElements,
                NumberOfPiezoelectricPerElements = numberOfPiezoelectricPerElements,
                PiezoelectricConstant            = request.PiezoelectricConstant,
                PiezoelectricDegreesOfFreedom    = request.NumberOfElements + 1,
                PiezoelectricGeometricProperty   = piezoelectricGeometricProperty,
                PiezoelectricProfile             = request.PiezoelectricProfile,
                PiezoelectricSpecificMass        = request.PiezoelectricSpecificMass,
                PiezoelectricYoungModulus        = request.PiezoelectricYoungModulus,
                Profile = request.Profile
            };

            return(beam);
        }
        /// <summary>
        /// This method validates the <see cref="BeamWithPiezoelectricRequest{TProfile}"/>.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        protected override async Task <FiniteElementResponse> ValidateOperation(BeamWithPiezoelectricRequest <TProfile> request)
        {
            FiniteElementResponse response = await base.ValidateOperation(request).ConfigureAwait(false);

            if (response.Success == false)
            {
                return(response);
            }

            if (request.PiezoelectricYoungModulus <= 0)
            {
                response.AddError(OperationErrorCode.RequestValidationError, $"Piezoelectric Young Modulus: {request.PiezoelectricYoungModulus} must be greather than zero.");
            }

            if (request.PiezoelectricConstant <= 0)
            {
                response.AddError(OperationErrorCode.RequestValidationError, $"Piezoelectric Constant: {request.PiezoelectricConstant} must be greather than zero.");
            }

            if (request.DielectricConstant <= 0)
            {
                response.AddError(OperationErrorCode.RequestValidationError, $"Dielectric Constant: {request.DielectricConstant} must be greather than zero.");
            }

            if (request.ElasticityConstant <= 0)
            {
                response.AddError(OperationErrorCode.RequestValidationError, $"Elasticity Constant: {request.ElasticityConstant} must be greather than zero.");
            }

            if (request.DielectricPermissiveness <= 0)
            {
                response.AddError(OperationErrorCode.RequestValidationError, $"Dielectric Permissiveness: {request.DielectricPermissiveness} must be greather than zero.");
            }

            if (request.PiezoelectricSpecificMass <= 0)
            {
                response.AddError(OperationErrorCode.RequestValidationError, $"Piezoelectric SpecificMass: {request.PiezoelectricSpecificMass} must be greather than zero.");
            }

            foreach (var electricalCharge in request.ElectricalCharges)
            {
                if (electricalCharge.NodePosition < 0 || electricalCharge.NodePosition > request.NumberOfElements)
                {
                    response.AddError(OperationErrorCode.RequestValidationError, $"Electrical Charge NodePosition: {electricalCharge.NodePosition} must be greather than zero and less than number of elements: {request.NumberOfElements}. Electrical Charge index: {request.ElectricalCharges.IndexOf(electricalCharge)}.");
                }
            }

            if (Enum.TryParse(typeof(PiezoelectricPosition), Regex.Replace(request.PiezoelectricPosition, @"\s", ""), ignoreCase: true, out _) == false)
            {
                response.AddError(OperationErrorCode.RequestValidationError, $"Invalid piezoelectric position: '{request.PiezoelectricPosition}'.");
            }

            if (await this._profileValidator.Execute(request.PiezoelectricProfile, response).ConfigureAwait(false) == false)
            {
                response.AddError(OperationErrorCode.RequestValidationError, "Invalid piezoelectric profile.");
            }

            if (request.ElementsWithPiezoelectric == null)
            {
                return(response);
            }

            if (request.ElementsWithPiezoelectric.Max() > request.NumberOfElements || request.ElementsWithPiezoelectric.Min() < 1)
            {
                response.AddError(OperationErrorCode.RequestValidationError, $"Element with piezoelectric must be greather than one (1) and less than number of elements: {request.NumberOfElements}.");
            }

            return(response);
        }