本文整理汇总了Golang中github.com/cpmech/gosl/io.Pfcyan函数的典型用法代码示例。如果您正苦于以下问题:Golang Pfcyan函数的具体用法?Golang Pfcyan怎么用?Golang Pfcyan使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Pfcyan函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: run_rootsol_test
// run_rootsol_test runs root solution test
// Note: xguess is the trial solution for Newton's method (not Brent's)
func run_rootsol_test(tst *testing.T, xa, xb, xguess, tolcmp float64, ffcnA Cb_yxe, ffcnB Cb_f, JfcnB Cb_Jd, fname string, save, show bool) (xbrent float64) {
// Brent
io.Pfcyan("\n - - - - - - - using Brent's method - - -- - - - \n")
var o Brent
o.Init(ffcnA)
var err error
xbrent, err = o.Solve(xa, xb, false)
if err != nil {
chk.Panic("%v", err)
}
var ybrent float64
ybrent, err = ffcnA(xbrent)
if err != nil {
chk.Panic("%v", err)
}
io.Pforan("x = %v\n", xbrent)
io.Pforan("f(x) = %v\n", ybrent)
io.Pforan("nfeval = %v\n", o.NFeval)
io.Pforan("nit = %v\n", o.It)
if math.Abs(ybrent) > 1e-10 {
chk.Panic("Brent failed: f(x) = %g > 1e-10\n", ybrent)
}
// Newton
io.Pfcyan("\n - - - - - - - using Newton's method - - -- - - - \n")
var p NlSolver
p.Init(1, ffcnB, nil, JfcnB, true, false, nil)
xnewt := []float64{xguess}
var cnd float64
cnd, err = p.CheckJ(xnewt, 1e-6, true, !chk.Verbose)
io.Pforan("cond(J) = %v\n", cnd)
if err != nil {
chk.Panic("%v", err.Error())
}
err = p.Solve(xnewt, false)
if err != nil {
chk.Panic("%v", err.Error())
}
var ynewt float64
ynewt, err = ffcnA(xnewt[0])
if err != nil {
chk.Panic("%v", err)
}
io.Pforan("x = %v\n", xnewt[0])
io.Pforan("f(x) = %v\n", ynewt)
io.Pforan("nfeval = %v\n", p.NFeval)
io.Pforan("nJeval = %v\n", p.NJeval)
io.Pforan("nit = %v\n", p.It)
if math.Abs(ynewt) > 1e-9 {
chk.Panic("Newton failed: f(x) = %g > 1e-10\n", ynewt)
}
// compare Brent's and Newton's solutions
PlotYxe(ffcnA, "results", fname, xbrent, xa, xb, 101, "Brent", "'b-'", save, show, func() {
plt.PlotOne(xnewt[0], ynewt, "'g+', ms=15, label='Newton'")
})
chk.Scalar(tst, "xbrent - xnewt", tolcmp, xbrent, xnewt[0])
return
}
示例2: Test_intordmut01
func Test_intordmut01(tst *testing.T) {
//verbose()
chk.PrintTitle("intordmut01")
var ops OpsData
ops.SetDefault()
ops.Pm = 1
rnd.Init(0)
a := []int{1, 2, 3, 4, 5, 6, 7, 8}
io.Pforan("before: a = %v\n", a)
ops.OrdSti = []int{2, 5, 4}
IntOrdMutation(a, 0, &ops)
io.Pfcyan("after: a = %v\n", a)
chk.Ints(tst, "a", a, []int{1, 2, 6, 7, 3, 4, 5, 8})
nums := utl.IntRange2(1, 9)
sort.Ints(a)
chk.Ints(tst, "asorted = 12345678", a, nums)
a = []int{1, 2, 3, 4, 5, 6, 7, 8}
io.Pforan("\nbefore: a = %v\n", a)
ops.OrdSti = nil
IntOrdMutation(a, 0, &ops)
io.Pfcyan("after: a = %v\n", a)
sort.Ints(a)
chk.Ints(tst, "asorted = 12345678", a, nums)
}
示例3: PlotNurbsBasis
// PlotNurbsBasis plots basis functions la and lb
func PlotNurbsBasis(dirout, fn string, b *Nurbs, la, lb int) {
npts := 41
plt.Reset()
if io.FnExt(fn) == ".eps" {
plt.SetForEps(1.5, 500)
} else {
plt.SetForPng(1.5, 600, 150)
}
plt.Subplot(3, 2, 1)
b.DrawCtrl2d(false, "", "")
b.DrawElems2d(npts, false, "", "")
t0 := time.Now()
b.PlotBasis(la, "", 11, 0) // 0 => CalcBasis
io.Pfcyan("time elapsed (calcbasis) = %v\n", time.Now().Sub(t0))
plt.Equal()
plt.Subplot(3, 2, 2)
b.DrawCtrl2d(false, "", "")
b.DrawElems2d(npts, false, "", "")
b.PlotBasis(lb, "", 11, 0) // 0 => CalcBasis
plt.Equal()
plt.Subplot(3, 2, 3)
b.DrawCtrl2d(false, "", "")
b.DrawElems2d(npts, false, "", "")
b.PlotBasis(la, "", 11, 1) // 1 => CalcBasisAndDerivs
plt.Equal()
plt.Subplot(3, 2, 4)
b.DrawCtrl2d(false, "", "")
b.DrawElems2d(npts, false, "", "")
b.PlotBasis(lb, "", 11, 1) // 1 => CalcBasisAndDerivs
plt.Equal()
plt.Subplot(3, 2, 5)
b.DrawCtrl2d(false, "", "")
b.DrawElems2d(npts, false, "", "")
t0 = time.Now()
b.PlotBasis(la, "", 11, 2) // 2 => RecursiveBasis
io.Pfcyan("time elapsed (recursive) = %v\n", time.Now().Sub(t0))
plt.Equal()
plt.Subplot(3, 2, 6)
b.DrawCtrl2d(false, "", "")
b.DrawElems2d(npts, false, "", "")
b.PlotBasis(lb, "", 11, 2) // 2 => RecursiveBasis
plt.Equal()
plt.SaveD(dirout, fn)
}
示例4: Test_cubiceq02
func Test_cubiceq02(tst *testing.T) {
//verbose()
chk.PrintTitle("cubiceq02. y(x) = x³ + x²")
a, b, c := 1.0, 0.0, 0.0
x1, x2, x3, nx := EqCubicSolveReal(a, b, c)
io.Pforan("\na=%v b=%v c=%v\n", a, b, c)
io.Pfcyan("nx=%v\n", nx)
io.Pfcyan("x1=%v x2=%v x3=%v\n", x1, x2, x3)
chk.IntAssert(nx, 2)
chk.Scalar(tst, "x1", 1e-17, x1, -1)
chk.Scalar(tst, "x2", 1e-17, x2, 0)
}
示例5: Test_cxdeb01
func Test_cxdeb01(tst *testing.T) {
//verbose()
chk.PrintTitle("cxdeb01. Deb's crossover")
var ops OpsData
ops.SetDefault()
ops.Pc = 1.0
ops.Xrange = [][]float64{{-3, 3}, {-4, 4}}
ops.EnfRange = true
rnd.Init(0)
A := []float64{-1, 1}
B := []float64{1, 2}
a := make([]float64, len(A))
b := make([]float64, len(A))
FltCrossoverDeb(a, b, A, B, 0, &ops)
io.Pforan("A = %v\n", A)
io.Pforan("B = %v\n", B)
io.Pfcyan("a = %.6f\n", a)
io.Pfcyan("b = %.6f\n", b)
nsamples := 1000
a0s, a1s := make([]float64, nsamples), make([]float64, nsamples)
b0s, b1s := make([]float64, nsamples), make([]float64, nsamples)
for i := 0; i < nsamples; i++ {
FltCrossoverDeb(a, b, B, A, 0, &ops)
a0s[i], a1s[i] = a[0], a[1]
b0s[i], b1s[i] = b[0], b[1]
}
ha0 := rnd.Histogram{Stations: []float64{-4, -3.5, -3, -2.5, -2, -1.5, -1, -0.5, 0, 0.5, 1}}
hb0 := rnd.Histogram{Stations: []float64{0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 5, 5.5, 6}}
ha1 := rnd.Histogram{Stations: utl.LinSpace(-4, 4, 11)}
hb1 := rnd.Histogram{Stations: utl.LinSpace(-4, 4, 11)}
ha0.Count(a0s, true)
hb0.Count(b0s, true)
ha1.Count(a1s, true)
hb1.Count(b1s, true)
io.Pforan("\na0s\n")
io.Pf("%s", rnd.TextHist(ha0.GenLabels("%.1f"), ha0.Counts, 60))
io.Pforan("b0s\n")
io.Pf("%s", rnd.TextHist(hb0.GenLabels("%.1f"), hb0.Counts, 60))
io.Pforan("\na1s\n")
io.Pf("%s", rnd.TextHist(ha1.GenLabels("%.1f"), ha1.Counts, 60))
io.Pforan("b1s\n")
io.Pf("%s", rnd.TextHist(hb1.GenLabels("%.1f"), hb1.Counts, 60))
}
示例6: Test_cubiceq01
func Test_cubiceq01(tst *testing.T) {
//verbose()
chk.PrintTitle("cubiceq01. y(x) = x³ - 3x² - 144x + 432")
a, b, c := -3.0, -144.0, 432.0
x1, x2, x3, nx := EqCubicSolveReal(a, b, c)
io.Pforan("\na=%v b=%v c=%v\n", a, b, c)
io.Pfcyan("nx=%v\n", nx)
io.Pfcyan("x1=%v x2=%v x3=%v\n", x1, x2, x3)
chk.IntAssert(nx, 3)
chk.Scalar(tst, "x1", 1e-17, x1, -12)
chk.Scalar(tst, "x2", 1e-17, x2, 12)
chk.Scalar(tst, "x3", 1e-14, x3, 3)
}
示例7: Clean
// Clean deletes temporary data structures
func (o *LinSolMumps) Clean() {
// exit if not initialised
if !o.is_initialised {
return
}
// start time
if o.ton {
o.tini = time.Now()
}
// message
if o.verb {
io.Pfgreen("\n . . . . . . . . . . . . . . LinSolMumps.Clean . . . . . . . . . . . . . . . \n\n")
}
// clean up
if o.cmplx {
o.mz.job = -2 // finalize code
C.zmumps_c(&o.mz) // do finalize
} else {
o.m.job = -2 // finalize code
C.dmumps_c(&o.m) // do finalize
}
// duration
if o.ton {
io.Pfcyan("%s: Time spent in LinSolMumps.Clean = %v\n", o.name, time.Now().Sub(o.tini))
}
}
示例8: SolveC
// SolveC solves the linear Complex system A.x = b
// NOTES:
// 1) sum_b_to_root is a flag for MUMPS; it tells Solve to sum the values in 'b' arrays to the root processor
func (o *LinSolMumps) SolveC(xR, xC, bR, bC []float64, sum_b_to_root bool) (err error) {
// check
if !o.cmplx {
return chk.Err(_linsol_mumps_err11)
}
// start time
if o.ton {
o.tini = time.Now()
}
// message
if o.verb {
io.Pfgreen("\n . . . . . . . . . . . . . . LinSolMumps.SolveC . . . . . . . . . . . . . . . \n\n")
}
// MUMPS: set RHS in processor # 0
if sum_b_to_root {
mpi.SumToRoot(xR, bR)
mpi.SumToRoot(xC, bC)
// join complex values
if mpi.Rank() == 0 {
for i := 0; i < len(xR); i++ {
o.xRC[i*2], o.xRC[i*2+1] = xR[i], xC[i]
}
}
} else {
// join complex values
if mpi.Rank() == 0 {
for i := 0; i < len(xR); i++ {
o.xRC[i*2], o.xRC[i*2+1] = bR[i], bC[i]
}
}
}
// MUMPS: solve
o.mz.job = 3 // solution code
C.zmumps_c(&o.mz) // solve
if o.mz.info[1-1] < 0 {
return chk.Err(_linsol_mumps_err12, mumps_error(o.mz.info[1-1], o.mz.info[2-1]))
}
// MUMPS: split complex values
if mpi.Rank() == 0 {
for i := 0; i < len(xR); i++ {
xR[i], xC[i] = o.xRC[i*2], o.xRC[i*2+1]
}
}
// MUMPS: broadcast from root
mpi.BcastFromRoot(xR)
mpi.BcastFromRoot(xC)
// duration
if o.ton {
io.Pfcyan("%s: Time spent in LinSolMumps.Solve = %v\n", o.name, time.Now().Sub(o.tini))
}
return
}
示例9: 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))
}
示例10: Clean
// Clean deletes temporary data structures
func (o *LinSolUmfpack) Clean() {
// start time
if o.ton {
o.tini = time.Now()
}
// message
if o.verb {
io.Pfgreen("\n . . . . . . . . . . . . . . LinSolUmfpack.Clean . . . . . . . . . . . . . . . \n\n")
}
// clean up
if o.cmplx {
C.umfpack_zl_free_symbolic(&o.usymb)
C.umfpack_zl_free_numeric(&o.unum)
} else {
C.umfpack_dl_free_symbolic(&o.usymb)
C.umfpack_dl_free_numeric(&o.unum)
}
// duration
if o.ton {
io.Pfcyan("%s: Time spent in LinSolUmfpack.Clean = %v\n", o.name, time.Now().Sub(o.tini))
}
}
示例11: Test_groups01
func Test_groups01(tst *testing.T) {
//verbose()
chk.PrintTitle("groups01")
Init(0)
ng := 3 // number of groups
nints := 12 // number of integers
size := nints / ng // groups size
ints := utl.IntRange(nints)
groups := utl.IntsAlloc(ng, size)
hists := make([]*IntHistogram, ng)
for i := 0; i < ng; i++ {
hists[i] = &IntHistogram{Stations: utl.IntRange(nints + 1)}
}
IntGetGroups(groups, ints)
io.Pfcyan("groups = %v\n", groups)
for i := 0; i < NSAMPLES; i++ {
IntGetGroups(groups, ints)
for j := 0; j < ng; j++ {
check_repeated(groups[j])
hists[j].Count(groups[j], false)
}
}
for i := 0; i < ng; i++ {
io.Pf("\n")
io.Pf(TextHist(hists[i].GenLabels("%d"), hists[i].Counts, 60))
}
}
示例12: SolveC
// SolveC solves the linear Complex system A.x = b
func (o *LinSolUmfpack) SolveC(xR, xC, bR, bC []float64, dummy bool) (err error) {
// check
if !o.cmplx {
return chk.Err(_linsol_umfpack_err12)
}
// start time
if o.ton {
o.tini = time.Now()
}
// message
if o.verb {
io.Pfgreen("\n . . . . . . . . . . . . . . LinSolUmfpack.SolveC . . . . . . . . . . . . . . . \n\n")
}
// UMFPACK: pointers
pxR := (*C.double)(unsafe.Pointer(&xR[0]))
pxC := (*C.double)(unsafe.Pointer(&xC[0]))
pbR := (*C.double)(unsafe.Pointer(&bR[0]))
pbC := (*C.double)(unsafe.Pointer(&bC[0]))
// UMFPACK: solve
st := C.umfpack_zl_solve(C.UMFPACK_A, o.ap, o.ai, o.ax, o.az, pxR, pxC, pbR, pbC, o.unum, o.uctrl, nil)
if st != C.UMFPACK_OK {
chk.Err(_linsol_umfpack_err13, Uerr2Text[int(st)])
}
// duration
if o.ton {
io.Pfcyan("%s: Time spent in LinSolUmfpack.Solve = %v\n", o.name, time.Now().Sub(o.tini))
}
return
}
示例13: Test_beam01b
func Test_beam01b(tst *testing.T) {
//verbose()
chk.PrintTitle("beam01b. simply supported")
// start simulation
analysis := NewFEM("data/beam01.sim", "", true, true, false, false, chk.Verbose, 0)
// run simulation
err := analysis.Run()
if err != nil {
tst.Errorf("Run failed:\n%v", err)
return
}
// check
dom := analysis.Domains[0]
ele := dom.Elems[0].(*Beam)
_, M := ele.CalcVandM(dom.Sol, 0.5, 1)
qn, L := 15.0, 1.0
Mcentre := qn * L * L / 8.0
io.Pforan("M = %v (%v)\n", M, Mcentre)
chk.Scalar(tst, "M @ centre", 1e-17, M[0], Mcentre)
// check moment using OutIpsData
idx_centre := 5 // considering 11 stations
dat := ele.OutIpsData()
res := dat[idx_centre].Calc(dom.Sol)
io.Pfcyan("M @ centre (OutIpsData) = %v\n", res["M"])
chk.Scalar(tst, "M @ centre (OutIpsData)", 1e-17, res["M"], Mcentre)
}
示例14: PlotNurbsDerivs
// PlotNurbsDerivs plots derivatives of basis functions la and lb
func PlotNurbsDerivs(dirout, fn string, b *Nurbs, la, lb int) {
npts := 41
plt.Reset()
if io.FnExt(fn) == ".eps" {
plt.SetForEps(1.5, 500)
} else {
plt.SetForPng(1.5, 600, 150)
}
plt.Subplot(4, 2, 1)
t0 := time.Now()
b.PlotDeriv(la, 0, "", npts, 0) // 0 => CalcBasisAndDerivs
io.Pfcyan("time elapsed (calcbasis) = %v\n", time.Now().Sub(t0))
plt.Equal()
plt.Subplot(4, 2, 2)
t0 = time.Now()
b.PlotDeriv(la, 0, "", npts, 1) // 1 => NumericalDeriv
io.Pfcyan("time elapsed (numerical) = %v\n", time.Now().Sub(t0))
plt.Equal()
plt.Subplot(4, 2, 3)
b.PlotDeriv(la, 1, "", npts, 0) // 0 => CalcBasisAndDerivs
plt.Equal()
plt.Subplot(4, 2, 4)
b.PlotDeriv(la, 1, "", npts, 1) // 0 => NumericalDeriv
plt.Equal()
plt.Subplot(4, 2, 5)
b.PlotDeriv(lb, 0, "", npts, 0) // 0 => CalcBasisAndDerivs
plt.Equal()
plt.Subplot(4, 2, 6)
b.PlotDeriv(lb, 0, "", npts, 1) // 0 => NumericalDeriv
plt.Equal()
plt.Subplot(4, 2, 7)
b.PlotDeriv(lb, 1, "", npts, 0) // 0 => CalcBasisAndDerivs
plt.Equal()
plt.Subplot(4, 2, 8)
b.PlotDeriv(lb, 1, "", npts, 1) // 0 => NumericalDeriv
plt.Equal()
plt.SaveD(dirout, fn)
}
示例15: Test_porous01
func Test_porous01(tst *testing.T) {
chk.PrintTitle("porous01")
mdb := ReadMat("data", "porous.mat")
if mdb == nil {
tst.Errorf("test failed\n")
return
}
io.Pf("porous.mat just read:\n%v\n", mdb)
mat := mdb.Get("porous1")
if mat == nil {
tst.Errorf("test failed\n")
return
}
io.Pforan("mat = %+v\n", mat)
cnd := mdb.GroupGet("porous1", "c")
if mat == nil {
tst.Errorf("test failed\n")
return
}
io.Pfcyan("cnd = %+v\n", cnd)
lrm := mdb.GroupGet("porous1", "l")
if mat == nil {
tst.Errorf("test failed\n")
return
}
io.Pforan("lrm = %+v\n", lrm)
por := mdb.GroupGet("porous1", "p")
if mat == nil {
tst.Errorf("test failed\n")
return
}
io.Pfcyan("por = %+v\n", por)
sld := mdb.GroupGet("porous1", "s")
if mat == nil {
tst.Errorf("test failed\n")
return
}
io.Pforan("sld = %+v\n", sld)
}