<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://ascend4.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Karthik0112358</id>
	<title>ASCEND - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://ascend4.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Karthik0112358"/>
	<link rel="alternate" type="text/html" href="https://ascend4.org/Special:Contributions/Karthik0112358"/>
	<updated>2026-04-28T22:09:05Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=3061</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=3061"/>
		<updated>2011-08-26T03:32:26Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on adding the Mass Matrix functionality in Radau5 Solver for ASCEND during [[GSOC2011]].&lt;br /&gt;
&lt;br /&gt;
Code branch: {{srcbranchdir|karthik|}} &lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# Evaluation of mass matrix for a wide range of systems of equations, in the form of a set of CUnit test cases:&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Accepting all equations and creating a mass matrix of correct dimensions.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying all derivatives in an equation.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Finding the real values of derivative variables.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying the derivatives using these real values.&amp;lt;/strike&amp;gt; &lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Checking if the equation is linear with respect to the derivatives.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of the derivative contains another variable which is not fixed.&amp;lt;/strike&amp;gt; &lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is raised to a power other than 1.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is in the denominator.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is present in the index of any term.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is inside a function.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of derivative contains a function.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Display corresponding error messages.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating the coefficient.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating a base coefficient to the derivative.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Compounding the base coefficient while processing terms in the equation.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Processing the coefficients and entering them to the mass matrix.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## Test with CUnit.&lt;br /&gt;
# Complete DAE solution of those solutions using RADAU5.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;August 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Example of mass matrix for DAE. &lt;br /&gt;
&lt;br /&gt;
[[File:Demonstration of Mass Matrix for DAE.png]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 22&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added some screen shots:&lt;br /&gt;
&lt;br /&gt;
[[File:Computing Coefficient.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Derivative in index.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Derivative raised to power.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Non-Constant_coefficients.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Check_in_Denominator.png]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote [http://ascend4.org/User:Karthik0112358/test_radau5 test_radau5.c]. Working on some issues.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 15&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* CUnit up and running.&lt;br /&gt;
* Code completed for writing mass matrix, adding comments and checking if I missed any cases. Only integrating to Radau5 left.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 4&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have completed writing the function which evaluates the coefficient after confirming the equation is linear with respect to the derivatives. Code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. Hence Goal 1.4 complete.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 31&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
More added to [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Was not able to commit to svn due to current LAN problems at college. Will commit tomorrow. For now here is the code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 14&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote code for catching errors in equation where the derivative is raised to a higher/lower power. This was part of Goal 1.3.2. Svn committed the code: http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 13&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have come up with a simplified algorithm for Goal 1.4.2 after going through the code which simplifies equations. Will try to implement it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;br /&gt;
[[Category:ASCEND Contributors]]&lt;br /&gt;
&lt;br /&gt;
== Mathematical note on my project ==&lt;br /&gt;
&lt;br /&gt;
* RADAU5 is used to find numerical solutions for a stiff (or differential algebraic) system of first order ordinary differential equations. &lt;br /&gt;
* Problems must be of the form &amp;lt;math&amp;gt;\mathrm{M} \mathbf{y^{&#039;}} = \mathbf{f} \left(\mathbf{t},\mathbf{y} \right)&amp;lt;/math&amp;gt; with possibly singular matrix &amp;lt;math&amp;gt;\mathrm{M}&amp;lt;/math&amp;gt;. Any solution to this equation is a function &amp;lt;math&amp;gt;\mathbf{u} \left(\mathbf{t} \right)&amp;lt;/math&amp;gt; satisfying &amp;lt;math&amp;gt;\mathrm{M} \mathbf{u^{&#039;}\left(\mathbf{t} \right)} = \mathbf{f} \left(\mathbf{t},\mathbf{u\left(\mathbf{t} \right)} \right)&amp;lt;/math&amp;gt;.&lt;br /&gt;
* An implicit Runge-Kutta method of order 5 (Radau IIA) is implemented to solve problems.&lt;br /&gt;
* We refer to &amp;lt;math&amp;gt;\mathrm{M}&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;\mathrm{M} \mathbf{y^{&#039;}} = \mathbf{f} \left(\mathbf{t},\mathbf{y} \right)&amp;lt;/math&amp;gt;, as the Mass Matrix for the set of equations. &lt;br /&gt;
* If the dimension of the Mass Matrix, &amp;lt;math&amp;gt;\mathrm{M}&amp;lt;/math&amp;gt; is &#039;&#039;a&#039;&#039;x&#039;&#039;b&#039;&#039; (i.e. &#039;&#039;a&#039;&#039; rows and &#039;&#039;b&#039;&#039; columns) then &#039;&#039;a&#039;&#039; is equal to the number of equations and &#039;&#039;b&#039;&#039; is equal to the dimension of vector space in which &#039;&#039;y(t)&#039;&#039; lies.&lt;br /&gt;
* Let &#039;&#039;m&#039;&#039;&amp;lt;sub&amp;gt;ij&amp;lt;/sub&amp;gt; be the element at the &#039;&#039;m&#039;&#039;&amp;lt;sup&amp;gt;th&amp;lt;/sup&amp;gt; row and &#039;&#039;n&#039;&#039;&amp;lt;sup&amp;gt;th&amp;lt;/sup&amp;gt; column of Mass Matrix &amp;lt;math&amp;gt;\mathrm{M}&amp;lt;/math&amp;gt;. So &#039;&#039;m&#039;&#039;&amp;lt;sub&amp;gt;ij&amp;lt;/sub&amp;gt; are the coefficients of the derivative operators in the set of Differential Algebraic equations. Note that every &#039;&#039;m&#039;&#039;&amp;lt;sub&amp;gt;ij&amp;lt;/sub&amp;gt; has to be a constant. &lt;br /&gt;
* Initial data and the set of equations are accepted through ascend model files and the mass matrix is calculated (ONCE).&lt;br /&gt;
* The solutions are determined in a neighborhood of the initial input time by RADAU5 solver.&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=3060</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=3060"/>
		<updated>2011-08-25T15:40:48Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Mathematical note on my project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;August 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Example of mass matrix for DAE. &lt;br /&gt;
&lt;br /&gt;
[[File:Demonstration of Mass Matrix for DAE.png]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 22&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added some screen shots:&lt;br /&gt;
&lt;br /&gt;
[[File:Computing Coefficient.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Derivative in index.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Derivative raised to power.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Non-Constant_coefficients.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Check_in_Denominator.png]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote [http://ascend4.org/User:Karthik0112358/test_radau5 test_radau5.c]. Working on some issues.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 15&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* CUnit up and running.&lt;br /&gt;
* Code completed for writing mass matrix, adding comments and checking if I missed any cases. Only integrating to Radau5 left.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 4&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have completed writing the function which evaluates the coefficient after confirming the equation is linear with respect to the derivatives. Code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. Hence Goal 1.4 complete.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 31&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
More added to [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Was not able to commit to svn due to current LAN problems at college. Will commit tomorrow. For now here is the code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 14&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote code for catching errors in equation where the derivative is raised to a higher/lower power. This was part of Goal 1.3.2. Svn committed the code: http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 13&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have come up with a simplified algorithm for Goal 1.4.2 after going through the code which simplifies equations. Will try to implement it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;br /&gt;
[[Category:ASCEND Contributors]]&lt;br /&gt;
&lt;br /&gt;
== Mathematical note on my project ==&lt;br /&gt;
&lt;br /&gt;
* RADAU5 is used to find numerical solutions for a stiff (or differential algebraic) system of first order ordinary differential equations. &lt;br /&gt;
* Problems must be of the form &amp;lt;math&amp;gt;\mathrm{M} \mathbf{y^{&#039;}} = \mathbf{f} \left(\mathbf{t},\mathbf{y} \right)&amp;lt;/math&amp;gt; with possibly singular matrix &amp;lt;math&amp;gt;\mathrm{M}&amp;lt;/math&amp;gt;. Any solution to this equation is a function &amp;lt;math&amp;gt;\mathbf{u} \left(\mathbf{t} \right)&amp;lt;/math&amp;gt; satisfying &amp;lt;math&amp;gt;\mathrm{M} \mathbf{u^{&#039;}\left(\mathbf{t} \right)} = \mathbf{f} \left(\mathbf{t},\mathbf{u\left(\mathbf{t} \right)} \right)&amp;lt;/math&amp;gt;.&lt;br /&gt;
* An implicit Runge-Kutta method of order 5 (Radau IIA) is implemented to solve problems.&lt;br /&gt;
* We refer to &amp;lt;math&amp;gt;\mathrm{M}&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;\mathrm{M} \mathbf{y^{&#039;}} = \mathbf{f} \left(\mathbf{t},\mathbf{y} \right)&amp;lt;/math&amp;gt;, as the Mass Matrix for the set of equations. &lt;br /&gt;
* If the dimension of the Mass Matrix, &amp;lt;math&amp;gt;\mathrm{M}&amp;lt;/math&amp;gt; is &#039;&#039;a&#039;&#039;x&#039;&#039;b&#039;&#039; (i.e. &#039;&#039;a&#039;&#039; rows and &#039;&#039;b&#039;&#039; columns) then &#039;&#039;a&#039;&#039; is equal to the number of equations and &#039;&#039;b&#039;&#039; is equal to the dimension of vector space in which &#039;&#039;y(t)&#039;&#039; lies.&lt;br /&gt;
* Let &#039;&#039;m&#039;&#039;&amp;lt;sub&amp;gt;ij&amp;lt;/sub&amp;gt; be the element at the &#039;&#039;m&#039;&#039;&amp;lt;sup&amp;gt;th&amp;lt;/sup&amp;gt; row and &#039;&#039;n&#039;&#039;&amp;lt;sup&amp;gt;th&amp;lt;/sup&amp;gt; column of Mass Matrix &amp;lt;math&amp;gt;\mathrm{M}&amp;lt;/math&amp;gt;. So &#039;&#039;m&#039;&#039;&amp;lt;sub&amp;gt;ij&amp;lt;/sub&amp;gt; are the coefficients of the derivative operators in the set of Differential Algebraic equations. Note that every &#039;&#039;m&#039;&#039;&amp;lt;sub&amp;gt;ij&amp;lt;/sub&amp;gt; has to be a constant. &lt;br /&gt;
* Initial data and the set of equations are accepted through ascend model files and the mass matrix is calculated (ONCE).&lt;br /&gt;
* The solutions are determined in a neighborhood of the initial input time by RADAU5 solver.&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=3059</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=3059"/>
		<updated>2011-08-25T15:39:29Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;August 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Example of mass matrix for DAE. &lt;br /&gt;
&lt;br /&gt;
[[File:Demonstration of Mass Matrix for DAE.png]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 22&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added some screen shots:&lt;br /&gt;
&lt;br /&gt;
[[File:Computing Coefficient.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Derivative in index.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Derivative raised to power.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Non-Constant_coefficients.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Check_in_Denominator.png]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote [http://ascend4.org/User:Karthik0112358/test_radau5 test_radau5.c]. Working on some issues.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 15&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* CUnit up and running.&lt;br /&gt;
* Code completed for writing mass matrix, adding comments and checking if I missed any cases. Only integrating to Radau5 left.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 4&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have completed writing the function which evaluates the coefficient after confirming the equation is linear with respect to the derivatives. Code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. Hence Goal 1.4 complete.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 31&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
More added to [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Was not able to commit to svn due to current LAN problems at college. Will commit tomorrow. For now here is the code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 14&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote code for catching errors in equation where the derivative is raised to a higher/lower power. This was part of Goal 1.3.2. Svn committed the code: http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 13&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have come up with a simplified algorithm for Goal 1.4.2 after going through the code which simplifies equations. Will try to implement it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;br /&gt;
[[Category:ASCEND Contributors]]&lt;br /&gt;
&lt;br /&gt;
== Mathematical note on my project ==&lt;br /&gt;
&lt;br /&gt;
* RADAU5 is used to find numerical solutions for a stiff (or differential algebraic) system of first order ordinary differential equations. &lt;br /&gt;
* Problems must be of the form &amp;lt;math&amp;gt;\mathrm{M} \mathbf{y^{&#039;}} = \mathbf{f} \left(\mathbf{t},\mathbf{y} \right)&amp;lt;/math&amp;gt; with possibly singular matrix &amp;lt;math&amp;gt;\mathrm{M}&amp;lt;/math&amp;gt;. Any solution to this equation is a function &amp;lt;math&amp;gt;\mathbf{u} \left(\mathbf{t} \right)&amp;lt;/math&amp;gt; satisfying &amp;lt;math&amp;gt;\mathrm{M} \mathbf{u^{&#039;}\left(\mathbf{t} \right)} = \mathbf{f} \left(\mathbf{t},\mathbf{u\left(\mathbf{t} \right)} \right)&amp;lt;/math&amp;gt;.&lt;br /&gt;
* An implicit Runge-Kutta method of order 5 (Radau IIA) is implemented to solve problems.&lt;br /&gt;
* We refer to &amp;lt;math&amp;gt;\mathrm{M}&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;\mathrm{M} \mathbf{y^{&#039;}} = \mathbf{f} \left(\mathbf{t},\mathbf{y} \right)&amp;lt;/math&amp;gt;, as the Mass Matrix for the set of equations. &lt;br /&gt;
* If the dimension of the Mass Matrix, &amp;lt;math&amp;gt;\mathrm{M}&amp;lt;/math&amp;gt; is &#039;&#039;a&#039;&#039;x&#039;&#039;b&#039;&#039; (i.e. &#039;&#039;a&#039;&#039; rows and &#039;&#039;b&#039;&#039; columns) then &#039;&#039;a&#039;&#039; is equal to the number of equations and &#039;&#039;b&#039;&#039; is equal to the dimension of vector space in which &#039;&#039;y(t)&#039;&#039; lies.&lt;br /&gt;
* Let &#039;&#039;m&#039;&#039;&amp;lt;sub&amp;gt;ij&amp;lt;/sub&amp;gt; be the element at the &#039;&#039;m&#039;&#039;&amp;lt;sup&amp;gt;th&amp;lt;/sup&amp;gt; row and &#039;&#039;n&#039;&#039;&amp;lt;sup&amp;gt;th&amp;lt;/sup&amp;gt; column of Mass Matrix &amp;lt;math&amp;gt;\mathrm{M}&amp;lt;/math&amp;gt;. So &#039;&#039;m&#039;&#039;&amp;lt;sub&amp;gt;ij&amp;lt;/sub&amp;gt; are the coefficients of the derivative operators in the set of Differential Algebraic equations. Note that every &#039;&#039;m&#039;&#039;&amp;lt;sub&amp;gt;ij&amp;lt;/sub&amp;gt; has to be a constant. &lt;br /&gt;
* Initial data and the set of equations are accepted through ascend model files and the mass matrix is calculated.&lt;br /&gt;
* The solutions are determined in a neighborhood of the initial input time by RADAU5 solver.&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=File:Demonstration_of_Mass_Matrix_for_DAE.png&amp;diff=3057</id>
		<title>File:Demonstration of Mass Matrix for DAE.png</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=File:Demonstration_of_Mass_Matrix_for_DAE.png&amp;diff=3057"/>
		<updated>2011-08-24T22:36:00Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=3056</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=3056"/>
		<updated>2011-08-24T22:35:23Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on adding the Mass Matrix functionality in Radau5 Solver for ASCEND during [[GSOC2011]].&lt;br /&gt;
&lt;br /&gt;
Code branch: {{srcbranchdir|karthik|}} &lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# Evaluation of mass matrix for a wide range of systems of equations, in the form of a set of CUnit test cases:&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Accepting all equations and creating a mass matrix of correct dimensions.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying all derivatives in an equation.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Finding the real values of derivative variables.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying the derivatives using these real values.&amp;lt;/strike&amp;gt; &lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Checking if the equation is linear with respect to the derivatives.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of the derivative contains another variable which is not fixed.&amp;lt;/strike&amp;gt; &lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is raised to a power other than 1.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is in the denominator.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is present in the index of any term.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is inside a function.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of derivative contains a function.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Display corresponding error messages.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating the coefficient.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating a base coefficient to the derivative.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Compounding the base coefficient while processing terms in the equation.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Processing the coefficients and entering them to the mass matrix.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## Test with CUnit.&lt;br /&gt;
# Complete DAE solution of those solutions using RADAU5.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;August 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Example of mass matrix for DAE. &lt;br /&gt;
&lt;br /&gt;
[[File:Demonstration of Mass Matrix for DAE.png]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 22&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added some screen shots:&lt;br /&gt;
&lt;br /&gt;
[[File:Computing Coefficient.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Derivative in index.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Derivative raised to power.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Non-Constant_coefficients.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Check_in_Denominator.png]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote [http://ascend4.org/User:Karthik0112358/test_radau5 test_radau5.c]. Working on some issues.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 15&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* CUnit up and running.&lt;br /&gt;
* Code completed for writing mass matrix, adding comments and checking if I missed any cases. Only integrating to Radau5 left.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 4&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have completed writing the function which evaluates the coefficient after confirming the equation is linear with respect to the derivatives. Code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. Hence Goal 1.4 complete.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 31&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
More added to [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Was not able to commit to svn due to current LAN problems at college. Will commit tomorrow. For now here is the code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 14&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote code for catching errors in equation where the derivative is raised to a higher/lower power. This was part of Goal 1.3.2. Svn committed the code: http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 13&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have come up with a simplified algorithm for Goal 1.4.2 after going through the code which simplifies equations. Will try to implement it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;br /&gt;
[[Category:ASCEND Contributors]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=File:Check_in_Denominator.png&amp;diff=3039</id>
		<title>File:Check in Denominator.png</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=File:Check_in_Denominator.png&amp;diff=3039"/>
		<updated>2011-08-22T23:35:18Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: uploaded a new version of &amp;quot;File:Check in Denominator.png&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=3038</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=3038"/>
		<updated>2011-08-22T23:23:17Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on adding the Mass Matrix functionality in Radau5 Solver for ASCEND during [[GSOC2011]].&lt;br /&gt;
&lt;br /&gt;
Code branch: {{srcbranchdir|karthik|}} &lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# Evaluation of mass matrix for a wide range of systems of equations, in the form of a set of CUnit test cases:&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Accepting all equations and creating a mass matrix of correct dimensions.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying all derivatives in an equation.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Finding the real values of derivative variables.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying the derivatives using these real values.&amp;lt;/strike&amp;gt; &lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Checking if the equation is linear with respect to the derivatives.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of the derivative contains another variable which is not fixed.&amp;lt;/strike&amp;gt; &lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is raised to a power other than 1.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is in the denominator.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is present in the index of any term.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is inside a function.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of derivative contains a function.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Display corresponding error messages.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating the coefficient.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating a base coefficient to the derivative.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Compounding the base coefficient while processing terms in the equation.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Processing the coefficients and entering them to the mass matrix.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## Test with CUnit.&lt;br /&gt;
# Complete DAE solution of those solutions using RADAU5.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;August 22&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added some screen shots:&lt;br /&gt;
&lt;br /&gt;
[[File:Computing Coefficient.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Derivative in index.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Derivative raised to power.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Non-Constant_coefficients.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Check_in_Denominator.png]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote [http://ascend4.org/User:Karthik0112358/test_radau5 test_radau5.c]. Working on some issues.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 15&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* CUnit up and running.&lt;br /&gt;
* Code completed for writing mass matrix, adding comments and checking if I missed any cases. Only integrating to Radau5 left.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 4&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have completed writing the function which evaluates the coefficient after confirming the equation is linear with respect to the derivatives. Code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. Hence Goal 1.4 complete.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 31&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
More added to [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Was not able to commit to svn due to current LAN problems at college. Will commit tomorrow. For now here is the code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 14&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote code for catching errors in equation where the derivative is raised to a higher/lower power. This was part of Goal 1.3.2. Svn committed the code: http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 13&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have come up with a simplified algorithm for Goal 1.4.2 after going through the code which simplifies equations. Will try to implement it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;br /&gt;
[[Category:ASCEND Contributors]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=File:Check_in_Denominator.png&amp;diff=3037</id>
		<title>File:Check in Denominator.png</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=File:Check_in_Denominator.png&amp;diff=3037"/>
		<updated>2011-08-22T23:22:57Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=File:Non-Constant_coefficients.png&amp;diff=3036</id>
		<title>File:Non-Constant coefficients.png</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=File:Non-Constant_coefficients.png&amp;diff=3036"/>
		<updated>2011-08-22T23:22:27Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=File:Derivative_raised_to_power.png&amp;diff=3035</id>
		<title>File:Derivative raised to power.png</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=File:Derivative_raised_to_power.png&amp;diff=3035"/>
		<updated>2011-08-22T23:21:42Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=File:Derivative_in_index.png&amp;diff=3034</id>
		<title>File:Derivative in index.png</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=File:Derivative_in_index.png&amp;diff=3034"/>
		<updated>2011-08-22T23:19:58Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: Detects if derivative is present in index.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Detects if derivative is present in index.&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=3033</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=3033"/>
		<updated>2011-08-22T23:16:24Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on adding the Mass Matrix functionality in Radau5 Solver for ASCEND during [[GSOC2011]].&lt;br /&gt;
&lt;br /&gt;
Code branch: {{srcbranchdir|karthik|}} &lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# Evaluation of mass matrix for a wide range of systems of equations, in the form of a set of CUnit test cases:&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Accepting all equations and creating a mass matrix of correct dimensions.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying all derivatives in an equation.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Finding the real values of derivative variables.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying the derivatives using these real values.&amp;lt;/strike&amp;gt; &lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Checking if the equation is linear with respect to the derivatives.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of the derivative contains another variable which is not fixed.&amp;lt;/strike&amp;gt; &lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is raised to a power other than 1.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is in the denominator.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is present in the index of any term.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is inside a function.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of derivative contains a function.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Display corresponding error messages.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating the coefficient.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating a base coefficient to the derivative.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Compounding the base coefficient while processing terms in the equation.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Processing the coefficients and entering them to the mass matrix.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## Test with CUnit.&lt;br /&gt;
# Complete DAE solution of those solutions using RADAU5.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;August 22&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added some screen shots:&lt;br /&gt;
&lt;br /&gt;
[[File:Computing Coefficient.png]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote [http://ascend4.org/User:Karthik0112358/test_radau5 test_radau5.c]. Working on some issues.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 15&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* CUnit up and running.&lt;br /&gt;
* Code completed for writing mass matrix, adding comments and checking if I missed any cases. Only integrating to Radau5 left.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 4&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have completed writing the function which evaluates the coefficient after confirming the equation is linear with respect to the derivatives. Code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. Hence Goal 1.4 complete.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 31&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
More added to [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Was not able to commit to svn due to current LAN problems at college. Will commit tomorrow. For now here is the code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 14&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote code for catching errors in equation where the derivative is raised to a higher/lower power. This was part of Goal 1.3.2. Svn committed the code: http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 13&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have come up with a simplified algorithm for Goal 1.4.2 after going through the code which simplifies equations. Will try to implement it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;br /&gt;
[[Category:ASCEND Contributors]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=3032</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=3032"/>
		<updated>2011-08-22T23:15:36Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on adding the Mass Matrix functionality in Radau5 Solver for ASCEND during [[GSOC2011]].&lt;br /&gt;
&lt;br /&gt;
Code branch: {{srcbranchdir|karthik|}} &lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# Evaluation of mass matrix for a wide range of systems of equations, in the form of a set of CUnit test cases:&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Accepting all equations and creating a mass matrix of correct dimensions.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying all derivatives in an equation.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Finding the real values of derivative variables.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying the derivatives using these real values.&amp;lt;/strike&amp;gt; &lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Checking if the equation is linear with respect to the derivatives.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of the derivative contains another variable which is not fixed.&amp;lt;/strike&amp;gt; &lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is raised to a power other than 1.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is in the denominator.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is present in the index of any term.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is inside a function.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of derivative contains a function.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Display corresponding error messages.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating the coefficient.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating a base coefficient to the derivative.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Compounding the base coefficient while processing terms in the equation.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Processing the coefficients and entering them to the mass matrix.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## Test with CUnit.&lt;br /&gt;
# Complete DAE solution of those solutions using RADAU5.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;August 22&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added some screen shots:&lt;br /&gt;
&lt;br /&gt;
[[File:Demonstration of Computation of Mass Matrix - Computing Coefficient.png]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote [http://ascend4.org/User:Karthik0112358/test_radau5 test_radau5.c]. Working on some issues.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 15&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* CUnit up and running.&lt;br /&gt;
* Code completed for writing mass matrix, adding comments and checking if I missed any cases. Only integrating to Radau5 left.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 4&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have completed writing the function which evaluates the coefficient after confirming the equation is linear with respect to the derivatives. Code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. Hence Goal 1.4 complete.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 31&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
More added to [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Was not able to commit to svn due to current LAN problems at college. Will commit tomorrow. For now here is the code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 14&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote code for catching errors in equation where the derivative is raised to a higher/lower power. This was part of Goal 1.3.2. Svn committed the code: http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 13&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have come up with a simplified algorithm for Goal 1.4.2 after going through the code which simplifies equations. Will try to implement it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;br /&gt;
[[Category:ASCEND Contributors]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=File:Computing_Coefficient.png&amp;diff=3031</id>
		<title>File:Computing Coefficient.png</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=File:Computing_Coefficient.png&amp;diff=3031"/>
		<updated>2011-08-22T23:14:18Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: This computes the Mass matrix, provided linearity in derivatives across all equations.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This computes the Mass matrix, provided linearity in derivatives across all equations.&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=3030</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=3030"/>
		<updated>2011-08-22T23:05:22Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on adding the Mass Matrix functionality in Radau5 Solver for ASCEND during [[GSOC2011]].&lt;br /&gt;
&lt;br /&gt;
Code branch: {{srcbranchdir|karthik|}} &lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# Evaluation of mass matrix for a wide range of systems of equations, in the form of a set of CUnit test cases:&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Accepting all equations and creating a mass matrix of correct dimensions.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying all derivatives in an equation.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Finding the real values of derivative variables.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying the derivatives using these real values.&amp;lt;/strike&amp;gt; &lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Checking if the equation is linear with respect to the derivatives.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of the derivative contains another variable which is not fixed.&amp;lt;/strike&amp;gt; &lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is raised to a power other than 1.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is in the denominator.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is present in the index of any term.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is inside a function.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of derivative contains a function.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Display corresponding error messages.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating the coefficient.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating a base coefficient to the derivative.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Compounding the base coefficient while processing terms in the equation.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Processing the coefficients and entering them to the mass matrix.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## Test with CUnit.&lt;br /&gt;
# Complete DAE solution of those solutions using RADAU5.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;August 22&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added some screen shots:&lt;br /&gt;
[[File:PyGTK Study - 15.png]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote [http://ascend4.org/User:Karthik0112358/test_radau5 test_radau5.c]. Working on some issues.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 15&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* CUnit up and running.&lt;br /&gt;
* Code completed for writing mass matrix, adding comments and checking if I missed any cases. Only integrating to Radau5 left.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 4&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have completed writing the function which evaluates the coefficient after confirming the equation is linear with respect to the derivatives. Code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. Hence Goal 1.4 complete.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 31&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
More added to [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Was not able to commit to svn due to current LAN problems at college. Will commit tomorrow. For now here is the code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 14&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote code for catching errors in equation where the derivative is raised to a higher/lower power. This was part of Goal 1.3.2. Svn committed the code: http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 13&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have come up with a simplified algorithm for Goal 1.4.2 after going through the code which simplifies equations. Will try to implement it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;br /&gt;
[[Category:ASCEND Contributors]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358/test_radau5&amp;diff=3012</id>
		<title>User:Karthik0112358/test radau5</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358/test_radau5&amp;diff=3012"/>
		<updated>2011-08-19T23:22:58Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;ascend/general/env.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/general/ospath.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/general/list.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/general/ltmatrix.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;ascend/general/platform.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/utilities/ascEnvVar.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/utilities/error.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;ascend/compiler/ascCompiler.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/module.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/parser.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/library.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/symtab.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/simlist.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/instquery.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/parentchild.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/atomvalue.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/reverse_ad.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/mathinst.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/watchpt.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/initialize.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/name.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/visitinst.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/functype.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/safe.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/qlfdid.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/instance_io.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;ascend/compiler/slvreq.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;ascend/system/system.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/system/slv_client.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/solver/solver.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/system/slv_server.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/system/slv_param.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/integrator/integrator.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;test/common.h&amp;gt;&lt;br /&gt;
/* Help taken from Shrikanth */&lt;br /&gt;
/* a simple integrator reporter for testing */&lt;br /&gt;
int test_radau5_reporter_init(struct IntegratorSystemStruct *integ){&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int test_radau5_reporter_write(struct IntegratorSystemStruct *integ){&lt;br /&gt;
	return 0; /* no interrupt */&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int test_radau5_reporter_writeobs(struct IntegratorSystemStruct *integ){&lt;br /&gt;
	CONSOLE_DEBUG(&amp;quot;x = %f&amp;quot;, var_value(integ-&amp;gt;x));&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int test_radau5_reporter_close(struct IntegratorSystemStruct *integ){&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
IntegratorReporter test_radau5_reporter = {&lt;br /&gt;
	test_radau5_reporter_init&lt;br /&gt;
	,test_radau5_reporter_write&lt;br /&gt;
	,test_radau5_reporter_writeobs&lt;br /&gt;
	,test_radau5_reporter_close&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
	Test solving a simple IPOPT model&lt;br /&gt;
*/&lt;br /&gt;
static void test_boundary(){&lt;br /&gt;
&lt;br /&gt;
	struct module_t *m;&lt;br /&gt;
&lt;br /&gt;
	Asc_CompilerInit(1);&lt;br /&gt;
	Asc_PutEnv(ASC_ENV_LIBRARY &amp;quot;=models:solvers/conopt:solvers/qrslv:solvers/cmslv:solvers/ida:solvers/lsode:solvers/ipopt&amp;quot;);&lt;br /&gt;
	&lt;br /&gt;
	/* load the file */&lt;br /&gt;
	char path[PATH_MAX];&lt;br /&gt;
	strcpy((char *)path,&amp;quot;test/radau5/&amp;quot;);&lt;br /&gt;
#define FILESTEM &amp;quot;boundaries&amp;quot;&lt;br /&gt;
	strncat(path, FILESTEM, PATH_MAX - strlen(path));&lt;br /&gt;
	strncat(path, &amp;quot;.a4c&amp;quot;, PATH_MAX - strlen(path));&lt;br /&gt;
	{&lt;br /&gt;
		int status;&lt;br /&gt;
		m = Asc_OpenModule(path,&amp;amp;status);&lt;br /&gt;
		CU_ASSERT_FATAL(status == 0);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/* parse it */&lt;br /&gt;
	CU_ASSERT(0 == zz_parse());&lt;br /&gt;
&lt;br /&gt;
	/* find the model */&lt;br /&gt;
	CU_ASSERT(FindType(AddSymbol(FILESTEM))!=NULL);&lt;br /&gt;
&lt;br /&gt;
	/* instantiate it */&lt;br /&gt;
	struct Instance *siminst = SimsCreateInstance(AddSymbol(FILESTEM), AddSymbol(&amp;quot;sim1&amp;quot;), e_normal, NULL);&lt;br /&gt;
	CU_ASSERT_FATAL(siminst!=NULL);&lt;br /&gt;
&lt;br /&gt;
    CONSOLE_DEBUG(&amp;quot;RUNNING ON_LOAD&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
	/** Call on_load */&lt;br /&gt;
	struct Name *name = CreateIdName(AddSymbol(&amp;quot;on_load&amp;quot;));&lt;br /&gt;
	enum Proc_enum pe = Initialize(GetSimulationRoot(siminst),name,&amp;quot;sim1&amp;quot;, ASCERR, WP_STOPONERR, NULL, NULL);&lt;br /&gt;
	CU_ASSERT(pe==Proc_all_ok);&lt;br /&gt;
&lt;br /&gt;
	/* create the integrator */&lt;br /&gt;
&lt;br /&gt;
	slv_system_t sys = system_build(GetSimulationRoot(siminst));&lt;br /&gt;
	CU_ASSERT_FATAL(sys != NULL);&lt;br /&gt;
&lt;br /&gt;
	IntegratorSystem *integ = integrator_new(sys,siminst);&lt;br /&gt;
	&lt;br /&gt;
	CU_ASSERT_FATAL(0 == integrator_set_engine(integ,&amp;quot;RADAU5&amp;quot;));&lt;br /&gt;
	CONSOLE_DEBUG(&amp;quot;Assigned integrator &#039;%s&#039;...&amp;quot;,integ-&amp;gt;internals-&amp;gt;name);&lt;br /&gt;
&lt;br /&gt;
	slv_parameters_t p;&lt;br /&gt;
	CU_ASSERT(0 == integrator_params_get(integ,&amp;amp;p));&lt;br /&gt;
	/* TODO set some parameters? */&lt;br /&gt;
&lt;br /&gt;
	/* perform problem analysis */&lt;br /&gt;
	CU_ASSERT_FATAL(0 == integrator_analyse(integ));&lt;br /&gt;
&lt;br /&gt;
	/* TODO assign an integrator reporter */&lt;br /&gt;
	integrator_set_reporter(integ, &amp;amp;test_radau5_reporter);&lt;br /&gt;
&lt;br /&gt;
	integrator_set_minstep(integ,0);&lt;br /&gt;
	integrator_set_maxstep(integ,0);&lt;br /&gt;
	integrator_set_stepzero(integ,0);&lt;br /&gt;
	integrator_set_maxsubsteps(integ,0);&lt;br /&gt;
&lt;br /&gt;
	/* set a linearly-distributed samplelist */&lt;br /&gt;
	double start = 0, end = 2.0;&lt;br /&gt;
	int num = 500;&lt;br /&gt;
	dim_type d;&lt;br /&gt;
	SetDimFraction(d,D_TIME,CreateFraction(1,1));&lt;br /&gt;
	SampleList *samplelist = samplelist_new(num+1, &amp;amp;d);&lt;br /&gt;
	double val = start;&lt;br /&gt;
	double inc = (end-start)/(num);&lt;br /&gt;
	unsigned long i;&lt;br /&gt;
	for(i=0; i&amp;lt;=num; ++i){&lt;br /&gt;
		samplelist_set(samplelist,i,val);&lt;br /&gt;
		val += inc;&lt;br /&gt;
	}&lt;br /&gt;
	integrator_set_samples(integ,samplelist);&lt;br /&gt;
&lt;br /&gt;
	CU_ASSERT_FATAL(0 == integrator_solve(integ, 0, samplelist_length(samplelist)-1));&lt;br /&gt;
&lt;br /&gt;
	integrator_free(integ);&lt;br /&gt;
	samplelist_free(samplelist);&lt;br /&gt;
	&lt;br /&gt;
	CU_ASSERT_FATAL(NULL != sys);&lt;br /&gt;
	system_destroy(sys);&lt;br /&gt;
	system_free_reused_mem();&lt;br /&gt;
&lt;br /&gt;
	/* destroy all that stuff */&lt;br /&gt;
	CONSOLE_DEBUG(&amp;quot;Destroying instance tree&amp;quot;);&lt;br /&gt;
	CU_ASSERT(siminst != NULL);&lt;br /&gt;
&lt;br /&gt;
	solver_destroy_engines();&lt;br /&gt;
	sim_destroy(siminst);&lt;br /&gt;
	Asc_CompilerDestroy();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*===========================================================================*/&lt;br /&gt;
/* Registration information */&lt;br /&gt;
&lt;br /&gt;
#define TESTS(T) \&lt;br /&gt;
	T(boundary)&lt;br /&gt;
&lt;br /&gt;
REGISTER_TESTS_SIMPLE(solver_radau5, TESTS)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=3011</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=3011"/>
		<updated>2011-08-19T22:48:05Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during [[GSOC2011]].&lt;br /&gt;
&lt;br /&gt;
Code branch: {{srcbranchdir|karthik|}} &lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# Evaluation of mass matrix for a wide range of systems of equations, in the form of a set of CUnit test cases:&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Accepting all equations and creating a mass matrix of correct dimensions.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying all derivatives in an equation.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Finding the real values of derivative variables.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying the derivatives using these real values.&amp;lt;/strike&amp;gt; &lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Checking if the equation is linear with respect to the derivatives.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of the derivative contains another variable which is not fixed.&amp;lt;/strike&amp;gt; &lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is raised to a power other than 1.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is in the denominator.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is present in the index of any term.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is inside a function.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of derivative contains a function.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Display corresponding error messages.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating the coefficient.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating a base coefficient to the derivative.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Compounding the base coefficient while processing terms in the equation.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Processing the coefficients and entering them to the mass matrix.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## Test with CUnit.&lt;br /&gt;
# Complete DAE solution of those solutions using RADAU5.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;August 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote [http://ascend4.org/User:Karthik0112358/test_radau5 test_radau5.c]. Working on some issues.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 15&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* CUnit up and running.&lt;br /&gt;
* Code completed for writing mass matrix, adding comments and checking if I missed any cases. Only integrating to Radau5 left.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 4&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have completed writing the function which evaluates the coefficient after confirming the equation is linear with respect to the derivatives. Code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. Hence Goal 1.4 complete.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 31&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
More added to [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Was not able to commit to svn due to current LAN problems at college. Will commit tomorrow. For now here is the code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 14&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote code for catching errors in equation where the derivative is raised to a higher/lower power. This was part of Goal 1.3.2. Svn committed the code: http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 13&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have come up with a simplified algorithm for Goal 1.4.2 after going through the code which simplifies equations. Will try to implement it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;br /&gt;
[[Category:ASCEND Contributors]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358/test_radau5&amp;diff=3010</id>
		<title>User:Karthik0112358/test radau5</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358/test_radau5&amp;diff=3010"/>
		<updated>2011-08-19T22:47:33Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: Created page with &amp;#039;&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt; #include &amp;lt;string.h&amp;gt; #include &amp;lt;stdlib.h&amp;gt; #include &amp;lt;stdio.h&amp;gt;  #include &amp;lt;ascend/general/env.h&amp;gt; #include &amp;lt;ascend/general/ospath.h&amp;gt; #include &amp;lt;ascend/general/list.h&amp;gt; …&amp;#039;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;ascend/general/env.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/general/ospath.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/general/list.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/general/ltmatrix.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;ascend/general/platform.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/utilities/ascEnvVar.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/utilities/error.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;ascend/compiler/ascCompiler.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/module.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/parser.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/library.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/symtab.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/simlist.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/instquery.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/parentchild.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/atomvalue.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/reverse_ad.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/mathinst.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/watchpt.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/initialize.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/name.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/visitinst.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/functype.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/safe.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/qlfdid.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/instance_io.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;ascend/compiler/slvreq.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;ascend/system/system.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/system/slv_client.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/solver/solver.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/system/slv_server.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/system/slv_param.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/integrator/integrator.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;test/common.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/* a simple integrator reporter for testing */&lt;br /&gt;
int test_radau5_reporter_init(struct IntegratorSystemStruct *integ){&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int test_radau5_reporter_write(struct IntegratorSystemStruct *integ){&lt;br /&gt;
	return 0; /* no interrupt */&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int test_radau5_reporter_writeobs(struct IntegratorSystemStruct *integ){&lt;br /&gt;
	CONSOLE_DEBUG(&amp;quot;x = %f&amp;quot;, var_value(integ-&amp;gt;x));&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int test_radau5_reporter_close(struct IntegratorSystemStruct *integ){&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
IntegratorReporter test_radau5_reporter = {&lt;br /&gt;
	test_radau5_reporter_init&lt;br /&gt;
	,test_radau5_reporter_write&lt;br /&gt;
	,test_radau5_reporter_writeobs&lt;br /&gt;
	,test_radau5_reporter_close&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
	Test solving a simple IPOPT model&lt;br /&gt;
*/&lt;br /&gt;
static void test_boundary(){&lt;br /&gt;
&lt;br /&gt;
	struct module_t *m;&lt;br /&gt;
&lt;br /&gt;
	Asc_CompilerInit(1);&lt;br /&gt;
	Asc_PutEnv(ASC_ENV_LIBRARY &amp;quot;=models:solvers/conopt:solvers/qrslv:solvers/cmslv:solvers/ida:solvers/lsode:solvers/ipopt&amp;quot;);&lt;br /&gt;
	&lt;br /&gt;
	/* load the file */&lt;br /&gt;
	char path[PATH_MAX];&lt;br /&gt;
	strcpy((char *)path,&amp;quot;test/radau5/&amp;quot;);&lt;br /&gt;
#define FILESTEM &amp;quot;boundaries&amp;quot;&lt;br /&gt;
	strncat(path, FILESTEM, PATH_MAX - strlen(path));&lt;br /&gt;
	strncat(path, &amp;quot;.a4c&amp;quot;, PATH_MAX - strlen(path));&lt;br /&gt;
	{&lt;br /&gt;
		int status;&lt;br /&gt;
		m = Asc_OpenModule(path,&amp;amp;status);&lt;br /&gt;
		CU_ASSERT_FATAL(status == 0);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/* parse it */&lt;br /&gt;
	CU_ASSERT(0 == zz_parse());&lt;br /&gt;
&lt;br /&gt;
	/* find the model */&lt;br /&gt;
	CU_ASSERT(FindType(AddSymbol(FILESTEM))!=NULL);&lt;br /&gt;
&lt;br /&gt;
	/* instantiate it */&lt;br /&gt;
	struct Instance *siminst = SimsCreateInstance(AddSymbol(FILESTEM), AddSymbol(&amp;quot;sim1&amp;quot;), e_normal, NULL);&lt;br /&gt;
	CU_ASSERT_FATAL(siminst!=NULL);&lt;br /&gt;
&lt;br /&gt;
    CONSOLE_DEBUG(&amp;quot;RUNNING ON_LOAD&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
	/** Call on_load */&lt;br /&gt;
	struct Name *name = CreateIdName(AddSymbol(&amp;quot;on_load&amp;quot;));&lt;br /&gt;
	enum Proc_enum pe = Initialize(GetSimulationRoot(siminst),name,&amp;quot;sim1&amp;quot;, ASCERR, WP_STOPONERR, NULL, NULL);&lt;br /&gt;
	CU_ASSERT(pe==Proc_all_ok);&lt;br /&gt;
&lt;br /&gt;
	/* create the integrator */&lt;br /&gt;
&lt;br /&gt;
	slv_system_t sys = system_build(GetSimulationRoot(siminst));&lt;br /&gt;
	CU_ASSERT_FATAL(sys != NULL);&lt;br /&gt;
&lt;br /&gt;
	IntegratorSystem *integ = integrator_new(sys,siminst);&lt;br /&gt;
	&lt;br /&gt;
	CU_ASSERT_FATAL(0 == integrator_set_engine(integ,&amp;quot;RADAU5&amp;quot;));&lt;br /&gt;
	CONSOLE_DEBUG(&amp;quot;Assigned integrator &#039;%s&#039;...&amp;quot;,integ-&amp;gt;internals-&amp;gt;name);&lt;br /&gt;
&lt;br /&gt;
	slv_parameters_t p;&lt;br /&gt;
	CU_ASSERT(0 == integrator_params_get(integ,&amp;amp;p));&lt;br /&gt;
	/* TODO set some parameters? */&lt;br /&gt;
&lt;br /&gt;
	/* perform problem analysis */&lt;br /&gt;
	CU_ASSERT_FATAL(0 == integrator_analyse(integ));&lt;br /&gt;
&lt;br /&gt;
	/* TODO assign an integrator reporter */&lt;br /&gt;
	integrator_set_reporter(integ, &amp;amp;test_radau5_reporter);&lt;br /&gt;
&lt;br /&gt;
	integrator_set_minstep(integ,0);&lt;br /&gt;
	integrator_set_maxstep(integ,0);&lt;br /&gt;
	integrator_set_stepzero(integ,0);&lt;br /&gt;
	integrator_set_maxsubsteps(integ,0);&lt;br /&gt;
&lt;br /&gt;
	/* set a linearly-distributed samplelist */&lt;br /&gt;
	double start = 0, end = 2.0;&lt;br /&gt;
	int num = 500;&lt;br /&gt;
	dim_type d;&lt;br /&gt;
	SetDimFraction(d,D_TIME,CreateFraction(1,1));&lt;br /&gt;
	SampleList *samplelist = samplelist_new(num+1, &amp;amp;d);&lt;br /&gt;
	double val = start;&lt;br /&gt;
	double inc = (end-start)/(num);&lt;br /&gt;
	unsigned long i;&lt;br /&gt;
	for(i=0; i&amp;lt;=num; ++i){&lt;br /&gt;
		samplelist_set(samplelist,i,val);&lt;br /&gt;
		val += inc;&lt;br /&gt;
	}&lt;br /&gt;
	integrator_set_samples(integ,samplelist);&lt;br /&gt;
&lt;br /&gt;
	CU_ASSERT_FATAL(0 == integrator_solve(integ, 0, samplelist_length(samplelist)-1));&lt;br /&gt;
&lt;br /&gt;
	integrator_free(integ);&lt;br /&gt;
	samplelist_free(samplelist);&lt;br /&gt;
	&lt;br /&gt;
	CU_ASSERT_FATAL(NULL != sys);&lt;br /&gt;
	system_destroy(sys);&lt;br /&gt;
	system_free_reused_mem();&lt;br /&gt;
&lt;br /&gt;
	/* destroy all that stuff */&lt;br /&gt;
	CONSOLE_DEBUG(&amp;quot;Destroying instance tree&amp;quot;);&lt;br /&gt;
	CU_ASSERT(siminst != NULL);&lt;br /&gt;
&lt;br /&gt;
	solver_destroy_engines();&lt;br /&gt;
	sim_destroy(siminst);&lt;br /&gt;
	Asc_CompilerDestroy();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*===========================================================================*/&lt;br /&gt;
/* Registration information */&lt;br /&gt;
&lt;br /&gt;
#define TESTS(T) \&lt;br /&gt;
	T(boundary)&lt;br /&gt;
&lt;br /&gt;
REGISTER_TESTS_SIMPLE(solver_radau5, TESTS)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2993</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2993"/>
		<updated>2011-08-15T11:16:29Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Goals */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during [[GSOC2011]].&lt;br /&gt;
&lt;br /&gt;
Code branch: {{srcbranchdir|karthik|}} &lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# Evaluation of mass matrix for a wide range of systems of equations, in the form of a set of CUnit test cases:&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Accepting all equations and creating a mass matrix of correct dimensions.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying all derivatives in an equation.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Finding the real values of derivative variables.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying the derivatives using these real values.&amp;lt;/strike&amp;gt; &lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Checking if the equation is linear with respect to the derivatives.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of the derivative contains another variable which is not fixed.&amp;lt;/strike&amp;gt; &lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is raised to a power other than 1.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is in the denominator.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is present in the index of any term.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is inside a function.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of derivative contains a function.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Display corresponding error messages.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating the coefficient.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating a base coefficient to the derivative.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Compounding the base coefficient while processing terms in the equation.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Processing the coefficients and entering them to the mass matrix.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## Test with CUnit.&lt;br /&gt;
# Complete DAE solution of those solutions using RADAU5.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;August 15&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* CUnit up and running.&lt;br /&gt;
* Code completed for writing mass matrix, adding comments and checking if I missed any cases. Only integrating to Radau5 left.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 4&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have completed writing the function which evaluates the coefficient after confirming the equation is linear with respect to the derivatives. Code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. Hence Goal 1.4 complete.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 31&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
More added to [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Was not able to commit to svn due to current LAN problems at college. Will commit tomorrow. For now here is the code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 14&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote code for catching errors in equation where the derivative is raised to a higher/lower power. This was part of Goal 1.3.2. Svn committed the code: http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 13&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have come up with a simplified algorithm for Goal 1.4.2 after going through the code which simplifies equations. Will try to implement it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;br /&gt;
[[Category:ASCEND Contributors]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2992</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2992"/>
		<updated>2011-08-15T11:13:56Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during [[GSOC2011]].&lt;br /&gt;
&lt;br /&gt;
Code branch: {{srcbranchdir|karthik|}} &lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# Evaluation of mass matrix for a wide range of systems of equations, in the form of a set of CUnit test cases:&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Accepting all equations and creating a mass matrix of correct dimensions.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying all derivatives in an equation.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Finding the real values of derivative variables.&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying the derivatives using these real values.&amp;lt;/strike&amp;gt; &lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Checking if the equation is linear with respect to the derivatives.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of the derivative contains another variable which is not fixed.&amp;lt;/strike&amp;gt; &lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is raised to a power other than 1.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is in the denominator.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is present in the index of any term.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is inside a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of derivative contains a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Display corresponding error messages.&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating the coefficient.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating a base coefficient to the derivative.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Compounding the base coefficient while processing terms in the equation.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Processing the coefficients and entering them to the mass matrix.&amp;lt;/strike&amp;gt;&lt;br /&gt;
# Complete DAE solution of those solutions using RADAU5.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;August 15&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* CUnit up and running.&lt;br /&gt;
* Code completed for writing mass matrix, adding comments and checking if I missed any cases. Only integrating to Radau5 left.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;August 4&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have completed writing the function which evaluates the coefficient after confirming the equation is linear with respect to the derivatives. Code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. Hence Goal 1.4 complete.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 31&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
More added to [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Was not able to commit to svn due to current LAN problems at college. Will commit tomorrow. For now here is the code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 14&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote code for catching errors in equation where the derivative is raised to a higher/lower power. This was part of Goal 1.3.2. Svn committed the code: http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 13&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have come up with a simplified algorithm for Goal 1.4.2 after going through the code which simplifies equations. Will try to implement it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;br /&gt;
[[Category:ASCEND Contributors]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358/Coefficient_Calculator&amp;diff=2953</id>
		<title>User:Karthik0112358/Coefficient Calculator</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358/Coefficient_Calculator&amp;diff=2953"/>
		<updated>2011-08-04T23:01:13Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*	ASCEND modelling environment&lt;br /&gt;
	Copyright (C) 1997, 2006 Carnegie Mellon University&lt;br /&gt;
	Copyright (C) 1993, 1994 Joseph James Zaher, Benjamin Andrew Allan&lt;br /&gt;
	Copyright (C) 1993 Joseph James Zaher&lt;br /&gt;
	Copyright (C) 1990 Thomas Guthrie Epperly, Karl Michael Westerberg&lt;br /&gt;
&lt;br /&gt;
	This program is free software; you can redistribute it and/or modify&lt;br /&gt;
	it under the terms of the GNU General Public License as published by&lt;br /&gt;
	the Free Software Foundation; either version 2, or (at your option)&lt;br /&gt;
	any later version.&lt;br /&gt;
&lt;br /&gt;
	This program is distributed in the hope that it will be useful,&lt;br /&gt;
	but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
	GNU General Public License for more details.&lt;br /&gt;
&lt;br /&gt;
	You should have received a copy of the GNU General Public License&lt;br /&gt;
	along with this program; if not, write to the Free Software&lt;br /&gt;
	Foundation, Inc., 59 Temple Place - Suite 330,&lt;br /&gt;
	Boston, MA 02111-1307, USA.&lt;br /&gt;
*/&lt;br /&gt;
/*&lt;br /&gt;
KARTHIK C S, June 2011&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;lt;math.h&amp;gt;&lt;br /&gt;
#include &amp;quot;relation_util.h&amp;quot;&lt;br /&gt;
#include &amp;lt;ascend/general/ascMalloc.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/general/panic.h&amp;gt;&lt;br /&gt;
#include &amp;quot;relation_type.h&amp;quot;&lt;br /&gt;
#include &amp;quot;expr_types.h&amp;quot;&lt;br /&gt;
#include &amp;quot;instance_enum.h&amp;quot;&lt;br /&gt;
#include &amp;quot;functype.h&amp;quot;&lt;br /&gt;
#include &amp;quot;mathinst.c&amp;quot;&lt;br /&gt;
/*------------------------------------------------------------------------------&lt;br /&gt;
  FINDING COEFFICIENTS OF THE DERIVATIVE TERMS IN A RELATION&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
	Compute the coefficients of the derivative terms in the relation (compiler-side routine)&lt;br /&gt;
&lt;br /&gt;
	@param i Instance pointer through which the coefficients of the derivative terms of the relation are found&lt;br /&gt;
	@param coefficient pointer to a double in which the coefficients shall be stored (must have already been allocated)&lt;br /&gt;
	@param Info of structure Info_abt_deriv which contains the real value of all the derivative variables&lt;br /&gt;
&lt;br /&gt;
 	@return 0 on success, and otherwise on failure&lt;br /&gt;
&lt;br /&gt;
	Here we compute the coefficients of the derivative terms by first extracting each term. &lt;br /&gt;
	We then check if its a derivative variable and if so we compute its coefficient by considering the terms previous to it and after it. &lt;br /&gt;
	In this process we also check if the equation is linear wrt its derivatives. Suitable error messages are displayed if its not.&lt;br /&gt;
*/&lt;br /&gt;
/* Started reorganizing the entire Inspect_Equation(). Providing modularity for efficiency and flexibility.*/&lt;br /&gt;
/*&lt;br /&gt;
static int Inspect_Equation(struct Info_abt_deriv Info,int *order,double *var,double *func,int *ope,unsigned long length_rel){&lt;br /&gt;
	int i,j,k;&lt;br /&gt;
	int varc=-1,opec=-1,funcc=-1,numc=-1;&lt;br /&gt;
	int flag,count,c,denom_flag,point;&lt;br /&gt;
	unsigned long bin_num,pass,new_bin_num;&lt;br /&gt;
	for (i=0;i&amp;lt;Info.no_of_deriv;i++){&lt;br /&gt;
		flag=0;&lt;br /&gt;
		for(j=0;j&amp;lt;length_rel;j++){&lt;br /&gt;
			switch(order[j]){&lt;br /&gt;
				case 1:&lt;br /&gt;
					++numc;&lt;br /&gt;
					break;&lt;br /&gt;
				case 2:&lt;br /&gt;
					++varc;&lt;br /&gt;
					//Write Error catching analysis code here&lt;br /&gt;
					if(Info.deriv_values[i]==var[varc]) {&lt;br /&gt;
						if(order[j-1]==2) {&lt;br /&gt;
							count=1;&lt;br /&gt;
							c=1;&lt;br /&gt;
							k=0;&lt;br /&gt;
							while(count!=0&amp;amp;&amp;amp;(j+c)&amp;lt;=length_rel) {&lt;br /&gt;
								count=(order[c+j]==3)?--count:++count;&lt;br /&gt;
								k=(order[c+j]==3)?++k:k;&lt;br /&gt;
								++c;&lt;br /&gt;
							}&lt;br /&gt;
							--c;&lt;br /&gt;
							if(ope[opec+k]!=1||ope[opec+k]!=2){&lt;br /&gt;
								CONSOLE_DEBUG(&amp;quot;The coefficient of the derivative term contains a non constant term&amp;quot;);&lt;br /&gt;
							}&lt;br /&gt;
						}else if(order[j+1]==2) {&lt;br /&gt;
							count=1;&lt;br /&gt;
							c=2;&lt;br /&gt;
							k=0;&lt;br /&gt;
							while(count!=0&amp;amp;&amp;amp;(j+c)&amp;lt;=length_rel){	&lt;br /&gt;
								count=(order[c+j]==3)?--count:++count;&lt;br /&gt;
								k=(order[c+j]==3)?++k:k;&lt;br /&gt;
								++c;&lt;br /&gt;
							}&lt;br /&gt;
							--c;&lt;br /&gt;
							if(ope[opec+k]!=1||ope[opec+k]!=2){&lt;br /&gt;
								CONSOLE_DEBUG(&amp;quot;The coefficient of the derivative term contains a non constant term&amp;quot;);&lt;br /&gt;
							}	&lt;br /&gt;
						}&lt;br /&gt;
						c=1;&lt;br /&gt;
						count=0;&lt;br /&gt;
						denom_flag=0;&lt;br /&gt;
						while(order[j+c]!=4&amp;amp;&amp;amp;(j+c)&amp;lt;=length_rel) {&lt;br /&gt;
							if(order[c+j]==3) {&lt;br /&gt;
								++count;&lt;br /&gt;
								if(ope[opec+count]==4) {&lt;br /&gt;
									if(count&amp;gt;c-count) {&lt;br /&gt;
										denom_flag=(denom_flag==0)?1:0;&lt;br /&gt;
									}&lt;br /&gt;
								}					&lt;br /&gt;
							}							&lt;br /&gt;
							++c;						&lt;br /&gt;
						}&lt;br /&gt;
						if(denom_flag==1){&lt;br /&gt;
							CONSOLE_DEBUG(&amp;quot;The derivative is in denominator&amp;quot;);&lt;br /&gt;
						}&lt;br /&gt;
						c=1;&lt;br /&gt;
						count=0;&lt;br /&gt;
						while(order[j+c]!=4&amp;amp;&amp;amp;(j+c)&amp;lt;=length_rel) {&lt;br /&gt;
							if(order[c+j]==3) {&lt;br /&gt;
								++count;&lt;br /&gt;
								if(ope[opec+count]==6) {&lt;br /&gt;
									if(count&amp;gt;c-count) {&lt;br /&gt;
										CONSOLE_DEBUG(&amp;quot;The derivative is in index&amp;quot;);&lt;br /&gt;
									}&lt;br /&gt;
								}					&lt;br /&gt;
							}							&lt;br /&gt;
							++c;						&lt;br /&gt;
						}&lt;br /&gt;
						/* We implement here an algorithm which finds the span of an operator. The span of an operator &lt;br /&gt;
						is defined as the number of terms the operator links in an expression. We see if the derivative &lt;br /&gt;
						is in the upper span (the set of terms to the left of an operator in infix form) of the operator, &lt;br /&gt;
						by using a variable to point at the location of the derivative in a binary representation of the &lt;br /&gt;
						relation where 0 means a number or variable and 1 means an operator. Then we display an error is &lt;br /&gt;
						the derivative is raised to a higher/lower power.* /&lt;br /&gt;
						c=0;&lt;br /&gt;
						count=-1;&lt;br /&gt;
						bin_num=0;&lt;br /&gt;
						pass=0;&lt;br /&gt;
						/* Need to write code here to check if the derivative is being raised to power 1. &lt;br /&gt;
						The idea is to locate every ^ operator and see if the item immediately following &lt;br /&gt;
						it in the infix notation is 1 which does not have any prior connection with any other&lt;br /&gt;
						operator. * /&lt;br /&gt;
						/* As a second thought, I think I will segregate each Error case as a function, considering the recursive algorithms used in some of the cases. * /&lt;br /&gt;
						if(flag==0){						&lt;br /&gt;
							while(order[c]!=4){&lt;br /&gt;
								++c;		&lt;br /&gt;
							}&lt;br /&gt;
							for(k=c-1;k&amp;gt;=0;k--) {&lt;br /&gt;
								if(order[k]==3) {&lt;br /&gt;
									bin_num+=pow(2,c-k-1);&lt;br /&gt;
								}&lt;br /&gt;
							}&lt;br /&gt;
							point=j;&lt;br /&gt;
							for(k=c-1;k&amp;gt;=0;k--) {&lt;br /&gt;
								if(bin_num-pass&amp;gt;0) {	&lt;br /&gt;
									++count;									&lt;br /&gt;
									pass+=pow(2,k);							&lt;br /&gt;
									if(point+k==c-3) {&lt;br /&gt;
										if(ope[count]==6) {&lt;br /&gt;
											CONSOLE_DEBUG(&amp;quot;The derivative is raised to a power other than one&amp;quot;);&lt;br /&gt;
										} else {&lt;br /&gt;
											&lt;br /&gt;
										}&lt;br /&gt;
									} else {&lt;br /&gt;
	&lt;br /&gt;
									}&lt;br /&gt;
								}&lt;br /&gt;
							}	&lt;br /&gt;
						}else {&lt;br /&gt;
							while(order[c]!=4){&lt;br /&gt;
								++c;&lt;br /&gt;
							}&lt;br /&gt;
							++c;&lt;br /&gt;
							while(c&amp;lt;=length_rel) {&lt;br /&gt;
								++c;						&lt;br /&gt;
							}&lt;br /&gt;
						}&lt;br /&gt;
					}&lt;br /&gt;
					break;&lt;br /&gt;
				case 3:&lt;br /&gt;
					++opec;&lt;br /&gt;
					break;&lt;br /&gt;
				case 4:&lt;br /&gt;
					flag=1;&lt;br /&gt;
					break;&lt;br /&gt;
				default:&lt;br /&gt;
					/* Give Error Message * /	&lt;br /&gt;
					break;		&lt;br /&gt;
			}&lt;br /&gt;
		}		&lt;br /&gt;
	}&lt;br /&gt;
	return 1;&lt;br /&gt;
}&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/* So here it begins */&lt;br /&gt;
&lt;br /&gt;
char* find_left_bin_number(int *,unsigned long ,int *);&lt;br /&gt;
char* find_right_bin_number(int *,unsigned long ,int *);&lt;br /&gt;
int find_variable(struct Info_abt_deriv, double);&lt;br /&gt;
check_for_alg_coeff();&lt;br /&gt;
&lt;br /&gt;
/* Functions need to write:&lt;br /&gt;
check_in denominator();&lt;br /&gt;
check_in_indices();&lt;br /&gt;
check_in_bases();&lt;br /&gt;
check_for_func_coeff();&lt;br /&gt;
check_inside_func();&lt;br /&gt;
shift_by_one();&lt;br /&gt;
shift_by_two();&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
static int Inspect_Equation(struct Info_abt_deriv Info,int *order,double *var,double *func,int *ope,unsigned long length_rel){&lt;br /&gt;
	int result;&lt;br /&gt;
	int var_index;&lt;br /&gt;
	char *left_bin_num,*right_bin_num;&lt;br /&gt;
	int *len_left_bin_num,*len_right_bin_num; /* Pointers are used so that these can be passed by reference */&lt;br /&gt;
	left_bin_num=ASC_NEW_ARRAY(char,length_rel);&lt;br /&gt;
	right_bin_num=ASC_NEW_ARRAY(char,length_rel);&lt;br /&gt;
	left_bin_num=find_left_bin_number(order,length_rel,len_left_bin_num);&lt;br /&gt;
	right_bin_num=find_right_bin_number(order,length_rel,len_right_bin_num);&lt;br /&gt;
	result=0;&lt;br /&gt;
/* We write here an inspection for special cases, like : 3=4+Q(x,y)/x, where is Q(x,y) is a linear function in x */&lt;br /&gt;
&lt;br /&gt;
/* End of special cases */&lt;br /&gt;
&lt;br /&gt;
/* We start inspecting general cases */&lt;br /&gt;
&lt;br /&gt;
	flag=0;&lt;br /&gt;
	for(j=0;j&amp;lt;length_rel;j++){&lt;br /&gt;
		switch(order[j]){&lt;br /&gt;
			case 1:&lt;br /&gt;
				++numc;&lt;br /&gt;
				break;&lt;br /&gt;
			case 2:&lt;br /&gt;
				++varc;&lt;br /&gt;
				/* Write Error catching analysis code here */&lt;br /&gt;
				var_index=find_variable(Info,var[varc]);&lt;br /&gt;
				if(var_index!=0){&lt;br /&gt;
					result+=check_in denominator(left_bin_num,len_left_bin_num,right_bin_num,len_right_bin_num,var_index,flag);&lt;br /&gt;
					result+=check_in_indices();&lt;br /&gt;
					result+=check_in_bases();&lt;br /&gt;
					result+=check_for_alg_coeff();&lt;br /&gt;
					result+=check_for_func_coeff();&lt;br /&gt;
					result+=check_inside_func();&lt;br /&gt;
				}&lt;br /&gt;
				break;&lt;br /&gt;
			case 3:&lt;br /&gt;
				++opec;&lt;br /&gt;
				break;&lt;br /&gt;
			case 4:&lt;br /&gt;
				flag=1;&lt;br /&gt;
				break;&lt;br /&gt;
			default:&lt;br /&gt;
				/* Give Error Message */	&lt;br /&gt;
				break;		&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	return (result&amp;gt;0)?0:1;&lt;br /&gt;
}&lt;br /&gt;
char* find_left_bin_number(int *order,unsigned long length_rel,int *len_left_bin_num) {&lt;br /&gt;
	int i;&lt;br /&gt;
	char *bin_num;&lt;br /&gt;
	bin_num=ASC_NEW_ARRAY(char,length_rel);&lt;br /&gt;
	for(i=0;order[i]!=4;i++) {&lt;br /&gt;
		bin_num[i](order[i]&amp;lt;=2)?&#039;0&#039;:&#039;1&#039;;&lt;br /&gt;
		*len_left_bin_num=i+1;&lt;br /&gt;
	}	&lt;br /&gt;
	return bin_num;&lt;br /&gt;
}&lt;br /&gt;
char* find_right_bin_number(int *order,unsigned long length_rel,int *len_right_bin_num) {&lt;br /&gt;
	int i,j;&lt;br /&gt;
	char *bin_num;&lt;br /&gt;
	bin_num=ASC_NEW_ARRAY(char,length_rel);&lt;br /&gt;
	for(i=0;order[i]!=4;i++);&lt;br /&gt;
	for(j=i+1;j&amp;lt;=length_rel;j++) {&lt;br /&gt;
		bin_num[j-i-1](order[j]&amp;lt;=2)?&#039;0&#039;:&#039;1&#039;;&lt;br /&gt;
		*len_right_bin_num=j-i-1;&lt;br /&gt;
	}	&lt;br /&gt;
	return bin_num;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int find_variable(struct Info_abt_deriv Info, double index) {&lt;br /&gt;
	int i=0;&lt;br /&gt;
	for(i=0;i&amp;lt;Info.no_of_deriv;i++) {&lt;br /&gt;
		if(Info.deriv_values[i]==index) {&lt;br /&gt;
			return 1;&lt;br /&gt;
		}		&lt;br /&gt;
	}&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int check_for_alg_coeff() {&lt;br /&gt;
/* start code here */&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void coefficient_match(double *coefficient,struct Info_abt_deriv Info,int *order,double *num,double *var,double *func,int *ope, unsigned long length_rel){&lt;br /&gt;
	int i,j,k,p;&lt;br /&gt;
	double value;&lt;br /&gt;
	int flag;&lt;br /&gt;
	int varc=-1,opec=-1,funcc=-1,numc=-1;&lt;br /&gt;
	int c;&lt;br /&gt;
	if(Inspect_Equation(Info,order,var,func,ope,length_rel)==1){&lt;br /&gt;
		for (i=0;i&amp;lt;Info.no_of_deriv;i++){&lt;br /&gt;
			value=1.0;&lt;br /&gt;
			flag=0;&lt;br /&gt;
			for(j=0;j&amp;lt;length_rel;j++){&lt;br /&gt;
				switch(order[j]){&lt;br /&gt;
					case 1:&lt;br /&gt;
						++numc;&lt;br /&gt;
						break;&lt;br /&gt;
					case 2:&lt;br /&gt;
						++varc;&lt;br /&gt;
						/*if(Info.deriv_values[i]==var[varc]) {&lt;br /&gt;
							if(order[j-1]==1&amp;amp;&amp;amp;order[j+1]==3) {&lt;br /&gt;
								if(ope[opec+1]==3) {&lt;br /&gt;
									value=num[numc];&lt;br /&gt;
								}&lt;br /&gt;
							}else if(order[j+1]==1&amp;amp;&amp;amp;order[j+2]==3) {&lt;br /&gt;
								if(ope[opec+1]==3) {&lt;br /&gt;
									value=num[numc+1];&lt;br /&gt;
								}&lt;br /&gt;
							}else {							&lt;br /&gt;
								while(order[c+j]!=4){&lt;br /&gt;
									c=1;&lt;br /&gt;
									while(order[c+j]==2||order[c+j]==1) {&lt;br /&gt;
										c++;&lt;br /&gt;
									}		&lt;br /&gt;
								}								&lt;br /&gt;
							}&lt;br /&gt;
						}*/&lt;br /&gt;
/*&lt;br /&gt;
 We write here a piece of code which sees the relation as follows:&lt;br /&gt;
(i) the variable whose coefficient we have to find is replaced by 1. &lt;br /&gt;
(ii) every other variable is replaced by 0.&lt;br /&gt;
(iii) we simplify the expression we have but with certain new rules:&lt;br /&gt;
(iii) (i) If + or - operator is encountered then we replace the number preceeding or succeeding it by 0.&lt;br /&gt;
(iii) (ii) If ^ is encountered we ignore it and the number following it(which has to be 1). &lt;br /&gt;
*/&lt;br /&gt;
						for(p=0;order[p]!=4;p++) {&lt;br /&gt;
							/* Implement above algorithm here*/&lt;br /&gt;
\						}&lt;br /&gt;
						break;&lt;br /&gt;
					case 3:&lt;br /&gt;
						++opec;&lt;br /&gt;
						break;&lt;br /&gt;
					case 4:&lt;br /&gt;
						flag=1;&lt;br /&gt;
						break;&lt;br /&gt;
					default:&lt;br /&gt;
					/* Give Error Message */	&lt;br /&gt;
						break;		&lt;br /&gt;
				}&lt;br /&gt;
			}	&lt;br /&gt;
		}&lt;br /&gt;
	}else {&lt;br /&gt;
		CONSOLE_DEBUG(&amp;quot;Equation cannot be accepted by solver&amp;quot;);&lt;br /&gt;
	}	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static int coefficient_calculator(struct Instance *i,double *coefficient,struct Info_abt_deriv Info){&lt;br /&gt;
	struct relation *r;&lt;br /&gt;
	enum Expr_enum reltype;&lt;br /&gt;
	unsigned long t;       			/* the current term in the relation r */&lt;br /&gt;
	unsigned long num_var; 			/* the number of variables in the relation r */&lt;br /&gt;
	unsigned long v;      			/* loop variable */&lt;br /&gt;
	int lhs;               			/* looking at left(=1) or right(=0) hand side of r */&lt;br /&gt;
	unsigned long length_lhs, length_rhs;&lt;br /&gt;
	double *num;				/* pointer for storing all constants in relation */&lt;br /&gt;
	double *var;				/* pointer for storing all real value of variables in relation */&lt;br /&gt;
	int *ope;				/* pointer for storing all operators in relation */&lt;br /&gt;
	double *func;				/* pointer for storing all functions in relation */&lt;br /&gt;
	int *order;				/* pointer for storing order of all constants, variables and operators in postfix form in relation */&lt;br /&gt;
	int varc=0,numc=0,orderc=0,opec=0,funcc=0;	/* counters for various arrays */&lt;br /&gt;
	CONST struct relation_term *term;&lt;br /&gt;
	CONST struct Func *fxnptr;&lt;br /&gt;
	r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
	if( r == NULL ) {&lt;br /&gt;
		CONSOLE_DEBUG(&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
		return -1;&lt;br /&gt;
	}&lt;br /&gt;
	num_var = NumberVariables(r);&lt;br /&gt;
	length_lhs = RelationLength(r, 1);&lt;br /&gt;
	length_rhs = RelationLength(r, 0);&lt;br /&gt;
	num=ASC_NEW_ARRAY(double,length_lhs+length_rhs);&lt;br /&gt;
	var=ASC_NEW_ARRAY(double,length_lhs+length_rhs);&lt;br /&gt;
	ope=ASC_NEW_ARRAY(int,length_lhs+length_rhs);&lt;br /&gt;
	func=ASC_NEW_ARRAY(double,length_lhs+length_rhs);&lt;br /&gt;
	order = ASC_NEW_ARRAY(int,(length_lhs+length_rhs+1));&lt;br /&gt;
	lhs = 1;&lt;br /&gt;
	t = 0;&lt;br /&gt;
&lt;br /&gt;
	for (v=0; v&amp;lt;length_lhs+length_rhs; v++) {&lt;br /&gt;
/* Initializing all entries to 0 */&lt;br /&gt;
		order[v]=0;&lt;br /&gt;
		func[v]=0.0;&lt;br /&gt;
		ope[v]=0;&lt;br /&gt;
		num[v]=0.0;&lt;br /&gt;
		var[v]=0.0;&lt;br /&gt;
	}&lt;br /&gt;
	order[length_lhs+length_rhs]=0;&lt;br /&gt;
	while(1) {&lt;br /&gt;
		if( lhs &amp;amp;&amp;amp; (t &amp;gt;= length_lhs) ) {&lt;br /&gt;
/* need to switch to the right hand side--if it exists */&lt;br /&gt;
			if( length_rhs ) {&lt;br /&gt;
				lhs = t = 0;&lt;br /&gt;
				order[orderc++]=4;&lt;br /&gt;
			} else {&lt;br /&gt;
/* &lt;br /&gt;
	We know that (length_lhs+length_rhs&amp;gt;0) and that (length_rhs==0),&lt;br /&gt;
	the length_lhs must be &amp;gt; 0&lt;br /&gt;
*/&lt;br /&gt;
				coefficient_match(coefficient,Info,order,num,var,func,ope,length_lhs+length_rhs+1);&lt;br /&gt;
			        return 0;&lt;br /&gt;
      			}&lt;br /&gt;
    		} else if( (!lhs) &amp;amp;&amp;amp; (t &amp;gt;= length_rhs) ) {&lt;br /&gt;
/* we have processed both sides, quit */&lt;br /&gt;
				coefficient_match(coefficient,Info,order,num,var,func,ope,length_lhs+length_rhs+1);&lt;br /&gt;
			        return 0;&lt;br /&gt;
		}&lt;br /&gt;
		term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
		switch( RelationTermType(term) ) {&lt;br /&gt;
			case e_zero:&lt;br /&gt;
				num[numc++]=0.0;&lt;br /&gt;
				order[orderc++]=1;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_real:&lt;br /&gt;
				num[numc++]=(double)TermReal(term);&lt;br /&gt;
				order[orderc++]=1;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_int:&lt;br /&gt;
				num[numc++]=(double)TermInteger(term);&lt;br /&gt;
				order[orderc++]=1;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_var:&lt;br /&gt;
				var[varc++]= TermVariable(r, term);&lt;br /&gt;
				order[orderc++]=2;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_plus:&lt;br /&gt;
				ope[opec++]=1;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_minus:&lt;br /&gt;
				ope[opec++]=2;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_times:&lt;br /&gt;
				ope[opec++]=3;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_divide:&lt;br /&gt;
				ope[opec++]=4;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_uminus:&lt;br /&gt;
				ope[opec++]=5;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_power:&lt;br /&gt;
				ope[opec++]=6;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_ipower:&lt;br /&gt;
				ope[opec++]=7;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_func:&lt;br /&gt;
				ope[opec++]=8;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				fxnptr = TermFunc(term);&lt;br /&gt;
				func[funcc] = FuncEval( fxnptr, func[funcc] );&lt;br /&gt;
				++funcc;&lt;br /&gt;
				break;&lt;br /&gt;
			default:&lt;br /&gt;
				ASC_PANIC(&amp;quot;Unknown relation term type&amp;quot;);&lt;br /&gt;
				break;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
	}&lt;br /&gt;
}	&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2952</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2952"/>
		<updated>2011-08-04T22:16:14Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during [[GSOC2011]].&lt;br /&gt;
&lt;br /&gt;
Code branch: {{srcbranchdir|karthik|}} &lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# Evaluation of mass matrix for a wide range of systems of equations, in the form of a set of CUnit test cases:&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Accepting all equations and creating a mass matrix of correct dimensions.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying all derivatives in an equation.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Finding the real values of derivative variables.&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying the derivatives using these real values.&amp;lt;/strike&amp;gt; &lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Checking if the equation is linear with respect to the derivatives.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of the derivative contains another variable which is not fixed.&amp;lt;/strike&amp;gt; &lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is raised to a power other than 1.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is in the denominator.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is present in the index of any term.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is inside a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of derivative contains a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Display corresponding error messages.&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating the coefficient.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating a base coefficient to the derivative.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Compounding the base coefficient while processing terms in the equation.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Processing the coefficients and entering them to the mass matrix.&amp;lt;/strike&amp;gt;&lt;br /&gt;
# Complete DAE solution of those solutions using RADAU5.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;August 4&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have completed writing the function which evaluates the coefficient after confirming the equation is linear with respect to the derivatives. Code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. Hence Goal 1.4 complete.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 31&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
More added to [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Was not able to commit to svn due to current LAN problems at college. Will commit tomorrow. For now here is the code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 14&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote code for catching errors in equation where the derivative is raised to a higher/lower power. This was part of Goal 1.3.2. Svn committed the code: http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 13&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have come up with a simplified algorithm for Goal 1.4.2 after going through the code which simplifies equations. Will try to implement it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2951</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2951"/>
		<updated>2011-08-04T22:06:33Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Goals */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during [[GSOC2011]].&lt;br /&gt;
&lt;br /&gt;
Code branch: {{srcbranchdir|karthik|}} &lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# Evaluation of mass matrix for a wide range of systems of equations, in the form of a set of CUnit test cases:&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Accepting all equations and creating a mass matrix of correct dimensions.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying all derivatives in an equation.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Finding the real values of derivative variables.&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying the derivatives using these real values.&amp;lt;/strike&amp;gt; &lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Checking if the equation is linear with respect to the derivatives.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of the derivative contains another variable which is not fixed.&amp;lt;/strike&amp;gt; &lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is raised to a power other than 1.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is in the denominator.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is present in the index of any term.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is inside a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of derivative contains a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Display corresponding error messages.&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating the coefficient.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating a base coefficient to the derivative.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Compounding the base coefficient while processing terms in the equation.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Processing the coefficients and entering them to the mass matrix.&amp;lt;/strike&amp;gt;&lt;br /&gt;
# Complete DAE solution of those solutions using RADAU5.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;July 31&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
More added to [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Was not able to commit to svn due to current LAN problems at college. Will commit tomorrow. For now here is the code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 14&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote code for catching errors in equation where the derivative is raised to a higher/lower power. This was part of Goal 1.3.2. Svn committed the code: http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 13&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have come up with a simplified algorithm for Goal 1.4.2 after going through the code which simplifies equations. Will try to implement it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2950</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2950"/>
		<updated>2011-08-04T22:05:51Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Goals */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during [[GSOC2011]].&lt;br /&gt;
&lt;br /&gt;
Code branch: {{srcbranchdir|karthik|}} &lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# Evaluation of mass matrix for a wide range of systems of equations, in the form of a set of CUnit test cases:&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Accepting all equations and creating a mass matrix of correct dimensions.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying all derivatives in an equation.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Finding the real values of derivative variables.&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying the derivatives using these real values.&amp;lt;/strike&amp;gt; &lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Checking if the equation is linear with respect to the derivatives.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of the derivative contains another variable which is not fixed.&amp;lt;/strike&amp;gt; &lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is raised to a power other than 1.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is in the denominator.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is present in the index of any term.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is inside a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of derivative contains a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Display corresponding error messages.&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating the coefficient.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating a base coefficient to the derivative.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Compounding the base coefficient while processing terms in the equation.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Processing the coefficients and entering them to the mass matrix.&amp;lt;/strike&amp;gt;&lt;br /&gt;
# Complete DAE solution of those solutions using RADAU5.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;July 31&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
More added to [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Was not able to commit to svn due to current LAN problems at college. Will commit tomorrow. For now here is the code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 14&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote code for catching errors in equation where the derivative is raised to a higher/lower power. This was part of Goal 1.3.2. Svn committed the code: http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 13&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have come up with a simplified algorithm for Goal 1.4.2 after going through the code which simplifies equations. Will try to implement it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358/Coefficient_Calculator&amp;diff=2937</id>
		<title>User:Karthik0112358/Coefficient Calculator</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358/Coefficient_Calculator&amp;diff=2937"/>
		<updated>2011-07-31T22:39:00Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*	ASCEND modelling environment&lt;br /&gt;
	Copyright (C) 1997, 2006 Carnegie Mellon University&lt;br /&gt;
	Copyright (C) 1993, 1994 Joseph James Zaher, Benjamin Andrew Allan&lt;br /&gt;
	Copyright (C) 1993 Joseph James Zaher&lt;br /&gt;
	Copyright (C) 1990 Thomas Guthrie Epperly, Karl Michael Westerberg&lt;br /&gt;
&lt;br /&gt;
	This program is free software; you can redistribute it and/or modify&lt;br /&gt;
	it under the terms of the GNU General Public License as published by&lt;br /&gt;
	the Free Software Foundation; either version 2, or (at your option)&lt;br /&gt;
	any later version.&lt;br /&gt;
&lt;br /&gt;
	This program is distributed in the hope that it will be useful,&lt;br /&gt;
	but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
	GNU General Public License for more details.&lt;br /&gt;
&lt;br /&gt;
	You should have received a copy of the GNU General Public License&lt;br /&gt;
	along with this program; if not, write to the Free Software&lt;br /&gt;
	Foundation, Inc., 59 Temple Place - Suite 330,&lt;br /&gt;
	Boston, MA 02111-1307, USA.&lt;br /&gt;
*/&lt;br /&gt;
/*&lt;br /&gt;
KARTHIK C S, June 2011&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;lt;math.h&amp;gt;&lt;br /&gt;
#include &amp;quot;relation_util.h&amp;quot;&lt;br /&gt;
#include &amp;lt;ascend/general/ascMalloc.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/general/panic.h&amp;gt;&lt;br /&gt;
#include &amp;quot;relation_type.h&amp;quot;&lt;br /&gt;
#include &amp;quot;expr_types.h&amp;quot;&lt;br /&gt;
#include &amp;quot;instance_enum.h&amp;quot;&lt;br /&gt;
#include &amp;quot;functype.h&amp;quot;&lt;br /&gt;
#include &amp;quot;mathinst.c&amp;quot;&lt;br /&gt;
/*------------------------------------------------------------------------------&lt;br /&gt;
  FINDING COEFFICIENTS OF THE DERIVATIVE TERMS IN A RELATION&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
	Compute the coefficients of the derivative terms in the relation (compiler-side routine)&lt;br /&gt;
&lt;br /&gt;
	@param i Instance pointer through which the coefficients of the derivative terms of the relation are found&lt;br /&gt;
	@param coefficient pointer to a double in which the coefficients shall be stored (must have already been allocated)&lt;br /&gt;
	@param Info of structure Info_abt_deriv which contains the real value of all the derivative variables&lt;br /&gt;
&lt;br /&gt;
 	@return 0 on success, and otherwise on failure&lt;br /&gt;
&lt;br /&gt;
	Here we compute the coefficients of the derivative terms by first extracting each term. &lt;br /&gt;
	We then check if its a derivative variable and if so we compute its coefficient by considering the terms previous to it and after it. &lt;br /&gt;
	In this process we also check if the equation is linear wrt its derivatives. Suitable error messages are displayed if its not.&lt;br /&gt;
*/&lt;br /&gt;
/* Started reorganizing the entire Inspect_Equation(). Providing modularity for efficiency and flexibility.*/&lt;br /&gt;
/*&lt;br /&gt;
static int Inspect_Equation(struct Info_abt_deriv Info,int *order,double *var,double *func,int *ope,unsigned long length_rel){&lt;br /&gt;
	int i,j,k;&lt;br /&gt;
	int varc=-1,opec=-1,funcc=-1,numc=-1;&lt;br /&gt;
	int flag,count,c,denom_flag,point;&lt;br /&gt;
	unsigned long bin_num,pass,new_bin_num;&lt;br /&gt;
	for (i=0;i&amp;lt;Info.no_of_deriv;i++){&lt;br /&gt;
		flag=0;&lt;br /&gt;
		for(j=0;j&amp;lt;length_rel;j++){&lt;br /&gt;
			switch(order[j]){&lt;br /&gt;
				case 1:&lt;br /&gt;
					++numc;&lt;br /&gt;
					break;&lt;br /&gt;
				case 2:&lt;br /&gt;
					++varc;&lt;br /&gt;
					//Write Error catching analysis code here&lt;br /&gt;
					if(Info.deriv_values[i]==var[varc]) {&lt;br /&gt;
						if(order[j-1]==2) {&lt;br /&gt;
							count=1;&lt;br /&gt;
							c=1;&lt;br /&gt;
							k=0;&lt;br /&gt;
							while(count!=0&amp;amp;&amp;amp;(j+c)&amp;lt;=length_rel) {&lt;br /&gt;
								count=(order[c+j]==3)?--count:++count;&lt;br /&gt;
								k=(order[c+j]==3)?++k:k;&lt;br /&gt;
								++c;&lt;br /&gt;
							}&lt;br /&gt;
							--c;&lt;br /&gt;
							if(ope[opec+k]!=1||ope[opec+k]!=2){&lt;br /&gt;
								CONSOLE_DEBUG(&amp;quot;The coefficient of the derivative term contains a non constant term&amp;quot;);&lt;br /&gt;
							}&lt;br /&gt;
						}else if(order[j+1]==2) {&lt;br /&gt;
							count=1;&lt;br /&gt;
							c=2;&lt;br /&gt;
							k=0;&lt;br /&gt;
							while(count!=0&amp;amp;&amp;amp;(j+c)&amp;lt;=length_rel){	&lt;br /&gt;
								count=(order[c+j]==3)?--count:++count;&lt;br /&gt;
								k=(order[c+j]==3)?++k:k;&lt;br /&gt;
								++c;&lt;br /&gt;
							}&lt;br /&gt;
							--c;&lt;br /&gt;
							if(ope[opec+k]!=1||ope[opec+k]!=2){&lt;br /&gt;
								CONSOLE_DEBUG(&amp;quot;The coefficient of the derivative term contains a non constant term&amp;quot;);&lt;br /&gt;
							}	&lt;br /&gt;
						}&lt;br /&gt;
						c=1;&lt;br /&gt;
						count=0;&lt;br /&gt;
						denom_flag=0;&lt;br /&gt;
						while(order[j+c]!=4&amp;amp;&amp;amp;(j+c)&amp;lt;=length_rel) {&lt;br /&gt;
							if(order[c+j]==3) {&lt;br /&gt;
								++count;&lt;br /&gt;
								if(ope[opec+count]==4) {&lt;br /&gt;
									if(count&amp;gt;c-count) {&lt;br /&gt;
										denom_flag=(denom_flag==0)?1:0;&lt;br /&gt;
									}&lt;br /&gt;
								}					&lt;br /&gt;
							}							&lt;br /&gt;
							++c;						&lt;br /&gt;
						}&lt;br /&gt;
						if(denom_flag==1){&lt;br /&gt;
							CONSOLE_DEBUG(&amp;quot;The derivative is in denominator&amp;quot;);&lt;br /&gt;
						}&lt;br /&gt;
						c=1;&lt;br /&gt;
						count=0;&lt;br /&gt;
						while(order[j+c]!=4&amp;amp;&amp;amp;(j+c)&amp;lt;=length_rel) {&lt;br /&gt;
							if(order[c+j]==3) {&lt;br /&gt;
								++count;&lt;br /&gt;
								if(ope[opec+count]==6) {&lt;br /&gt;
									if(count&amp;gt;c-count) {&lt;br /&gt;
										CONSOLE_DEBUG(&amp;quot;The derivative is in index&amp;quot;);&lt;br /&gt;
									}&lt;br /&gt;
								}					&lt;br /&gt;
							}							&lt;br /&gt;
							++c;						&lt;br /&gt;
						}&lt;br /&gt;
						/* We implement here an algorithm which finds the span of an operator. The span of an operator &lt;br /&gt;
						is defined as the number of terms the operator links in an expression. We see if the derivative &lt;br /&gt;
						is in the upper span (the set of terms to the left of an operator in infix form) of the operator, &lt;br /&gt;
						by using a variable to point at the location of the derivative in a binary representation of the &lt;br /&gt;
						relation where 0 means a number or variable and 1 means an operator. Then we display an error is &lt;br /&gt;
						the derivative is raised to a higher/lower power.* /&lt;br /&gt;
						c=0;&lt;br /&gt;
						count=-1;&lt;br /&gt;
						bin_num=0;&lt;br /&gt;
						pass=0;&lt;br /&gt;
						/* Need to write code here to check if the derivative is being raised to power 1. &lt;br /&gt;
						The idea is to locate every ^ operator and see if the item immediately following &lt;br /&gt;
						it in the infix notation is 1 which does not have any prior connection with any other&lt;br /&gt;
						operator. * /&lt;br /&gt;
						/* As a second thought, I think I will segregate each Error case as a function, considering the recursive algorithms used in some of the cases. * /&lt;br /&gt;
						if(flag==0){						&lt;br /&gt;
							while(order[c]!=4){&lt;br /&gt;
								++c;		&lt;br /&gt;
							}&lt;br /&gt;
							for(k=c-1;k&amp;gt;=0;k--) {&lt;br /&gt;
								if(order[k]==3) {&lt;br /&gt;
									bin_num+=pow(2,c-k-1);&lt;br /&gt;
								}&lt;br /&gt;
							}&lt;br /&gt;
							point=j;&lt;br /&gt;
							for(k=c-1;k&amp;gt;=0;k--) {&lt;br /&gt;
								if(bin_num-pass&amp;gt;0) {	&lt;br /&gt;
									++count;									&lt;br /&gt;
									pass+=pow(2,k);							&lt;br /&gt;
									if(point+k==c-3) {&lt;br /&gt;
										if(ope[count]==6) {&lt;br /&gt;
											CONSOLE_DEBUG(&amp;quot;The derivative is raised to a power other than one&amp;quot;);&lt;br /&gt;
										} else {&lt;br /&gt;
											&lt;br /&gt;
										}&lt;br /&gt;
									} else {&lt;br /&gt;
	&lt;br /&gt;
									}&lt;br /&gt;
								}&lt;br /&gt;
							}	&lt;br /&gt;
						}else {&lt;br /&gt;
							while(order[c]!=4){&lt;br /&gt;
								++c;&lt;br /&gt;
							}&lt;br /&gt;
							++c;&lt;br /&gt;
							while(c&amp;lt;=length_rel) {&lt;br /&gt;
								++c;						&lt;br /&gt;
							}&lt;br /&gt;
						}&lt;br /&gt;
					}&lt;br /&gt;
					break;&lt;br /&gt;
				case 3:&lt;br /&gt;
					++opec;&lt;br /&gt;
					break;&lt;br /&gt;
				case 4:&lt;br /&gt;
					flag=1;&lt;br /&gt;
					break;&lt;br /&gt;
				default:&lt;br /&gt;
					/* Give Error Message * /	&lt;br /&gt;
					break;		&lt;br /&gt;
			}&lt;br /&gt;
		}		&lt;br /&gt;
	}&lt;br /&gt;
	return 1;&lt;br /&gt;
}&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/* So here it begins */&lt;br /&gt;
&lt;br /&gt;
char* find_left_bin_number(int *,unsigned long ,int *);&lt;br /&gt;
char* find_right_bin_number(int *,unsigned long ,int *);&lt;br /&gt;
int find_variable(struct Info_abt_deriv, double);&lt;br /&gt;
check_for_alg_coeff();&lt;br /&gt;
&lt;br /&gt;
/* Functions need to write:&lt;br /&gt;
check_in denominator();&lt;br /&gt;
check_in_indices();&lt;br /&gt;
check_in_bases();&lt;br /&gt;
check_for_func_coeff();&lt;br /&gt;
check_inside_func();&lt;br /&gt;
shift_by_one();&lt;br /&gt;
shift_by_two();&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
static int Inspect_Equation(struct Info_abt_deriv Info,int *order,double *var,double *func,int *ope,unsigned long length_rel){&lt;br /&gt;
	int result;&lt;br /&gt;
	int var_index;&lt;br /&gt;
	char *left_bin_num,*right_bin_num;&lt;br /&gt;
	int *len_left_bin_num,*len_right_bin_num; /* Pointers are used so that these can be passed by reference */&lt;br /&gt;
	left_bin_num=ASC_NEW_ARRAY(char,length_rel);&lt;br /&gt;
	right_bin_num=ASC_NEW_ARRAY(char,length_rel);&lt;br /&gt;
	left_bin_num=find_left_bin_number(order,length_rel,len_left_bin_num);&lt;br /&gt;
	right_bin_num=find_right_bin_number(order,length_rel,len_right_bin_num);&lt;br /&gt;
	result=0;&lt;br /&gt;
/* We write here an inspection for special cases, like : 3=4+Q(x,y)/x, where is Q(x,y) is a linear function in x */&lt;br /&gt;
&lt;br /&gt;
/* End of special cases */&lt;br /&gt;
&lt;br /&gt;
/* We start inspecting general cases */&lt;br /&gt;
&lt;br /&gt;
	flag=0;&lt;br /&gt;
	for(j=0;j&amp;lt;length_rel;j++){&lt;br /&gt;
		switch(order[j]){&lt;br /&gt;
			case 1:&lt;br /&gt;
				++numc;&lt;br /&gt;
				break;&lt;br /&gt;
			case 2:&lt;br /&gt;
				++varc;&lt;br /&gt;
				/* Write Error catching analysis code here */&lt;br /&gt;
				var_index=find_variable(Info,var[varc]);&lt;br /&gt;
				if(var_index!=0){&lt;br /&gt;
					result+=check_in denominator(left_bin_num,len_left_bin_num,right_bin_num,len_right_bin_num,var_index,flag);&lt;br /&gt;
					result+=check_in_indices();&lt;br /&gt;
					result+=check_in_bases();&lt;br /&gt;
					result+=check_for_alg_coeff();&lt;br /&gt;
					result+=check_for_func_coeff();&lt;br /&gt;
					result+=check_inside_func();&lt;br /&gt;
				}&lt;br /&gt;
				break;&lt;br /&gt;
			case 3:&lt;br /&gt;
				++opec;&lt;br /&gt;
				break;&lt;br /&gt;
			case 4:&lt;br /&gt;
				flag=1;&lt;br /&gt;
				break;&lt;br /&gt;
			default:&lt;br /&gt;
				/* Give Error Message */	&lt;br /&gt;
				break;		&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	return (result&amp;gt;0)?0:1;&lt;br /&gt;
}&lt;br /&gt;
char* find_left_bin_number(int *order,unsigned long length_rel,int *len_left_bin_num) {&lt;br /&gt;
	int i;&lt;br /&gt;
	char *bin_num;&lt;br /&gt;
	bin_num=ASC_NEW_ARRAY(char,length_rel);&lt;br /&gt;
	for(i=0;order[i]!=4;i++) {&lt;br /&gt;
		bin_num[i](order[i]&amp;lt;=2)?&#039;0&#039;:&#039;1&#039;;&lt;br /&gt;
		*len_left_bin_num=i+1;&lt;br /&gt;
	}	&lt;br /&gt;
	return bin_num;&lt;br /&gt;
}&lt;br /&gt;
char* find_right_bin_number(int *order,unsigned long length_rel,int *len_right_bin_num) {&lt;br /&gt;
	int i,j;&lt;br /&gt;
	char *bin_num;&lt;br /&gt;
	bin_num=ASC_NEW_ARRAY(char,length_rel);&lt;br /&gt;
	for(i=0;order[i]!=4;i++);&lt;br /&gt;
	for(j=i+1;j&amp;lt;=length_rel;j++) {&lt;br /&gt;
		bin_num[j-i-1](order[j]&amp;lt;=2)?&#039;0&#039;:&#039;1&#039;;&lt;br /&gt;
		*len_right_bin_num=j-i-1;&lt;br /&gt;
	}	&lt;br /&gt;
	return bin_num;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int find_variable(struct Info_abt_deriv Info, double index) {&lt;br /&gt;
	int i=0;&lt;br /&gt;
	for(i=0;i&amp;lt;Info.no_of_deriv;i++) {&lt;br /&gt;
		if(Info.deriv_values[i]==index) {&lt;br /&gt;
			return 1;&lt;br /&gt;
		}		&lt;br /&gt;
	}&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int check_for_alg_coeff() {&lt;br /&gt;
/* start code here */&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void coefficient_match(double *coefficient,struct Info_abt_deriv Info,int *order,double *num,double *var,double *func,int *ope, unsigned long length_rel){&lt;br /&gt;
	int i,j,k;&lt;br /&gt;
	double value;&lt;br /&gt;
	int flag;&lt;br /&gt;
	int varc=-1,opec=-1,funcc=-1,numc=-1;&lt;br /&gt;
	int c;&lt;br /&gt;
	if(Inspect_Equation(Info,order,var,func,ope,length_rel)==1){&lt;br /&gt;
		for (i=0;i&amp;lt;Info.no_of_deriv;i++){&lt;br /&gt;
			value=1.0;&lt;br /&gt;
			flag=0;&lt;br /&gt;
			for(j=0;j&amp;lt;length_rel;j++){&lt;br /&gt;
				switch(order[j]){&lt;br /&gt;
					case 1:&lt;br /&gt;
						++numc;&lt;br /&gt;
						break;&lt;br /&gt;
					case 2:&lt;br /&gt;
						++varc;&lt;br /&gt;
						if(Info.deriv_values[i]==var[varc]) {&lt;br /&gt;
							if(order[j-1]==1&amp;amp;&amp;amp;order[j+1]==3) {&lt;br /&gt;
								if(ope[opec+1]==3) {&lt;br /&gt;
									value=num[numc];&lt;br /&gt;
								}&lt;br /&gt;
							}else if(order[j+1]==1&amp;amp;&amp;amp;order[j+2]==3) {&lt;br /&gt;
								if(ope[opec+1]==3) {&lt;br /&gt;
									value=num[numc+1];&lt;br /&gt;
								}&lt;br /&gt;
							}else {							&lt;br /&gt;
								while(order[c+j]!=4){&lt;br /&gt;
									c=1;&lt;br /&gt;
									while(order[c+j]==2||order[c+j]==1) {&lt;br /&gt;
										c++;&lt;br /&gt;
									}		&lt;br /&gt;
								}								&lt;br /&gt;
							}&lt;br /&gt;
						}&lt;br /&gt;
						break;&lt;br /&gt;
					case 3:&lt;br /&gt;
						++opec;&lt;br /&gt;
						break;&lt;br /&gt;
					case 4:&lt;br /&gt;
						flag=1;&lt;br /&gt;
						break;&lt;br /&gt;
					default:&lt;br /&gt;
					/* Give Error Message */	&lt;br /&gt;
						break;		&lt;br /&gt;
				}&lt;br /&gt;
			}	&lt;br /&gt;
		}&lt;br /&gt;
	}else {&lt;br /&gt;
		CONSOLE_DEBUG(&amp;quot;Equation cannot be accepted by solver&amp;quot;);&lt;br /&gt;
	}	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static int coefficient_calculator(struct Instance *i,double *coefficient,struct Info_abt_deriv Info){&lt;br /&gt;
	struct relation *r;&lt;br /&gt;
	enum Expr_enum reltype;&lt;br /&gt;
	unsigned long t;       			/* the current term in the relation r */&lt;br /&gt;
	unsigned long num_var; 			/* the number of variables in the relation r */&lt;br /&gt;
	unsigned long v;      			/* loop variable */&lt;br /&gt;
	int lhs;               			/* looking at left(=1) or right(=0) hand side of r */&lt;br /&gt;
	unsigned long length_lhs, length_rhs;&lt;br /&gt;
	double *num;				/* pointer for storing all constants in relation */&lt;br /&gt;
	double *var;				/* pointer for storing all real value of variables in relation */&lt;br /&gt;
	int *ope;				/* pointer for storing all operators in relation */&lt;br /&gt;
	double *func;				/* pointer for storing all functions in relation */&lt;br /&gt;
	int *order;				/* pointer for storing order of all constants, variables and operators in postfix form in relation */&lt;br /&gt;
	int varc=0,numc=0,orderc=0,opec=0,funcc=0;	/* counters for various arrays */&lt;br /&gt;
	CONST struct relation_term *term;&lt;br /&gt;
	CONST struct Func *fxnptr;&lt;br /&gt;
	r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
	if( r == NULL ) {&lt;br /&gt;
		CONSOLE_DEBUG(&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
		return -1;&lt;br /&gt;
	}&lt;br /&gt;
	num_var = NumberVariables(r);&lt;br /&gt;
	length_lhs = RelationLength(r, 1);&lt;br /&gt;
	length_rhs = RelationLength(r, 0);&lt;br /&gt;
	num=ASC_NEW_ARRAY(double,length_lhs+length_rhs);&lt;br /&gt;
	var=ASC_NEW_ARRAY(double,length_lhs+length_rhs);&lt;br /&gt;
	ope=ASC_NEW_ARRAY(int,length_lhs+length_rhs);&lt;br /&gt;
	func=ASC_NEW_ARRAY(double,length_lhs+length_rhs);&lt;br /&gt;
	order = ASC_NEW_ARRAY(int,(length_lhs+length_rhs+1));&lt;br /&gt;
	lhs = 1;&lt;br /&gt;
	t = 0;&lt;br /&gt;
&lt;br /&gt;
	for (v=0; v&amp;lt;length_lhs+length_rhs; v++) {&lt;br /&gt;
/* Initializing all entries to 0 */&lt;br /&gt;
		order[v]=0;&lt;br /&gt;
		func[v]=0.0;&lt;br /&gt;
		ope[v]=0;&lt;br /&gt;
		num[v]=0.0;&lt;br /&gt;
		var[v]=0.0;&lt;br /&gt;
	}&lt;br /&gt;
	order[length_lhs+length_rhs]=0;&lt;br /&gt;
	while(1) {&lt;br /&gt;
		if( lhs &amp;amp;&amp;amp; (t &amp;gt;= length_lhs) ) {&lt;br /&gt;
/* need to switch to the right hand side--if it exists */&lt;br /&gt;
			if( length_rhs ) {&lt;br /&gt;
				lhs = t = 0;&lt;br /&gt;
				order[orderc++]=4;&lt;br /&gt;
			} else {&lt;br /&gt;
/* &lt;br /&gt;
	We know that (length_lhs+length_rhs&amp;gt;0) and that (length_rhs==0),&lt;br /&gt;
	the length_lhs must be &amp;gt; 0&lt;br /&gt;
*/&lt;br /&gt;
				coefficient_match(coefficient,Info,order,num,var,func,ope,length_lhs+length_rhs+1);&lt;br /&gt;
			        return 0;&lt;br /&gt;
      			}&lt;br /&gt;
    		} else if( (!lhs) &amp;amp;&amp;amp; (t &amp;gt;= length_rhs) ) {&lt;br /&gt;
/* we have processed both sides, quit */&lt;br /&gt;
				coefficient_match(coefficient,Info,order,num,var,func,ope,length_lhs+length_rhs+1);&lt;br /&gt;
			        return 0;&lt;br /&gt;
		}&lt;br /&gt;
		term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
		switch( RelationTermType(term) ) {&lt;br /&gt;
			case e_zero:&lt;br /&gt;
				num[numc++]=0.0;&lt;br /&gt;
				order[orderc++]=1;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_real:&lt;br /&gt;
				num[numc++]=(double)TermReal(term);&lt;br /&gt;
				order[orderc++]=1;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_int:&lt;br /&gt;
				num[numc++]=(double)TermInteger(term);&lt;br /&gt;
				order[orderc++]=1;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_var:&lt;br /&gt;
				var[varc++]= TermVariable(r, term);&lt;br /&gt;
				order[orderc++]=2;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_plus:&lt;br /&gt;
				ope[opec++]=1;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_minus:&lt;br /&gt;
				ope[opec++]=2;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_times:&lt;br /&gt;
				ope[opec++]=3;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_divide:&lt;br /&gt;
				ope[opec++]=4;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_uminus:&lt;br /&gt;
				ope[opec++]=5;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_power:&lt;br /&gt;
				ope[opec++]=6;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_ipower:&lt;br /&gt;
				ope[opec++]=7;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_func:&lt;br /&gt;
				ope[opec++]=8;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				fxnptr = TermFunc(term);&lt;br /&gt;
				func[funcc] = FuncEval( fxnptr, func[funcc] );&lt;br /&gt;
				++funcc;&lt;br /&gt;
				break;&lt;br /&gt;
			default:&lt;br /&gt;
				ASC_PANIC(&amp;quot;Unknown relation term type&amp;quot;);&lt;br /&gt;
				break;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
	}&lt;br /&gt;
}	&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2936</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2936"/>
		<updated>2011-07-31T22:38:07Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during [[GSOC2011]].&lt;br /&gt;
&lt;br /&gt;
Code branch: {{srcbranchdir|karthik|}} &lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# Evaluation of mass matrix for a wide range of systems of equations, in the form of a set of CUnit test cases:&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Accepting all equations and creating a mass matrix of correct dimensions.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying all derivatives in an equation.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Finding the real values of derivative variables.&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying the derivatives using these real values.&amp;lt;/strike&amp;gt; &lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Checking if the equation is linear with respect to the derivatives.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of the derivative contains another variable which is not fixed.&amp;lt;/strike&amp;gt; &lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is raised to a power other than 1.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is in the denominator.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is present in the index of any term.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is inside a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of derivative contains a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Display corresponding error messages.&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating the coefficient.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating a base coefficient to the derivative.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Compounding the base coefficient while processing terms in the equation.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Processing the coefficients and entering them to the mass matrix.&amp;lt;/strike&amp;gt;&lt;br /&gt;
# Complete DAE solution of those solutions using RADAU5.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;July 31&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
More added to [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Was not able to commit to svn due to current LAN problems at college. Will commit tomorrow. For now here is the code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 14&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote code for catching errors in equation where the derivative is raised to a higher/lower power. This was part of Goal 1.3.2. Svn committed the code: http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 13&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have come up with a simplified algorithm for Goal 1.4.2 after going through the code which simplifies equations. Will try to implement it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358/Coefficient_Calculator&amp;diff=2924</id>
		<title>User:Karthik0112358/Coefficient Calculator</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358/Coefficient_Calculator&amp;diff=2924"/>
		<updated>2011-07-25T21:02:10Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*	ASCEND modelling environment&lt;br /&gt;
	Copyright (C) 1997, 2006 Carnegie Mellon University&lt;br /&gt;
	Copyright (C) 1993, 1994 Joseph James Zaher, Benjamin Andrew Allan&lt;br /&gt;
	Copyright (C) 1993 Joseph James Zaher&lt;br /&gt;
	Copyright (C) 1990 Thomas Guthrie Epperly, Karl Michael Westerberg&lt;br /&gt;
&lt;br /&gt;
	This program is free software; you can redistribute it and/or modify&lt;br /&gt;
	it under the terms of the GNU General Public License as published by&lt;br /&gt;
	the Free Software Foundation; either version 2, or (at your option)&lt;br /&gt;
	any later version.&lt;br /&gt;
&lt;br /&gt;
	This program is distributed in the hope that it will be useful,&lt;br /&gt;
	but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
	GNU General Public License for more details.&lt;br /&gt;
&lt;br /&gt;
	You should have received a copy of the GNU General Public License&lt;br /&gt;
	along with this program; if not, write to the Free Software&lt;br /&gt;
	Foundation, Inc., 59 Temple Place - Suite 330,&lt;br /&gt;
	Boston, MA 02111-1307, USA.&lt;br /&gt;
*/&lt;br /&gt;
/*&lt;br /&gt;
KARTHIK C S, June 2011&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;lt;math.h&amp;gt;&lt;br /&gt;
#include &amp;quot;relation_util.h&amp;quot;&lt;br /&gt;
#include &amp;lt;ascend/general/ascMalloc.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/general/panic.h&amp;gt;&lt;br /&gt;
#include &amp;quot;relation_type.h&amp;quot;&lt;br /&gt;
#include &amp;quot;expr_types.h&amp;quot;&lt;br /&gt;
#include &amp;quot;instance_enum.h&amp;quot;&lt;br /&gt;
#include &amp;quot;functype.h&amp;quot;&lt;br /&gt;
#include &amp;quot;mathinst.c&amp;quot;&lt;br /&gt;
/*------------------------------------------------------------------------------&lt;br /&gt;
  FINDING COEFFICIENTS OF THE DERIVATIVE TERMS IN A RELATION&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
	Compute the coefficients of the derivative terms in the relation (compiler-side routine)&lt;br /&gt;
&lt;br /&gt;
	@param i Instance pointer through which the coefficients of the derivative terms of the relation are found&lt;br /&gt;
	@param coefficient pointer to a double in which the coefficients shall be stored (must have already been allocated)&lt;br /&gt;
	@param Info of structure Info_abt_deriv which contains the real value of all the derivative variables&lt;br /&gt;
&lt;br /&gt;
 	@return 0 on success, and otherwise on failure&lt;br /&gt;
&lt;br /&gt;
	Here we compute the coefficients of the derivative terms by first extracting each term. &lt;br /&gt;
	We then check if its a derivative variable and if so we compute its coefficient by considering the terms previous to it and after it. &lt;br /&gt;
	In this process we also check if the equation is linear wrt its derivatives. Suitable error messages are displayed if its not.&lt;br /&gt;
*/&lt;br /&gt;
/* Started reorganizing the entire Inspect_Equation(). Providing modularity for efficiency and flexibility.*/&lt;br /&gt;
/*&lt;br /&gt;
static int Inspect_Equation(struct Info_abt_deriv Info,int *order,double *var,double *func,int *ope,unsigned long length_rel){&lt;br /&gt;
	int i,j,k;&lt;br /&gt;
	int varc=-1,opec=-1,funcc=-1,numc=-1;&lt;br /&gt;
	int flag,count,c,denom_flag,point;&lt;br /&gt;
	unsigned long bin_num,pass,new_bin_num;&lt;br /&gt;
	for (i=0;i&amp;lt;Info.no_of_deriv;i++){&lt;br /&gt;
		flag=0;&lt;br /&gt;
		for(j=0;j&amp;lt;length_rel;j++){&lt;br /&gt;
			switch(order[j]){&lt;br /&gt;
				case 1:&lt;br /&gt;
					++numc;&lt;br /&gt;
					break;&lt;br /&gt;
				case 2:&lt;br /&gt;
					++varc;&lt;br /&gt;
					//Write Error catching analysis code here&lt;br /&gt;
					if(Info.deriv_values[i]==var[varc]) {&lt;br /&gt;
						if(order[j-1]==2) {&lt;br /&gt;
							count=1;&lt;br /&gt;
							c=1;&lt;br /&gt;
							k=0;&lt;br /&gt;
							while(count!=0&amp;amp;&amp;amp;(j+c)&amp;lt;=length_rel) {&lt;br /&gt;
								count=(order[c+j]==3)?--count:++count;&lt;br /&gt;
								k=(order[c+j]==3)?++k:k;&lt;br /&gt;
								++c;&lt;br /&gt;
							}&lt;br /&gt;
							--c;&lt;br /&gt;
							if(ope[opec+k]!=1||ope[opec+k]!=2){&lt;br /&gt;
								CONSOLE_DEBUG(&amp;quot;The coefficient of the derivative term contains a non constant term&amp;quot;);&lt;br /&gt;
							}&lt;br /&gt;
						}else if(order[j+1]==2) {&lt;br /&gt;
							count=1;&lt;br /&gt;
							c=2;&lt;br /&gt;
							k=0;&lt;br /&gt;
							while(count!=0&amp;amp;&amp;amp;(j+c)&amp;lt;=length_rel){	&lt;br /&gt;
								count=(order[c+j]==3)?--count:++count;&lt;br /&gt;
								k=(order[c+j]==3)?++k:k;&lt;br /&gt;
								++c;&lt;br /&gt;
							}&lt;br /&gt;
							--c;&lt;br /&gt;
							if(ope[opec+k]!=1||ope[opec+k]!=2){&lt;br /&gt;
								CONSOLE_DEBUG(&amp;quot;The coefficient of the derivative term contains a non constant term&amp;quot;);&lt;br /&gt;
							}	&lt;br /&gt;
						}&lt;br /&gt;
						c=1;&lt;br /&gt;
						count=0;&lt;br /&gt;
						denom_flag=0;&lt;br /&gt;
						while(order[j+c]!=4&amp;amp;&amp;amp;(j+c)&amp;lt;=length_rel) {&lt;br /&gt;
							if(order[c+j]==3) {&lt;br /&gt;
								++count;&lt;br /&gt;
								if(ope[opec+count]==4) {&lt;br /&gt;
									if(count&amp;gt;c-count) {&lt;br /&gt;
										denom_flag=(denom_flag==0)?1:0;&lt;br /&gt;
									}&lt;br /&gt;
								}					&lt;br /&gt;
							}							&lt;br /&gt;
							++c;						&lt;br /&gt;
						}&lt;br /&gt;
						if(denom_flag==1){&lt;br /&gt;
							CONSOLE_DEBUG(&amp;quot;The derivative is in denominator&amp;quot;);&lt;br /&gt;
						}&lt;br /&gt;
						c=1;&lt;br /&gt;
						count=0;&lt;br /&gt;
						while(order[j+c]!=4&amp;amp;&amp;amp;(j+c)&amp;lt;=length_rel) {&lt;br /&gt;
							if(order[c+j]==3) {&lt;br /&gt;
								++count;&lt;br /&gt;
								if(ope[opec+count]==6) {&lt;br /&gt;
									if(count&amp;gt;c-count) {&lt;br /&gt;
										CONSOLE_DEBUG(&amp;quot;The derivative is in index&amp;quot;);&lt;br /&gt;
									}&lt;br /&gt;
								}					&lt;br /&gt;
							}							&lt;br /&gt;
							++c;						&lt;br /&gt;
						}&lt;br /&gt;
						/* We implement here an algorithm which finds the span of an operator. The span of an operator &lt;br /&gt;
						is defined as the number of terms the operator links in an expression. We see if the derivative &lt;br /&gt;
						is in the upper span (the set of terms to the left of an operator in infix form) of the operator, &lt;br /&gt;
						by using a variable to point at the location of the derivative in a binary representation of the &lt;br /&gt;
						relation where 0 means a number or variable and 1 means an operator. Then we display an error is &lt;br /&gt;
						the derivative is raised to a higher/lower power.* /&lt;br /&gt;
						c=0;&lt;br /&gt;
						count=-1;&lt;br /&gt;
						bin_num=0;&lt;br /&gt;
						pass=0;&lt;br /&gt;
						/* Need to write code here to check if the derivative is being raised to power 1. &lt;br /&gt;
						The idea is to locate every ^ operator and see if the item immediately following &lt;br /&gt;
						it in the infix notation is 1 which does not have any prior connection with any other&lt;br /&gt;
						operator. * /&lt;br /&gt;
						/* As a second thought, I think I will segregate each Error case as a function, considering the recursive algorithms used in some of the cases. * /&lt;br /&gt;
						if(flag==0){						&lt;br /&gt;
							while(order[c]!=4){&lt;br /&gt;
								++c;		&lt;br /&gt;
							}&lt;br /&gt;
							for(k=c-1;k&amp;gt;=0;k--) {&lt;br /&gt;
								if(order[k]==3) {&lt;br /&gt;
									bin_num+=pow(2,c-k-1);&lt;br /&gt;
								}&lt;br /&gt;
							}&lt;br /&gt;
							point=j;&lt;br /&gt;
							for(k=c-1;k&amp;gt;=0;k--) {&lt;br /&gt;
								if(bin_num-pass&amp;gt;0) {	&lt;br /&gt;
									++count;									&lt;br /&gt;
									pass+=pow(2,k);							&lt;br /&gt;
									if(point+k==c-3) {&lt;br /&gt;
										if(ope[count]==6) {&lt;br /&gt;
											CONSOLE_DEBUG(&amp;quot;The derivative is raised to a power other than one&amp;quot;);&lt;br /&gt;
										} else {&lt;br /&gt;
											&lt;br /&gt;
										}&lt;br /&gt;
									} else {&lt;br /&gt;
	&lt;br /&gt;
									}&lt;br /&gt;
								}&lt;br /&gt;
							}	&lt;br /&gt;
						}else {&lt;br /&gt;
							while(order[c]!=4){&lt;br /&gt;
								++c;&lt;br /&gt;
							}&lt;br /&gt;
							++c;&lt;br /&gt;
							while(c&amp;lt;=length_rel) {&lt;br /&gt;
								++c;						&lt;br /&gt;
							}&lt;br /&gt;
						}&lt;br /&gt;
					}&lt;br /&gt;
					break;&lt;br /&gt;
				case 3:&lt;br /&gt;
					++opec;&lt;br /&gt;
					break;&lt;br /&gt;
				case 4:&lt;br /&gt;
					flag=1;&lt;br /&gt;
					break;&lt;br /&gt;
				default:&lt;br /&gt;
					/* Give Error Message * /	&lt;br /&gt;
					break;		&lt;br /&gt;
			}&lt;br /&gt;
		}		&lt;br /&gt;
	}&lt;br /&gt;
	return 1;&lt;br /&gt;
}&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/* So here it begins */&lt;br /&gt;
&lt;br /&gt;
static int Inspect_Equation(struct Info_abt_deriv Info,int *order,double *var,double *func,int *ope,unsigned long length_rel){&lt;br /&gt;
	double var_index;&lt;br /&gt;
	char *left_bin_num,*right_bin_num;&lt;br /&gt;
	left_bin_num=find_left_bin_number(order,length_rel);&lt;br /&gt;
	right_bin_num=find_right_bin_number(order,length_rel);&lt;br /&gt;
/* We write here an inspection for special cases, like : 3=4+Q(x,y)/x, where is Q(x,y) is a linear function in x */&lt;br /&gt;
&lt;br /&gt;
/* End of special cases */&lt;br /&gt;
&lt;br /&gt;
/* We start inspecting general cases */&lt;br /&gt;
&lt;br /&gt;
	flag=0;&lt;br /&gt;
	for(j=0;j&amp;lt;length_rel;j++){&lt;br /&gt;
		switch(order[j]){&lt;br /&gt;
			case 1:&lt;br /&gt;
				++numc;&lt;br /&gt;
				break;&lt;br /&gt;
			case 2:&lt;br /&gt;
				++varc;&lt;br /&gt;
				/* Write Error catching analysis code here */&lt;br /&gt;
				var_index=find_variable(Info,var[varc]);&lt;br /&gt;
				if(var_index!=0){&lt;br /&gt;
					&lt;br /&gt;
				}&lt;br /&gt;
				break;&lt;br /&gt;
			case 3:&lt;br /&gt;
				++opec;&lt;br /&gt;
				break;&lt;br /&gt;
			case 4:&lt;br /&gt;
				flag=1;&lt;br /&gt;
				break;&lt;br /&gt;
			default:&lt;br /&gt;
				/* Give Error Message */	&lt;br /&gt;
				break;		&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	return 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void coefficient_match(double *coefficient,struct Info_abt_deriv Info,int *order,double *num,double *var,double *func,int *ope, unsigned long length_rel){&lt;br /&gt;
	int i,j,k;&lt;br /&gt;
	double value;&lt;br /&gt;
	int flag;&lt;br /&gt;
	int varc=-1,opec=-1,funcc=-1,numc=-1;&lt;br /&gt;
	int c;&lt;br /&gt;
	if(Inspect_Equation(Info,order,var,func,ope,length_rel)==1){&lt;br /&gt;
		for (i=0;i&amp;lt;Info.no_of_deriv;i++){&lt;br /&gt;
			value=1.0;&lt;br /&gt;
			flag=0;&lt;br /&gt;
			for(j=0;j&amp;lt;length_rel;j++){&lt;br /&gt;
				switch(order[j]){&lt;br /&gt;
					case 1:&lt;br /&gt;
						++numc;&lt;br /&gt;
						break;&lt;br /&gt;
					case 2:&lt;br /&gt;
						++varc;&lt;br /&gt;
						if(Info.deriv_values[i]==var[varc]) {&lt;br /&gt;
							if(order[j-1]==1&amp;amp;&amp;amp;order[j+1]==3) {&lt;br /&gt;
								if(ope[opec+1]==3) {&lt;br /&gt;
									value=num[numc];&lt;br /&gt;
								}&lt;br /&gt;
							}else if(order[j+1]==1&amp;amp;&amp;amp;order[j+2]==3) {&lt;br /&gt;
								if(ope[opec+1]==3) {&lt;br /&gt;
									value=num[numc+1];&lt;br /&gt;
								}&lt;br /&gt;
							}else {							&lt;br /&gt;
								while(order[c+j]!=4){&lt;br /&gt;
									c=1;&lt;br /&gt;
									while(order[c+j]==2||order[c+j]==1) {&lt;br /&gt;
										c++;&lt;br /&gt;
									}		&lt;br /&gt;
								}								&lt;br /&gt;
							}&lt;br /&gt;
						}&lt;br /&gt;
						break;&lt;br /&gt;
					case 3:&lt;br /&gt;
						++opec;&lt;br /&gt;
						break;&lt;br /&gt;
					case 4:&lt;br /&gt;
						flag=1;&lt;br /&gt;
						break;&lt;br /&gt;
					default:&lt;br /&gt;
					/* Give Error Message */	&lt;br /&gt;
						break;		&lt;br /&gt;
				}&lt;br /&gt;
			}	&lt;br /&gt;
		}&lt;br /&gt;
	}else {&lt;br /&gt;
		CONSOLE_DEBUG(&amp;quot;Equation cannot be accepted by solver&amp;quot;);&lt;br /&gt;
	}	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static int coefficient_calculator(struct Instance *i,double *coefficient,struct Info_abt_deriv Info){&lt;br /&gt;
	struct relation *r;&lt;br /&gt;
	enum Expr_enum reltype;&lt;br /&gt;
	unsigned long t;       			/* the current term in the relation r */&lt;br /&gt;
	unsigned long num_var; 			/* the number of variables in the relation r */&lt;br /&gt;
	unsigned long v;      			/* loop variable */&lt;br /&gt;
	int lhs;               			/* looking at left(=1) or right(=0) hand side of r */&lt;br /&gt;
	unsigned long length_lhs, length_rhs;&lt;br /&gt;
	double *num;				/* pointer for storing all constants in relation */&lt;br /&gt;
	double *var;				/* pointer for storing all real value of variables in relation */&lt;br /&gt;
	int *ope;				/* pointer for storing all operators in relation */&lt;br /&gt;
	double *func;				/* pointer for storing all functions in relation */&lt;br /&gt;
	int *order;				/* pointer for storing order of all constants, variables and operators in postfix form in relation */&lt;br /&gt;
	int varc=0,numc=0,orderc=0,opec=0,funcc=0;	/* counters for various arrays */&lt;br /&gt;
	CONST struct relation_term *term;&lt;br /&gt;
	CONST struct Func *fxnptr;&lt;br /&gt;
	r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
	if( r == NULL ) {&lt;br /&gt;
		CONSOLE_DEBUG(&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
		return -1;&lt;br /&gt;
	}&lt;br /&gt;
	num_var = NumberVariables(r);&lt;br /&gt;
	length_lhs = RelationLength(r, 1);&lt;br /&gt;
	length_rhs = RelationLength(r, 0);&lt;br /&gt;
	num=ASC_NEW_ARRAY(double,length_lhs+length_rhs);&lt;br /&gt;
	var=ASC_NEW_ARRAY(double,length_lhs+length_rhs);&lt;br /&gt;
	ope=ASC_NEW_ARRAY(int,length_lhs+length_rhs);&lt;br /&gt;
	func=ASC_NEW_ARRAY(double,length_lhs+length_rhs);&lt;br /&gt;
	order = ASC_NEW_ARRAY(int,(length_lhs+length_rhs+1));&lt;br /&gt;
	lhs = 1;&lt;br /&gt;
	t = 0;&lt;br /&gt;
&lt;br /&gt;
	for (v=0; v&amp;lt;length_lhs+length_rhs; v++) {&lt;br /&gt;
/* Initializing all entries to 0 */&lt;br /&gt;
		order[v]=0;&lt;br /&gt;
		func[v]=0.0;&lt;br /&gt;
		ope[v]=0;&lt;br /&gt;
		num[v]=0.0;&lt;br /&gt;
		var[v]=0.0;&lt;br /&gt;
	}&lt;br /&gt;
	order[length_lhs+length_rhs]=0;&lt;br /&gt;
	while(1) {&lt;br /&gt;
		if( lhs &amp;amp;&amp;amp; (t &amp;gt;= length_lhs) ) {&lt;br /&gt;
/* need to switch to the right hand side--if it exists */&lt;br /&gt;
			if( length_rhs ) {&lt;br /&gt;
				lhs = t = 0;&lt;br /&gt;
				order[orderc++]=4;&lt;br /&gt;
			} else {&lt;br /&gt;
/* &lt;br /&gt;
	We know that (length_lhs+length_rhs&amp;gt;0) and that (length_rhs==0),&lt;br /&gt;
	the length_lhs must be &amp;gt; 0&lt;br /&gt;
*/&lt;br /&gt;
				coefficient_match(coefficient,Info,order,num,var,func,ope,length_lhs+length_rhs+1);&lt;br /&gt;
			        return 0;&lt;br /&gt;
      			}&lt;br /&gt;
    		} else if( (!lhs) &amp;amp;&amp;amp; (t &amp;gt;= length_rhs) ) {&lt;br /&gt;
/* we have processed both sides, quit */&lt;br /&gt;
				coefficient_match(coefficient,Info,order,num,var,func,ope,length_lhs+length_rhs+1);&lt;br /&gt;
			        return 0;&lt;br /&gt;
		}&lt;br /&gt;
		term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
		switch( RelationTermType(term) ) {&lt;br /&gt;
			case e_zero:&lt;br /&gt;
				num[numc++]=0.0;&lt;br /&gt;
				order[orderc++]=1;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_real:&lt;br /&gt;
				num[numc++]=(double)TermReal(term);&lt;br /&gt;
				order[orderc++]=1;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_int:&lt;br /&gt;
				num[numc++]=(double)TermInteger(term);&lt;br /&gt;
				order[orderc++]=1;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_var:&lt;br /&gt;
				var[varc++]= TermVariable(r, term);&lt;br /&gt;
				order[orderc++]=2;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_plus:&lt;br /&gt;
				ope[opec++]=1;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_minus:&lt;br /&gt;
				ope[opec++]=2;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_times:&lt;br /&gt;
				ope[opec++]=3;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_divide:&lt;br /&gt;
				ope[opec++]=4;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_uminus:&lt;br /&gt;
				ope[opec++]=5;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_power:&lt;br /&gt;
				ope[opec++]=6;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_ipower:&lt;br /&gt;
				ope[opec++]=7;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_func:&lt;br /&gt;
				ope[opec++]=8;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				fxnptr = TermFunc(term);&lt;br /&gt;
				func[funcc] = FuncEval( fxnptr, func[funcc] );&lt;br /&gt;
				++funcc;&lt;br /&gt;
				break;&lt;br /&gt;
			default:&lt;br /&gt;
				ASC_PANIC(&amp;quot;Unknown relation term type&amp;quot;);&lt;br /&gt;
				break;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
	}&lt;br /&gt;
}	&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358/Coefficient_Calculator&amp;diff=2923</id>
		<title>User:Karthik0112358/Coefficient Calculator</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358/Coefficient_Calculator&amp;diff=2923"/>
		<updated>2011-07-25T20:59:48Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*	ASCEND modelling environment&lt;br /&gt;
	Copyright (C) 1997, 2006 Carnegie Mellon University&lt;br /&gt;
	Copyright (C) 1993, 1994 Joseph James Zaher, Benjamin Andrew Allan&lt;br /&gt;
	Copyright (C) 1993 Joseph James Zaher&lt;br /&gt;
	Copyright (C) 1990 Thomas Guthrie Epperly, Karl Michael Westerberg&lt;br /&gt;
&lt;br /&gt;
	This program is free software; you can redistribute it and/or modify&lt;br /&gt;
	it under the terms of the GNU General Public License as published by&lt;br /&gt;
	the Free Software Foundation; either version 2, or (at your option)&lt;br /&gt;
	any later version.&lt;br /&gt;
&lt;br /&gt;
	This program is distributed in the hope that it will be useful,&lt;br /&gt;
	but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
	GNU General Public License for more details.&lt;br /&gt;
&lt;br /&gt;
	You should have received a copy of the GNU General Public License&lt;br /&gt;
	along with this program; if not, write to the Free Software&lt;br /&gt;
	Foundation, Inc., 59 Temple Place - Suite 330,&lt;br /&gt;
	Boston, MA 02111-1307, USA.&lt;br /&gt;
*/&lt;br /&gt;
/*&lt;br /&gt;
KARTHIK C S, June 2011&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;lt;math.h&amp;gt;&lt;br /&gt;
#include &amp;quot;relation_util.h&amp;quot;&lt;br /&gt;
#include &amp;lt;ascend/general/ascMalloc.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/general/panic.h&amp;gt;&lt;br /&gt;
#include &amp;quot;relation_type.h&amp;quot;&lt;br /&gt;
#include &amp;quot;expr_types.h&amp;quot;&lt;br /&gt;
#include &amp;quot;instance_enum.h&amp;quot;&lt;br /&gt;
#include &amp;quot;functype.h&amp;quot;&lt;br /&gt;
#include &amp;quot;mathinst.c&amp;quot;&lt;br /&gt;
/*------------------------------------------------------------------------------&lt;br /&gt;
  FINDING COEFFICIENTS OF THE DERIVATIVE TERMS IN A RELATION&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
	Compute the coefficients of the derivative terms in the relation (compiler-side routine)&lt;br /&gt;
&lt;br /&gt;
	@param i Instance pointer through which the coefficients of the derivative terms of the relation are found&lt;br /&gt;
	@param coefficient pointer to a double in which the coefficients shall be stored (must have already been allocated)&lt;br /&gt;
	@param Info of structure Info_abt_deriv which contains the real value of all the derivative variables&lt;br /&gt;
&lt;br /&gt;
 	@return 0 on success, and otherwise on failure&lt;br /&gt;
&lt;br /&gt;
	Here we compute the coefficients of the derivative terms by first extracting each term. &lt;br /&gt;
	We then check if its a derivative variable and if so we compute its coefficient by considering the terms previous to it and after it. &lt;br /&gt;
	In this process we also check if the equation is linear wrt its derivatives. Suitable error messages are displayed if its not.&lt;br /&gt;
*/&lt;br /&gt;
/* Started reorganizing the entire Inspect_Equation(). Providing modularity for efficiency and flexibility.*/&lt;br /&gt;
/*&lt;br /&gt;
static int Inspect_Equation(struct Info_abt_deriv Info,int *order,double *var,double *func,int *ope,unsigned long length_rel){&lt;br /&gt;
	int i,j,k;&lt;br /&gt;
	int varc=-1,opec=-1,funcc=-1,numc=-1;&lt;br /&gt;
	int flag,count,c,denom_flag,point;&lt;br /&gt;
	unsigned long bin_num,pass,new_bin_num;&lt;br /&gt;
	for (i=0;i&amp;lt;Info.no_of_deriv;i++){&lt;br /&gt;
		flag=0;&lt;br /&gt;
		for(j=0;j&amp;lt;length_rel;j++){&lt;br /&gt;
			switch(order[j]){&lt;br /&gt;
				case 1:&lt;br /&gt;
					++numc;&lt;br /&gt;
					break;&lt;br /&gt;
				case 2:&lt;br /&gt;
					++varc;&lt;br /&gt;
					//Write Error catching analysis code here&lt;br /&gt;
					if(Info.deriv_values[i]==var[varc]) {&lt;br /&gt;
						if(order[j-1]==2) {&lt;br /&gt;
							count=1;&lt;br /&gt;
							c=1;&lt;br /&gt;
							k=0;&lt;br /&gt;
							while(count!=0&amp;amp;&amp;amp;(j+c)&amp;lt;=length_rel) {&lt;br /&gt;
								count=(order[c+j]==3)?--count:++count;&lt;br /&gt;
								k=(order[c+j]==3)?++k:k;&lt;br /&gt;
								++c;&lt;br /&gt;
							}&lt;br /&gt;
							--c;&lt;br /&gt;
							if(ope[opec+k]!=1||ope[opec+k]!=2){&lt;br /&gt;
								CONSOLE_DEBUG(&amp;quot;The coefficient of the derivative term contains a non constant term&amp;quot;);&lt;br /&gt;
							}&lt;br /&gt;
						}else if(order[j+1]==2) {&lt;br /&gt;
							count=1;&lt;br /&gt;
							c=2;&lt;br /&gt;
							k=0;&lt;br /&gt;
							while(count!=0&amp;amp;&amp;amp;(j+c)&amp;lt;=length_rel){	&lt;br /&gt;
								count=(order[c+j]==3)?--count:++count;&lt;br /&gt;
								k=(order[c+j]==3)?++k:k;&lt;br /&gt;
								++c;&lt;br /&gt;
							}&lt;br /&gt;
							--c;&lt;br /&gt;
							if(ope[opec+k]!=1||ope[opec+k]!=2){&lt;br /&gt;
								CONSOLE_DEBUG(&amp;quot;The coefficient of the derivative term contains a non constant term&amp;quot;);&lt;br /&gt;
							}	&lt;br /&gt;
						}&lt;br /&gt;
						c=1;&lt;br /&gt;
						count=0;&lt;br /&gt;
						denom_flag=0;&lt;br /&gt;
						while(order[j+c]!=4&amp;amp;&amp;amp;(j+c)&amp;lt;=length_rel) {&lt;br /&gt;
							if(order[c+j]==3) {&lt;br /&gt;
								++count;&lt;br /&gt;
								if(ope[opec+count]==4) {&lt;br /&gt;
									if(count&amp;gt;c-count) {&lt;br /&gt;
										denom_flag=(denom_flag==0)?1:0;&lt;br /&gt;
									}&lt;br /&gt;
								}					&lt;br /&gt;
							}							&lt;br /&gt;
							++c;						&lt;br /&gt;
						}&lt;br /&gt;
						if(denom_flag==1){&lt;br /&gt;
							CONSOLE_DEBUG(&amp;quot;The derivative is in denominator&amp;quot;);&lt;br /&gt;
						}&lt;br /&gt;
						c=1;&lt;br /&gt;
						count=0;&lt;br /&gt;
						while(order[j+c]!=4&amp;amp;&amp;amp;(j+c)&amp;lt;=length_rel) {&lt;br /&gt;
							if(order[c+j]==3) {&lt;br /&gt;
								++count;&lt;br /&gt;
								if(ope[opec+count]==6) {&lt;br /&gt;
									if(count&amp;gt;c-count) {&lt;br /&gt;
										CONSOLE_DEBUG(&amp;quot;The derivative is in index&amp;quot;);&lt;br /&gt;
									}&lt;br /&gt;
								}					&lt;br /&gt;
							}							&lt;br /&gt;
							++c;						&lt;br /&gt;
						}&lt;br /&gt;
						/* We implement here an algorithm which finds the span of an operator. The span of an operator &lt;br /&gt;
						is defined as the number of terms the operator links in an expression. We see if the derivative &lt;br /&gt;
						is in the upper span (the set of terms to the left of an operator in infix form) of the operator, &lt;br /&gt;
						by using a variable to point at the location of the derivative in a binary representation of the &lt;br /&gt;
						relation where 0 means a number or variable and 1 means an operator. Then we display an error is &lt;br /&gt;
						the derivative is raised to a higher/lower power.*/&lt;br /&gt;
						c=0;&lt;br /&gt;
						count=-1;&lt;br /&gt;
						bin_num=0;&lt;br /&gt;
						pass=0;&lt;br /&gt;
						/* Need to write code here to check if the derivative is being raised to power 1. &lt;br /&gt;
						The idea is to locate every ^ operator and see if the item immediately following &lt;br /&gt;
						it in the infix notation is 1 which does not have any prior connection with any other&lt;br /&gt;
						operator. */&lt;br /&gt;
						/* As a second thought, I think I will segregate each Error case as a function, considering the recursive 							algorithms used in some of the cases. */&lt;br /&gt;
						if(flag==0){						&lt;br /&gt;
							while(order[c]!=4){&lt;br /&gt;
								++c;		&lt;br /&gt;
							}&lt;br /&gt;
							for(k=c-1;k&amp;gt;=0;k--) {&lt;br /&gt;
								if(order[k]==3) {&lt;br /&gt;
									bin_num+=pow(2,c-k-1);&lt;br /&gt;
								}&lt;br /&gt;
							}&lt;br /&gt;
							point=j;&lt;br /&gt;
							for(k=c-1;k&amp;gt;=0;k--) {&lt;br /&gt;
								if(bin_num-pass&amp;gt;0) {	&lt;br /&gt;
									++count;									&lt;br /&gt;
									pass+=pow(2,k);							&lt;br /&gt;
									if(point+k==c-3) {&lt;br /&gt;
										if(ope[count]==6) {&lt;br /&gt;
											CONSOLE_DEBUG(&amp;quot;The derivative is raised to a power other than one&amp;quot;);&lt;br /&gt;
										} else {&lt;br /&gt;
											&lt;br /&gt;
										}&lt;br /&gt;
									} else {&lt;br /&gt;
	&lt;br /&gt;
									}&lt;br /&gt;
								}&lt;br /&gt;
							}	&lt;br /&gt;
						}else {&lt;br /&gt;
							while(order[c]!=4){&lt;br /&gt;
								++c;&lt;br /&gt;
							}&lt;br /&gt;
							++c;&lt;br /&gt;
							while(c&amp;lt;=length_rel) {&lt;br /&gt;
								++c;						&lt;br /&gt;
							}&lt;br /&gt;
						}&lt;br /&gt;
					}&lt;br /&gt;
					break;&lt;br /&gt;
				case 3:&lt;br /&gt;
					++opec;&lt;br /&gt;
					break;&lt;br /&gt;
				case 4:&lt;br /&gt;
					flag=1;&lt;br /&gt;
					break;&lt;br /&gt;
				default:&lt;br /&gt;
					/* Give Error Message */	&lt;br /&gt;
					break;		&lt;br /&gt;
			}&lt;br /&gt;
		}		&lt;br /&gt;
	}&lt;br /&gt;
	return 1;&lt;br /&gt;
}&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/* So here it begins */&lt;br /&gt;
&lt;br /&gt;
static int Inspect_Equation(struct Info_abt_deriv Info,int *order,double *var,double *func,int *ope,unsigned long length_rel){&lt;br /&gt;
	double var_index;&lt;br /&gt;
	char *left_bin_num,*right_bin_num;&lt;br /&gt;
	left_bin_num=find_left_bin_number(order,length_rel);&lt;br /&gt;
	right_bin_num=find_right_bin_number(order,length_rel);&lt;br /&gt;
/* We write here an inspection for special cases, like : 3=4+Q(x,y)/x, where is Q(x,y) is a linear function in x */&lt;br /&gt;
&lt;br /&gt;
/* End of special cases */&lt;br /&gt;
&lt;br /&gt;
/* We start inspecting general cases */&lt;br /&gt;
&lt;br /&gt;
	flag=0;&lt;br /&gt;
	for(j=0;j&amp;lt;length_rel;j++){&lt;br /&gt;
		switch(order[j]){&lt;br /&gt;
			case 1:&lt;br /&gt;
				++numc;&lt;br /&gt;
				break;&lt;br /&gt;
			case 2:&lt;br /&gt;
				++varc;&lt;br /&gt;
				/* Write Error catching analysis code here */&lt;br /&gt;
				var_index=find_variable(Info,var[varc]);&lt;br /&gt;
				if(var_index!=0){&lt;br /&gt;
					&lt;br /&gt;
				}&lt;br /&gt;
				break;&lt;br /&gt;
			case 3:&lt;br /&gt;
				++opec;&lt;br /&gt;
				break;&lt;br /&gt;
			case 4:&lt;br /&gt;
				flag=1;&lt;br /&gt;
				break;&lt;br /&gt;
			default:&lt;br /&gt;
				/* Give Error Message */	&lt;br /&gt;
				break;		&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	return 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void coefficient_match(double *coefficient,struct Info_abt_deriv Info,int *order,double *num,double *var,double *func,int *ope, unsigned long length_rel){&lt;br /&gt;
	int i,j,k;&lt;br /&gt;
	double value;&lt;br /&gt;
	int flag;&lt;br /&gt;
	int varc=-1,opec=-1,funcc=-1,numc=-1;&lt;br /&gt;
	int c;&lt;br /&gt;
	if(Inspect_Equation(Info,order,var,func,ope,length_rel)==1){&lt;br /&gt;
		for (i=0;i&amp;lt;Info.no_of_deriv;i++){&lt;br /&gt;
			value=1.0;&lt;br /&gt;
			flag=0;&lt;br /&gt;
			for(j=0;j&amp;lt;length_rel;j++){&lt;br /&gt;
				switch(order[j]){&lt;br /&gt;
					case 1:&lt;br /&gt;
						++numc;&lt;br /&gt;
						break;&lt;br /&gt;
					case 2:&lt;br /&gt;
						++varc;&lt;br /&gt;
						if(Info.deriv_values[i]==var[varc]) {&lt;br /&gt;
							if(order[j-1]==1&amp;amp;&amp;amp;order[j+1]==3) {&lt;br /&gt;
								if(ope[opec+1]==3) {&lt;br /&gt;
									value=num[numc];&lt;br /&gt;
								}&lt;br /&gt;
							}else if(order[j+1]==1&amp;amp;&amp;amp;order[j+2]==3) {&lt;br /&gt;
								if(ope[opec+1]==3) {&lt;br /&gt;
									value=num[numc+1];&lt;br /&gt;
								}&lt;br /&gt;
							}else {							&lt;br /&gt;
								while(order[c+j]!=4){&lt;br /&gt;
									c=1;&lt;br /&gt;
									while(order[c+j]==2||order[c+j]==1) {&lt;br /&gt;
										c++;&lt;br /&gt;
									}		&lt;br /&gt;
								}								&lt;br /&gt;
							}&lt;br /&gt;
						}&lt;br /&gt;
						break;&lt;br /&gt;
					case 3:&lt;br /&gt;
						++opec;&lt;br /&gt;
						break;&lt;br /&gt;
					case 4:&lt;br /&gt;
						flag=1;&lt;br /&gt;
						break;&lt;br /&gt;
					default:&lt;br /&gt;
					/* Give Error Message */	&lt;br /&gt;
						break;		&lt;br /&gt;
				}&lt;br /&gt;
			}	&lt;br /&gt;
		}&lt;br /&gt;
	}else {&lt;br /&gt;
		CONSOLE_DEBUG(&amp;quot;Equation cannot be accepted by solver&amp;quot;);&lt;br /&gt;
	}	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static int coefficient_calculator(struct Instance *i,double *coefficient,struct Info_abt_deriv Info){&lt;br /&gt;
	struct relation *r;&lt;br /&gt;
	enum Expr_enum reltype;&lt;br /&gt;
	unsigned long t;       			/* the current term in the relation r */&lt;br /&gt;
	unsigned long num_var; 			/* the number of variables in the relation r */&lt;br /&gt;
	unsigned long v;      			/* loop variable */&lt;br /&gt;
	int lhs;               			/* looking at left(=1) or right(=0) hand side of r */&lt;br /&gt;
	unsigned long length_lhs, length_rhs;&lt;br /&gt;
	double *num;				/* pointer for storing all constants in relation */&lt;br /&gt;
	double *var;				/* pointer for storing all real value of variables in relation */&lt;br /&gt;
	int *ope;				/* pointer for storing all operators in relation */&lt;br /&gt;
	double *func;				/* pointer for storing all functions in relation */&lt;br /&gt;
	int *order;				/* pointer for storing order of all constants, variables and operators in postfix form in relation */&lt;br /&gt;
	int varc=0,numc=0,orderc=0,opec=0,funcc=0;	/* counters for various arrays */&lt;br /&gt;
	CONST struct relation_term *term;&lt;br /&gt;
	CONST struct Func *fxnptr;&lt;br /&gt;
	r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
	if( r == NULL ) {&lt;br /&gt;
		CONSOLE_DEBUG(&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
		return -1;&lt;br /&gt;
	}&lt;br /&gt;
	num_var = NumberVariables(r);&lt;br /&gt;
	length_lhs = RelationLength(r, 1);&lt;br /&gt;
	length_rhs = RelationLength(r, 0);&lt;br /&gt;
	num=ASC_NEW_ARRAY(double,length_lhs+length_rhs);&lt;br /&gt;
	var=ASC_NEW_ARRAY(double,length_lhs+length_rhs);&lt;br /&gt;
	ope=ASC_NEW_ARRAY(int,length_lhs+length_rhs);&lt;br /&gt;
	func=ASC_NEW_ARRAY(double,length_lhs+length_rhs);&lt;br /&gt;
	order = ASC_NEW_ARRAY(int,(length_lhs+length_rhs+1));&lt;br /&gt;
	lhs = 1;&lt;br /&gt;
	t = 0;&lt;br /&gt;
&lt;br /&gt;
	for (v=0; v&amp;lt;length_lhs+length_rhs; v++) {&lt;br /&gt;
/* Initializing all entries to 0 */&lt;br /&gt;
		order[v]=0;&lt;br /&gt;
		func[v]=0.0;&lt;br /&gt;
		ope[v]=0;&lt;br /&gt;
		num[v]=0.0;&lt;br /&gt;
		var[v]=0.0;&lt;br /&gt;
	}&lt;br /&gt;
	order[length_lhs+length_rhs]=0;&lt;br /&gt;
	while(1) {&lt;br /&gt;
		if( lhs &amp;amp;&amp;amp; (t &amp;gt;= length_lhs) ) {&lt;br /&gt;
/* need to switch to the right hand side--if it exists */&lt;br /&gt;
			if( length_rhs ) {&lt;br /&gt;
				lhs = t = 0;&lt;br /&gt;
				order[orderc++]=4;&lt;br /&gt;
			} else {&lt;br /&gt;
/* &lt;br /&gt;
	We know that (length_lhs+length_rhs&amp;gt;0) and that (length_rhs==0),&lt;br /&gt;
	the length_lhs must be &amp;gt; 0&lt;br /&gt;
*/&lt;br /&gt;
				coefficient_match(coefficient,Info,order,num,var,func,ope,length_lhs+length_rhs+1);&lt;br /&gt;
			        return 0;&lt;br /&gt;
      			}&lt;br /&gt;
    		} else if( (!lhs) &amp;amp;&amp;amp; (t &amp;gt;= length_rhs) ) {&lt;br /&gt;
/* we have processed both sides, quit */&lt;br /&gt;
				coefficient_match(coefficient,Info,order,num,var,func,ope,length_lhs+length_rhs+1);&lt;br /&gt;
			        return 0;&lt;br /&gt;
		}&lt;br /&gt;
		term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
		switch( RelationTermType(term) ) {&lt;br /&gt;
			case e_zero:&lt;br /&gt;
				num[numc++]=0.0;&lt;br /&gt;
				order[orderc++]=1;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_real:&lt;br /&gt;
				num[numc++]=(double)TermReal(term);&lt;br /&gt;
				order[orderc++]=1;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_int:&lt;br /&gt;
				num[numc++]=(double)TermInteger(term);&lt;br /&gt;
				order[orderc++]=1;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_var:&lt;br /&gt;
				var[varc++]= TermVariable(r, term);&lt;br /&gt;
				order[orderc++]=2;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_plus:&lt;br /&gt;
				ope[opec++]=1;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_minus:&lt;br /&gt;
				ope[opec++]=2;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_times:&lt;br /&gt;
				ope[opec++]=3;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_divide:&lt;br /&gt;
				ope[opec++]=4;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_uminus:&lt;br /&gt;
				ope[opec++]=5;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_power:&lt;br /&gt;
				ope[opec++]=6;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_ipower:&lt;br /&gt;
				ope[opec++]=7;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				break;&lt;br /&gt;
			case e_func:&lt;br /&gt;
				ope[opec++]=8;&lt;br /&gt;
				order[orderc++]=3;&lt;br /&gt;
				fxnptr = TermFunc(term);&lt;br /&gt;
				func[funcc] = FuncEval( fxnptr, func[funcc] );&lt;br /&gt;
				++funcc;&lt;br /&gt;
				break;&lt;br /&gt;
			default:&lt;br /&gt;
				ASC_PANIC(&amp;quot;Unknown relation term type&amp;quot;);&lt;br /&gt;
				break;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
	}&lt;br /&gt;
}	&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2922</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2922"/>
		<updated>2011-07-25T20:57:46Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during [[GSOC2011]].&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# Evaluation of mass matrix for a wide range of systems of equations, in the form of a set of CUnit test cases:&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Accepting all equations and creating a mass matrix of correct dimensions.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying all derivatives in an equation.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Finding the real values of derivative variables.&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying the derivatives using these real values.&amp;lt;/strike&amp;gt; &lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Checking if the equation is linear with respect to the derivatives.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of the derivative contains another variable which is not fixed.&amp;lt;/strike&amp;gt; &lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is raised to a power other than 1.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is in the denominator.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is present in the index of any term.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is inside a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of derivative contains a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Display corresponding error messages.&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating the coefficient.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating a base coefficient to the derivative.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Compounding the base coefficient while processing terms in the equation.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Processing the coefficients and entering them to the mass matrix.&amp;lt;/strike&amp;gt;&lt;br /&gt;
# Complete DAE solution of those solutions using RADAU5.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;July 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Was not able to commit to svn due to current LAN problems at college. Will commit tomorrow. For now here is the code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 14&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote code for catching errors in equation where the derivative is raised to a higher/lower power. This was part of Goal 1.3.2. Svn committed the code: http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 13&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have come up with a simplified algorithm for Goal 1.4.2 after going through the code which simplifies equations. Will try to implement it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2872</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2872"/>
		<updated>2011-07-14T18:55:53Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Goals */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during [[GSOC2011]].&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# Evaluation of mass matrix for a wide range of systems of equations, in the form of a set of CUnit test cases:&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Accepting all equations and creating a mass matrix of correct dimensions.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying all derivatives in an equation.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Finding the real values of derivative variables.&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying the derivatives using these real values.&amp;lt;/strike&amp;gt; &lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Checking if the equation is linear with respect to the derivatives.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of the derivative contains another variable which is not fixed.&amp;lt;/strike&amp;gt; &lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is raised to a power other than 1.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is in the denominator.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is present in the index of any term.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is inside a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of derivative contains a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Display corresponding error messages.&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating the coefficient.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating a base coefficient to the derivative.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Compounding the base coefficient while processing terms in the equation.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Processing the coefficients and entering them to the mass matrix.&amp;lt;/strike&amp;gt;&lt;br /&gt;
# Complete DAE solution of those solutions using RADAU5.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;July 14&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote code for catching errors in equation where the derivative is raised to a higher/lower power. This was part of Goal 1.3.2. Svn committed the code: http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 13&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have come up with a simplified algorithm for Goal 1.4.2 after going through the code which simplifies equations. Will try to implement it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2871</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2871"/>
		<updated>2011-07-14T18:55:13Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during [[GSOC2011]].&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# Evaluation of mass matrix for a wide range of systems of equations, in the form of a set of CUnit test cases:&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Accepting all equations and creating a mass matrix of correct dimensions.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying all derivatives in an equation.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Finding the real values of derivative variables.&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying the derivatives using these real values.&amp;lt;/strike&amp;gt; &lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Checking if the equation is linear with respect to the derivatives.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of the derivative contains another variable which is not fixed.&amp;lt;/strike&amp;gt; &lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is raised to a power other than 1.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is in the denominator.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is present in the index of any term.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is inside a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of derivative contains a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Display corresponding error messages.&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating the coefficient.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating a base coefficient to the derivative.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Compounding the base coefficient while processing terms in the equation.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Processing the coefficients and entering them to the mass matrix.&amp;lt;/strike&amp;gt;&lt;br /&gt;
# Complete DAE solution of those solutions using RADAU5.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;July 14&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Wrote code for catching errors in equation where the derivative is raised to a higher/lower power. This was part of Goal 1.3.2. Svn committed the code: http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 13&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have come up with a simplified algorithm for Goal 1.4.2 after going through the code which simplifies equations. Will try to implement it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2854</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2854"/>
		<updated>2011-07-13T21:57:35Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Goals */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during [[GSOC2011]].&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# Evaluation of mass matrix for a wide range of systems of equations, in the form of a set of CUnit test cases:&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Accepting all equations and creating a mass matrix of correct dimensions.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying all derivatives in an equation.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Finding the real values of derivative variables.&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying the derivatives using these real values.&amp;lt;/strike&amp;gt; &lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Checking if the equation is linear with respect to the derivatives.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of the derivative contains another variable which is not fixed.&amp;lt;/strike&amp;gt; &lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is raised to a power other than 1.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is in the denominator.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is present in the index of any term.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is inside a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of derivative contains a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Display corresponding error messages.&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating the coefficient.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating a base coefficient to the derivative.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Compounding the base coefficient while processing terms in the equation.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Processing the coefficients and entering them to the mass matrix.&amp;lt;/strike&amp;gt;&lt;br /&gt;
# Complete DAE solution of those solutions using RADAU5.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;July 13&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have come up with a simplified algorithm for Goal 1.4.2 after going through the code which simplifies equations. Will try to implement it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2849</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2849"/>
		<updated>2011-07-13T19:33:50Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during [[GSOC2011]].&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# Evaluation of mass matrix for a wide range of systems of equations, in the form of a set of CUnit test cases:&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Accepting all equations and creating a mass matrix of correct dimensions.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying all derivatives in an equation.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Finding the real values of derivative variables.&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying the derivatives using these real values.&amp;lt;/strike&amp;gt; &lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Checking if the equation is linear with respect to the derivatives.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of the derivative contains another variable which is not fixed.&amp;lt;/strike&amp;gt; &lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is raised to a power other than 1.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is in the denominator.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is present in the index of any term.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is inside a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of derivative contains a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Display corresponding error messages.&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating the coefficient.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating a base coefficient to the derivative.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Compounding the base coefficient while processing terms in the equation.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Processing the coefficients and entering them to the mass matrix.&amp;lt;/strike&amp;gt;&lt;br /&gt;
# Complete DAE solution of those solutions using RADAU5.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;July 13&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have come up with a simplified algorithm for Goal 1.4.2 after going through the code which simplifies equations. Will try to implement it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2848</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2848"/>
		<updated>2011-07-13T18:02:57Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Goals */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during [[GSOC2011]].&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# Evaluation of mass matrix for a wide range of systems of equations, in the form of a set of CUnit test cases:&lt;br /&gt;
## &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Accepting all equations and creating a mass matrix of correct dimensions.&amp;lt;/strike&amp;gt;&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying all derivatives in an equation.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Finding the real values of derivative variables.&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying the derivatives using these real values.&amp;lt;/strike&amp;gt; &lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Checking if the equation is linear with respect to the derivatives.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of the derivative contains another variable which is not fixed.&amp;lt;/strike&amp;gt; &lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is raised to a power other than 1.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is in the denominator.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is present in the index of any term.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the derivative is inside a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;If the coefficient of derivative contains a function.&amp;lt;/span&amp;gt;&lt;br /&gt;
### Display corresponding error messages.&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating the coefficient.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating a base coefficient to the derivative.&amp;lt;/strike&amp;gt;&lt;br /&gt;
### &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Compounding the base coefficient while processing terms in the equation.&amp;lt;/span&amp;gt;&lt;br /&gt;
### &amp;lt;strike style=&amp;quot;color:green&amp;quot;&amp;gt;Processing the coefficients and entering them to the mass matrix.&amp;lt;/strike&amp;gt;&lt;br /&gt;
# Complete DAE solution of those solutions using RADAU5.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2847</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2847"/>
		<updated>2011-07-13T17:27:11Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Goals */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during [[GSOC2011]].&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# Evaluation of mass matrix for a wide range of systems of equations, in the form of a set of CUnit test cases:&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Identifying all derivatives in an equation.&amp;lt;/span&amp;gt;&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Checking if the equation is linear with respect to the derivatives.&amp;lt;/span&amp;gt;&lt;br /&gt;
## &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Evaluating the coefficient.&amp;lt;/span&amp;gt;&lt;br /&gt;
# Complete DAE solution of those solutions using RADAU5.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2844</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2844"/>
		<updated>2011-07-12T23:11:29Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during GSOC2011.&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# I would like to implement the option of generating mass matrix in RADAU5. There are 4 parts to this:&lt;br /&gt;
## Identify all terms in equation&lt;br /&gt;
## Checking each term for derivative variables&lt;br /&gt;
## For terms that have a derivative, checking if all factors are constant-valued&lt;br /&gt;
## Evaluating those constant-valued factors and multiplying them together&lt;br /&gt;
# The reduced space SQP (rSQP) algorithm has seen many applications in large-scale engineering models. I intend to accept an input and parse it such that the solver can act on it. Further I am going to take up various test cases and check for bugs/inconsistencies. And if time permits I would like to write an optimization algorithm/code which, based on the given input, decides which is the best solver to send the input to.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;July 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have decided to get the job done in two parts. First a function called Inspect_Equation, which determines if the equation can be solved by Radau5 and is linear. Once the given set of equations pass this function, the coefficients are evaluated in the coefficient_match function. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2807</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2807"/>
		<updated>2011-07-07T04:25:35Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during GSOC2011.&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# I would like to implement the option of generating mass matrix in RADAU5. There are 4 parts to this:&lt;br /&gt;
## Identify all terms in equation&lt;br /&gt;
## Checking each term for derivative variables&lt;br /&gt;
## For terms that have a derivative, checking if all factors are constant-valued&lt;br /&gt;
## Evaluating those constant-valued factors and multiplying them together&lt;br /&gt;
# The reduced space SQP (rSQP) algorithm has seen many applications in large-scale engineering models. I intend to accept an input and parse it such that the solver can act on it. Further I am going to take up various test cases and check for bugs/inconsistencies. And if time permits I would like to write an optimization algorithm/code which, based on the given input, decides which is the best solver to send the input to.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;July 6&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have some svn commits:&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/compiler/coefficient_calculate.c&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.h&lt;br /&gt;
# http://code.ascend4.org/viewvc/code/branches/karthik/ascend/system/mass_matrix.c&lt;br /&gt;
&lt;br /&gt;
One more function in progress. Will add that too ASAP.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2770</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2770"/>
		<updated>2011-07-02T20:54:18Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during GSOC2011.&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# I would like to implement the option of generating mass matrix in RADAU5. There are 4 parts to this:&lt;br /&gt;
## Identify all terms in equation&lt;br /&gt;
## Checking each term for derivative variables&lt;br /&gt;
## For terms that have a derivative, checking if all factors are constant-valued&lt;br /&gt;
## Evaluating those constant-valued factors and multiplying them together&lt;br /&gt;
# The reduced space SQP (rSQP) algorithm has seen many applications in large-scale engineering models. I intend to accept an input and parse it such that the solver can act on it. Further I am going to take up various test cases and check for bugs/inconsistencies. And if time permits I would like to write an optimization algorithm/code which, based on the given input, decides which is the best solver to send the input to.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
* John Pye suggested I concentrate only on linear equations in y&#039;. This reduces my job to give errors in every other case. I am thinking of trying to read if the coefficients of derivatives are either algebraic variables or constants. Otherwise I will display an error message for now. John Pye asked me to display helpful messages along with errors. I will work on that right at the next stage. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2769</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2769"/>
		<updated>2011-07-02T00:40:22Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during GSOC2011.&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# I would like to implement the option of generating mass matrix in RADAU5. There are 4 parts to this:&lt;br /&gt;
## Identify all terms in equation&lt;br /&gt;
## Checking each term for derivative variables&lt;br /&gt;
## For terms that have a derivative, checking if all factors are constant-valued&lt;br /&gt;
## Evaluating those constant-valued factors and multiplying them together&lt;br /&gt;
# The reduced space SQP (rSQP) algorithm has seen many applications in large-scale engineering models. I intend to accept an input and parse it such that the solver can act on it. Further I am going to take up various test cases and check for bugs/inconsistencies. And if time permits I would like to write an optimization algorithm/code which, based on the given input, decides which is the best solver to send the input to.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
* So currently I am looking at a way to implement this piece of code, I had written a few days back: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()]. I need to tweak it into [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] so that I can identify if a term has a derivative. They rest is already done. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2768</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2768"/>
		<updated>2011-07-01T23:55:02Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during GSOC2011.&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# I would like to implement the option of generating mass matrix in RADAU5. There are 4 parts to this:&lt;br /&gt;
## Identify all terms in equation&lt;br /&gt;
## Checking each term for derivative variables&lt;br /&gt;
## For terms that have a derivative, checking if all factors are constant-valued&lt;br /&gt;
## Evaluating those constant-valued factors and multiplying them together&lt;br /&gt;
# The reduced space SQP (rSQP) algorithm has seen many applications in large-scale engineering models. I intend to accept an input and parse it such that the solver can act on it. Further I am going to take up various test cases and check for bugs/inconsistencies. And if time permits I would like to write an optimization algorithm/code which, based on the given input, decides which is the best solver to send the input to.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;July 1&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I just found out that during execution, the relations are stored in a simplified manner. As in if we have an equation:&lt;br /&gt;
&lt;br /&gt;
(20+9)*6*dx_dt[2]= ((3.0+1)*dx_dt[1]) + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
Then it gets reprocessed as:&lt;br /&gt;
&lt;br /&gt;
174*dx_dt[2]= 4.0*dx_dt[1] + 4*x[1] + 7/x[2] &lt;br /&gt;
&lt;br /&gt;
So, Evaluation of coefficient is solved pre-hand. I do not need to worry about this. The equations are simplified and stored in relation structure. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358/Coefficient_Calculator&amp;diff=2763</id>
		<title>User:Karthik0112358/Coefficient Calculator</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358/Coefficient_Calculator&amp;diff=2763"/>
		<updated>2011-06-30T10:58:26Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define INTEG_OTHER_VAR -1L&lt;br /&gt;
#define INTEG_ALGEBRAIC_VAR 0L&lt;br /&gt;
#define INTEG_STATE_VAR 1L&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i,double *coefficient){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   long index, type;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
// the current term in the relation r &lt;br /&gt;
   unsigned long t; &lt;br /&gt;
// the number of variables in the relation r &lt;br /&gt;
   unsigned long num_var; &lt;br /&gt;
// the index of the variable we are looking at &lt;br /&gt;
   unsigned long v;       &lt;br /&gt;
// looking at left(=1) or right(=0) hand side of r &lt;br /&gt;
   int lhs;               &lt;br /&gt;
// the memory for the stacks &lt;br /&gt;
   double *stacks;        &lt;br /&gt;
// height of each stack &lt;br /&gt;
   unsigned long stack_height; &lt;br /&gt;
// the top position in the stacks &lt;br /&gt;
   long s = -1;           &lt;br /&gt;
   unsigned long length_lhs, length_rhs;&lt;br /&gt;
   CONST struct relation_term *term;&lt;br /&gt;
   CONST struct Func *fxnptr;&lt;br /&gt;
   num_var = NumberVariables(r);&lt;br /&gt;
   length_lhs = RelationLength(r, 1);&lt;br /&gt;
   length_rhs = RelationLength(r, 0);&lt;br /&gt;
   if( (length_lhs + length_rhs) == 0 ) {&lt;br /&gt;
      for( v = 0; v &amp;lt; num_var; v++ ) coefficient[v] = 0.0;&lt;br /&gt;
      *residual = 0.0;&lt;br /&gt;
      return 0;&lt;br /&gt;
   }&lt;br /&gt;
   else {&lt;br /&gt;
      stack_height = 1 + MAX(length_lhs,length_rhs);&lt;br /&gt;
   }&lt;br /&gt;
//creating stacks&lt;br /&gt;
   stacks = tmpalloc_array(((num_var+1)*stack_height),double);&lt;br /&gt;
   if( stacks == NULL ) return 1;&lt;br /&gt;
#define res_stack(s)    stacks[(s)]&lt;br /&gt;
#define coeff_stack(v,s) stacks[((v)*stack_height)+(s)]&lt;br /&gt;
   lhs = 1;&lt;br /&gt;
   t = 0;&lt;br /&gt;
   while(1) {&lt;br /&gt;
      if( lhs &amp;amp;&amp;amp; (t &amp;gt;= length_lhs) ) {&lt;br /&gt;
         if( length_rhs ) {&lt;br /&gt;
            lhs = t = 0;&lt;br /&gt;
         }&lt;br /&gt;
         else {&lt;br /&gt;
            for( v = 1; v &amp;lt;= num_var; v++ ) coefficient[v-1] = coeff_stack(v,s);&lt;br /&gt;
            return 0;&lt;br /&gt;
         }&lt;br /&gt;
      }&lt;br /&gt;
      else if( (!lhs) &amp;amp;&amp;amp; (t &amp;gt;= length_rhs) ) {&lt;br /&gt;
         if( length_lhs ) {&lt;br /&gt;
            for( v = 1; v &amp;lt;= num_var; v++ ) {&lt;br /&gt;
               coefficient[v-1] = coeff_stack(v,s-1) - coeff_stack(v,s);&lt;br /&gt;
            }&lt;br /&gt;
            return 0;&lt;br /&gt;
         }&lt;br /&gt;
         else {&lt;br /&gt;
            for( v = 1; v &amp;lt;= num_var; v++ ) {&lt;br /&gt;
               coefficient[v-1] = -coeff_stack(v,s);&lt;br /&gt;
            }&lt;br /&gt;
            return 0;&lt;br /&gt;
         }&lt;br /&gt;
      }&lt;br /&gt;
      term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
/*&lt;br /&gt;
// Here I need something to take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure.&lt;br /&gt;
// Let me assume its done. Let me call it info.&lt;br /&gt;
      type = Classify_Var(info,&amp;amp;index);&lt;br /&gt;
      if(type==INTEG_ALGEBRAIC_VAR){&lt;br /&gt;
// It is an algebraic variable (solver variable)&lt;br /&gt;
      }else if(type==INTEG_OTHER_VAR){&lt;br /&gt;
// It is an independent variable&lt;br /&gt;
      }else if(type&amp;gt;=INTEG_STATE_VAR){&lt;br /&gt;
         if(type == 1){&lt;br /&gt;
// It is one of the states.One of y_i&lt;br /&gt;
         }else if(type == 2){ &lt;br /&gt;
// Detects it as first order derivative. Write suitable code for determining coefficient here.        &lt;br /&gt;
         }else{&lt;br /&gt;
// Error message for higher order derivatives. &lt;br /&gt;
         }   &lt;br /&gt;
      }&lt;br /&gt;
*/&lt;br /&gt;
      switch( RelationTermType(term) ) {&lt;br /&gt;
         case e_zero:&lt;br /&gt;
         case e_real:&lt;br /&gt;
         case e_int:&lt;br /&gt;
            break;&lt;br /&gt;
         case e_var:&lt;br /&gt;
//write code here      &lt;br /&gt;
            break;&lt;br /&gt;
         case e_plus:&lt;br /&gt;
         case e_minus:&lt;br /&gt;
         case e_times:&lt;br /&gt;
         case e_divide:&lt;br /&gt;
         case e_uminus:&lt;br /&gt;
         case e_power:&lt;br /&gt;
         case e_ipower:&lt;br /&gt;
            break;&lt;br /&gt;
         case e_func:&lt;br /&gt;
            break;&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
#undef grad_stack&lt;br /&gt;
#undef res_stack&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358/coefficient_find&amp;diff=2762</id>
		<title>User:Karthik0112358/coefficient find</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358/coefficient_find&amp;diff=2762"/>
		<updated>2011-06-30T08:16:22Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//This is just a function. I am not sure where to place it (either in a separate place or with in the previous skeletal code).&lt;br /&gt;
int coefficient_find(struct rel_relation *rel, const var_filter_t *filter,real64 *coefficients,int32 *variables,int32 *count){&lt;br /&gt;
   const struct var_variable **vlist=NULL;&lt;br /&gt;
   int32 len,c;&lt;br /&gt;
   real64 *coefficient;&lt;br /&gt;
   int status;&lt;br /&gt;
   assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
   len = rel_n_incidences(rel);&lt;br /&gt;
   vlist = rel_incidence_list(rel);&lt;br /&gt;
   *count = 0;&lt;br /&gt;
   coefficient = (real64 *)rel_tmpalloc(len*sizeof(real64));&lt;br /&gt;
   assert(coefficient !=NULL);&lt;br /&gt;
   status =(int32)Coefficient_Calculator(rel_instance(rel),coefficient); &lt;br /&gt;
   for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
      if (var_apply_filter(vlist[c],filter)) {&lt;br /&gt;
         variables[*count] = var_sindex(vlist[c]);&lt;br /&gt;
         coefficients[*count] = coefficient[c];&lt;br /&gt;
         (*count)++;&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2761</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2761"/>
		<updated>2011-06-30T07:19:03Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during GSOC2011.&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# I would like to implement the option of generating mass matrix in RADAU5. There are 4 parts to this:&lt;br /&gt;
## Identify all terms in equation&lt;br /&gt;
## Checking each term for derivative variables&lt;br /&gt;
## For terms that have a derivative, checking if all factors are constant-valued&lt;br /&gt;
## Evaluating those constant-valued factors and multiplying them together&lt;br /&gt;
# The reduced space SQP (rSQP) algorithm has seen many applications in large-scale engineering models. I intend to accept an input and parse it such that the solver can act on it. Further I am going to take up various test cases and check for bugs/inconsistencies. And if time permits I would like to write an optimization algorithm/code which, based on the given input, decides which is the best solver to send the input to.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;June 30&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Implementation of the pseudo-code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2754</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2754"/>
		<updated>2011-06-29T03:28:19Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during GSOC2011.&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# I would like to implement the option of generating mass matrix in RADAU5. There are 4 parts to this:&lt;br /&gt;
## Identify all terms in equation&lt;br /&gt;
## Checking each term for derivative variables&lt;br /&gt;
## For terms that have a derivative, checking if all factors are constant-valued&lt;br /&gt;
## Evaluating those constant-valued factors and multiplying them together&lt;br /&gt;
# The reduced space SQP (rSQP) algorithm has seen many applications in large-scale engineering models. I intend to accept an input and parse it such that the solver can act on it. Further I am going to take up various test cases and check for bugs/inconsistencies. And if time permits I would like to write an optimization algorithm/code which, based on the given input, decides which is the best solver to send the input to.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2753</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2753"/>
		<updated>2011-06-29T03:26:07Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested to consider more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2752</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2752"/>
		<updated>2011-06-29T03:24:52Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
# After evaluating the entire relation, if a particular derivative was not found, then by default it will be assigned a coefficient of 0.&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested I considered more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2751</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2751"/>
		<updated>2011-06-29T03:22:31Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
# So the code for reading each equation and extracting each term is written in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]. So I start here at the point where I have each term.&lt;br /&gt;
# I write a switch case which considers cases based on the type of the relation term. However each term processed is stored in an structure in a particular way. All numbers are stored in an floating point array, all variables in a character array, all operators in an enum and and array to maintain the order of entry of these terms.&lt;br /&gt;
## Its a real number&lt;br /&gt;
## If its a variable, then:&lt;br /&gt;
### If identified as a term containing a derivative, then I evaluate the coefficient the following way:&lt;br /&gt;
#### Since we have the relation evaluated in postfix manner, I run backwards in the array which contains the order, to find the last collection of terms which makes sense, as in numbers separated properly by operator, etc. I evaluate this to be the coefficient. &lt;br /&gt;
## Its an operator&lt;br /&gt;
&lt;br /&gt;
Again this was the basic outline. After discussing with John Pye, he suggested I considered more cases and I will build on the above pseudo-code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2750</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2750"/>
		<updated>2011-06-29T01:38:19Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during GSOC2011.&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# I would like to implement the option of generating mass matrix in RADAU5. There are 4 parts to this:&lt;br /&gt;
## Identify all terms in equation&lt;br /&gt;
## Checking each term for derivative variables&lt;br /&gt;
## For terms that have a derivative, checking if all factors are constant-valued&lt;br /&gt;
## Evaluating those constant-valued factors and multiplying them together&lt;br /&gt;
# The reduced space SQP (rSQP) algorithm has seen many applications in large-scale engineering models. I intend to accept an input and parse it such that the solver can act on it. Further I am going to take up various test cases and check for bugs/inconsistencies. And if time permits I would like to write an optimization algorithm/code which, based on the given input, decides which is the best solver to send the input to.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;June 29&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So I am updating here some Pseudo-Code regarding the approach at the lowest level:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2749</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2749"/>
		<updated>2011-06-29T00:45:54Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during GSOC2011.&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# I would like to implement the option of generating mass matrix in RADAU5. There are 4 parts to this:&lt;br /&gt;
## Identify all terms in equation&lt;br /&gt;
## Checking each term for derivative variables&lt;br /&gt;
## For terms that have a derivative, checking if all factors are constant-valued&lt;br /&gt;
## Evaluating those constant-valued factors and multiplying them together&lt;br /&gt;
# The reduced space SQP (rSQP) algorithm has seen many applications in large-scale engineering models. I intend to accept an input and parse it such that the solver can act on it. Further I am going to take up various test cases and check for bugs/inconsistencies. And if time permits I would like to write an optimization algorithm/code which, based on the given input, decides which is the best solver to send the input to.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2748</id>
		<title>User:Karthik0112358</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=User:Karthik0112358&amp;diff=2748"/>
		<updated>2011-06-29T00:45:23Z</updated>

		<summary type="html">&lt;p&gt;Karthik0112358: /* Progress reports */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;C S Karthik&#039;&#039;&#039; is an undergraduate at IIT-Bombay and is working on addition of an rSQP optimiser for ASCEND during GSOC2011.&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
# I would like to implement the option of generating mass matrix in RADAU5. There are 4 parts to this:&lt;br /&gt;
## Identify all terms in equation&lt;br /&gt;
## Checking each term for derivative variables&lt;br /&gt;
## For terms that have a derivative, checking if all factors are constant-valued&lt;br /&gt;
## Evaluating those constant-valued factors and multiplying them together&lt;br /&gt;
# The reduced space SQP (rSQP) algorithm has seen many applications in large-scale engineering models. I intend to accept an input and parse it such that the solver can act on it. Further I am going to take up various test cases and check for bugs/inconsistencies. And if time permits I would like to write an optimization algorithm/code which, based on the given input, decides which is the best solver to send the input to.&lt;br /&gt;
&lt;br /&gt;
== Progress reports ==&lt;br /&gt;
&#039;&#039;&#039;June 28&#039;&#039;&#039;&lt;br /&gt;
So what am I able to code uptill now? The following have been accomplished:&lt;br /&gt;
# I am able to read each equation independently.&lt;br /&gt;
# I am able to segregate each term. I am able to identify them as numbers, operators or variables.&lt;br /&gt;
# I am able to find an index for all variables. The algebraic come first followed by the differential.&lt;br /&gt;
What are the problems to be addressed?&lt;br /&gt;
# I am able to capture coefficients of all the terms. But how do I separate the differential terms from the algebraic ones? If only there was a way I knew to find the number of differential or algebraic variables involved (ascend/integrator has some code which addresses this. But it uses variable_var structure). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 25&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some more doxy searches. I am assuming code written on June 24 to be correct and proceed with exploiting var_variable structure.&lt;br /&gt;
&lt;br /&gt;
So here is an idea. To understand the working of relation_term structure, I add print statements in {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}} and try to see how the data members interact. &lt;br /&gt;
&lt;br /&gt;
Apparently, Expr_enum is there for abstraction or atleast it seems so. I do not see any other way out other than the code I wrote yesterday. Need some suggestion here. As a last resort in case John Pye does not agree with my previous idea, I will have to brute force every equation into a particular way by moving terms across (which John Pye did not like). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 24&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I am writing skeletal code for Goal Part 1.1 and 1.2. Will remove it if John Pye tells me it is not apt. &lt;br /&gt;
&lt;br /&gt;
So I have added some code here: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
Further I have written a function needed for above code here: [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()].&lt;br /&gt;
&lt;br /&gt;
I went through a lot of doxy pages, but I was unable to find a way by which I could take data from relation_term structure&#039;s term and pass it to Classify_Var() which accepts var_variable structure. I need some assistance here. If I am able to find a way then Goals: 1.1 and 1.2 would be over. &lt;br /&gt;
&lt;br /&gt;
PS: All function references used in [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()] and [http://ascend4.org/User:Karthik0112358/Classify_Var Classify_Var()] are either from ascend/compiler or ascend/system and none of ascend/integrator are used.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 23&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Today is more like a &amp;quot;No-Coding-day&amp;quot;. I plan to spend the entire day studying all the references John Pye has given me over the last 2 days. Trying to understand expression evaluation data structures to greater depths. Will report more.&lt;br /&gt;
&lt;br /&gt;
# [http://ascend4.org/images/7/77/Ascendimpl.pdf Implementation of an Ascend Interpreter]: Ascend is an object oriented language and hence the concept of dealing with instances. A tree data structure was chosen so that parent-child linkage could be exploited for effective storage and referencing. It is followed by explanation of various functionalities - same, alike, arrays in ASCEND. Base types, Relations are discussed.  After Parsing, we finally come to the main topic- Instantiation. There is stress on the fact that ASCEND executes in a line by line fashion. The Multi-Pass Instantiator seems to have solved the problem of the interpreter&#039;s capability to allow multiple passes by storage of unexecuted instructions in instance data structure. The explanation provided through an algorithm is excellent demonstration. Final Note: Although gave me nice insight, not useful for resolving problem at hand.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 21&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally I have been able to reach the lowest level for coding this mass matrix. It involves rewriting  {{doxy|dc/d30/a00508_source.html|RelationEvaluateResidualGradientSafe()}}. The code as stated below requires some understanding. John Pye had provided some references. Will see if they are related and may help me.&lt;br /&gt;
&lt;br /&gt;
Hopefully the last of the skeletal code: [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()].&lt;br /&gt;
&lt;br /&gt;
So here is some explanation of the intent of [http://ascend4.org/User:Karthik0112358/Coefficient_Calculator Coefficient_Calculator()]: I have assumed the equation looks like Q(x,y,y&#039;)=0. I have tried to find the length of the relation and get each term out. I have dealt with finishing cases also such as when both lhs and rhs are processed or when pointers are passed to top of stack. I would like to add a switch case for various terms which would be preceded by the following code segment:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
term = NewRelationTerm(r, t++, lhs);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 20&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I have worked on a skeletal code (this is an addition to previous skeletal code- in other words providing some flesh to the skeleton) where I try to determine a row entry of the mass matrix: [http://ascend4.org/User:Karthik0112358/coefficient_find coefficient_find()].&lt;br /&gt;
&lt;br /&gt;
Again here I have tried to get a required version of relman_diff2() of {{src|ascend/system/relman.c}}. So in crux the entire task boils down to rewriting RelationCalcResidGradSafe() of {{src|ascend/compiler/relation_util.c}} into a function which gets the coefficients of the derivative terms - Coefficient_Calculator(). I will get a code out for that.&lt;br /&gt;
&lt;br /&gt;
As of now I have a partial code for Coefficient_Calculator():&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int Coefficient_Calculator(struct Instance *i){&lt;br /&gt;
   struct relation *r;&lt;br /&gt;
   enum Expr_enum reltype;&lt;br /&gt;
   int dummy_int;&lt;br /&gt;
   r = (struct relation *)GetInstanceRelation(i, &amp;amp;reltype);&lt;br /&gt;
   if( r == NULL ) {&lt;br /&gt;
      ERROR_REPORTER_HERE(ASC_PROG_ERR,&amp;quot;null relation\n&amp;quot;);&lt;br /&gt;
      return -1;&lt;br /&gt;
   }&lt;br /&gt;
//At this point of writing the code, I realize the significance of why John Pye had asked me to understand expression-evaluation data structures. I need to write cases for reltype. I need some thinking.   &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As part of understanding {{doxy|d8/d7f/a00787.html#ga87d7fb16138e4b6b8ae5a1372b18c81b|Expr_enum}} better, I would like to do a bit of &amp;quot;doxy search&amp;quot;. Will get back with some update. &lt;br /&gt;
&lt;br /&gt;
Simultaneously I will also write some test code file in compiler/test/ and try to see if I can get to know the contents of the structure. I will report worthy findings here. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 19&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
So here is some skeletal-code: [http://ascend4.org/User:Karthik0112358/massmatrix massmatrix()]. This is code for one of the top layers. &lt;br /&gt;
&lt;br /&gt;
I know I haven&#039;t followed the coding style of Ascend. I will modify code ASAP once other parts fall into place.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 17&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
After giving it some thought, I think the structure of the mass matrix function should look more like system_jacobian() which is present in [http://www.ascend4.org/doxy/d1/d56/a00707_source.html#l00028 jacobian.c] in ascend/system. Will sketch a pseudo code out after better clarity.&lt;br /&gt;
&lt;br /&gt;
I am trying to see how to utilize {{doxy|d5/d0f/a00308.html|System Structure}}, as I see potential information regarding extracting coefficients of &#039;&#039;y&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sub&amp;gt;&amp;lt;sup&amp;gt;&#039;&#039;&#039; &#039;&#039;&amp;lt;/sup&amp;gt; in equation. Since I am asked not to access the structure directly, I am looking through its implementation in slv_client.h.&lt;br /&gt;
&lt;br /&gt;
After reading {{src|ascend/system/slv_client.h}} comments (which I might add are very descriptive and helpful), I realize the importance of the rel_relation structure as this contains the equation data. I have stopped trying to understand struct system and focus back on rel_relation.&lt;br /&gt;
&lt;br /&gt;
So here is a plan. I replicate the entire set of codes required to find the Jacobian matrix. Now from what I know entries to the Jacobian are done row wise. Now Jacobian(&#039;&#039;mXn&#039;&#039; matrix) is found out for functions &#039;&#039;F&#039;&#039; : &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt; → &#039;&#039;&#039;R&#039;&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;m&#039;&#039;&amp;lt;/sup&amp;gt;. However with the mass matrix problem, I am dealing with equations. So, my idea is to manipulate these equations into functions and replace the content of  the (&#039;&#039;i&#039;&#039;,&#039;&#039;j&#039;&#039;) entry (by replacing the code which writes the content) into Jacobian with a different set of code, so that we get desirable result. Will get back on this. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 16&#039;&#039;&#039;&lt;br /&gt;
* Reading relman_diff2() and trying to understand what are the input variables, which header to include, etc. Got some nice help from http://www.ascend4.org/doxy/d0/d7e/a00770.html#ga9469a6f8ff5a7d0eec8a1cad74732fdf. Came up with a vague code structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/rel_blackbox.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_util.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ascend/compiler/relation_io.h&amp;gt;&lt;br /&gt;
#include &amp;quot;mass_matrix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;slv_server.h&amp;quot;&lt;br /&gt;
#define IPTR(i) ((struct Instance *)(i))&lt;br /&gt;
#define KILL 0 /* compile dead code if kill = 1 */&lt;br /&gt;
#define REIMPLEMENT 0 /* code that needs to be reimplemented */&lt;br /&gt;
#define rel_tmpalloc_array(nelts,type)  \&lt;br /&gt;
   ((nelts) &amp;gt; 0 ? (type *)tmpalloc((nelts)*sizeof(type)) : NULL)&lt;br /&gt;
static double dsolve_scratch = 0.0;        /* some workspace */&lt;br /&gt;
#define DSOLVE_TOLERANCE 1.0e-08                /* no longer needed */&lt;br /&gt;
#define BROKENKIRK 0&lt;br /&gt;
/* return 0 on success (derivatives, variables and count are output vars too) */&lt;br /&gt;
int massmatrix(struct rel_relation *rel, const var_filter_t *filter&lt;br /&gt;
        ,real64 *derivatives, int32 *variables&lt;br /&gt;
        ,int32 *count){&lt;br /&gt;
  const struct var_variable **vlist=NULL;&lt;br /&gt;
  int32 len,c;&lt;br /&gt;
  int status;&lt;br /&gt;
  //CONSOLE_DEBUG(&amp;quot;In Function: relman_diff2&amp;quot;);&lt;br /&gt;
  assert(rel!=NULL &amp;amp;&amp;amp; filter!=NULL);&lt;br /&gt;
  len = rel_n_incidences(rel);//this gives me the length of incidence- which I think is the number of columns of mass matrix&lt;br /&gt;
  vlist = rel_incidence_list(rel);//have to write rel_mass_matrix() which basically does the same thing&lt;br /&gt;
  *count = 0;&lt;br /&gt;
&lt;br /&gt;
    for (c=0; c &amp;lt; len; c++) {&lt;br /&gt;
     //write the stuff here&lt;br /&gt;
     &lt;br /&gt;
      }&lt;br /&gt;
  return status;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 15&#039;&#039;&#039;&lt;br /&gt;
* Trying to understand about expression-evaluation data structures by reading the following c code: ascend/system/relman.c.&lt;br /&gt;
* Re-reading [http://ascend4.org/Developer%27s_Manual Developer&#039;s Manual] for better clarity.&lt;br /&gt;
* Checked out contents of [http://trilinos.sandia.gov/packages/moocho/ Moocho] and broadly read basic documentation.&lt;br /&gt;
* Installing MOOCHO: Downloaded [http://trilinos.sandia.gov/download/trilinos-10.6.html trilinos-10.6.4-Source.tar.gz]. As first step of the [http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt installation], I downloaded [http://www.cmake.org/cmake/resources/software.html CMake]. In the last step of Installation of CMake, I got the following error: &lt;br /&gt;
&lt;br /&gt;
CMake Error at cmake_install.cmake:36 (FILE):&lt;br /&gt;
file cannot create directory: /usr/local/doc/cmake-2.8.  Maybe need&lt;br /&gt;
administrative privileges.&lt;br /&gt;
&lt;br /&gt;
make: *** [install] Error 1&lt;br /&gt;
&lt;br /&gt;
Further on trying to install Trilinos, with the following commands, I got the following error : &lt;br /&gt;
&lt;br /&gt;
~/SOME_BUILD_DIR$ cmake \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D CMAKE_BUILD_TYPE:STRING=DEBUG \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos ENABLE &amp;lt;moocho&amp;gt;:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D Trilinos_ENABLE_TESTS:BOOL=ON \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; -D DART_TESTING_TIMEOUT:STRING=600 \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $EXTRA_ARGS \&lt;br /&gt;
&lt;br /&gt;
&amp;gt; {TRILINOS_HOME}&lt;br /&gt;
&lt;br /&gt;
bash: moocho: No such file or directory&lt;br /&gt;
&lt;br /&gt;
I contacted Bartlett, Roscoe A (rabartl@sandia.gov) via email regarding this problem. Hoping for an early reply.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;June 6 - June 12&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finding a temporary fix for the mass matrix problem. I have split the task as to finding solution to 2 problems:&lt;br /&gt;
* (i) Making sure algebraic equations are being sent to solver.&lt;br /&gt;
* (ii) Writing a feasible mass matrix function to generate the mass matrix. This depends on (i).&lt;br /&gt;
&lt;br /&gt;
Regarding Solving Part (i), I made an outside link and was able to capture all the variables involved. Trying to use them to find total number of equations. In completing part (ii) I am facing &amp;quot;INSUFFICIENT MEMORY&amp;quot; problem. Trying to fix that too. I am at present able to count total number of variables, solver variables, independent variables and number of differential equations. I would like to figure out a way to count number of free variables.&lt;br /&gt;
&lt;br /&gt;
I have been able to find a solution to part(i), but it has 2 constraints,&lt;br /&gt;
* If number of total variables&amp;gt;&amp;gt;total number of equations, then the max number of substeps has to be reduced.&lt;br /&gt;
* The solution involves providing data outside given data structures and thus cannot employed as it is to ascend.&lt;br /&gt;
&lt;br /&gt;
As far as part (ii) goes, there seems to be a simple fix. I am trying to figure it out through Valgrind&#039;s Memory loss method.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 30 - June 5&#039;&#039;&#039;&lt;br /&gt;
* Completed reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;May 23 - May 29&#039;&#039;&#039;&lt;br /&gt;
* Continue reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prior to 23 May 2011:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Related to rSQP:&lt;br /&gt;
* Started reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. However was later redirected to chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot; from Winston, 1994, 3rd (or a later) Ed., Duxbury Press (Belmont, California) as a preliminary reading for mathematical background. &lt;br /&gt;
* Completed reading chapter 12 (Nonlinear programming) of &amp;quot;Operations Research: Applications and Algorithms&amp;quot;. &lt;br /&gt;
* Re-reading [http://trilinos.sandia.gov/packages/docs/r10.6/packages/moocho/doc/html/MoochoOverview.pdf Mathematical and High-Level Overview of MOOCHO]. &lt;br /&gt;
* Revisited theory behind the Simplex Algorithm from &amp;quot;Introduction to Algorithms&amp;quot;, 3rd Edition, Page 864-879 authored by Cormen, Leisersin, Rivest, Stein. &lt;br /&gt;
&lt;br /&gt;
Related to Radau5:&lt;br /&gt;
* Investigated code ascend/integrator/integrator.h and ascend/integrator/integrator.c to understand the data structures used.&lt;br /&gt;
* Devised and tried implementation of various for the mass matrix problem in solvers/radau5/asc_radau5.c.&lt;br /&gt;
* Settled on the idea of replacing neq with total number of equations as compared to the previous implementation of number of states. &lt;br /&gt;
[[Category:GSOC2011]]&lt;/div&gt;</summary>
		<author><name>Karthik0112358</name></author>
	</entry>
</feed>