Weather simulation

Started by
14 comments, last by Stainless 8 years, 2 months ago

The reason I took the "designed" approach is to give the designers chance to add complexity to the game play.

If you watched any films about the US bombing campaign in WWII, you will always see times when the weather has a massive effect on the mission. Cloud obscuring the target, do I go around and fly through the flak again or do I drop and hope?

The initial pressure regions defined by the designers have attached velocities. So over the course of the mission the weather fronts move (the weather fronts are calculated not drawn).

This means winds change direction, clouds move, all the things that you would expect to happen happen.

It also means I can do some very simple maths to detect updrafts and downdrafts, simply look at the wind direction and terrain normal and I can generate nice effects.

My problem is the rest of the simulation, the bit that makes it feel real rather than designed.

Clouds forming down wind of mountain peaks. Sleet mixed in with the rain where cold air meets warm air. Precipitation. Snow. Fog. all these things that make it real.

What I don't want to do is make the whole system designed. I want a designer to spend 30 minutes setting up weather not two days.

To do this I have to bring temperature into the simulation.

I may be able to take existing real world data from many sources and create a sort of global ambient temperature map I suppose, but that feels wrong.

What I am thinking of doing is just do the sun energy calculation for a full day. Calculate the total energy added to the system at any point over 24 hours, then use some formula to relate that to ambient temperature.

Then do a pass with the starting cloud formations to modify that temperature map.

Do we think that would work?

Any other terms I should add?

Advertisement

Had a think about it and I think what I should do is ...

1) Calculate the total energy input from the sun for a 24 hour period.

2) Use this to calculate a base ambient temperature. (Use a SHC from some web resource for the terrain type, multiply the two, half it.)

3) Calculate a total energy supplied by the sun up until the simulation start time and add this as a heating effect.

This will give me a finger in the air starting point for the ambient temperature.

I also think when I get this working I should open source it to see if anyone can improve it.

code is irrevelant

look at the title and read that pdf




/*
*  A Method for Modeling Clouds based on Atmospheric Fluid Dynamics
*	Ryo Miyazaki Satoru Yoshida Yoshinori Dobashi† Tomoyuki Nishita
*	University of Tokyo †Hokkaido University
*	7-3-1, Hongo, Bunkyo-ku Kita 13, Nishi 8, Kita-ku,
*	Tokyo, 113-0033, Japan Sapporo, 060-8628, Japan
* 	{ryomiya, yoshida, nis}@nis-lab.is.s.u-tokyo.ac.jp doba@nis-ei.eng.hokudai.ac.jp
*
*
*  Coded by me ;]
*
*
*/


//deltaV / deltaT = -(grad(pressure) / density) + visc_coeff*grad(V)   ---- velocity

// grad(div) is the flow caused by the gradient of the mass flow around lattices
// Let vx be the x component of the velocity v for the current time step and vx* be the x component of v for the next time step.

/*
Velocity field update / Viscosity and Pressure Effect

vx is of course the x part of velocity vector

//vx*[x][y][z] = vx[x][y][z] + kv * grad(vx)[x][y][z] + kp * grad(diw)x  //for the same cell

//kv is the viscosity ratio
//kp is the coefficient of the pressure effect

grad(vx)[x][y][z] = divBy6 * ( cell[x+1][y][z].v.x + cell[x-1][y][z].v.x + cell[x][y+1][z].v.x +
cell[x][y-1][z].v.x + cell[x][y][z+1].v.x + cell[x][y][z-1].v.x - 6.0f * cell[x][y][x].v.x );

grad(diw)x = divBy2 * ( cell[x+1][y][z].v.x + cell[x-1][y][z].v.x - 2.0f * cell[x][y][z].v.x   ) +
divBy4 * (  cell[x+1][y+1][z].v.y + cell[x-1][y-1][z] - cell[x-1][y+1][z].v.y - cell[x+1][y-1][z].v.y +
cell[x+1][y][z+1].v.z + cell[x-1][y][z-1].v.z - cell[x-1][y][z+1].v.z - cell[x+1][y][z-1].v.z );



*/



/*
  WATER VAPOR DIFFUSION

  Wv*[x][y][z] = Wv[x][y][z] + temperature_coeff * grad(Wv)[x][y][z];


  grad(Wv) = divBy6 * ( cell[x+1][y][z].w + cell[x-1][y][z].w + cell[x][y+1][z].w +
cell[x][y-1][z].w + cell[x][y][z+1].w + cell[x][y][z-1].w - 6.0f * cell[x][y][x].w );


*/



/*
  Thermal Diffusion

   E*[x][y][z] = E[x][y][z] + temp_diff_coeff * grad(E)[x][y][z];


  grad(E) = divBy6 * ( cell[x+1][y][z].temp + cell[x-1][y][z].temp + cell[x][y+1][z].temp +
cell[x][y-1][z].temp + cell[x][y][z+1].temp + cell[x][y][z-1].temp - 6.0f * cell[x][y][x].temp );



*/



