tutorials:radiation-model-in-crop_model
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorials:radiation-model-in-crop_model [2025/05/27 15:00] – barley1965 | tutorials:radiation-model-in-crop_model [2025/06/03 08:42] (current) – barley1965 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ** Introducing light interception of leaves** | + | ====== |
- | 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. | + | //Open the file {{ :tutorials:Light.gsz |
- | 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, | + | 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, |
<code java> | <code java> | ||
Line 22: | Line 22: | ||
This light source has to be coupled with a light node so that we can move it around in the scene. The following code defines a light node: | This light source has to be coupled with a light node so that we can move it around in the scene. The following code defines a light node: | ||
+ | |||
+ | <code java> | ||
+ | //a module defining the light node: | ||
+ | module MyLight extends LightNode(0.0, | ||
+ | { setLight(new MyLamp());} | ||
+ | } | ||
+ | </ | ||
Note that we actually also give the emitted light a color with the constructor of light node: The three arguments are for red, green, and blue, and at the moment this gives all white light. However, as the LightNode is “masked” by the object MyLamp you have to comment it out to see the effect of changing the color in the LightNode: | Note that we actually also give the emitted light a color with the constructor of light node: The three arguments are for red, green, and blue, and at the moment this gives all white light. However, as the LightNode is “masked” by the object MyLamp you have to comment it out to see the effect of changing the color in the LightNode: | ||
- | Before: | + | |
+ | Before: | ||
+ | {{: | ||
+ | <code java> | ||
+ | //a module defining the light node: | ||
+ | module MyLight extends LightNode(0.0, | ||
+ | { setLight(new MyLamp()); | ||
+ | } | ||
+ | </ | ||
After: | After: | ||
+ | {{: | ||
+ | <code java> | ||
+ | //a module defining the light node: | ||
+ | module MyLight extends LightNode(0.0, | ||
+ | //{ setLight(new MyLamp());} | ||
+ | } | ||
+ | </ | ||
- | The lamp then has to be inserted into the scene, you do this inside the init() method: | + | The lamp then has to be inserted into the scene, you do this inside the '' |
+ | |||
+ | <code java> | ||
+ | protected void init() | ||
+ | [ | ||
+ | Axiom ==> //insert a plane here | ||
+ | [ Plane().(setShader(WHITE))] | ||
+ | |||
+ | Bud(1, PHYLLOCHRON, | ||
+ | //insert the lamp here | ||
+ | ==>> ^ M(50) RU(180) MyLight; | ||
+ | ] | ||
+ | </ | ||
- | Also, we want to insert a white plane into the scene so that the simulated plant is no longer “floating” in space but instead is rooted in the plane. The Plane object is inserted using its constructor, | + | Also, we want to insert a white plane into the scene so that the simulated plant is no longer “floating” in space but instead is rooted in the plane. The Plane object is inserted using its constructor, |
- | Then we have to invoke the radiation model of GroIMP, just before the init() method: | + | Then we have to invoke the radiation model of GroIMP, just before the '' |
- | + | ||
- | Furthermore, | + | <code java> |
+ | // | ||
+ | LightModel lm = new LightModel(100000, | ||
+ | </ | ||
+ | |||
+ | Furthermore, | ||
+ | |||
+ | <code java> | ||
+ | module Leaf(float al) extends Parallelogram(2, | ||
+ | {setShader(new AlgorithmSwitchShader(new RGBAShader(0, | ||
+ | } | ||
+ | </ | ||
Note that the shader of the leaf looks rather complicated: | Note that the shader of the leaf looks rather complicated: | ||
- | In the run method, the Leaf is initiated with al = 0, thus Leaf(0). | + | |
+ | In the run method, the Leaf is initiated with '' | ||
+ | |||
+ | <code java> | ||
+ | Bud(r, p, o), (r < 10 && p == 0 && o < 4) ==> RV(-0.1) Internode Node | ||
+ | [RL(BRANCH_ANGLE) Bud(r, PHYLLOCHRON, | ||
+ | RH(GOLDEN_ANGLE) RV(-0.1) Internode Bud(r+1, PHYLLOCHRON, | ||
+ | </ | ||
- | Furthermore, | + | Furthermore, |
+ | |||
+ | <code java> | ||
+ | //the new protected method absorb() | ||
+ | protected void absorb() | ||
+ | [ | ||
+ | lf:Leaf ::> {lf[al] = lm.getAbsorbedPower3d(lf).integrate()*2.25; | ||
+ | // | ||
+ | |||
+ | } | ||
+ | ] | ||
+ | </ | ||
- | 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 |
- | 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 | ||
+ | |||
+ | <code java> | ||
+ | //the new public method grow() | ||
+ | public void grow() | ||
+ | { | ||
+ | run(); | ||
+ | lm.compute(); | ||
+ | absorb(); | ||
+ | } | ||
+ | </ | ||
- | This method invokes run () once, then runs the light model (lm.compute()), | + | This method invokes |
- | 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 '' |
+ | |||
+ | <code java> | ||
+ | //the new protected method absorb() | ||
+ | protected void absorb() | ||
+ | [ | ||
+ | lf:Leaf ::> {lf[al] = lm.getAbsorbedPower3d(lf).integrate()*2.25; | ||
+ | // | ||
+ | lf.(setShader(new AlgorithmSwitchShader(new RGBAShader(lf[al]/ | ||
+ | } | ||
+ | ] | ||
+ | </ | ||
- | 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 '' |
- | 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.1748350856.txt.gz · Last modified: 2025/05/27 15:00 by barley1965