Exemplo n.º 1
0
// Calculate Mu_b - (-Omega_+(0))
func AbsErrorMu_b(env *tempAll.Environment, variables []string) solve.Diffable {
	F := func(v vec.Vector) (float64, error) {
		if v.ContainsNaN() {
			fmt.Printf("got NaN in AbsErrorMu_b (v=%v)\n", v)
			return 0.0, errors.New("NaN in input")
		}
		env.Set(v, variables)
		zv := vec.ZeroVector(3)
		omega0, err := tempCrit.OmegaPlus(env, zv)
		if err != nil {
			return 0.0, err
		}
		lhs := env.Mu_b
		rhs := -omega0
		return lhs - rhs, nil
	}
	h := 1e-5
	epsabs := 1e-4
	return solve.SimpleDiffable(F, len(variables), h, epsabs)
}
Exemplo n.º 2
0
// Solve the (D1, Mu_h, Mu_b) system with Beta and x fixed.
func SolveD1Mu_hMu_b(env *tempAll.Environment, epsAbs, epsRel float64) (vec.Vector, error) {
	/*
		// fix pair coefficients
		if env.A == 0.0 && env.B == 0.0 && env.FixedPairCoeffs {
			D1, Mu_h, Mu_b, Beta, Be_field := env.D1, env.Mu_h, env.Mu_b, env.Beta, env.Be_field
			env.Mu_b = 0.0 // Mu_b is 0 at T_c
			env.Be_field = 0.0
			_, err := tempCrit.CritTempSolve(env, epsAbs, epsRel)
			if err != nil {
				return nil, err
			}
			omegaFit, err := tempCrit.OmegaFit(env, tempCrit.OmegaPlus)
			if err != nil {
				return nil, err
			}
			env.A, env.B = omegaFit[0], omegaFit[2]
			env.PairCoeffsReady = true
			// uncache env
			env.D1, env.Mu_h, env.Mu_b, env.Beta, env.Be_field = D1, Mu_h, Mu_b, Beta, Be_field
		}
	*/
	maxIters := 1000
	oldMu_b := env.Mu_b
	for i := 0; i < maxIters; i++ {
		// iterate D1/Mu_h
		solution, err := SolveD1Mu_h(env, epsAbs, epsRel)
		if err != nil {
			return nil, err
		}
		// iterate Mu_b
		Be_field := env.Be_field
		env.Be_field = 0.0
		zv := vec.ZeroVector(3)
		omega0, err := tempCrit.OmegaPlus(env, zv)
		//omegaFit, err := tempCrit.OmegaFit(env, tempCrit.OmegaPlus)
		if err != nil {
			return nil, err
		}
		env.Mu_b = -omega0
		env.Be_field = Be_field
		//A, Mub_eff := omegaFit[0], omegaFit[3]
		//env.Mu_b = -omega0 + 2.0 * env.Be_field * env.A
		//Mub_eff := omegaFit[3]
		//env.Mu_b = Mub_eff
		//fmt.Printf("iterating Mu_b: now %f, before %f\n", env.Mu_b, oldMu_b)
		// check if done
		if math.Abs(env.Mu_b-oldMu_b) < epsAbs || !env.IterateD1Mu_hMu_b {
			return []float64{solution[0], solution[1], env.Mu_b}, nil
		}
		oldMu_b = env.Mu_b
	}
	return []float64{0.0, 0.0, 0.0}, fmt.Errorf("failed to find D1/Mu_h/Mu_b solution for env=%s\n", env.String())
	/*
		system, start := D1Mu_hMu_bSystem(env)
		solution, err := solve.MultiDim(system, start, epsAbs, epsRel)
		if err != nil {
			return nil, err
		}
		return solution, nil
	*/
}