Esempio n. 1
0
func TestSolutionCompute(t *testing.T) {
	config, _ := config.New("fixtures/002_020.json")
	system, _ := system.New(&config.System)
	uncertainty, _ := uncertainty.NewEpistemic(system, &config.Uncertainty)

	quantity, _ := quantity.New(system, uncertainty, &config.Quantity)
	ni, no := quantity.Dimensions()

	solution, _ := New(ni, no, &config.Solution)
	surrogate := solution.Compute(quantity, quantity)

	nn := surrogate.Surrogate.Nodes

	assert.Equal(nn, uint(841), t)

	grid := grid.NewClosed(ni)
	nodes := grid.Compute(surrogate.Surrogate.Indices)

	values := make([]float64, nn*no)
	for i := uint(0); i < nn; i++ {
		quantity.Compute(nodes[i*ni:(i+1)*ni], values[i*no:(i+1)*no])
	}

	assert.EqualWithin(values, solution.Evaluate(surrogate, nodes), 1e-15, t)
}
Esempio n. 2
0
func Run(function func(*config.Config) error) {
	flag.Usage = usage
	flag.Parse()

	if len(*profileFile) > 0 {
		profile, err := os.Create(*profileFile)
		if err != nil {
			fail(errors.New("cannot enable profiling"))
		}
		pprof.StartCPUProfile(profile)
		defer pprof.StopCPUProfile()
	}

	if len(*configFile) == 0 {
		fail(errors.New("expected a filename"))
	}
	config, err := config.New(*configFile)
	if err != nil {
		fail(err)
	}
	if *verbose {
		config.Verbose = true
	}
	if !config.Verbose {
		log.SetOutput(null{})
	}

	if err = function(config); err != nil {
		fail(err)
	}
}
Esempio n. 3
0
func TestNewEpistemic(t *testing.T) {
	const (
		nt = 10
		σ  = 0.2
	)

	config, _ := config.New("fixtures/001_010.json")
	system, _ := system.New(&config.System)
	reference := system.ReferenceTime()
	uncertainty, _ := NewEpistemic(system, &config.Uncertainty)

	point := make([]float64, nt)
	value := make([]float64, nt)
	for i := 0; i < nt; i++ {
		α := float64(i) / (nt - 1)
		point[i] = α
		value[i] = (1.0 - σ + 2.0*σ*α) * reference[i]
	}

	assert.EqualWithin(uncertainty.Backward(point), value, 1e-15, t)
}
Esempio n. 4
0
func TestNew(t *testing.T) {
	config, _ := config.New("fixtures/002_020.json")

	system, _ := New(&config.System)
	assert.Equal(system.Platform.Len(), 2, t)
	assert.Equal(system.Application.Len(), 20, t)

	schedule := system.schedule
	assert.Equal(schedule.Mapping, []uint{
		0, 1, 0, 0, 1, 1, 1, 0, 0, 1,
		1, 0, 0, 0, 0, 1, 1, 1, 1, 1,
	}, t)
	assert.Equal(schedule.Order, []uint{
		0, 1, 2, 9, 12, 16, 18, 14, 17, 13,
		15, 3, 5, 11, 19, 8, 7, 6, 4, 10,
	}, t)
	assert.EqualWithin(schedule.Start, []float64{
		0.000, 0.010, 0.013, 0.187, 0.265, 0.218, 0.262, 0.260, 0.242, 0.051,
		0.267, 0.237, 0.079, 0.152, 0.113, 0.170, 0.079, 0.141, 0.113, 0.242,
	}, 1e-15, t)
	assert.EqualWithin(schedule.Span, 0.291, 1e-15, t)
}
Esempio n. 5
0
func TestNewAleatory(t *testing.T) {
	const (
		nt = 10
		σ  = 0.2
	)

	config, _ := config.New("fixtures/001_010.json")
	system, _ := system.New(&config.System)
	uncertainty, _ := NewAleatory(system, &config.Uncertainty)

	point := make([]float64, nt)
	for i := 0; i < nt; i++ {
		point[i] = 0.5
	}

	assert.EqualWithin(uncertainty.Backward(point), []float64{
		3.1402438661763954e-02, 1.7325483399593899e-02,
		2.7071067811865485e-02, 3.1402438661763954e-02,
		4.0065180361560912e-02, 3.2485281374238568e-02,
		1.7325483399593888e-02, 2.5988225099390850e-02,
		1.6242640687119302e-02, 3.2485281374238568e-02,
	}, 1e-15, t)
}