User Tools

Site Tools


tutorials:radiation-model-in-crop_model

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorials:radiation-model-in-crop_model [2025/05/27 15:36] barley1965tutorials:radiation-model-in-crop_model [2025/06/03 08:42] (current) barley1965
Line 1: Line 1:
 ====== Introducing light interception of leaves ====== ====== Introducing light interception of leaves ======
  
- +//Open the file {{ :tutorials:Light.gsz |Light.gsz}}.// This is a simple model of a plant that will grow (produce new leaves and internodes) and branch, while each leaf intercepts light from a lamp hanging over it.  
- +One of the first things that come to mind when thinking about plant functions is, of course, photosynthesis. In order for the plant to do photosynthesis, it needs energy, water and CO<sub>2</sub>. Thus, first, some plant parts (normally the leaves), need to intercept and absorb light and transfer part of the energy gained from this process onto specialized molecules. Let us first look at light capture: There are several ways to model this. The nice thing about a 3D model is that we have information about the position of each leaf. We further have information about the position of light sources. To model the light environment in our 3D scene, we first have to create a light source. The following code defines a new lamp:
-Open the file //Light.gsz//This is a simple model of a plant that will grow (produce new leaves and internodes) and branch, while each leaf intercepts light from a lamp hanging over it.  +
-One of the first things that come to mind when thinking about plant functions is, of course, photosynthesis. In order for the plant to do photosynthesis, it needs energy, water and CO2. Thus, first, some plant parts (normally the leaves), need to intercept and absorb light and transfer part of the energy gained from this process onto specialized molecules. Let us first look at light capture: There are several ways to model this. The nice thing about a 3D model is that we have information about the position of each leaf. We further have information about the position of light sources. To model the light environment in our 3D scene, we first have to create a light source. The following code defines a new lamp:+
  
 <code java> <code java>
Line 94: Line 92:
 </code> </code>
    
-Furthermore, we have to introduce a new method, absorb(), which will invoke a method of the radiation model that measures the amount of absorbed light for each leaf and writes the result to the parameter al (you can write this method after the run method):+Furthermore, we have to introduce a new method,'' absorb()'', which will invoke a method of the radiation model that measures the amount of absorbed light for each leaf and writes the result to the parameter ''al'' (you can write this method after the run method): 
 + 
 +<code java> 
 +//the new protected method absorb() 
 +protected void absorb() 
 +
 + lf:Leaf ::> {lf[al] = lm.getAbsorbedPower3d(lf).integrate()*2.25; 
 + //println(lf[al]); 
 +  
 +
 +
 +</code>
    
-The rule in this method updates the parameter al of Leaf, by letting the LightModel instance lm calculate the absorbed power. As this is done separately for red, green, and blue light, we have to also invoke integrate() and multiply by a factor 2.25 to convert from W to µmol photons (the input later for the photosynthesis model). In order to see immediately how much light a leaf has absorbed we can use a println() command, it will print out the value of lf[al] into the XL console window below, however, at the moment it is commented out. Note that the println command will go to the next line after printing while a simple print command would stay on the same line.  +The rule in this method updates the parameter ''al'' of ''Leaf'', by letting the LightModel instance ''lm'' calculate the absorbed power. As this is done separately for red, green, and blue light, we have to also invoke ''integrate()'' and multiply by a factor 2.25 to convert from W to µmol photons (the input later for the photosynthesis model). In order to see immediately how much light a leaf has absorbed we can use a ''println()'' command, it will print out the value of ''lf[al]'' into the XL console window below, however, at the moment it is commented out. Note that the ''println'' command will go to the next line after printing while a simple ''print'' command would stay on the same line.  
-Note that we make this method protected (like the run() method is now), because we are not going to invoke absorb() or run() directly but from another method that we will call grow():+ 
 +Note that we make this method ''protected'' (like the ''run()'' method is now), because we are not going to invoke ''absorb()'' or ''run()'' directly but from another method that we will call ''grow()'': 
 + 
 +<code java> 
 +//the new public method grow() 
 +public void grow() 
 +
 + run(); 
 + lm.compute(); 
 + absorb(); 
 +
 +</code>
    
-This method invokes run () once, then runs the light model (lm.compute()), then the rule absorb() which measures light. We are thus dealing here with a method that does not contain L-system rules itself but that will instead invoke other methods containing L-systems. Note that this is the reason why the body of the method is surrounded by a pair of curly braces (accolades), { and }, and not square brackets, [ and ], as we know it from methods containing L-system rules.  +This method invokes ''run()'' once, then runs the light model (''lm.compute()''), then the rule ''absorb()'', which measures light. We are thus dealing here with a method that does not contain L-system rules itself but that will instead invoke other methods containing L-systems. Note that this is the reason why the body of the method is surrounded by a pair of curly braces (accolades), ''{'' and ''}'', and not square brackets, ''['' and '']'', as we know it from methods containing L-system rules.  
-Next, we have to add in the absorb() method a command that will reset the shader of the leaf each time the method is carried out: +Next, we have to add in the ''absorb()'' method a command that will reset the shader of the leaf each time the method is carried out:  
 + 
 +<code java> 
 +//the new protected method absorb() 
 +protected void absorb() 
 +
 + lf:Leaf ::> {lf[al] = lm.getAbsorbedPower3d(lf).integrate()*2.25; 
 + //println(lf[al]); 
 + lf.(setShader(new AlgorithmSwitchShader(new RGBAShader(lf[al]/5.0,lf[al]*2,lf[al]/100.0), GREEN))); 
 +
 +
 +</code>
    
-Note that the shader of each leaf is now reset using the value of al to paint the leaf, thereby indicating the amount of absorbed light, a gradient of green. +Note that the shader of each leaf is now reset using the value of ''al'' to paint the leaf, thereby indicating the amount of absorbed light, a gradient of green. 
-Task: Do some simulations with different plant parameters (L. 60 – 63, e.g., you could change the phyllochron). Manually change the position of the lamp by selecting it in the scene and dragging it at one of the arrow tips. This can be done during the simulation. Observe the effect on light interception of the leaves. + 
 +//Task: Do some simulations with different plant parameters (L. 60 – 63, e.g., you could change the phyllochron). Manually change the position of the lamp by selecting it in the scene and dragging it at one of the arrow tips. This can be done during the simulation. Observe the effect on light interception of the leaves.// 
        
  
  
tutorials/radiation-model-in-crop_model.1748353012.txt.gz · Last modified: 2025/05/27 15:36 by barley1965