diff options
-rw-r--r-- | csv/csv.go | 4 | ||||
-rw-r--r-- | draw/draw.go | 4 | ||||
-rw-r--r-- | file/file.go | 4 | ||||
-rw-r--r-- | forces/forces.go | 13 | ||||
-rw-r--r-- | main.go | 39 | ||||
-rw-r--r-- | structs/vector2D.go | 8 |
6 files changed, 47 insertions, 25 deletions
diff --git a/csv/csv.go b/csv/csv.go index 007c0f9..1b3c0bc 100644 --- a/csv/csv.go +++ b/csv/csv.go @@ -21,10 +21,10 @@ func Import(path string, start int, end int, slice []structs.Star2D) []structs.S // Handle errors if errx != nil { - logplus.LogFError("error reading value from csv in line nr. %d (%s)", linenr, errx) + logplus.LogErrorf("error reading value from csv in line nr. %d (%s)", linenr, errx) } if erry != nil { - logplus.LogFError("error reading value from csv in line nr. %d (%s)", linenr, erry) + logplus.LogErrorf("error reading value from csv in line nr. %d (%s)", linenr, erry) } // Create a temporary star for assembling the star diff --git a/draw/draw.go b/draw/draw.go index fbf8d9f..c5d1474 100644 --- a/draw/draw.go +++ b/draw/draw.go @@ -109,10 +109,6 @@ func Slice(slice []structs.Star2D, path string) { // draw all the stars in the given slice drawStars(dc, slice) - dc.SetRGB(1, 1, 1) - - dc.Fill() - // save the plot to the given path saveImage(dc, path) } diff --git a/file/file.go b/file/file.go index ce6ac9c..c5992a7 100644 --- a/file/file.go +++ b/file/file.go @@ -13,7 +13,7 @@ type File struct { func Open(path string) (File, error) { file, err := os.Open(path) if err != nil { - logplus.LogFError("openStarsCSV Panic! (cannot read file from %s)", path) + logplus.LogErrorf("openStarsCSV Panic! (cannot read file from %s)\n", path) } return File{f: file}, err } @@ -21,7 +21,7 @@ func Open(path string) (File, error) { func (file *File) ReadCSV() ([][]string, error) { lines, err := csv.NewReader(file.f).ReadAll() if err != nil { - logplus.LogError("openStarsCSV Panic! (cannot read the files content)") + logplus.LogErrorf("openStarsCSV Panic! (cannot read the files content)\n") } return lines, err } diff --git a/forces/forces.go b/forces/forces.go index 7130503..d4ded26 100644 --- a/forces/forces.go +++ b/forces/forces.go @@ -1,14 +1,14 @@ package forces import ( - "git.darknebu.la/GalaxySimulator/Source/structs" "fmt" + "git.darknebu.la/GalaxySimulator/Source/structs" "git.darknebu.la/bit/logplus" "gopkg.in/cheggaaa/pb.v1" "math" ) -// forces_acting calculates the force inbetween the two given stars s1 and s2 +// forces_acting calculates the force in between the two given stars s1 and s2 // The function return the force func accelerationActing(s1 structs.Star2D, s2 structs.Star2D) structs.Vec2 { @@ -60,6 +60,15 @@ func accelerationThread(starSlice []structs.Star2D, localRangeStart int, localRa // iterate over the given range for index := localRangeStart; index < localRangeEnd; index++ { + /* + TODO: Genrate an Octree: + In the first step, all the stars are inside of one big cell that is subdivided recursively. + A cell is subdivided as long as none of the exit conditions has been met: + 1. The Cell contains fewer than a given number of stars + 2. The Cell reaches a minimum size + 3. When a maximum number of subdivisions has been reached + */ + // Calculate the acceleration acting inbetween the given star and all other stars var a = accelerations(starSlice, index) diff --git a/main.go b/main.go index 7424965..e831ef3 100644 --- a/main.go +++ b/main.go @@ -1,42 +1,51 @@ package main import ( + "fmt" "git.darknebu.la/GalaxySimulator/Source/csv" "git.darknebu.la/GalaxySimulator/Source/draw" - "git.darknebu.la/GalaxySimulator/Source/forces" + // "git.darknebu.la/GalaxySimulator/Source/forces" "git.darknebu.la/GalaxySimulator/Source/structs" - "fmt" "git.darknebu.la/bit/logplus" - "math" + // "math" + "os" ) func main() { + // Define a logging level for logplus logplus.SetLogLevel(logplus.LevelAll) - var threads int = 8 + + // var threads int = 8 var frames int = 1 var rangeStart int = 0 - var rangeEnd int = 50000 + + // Error handling (panic if there enouth arguments are provided) + if len(os.Args) < 2 { + panic("It seems like you forgot to supply a number of stars!") + } + rangeEnd, _ := os.Args[1] // the slice starsSlice stores the star structures starsSlice := []structs.Star2D{} - logplus.LogNeutral("Opening the csv") + // Import data from a csv + logplus.LogNeutralf("Opening the csv") starsSlice = csv.Import("data/U_ALL.csv", rangeStart, rangeEnd, starsSlice) // Simulate frames for i := 0; i < frames; i++ { - logplus.LogPositive("--- --- --- --- ---") - logplus.LogPositive(fmt.Sprintf("Frames %d/%d", i, frames)) + logplus.LogPositivef("--- --- --- --- ---") + // logplus.LogPositive(fmt.Sprintf("Frames %d/%d", i, frames)) logplus.LogPositive("Done drawing the quadtree") - logplus.LogNeutral("Calculate the new Star positions") - starsSlice = forces.NextTimestep(starsSlice, 25*math.Pow(10, 4+7)) + // logplus.LogNeutral("Calculate the new Star positions") + // starsSlice = forces.NextTimestep(starsSlice, 25*math.Pow(10, 4+7)) - logplus.LogNeutral("Calculate the acting accelerations") - starsSlice = forces.CalcAllAccelerations(starsSlice, threads) + // logplus.LogNeutral("Calculate the acting accelerations") + // starsSlice = forces.CalcAllAccelerations(starsSlice, threads) - outputName := fmt.Sprintf("out_%d.png", i+3) - logplus.LogNeutral(fmt.Sprintf("draw the slice and save it to %s\n", outputName)) + // draw the galaxy + outputName := fmt.Sprintf("out_%d.png", i+4) + logplus.LogNeutralf(fmt.Sprintf("draw the slice and save it to %s", outputName)) draw.Slice(starsSlice, outputName) - } } diff --git a/structs/vector2D.go b/structs/vector2D.go index 47e457f..6beedb2 100644 --- a/structs/vector2D.go +++ b/structs/vector2D.go @@ -8,6 +8,14 @@ type Vec2 struct { X, Y float64 } +// newVec2 returns a new Vec2 using the given coordinates +func newVec2(x float64, y float64) *Vec2 { + return &Vec2{ + X: x, + Y: y, + } +} + // creates a copy of the vector func (v *Vec2) Copy() Vec2 { return Vec2{v.X, v.Y} |