本文整理汇总了Golang中github.com/cpmech/gosl/io.PfRed函数的典型用法代码示例。如果您正苦于以下问题:Golang PfRed函数的具体用法?Golang PfRed怎么用?Golang PfRed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PfRed函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
// catch errors
var tst testing.T
defer func() {
if mpi.Rank() == 0 {
if err := recover(); err != nil {
io.PfRed("ERROR: %v\n", err)
}
if tst.Failed() {
io.PfRed("test failed\n")
}
}
mpi.Stop(false)
}()
mpi.Start(false)
// start global variables and log
analysis := fem.NewFEM("data/bh16.sim", "", true, true, false, true, true, 0)
// run simulation
err := analysis.Run()
if err != nil {
tst.Error("Run failed\n")
return
}
// check
skipK := true
tolK := 1e-12
tolu := 1e-15
tols := 1e-12
fem.TestingCompareResultsU(&tst, "data/bh16.sim", "cmp/bh16.cmp", "", tolK, tolu, tols, skipK, true)
}
示例2: main
func main() {
// catch errors
var tst testing.T
defer func() {
if mpi.Rank() == 0 {
if err := recover(); err != nil {
io.PfRed("ERROR: %v\n", err)
}
if tst.Failed() {
io.PfRed("test failed\n")
}
}
mpi.Stop(false)
}()
mpi.Start(false)
// start global variables and log
analysis := fem.NewFEM("data/p01.sim", "", true, true, false, true, true, 0)
// run simulation
err := analysis.Run()
if err != nil {
tst.Error("Run failed\n")
return
}
}
示例3: check
func check(problem int, tolf, tolg float64) {
io.Pf("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> problem %d <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n", problem)
opt := getfcn(problem)
x := opt.RptXref
f := make([]float64, opt.Nf)
g := make([]float64, opt.Ng)
h := make([]float64, opt.Nh)
opt.MinProb(f, g, h, x, nil, 0)
err := math.Abs(f[0] - opt.RptFref[0])
io.Pforan("nx=%d nf=%d ng=%d nh=%d\n", opt.Nflt, opt.Nf, opt.Ng, opt.Nh)
io.Pforan("x = %v\n", x)
io.Pforan("f = %v err = %v\n", f, err)
io.Pforan("g = %v\n", g)
io.Pforan("h = %v\n", h)
for i := 0; i < opt.Ng; i++ {
if g[i] < 0 {
io.PfRed("unfeasible on g\n")
}
}
for i := 0; i < opt.Nh; i++ {
if math.Abs(h[i]) > opt.EpsH {
io.PfRed("unfeasible on h\n")
}
}
if err > tolf {
io.PfRed("err is too big\n")
}
}
示例4: main
func main() {
// catch errors
var tst testing.T
defer func() {
if mpi.Rank() == 0 {
if err := recover(); err != nil {
io.PfRed("ERROR: %v\n", err)
}
if tst.Failed() {
io.PfRed("test failed\n")
}
}
mpi.Stop(false)
}()
mpi.Start(false)
// start global variables and log
if !fem.Start("data/p01.sim", true, true) {
tst.Error("Start failed\n")
return
}
// make sure to flush log
defer fem.End()
// run simulation
if !fem.Run() {
tst.Error("Run failed\n")
return
}
}
示例5: main
func main() {
// filename
filename, fnkey := io.ArgToFilename(0, "sg111", ".sim", true)
// fem
if !fem.Start(filename, false, false, false) {
io.PfRed("Start failed\n")
return
}
dom, sum, ok := fem.AllocSetAndInit(0, true, true)
if !ok {
io.PfRed("AllocSetAndInit failed\n")
return
}
// selected node and dof index
nidx := 1
didx := 1
// gofem
ntout := len(sum.OutTimes)
uy := make([]float64, ntout)
for tidx, _ := range sum.OutTimes {
// read results from file
if !dom.In(sum, tidx, true) {
io.PfRed("plot_spo751: cannot read solution\n")
return
}
// collect results for load versus time plot
nod := dom.Nodes[nidx]
eq := nod.Dofs[didx].Eq
uy[tidx] = dom.Sol.Y[eq]
// check
if math.Abs(dom.Sol.T-sum.OutTimes[tidx]) > 1e-14 {
io.PfRed("output times do not match time in solution array\n")
return
}
}
// plot fem results
plt.SetForPng(0.8, 400, 200)
plt.Plot(sum.OutTimes, uy, "'ro-', clip_on=0, label='gofem'")
// analytical solution
tAna := utl.LinSpace(0, 5, 101)
uyAna := make([]float64, len(tAna))
for i, t := range tAna {
uyAna[i] = solution_uy(t, 1.0)
}
plt.Plot(tAna, uyAna, "'g-', clip_on=0, label='analytical'")
// save
plt.Gll("$t$", "$u_y$", "")
plt.SaveD("/tmp", fnkey+".png")
}
示例6: main
func main() {
// filename
filename, fnkey := io.ArgToFilename(0, "rjoint01", ".sim", true)
// fem
if !fem.Start(filename, false, false, false) {
io.PfRed("Start failed\n")
return
}
dom, sum, ok := fem.AllocSetAndInit(0, true, true)
if !ok {
io.PfRed("AllocSetAndInit failed\n")
return
}
// rjoint element
eid := 2
ele := dom.Elems[eid].(*fem.Rjoint)
ipd := ele.OutIpsData()
// load results from file
n := len(sum.OutTimes)
mtau0 := make([]float64, n)
mtau1 := make([]float64, n)
mtau2 := make([]float64, n)
ompb0 := make([]float64, n)
ompb1 := make([]float64, n)
ompb2 := make([]float64, n)
for i, _ := range sum.OutTimes {
if !dom.In(sum, i, true) {
io.PfRed("cannot read solution\n")
return
}
res0 := ipd[0].Calc(dom.Sol)
res1 := ipd[1].Calc(dom.Sol)
res2 := ipd[2].Calc(dom.Sol)
mtau0[i] = -res0["tau"]
mtau1[i] = -res1["tau"]
mtau2[i] = -res2["tau"]
ompb0[i] = res0["ompb"]
ompb1[i] = res1["ompb"]
ompb2[i] = res2["ompb"]
}
// plot
plt.SetForPng(0.8, 400, 200)
plt.Plot(ompb0, mtau0, "'r-', marker='.', label='p0', clip_on=0")
plt.Plot(ompb1, mtau1, "'g-', marker='.', label='p1', clip_on=0")
plt.Plot(ompb2, mtau2, "'b-', marker='.', label='p2', clip_on=0")
plt.Gll("$\\bar{\\omega}_p$", "$-\\tau$", "")
plt.SaveD("/tmp", fnkey+".png")
}
示例7: CheckFront0
// CheckFront0 returns front0 and number of failed/success
func CheckFront0(opt *Optimiser, verbose bool) (nfailed int, front0 []*Solution) {
front0 = make([]*Solution, 0)
var nsuccess int
for _, sol := range opt.Solutions {
var failed bool
for _, oor := range sol.Oor {
if oor > 0 {
failed = true
break
}
}
if failed {
nfailed++
} else {
nsuccess++
if sol.FrontId == 0 {
front0 = append(front0, sol)
}
}
}
if verbose {
if nfailed > 0 {
io.PfRed("N failed = %d out of %d\n", nfailed, opt.Nsol)
} else {
io.PfGreen("N success = %d out of %d\n", nsuccess, opt.Nsol)
}
io.PfYel("N front 0 = %d\n", len(front0))
}
return
}
示例8: End
// End must be called at the end to flush log file
func End() {
if err := recover(); err != nil {
io.PfRed("ERROR: %v\n", err)
} else {
fem.End()
}
}
示例9: main
func main() {
// dimensions
lx, ly := 10.0, 3.0
// define structured mesh data
var gd gemlab.InData
gd.Nparts = 4
gd.Sregs = &gemlab.Sregs{
Tags: []int{-1},
Nxs: []int{10},
Nys: []int{3},
Nzs: []int{3},
Points: [][]float64{
{0, 0}, {lx, 0}, {lx, ly}, {0, ly},
},
Conn: [][]int{{0, 1, 2, 3}},
Btags: [][]int{{-20, -11, -21, -10}},
}
// tag vertices along line (middle vertical line)
gd.VtagsL = &gemlab.VtagsL{
Tags: []int{-1},
Xxa: [][]float64{{lx / 2.0, 0}},
Xxb: [][]float64{{lx / 2.0, ly}},
}
fnk := "d2-coarse"
if err := gemlab.Generate(fnk, &gd); err != nil {
io.PfRed("%v\n", err.Error())
}
}
示例10: main
func main() {
// dimensions
lx, ly, lz := 10.0, 3.0, 3.0
// define structured mesh data
var gd gemlab.InData
gd.Nparts = 4
gd.Sregs = &gemlab.Sregs{
Tags: []int{-1},
Nxs: []int{10},
Nys: []int{3},
Nzs: []int{3},
Points: [][]float64{
{0, 0, 0}, {lx, 0, 0}, {lx, ly, 0}, {0, ly, 0},
{0, 0, lz}, {lx, 0, lz}, {lx, ly, lz}, {0, ly, lz},
},
Conn: [][]int{{0, 1, 2, 3, 4, 5, 6, 7}},
Btags: [][]int{{-10, -11, -20, -21, -30, -31}},
}
fnk := "d3-coarse"
if err := gemlab.Generate(fnk, &gd); err != nil {
io.PfRed("%v\n", err.Error())
}
}
示例11: Test_cxint01
func Test_cxint01(tst *testing.T) {
//verbose()
chk.PrintTitle("cxint01")
var ops OpsData
ops.SetDefault()
ops.Pc = 1
ops.Ncuts = 1
A := []int{1, 2}
B := []int{-1, -2}
a := make([]int, len(A))
b := make([]int, len(A))
IntCrossover(a, b, A, B, 0, &ops)
io.Pfred("A = %2d\n", A)
io.PfRed("B = %2d\n", B)
io.Pfcyan("a = %2d\n", a)
io.Pfblue2("b = %2d\n", b)
chk.Ints(tst, "a", a, []int{1, -2})
chk.Ints(tst, "b", b, []int{-1, 2})
io.Pf("\n")
A = []int{1, 2, 3, 4, 5, 6, 7, 8}
B = []int{-1, -2, -3, -4, -5, -6, -7, -8}
a = make([]int, len(A))
b = make([]int, len(A))
ops.Cuts = []int{1, 3}
IntCrossover(a, b, A, B, 0, &ops)
io.Pfred("A = %2v\n", A)
io.PfRed("B = %2v\n", B)
io.Pfcyan("a = %2v\n", a)
io.Pfblue2("b = %2v\n", b)
chk.Ints(tst, "a", a, []int{1, -2, -3, 4, 5, 6, 7, 8})
chk.Ints(tst, "b", b, []int{-1, 2, 3, -4, -5, -6, -7, -8})
ops.Cuts = []int{5, 7}
IntCrossover(a, b, A, B, 0, &ops)
io.Pfred("A = %2v\n", A)
io.PfRed("B = %2v\n", B)
io.Pfcyan("a = %2v\n", a)
io.Pfblue2("b = %2v\n", b)
chk.Ints(tst, "a", a, []int{1, 2, 3, 4, 5, -6, -7, 8})
chk.Ints(tst, "b", b, []int{-1, -2, -3, -4, -5, 6, 7, -8})
}
示例12: main
func main() {
// catch errors
defer func() {
if err := recover(); err != nil {
if mpi.Rank() == 0 {
chk.Verbose = true
for i := 8; i > 3; i-- {
chk.CallerInfo(i)
}
io.PfRed("ERROR: %v\n", err)
}
}
mpi.Stop(false)
}()
mpi.Start(false)
// default input parameters
// read input parameters
fnamepath, _ := io.ArgToFilename(0, "", ".sim", true)
verbose := io.ArgToBool(1, true)
erasePrev := io.ArgToBool(2, true)
saveSummary := io.ArgToBool(3, true)
allowParallel := io.ArgToBool(4, true)
alias := io.ArgToString(5, "")
// message
if mpi.Rank() == 0 && verbose {
io.PfWhite("\nGofem v3 -- Go Finite Element Method\n\n")
io.Pf("Copyright 2015 Dorival Pedroso and Raul Durand. All rights reserved.\n")
io.Pf("Use of this source code is governed by a BSD-style\n")
io.Pf("license that can be found in the LICENSE file.\n\n")
io.Pf("\n%v\n", io.ArgsTable(
"filename path", "fnamepath", fnamepath,
"show messages", "verbose", verbose,
"erase previous results", "erasePrev", erasePrev,
"save summary", "saveSummary", saveSummary,
"allow parallel run", "allowParallel", allowParallel,
"word to add to results", "alias", alias,
))
}
// profiling?
defer utl.DoProf(false)()
// analysis data
readSummary := false
analysis := fem.NewFEM(fnamepath, alias, erasePrev, saveSummary, readSummary, allowParallel, verbose, 0)
// run simulation
err := analysis.Run()
if err != nil {
chk.Panic("Run failed:\n%v", err)
}
}
示例13: 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)
}
}
示例14: main
func main() {
// catch errors
defer func() {
if err := recover(); err != nil {
io.PfRed("ERROR: %v\n", err)
}
}()
// input data
var mshfn string
mshfn, fnkey = io.ArgToFilename(0, "data/d2-coarse", ".msh", true)
io.Pf("\n%s\n", io.ArgsTable(
"mesh filename", "mshfn", mshfn,
))
// read mesh
msh, err := inp.ReadMsh("", mshfn, 0)
if err != nil {
io.PfRed("cannot read mesh:\n%v", err)
return
}
ndim = msh.Ndim
verts = msh.Verts
cells = msh.Cells
dirout = "/tmp/gofem"
// buffers
geo := new(bytes.Buffer)
vtu := new(bytes.Buffer)
// generate topology
topology(geo)
// points data
pdata_write(vtu)
// cells data
cdata_write(vtu)
// write vtu file
vtu_write(geo, vtu)
}
示例15: main
func main() {
// filename
filename, fnkey := io.ArgToFilename(0, "sg1121", ".sim", true)
// results
out.Start(filename, 0, 0)
out.Define("A", out.N{30})
out.LoadResults(nil)
// plot FEM results
out.Plot("t", "uy", "A", plt.Fmt{C: "k", Ls: "-", L: "gofem"}, -1)
// old results
b, err := io.ReadFile("cmp/sg1121gofemold.json")
if err != nil {
io.PfRed("cannot read comparison file\n")
return
}
var gofemold struct {
Time, Uy30 []float64
}
err = json.Unmarshal(b, &gofemold)
if err != nil {
io.PfRed("cannot unmarshal comparison file\n")
return
}
// mechsys results
_, res, err := io.ReadTable("cmp/sg1121mechsysN30.cmp")
if err != nil {
io.PfRed("cannot read mechsys comparison file\n")
return
}
// save
plt.SetForPng(0.8, 400, 200)
out.Draw("/tmp", fnkey+".png", false, func(i, j, n int) {
plt.Plot(gofemold.Time, gofemold.Uy30, "'r-', lw=2, label='gofemOld'")
plt.Plot(res["Time"], res["uy"], "'b-', label='mechsys'")
})
}