/*
  Buoyancy      AD NOTE 2.: since in paper we have z versor pointing upward we need to convert it to y component since we have lefthanded(or righthanded ;p) system  

kb is the coefficient affecting the strength of the
buoyancy force.


Vz*(x,y,z) = Vz(x,y,z) + kb * divBy4 * (  4.0f * E[x][y][z] - E[x+1][y][z] - E[x-1][y][z] - E[x][y+1][z] - E[x][y-1][z]  );

so the code seems to be like this: (rewritten to y as up vector)


cell[x][y][z].v.y* = cell[x][y][z].y + kb * divBy4 * ( 4.0f * cell[x][y][z].temp - cell[x+1][y][z].temp - cell[x-1][y][z].temp -
cell[x][y][z+1] - cell [x][y][z-1] );
*/



/*
			  PHASE TRANSMISSION


 (6) Phase Transition
The amount of water droplets generated by the phase
transition is determined in proportion to the difference
between the maximum amount of water vapor and the
amount of water vapor in each lattice. The maximum
amount of water vapor for a unit volume of air is a
function of its temperature (see appendix for details ).


APPENDIX

The amount of water droplets is proportional to the
difference between the maximum amount, 'wmax', of water
vapor 'wv' and the amount of water droplets 'wl' of each
lattice. That is, the amount of water droplets created at
each time step is computed by the following equation.



(A.1)
where alpha is the phase transition rate. Q is the latent heat.
wmax is a function of the temperature T[K] and is given by
the following equation:
( ) 217.0 exp[19.482 4303.4 /( 29.5)] / . max w T = - T - T (A.2)


*/
const long double viscosity_coeff = 0.9670;
const long double waterVapor_coeff = 0.9670;
const long double temperature_coeff = 0.9670;
const long double divBy6 = 0.16670; //1.(6)
const long double divBy4 = 0.250;
const long double divBy2 = 0.50;
		 /* Deleted bullcrap not even worth watching */
#endif

The problem with this is I really need to work out an ambient temperature value for each location on the map.

There are many topogrpahic temperature maps, by studying them you could create your own initial value map

Has anyone come across a way of calculating an ambient temperature for a location based on date/time/location data?

Thats almost impossible to achieve, unless your run fullscale simulation, and learn your program, how things change. (still it will be far from ideal due to external forces)

And the wind that causes temperature to move (cool down heat up).

I believe there are heat maps on nasa page, so you could make some kind of one year peroid temperature map (with maybe data from each month, or only for winter, spring, summer, autsomething tongue.png, you wont be able to get acutal day, time, hour weather without running some simple simulation. or lerping <- which is bad as f

still code is wrong there, (didint have time to fix it) but the pdf is really good.

vital is to add third dimension. gravity, coriolis force or whatever its called

i am a bit to late with that post but was searchign for that code and pdf name.

but now i dont know if this is answered or what, still i could write an essay about weather

Yes I tried that sort of system before. The results were encouraging, but used far too much CPU time to make it worthwhile.

I moved the equations into shaders and it still took about a minute to generate a full cloud map. That's why I ended up trying this pseudo-scientific approach.

I think you have to be very careful about a realistic way to simulate this. May be too difficult and take too much calculation power.

As for how much starting conditions matter, that's completely dependent on what math functions you put in and how they interact. If the range of parameters that lead to equilibrium are narrow, the system may diverge rather than converge and you may get stupid results. A system may converge too narrowly. One parameter may dominate all others. Such an artificial system will only behave like sensible like a real system when you set it up so that it does. And that may actually be a sweet spot. Your world may get hotter and hotter and approach infinite hotness in infinite time. If you make energy, and temperature, a finite quantity, then it will not. But then all heat may end up in one place and stop moving around the map. Then you constrain it even more and it may stay too constant. Then you crank up how fast it changes and all you get a bunch of quickly osculating noise.

There's no way to know how your complex system behaves until you run simulations. And if you have a lot of degrees of freedom, you cannot find what constants you need to put into your function to get the behavior you want.

You may need to evolve your parameters or use some fancy numerical approach to your multivariate problem. All a headache.

So having tried actual simulations which seems to have failed, can you not take a bunch of datasets and mix them up randomly while keeping it continuous somehow?

Try to look at just temperature and try to figure out what it has to do, at the bare minimum. Then find the simplest way to implement it. You can have a sine oscillate between a minimum and maximum during the day and during the year. Then you can vary those minima and maxima.

Problem is that if you want everything to be smooth and continuous throughout all your game tiles, you just need a smooth 3d function with interesting topography. To generate one randomly is not so hard. Just sum a bunch of functions in 2 variables and see what kind of heat landscape that gives you in a graphing program.

To generate one that makes sense for your topography, that's a lot harder.

Sometimes, you can make up a bunch equations with a bunch of parameters. Then you can kind of paint how a solutions would look like by making up a bunch of numbers. Then use a numerical method that tries to converge for the parameters that make the function fit the made-up dataset you created.

To generate something that behaves like a real weather system, for that you need a real weather simulation.

I used a table of SHC values I found on the internet and converted the suns incident radiation (in watts per square meter) to an energy value and applied this to the terrain over a 24 hour period. Using this I was able to get an initial value for ambient temperature that looks ok.

The results look like this though it's hard to tell anything from an image.

temperature.jpg

This topic is closed to new replies.

Advertisement