Fr/A local weather system

From FlightGear wiki
Revision as of 16:19, 2 September 2012 by Sahliyoussef (talk | contribs)
Jump to navigation Jump to search

Statut: Août 2010

Le système météo actuel de FlightGear peut être appelé Global quand Flightgear se lance sans connexion internet : tous les paramètres, que ce soit pour le vent, les nuages, la pression atmosphérique, restent identiques et immuables. Il n'est pas possible de voler dans un endroit où le temps est différent, ou voir des changements atmosphériques dans un autre lieu.

Quand nous nous connectons, le système météo offre un lien avec des serveurs METAR, qui déterminent le temps de manière locale : on peut changer de météo en volant en un lieu où le METAR disponible est différent, mais le changement s'opère de manière globale, c'est-à-dire qu'il n'y a pas de transition comme par exemple, traverser des nuages denses, puis avoir du soleil et une bonne visibilité.

Au contraire, un système de météo locale permet des changements continus de la météo d'un endroit à un autre, car les phénomènes météorologiques sont liés à un endroit précis. Inutile de dire qu'il est plus compliqué à simuler. Voici un schéma conceptuel expliquant comment un système météorologique local pour FlightGear pourrait être créé en utilisant la technologie et le code existants.


Echelle des phénomènes météorologiques

La météo réelle est déterminée par des processus se produisant à des echelles de taille très différentes. A la plus petite echelle est le système de régions de haute et basse pression et de fronts entre les masses d'air froid et d'air chaud, qui ont des echelles spatiales de taille : O(1000) km. D'autre part existent des phénomènes très localisés, par exemple une surface goudronnée noire chauffée par le soleil agit comme la source d'un courant ascendant thermique qui aura comme conséquences un cumulus. Ces deux côté sont pertinents dans une simulation et dans Flightgear - un avion sur un vol long-courrier est en mesure d'observer les fronts météorologiques à grande échelle de loin, alors qu'un pilote de planeur a besoin d'une simulation raisonnable des courants ascendants et des vents liés aux caractéristiques du terrain, cela d'une manière crédible pour une expérience de vol réaliste. Un système météo local doit donc :

  • simuler la météo à différentes echelles
  • idéalement générer le temps avec ou sans connexion
  • autoriser une quelconque modification par l'utilisateur
  • être suffisament rapide pour pouvoir générer en temps réel

Actuellement, les dynamiques atmosphériques sont un problème très complexe, qui même résolu a besoin d'heures de travail de la part d'un CPU, même très puissant. Ainsi, il est clair qu'un système de météo locale ne peux pas être (même approximativement) physiquement une représentation du processus atmosphérique, mais le système doit être une maquette crédible d'une telle simulation, remplacée par des règles heuristiques.

Pour donner un exemple, Il faut considérer un developpement de cumulus. La création de cumulus est reduite lors d'une journée à température élevée, sous un ciel de cirrus brumeux. La raison est que Le ciel composé de cirrus réfléchit une part de la lumière du soleil, qui ne chauffera pas le sol, ce qui provoquera un atténuement de la formation de cumulus. Une simulation précise devrait commencer avec la valeur de l'energie du soleil absorbée par différentes surfaces, puis résoudre les équations gouvernant le flux ascendant de l'air chaud, du sol jusqu'à l'altitude adéquate, suivi par des équations de la dynamiques des fluides pour la création de cumulus dûe à la convection. Une règle heuristique devrait simplement exposer que la rpobalité régissant le placement des cumulus dans l'environnement de Flightgear est réduite de 50% quand une couverture de cirrus est presente (évidemment, la sophistiquation des règles détermine le réalisme de la météo).

Dans la suite, la technologie pour un tel système météo appelé à différentes échelles est décrit- d'abord pour un situation sans connexion, suivi par des idées sur son implémentation dans un vol en ligne, et sa connexion avec le système METAR.

Small scale - effect volumes and average conditions

To simulate local weather at small scale, effect volumes (EV) are a useful concept. The effect volumes define regions in which the normal weather conditions (wind, turbulence, updraft, visibility, precipitation...) are replaced by ones characteristic for the region. As an example, one would define the inside of a cloud as an effect volume in which visibility is reduced as compared to outside, or the precipitation layer underneath a thunderstorm as an EV in which heavy rain is on, visibility is reduced, the temperature is reduced and some turbulence may be active.

The conditions characteristic for the EV are imposed once the aircraft enters the volume, they are restored to the outside values once the aircraft leaves the region again. The Flightgear AI system already has examples of structures which in essence are EVs - thermal and thunderstorm. The first structure contains an EV in which vertical air motion is active, the second one in which turbulence is present. These structures could be generalized to an AI system weather in which essentially all weather parameters inside the volume could be set by XML tags.

On the visual side, parts of the EV must also be tied to visible models. The inside of a cloud can be modelled by reduced visibility, but the outside of the cloud must be a model. Similarly, the inside of a rain front appears as rain generated by the Flightgear system, but the outside must be a 3-d model of a precipitation layer. This means that individual 3-d models for various visible atmospheric phenomena (clouds, precipitation, fog, ...) need to be created (see Howto: Modelling Clouds for a collection of techniques for creating cloud and precipitation models).

Outside the EV, many meteorological parameters may vary in a continuous way, for example visibility may decrease from 5000 to 4000 m when flying 20 km north - but inside the cloud (the EV), it will change in a discontinuous way very suddenly to a low value (say 30 m), to jump back to a large value outside the cloud. Thus, the EVs are used to simulate only discontinuous, local changes in conditions, the larger scale changes in the background need to be taken care of by a different system.

EV's should be implemented such that they can be user-specified, i.e. a user should be able to place any particular combination of weather effects and cloud/precipitation model to a specific location.

Mid scale - weather tiles

Weather needs to be explicitly simulated about as far as one can see from an aircraft - that naturally leads to the concept of weather tiles (analoguous to scenery tiles) which would cover a region of, say, 30x30 km or something of that size. Inside tiles, weather is simulated explicitly in terms of EVs and 3-d models.

As experiments will quickly convince anyone, placing a random set of cloud models into a tile does not create a realistic sky appearance. Instead, some cloud types usually occur together, others do not. The underlying reason is of course that there is large scale dynamics of the weather which determines what happens in a given location. For instance, Cirrus clouds are found at the leading edge of a warmfront - and they are usually followed by lower, layered cloud types like Altostratus, but typically not by a thunderstorm front.

Thus, there need to be different 'types' of tiles, each representing a typical snapshot of a development inside the larger system. Tile themes would be something like 'leading edge of warmfront', 'trailing edge of warmfront', 'cold front', 'dry high-pressure region', 'developed tropical thunderstorms' and so on. This has the added benefit that the user can specify the weather locally simply by chosing an appropriate tile from a menu (he does not need to micromanage the weather by placing individual EV and cloud models).

The type of tile then determines the rules for populating the tile with EV and models. A 'leading edge of a warmfront' tile could for example have the rules

  • populate the northern part of the tile randomly with 10 Cirrus clouds between 25.000 and 30.000 ft
  • make sure the models are spaced sufficiently far apart
  • make sure the models show the same type of texture (do not mix feathery Cirrus textures with amorphous ones)
  • populate the southern part of the tile with 20 Cirrocumulus clouds between 20.000 and 25.000 ft

(...)

The values of weather parameters outside the EVs would be set for the tile center and interpolated between neighbouring tiles.

Technically, each tile can be populated by a Nasal script specific for the tile type whenever the tile is needed (probably when it becomes visible). As an example for the development state of the system (March 2010), here is the view for a weather tile representing an approaching cold front with a Stratocumulus layer and occasional Cumulonimbus activity.

Clouds-coldfront02.jpg

Large scale - tile placement rules

To create a realistic experience for flights beyond a tile, there need to be matching rules for tiles. Since each tile represents a particular development in a larger weather environment, only certain types of tiles match. For instance, one cannot place a 'high-pressure region' tile next to a 'low pressure region' tile without crossing a front. With a moderately large library of different tile types and a set of placement rules, out of which (in offline mode) a credible set of neighbouring tiles is chosen, a more or less realistic long-distance flight experience can result.

If each tile type contains default values for weather parameters (to be overwritten by METAR info if available), the actual value of any parameter such as atmospheric pressure of visibility can be obtained by interpolation between tile centers, and the parameters will vary even in the absence of METAR info simpy due to the tile placement rules mocking up the presence of real large-scale weather systems.

Tile placement rules can be implemented in a Nasal loop which monitors the local position and initializes a new tile as soon as it is needed.


Connection with the METAR system

Connecting the above concepts with real METAR info is not straightforward. The METAR info should conceptually influence three different things:

  • selection of tile type
  • placement of EVs and models inside the tile
  • continuously varying weather parameters

Selection of tile type

If METAR info is to determine tile type selection, one would need to find an algorithm which gets the METAR from nearby stations and tries to extract a more global weather pattern from that info. For instances, pressure differences and wind direction could be used to locate high and low pressure regions, temperature differences (corrected for elevation) could help to find cold and warm air masses, and based on the most likely weather pattern given these bits of information, the initial tile type as well as the most likely matching neighbouring tiles could be chosen.

Placement of EVs and models inside the tile

At least some aspects of EV and model placement, such as cloud base, precipitation strength or number of clouds to be placed can more or less be inferred directly from the METAR information. However, in general the tile rules may in details conflict with the METAR info, so the weather system outlined here would not always literally reproduce the METAR (for example, it could happen that the METAR reports rain at an airfield, but that the tile generation does not place a raincloud directly above the airfield).

METAR and continuously varying weather parameters

If METAR info is available, this (rather than default tile center info) should be used to set parameters like visibility, pressure or temperature. To avoid discontinuous jumps, the info should be linearly interpolated in time for each nearby position from which a METAR is available. If METAR is updated every 10 minutes, one can use the information at startup for each position for the first 10 minutes of flight, then as soon as the next METAR is available slowly change the value (at each position) within the next 10 minutes to the values just fetched, and continue to do so (in essence creating a 10 minute offset from real to simulated weather).

To interpolate in space, in principle a simple algorithm with inverse distance weighting can be used (there are more accurate but also more complicated solutions): If, say, the pressure p is known at n positions, such that the pressure at position i is p_i and the distance between aircraft and i is d_i, then a good approximation of the local pressure is

p = (sum p_i (1/d_i)) / (sum 1/d_i)

as this will make the pressure at position i equal to p_i and lead to the average of the individual pressures if the distance to all METAR stations is the same.

Related Discussions

Connection with the Multiplayer system

(should be written by someone who knows what the Multiplayer system can and cannot do)

