Golang 写的一个计算挡土墙主动土压力的计算小程序

package main

import (
    "fmt"
    "math"
    "sort"
)

// 定义挡土墙的参数
var (
    height float64
    alpha  float64
    beta   float64
    delta  float64
)

// 定义墙后土体的参数
var (
    gamma    float64
    cohesion float64
    phi      float64
)

var q float64

type Rad float64
type Degree float64

// 提示用户输入具体墙的高度、倾角、墙顶边坡倾角、挡土墙与土体之间的摩擦角、土体重度、土体黏聚强度和土体摩擦角的值。
// 这些输入的值将存储在相应的变量中。
func init() {
    fmt.Print("请输入挡土墙高度h(m):")
    fmt.Scanf("%f", &height)
    fmt.Print("请输入挡土墙倾角α(°):")
    fmt.Scanf("%f", &alpha)
    fmt.Print("请输入墙顶边坡倾角β(°):")
    fmt.Scanf("%f", &beta)
    fmt.Print("请输入挡土墙与土体之间的摩擦角δ(°):")
    fmt.Scanf("%f", &delta)
    fmt.Print("请输入土体重度γ(kN/m3):")
    fmt.Scanf("%f", &gamma)
    fmt.Print("请输入土体黏聚强度c(kPa)")
    fmt.Scanf("%f", &cohesion)
    fmt.Print("请输入土体摩擦角φ(°):")
    fmt.Scanf("%f", &phi)
    fmt.Print("请输入坡顶超载q(kN/m2):")
    fmt.Scanf("%f", &q)
}

// ToDegree 函数将弧度值转换为角度值。它接受一个 Rad 值作为输入,并返回一个 Degree 值。
func (d Degree) toRad() Rad {
    return Rad(d * math.Pi / 180)
}

func main() {
    //假设破裂角θ
    var theta float64
    type totalActiveEarthPressure struct {
        theta   float64
        presure float64
    }
    var presure float64
    var totalActiveEarthPressures []totalActiveEarthPressure

    for theta = beta + 0.1; theta <= 180-alpha; theta += 0.1 {
        // 计算每个θ下的主动土压力
        l1 := height / math.Sin(float64(Degree(alpha).toRad()))
        l2 := l1 / math.Sin(float64(Degree(theta-beta).toRad())) * math.Sin(float64(Degree(alpha+beta).toRad()))
        l3 := l1 / math.Sin(float64(Degree(theta-beta).toRad())) * math.Sin(float64(Degree(180-alpha-theta).toRad()))
        //破裂体的重量
        G := 0.5*l1*l2*math.Sin(float64(Degree(180-alpha-theta).toRad()))*gamma + q*l3*math.Cos(float64(Degree(beta).toRad()))
        //核心公式
        presure = (G*math.Sin(float64(Degree(theta-phi).toRad())) - cohesion*l2*math.Cos(float64(Degree(phi).toRad()))) / math.Sin(float64(Degree(theta-phi+alpha-delta).toRad()))
        totalActiveEarthPressures = append(totalActiveEarthPressures, totalActiveEarthPressure{theta: theta, presure: presure})
    }
    // 按主动土压力降序排序,寻找极值及相应的破裂角。
    sort.Slice(totalActiveEarthPressures, func(i, j int) bool {
        return totalActiveEarthPressures[i].presure > totalActiveEarthPressures[j].presure
    })
    fmt.Printf("破裂角θ=%.2f°,相应的主动土压力为%.2fkN/m\n", totalActiveEarthPressures[0].theta, totalActiveEarthPressures[0].presure)
    fmt.Println("计算完成")
}

转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 admin@yantu.org