本文整理汇总了Golang中github.com/cpmech/gosl/io.Pfyel函数的典型用法代码示例。如果您正苦于以下问题:Golang Pfyel函数的具体用法?Golang Pfyel怎么用?Golang Pfyel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Pfyel函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: checkinput
func checkinput(tst *testing.T, m *Mesh, nverts, ncells int, X [][]float64, vtags, ctags, parts []int, types []string, V [][]int, etags, ftags [][]int) {
if len(m.Verts) != nverts {
tst.Errorf("nverts is incorrect: %d != %d", len(m.Verts), nverts)
return
}
if len(m.Cells) != ncells {
tst.Errorf("ncells is incorrect: %d != %d", len(m.Cells), ncells)
return
}
io.Pfyel("\nvertices:\n")
for i, v := range m.Verts {
io.Pf("%+v\n", v)
chk.Vector(tst, io.Sf("vertex %2d: X", v.Id), 1e-15, v.X, X[v.Id])
if v.Tag != vtags[i] {
tst.Errorf("vtag is incorrect: %d != %d", v.Tag, vtags[i])
return
}
}
io.Pfyel("\ncells:\n")
for i, c := range m.Cells {
io.Pf("%+v\n", c)
if c.Tag != ctags[i] {
tst.Errorf("ctag is incorrect: %d != %d", c.Tag, ctags[i])
return
}
if c.Part != parts[i] {
tst.Errorf("part is incorrect: %d != %d", c.Part, parts[i])
return
}
chk.String(tst, types[i], c.Type)
chk.Ints(tst, io.Sf("cell %2d : V", c.Id), c.V, V[c.Id])
chk.Ints(tst, io.Sf("cell %2d : edgetags", c.Id), c.EdgeTags, etags[c.Id])
}
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:34,代码来源:t_mesh_test.go
示例2: Test_ind01
func Test_ind01(tst *testing.T) {
//verbose()
chk.PrintTitle("ind01. representation and copying")
rnd.Init(0)
nbases := 3
A := get_individual(0, nbases)
B := A.GetCopy()
chk.Scalar(tst, "ova0", 1e-17, B.Ovas[0], 123)
chk.Scalar(tst, "ova1", 1e-17, B.Ovas[1], 345)
chk.Scalar(tst, "oor0", 1e-17, B.Oors[0], 10)
chk.Scalar(tst, "oor1", 1e-17, B.Oors[1], 20)
chk.Scalar(tst, "oor2", 1e-17, B.Oors[2], 30)
fmts := map[string][]string{"int": {" %d"}, "flt": {" %.1f"}, "str": {" %q"}, "key": {" %x"}, "byt": {" %q"}, "fun": {" %q"}}
oA := A.Output(fmts, false)
oB := B.Output(fmts, false)
io.Pfyel("\n%v\n", oA)
io.Pfyel("%v\n\n", oB)
chk.String(tst, oA, " 1 20 300 4.4 5.5 666.0 \"abc\" \"b\" \"c\" 53 47 41 \"ABC\" \"DEF\" \"GHI\" \"f0\" \"f1\" \"f2\"")
chk.String(tst, oB, " 1 20 300 4.4 5.5 666.0 \"abc\" \"b\" \"c\" 53 47 41 \"ABC\" \"DEF\" \"GHI\" \"f0\" \"f1\" \"f2\"")
A.SetFloat(1, 33)
A.SetFloat(2, 88)
oA = A.Output(fmts, false)
io.Pfyel("\n%v\n", oA)
chk.String(tst, oA, " 1 20 300 4.4 33.0 88.0 \"abc\" \"b\" \"c\" 53 47 41 \"ABC\" \"DEF\" \"GHI\" \"f0\" \"f1\" \"f2\"")
}
开发者ID:postfix,项目名称:goga-1,代码行数:31,代码来源:t_individual_test.go
示例3: Test_stat02
func Test_stat02(tst *testing.T) {
//verbose()
chk.PrintTitle("stat02")
x := [][]float64{
{100, 100, 102, 98, 77, 99, 70, 105, 98},
{80, 101, 12, 58, 47, 80, 20, 111, 89},
{50, 130, 72, 38, 71, 15, 10, 12, 55},
}
y, z := StatTable(x, true, true)
la.PrintMat("x", x, "%5g", false)
la.PrintMat("y", y, "%13.6f", false)
la.PrintMat("z", z, "%13.6f", false)
io.Pforan("\nmin\n")
chk.Scalar(tst, "y00=min(x[0,:])", 1e-17, y[0][0], 70)
chk.Scalar(tst, "y01=min(x[1,:])", 1e-17, y[0][1], 12)
chk.Scalar(tst, "y02=min(x[2,:])", 1e-17, y[0][2], 10)
io.Pforan("\nave\n")
chk.Scalar(tst, "y10=ave(x[0,:])", 1e-17, y[1][0], 849.0/9.0)
chk.Scalar(tst, "y11=ave(x[1,:])", 1e-17, y[1][1], 598.0/9.0)
chk.Scalar(tst, "y12=ave(x[2,:])", 1e-17, y[1][2], 453.0/9.0)
io.Pforan("\nmax\n")
chk.Scalar(tst, "y20=max(x[0,:])", 1e-17, y[2][0], 105)
chk.Scalar(tst, "y21=max(x[1,:])", 1e-17, y[2][1], 111)
chk.Scalar(tst, "y22=max(x[2,:])", 1e-17, y[2][2], 130)
io.Pforan("\ndev\n")
chk.Scalar(tst, "y30=dev(x[0,:])", 1e-17, y[3][0], 12.134661099511597)
chk.Scalar(tst, "y31=dev(x[1,:])", 1e-17, y[3][1], 34.688294535444918)
chk.Scalar(tst, "y32=dev(x[2,:])", 1e-17, y[3][2], 38.343839140075687)
io.Pfyel("\nmin\n")
chk.Scalar(tst, "z00=min(y[0,:])=min(min)", 1e-17, z[0][0], 10)
chk.Scalar(tst, "z01=min(y[1,:])=min(ave)", 1e-17, z[0][1], 453.0/9.0)
chk.Scalar(tst, "z02=min(y[2,:])=min(max)", 1e-17, z[0][2], 105)
chk.Scalar(tst, "z03=min(y[3,:])=min(dev)", 1e-17, z[0][3], 12.134661099511597)
io.Pfyel("\nave\n")
chk.Scalar(tst, "z10=ave(y[0,:])=ave(min)", 1e-17, z[1][0], 92.0/3.0)
chk.Scalar(tst, "z11=ave(y[1,:])=ave(ave)", 1e-17, z[1][1], ((849.0+598.0+453.0)/9.0)/3.0)
chk.Scalar(tst, "z12=ave(y[2,:])=ave(max)", 1e-17, z[1][2], 346.0/3.0)
chk.Scalar(tst, "z13=ave(y[3,:])=ave(dev)", 1e-17, z[1][3], (12.134661099511597+34.688294535444918+38.343839140075687)/3.0)
io.Pfyel("\nmax\n")
chk.Scalar(tst, "z20=max(y[0,:])=max(min)", 1e-17, z[2][0], 70)
chk.Scalar(tst, "z21=max(y[1,:])=max(ave)", 1e-17, z[2][1], 849.0/9.0)
chk.Scalar(tst, "z22=max(y[2,:])=max(max)", 1e-17, z[2][2], 130)
chk.Scalar(tst, "z23=max(y[3,:])=max(dev)", 1e-17, z[2][3], 38.343839140075687)
io.Pfyel("\ndev\n")
chk.Scalar(tst, "z30=dev(y[0,:])=dev(min)", 1e-17, z[3][0], 34.078341117685483)
chk.Scalar(tst, "z31=dev(y[1,:])=dev(ave)", 1e-17, z[3][1], 22.261169573539771)
chk.Scalar(tst, "z32=dev(y[2,:])=dev(max)", 1e-17, z[3][2], 13.051181300301263)
chk.Scalar(tst, "z33=dev(y[3,:])=dev(dev)", 1e-17, z[3][3], 14.194778389023206)
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:52,代码来源:t_stat_test.go
示例4:
// CalcΔεElast calculates Δε corresponding to an elastic loading with Δp and Δq
func CalcΔεElast(Δε []float64, K, G float64, Δp, Δq float64, axsym bool) (Δεv, Δεd float64, err error) {
Δεv = -Δp / K
Δεd = Δq / (3.0 * G)
var Δεx, Δεy, Δεz float64
if axsym { // axisymmetric
compression := true
if compression {
Δεx = Δεv/3.0 + Δεd/2.0
Δεy = Δεx
Δεz = Δεv/3.0 - Δεd
} else {
Δεx = Δεv/3.0 - Δεd/2.0
Δεy = Δεv/3.0 + Δεd
Δεz = Δεx
}
} else { // plane-strain with Δεy = Δεx / 2
c := 9.0 * Δεd * Δεd / (4.0 * Δεv * Δεv)
α := 0.0
if math.Abs(c-1.0) > 1e-15 {
d := 3.0 * (4.0*c - 1.0)
if d < 0.0 {
return 0, 0, chk.Err("discriminant < 0: c=%v d=%v", c, d)
}
α1 := (1.0 + 2.0*c + math.Sqrt(d)) / (2.0 - 2.0*c)
α2 := (1.0 + 2.0*c - math.Sqrt(d)) / (2.0 - 2.0*c)
α = α1
io.Pfyel("d, α1, α2 = %v, %v, %v\n", d, α1, α2)
}
io.Pfyel("c, α = %v, %v\n", c, α)
Δεy = Δεv / (1.0 + α)
Δεx = α * Δεy
Δεz = 0
}
//io.Pfpink("Δp=%v, Δq=%v => Δεv=%v, Δεd=%v => Δεx=%v, Δεy=%v, Δεz=%v\n", Δp, Δq, Δεv, Δεd, Δεx, Δεy, Δεz)
Δε[0] = Δεx
Δε[1] = Δεy
Δε[2] = Δεz
Δε[3] = 0
Δεv_ := tsr.M_εv(Δε)
Δεd_ := tsr.M_εd(Δε)
if math.Abs(Δεv-Δεv_) > 1e-15 {
return 0, 0, chk.Err(_path_err09, Δεv, Δεv_)
}
if Δεd < 0 {
Δεd_ = -Δεd_ // allow negative values
}
if math.Abs(Δεd-Δεd_) > 1e-15 {
return 0, 0, chk.Err(_path_err10, Δεd, Δεd_)
}
return
}
开发者ID:PatrickSchm,项目名称:gofem,代码行数:52,代码来源:path.go
示例5: Test_shp01
func Test_shp01(tst *testing.T) {
//verbose()
chk.PrintTitle("shp01")
r := []float64{0, 0, 0}
verb := true
for name, _ := range Functions {
io.Pfyel("--------------------------------- %-6s---------------------------------\n", name)
// check S
tol := 1e-17
if name == "tri10" {
tol = 1e-14
}
checkShape(tst, name, tol, verb)
// check dSdR
tol = 1e-14
if name == "lin5" || name == "lin4" || name == "tri10" || name == "qua12" || name == "qua16" {
tol = 1e-10
}
if name == "tri15" {
tol = 1e-9
}
checkDerivs(tst, name, r, tol, verb)
io.PfGreen("OK\n")
}
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:32,代码来源:t_shapes_test.go
示例6: Test_MTint01
func Test_MTint01(tst *testing.T) {
//verbose()
chk.PrintTitle("MTint01. integers (Mersenne Twister)")
Init(1234)
nints := 10
vals := make([]int, NSAMPLES)
// using MTint
t0 := time.Now()
for i := 0; i < NSAMPLES; i++ {
vals[i] = MTint(0, nints-1)
}
io.Pforan("time elapsed = %v\n", time.Now().Sub(t0))
hist := IntHistogram{Stations: utl.IntRange(nints + 1)}
hist.Count(vals, true)
io.Pfyel(TextHist(hist.GenLabels("%d"), hist.Counts, 60))
// using MTints
t0 = time.Now()
MTints(vals, 0, nints-1)
io.Pforan("time elapsed = %v\n", time.Now().Sub(t0))
hist.Count(vals, true)
io.Pfcyan(TextHist(hist.GenLabels("%d"), hist.Counts, 60))
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:29,代码来源:t_random_test.go
示例7: Test_imap
func Test_imap(tst *testing.T) {
//utl.Tsilent = false
chk.PrintTitle("Test imap")
for name, shape := range factory {
gndim := shape.Gndim
if gndim == 1 {
continue
}
io.Pfyel("--------------------------------- %-6s---------------------------------\n", name)
// check inverse mapping
tol := 1e-14
noise := 0.01
if name == "tri10" {
tol = 1e-14
}
if shape.FaceNvertsMax > 2 {
noise = 0.0
}
nverts := shape.Nverts
C := la.MatAlloc(gndim, nverts)
s := []float64{rand.Float64(), rand.Float64(), rand.Float64()} // scale factors
la.MatCopy(C, 1.0, shape.NatCoords)
_ = tol
io.Pf("nverts:%v\n", nverts)
io.Pf("gndim:%v\n", gndim)
for i := 0; i < gndim; i++ {
for j := 0; j < nverts; j++ {
C[i][j] *= s[i]
C[i][j] += noise * rand.Float64() // noise
}
}
r := make([]float64, 3)
x := make([]float64, 3)
R := la.MatAlloc(gndim, nverts)
for j := 0; j < nverts; j++ {
for i := 0; i < gndim; i++ {
x[i] = C[i][j]
}
err := shape.InvMap(r, x, C)
io.Pf("r:%v\n", r)
_ = err
for i := 0; i < gndim; i++ {
R[i][j] = r[i]
}
}
chk.Matrix(tst, "checking", tol, R, shape.NatCoords)
io.PfGreen("OK\n")
}
}
开发者ID:PaddySchmidt,项目名称:gofem,代码行数:57,代码来源:t_imap_test.go
示例8: Test_out02
func Test_out02(tst *testing.T) {
// finalise analysis process and catch errors
defer func() {
if err := recover(); err != nil {
tst.Fail()
io.PfRed("ERROR: %v\n", err)
}
}()
// test title
//verbose()
chk.PrintTitle("out02")
// start simulation
processing := fem.NewFEM("data/twoqua4.sim", "", true, true, false, false, chk.Verbose, 0)
// run simulation
err := processing.Run()
if err != nil {
tst.Errorf("Run failed:\n%v", err)
return
}
// start post-processing
Start("data/twoqua4.sim", 0, 0)
// get second ip coordinates
xip := Ipoints[1].X
io.Pfcyan("xip = %v\n", xip)
// define points
Define("A", N{-1})
Define("ips", Along{{xip[0], 0}, {xip[0], 1}})
// load results
LoadResults(nil)
// solution
var sol ana.CteStressPstrain
sol.Init(fun.Prms{
&fun.Prm{N: "qnH", V: -50},
&fun.Prm{N: "qnV", V: -100},
})
// check displacements
tolu := 1e-15
x := GetCoords("A")
ux := GetRes("ux", "A", 0)
uy := GetRes("uy", "A", 0)
io.Pforan("ux=%v uy=%v\n", ux, uy)
for j, t := range Times {
io.Pfyel("t=%g\n", t)
sol.CheckDispl(tst, t, []float64{ux[j], uy[j]}, x, tolu)
}
}
开发者ID:PaddySchmidt,项目名称:gofem,代码行数:56,代码来源:t_out_test.go
示例9: msg
// msg prints information on residuals
func (o *NlSolver) msg(typ string, it int, Ldx, fx_max float64, first, last bool) {
if first {
io.Pfpink("\n%4s%23s%23s\n", "it", "Ldx", "fx_max")
io.Pfpink("%4s%23s%23s\n", "", io.Sf("(%7.1e)", o.fnewt), io.Sf("(%7.1e)", o.ftol))
return
}
io.Pfyel("%4d%23.15e%23.15e\n", it, Ldx, fx_max)
if last {
io.Pfgrey(". . . converged with %s. nit=%d, nFeval=%d, nJeval=%d\n", typ, it, o.NFeval, o.NJeval)
}
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:12,代码来源:nlsolver.go
示例10: PrintConstraints
// PrintConstraints prints violated or not constraints
func (o System) PrintConstraints(P []float64, Pdemand float64, full bool) {
sumP := 0.0
for i, g := range o.G {
if full {
io.Pfyel("P%d range error = %v\n", i, utl.GtePenalty(P[i], g.Pmin, 1)+utl.GtePenalty(g.Pmax, P[i], 1))
}
sumP += P[i]
}
Ploss := 0.0
io.Pf("balance error = %v\n", math.Abs(sumP-Pdemand-Ploss))
}
开发者ID:cpmech,项目名称:goga,代码行数:12,代码来源:generators.go
示例11: Test_nurbs02
func Test_nurbs02(tst *testing.T) {
//verbose()
chk.PrintTitle("nurbs02. square with initial stress. run")
// fem
analysis := NewFEM("data/nurbs02.sim", "", true, false, false, false, chk.Verbose, 0)
// run simulation
err := analysis.Run()
if err != nil {
tst.Errorf("Run failed\n%v", err)
return
}
// domain
dom := analysis.Domains[0]
e := dom.Elems[0].(*ElemU)
io.PfYel("fex = %v\n", e.fex)
io.PfYel("fey = %v\n", e.fey)
la.PrintMat("K", e.K, "%10.2f", false)
// solution
var sol ana.CteStressPstrain
sol.Init(fun.Prms{
&fun.Prm{N: "qnH0", V: -20},
&fun.Prm{N: "qnV0", V: -20},
&fun.Prm{N: "qnH", V: -50},
&fun.Prm{N: "qnV", V: -100},
})
// check displacements
t := dom.Sol.T
tolu := 1e-16
for _, n := range dom.Nodes {
eqx := n.GetEq("ux")
eqy := n.GetEq("uy")
u := []float64{dom.Sol.Y[eqx], dom.Sol.Y[eqy]}
io.Pfyel("u = %v\n", u)
sol.CheckDispl(tst, t, u, n.Vert.C, tolu)
}
// check stresses
tols := 1e-13
for idx, ip := range e.IpsElem {
x := e.Cell.Shp.IpRealCoords(e.X, ip)
σ := e.States[idx].Sig
io.Pforan("σ = %v\n", σ)
sol.CheckStress(tst, t, σ, x, tols)
}
}
开发者ID:PaddySchmidt,项目名称:gofem,代码行数:52,代码来源:t_nurbs_test.go
示例12: PrintMemStat
// PrintMemStat prints memory statistics
func PrintMemStat(msg string) {
var mem runtime.MemStats
runtime.ReadMemStats(&mem)
io.PfYel("%s\n", msg)
io.Pfyel("Alloc = %v [KB] %v [MB] %v [GB]\n", mem.Alloc/KBSIZE, mem.Alloc/MBSIZE, mem.Alloc/GBSIZE)
io.Pfyel("HeapAlloc = %v [KB] %v [MB] %v [GB]\n", mem.HeapAlloc/KBSIZE, mem.HeapAlloc/MBSIZE, mem.HeapAlloc/GBSIZE)
io.Pfyel("Sys = %v [KB] %v [MB] %v [GB]\n", mem.Sys/KBSIZE, mem.Sys/MBSIZE, mem.Sys/GBSIZE)
io.Pfyel("HeapSys = %v [KB] %v [MB] %v [GB]\n", mem.HeapSys/KBSIZE, mem.HeapSys/MBSIZE, mem.HeapSys/GBSIZE)
io.Pfyel("TotalAlloc = %v [KB] %v [MB] %v [GB]\n", mem.TotalAlloc/KBSIZE, mem.TotalAlloc/MBSIZE, mem.TotalAlloc/GBSIZE)
io.Pfyel("Mallocs = %v\n", mem.Mallocs)
io.Pfyel("Frees = %v\n", mem.Frees)
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:13,代码来源:profiling.go
示例13: Test_nurbs03
func Test_nurbs03(tst *testing.T) {
//verbose()
chk.PrintTitle("nurbs03. ini stress free square")
// fem
analysis := NewFEM("data/nurbs03.sim", "", true, false, false, false, chk.Verbose, 0)
// run simulation
err := analysis.Run()
if err != nil {
tst.Errorf("Run failed\n%v", err)
return
}
// domain
dom := analysis.Domains[0]
// element
e := dom.Elems[0].(*ElemU)
io.PfYel("fex = %v\n", e.fex)
io.PfYel("fey = %v\n", e.fey)
la.PrintMat("K", e.K, "%10.2f", false)
// solution
var sol ana.CteStressPstrain
sol.Init(fun.Prms{
&fun.Prm{N: "qnH", V: -50},
&fun.Prm{N: "qnV", V: -100},
})
// check displacements
t := dom.Sol.T
tolu := 1e-16
for _, n := range dom.Nodes {
eqx := n.GetEq("ux")
eqy := n.GetEq("uy")
u := []float64{dom.Sol.Y[eqx], dom.Sol.Y[eqy]}
io.Pfyel("u = %v\n", u)
sol.CheckDispl(tst, t, u, n.Vert.C, tolu)
}
}
开发者ID:PaddySchmidt,项目名称:gofem,代码行数:42,代码来源:t_nurbs_test.go
示例14: Test_eigenp01
func Test_eigenp01(tst *testing.T) {
//verbose()
chk.PrintTitle("eigenp01")
// constants
tolP := 1e-14 // eigenprojectors
tolS := 1e-13 // spectral decomposition
toldP := 1e-9 // derivatives of eigenprojectors
ver := chk.Verbose // check P verbose
verdP := chk.Verbose // check dPda verbose
// run test
nd := test_nd
for idxA := 0; idxA < len(test_nd); idxA++ {
//for idxA := 10; idxA < 11; idxA++ {
//for idxA := 11; idxA < 12; idxA++ {
//for idxA := 12; idxA < 13; idxA++ {
// tensor and eigenvalues
A := test_AA[idxA]
a := M_Alloc2(nd[idxA])
Ten2Man(a, A)
io.PfYel("\n\ntst # %d ###################################################################################\n", idxA)
io.Pfblue2("a = %v\n", a)
io.Pfblue2("λ = %v\n", test_λ[idxA])
// check eigenprojectors
io.Pforan("\neigenprojectors\n")
λsorted := CheckEigenprojs(a, tolP, tolS, ver)
io.Pfyel("λsorted = %v\n", λsorted)
λchk := utl.DblGetSorted(test_λ[idxA])
chk.Vector(tst, "λchk", 1e-12, λsorted, λchk)
// check derivatives of eigenprojectors
io.Pforan("\nderivatives\n")
CheckEigenprojsDerivs(a, toldP, verdP, EV_ZERO)
}
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:40,代码来源:t_eigenprojs_test.go
示例15: Test_GOshuffleInts01
func Test_GOshuffleInts01(tst *testing.T) {
//verbose()
chk.PrintTitle("GOshuffleInts01")
Init(0)
n := 10
nums := utl.IntRange(n)
io.Pfgreen("before = %v\n", nums)
IntShuffle(nums)
io.Pfcyan("after = %v\n", nums)
sort.Ints(nums)
io.Pforan("sorted = %v\n", nums)
chk.Ints(tst, "nums", nums, utl.IntRange(n))
shufled := IntGetShuffled(nums)
io.Pfyel("shufled = %v\n", shufled)
sort.Ints(shufled)
chk.Ints(tst, "shufled", shufled, utl.IntRange(n))
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:22,代码来源:t_random_test.go
示例16: Test_shape01
func Test_shape01(tst *testing.T) {
//verbose()
chk.PrintTitle("shape01")
r := []float64{0, 0, 0}
verb := true
for name, shape := range factory {
io.Pfyel("--------------------------------- %-6s---------------------------------\n", name)
// check S
tol := 1e-17
if name == "tri10" {
tol = 1e-14
}
CheckShape(tst, shape, tol, verb)
// check Sf
tol = 1e-18
CheckShapeFace(tst, shape, tol, verb)
// check dSdR
tol = 1e-14
if name == "lin5" || name == "lin4" || name == "tri10" || name == "qua12" || name == "qua16" {
tol = 1e-10
}
if name == "tri15" {
tol = 1e-9
}
CheckDSdR(tst, shape, r, tol, verb)
io.PfGreen("OK\n")
}
}
开发者ID:PaddySchmidt,项目名称:gofem,代码行数:36,代码来源:t_shape_test.go
示例17: Test_sim02
func Test_sim02(tst *testing.T) {
//verbose()
chk.PrintTitle("sim01")
sim := ReadSim("data", "frees01.sim", "", true)
if sim == nil {
tst.Errorf("test failed: check error log\n")
return
}
if chk.Verbose {
sim.GetInfo(os.Stdout)
io.Pf("\n")
}
io.Pfyel("ndim = %v\n", sim.Ndim)
io.Pfyel("maxElev = %v\n", sim.MaxElev)
io.Pfyel("grav = %v\n", sim.Gfcn.F(0, nil))
io.Pfyel("Wrho0 = %v\n", sim.WaterRho0)
io.Pfyel("Wbulk = %v\n", sim.WaterBulk)
io.Pfyel("Wlevel = %v\n", sim.WaterLevel)
}
开发者ID:PatrickSchm,项目名称:gofem,代码行数:22,代码来源:t_read_test.go
示例18: TestingCompareResultsU
// testing_compare_results_u compares results with u-formulation
func TestingCompareResultsU(tst *testing.T, simfname, cmpfname string, tolK, tolu, tols float64, skipK, verbose bool) {
// only root can run this test
if !Global.Root {
return
}
// read summary
sum := ReadSum(Global.Dirout, Global.Fnkey)
if sum == nil {
tst.Error("cannot read summary file for simulation=%q\n", simfname)
return
}
// allocate domain
distr := false
d := NewDomain(Global.Sim.Regions[0], distr)
if !d.SetStage(0, Global.Sim.Stages[0], distr) {
tst.Errorf("TestingCompareResultsU: SetStage failed\n")
return
}
// read file
buf, err := io.ReadFile(cmpfname)
if err != nil {
tst.Errorf("TestingCompareResultsU: ReadFile failed\n")
return
}
// unmarshal json
var cmp_set T_results_set
err = json.Unmarshal(buf, &cmp_set)
if err != nil {
tst.Errorf("TestingCompareResultsU: Unmarshal failed\n")
return
}
// run comparisons
dmult := 1.0
for idx, cmp := range cmp_set {
// displacements multiplier
if idx == 0 && math.Abs(cmp.DispMult) > 1e-10 {
dmult = cmp.DispMult
}
// time index
tidx := idx + 1
if verbose {
io.PfYel("\n\ntidx = %d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n", tidx)
}
// load gofem results
if !d.In(sum, tidx, true) {
tst.Errorf("TestingCompareResultsU: reading of results failed\n")
return
}
if verbose {
io.Pfyel("time = %v\n", d.Sol.T)
}
// check K matrices
if !skipK {
if verbose {
io.Pfgreen(". . . checking K matrices . . .\n")
}
for eid, Ksg := range cmp.Kmats {
if e, ok := d.Elems[eid].(*ElemU); ok {
if !e.AddToKb(d.Kb, d.Sol, true) {
tst.Errorf("TestingCompareResultsU: AddToKb failed\n")
return
}
chk.Matrix(tst, io.Sf("K%d", eid), tolK, e.K, Ksg)
}
}
}
// check displacements
if verbose {
io.Pfgreen(". . . checking displacements . . .\n")
}
for nid, usg := range cmp.Disp {
ix := d.Vid2node[nid].Dofs[0].Eq
iy := d.Vid2node[nid].Dofs[1].Eq
chk.AnaNum(tst, "ux", tolu, d.Sol.Y[ix], usg[0]*dmult, verbose)
chk.AnaNum(tst, "uy", tolu, d.Sol.Y[iy], usg[1]*dmult, verbose)
if len(usg) == 3 {
iz := d.Vid2node[nid].Dofs[2].Eq
chk.AnaNum(tst, "uz", tolu, d.Sol.Y[iz], usg[2]*dmult, verbose)
}
}
// check stresses
if true {
if verbose {
io.Pfgreen(". . . checking stresses . . .\n")
}
for eid, sig := range cmp.Sigmas {
if verbose {
//.........这里部分代码省略.........
开发者ID:PatrickSchm,项目名称:gofem,代码行数:101,代码来源:testing.go
示例19: Solve
// Solve solves y(x) = 0 for x in [xa, xb] with f(xa) * f(xb) < 0
//
// Based on ZEROIN C math library: http://www.netlib.org/c/
// By: Oleg Keselyov <[email protected], [email protected]> May 23, 1991
//
// G.Forsythe, M.Malcolm, C.Moler, Computer methods for mathematical
// computations. M., Mir, 1980, p.180 of the Russian edition
//
// The function makes use of the bissection procedure combined with
// the linear or quadric inverse interpolation.
// At every step program operates on three abscissae - a, b, and c.
// b - the last and the best approximation to the root
// a - the last but one approximation
// c - the last but one or even earlier approximation than a that
// 1) |f(b)| <= |f(c)|
// 2) f(b) and f(c) have opposite signs, i.e. b and c confine
// the root
// At every step Zeroin selects one of the two new approximations, the
// former being obtained by the bissection procedure and the latter
// resulting in the interpolation (if a,b, and c are all different
// the quadric interpolation is utilized, otherwise the linear one).
// If the latter (i.e. obtained by the interpolation) point is
// reasonable (i.e. lies within the current interval [b,c] not being
// too close to the boundaries) it is accepted. The bissection result
// is used in the other case. Therefore, the range of uncertainty is
// ensured to be reduced at least by the factor 1.6
//
func (o *Brent) Solve(xa, xb float64, silent bool) (res float64, err error) {
// basic variables and function evaluation
a := xa // the last but one approximation
b := xb // the last and the best approximation to the root
c := a // the last but one or even earlier approximation than a that
fa, erra := o.Ffcn(a)
fb, errb := o.Ffcn(b)
o.NFeval = 2
if erra != nil {
return 0, chk.Err(_brent_err1, "a", xa, erra.Error())
}
if errb != nil {
return 0, chk.Err(_brent_err1, "b", xb, errb.Error())
}
fc := fa
// check input
if fa*fb >= -EPS {
return 0, chk.Err(_brent_err2, xa, xb, fa, fb)
}
// message
if !silent {
io.Pfpink("%4s%23s%23s%23s\n", "it", "x", "f(x)", "err")
io.Pfpink("%50s%23.1e\n", "", o.Tol)
}
// solve
var prev_step float64 // distance from the last but one to the last approximation
var tol_act float64 // actual tolerance
var p, q float64 // interpol. step is calculated in the form p/q (divisions are delayed)
var new_step float64 // step at this iteration
var t1, cb, t2 float64 // auxiliary variables
for o.It = 0; o.It < o.MaxIt; o.It++ {
// distance
prev_step = b - a
// swap data for b to be the best approximation
if math.Abs(fc) < math.Abs(fb) {
a = b
b = c
c = a
fa = fb
fb = fc
fc = fa
}
tol_act = 2.0*EPS*math.Abs(b) + o.Tol/2.0
new_step = (c - b) / 2.0
// converged?
if !silent {
io.Pfyel("%4d%23.15e%23.15e%23.15e\n", o.It, b, fb, math.Abs(new_step))
}
if math.Abs(new_step) <= tol_act || fb == 0.0 {
return b, nil
}
// decide if the interpolation can be tried
if math.Abs(prev_step) >= tol_act && math.Abs(fa) > math.Abs(fb) {
// if prev_step was large enough and was in true direction, interpolatiom may be tried
cb = c - b
// with two distinct points, linear interpolation must be applied
if a == c {
t1 = fb / fa
p = cb * t1
q = 1.0 - t1
// otherwise, quadric inverse interpolation is applied
} else {
q = fa / fc
//.........这里部分代码省略.........
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:101,代码来源:brent.go
示例20: Test_up01a
//.........这里部分代码省略.........
chk.Ints(tst, "equations with pl prescribed", ct_pl_eqs, []int{2, 5})
}
// initial values @ nodes
io.Pforan("initial values @ nodes\n")
for _, nod := range dom.Nodes {
z := nod.Vert.C[1]
for _, dof := range nod.Dofs {
u := dom.Sol.Y[dof.Eq]
switch dof.Key {
case "ux":
chk.Scalar(tst, io.Sf("nod %3d : ux(@ %4g)= %6g", nod.Vert.Id, z, u), 1e-17, u, 0)
case "uy":
chk.Scalar(tst, io.Sf("nod %3d : uy(@ %4g)= %6g", nod.Vert.Id, z, u), 1e-17, u, 0)
case "pl":
plC, _, _ := Global.HydroSt.Calc(z)
chk.Scalar(tst, io.Sf("nod %3d : pl(@ %4g)= %6g", nod.Vert.Id, z, u), 1e-13, u, plC)
}
}
}
// intial values @ integration points
io.Pforan("initial values @ integration points\n")
for _, ele := range dom.Elems {
e := ele.(*ElemUP)
for idx, ip := range e.P.IpsElem {
s := e.P.States[idx]
z := e.P.Shp.IpRealCoords(e.P.X, ip)[1]
chk.AnaNum(tst, io.Sf("sl(z=%11.8f)", z), 1e-17, s.A_sl, 1, chk.Verbose)
}
}
// parameters
ν := 0.2 // Poisson's coefficient
K0 := ν / (1.0 - ν) // earth pressure at rest
nf := 0.3 // porosity
sl := 1.0 // saturation
ρL := 1.0 // intrinsic (real) density of liquid
ρS_top := 2.0 // intrinsic (real) density of solids in top layer
ρS_bot := 3.0 // intrinsic (real) density of solids in bottom layer
h := 5.0 // height of each layer
g := 10.0 // gravity
// densities
nl := nf * sl // volume fraction of luqid
ns := 1.0 - nf // volume fraction of solid
ρl := nl * ρL // partial density of liquid
ρs_top := ns * ρS_top // partial density of solids in top layer
ρs_bot := ns * ρS_bot // partial density of solids in bottom layer
ρ_top := ρl + ρs_top // density of mixture in top layer
ρ_bot := ρl + ρs_bot // density of mixture in bottom layer
// absolute values of stresses
σV_z5 := ρ_top * g * h // total vertical stress @ elevation z = 5 m (absolute value)
σV_z0 := σV_z5 + ρ_bot*g*h // total vertical stress @ elevation z = 0 m (absolute value)
io.Pfyel("ρ_top = %g\n", ρ_top)
io.Pfyel("ρ_bot = %g\n", ρ_bot)
io.Pfyel("|ΔσV_top| = %g\n", ρ_top*g*h)
io.Pfyel("|ΔσV_bot| = %g\n", ρ_bot*g*h)
io.PfYel("|σV|(@ z=0) = %g\n", σV_z0)
io.PfYel("|σV|(@ z=5) = %g\n", σV_z5)
// stress functions
var sig fun.Pts
var pres fun.Pts
sig.Init(fun.Prms{
&fun.Prm{N: "t0", V: 0.00}, {N: "y0", V: -σV_z0},
&fun.Prm{N: "t1", V: 5.00}, {N: "y1", V: -σV_z5},
&fun.Prm{N: "t2", V: 10.00}, {N: "y2", V: 0.0},
})
pres.Init(fun.Prms{
&fun.Prm{N: "t0", V: 0.00}, {N: "y0", V: 100},
&fun.Prm{N: "t1", V: 10.00}, {N: "y1", V: 0},
})
// check stresses
io.Pforan("initial stresses @ integration points\n")
for _, ele := range dom.Elems {
e := ele.(*ElemUP)
for idx, ip := range e.U.IpsElem {
z := e.U.Shp.IpRealCoords(e.U.X, ip)[1]
σe := e.U.States[idx].Sig
sv := sig.F(z, nil)
sve := sv + pres.F(z, nil)
she := sve * K0
if math.Abs(σe[2]-σe[0]) > 1e-17 {
tst.Errorf("[1;31mσx is not equal to σz: %g != %g[0m\n", σe[2], σe[0])
return
}
if math.Abs(σe[3]) > 1e-17 {
tst.Errorf("[1;31mσxy is not equal to zero: %g != 0[0m\n", σe[3])
return
}
chk.AnaNum(tst, io.Sf("sx(z=%11.8f)", z), 0.0003792, σe[0], she, chk.Verbose)
chk.AnaNum(tst, io.Sf("sy(z=%11.8f)", z), 0.001517, σe[1], sve, chk.Verbose)
}
}
return
}
开发者ID:PatrickSchm,项目名称:gofem,代码行数:101,代码来源:t_up_test.go
注:本文中的github.com/cpmech/gosl/io.Pfyel函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论