// Calculate x - (x_1 + x_2) with Mu_h fixed. func AbsErrorX(env *tempAll.Environment, variables []string) solve.Diffable { F := func(v vec.Vector) (float64, error) { if v.ContainsNaN() { fmt.Printf("got NaN in AbsErrorX (v=%v)\n", v) return 0.0, errors.New("NaN in input") } env.Set(v, variables) // Before we evaluate error in X, Mu_b and D1 should have // appropriate values. system, start := D1Mu_bSystem(env) eps := 1e-9 _, err := solve.MultiDim(system, start, eps, eps) if err != nil { return 0.0, err } if env.Mu_b > 0.0 { fmt.Println("Warning: got Mu_b > 0 in AbsErrorX") env.Mu_b = 0.0 } // evaluate X error x1 := tempPair.X1(env) x2, err := tempCrit.X2(env) if err != nil { fmt.Printf("error from X2(): %v\n", err) return 0.0, err } lhs := env.X rhs := x1 + x2 return lhs - rhs, nil } h := 1e-5 epsabs := 1e-4 return solve.SimpleDiffable(F, len(variables), h, epsabs) }
func AbsErrorBeta(env *tempAll.Environment, variables []string) solve.Diffable { F := func(v vec.Vector) (float64, error) { if v.ContainsNaN() { fmt.Printf("got NaN in AbsErrorBeta (v=%v)\n", v) return 0.0, errors.New("NaN in input") } env.Set(v, variables) if !env.FixedPairCoeffs || !env.PairCoeffsReady { // Before we evaluate error in Beta, Mu_h and D1 should have // appropriate values. eps := 1e-9 _, err := D1MuSolve(env, eps, eps) if err != nil { return 0.0, err } } // Beta equation error = x - x1 - x2 x1 := X1(env) x2, err := tempCrit.X2(env) if err != nil { fmt.Printf("error from X2(): %v\n", err) return 0.0, err } lhs := env.X rhs := x1 + x2 return lhs - rhs, nil } h := 1e-5 epsabs := 1e-4 return solve.SimpleDiffable(F, len(variables), h, epsabs) }
// Make specific heat data func makeSHEnvs(plotEnvs []interface{}, errs []error, Xs []float64) []interface{} { SHenvs := make([]interface{}, len(plotEnvs)) F := func(i int, cerr chan<- error) { SHenvs[i] = nil pe := plotEnvs[i] if errs[i] != nil { cerr <- errs[i] return } if pe == nil { cerr <- errors.New("pe is nil") return } env, ok := pe.(tempAll.Environment) if !ok { cerr <- errors.New("conversion of plotEnvs[i] to Environment failed") return } X2, err := tempCrit.X2(&env) if err != nil { cerr <- err } SHenvs[i] = SpecificHeatEnv{env, X2, 0.0, 0.0} if X2 == 0.0 { cerr <- nil } sh_1, err := HolonSpecificHeat(&env) if err != nil { cerr <- err } fmt.Printf("sh_1 = %f\n", sh_1) sh_2, err := PairSpecificHeat(&env) if err != nil { cerr <- err } fmt.Printf("sh_2 = %f\n", sh_2) SHenvs[i] = SpecificHeatEnv{env, X2, sh_1, sh_2} cerr <- nil } SHerrs := parallel.Run(F, len(plotEnvs)) for _, err := range SHerrs { if err != nil { fmt.Println(err) } } SHenvs = fixXs(SHenvs, Xs) return SHenvs }
func TestPlotX2VsT(t *testing.T) { flag.Parse() if !(*testPlot || *longPlot) { return } var plotEnvs []interface{} var errs []error wd, _ := os.Getwd() cachePath := wd + "/__data_cache_tempLow" if *loadCache { var err error plotEnvs, errs, err = tempAll.LoadEnvCache(cachePath) if err != nil { t.Fatal(err) } } else { envs, err := lowDefaultEnvSet(*longPlot) if err != nil { t.Fatal(err) } // solve the full system eps := 1e-9 plotEnvs, errs = tempAll.MultiSolve(envs, eps, eps, D1MuBetaSolve) // cache results for future use err = tempAll.SaveEnvCache(cachePath, plotEnvs, errs) if err != nil { t.Fatal(err) } } Xs := getXs(plotEnvs) // T vs F0 plots vars := plots.GraphVars{"F0", "", []string{"Tz", "Thp", "X", "Be_field"}, []string{"t_z", "t_h^{\\prime}", "x", "eB"}, nil, tempAll.GetTemp} fileLabel := "plot_data.T_F0" grapherPath := wd + "/../plots/grapher.py" graphParams := map[string]string{plots.FILE_KEY: wd + "/" + fileLabel, plots.XLABEL_KEY: "$F_0$", plots.YLABEL_KEY: "$T$"} err := plots.MultiPlot(plotEnvs, errs, vars, graphParams, grapherPath) if err != nil { t.Fatalf("error making T(F0) plot: %v", err) } // X2 vs T plots fileLabel = "plot_data.x2_T" graphParams[plots.FILE_KEY] = wd + "/" + fileLabel graphParams[plots.XLABEL_KEY] = "$T$" graphParams[plots.YLABEL_KEY] = "$x_2$" vars.X = "" vars.XFunc = tempAll.GetTemp vars.YFunc = tempCrit.GetX2 err = plots.MultiPlot(plotEnvs, errs, vars, graphParams, grapherPath) if err != nil { t.Fatalf("error making X2(T) plot: %v", err) } // Mu_h vs T plots fileLabel = "plot_data.mu_h_T" graphParams[plots.FILE_KEY] = wd + "/" + fileLabel graphParams[plots.YLABEL_KEY] = "$\\mu_h$" vars.Y = "Mu_h" vars.YFunc = nil err = plots.MultiPlot(plotEnvs, errs, vars, graphParams, grapherPath) if err != nil { t.Fatalf("error making Mu_h(T) plot: %v", err) } // if looking for magnetization plot, make that plot and don't get Cv if *magnetization_calc { fileLabel = "plot_data.M_eB" graphParams[plots.FILE_KEY] = wd + "/" + fileLabel graphParams[plots.XLABEL_KEY] = "$eB$" graphParams[plots.YLABEL_KEY] = "$M$" vars.X = "Be_field" vars.XFunc = nil vars.Y = "" vars.YFunc = tempCrit.GetMagnetization vars.Params = []string{"Tz", "Thp", "X", "F0"} vars.ParamLabels = []string{"t_z", "t_h^{\\prime}", "x", "F_0"} err := plots.MultiPlot(plotEnvs, errs, vars, graphParams, grapherPath) if err != nil { t.Fatalf("error making M plot: %v", err) } return } // calculate specific heat contributions SHenvs := make([]interface{}, len(plotEnvs)) F := func(i int, cerr chan<- error) { pe := plotEnvs[i] if pe == nil { cerr <- errors.New("pe is nil") return } if errs[i] != nil { cerr <- errs[i] return } env, ok := pe.(tempAll.Environment) if !ok { cerr <- errors.New("pe is not Environment") } X2, err := tempCrit.X2(&env) if err != nil { cerr <- err return } SHenvs[i] = SpecificHeatEnv{env, X2, 0.0, 0.0} if X2 == 0.0 { cerr <- nil return } sh_1, err := HolonSpecificHeat(&env) if err != nil { cerr <- err return } fmt.Printf("sh_1 = %f\n", sh_1) sh_2, err := PairSpecificHeat(&env) if err != nil { cerr <- err return } fmt.Printf("sh_2 = %f\n", sh_2) SHenvs[i] = SpecificHeatEnv{env, X2, sh_1, sh_2} cerr <- nil } SHerrs := parallel.Run(F, len(plotEnvs)) for _, err := range SHerrs { if err != nil { fmt.Println(err) } } SHenvs = fixXs(SHenvs, Xs) // specific heat plots fileLabel = "plot_data.SH-1_mu_b" graphParams[plots.FILE_KEY] = wd + "/" + fileLabel graphParams[plots.YLABEL_KEY] = "$C_V^{1}$" vars.XFunc = GetSHTemp vars.Y = "SH_1" vars.YFunc = nil err = plots.MultiPlot(SHenvs, errs, vars, graphParams, grapherPath) if err != nil { t.Fatalf("error making specific heat plot: %v", err) } fileLabel = "plot_data.SH-2_mu_b" graphParams[plots.FILE_KEY] = wd + "/" + fileLabel graphParams[plots.YLABEL_KEY] = "$C_V^{2}$" vars.Y = "SH_2" err = plots.MultiPlot(SHenvs, errs, vars, graphParams, grapherPath) if err != nil { t.Fatalf("error making specific heat plot: %v", err) } SH12 := func(d interface{}) float64 { env := d.(SpecificHeatEnv) return env.SH_1 + env.SH_2 } fileLabel = "plot_data.SH-12_mu_b" graphParams[plots.FILE_KEY] = wd + "/" + fileLabel graphParams[plots.YLABEL_KEY] = "$C_V^{12}$" vars.Y = "" vars.YFunc = SH12 err = plots.MultiPlot(SHenvs, errs, vars, graphParams, grapherPath) if err != nil { t.Fatalf("error making specific heat plot: %v", err) } // C_V / T = C_V * Beta Gamma := func(d interface{}) float64 { env := d.(SpecificHeatEnv) return SH12(d) * env.Beta } fileLabel = "plot_data.gamma-12_mu_b" graphParams[plots.FILE_KEY] = wd + "/" + fileLabel graphParams[plots.YLABEL_KEY] = "$\\gamma^{12}$" vars.YFunc = Gamma err = plots.MultiPlot(SHenvs, errs, vars, graphParams, grapherPath) if err != nil { t.Fatalf("error making specific heat plot: %v", err) } Gamma1 := func(d interface{}) float64 { env := d.(SpecificHeatEnv) return env.SH_1 * env.Beta } fileLabel = "plot_data.gamma-1_mu_b" graphParams[plots.FILE_KEY] = wd + "/" + fileLabel graphParams[plots.YLABEL_KEY] = "$\\gamma^{1}$" vars.YFunc = Gamma1 err = plots.MultiPlot(SHenvs, errs, vars, graphParams, grapherPath) if err != nil { t.Fatalf("error making specific heat plot: %v", err) } Gamma2 := func(d interface{}) float64 { env := d.(SpecificHeatEnv) return env.SH_2 * env.Beta } fileLabel = "plot_data.gamma-2_mu_b" graphParams[plots.FILE_KEY] = wd + "/" + fileLabel graphParams[plots.YLABEL_KEY] = "$\\gamma^{2}$" vars.YFunc = Gamma2 err = plots.MultiPlot(SHenvs, errs, vars, graphParams, grapherPath) if err != nil { t.Fatalf("error making specific heat plot: %v", err) } }