Skip to content
Snippets Groups Projects
Commit 5b002816 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

improve compatibility with getdp for list handling

parent a5dcf0fb
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
...@@ -673,7 +673,6 @@ Affectation : ...@@ -673,7 +673,6 @@ Affectation :
} }
// This variant can be used to force the variable type to "list" // This variant can be used to force the variable type to "list"
| tSTRING '[' ']' NumericAffectation ListOfDouble tEND | tSTRING '[' ']' NumericAffectation ListOfDouble tEND
{ {
gmsh_yysymbol &s(gmsh_yysymbols[$1]); gmsh_yysymbol &s(gmsh_yysymbols[$1]);
...@@ -737,6 +736,42 @@ Affectation : ...@@ -737,6 +736,42 @@ Affectation :
} }
Free($1); Free($1);
} }
// for compatibility with GetDP
| tSTRING '(' FExpr ')' NumericAffectation FExpr tEND
{
int index = (int)$3;
if(!gmsh_yysymbols.count($1)){
if(!$5){
gmsh_yysymbol &s(gmsh_yysymbols[$1]);
s.list = true;
s.value.resize(index + 1, 0.);
s.value[index] = $6;
}
else
yymsg(0, "Unknown variable '%s'", $1);
}
else{
gmsh_yysymbol &s(gmsh_yysymbols[$1]);
if(s.list){
if((int)s.value.size() < index + 1) s.value.resize(index + 1, 0.);
switch($5){
case 0 : s.value[index] = $6; break;
case 1 : s.value[index] += $6; break;
case 2 : s.value[index] -= $6; break;
case 3 : s.value[index] *= $6; break;
case 4 :
if($6) s.value[index] /= $6;
else yymsg(0, "Division by zero in '%s[%d] /= %g'", $1, index, $6);
break;
}
}
else
yymsg(0, "Variable '%s' is not a list", $1);
}
Free($1);
}
| tSTRING '[' '{' RecursiveListOfDouble '}' ']' NumericAffectation ListOfDouble tEND | tSTRING '[' '{' RecursiveListOfDouble '}' ']' NumericAffectation ListOfDouble tEND
{ {
if(List_Nbr($4) != List_Nbr($8)){ if(List_Nbr($4) != List_Nbr($8)){
...@@ -783,6 +818,55 @@ Affectation : ...@@ -783,6 +818,55 @@ Affectation :
List_Delete($4); List_Delete($4);
List_Delete($8); List_Delete($8);
} }
// for compatibility with GetDP
| tSTRING '(' '{' RecursiveListOfDouble '}' ')' NumericAffectation ListOfDouble tEND
{
if(List_Nbr($4) != List_Nbr($8)){
yymsg(0, "Incompatible array dimensions in affectation");
}
else{
if(!gmsh_yysymbols.count($1)){
if(!$7){
gmsh_yysymbol &s(gmsh_yysymbols[$1]);
s.list = true;
for(int i = 0; i < List_Nbr($4); i++){
int index = (int)(*(double*)List_Pointer($4, i));
s.value.resize(index + 1, 0.);
s.value[index] = *(double*)List_Pointer($8, i);
}
}
else
yymsg(0, "Unknown variable '%s'", $1);
}
else{
gmsh_yysymbol &s(gmsh_yysymbols[$1]);
if(s.list){
for(int i = 0; i < List_Nbr($4); i++){
int index = (int)(*(double*)List_Pointer($4, i));
double d = *(double*)List_Pointer($8, i);
if((int)s.value.size() < index + 1) s.value.resize(index + 1, 0.);
switch($7){
case 0 : s.value[index] = d; break;
case 1 : s.value[index] += d; break;
case 2 : s.value[index] -= d; break;
case 3 : s.value[index] *= d; break;
case 4 :
if($8) s.value[index] /= d;
else yymsg(0, "Division by zero in '%s[%d] /= %g'", $1, index, d);
break;
}
}
}
else
yymsg(0, "Variable '%s' is not a list", $1);
}
}
Free($1);
List_Delete($4);
List_Delete($8);
}
| tSTRING NumericIncrement tEND | tSTRING NumericIncrement tEND
{ {
if(!gmsh_yysymbols.count($1)) if(!gmsh_yysymbols.count($1))
...@@ -3919,7 +4003,8 @@ FExpr : ...@@ -3919,7 +4003,8 @@ FExpr :
| tModulo '(' FExpr ',' FExpr ')' { $$ = fmod($3, $5); } | tModulo '(' FExpr ',' FExpr ')' { $$ = fmod($3, $5); }
| tHypot '(' FExpr ',' FExpr ')' { $$ = sqrt($3 * $3 + $5 * $5); } | tHypot '(' FExpr ',' FExpr ')' { $$ = sqrt($3 * $3 + $5 * $5); }
| tRand '(' FExpr ')' { $$ = $3 * (double)rand() / (double)RAND_MAX; } | tRand '(' FExpr ')' { $$ = $3 * (double)rand() / (double)RAND_MAX; }
// The following is for GetDP compatibility
// for compatibility with GetDP
| tExp '[' FExpr ']' { $$ = exp($3); } | tExp '[' FExpr ']' { $$ = exp($3); }
| tLog '[' FExpr ']' { $$ = log($3); } | tLog '[' FExpr ']' { $$ = log($3); }
| tLog10 '[' FExpr ']' { $$ = log10($3); } | tLog10 '[' FExpr ']' { $$ = log10($3); }
...@@ -3976,7 +4061,8 @@ FExpr_Single : ...@@ -3976,7 +4061,8 @@ FExpr_Single :
} }
Free($1); Free($1);
} }
// This is for GetDP compatibility (we should generalize it so
// for compatibility with GetDP (we should generalize it so
// that we can create variables with this syntax, use them // that we can create variables with this syntax, use them
// recursively, etc., but I don't have time to do it now) // recursively, etc., but I don't have time to do it now)
| tSTRING '~' '{' FExpr '}' | tSTRING '~' '{' FExpr '}'
...@@ -4394,6 +4480,19 @@ FExpr_Multi : ...@@ -4394,6 +4480,19 @@ FExpr_Multi :
} }
Free($1); Free($1);
} }
// for compatibility with GetDP
| tSTRING '(' ')'
{
$$ = List_Create(2, 1, sizeof(double));
if(!gmsh_yysymbols.count($1))
yymsg(0, "Unknown variable '%s'", $1);
else{
gmsh_yysymbol &s(gmsh_yysymbols[$1]);
for(unsigned int i = 0; i < s.value.size(); i++)
List_Add($$, &s.value[i]);
}
Free($1);
}
| tList '[' tSTRING ']' | tList '[' tSTRING ']'
{ {
$$ = List_Create(2, 1, sizeof(double)); $$ = List_Create(2, 1, sizeof(double));
...@@ -4424,6 +4523,25 @@ FExpr_Multi : ...@@ -4424,6 +4523,25 @@ FExpr_Multi :
Free($1); Free($1);
List_Delete($4); List_Delete($4);
} }
// for compatibility with GetDP
| tSTRING '(' '{' RecursiveListOfDouble '}' ')'
{
$$ = List_Create(2, 1, sizeof(double));
if(!gmsh_yysymbols.count($1))
yymsg(0, "Unknown variable '%s'", $1);
else{
gmsh_yysymbol &s(gmsh_yysymbols[$1]);
for(int i = 0; i < List_Nbr($4); i++){
int index = (int)(*(double*)List_Pointer_Fast($4, i));
if((int)s.value.size() < index + 1)
yymsg(0, "Uninitialized variable '%s[%d]'", $1, index);
else
List_Add($$, &s.value[index]);
}
}
Free($1);
List_Delete($4);
}
; ;
RecursiveListOfDouble : RecursiveListOfDouble :
......
...@@ -1328,9 +1328,11 @@ List of expressions are also widely used, and are defined as: ...@@ -1328,9 +1328,11 @@ List of expressions are also widely used, and are defined as:
@var{expression} | @var{expression} |
@var{expression} : @var{expression} | @var{expression} : @var{expression} |
@var{expression} : @var{expression} : @var{expression} | @var{expression} : @var{expression} : @var{expression} |
@var{string} [ ] | @var{string} [ ] |
@var{string} ( ) |
List [ @var{string} ] | List [ @var{string} ] |
@var{string} [ @{ @var{expression-list} @} ] | @var{string} [ @{ @var{expression-list} @} ] |
@var{string} ( @{ @var{expression-list} @} ) |
Point @{ @var{expression} @} | Point @{ @var{expression} @} |
@var{transform} | @var{transform} |
@var{extrude} @var{extrude}
...@@ -1345,24 +1347,24 @@ containing the range of numbers comprised between two ...@@ -1345,24 +1347,24 @@ containing the range of numbers comprised between two
@w{@var{expression}s}, with a unit incrementation step. The third case @w{@var{expression}s}, with a unit incrementation step. The third case
also permits to create a list containing the range of numbers comprised also permits to create a list containing the range of numbers comprised
between two @w{@var{expression}s}, but with a positive or negative between two @w{@var{expression}s}, but with a positive or negative
incrementation step equal to the third @var{expression}. The fourth and incrementation step equal to the third @var{expression}. The fourth,
fifth cases permit to reference an expression list. The sixth case fifth and sixth cases permit to reference an expression list. The
permits to reference an expression sublist (whose elements are those seventh and eight cases permit to reference an expression sublist (whose
corresponding to the indices provided by the @var{expression-list}). elements are those corresponding to the indices provided by the
The next two cases permit to retrieve the indices of entities created @var{expression-list}). The next two cases permit to retrieve the
through geometrical transformations and extrusions (see indices of entities created through geometrical transformations and
@ref{Transformations}, and @ref{Extrusions}). The last three cases extrusions (see @ref{Transformations}, and @ref{Extrusions}). The last
permit to retrieve the coordinates of a given geometry point three cases permit to retrieve the coordinates of a given geometry point
(@pxref{Points}), to retrieve the id numbers of all points, lines, (@pxref{Points}), to retrieve the id numbers of all points, lines,
surfaces or volumes in the model, or to retrieve the elementary entities surfaces or volumes in the model, or to retrieve the elementary entities
making up physical groups. making up physical groups.
To see the practical use of such expressions, have a look at the first To see the practical use of such expressions, have a look at the first
couple of examples in @ref{Tutorial}. Note that, in order to lighten the couple of examples in @ref{Tutorial}. Note that, in order to lighten the
syntax, you can always omit the braces @code{@{@}} enclosing an syntax, you can omit the braces @code{@{@}} enclosing an
@var{expression-list} if this @var{expression-list} only contains a single @var{expression-list} if this @var{expression-list} only contains a
item. Also note that a braced @var{expression-list} can be preceded by a single item. Also note that a braced @var{expression-list} can be
minus sign in order to change the sign of all the preceded by a minus sign in order to change the sign of all the
@w{@var{expression-list-item}s}. @w{@var{expression-list-item}s}.
@c ......................................................................... @c .........................................................................
...@@ -1835,6 +1837,9 @@ elements (indexed by the left hand side @var{expression-list}) of an ...@@ -1835,6 +1837,9 @@ elements (indexed by the left hand side @var{expression-list}) of an
existing expression list identifier. The two @w{@var{expression-list}s} must existing expression list identifier. The two @w{@var{expression-list}s} must
contain the same number of items. contain the same number of items.
@item @var{string} ( @{ @var{expression-list} @} ) = @{ @var{expression-list} @};
Same as above.
@item @var{string} += @var{expression}; @item @var{string} += @var{expression};
Adds and affects @var{expression} to an existing expression identifier. Adds and affects @var{expression} to an existing expression identifier.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment