⬆️ ⬇️

Simulation of the planet daisies

Simulation of the planet daisies



  1. Lyrics
  2. Interface description
  3. Decomposition
  4. Model
  5. Logics


1. Lyrics



A long time ago, I do not remember where, I learned about one amazing experiment, the beginning of the description was this: Imagine a planet, approximately the same as the Earth, which revolves around a star, approximately the same as the Sun. There is life on the planet, but not very diverse - there are only two kinds of daisies - black and white. Submitted? What a call! Author handsome, almost Exupery.



The following experiment was described: At the starting point, daisies are only in the form of seeds, and the planet is so cold that at the equator the temperature is on the verge of survival. Nevertheless, several daisies of black and white sprout, and they even begin to bloom. The white daisy, because of its high reflectivity reflects more light than green leaves and brown earth, in this place it locally becomes colder and it freezes. Around the black daisy, on the contrary, a small heated zone appears, as it absorbs more energy from the star. Daisy begins to feel better, blooms, and then, in the warmed earth, throws its seeds. A few more black daisies sprout from these seeds (because their parents are black), the flowering of these daisies warms an even larger area where even more daisies can grow, and they will also be black, because only black daisies leave the seeds here.



Thus, the warming caused by the blooming of black daisies provokes an even greater spread of black daisies, which in turn warm up more of the area around them, and so on in a circle. Thus, black daisies capture the equatorial region, but they cannot spread further - it’s too cold there.



However, such a violent bloom of black daisies reduces the reflectivity of the entire planet (albedo), this will affect the balance of absorbed / reflected energy on a planetary scale, which leads to an increase in the effective temperature of the planet, that is, it becomes warmer on the entire planet. After that, the black daisies expand their territories a little further south and north, which in turn leads to even greater global warming. Thus, the black daisies make their way to the poles, and the planet warms up.

')

But one should not forget - the planet has become warmer, and now there are all conditions for growth and white daisies too. Moreover, as it warms up, it gets hotter at the equator, and black daisies warm the earth around themselves even more, and in this area it becomes more and more uncomfortable. Not like white daisies, which reflect more energy, and create around themselves a pleasant cool zone in which they grow well, and throw away the seeds there as well. Well, you understand - White is jostling black from the equator. But here is a surprise - the albedo of the planet increases again because of the large areas of white daisies, the planet becomes cold and eventually some equilibrium occurs.



Further, the author does not intend to leave the planet in this dull for him, and comfortable for daisies state. This is what happens - the star, as they usually do, starts to glow brighter, and more energy falls on the planet. The reaction of the planet - an increase in the area of ​​distribution of white daisies, an increase in albedo - and a decrease in the effective temperature, a transition to a new equilibrium state. Almost the same thing happens when the star's luminosity decreases, only more black daisies appear.



The conclusion that the author makes is that the biosphere itself creates comfortable temperature conditions on the planet in wide ranges of star luminosity. The authors of this wonderful experiment are named James Lovelock and Andrew Watson. Who is interested in all the findings and a more detailed description, see. Wikipedia - Daisy world , there is written more and better. The meaning of this long introduction is not to retell the article from the wiki, but to come to the most interesting part - directly conducting the experiment. The author of the article describing the experiment asked a rhetorical question: The reasoning looks logical, but how to conduct such an experiment, where to get a planet with a star, with suitable conditions, and how to deliver daisy seeds there? Even if someone comes into the head to use Mars for this, then he will fail. I was very sad about this turn because I was a big fan of terraforming and cool experiments. But the author, to my great joy, said that such an experiment is possible with the help of computer simulation.



Well, of course!!! This experiment, as if for computer simulation itself, was invented, and even reached its goal (well, that is, it confounded some two wise men, see the wiki ). In this segment of the narration about the experiment, my breath came out straight because I thought of the lucky ones, who, looking at this description, somehow, turn the idea into something visual, accessible to watch in real time, “touch hands. At the same time, both the modeling process itself and the experiments were interesting. To read the experiment and marvel at the conclusions is one thing, but “playing” with this planet, experimenting with different conditions, is quite another. But then I still could not program :(, but the present times have arrived, fortunately, and therefore I propose to move from long and boring lyrics to the content part. Who just wants to play with the planet can move on to describing the interface, who is fascinated by the modeling process called Decomposition and beyond.



2. Interface Description







In the left part there are two blocks Populator and Updater, in the central part there is a visual display of the planet and some parameters, in the right part there are graphs of changes in the effective temperature and the Star constant.



Management is carried out in blocks Populator and Updater.



In the Populator block, you can set the ratio of white daisies, black daisies and empty cells, after clicking the Populate button, the planet will be populated accordingly. It is possible to populate the planet both at the beginning of the experiment, and at any other time, if necessary.



The Updater block is responsible for updating the model of the planet, you can set the number of updates at a time, as well as the value (negative ones are allowed) and the frequency of incrementing the stellar constant (for example, update 100 times, while increasing the stellar constant by 1 every two iterations).



Visual display of the planet:



White circles are areas with white daisies, black - with black, olive - empty cells.



In the upper left corner of the current values ​​of the effective temperature in Kelvin, stellar constant, albedo and iteration number.



Two color scales to the right of the planet: the left for black daisies, the right for whites. Each point of the scale corresponds to the temperature located opposite the belt of the planet. The legend is this: Blue is too cold for life, Yellow is possible to live, Green is not only possible to live, but also comfortable, Red is too hot for life.



3. Decomposition



The MVC pattern is used in the application, although in JavaFX, as I know, the view and controller are a bit stuck together, but the boundaries of the model are outlined quite clearly.



The model, in turn, is also divided into a part responsible for the state, and a part responsible for the behavior, in the best traditions, so to speak. There is still a part that is responsible for saving the results in the database, it seems to be working fine, but I did not make the interface and settings as unnecessary. I will not describe the type and layer of persistence, below everything is about the model and behavior.



4. Model



The model is represented by six ordinary classes Planet, Starr, Zone, Conditions, BlackDaizy, WhiteDaizy, NoDaizy, one abstract Daizy, and one listing Type. Although it was possible to have a smaller number of classes, I thought that the star is so large and important thing that it would be ugly to leave it without a class. And for daisies, in the program called “Planet of Daisies” a whole small hierarchy of classes was built, and even an enumeration was introduced. Thus, the main classes defining the state are Planet, Conditions and Zone.



Planet is the main aggregating class, an instance of this class in the application plays the role of a model, from it controllers get the state for the view, and the classes responsible for the behavior get a reference to the Planet instance to change the state.

The Planet class contains fields characterizing the state of the planet: this



/**  ,      */ private double albedo = 0; 


  /**  :    , *         -*/ private double temperature = 0; 


  /**    */ private double radius = Conditions.getInstance().radius; 


 /**       ,      ,      —  */ private int halfZonation = Conditions.getInstance().halfZonation; 


  /**  :     ,    -   ,    ,   ,        , *  - */ private long daiziesPerZone = Conditions.getInstance().daiziesPerZone; 


 /**   -            ,     */ private double effectiveArea; /**  .    area -  S = 2πrh, r –  , h –   . */ private double zoneArea; /**    ,  */ private double daisyArea; 


In addition, the Planet class contains a reference to the Starr star, an array of instances of the Zone class, each element of which characterizes a separate belt, an update counter, a sign inhabited well, that is, a habitable planet. As well as links to classes responsible for behavior.



  PopulatorImpl populator = new PopulatorImpl(); AlbedoCalculator albedoCalculator = new AlbedoCalculatorImpl(); 


which will be discussed below.



The second important class is Conditions, it contains all the constants. Here are some



 public double Kelvin = -273.15; // Planet constants public double radius = 1000.0; public int halfZonation = 90; public long daiziesPerZone = 100; /**  :       ,             ,          ,    ,  ..           - ,    ,  -  , , ,    */ public double planetDeltaTemper = 70.0; /*     */ public double blackDaisyAlbedo = 0.1; public double whiteDaisyAlbedo = 0.9; public double noDaisyAlbedo = 0.5; /*       ,       , */ public double blackComfortableTemper = 18 + (-Kelvin); public double whiteComfortableTemper = 22 + (-Kelvin); /**  -    ,    , *   ,        *      1367 /²*/ public double StarConstant = 1367.0; /**   - * */ public double StephanBoltsmanConst = 5.67e-8;   ,      Zone: /**      */ private double latitude; /**   -      , *     */ private double effectiveArea; /**   */ private double height; /**      zone*/ private double localTemperature; //   private long numBlackDaisies; private long numWhiteDaisies; private long numEmptyCells; 


Note the local temperature setting method that calculates the temperature as described above:



 public void setLocalTemperature(double globalTemperature) { this.localTemperature = globalTemperature + Conditions.getInstance().planetDeltaTemper*Math.cos(latitude); } 


In the class there are no methods that calculate the state, the value of all fields is passed in the parameters of the constructor, or are set by setters.



5. Logic



Almost all the behavior is collected in the logic packet, and represented by the following classes:



ZoneMaker - the class is used to create the entire array of zones of the planet, taking into account the fact that different planets may have different fragmentation (number of zones), and each zone has its own unique latitude, corresponding to the index in the array



AlbedoCalculator - interface, single method
  double calcAlbedo(Zone[] zones); 
its implementations are used to calculate the albedo of the entire planet depending on the ratio of black and white daisies and unoccupied space, as well as attention, their location - since daisies growing at different latitudes make different contributions to the total albedo.



StephanBoltsman - a class to calculate the effective temperature of the planet.



Populator - the interface responsible for settling the planet daisies.



Method



 void populate(Zone zone, int whiteExpectance, int blackExpectance, int noneExpectance); 


it is intended for filling in one, transferred in parameter, zones, parameters



 int whiteExpectance, int blackExpectance, int noneExpectance 


something like mathematical expectations, depending on their ratio, white and black daisies will be planted randomly around the zone, or a pass will be made, but the total number of daisy cells in the zone is always constant and depends on the initial settings (conditions are set . daiziesPerZone ).



This method is used in two other methods that already fill all zones on the planet:



 void populateInitial(Zone[] zones, int whiteExpectance, int blackExpectance, int noneExpectance); 


Fills all zones with the same ratio. The designer of the planet are the parameters 0,0,1. That is, the planet is created uninhabitable.



Method



 void rePopulate(Planet planet); 


is an implementation of the mechanism for crowding out daisies with daisies, and filling the empty space. It is used to redistribute daisies on the planet, depending on the prevailing conditions on the Planet. The method works approximately as follows: it defines three variables, first of all they are set to the values ​​of the number of white, black daisies and empty cells of the next zone.



Further, if the temperature for any type of daisies does not correspond to the living conditions, the corresponding parameter is reset. If it corresponds to the living conditions, the value remains unchanged. If the temperature is in the comfort interval, then the value is doubled. If for the first time the temperature has become suitable for life, for any type of daisies, the corresponding parameter is set to the arithmetic average of the number of corresponding daisies from adjacent zones.



Finally, you need to describe the Planet class update () method, which is responsible for the life cycle of each iteration:



 public void update() { albedo = albedoCalculator.calcAlbedo(zones); temperature = StephanBoltsman.countTemperature(albedo,star.getStarConstant()); updateLocalTempers(); populator.rePopulate(this); iterationId++; } 


First, the albedo of the planet is calculated based on the number and location of daisies. Then, the effective temperature of the planet is calculated using the albedo just found and the stellar constant (the value of which may also change). Then the values ​​of local temperatures in the zones are updated based on the found effective temperature. And in the end, using new data of local temperatures, redistribution of daisies is carried out.



Link to git Build: gradlew build

Source: https://habr.com/ru/post/341730/



All Articles