Development

  • Some users have expressed having problems when using the reset/new location facility, the local weather system should probably register listeners to /sim/signals/* and suspend/reset itself accordingly, so that all operations are gracefully interrupted? This may include releasing registered times and listeners, as well as terminating worker threads (once being used) [1]
  • Dynamically examining the FG/Nasal APIs by running code that may cause exceptions, may also cause errors printed to the console, it would probably be a good idea to expose logging related variables to the property tree, so that the log system can be optionally muted in such cases, i.e. by introducing a "NONE" or "MUTE" logging priority [2].
  • The feature-checking approach used by "compat_layer.nas" should probably be generalized and made available as a standard Nasal module, also for use by other scripts, as it provides a good method for handling backward compatibility [3]
  • we could introduce another hash/namespace in the compat_layer module for Nasal based workarounds that are directly performance critical, so that the C++ implementation is prioritized.
  • for some uses, threading may provide a real performance benefit. However, we need to ensure that threading is always OPTIONAL, so that users can easily verify if potential problems are related to threading or not. Worker threads seem to be the easiest and safest way for doing that.
  • excessive use of the property tree for storing all sort of state variables is a potential performance bottleneck, it is usually better to directly use Nasal data structures. In addition, it is much easier to make use of worker threads when all data is available in Nasal space, especially given that the property tree (and basically all Nasal extension functions) are not designed to be thread safe.
  • to be able to further optimize the system, it might be good to integrate some form of simple benchmark so that users can easily provide the results [4] (we talked about this in 9/2011, there are possibilities to provide this info automatically, but these would require modifying the core Nasal interpreter, and probably introducing some new instrumentation-specific opcodes, too - that doesn't seem to be a very popular idea at the moment, though).

Feature requests on the C++ side

Intended as a base for discussions on how to implement particular features in the C++ code. Also see Weather algorithms discussion from 06/2010.

As of version 0.81, the local weather system runs on a high-end system, but has problems on slower machines and could use performance boosts from implementing some features which currently are done from Nasal in C++. Guiding principles for that should be performance, accessibility, a clear structure and backward compatibility. The decision if a particular function should be implemented on the C++ level should be investigated with these in mind - usually performance is served better from C++, but Nasal structures remain more accessible. For example, cloud configurations (assembling a vector of coordinates where to place clouds) can usually be done in Nasal in a single frame and thus the performance boost when porting to C++ is marginal. On the other hand, cloud configurations are crated by functions which turn a set of parameters into cloud positions, and it is useful to have quick access to the parameters and functions to tune the system to reproduce a real sky better and better without the need to recompile the code. Thus, cloud configuration computations are an example for structures which should probably not be ported to C++.

Based on an idea by Hooray, version 0.81 of the local weather package has low-level function calls gathered in a separate Nasal file compat_layer.nas. The idea is that C++ counterparts for these are supplied, along with Nasal structures which check if the Flightgear core has the functionality and call the C++ function if the functionality is there while they use current Nasal implementations if no C++ structures are available, thus ensuring backward compatibility to Flightgear 2.0.0. Anyone interested in porting a structure to C++ could then start to implement one of the functions found there. These functions are:

Terrain related

  • (08/2012) provide an option to decouple terrain loading from visibility, so that geodinfo and the terrain presampler can also query terrain which is invisible [5] [6].
  • To check for wave conditions far from the original obstacle doesn't work well in Flightgear, because you can't rely on terrain far from your present location being loaded already. So by necessity one has to make it a more local phenomenon.

Environment related

  • (08/2012): Provide an option to disable the precipitation "layer" system [7]: Local Weather has no precipitation rendering. This is due to the fact that the system uses its own layer altitude definition and a 3d definition of where rain is falling, whereas the precipitation rendering system uses a lowest altitude criterion. Since lowest layer altitude is always zero when local weather is running (it uses its own cloud altitude management and since clouds need to be placed with offset to the layer, it's easiest to make that layer zero) Local Weather has never rain unless you fly to the dead sea (not much chance of rain there either...). Could someone please provide a dumb rain and snow flag which alwaysrenders rain when that flag is set and leave it to the weather system to set/unset that flag as it sees fit? [8] [9]
  • (06/2012) Sun is always painted on top of the skydome, you even see it through what is supposed to be terrain from high altitude. That's an issue for the maintainer of the sun code, it isn't curable via Nasal. See [10].
  • expose the atmospheric model to the property tree (or Nasal) [11] [12] [13] [14]
  • Once I cross the mountaintops, some system switches on turbulence (I suspect ridge lift, since I could not find any other property which would create turbulence). That's bad, because wave lift isn't turbulent at all. To disable the ridge lift system, set /environment/ridge-lift/enabled to 0

Cloud placement

  • 08/2012: Cloud placement meanwhile uses a new fgcommand "add-cloud", however that's using the property tree, and it only places a single cloud - it might make sense to provide another version which places multiple clouds at once, so that a single call can add several clouds. This would probably be faster by using a Nasal extension function, instead of an fgcommand.
  • calls to place cloud models into the scenery, to remove them and to change their position. Compared with the standard Flightgear 3d clouds, placing and moving models from Nasal seems exceedingly slow. However, local weather uses some features for which it is not obvious if they are supported by the way the standard 3d clouds are implemented. These are:
  • a 'cloudlet' is not a single texture, but a complete *.ac model. This allows to make multi-layered cloudlets and opens the possibility to make sure that one type of cloud texture is always seen in front of another (for example, a diffuse haze could always be before a well-structured cloud top, such that the top seems to emerge from the haze). This is a *very* useful feature for designing clouds, and is also non-trivial to get via explicit placement rules.
  • clouds need to be identified by various means. For movement, the system needs to know all clouds in the visual field, for deletion all clouds with given tile index, for evolution (not implemented yet) all cloudlets which belong to a particular Cumulus cloud. Internally, this is done by storing pointers to the cloud property node in various arrays, such that simply using the right array ensures that the correct cloud is referenced for an operation. Any C++ implementation should preferably allow similar referencing by pointer from Nasal or provide equivalent functionality to replace what the pointer array is for.

Performance bottlenecks

For reference, the main performance bottlenecks in v0.81 seem to be:

  • rotating cloud models towards the viewer. This scales with the number of vertices, and is currently done by the shader. Performance is needed whenever clouds are in the field of view. Probably performance here can not be improved significantly and this is an upper limit for the number of distinct clouds which can be in the field of view - for denser cloud population, larger textures containing a group of clouds can be used.
  • moving clouds with the wind. This scales with the number of cloudlets in the field of view and is done by Nasal. performance is needed whenever dynamical weather is on and clouds are in the field of view. Currently, the Nasal code limits the max. number of clouds in the loop to avoid a dramatic drop in framerate, which means that not all clouds in the visual field may be processed.
  • generating a cloud configuration. This is only a siginficant issue for convective clouds, where several thousand terrain coverage calls need to be done. More performance is needed in more detailed terrain (custom France for example). Performance is only needed when a weather tile is generated, so unlike in the previous cases, performance loss occurs over a finite time interval, after which things get back to normal
  • sampling terrain elevation (as above, just no terrain coverage, only elevation data is needed)
  • placing clouds into the scenery. Performance is reduced while the flightgear core lets clouds appear in the scenery
  • deleting clouds. A brief drop in framerate (usually less than a second) occurs when a large amount of information is deleted from the property tree.
  • frequently used fgcommands
  • property tree access (i.e. reduce property tree use and use native Nasal data structures where possible)

New Nasal API requests

For things that should be implemented as new Nasal APIs, rather than being hard coded features in C++ The file $FG_ROOT/Nasal/compat_layer.nas contains compatibility wrappers for functions that are currently implemented in Nasal space, because the corresponding features are not yet supported by the core fgfs/Nasal APIs. This may be a good starting point for implementing new Nasal APIs.

Current development status

The current version 0.7 supports placement of effect volumes for visibility, rain, snow, turbulence and thermal lift, as well as interpolation of visibility, pressure, temperature and dewpoint between weather stations. It has a variety of 40x40 km weather tiles with layered and non-layered clouds and weather effects, thunderstorms, external models of precipitation and (with a Git patch) also support for gliders, i.e. it creates thermals below convective clouds. Automatic weather tile reloading for long-range flights is implemented, both in a simple 'repeat-tile' function and a set of tile selection rules to simulate the long-range change of real weather. 3d clouds are rendered up to 45 km distance. Terrain presampling algorithms automatically adjust the cloud placement over elevated terrain.

A feature gallery of version 0.85:

[ Cumulus and Cirrocumulus clouds (Local Weather v0.85) [ Cirrus and Cirrostratus clouds heralding a warmfront (Local Weather v0.85) [ 45 km cloud visibility range (Local Weather v0.85) [ Realistic cloud bottoms (Local Weather v0.85) [ Cumulus and Altocumulus clouds (Local Weather v0.85) [ Multiple 3d layered clouds (Local Weather v0.85)


A feature gallery of version 1.0:

[ Realistic skies with multiple cloud types (Local Weather v1.0) [ Thin 3d cloud layers (Local Weather v1.0) [ Thermal soaring beneath Cumulus clouds (Local Weather v1.0) [ Flying with both thermal and ridge lift (Local Weather v1.0)

[ Thick stratocumulus layers (Local Weather v1.0) [ Thin Cirrocumulus sheets (Local Weather v1.0) [ Altostratus layers (Local Weather v1.0) [ Stratus coverage obscuring the sunlight (Local Weather v1.0)

[ Evening light... (Local Weather v1.0) [ ... and morning light (Local Weather v1.0) [ Multiple 3d layers (Local Weather v1.0) [ Heavy rain (Local Weather v1.0)

Download

Related content