Giter Site home page Giter Site logo

jw4339_assignment3's Introduction

jw4339_assignment3

For Assignemtn 10:

Please find in mpi_assignment_1.py and mpi_assignment_2.py

For Assignemnt 9:

no assignemtn 9

For Assignment 8:

Please find in nbody_numba.py

For Assignment 7:

Please find in nbody_cython.pyx

For Assignment 6:

Please find in calculator.py

For Assignment 5:

Please find in nbody_iter.py

For Assignment 4:

This repository is comment by: Qiming Chen [email protected], Aditi S Nair [email protected], and Michael Christopher Higgins [email protected]

jw4339_assignment3's People

Contributors

junjiew avatar

Watchers

James Cloos avatar Greg Watson avatar

jw4339_assignment3's Issues

Don't need to create local_bodies_dict.keys() every time

Instead of calling local_bodies_dict.keys() in lines 56, 87, and 109 you can create a single global variable:
BODIES_keys = BODIES.keys()

Then where you call local_bodies_dict.keys(), you can instead create a local copy of BODIES_keys. This way, you don't have to create local_bodies_dict.keys() every time advance and report_energy are called.

Reference to Global variables

In nbody_opt.py

    local_bodies_dict = BODIES
    body_keys = local_bodies_dict.keys()

In line 55-56/84-85/106-107, the reference to global variables can be in a better way by claiming in the parameter list.

Reduce repeated computations

            factor = dt * ((dx * dx + dy * dy + dz * dz) ** (-1.5))
            v1[0] -= dx * m2 * factor
            v1[1] -= dy * m2 * factor
            v1[2] -= dz * m2 * factor
            v2[0] += dx * m1 * factor
            v2[1] += dy * m1 * factor
            v2[2] += dz * m1 * factor

Here m2 * factor and m1 * factor are executed 3 times, which can be simplified for better performance.

Pre-compute values in BODIES

You can pre-compute the values in BODIES dict, so you don't have to keep looking up the global variables PI, SOLAR_MASS, and DAYS_PER_YEAR (and you can save time with the computation).

For example:

'sun': ([0.0, 0.0, 0.0], [0.0, 0.0, 0.0], SOLAR_MASS)

can be:

'sun': ([0.0, 0.0, 0.0], [0.0, 0.0, 0.0], 39.4784176044),

I think this doesn't make the code less clear, because there is no explanation of the values in the dictionary anyway.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.