[CIG-LONG] Quick question about new JSON format and equation parser

Walter Landry walter at geodynamics.org
Fri Jan 27 11:57:33 PST 2012


Hi George,

I am Cc'ing the cig-long list since this is something that other
people may run into.

George Hilley <hilley at stanford.edu> wrote:
> Hi Walter,
> 
> Happy New Year, and nice to meet you.
> 
> I was looking to use user-defined variables in a JSON Gale 2.0 input
> file as inputs to a set of equations to define boundary conditions
> and geometries of a model.  For example, I would like to specify an
> area for a shape that can be changed by simply changing a user
> defined variable that lives at the top of the file.  Here is a quick
> snippet:
> 
> "W":"40000",
> "Wf":"1000",
> 
> {"Block1Shape":{"Type":"EquationShape",
> "equation":"(z >= L/2) * (x <= (-1/2)*(W+Wf)) + (z <= -L/2)*(x <= (1/2)*(W-Wf)) + (z > -L/2)*(z < L/2)*(z <= (-L/W)*x - (1/2)*L*Wt/W)"},
> 
> L above is likewise defined as a variable in the JSON file.
> 
> This creates a parse error of the form (although this is from another set of equations):
> 
> Error when parsing equation: ((x <= (1/2)*(W+Wf))*scaled_plateRate)
>         Can't evaluate function/operator "+": Argument 1 of function/operator "+" is of type 'v' whereas type 'f' was expected
> 
> I suspect this is because muparserx is not getting the variable
> values passed into it.  Any way to get variables evaluated and then
> pass them into the equation function as floats so that muparserx can
> evaluate the symbolic expressions?

Unfortunately, this is not implemented.  You can define variables
within the equation itself, but you can not use arbitrary variables
from other places in the input file.  So you have to do something like

  "Block1Shape":
  {
    "Type":"EquationShape",
    "equation":"W=40000, Wf=1000, L=1, (z >= L/2) * (x <= (-1/2)*(W+Wf)) + (z <= -L/2)*(x <= (1/2)*(W-Wf)) + (z > -L/2)*(z < L/2)*(z <= (-L/W)*x - (1/2)*L*Wt/W)"
  },

where I assumed L=1.

Cheers,
Walter Landry


More information about the CIG-LONG mailing list