package com.fidms.web.domain;

import com.fidms.common.annotation.Excel;
import com.fidms.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.security.task.DelegatingSecurityContextAsyncTaskExecutor;

import java.math.BigDecimal;

import static java.lang.Math.pow;
import static java.lang.Math.sqrt;

/**
 * 流场输入对象 bz_flow_field_input_t
 * 
 * @author Allen
 * @date 2023-05-08
 */
public class FlowFieldInput extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 编号 */
    private Long id;

    /** 3d模型主键 */
    @Excel(name = "3d模型主键")
    private Long model3dId;

    @Excel(name = "3d模型")
    private String model3dName;

    /** 来流马赫数*/
    @Excel(name = "来流马赫数")
    private BigDecimal machNumber;

    /** 来流方向x */
    @Excel(name = "来流方向x")
    private BigDecimal flowDirectionX;

    /** 来流方向y */
    @Excel(name = "来流方向y")
    private BigDecimal flowDirectionY;

    /** 来流方向z */
    @Excel(name = "来流方向z")
    private BigDecimal flowDirectionZ;

    /** 流速x */
    @Excel(name = "流速x")
    private BigDecimal flowVelocityX;

    /** 流速y */
    @Excel(name = "流速y")
    private BigDecimal flowVelocityY;

    /** 流速z */
    @Excel(name = "流速z")
    private BigDecimal flowVelocityZ;

    /**红外波段*/
    @Excel(name = "红外波段")
    private BigDecimal infraredBand;

    /** 来流温度 */
    @Excel(name = "来流温度")
    private BigDecimal flowTemperature;

    /** 来流静压 */
    @Excel(name = "来流静压")
    private BigDecimal flowPressure;

    /** 来流密度 */
    @Excel(name = "来流密度")
    private BigDecimal flowDensity;

    /** 飞行高度 */
    @Excel(name = "飞行高度")
    private BigDecimal flightAltitude;

    /** 二氧化碳质量分数 */
    @Excel(name = "二氧化碳质量分数")
    private BigDecimal co2MassFraction;

    /** 一氧化碳质量分数 */
    @Excel(name = "一氧化碳质量分数")
    private BigDecimal coMassFraction;

    /** 水蒸气质量分数 */
    @Excel(name = "水蒸气质量分数")
    private BigDecimal h2oMassFraction;

    /** Fluent网格文件 */
    @Excel(name = "Fluent网格文件")
    private String fluentGridFile;

    /** Fluent网格文件路径 */
    @Excel(name = "Fluent网格文件路径")
    private String fluentGridFilePath;

    /** Fluent cas文件 */
    @Excel(name = "Fluent cas文件")
    private String fluentCasFile;

    /** Fluent cas文件路径 */
    @Excel(name = "Fluent cas文件路径")
    private String fluentCasFilePath;

    /** Fluent dat文件路径 */
    @Excel(name = "Fluent dat文件路径")
    private String fluentDatFile;

    /** Fluent dat文件 */
    @Excel(name = "Fluent dat文件")
    private String fluentDatFilePath;

    public void setId(Long id)
    {
        this.id = id;
    }

    public Long getId() 
    {
        return id;
    }
    public void setModel3dId(Long model3dId) 
    {
        this.model3dId = model3dId;
    }

    public Long getModel3dId() 
    {
        return model3dId;
    }

    public String getModel3dName() {
        return model3dName;
    }

    public void setModel3dName(String model3dName) {
        this.model3dName = model3dName;
    }

    public void setMachNumber(BigDecimal machNumber)
    {
        this.machNumber = machNumber;
    }
    public BigDecimal getMachNumber()
    {
        return machNumber;
    }

    public void setFlowDirectionX(BigDecimal flowDirectionX){this.flowDirectionX=flowDirectionX;};
    public BigDecimal getFlowDirectionX(){return flowDirectionX;};

    public void setFlowDirectionY(BigDecimal flowDirectionY){this.flowDirectionY=flowDirectionY;};
    public BigDecimal getFlowDirectionY(){return flowDirectionY;};

    public void setFlowDirectionZ(BigDecimal flowDirectionZ){this.flowDirectionZ=flowDirectionZ;};
    public BigDecimal getFlowDirectionZ(){return flowDirectionZ;};

    public void setFlowVelocityX(BigDecimal flowVelocityX)
    {
        this.flowVelocityX = flowVelocityX;
    }

    public BigDecimal getFlowVelocityX() 
    {
        return flowVelocityX;
    }
    public void setFlowVelocityY(BigDecimal flowVelocityY)
    {
        this.flowVelocityY = flowVelocityY;
    }

    public BigDecimal getFlowVelocityY() 
    {
        return flowVelocityY;
    }
    public void setFlowVelocityZ(BigDecimal flowVelocityZ)
    {
        this.flowVelocityZ = flowVelocityZ;
    }

    public BigDecimal getFlowVelocityZ() 
    {
        return flowVelocityZ;
    }

    public void setInfraredBand(BigDecimal infraredBand){this.infraredBand=infraredBand;}

    public BigDecimal getInfraredBand() {
        return infraredBand;
    }

    public void setFlowTemperature(BigDecimal flowTemperature){this.flowTemperature=flowTemperature;}
    public BigDecimal getFlowTemperature(){return flowTemperature;}

    public void setFlowPressure(BigDecimal flowPressure){this.flowPressure=flowPressure;}

    public BigDecimal getFlowPressure() {
        return flowPressure;
    }
    public void setFlowDensity(BigDecimal flowDensity){this.flowDensity=flowDensity;}

    public BigDecimal getFlowDensity() {
        return flowDensity;
    }

    public void setFlightAltitude(BigDecimal flightAltitude){this.flightAltitude=flightAltitude;}
    public BigDecimal getFlightAltitude(){return flightAltitude;}

    public void setCo2MassFraction(BigDecimal co2MassFraction) 
    {
        this.co2MassFraction = co2MassFraction;
    }

    public BigDecimal getCo2MassFraction() 
    {
        return co2MassFraction;
    }
    public void setCoMassFraction(BigDecimal coMassFraction) 
    {
        this.coMassFraction = coMassFraction;
    }

    public BigDecimal getCoMassFraction() 
    {
        return coMassFraction;
    }
    public void setH2oMassFraction(BigDecimal h2oMassFraction) 
    {
        this.h2oMassFraction = h2oMassFraction;
    }

    public BigDecimal getH2oMassFraction() 
    {
        return h2oMassFraction;
    }

    public void setFluentGridFile(String fluentGridFile) 
    {
        this.fluentGridFile = fluentGridFile;
    }

    public String getFluentGridFile() 
    {
        return fluentGridFile;
    }
    public void setFluentGridFilePath(String fluentGridFilePath) 
    {
        this.fluentGridFilePath = fluentGridFilePath;
    }

    public String getFluentGridFilePath() 
    {
        return fluentGridFilePath;
    }
    public void setFluentCasFile(String fluentCasFile) 
    {
        this.fluentCasFile = fluentCasFile;
    }

    public String getFluentCasFile() 
    {
        return fluentCasFile;
    }
    public void setFluentCasFilePath(String fluentCasFilePath) 
    {
        this.fluentCasFilePath = fluentCasFilePath;
    }

    public String getFluentCasFilePath() 
    {
        return fluentCasFilePath;
    }
    public void setFluentDatFile(String fluentDatFile) 
    {
        this.fluentDatFile = fluentDatFile;
    }

    public String getFluentDatFile() 
    {
        return fluentDatFile;
    }
    public void setFluentDatFilePath(String fluentDatFilePath) 
    {
        this.fluentDatFilePath = fluentDatFilePath;
    }

    public String getFluentDatFilePath() 
    {
        return fluentDatFilePath;
    }

    public void getFlowVelocity()
    {
        double directionx=0,directiony=0,directionz=0,machnum=0,temperature=0;
        if(this.flowDirectionX !=null)
            directionx = this.flowDirectionX.doubleValue();
        else
            directionx = 0;

        if(this.flowDirectionY != null)
            directiony = this.flowDirectionY.doubleValue();
        else
            directiony= 0;

        if(this.flowDirectionZ != null)
            directionz = this.flowDirectionZ.doubleValue();
        else
            directionz = 0;

        if(this.machNumber != null)
            machnum = this.machNumber.doubleValue();
        else
            machnum= 0;

        if(this.flowTemperature != null)
            temperature = this.flowTemperature.doubleValue();
        else
            temperature = 0;

        if(directionx != 0 && directiony!=0 && directionz!=0 && machnum!=0 && temperature!=0)
        {
            double flowVelocity  = machnum*(sqrt(temperature*1.4 * 287.06));
            final double a = pow(directionx, 2) + pow(directiony, 2) + pow(directionz, 2);

            double flowVelocityX = flowVelocity*directionx/(sqrt(a));
            this.setFlowVelocityX(BigDecimal.valueOf(flowVelocityX));

            double flowVelocityY = flowVelocity*directiony/(sqrt(a));
            this.setFlowVelocityY(BigDecimal.valueOf(flowVelocityY));

            double flowVelocityZ = flowVelocity*directionz/(sqrt(a));
            this.setFlowVelocityZ(BigDecimal.valueOf(flowVelocityZ));
        }
    }

    public void setTemperatureAndPressureAndDensityByFlightAltitude()
    {
        double temperature=0,pressure=0,density=0,altitude=0;
        if(this.flowTemperature!=null)
            temperature=this.flowTemperature.doubleValue();
        else
            temperature=0;

        if(this.flowPressure!=null)
            pressure=this.flowPressure.doubleValue();
        else
            pressure=0;

        if(this.flowDensity!=null)
            density=this.flowDensity.doubleValue();
        else
            density=0;

        if(this.flightAltitude!=null)
            altitude=this.flightAltitude.doubleValue();
        else
            altitude=0;
        //公式中未给出R的值，暂命为1；
        double R=1;
        if(altitude!=0 /*&& temperature!=0 && density!=0 && pressure!=0*/)
        {
            if(altitude>0 && altitude<=11000 )
            {
                temperature = 288.15 - 0.0065*altitude;
                pressure = 101325*pow((1-0.0065*altitude/288.15),(9800/0.0065/R));
                density = 1225*pow((1-0.0065*altitude/288.15),(9800/0.0065/R-1));
            }
            else if(altitude>11000 && altitude<=20000)
            {
                temperature=216.7;
                double temperature11 = 288.15-0.0065*11000;
                double pressure11=101325*pow((1-0.0065*11000/288.15),(9800/0.0065/R));
                pressure = pressure11*pow(Math.E,(-9800*(altitude-11000)/temperature11/R));
                double density11 = 1225*pow((1-0.0065*11000/288.15),(9800/0.0065/R-1));
                density = density11*pow(Math.E,(-9800*(altitude-11000/temperature11/R)));
            }
            else if(altitude>20000 && altitude<=32000)
            {
                double temperature11 = 288.15-0.0065*11000;
                double temperature20 = 216.7;
                temperature = temperature20+0.001*(altitude-20000);

                double pressure11=101325*pow((1-0.0065*11000/288.15),(9800/0.0065/R));
                double pressure20 = pressure11*pow(Math.E,(-9800*(20000-11000)/temperature11/R));
                pressure = pressure20*pow((1+0.001*(altitude-20000)/temperature20),-9800/0.001/R);

                double density11 = 1225*pow((1-0.0065*11000/288.15),(9800/0.0065/R-1));
                double density20 = density11*pow(Math.E,(-9800*(20000-11000/temperature11/R)));
                density = density20*pow((1+0.001*(altitude-20000)/temperature20),(-9800/0.001/R-1));
            }
            setFlowTemperature(BigDecimal.valueOf(temperature));
            setFlowPressure(BigDecimal.valueOf(pressure));
            setFlowDensity(BigDecimal.valueOf(density));
        }


    }

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("id", getId())
            .append("model3dId", getModel3dId())
            .append("model3dName", getModel3dName())
            .append("machNumber", getMachNumber())
            .append("flowDirectionX",getFlowDirectionX())
            .append("flowDirectionY",getFlowDirectionY())
            .append("flowDirectionZ",getFlowDirectionZ())
            .append("flowVelocityX", getFlowVelocityX())
            .append("flowVelocityY", getFlowVelocityY())
            .append("flowVelocityZ", getFlowVelocityZ())
            .append("infraredBand",getInfraredBand())
            .append("flowTemperature", getFlowTemperature())
            .append("flowPressure",getFlowPressure())
            .append("flowDensity", getFlowDensity())
            .append("flightAltitude",getFlightAltitude())
            .append("co2MassFraction", getCo2MassFraction())
            .append("coMassFraction", getCoMassFraction())
            .append("h2oMassFraction", getH2oMassFraction())
            .append("fluentGridFile", getFluentGridFile())
            .append("fluentGridFilePath", getFluentGridFilePath())
            .append("fluentCasFile", getFluentCasFile())
            .append("fluentCasFilePath", getFluentCasFilePath())
            .append("fluentDatFile", getFluentDatFile())
            .append("fluentDatFilePath", getFluentDatFilePath())
            .append("createBy", getCreateBy())
            .append("createTime", getCreateTime())
            .append("updateBy", getUpdateBy())
            .append("updateTime", getUpdateTime())
            .toString();
    }
}
