![]() |
|
#1
|
|||
|
|||
more array help (simulation project..)I am currently in the process of making a program that will simulate an oil spill. The project is going to allow the user to input the number of oil barrels spilled, wind speed. The program also accounts for some evaporation of oil.
I am supposed to use two arrays to show the how the oil moves on the screen (from east to west, which would be for left to right on the screen). The barrels are going to always be spilled in the middle left part of the screen. I am going to allow the user to input the barrels spilled, windspeed, and the number of time steps to process the array. But for now I am just going to input some numbers myself to test it. The formulas I have to use are: E % of the oil in a square evaporates; Of the remaining oil, 10 / (10 + V) of the oil remains in the same square, where V is the wind velocity in miles per hour; Of the oil which does not evaporate and does not remain in the same square, 40% moves to the square immediately to the east, 20% moves into each of the squares to the north-east and the south-east; and 10% moves into each of the squares to the north and south. One array holds the old values and one to hold the new values. Any oil moving beyond the bounds of the array will be lost to the simulation. Also the program should only display numbers to the left of the decimal. Here is what I have so far.. I am having trouble figuring out how to use the formulas to move the "oil" around in the array. CPP / C++ / C Code:
|
|
#2
|
||||
|
||||
|
Hello dilmv.
This sounds like a pretty interesting program. I think that you are definitely on the right track. I did this quick so there could be some typos, but it should get you started. CPP / C++ / C Code:
That should get you started. Just remember to check your limits for each direction before you calculate the oil in the square. __________________
The best damn Sports Blog period. |
|
#3
|
||||
|
||||
|
Quote:
You also may wish to consider using 2 arrays. Using one you will have different results by processing your array west to east vs east to west. Each time you do a calculation east-west the square with oil will add oil to the western 'square', then when you process that square, you will move both the old oil and the new oil. Switching to two arrays, you build the second array based only on the oil in each square during that timeslice (loop). Then move the new array into the old array and do it again. For example, spill[4][4] has 100 gallons, spill [4][5] to the west has 5 gallons Processing spill[4][4] moves 40 gallons into 5,5 making 45. Then in this loop when you process 5,5, you are processing the 45 instead of the actual amount of 5. The next loop is when you want to process the oil from the previous square. __________________
Age is unimportant -- except in cheese |
|
#4
|
|||
|
|||
|
Thanks for the help! I made some of the changes that were suggested. I understand what WaltP was taking about, using two arrays so my data is accurate. But I'm not quite sure how to go about using them in the program.
Right now my program moves around the "oil" slightly. However, the oil in the starting "square" becomes zero after the calculations are made to take evaporation away and to move the oil in the other directions. Also I need the program to not only move the oil to the direct North and South, it has to move North east and South east. Any more suggestions would be greatly appreciated. Thanks for the continued help :-) CPP / C++ / C Code:
|
|
#5
|
||||
|
||||
|
Hi dilmv. It appears that you have already defined two arrays in order to do as WaltP suggested. You should probably work on implementing that. Just go through your first array (oilspill) and put the "new" oil amounts into your second array (oilspill2). Then after that is complete, just run through and add all of the oil from oilspill2 to oilspill and clear oilspill2 to start again.
As for the other things, you changed something that I am not quite sure of: CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
Again northeast should be i-1 and j+1. So you should have something like: CPP / C++ / C Code:
Notice that I used the oilspill2 array. One thing that you may want to do is throw in some cout statements if you aren't getting the results that you want. How much is leaving in evaporation? Does that seem correct? How much is left? Does that seem correct? etc. I'd be interested in what you came up with. This should show a pretty good migration of the oil I believe. __________________
The best damn Sports Blog period. |
|
#6
|
|||
|
|||
|
Thanks again for the help. I added a few things. I added a loop that should control the number of timesteps to process the oil. However, I am having trouble getting the oil to continue to move on the screen more than a few times.
Here is the current code: CPP / C++ / C Code:
Sorry for asking all these questions but I know I will eventually get the hang of arrays and processing them. Thanks again for the help |
|
#7
|
||||
|
||||
|
Hi dilmv. There are still some problems with your program and is still seems that you are struggling with NORTH, SOUTH & EAST. The #define statement can do wonders for readability in my opinion. I added:
CPP / C++ / C Code:
To the top of the program to help me know which way I needed to move things. Also, your oil arrays should be doubles (as your barrels is). I am surprised that your compiler didn't give you warnings, mine gave me tons . Warnings are signifigant in C.Also, some of the problem is around C's treatment of integer division. This statement actually always results in 0 because C treats the first statement as integer division: CPP / C++ / C Code:
The easy fix is to specify your constants as decimals. CPP / C++ / C Code:
I used some printfs at the end of the program that you should probably change. I can not stand using the ghastly iostream library and didn't want to look up what I wanted to do. ![]() Here is what I came up with. You should change it to be more dynamic. I also added a summation to make sure that I am not creating oil or loosing too much oil. CPP / C++ / C Code:
__________________
The best damn Sports Blog period. |
Recent GIDBlog
Meeting the local Iraqis by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| looking for a way to identify a repetitive sequence of digits in an array or string | sho | C++ Forum | 8 | 14-Jun-2004 23:59 |
| Speed up C++ code about 3d array! | Truong Son | C++ Forum | 0 | 16-Mar-2004 21:52 |
| c: array comparison | jack | C Programming Language | 7 | 26-Jan-2004 11:21 |
| Extra null element in an array | samtediou | MySQL / PHP Forum | 2 | 11-Dec-2003 11:52 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The