{"action":"created","issue":{"url":"https://api.github.com/repos/NGEET/fates/issues/443","repository_url":"https://api.github.com/repos/NGEET/fates","labels_url":"https://api.github.com/repos/NGEET/fates/issues/443/labels{/name}","comments_url":"https://api.github.com/repos/NGEET/fates/issues/443/comments","events_url":"https://api.github.com/repos/NGEET/fates/issues/443/events","html_url":"https://github.com/NGEET/fates/issues/443","id":379921410,"node_id":"MDU6SXNzdWUzNzk5MjE0MTA=","number":443,"title":"optimizing photosynthesis","user":{"login":"rgknox","id":5891980,"node_id":"MDQ6VXNlcjU4OTE5ODA=","avatar_url":"https://avatars2.githubusercontent.com/u/5891980?v=4","gravatar_id":"","url":"https://api.github.com/users/rgknox","html_url":"https://github.com/rgknox","followers_url":"https://api.github.com/users/rgknox/followers","following_url":"https://api.github.com/users/rgknox/following{/other_user}","gists_url":"https://api.github.com/users/rgknox/gists{/gist_id}","starred_url":"https://api.github.com/users/rgknox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rgknox/subscriptions","organizations_url":"https://api.github.com/users/rgknox/orgs","repos_url":"https://api.github.com/users/rgknox/repos","events_url":"https://api.github.com/users/rgknox/events{/privacy}","received_events_url":"https://api.github.com/users/rgknox/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2018-11-12T19:33:12Z","updated_at":"2018-11-28T22:16:31Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"@walkeranthonyp, Nathan Collier and I met up at the DOE Modeling PI meeting and had a fun discussion about improving the photosynthesis code.  @walkeranthonyp has some more fundamental ways to improve how we go about this process regarding which schemes we use and how the equations themselves are cast, and Nate was interested in how we actual perform out solve for C_i (interstitial CO2), which is an iterative loop converging on a solution to non-linear algebraic equations.\r\n\r\nSee here where we perform the iteration: https://github.com/NGEET/fates/blob/master/biogeophys/FatesPlantRespPhotosynthMod.F90#L992\r\n\r\nAn important note here, is that the photosynthesis scheme calculates stomatal conductance (among other things), which in-turn effects latent-heat transfer from the surface, which effects land-atmospheric stability, which should tightly feed-back on these fluxes again.  Thus, photosynthesis is called inside this broader iteration loop  (CLM/ELM side of code)  that seeks to converge on a stability parameter and land-fluxes with a low residual (change since last iteration).  Note: These coupled iteration loops make the search for C_i (and the quadratic root finders) the most often called subroutines in the model.  We cap this loop iteration at 5 steps currently.\r\n\r\nI wanted to diagnose how efficient our code is currently performing the solve for C_I, and see if there is any low-hanging fruit that can be picked to help speed things up and make it more efficient.  \r\n\r\nThe first thing I did was do some counting statistics to see the distributions of how many iterations are performed.  The following plot shows results from a 1 year simulation at BCI, using a forest inventory initialization. \r\n\r\nTop Left Panel: Histogram of counts needed to converge on the outer loop (stability parameter)\r\nTop Right Panel: Histogram of the final residuals in the C_i loop, using the existing formulation. The red-line is the residual error criteria for success\r\nBottom Left Panel: Histogram of an ALTERNATIVE way to formulate the residual in the C_i loop, assuming that the residual is the change in C_i from previous time-point, normalized by the canopy CO2 partial pressure.\r\nBottom Right Panel: Histogram of the number of inner loop counts for C_i (which is capped at 5. Spoiler alert, almost every single iteration attempt used up 5).  \r\n\r\n![quad-bci-v1](https://user-images.githubusercontent.com/5891980/48369174-a1c89880-e66a-11e8-8e74-54fed1a08a62.png)\r\n\r\nSo all iterations used up the max 5 attempts.  Also, it seemed that the residual is strangely formed.  Why is it the difference in C_i normalized by air-pressure and not CO2 partial pressure which should have the same units?  I can't rectify the units on the current formulation, it is pascals of partial pressure divided by atmospheric pressure * 1 million?  (maybe they thought that C_i was in units of PPM?)  But it seems incredibly strict, the residuals at completion (due to step-count maxed) are all way above the error limit.\r\n\r\nI was curious if there would be a significant shift in how many iterations were required, if I changed both the way the residual is formed, and gave it a lower success threshold of 1e-5.  The residual that is evaluated here is the change in C_i divided by air CO2 partial pressure (which are the same units Pa, and similar magnitudes). \r\n\r\n![quad-bci-v2](https://user-images.githubusercontent.com/5891980/48369541-b8bbba80-e66b-11e8-91a8-ce43876591f2.png)\r\n\r\nMy take home from this exercise is that by adjusting the form of the residual there is a very modest effect on how quickly it converges.  Keep in mind here that the physics was not changed, nor was the algorithm changed that searches for a solution.\r\n\r\nNate Collier did some calculations, and thinks that with Newton-Raphson, a solution should be found within 2-3 steps (I think), so I think that would be a worthwhile undertaking, as this would speed up the code. I have to look at the code more thoroughly, to see what method we use now (bracketing?) but it is not Newton-Raphson.\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/NGEET/fates/issues/comments/442625968","html_url":"https://github.com/NGEET/fates/issues/443#issuecomment-442625968","issue_url":"https://api.github.com/repos/NGEET/fates/issues/443","id":442625968,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MjYyNTk2OA==","user":{"login":"walkeranthonyp","id":4901605,"node_id":"MDQ6VXNlcjQ5MDE2MDU=","avatar_url":"https://avatars3.githubusercontent.com/u/4901605?v=4","gravatar_id":"","url":"https://api.github.com/users/walkeranthonyp","html_url":"https://github.com/walkeranthonyp","followers_url":"https://api.github.com/users/walkeranthonyp/followers","following_url":"https://api.github.com/users/walkeranthonyp/following{/other_user}","gists_url":"https://api.github.com/users/walkeranthonyp/gists{/gist_id}","starred_url":"https://api.github.com/users/walkeranthonyp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/walkeranthonyp/subscriptions","organizations_url":"https://api.github.com/users/walkeranthonyp/orgs","repos_url":"https://api.github.com/users/walkeranthonyp/repos","events_url":"https://api.github.com/users/walkeranthonyp/events{/privacy}","received_events_url":"https://api.github.com/users/walkeranthonyp/received_events","type":"User","site_admin":false},"created_at":"2018-11-28T22:16:31Z","updated_at":"2018-11-28T22:16:31Z","author_association":"NONE","body":"@dlawrenncar Thanks! \r\n"}}
{"actor":{"display_login":"walkeranthonyp"}}