Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

E19: Numerical Methods for Engineering Applications Spring 2016 - HOMEWORK 13

Vectorized fluid simulation code

Download the (slow, explicitly looped) fluid simulation code from the course website. It contains a complete Python port of Jos Stam's method. Your job is to convert every explicit loop in Fluid.py over array indices (which appear in the program as i and j) into vectorized operations.

You will hopefully find the indexing_strategies.py script useful for this, as it gives a few hints about useful techniques. Here are some other miscellaneous tips for converting the various functions in Fluid.py:

  • For set_bnd, each individual border (top/bottom/left/right) can be handled in one assignment statement.
  • The looped version of solve uses the Gauss-Seidel method (http://en.wikipedia.org/wiki/Gauss-Seidel_method); for the vectorized version, it is far more natural to use the Jacobi method (http://en.wikipedia.org/wiki/Jacobi_method) instead. The former updates the solution element-by-element, in-place, whereas the latter updates the entire solution at once. You can keep the outermost loop over k.
  • For advect, you can let i and j be arrays created from numpy.meshgrid. The max and min calls will have to be replaced with the functions numpy.maximum and numpy.minimum, respectively. The other subtlety here is that i0 and j0 should be arrays of integer type (e.g., i0 = y.astype(int)).
  • For project, looking at dx and dy in the indexing_strategies.py script may be helpful.
  • It is best to vectorize one function at a time, and make sure you get identical results for each change you make (or near-identical, for Jacobi iteration vs. Gauss-Seidel).

You will find that a successful vectorized implementation is vastly faster than one with explicit loops. On my laptop, for N = 32, the looped code takes about 130 ms per update vs. 5 ms for vectorized. For N = 128, the respective runtimes are 2000 ms vs. 20 ms.

Submit your vectorized code via Moodle (with your name at the top of the file). Please do not change the interfaces of any of the functions - I want a drop-in replacement for Fluid.py that I can run against the code in sim.py.

Attachment:- fluid sim.zip

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91844737

Have any Question?


Related Questions in Computer Engineering

Question recently it has become obvious that people are

Question: Recently it has become obvious that people are storing data where it does not belong and people are accessing files and directories that they should not have access to. Elizabeth Montgomery is in charge of the ...

Suppose you insert 125 integer keys into a hash table with

Suppose you insert 125 integer keys into a hash table with an initial capacity of 25 and load factor threshold of 2. THe hash code is the key itself,and the function key mod table_capacity is used to map a key into a tab ...

Closure and evaluationresearching for the closure checklist

Closure and EvaluationResearching for the closure checklist and project evaluation a. To prepare for this task, you will be required to provide an annotated bibliography. Write an Annotated Bibliography for three (3) rel ...

A recent study reported that the prevalence of

A recent study reported that the prevalence of hyperlipidemia is 30% in children 2 to 6 years of age. If 12 children are analyzed what is the probability that at least 3 are hyperlipidemic?

Each of the following lists has an average of 50 for which

Each of the following lists has an average of 50. For which one is the spread of the numbers around the average biggest?smallest? a. 0, 20, 40, 50, 60, 80, 100 b. 0, 48, 49, 50, 51, 52, 100 c. 0, 1, 2, 50, 98, 99, 100 Gu ...

Round robin rr jobs are processed using a fixed time-slice

Round Robin (RR): Jobs are processed using a fixed time-slice. The jobs are initially kept in a queue based on the order of arrival. The job at the front of the queue is removed and served similar to the FIFO algorithm. ...

Tetrafluoromethane cf4 is a greenhouse gas synthesized by a

Tetrafluoromethane (CF 4 ) is a greenhouse gas synthesized by a violently explosive reaction between methane and fluorine. In joules, what is the average kinetic energy of a molecule of CF 4  at 57.2°C and 0.0010 atm?

Research the group members identified in the video hackers

Research the group members identified in the video "Hackers: Operation Get Rich or Die Tryin'"-Albert Gonzalez, Stephen Watt, Damon Patrick Toey, Humza Zaman, and Christopher Scott. Pick a member of the gang and describe ...

In 2005 team dad used a toyota truck with a system of

In 2005, Team DAD used a Toyota truck with a system of spinning lasers as its "visual" system. What advantages and or disadvantage does such a system have compared to camera-based systems?

Question three academically reviewed articles on management

Question: Three academically reviewed articles on Management Information Systems and complete the following activities: 1. Summarize all three (3) articles in 600 words or more in APA format with reference 2. Discuss at ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As