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

generalized Plugin(Extract) so that we can also create vector views
parent ef5ab5ea
Branches
Tags
No related merge requests found
// $Id: Evaluate.cpp,v 1.4 2004-05-13 15:09:45 geuzaine Exp $ // $Id: Evaluate.cpp,v 1.5 2004-05-13 15:54:56 geuzaine Exp $
// //
// Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
// //
...@@ -67,8 +67,8 @@ void GMSH_EvaluatePlugin::getInfos(char *author, char *copyright, ...@@ -67,8 +67,8 @@ void GMSH_EvaluatePlugin::getInfos(char *author, char *copyright,
strcpy(copyright, "DGR (www.multiphysics.com)"); strcpy(copyright, "DGR (www.multiphysics.com)");
strcpy(help_text, strcpy(help_text,
"Plugin(Evaluate) sets the values associated\n" "Plugin(Evaluate) sets the values associated\n"
"with the `TimeStep'-th time step in the view\n" "with the `TimeStep'-th time step in the scalar\n"
"`iView' to the expression `Expression'. In\n" "view `iView' to the expression `Expression'. In\n"
"addition to the usual mathematical functions\n" "addition to the usual mathematical functions\n"
"(Exp, Log, Sqrt, Sin, Cos, Fabs, etc.) and\n" "(Exp, Log, Sqrt, Sin, Cos, Fabs, etc.) and\n"
"operators (+, -, *, /, ^), `Expression' can\n" "operators (+, -, *, /, ^), `Expression' can\n"
......
// $Id: Extract.cpp,v 1.9 2004-05-13 15:09:45 geuzaine Exp $ // $Id: Extract.cpp,v 1.10 2004-05-13 15:54:56 geuzaine Exp $
// //
// Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
// //
...@@ -37,7 +37,9 @@ StringXNumber ExtractOptions_Number[] = { ...@@ -37,7 +37,9 @@ StringXNumber ExtractOptions_Number[] = {
}; };
StringXString ExtractOptions_String[] = { StringXString ExtractOptions_String[] = {
{GMSH_FULLRC, "Expression", NULL, "v0"} {GMSH_FULLRC, "Expression0", NULL, "v0"},
{GMSH_FULLRC, "Expression1", NULL, ""},
{GMSH_FULLRC, "Expression2", NULL, ""}
}; };
extern "C" extern "C"
...@@ -64,14 +66,17 @@ void GMSH_ExtractPlugin::getInfos(char *author, char *copyright, char *help_text ...@@ -64,14 +66,17 @@ void GMSH_ExtractPlugin::getInfos(char *author, char *copyright, char *help_text
strcpy(copyright, "DGR (www.multiphysics.com)"); strcpy(copyright, "DGR (www.multiphysics.com)");
strcpy(help_text, strcpy(help_text,
"Plugin(Extract) extracts a combination of\n" "Plugin(Extract) extracts a combination of\n"
"components from the view `iView', as specified\n" "components from the view `iView'. If\n"
"by `Expression'. In addition to the usual\n" "`Expression1' or `Expression2' is empty, the\n"
"plugin creates a scalar view using\n"
"`Expression0'; otherwise the plugin creates\n"
"a vector view. In addition to the usual\n"
"mathematical functions (Exp, Log, Sqrt, Sin,\n" "mathematical functions (Exp, Log, Sqrt, Sin,\n"
"Cos, Fabs, etc.) and operators (+, -, *, /, ^),\n" "Cos, Fabs, etc.) and operators (+, -, *, /, ^),\n"
"`Expression' can contain the symbols v0, v1,\n" "the expressions can contain the symbols v0,\n"
"v2, ..., vn, which represent the n components\n" "v1, v2, ..., vn, which represent the n\n"
"of the field. If `iView' < 0, the plugin is\n" "components of the field. If `iView' < 0, the\n"
"run on the current view.\n" "plugin is run on the current view.\n"
"\n" "\n"
"Plugin(Extract) creates one new view.\n"); "Plugin(Extract) creates one new view.\n");
} }
...@@ -101,36 +106,56 @@ void GMSH_ExtractPlugin::catchErrorMessage(char *errorMessage) const ...@@ -101,36 +106,56 @@ void GMSH_ExtractPlugin::catchErrorMessage(char *errorMessage) const
strcpy(errorMessage, "Extract failed..."); strcpy(errorMessage, "Extract failed...");
} }
static void extract(char *expr, List_T *inList, int inNb, static void extract(char *expr[3], List_T *inList, int inNb,
List_T *outList, int *outNb, List_T *outListScalar, int *outNbScalar,
List_T *outListVector, int *outNbVector,
int nbTime, int nbNod, int nbComp) int nbTime, int nbNod, int nbComp)
{ {
if(!inNb) if(!inNb)
return; return;
int outNbComp, *outNb;
List_T *outList;
if(!strlen(expr[1]) || !strlen(expr[2])){
outNbComp = 1;
outNb = outNbScalar;
outList = outListScalar;
}
else{
outNbComp = 3;
outNb = outNbVector;
outList = outListVector;
}
// if we have MathEval, we can evaluate arbitrary expressions; // if we have MathEval, we can evaluate arbitrary expressions;
// otherwise, we only allow to extract single components // otherwise, we only allow to extract single components
#if defined(HAVE_MATH_EVAL) #if defined(HAVE_MATH_EVAL)
void *f = evaluator_create(expr); void *f[3];
if(!f){ for(int i = 0; i < outNbComp; i++){
Msg(GERROR, "Invalid expression '%s'", expr); f[i] = evaluator_create(expr[i]);
return; if(!f[i]){
Msg(GERROR, "Invalid expression '%s'", expr[i]);
return;
}
} }
#else #else
int comp; int comp[3];
if (!strcmp(expr, "v0")) comp = 0; for(int i = 0; i < outNbComp; i++){
else if(!strcmp(expr, "v1")) comp = 1; if (!strcmp(expr[i], "v0")) comp[i] = 0;
else if(!strcmp(expr, "v2")) comp = 2; else if(!strcmp(expr[i], "v1")) comp[i] = 1;
else if(!strcmp(expr, "v3")) comp = 3; else if(!strcmp(expr[i], "v2")) comp[i] = 2;
else if(!strcmp(expr, "v4")) comp = 4; else if(!strcmp(expr[i], "v3")) comp[i] = 3;
else if(!strcmp(expr, "v5")) comp = 5; else if(!strcmp(expr[i], "v4")) comp[i] = 4;
else if(!strcmp(expr, "v6")) comp = 6; else if(!strcmp(expr[i], "v5")) comp[i] = 5;
else if(!strcmp(expr, "v7")) comp = 7; else if(!strcmp(expr[i], "v6")) comp[i] = 6;
else if(!strcmp(expr, "v8")) comp = 8; else if(!strcmp(expr[i], "v7")) comp[i] = 7;
else{ else if(!strcmp(expr[i], "v8")) comp[i] = 8;
Msg(GERROR, "Invalid expression '%s'", expr); else{
return; Msg(GERROR, "Invalid expression '%s'", expr[i]);
return;
}
} }
#endif #endif
...@@ -145,28 +170,33 @@ static void extract(char *expr, List_T *inList, int inNb, ...@@ -145,28 +170,33 @@ static void extract(char *expr, List_T *inList, int inNb,
List_Read(inList, i + 3 * nbNod + nbNod * nbComp * j + nbComp * k + l, &d[l]); List_Read(inList, i + 3 * nbNod + nbNod * nbComp * j + nbComp * k + l, &d[l]);
for(int l = nbComp; l < 9; l++) for(int l = nbComp; l < 9; l++)
d[l] = 0.; d[l] = 0.;
for(int l = 0; l < outNbComp; l++){
#if defined(HAVE_MATH_EVAL) #if defined(HAVE_MATH_EVAL)
char *names[] = { "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8" }; char *names[] = { "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8" };
double values[] = { d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8] }; double values[] = { d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8] };
res = evaluator_evaluate(f, sizeof(names)/sizeof(names[0]), names, values); res = evaluator_evaluate(f[l], sizeof(names)/sizeof(names[0]), names, values);
#else #else
res = d[comp]; res = d[comp[l]];
#endif #endif
List_Add(outList, &res); List_Add(outList, &res);
}
} }
} }
(*outNb)++; (*outNb)++;
} }
#if defined(HAVE_MATH_EVAL) #if defined(HAVE_MATH_EVAL)
evaluator_destroy(f); for(int i = 0; i < outNbComp; i++)
evaluator_destroy(f[i]);
#endif #endif
} }
Post_View *GMSH_ExtractPlugin::execute(Post_View * v) Post_View *GMSH_ExtractPlugin::execute(Post_View * v)
{ {
int iView = (int)ExtractOptions_Number[0].def; int iView = (int)ExtractOptions_Number[0].def;
char *expr = ExtractOptions_String[0].def; char *expr[3] = { ExtractOptions_String[0].def,
ExtractOptions_String[1].def,
ExtractOptions_String[2].def };
Post_View *vv; Post_View *vv;
if(v && iView < 0) if(v && iView < 0)
...@@ -183,39 +213,40 @@ Post_View *GMSH_ExtractPlugin::execute(Post_View * v) ...@@ -183,39 +213,40 @@ Post_View *GMSH_ExtractPlugin::execute(Post_View * v)
// FIXME: this is not secure: if BeginView forces a post.list // FIXME: this is not secure: if BeginView forces a post.list
// reallocation, vv is wrong // reallocation, vv is wrong
Post_View *view = BeginView(1); Post_View *view = BeginView(1);
Post_View *z = view;
// points // points
extract(expr, vv->SP, vv->NbSP, view->SP, &view->NbSP, vv->NbTimeStep, 1, 1); extract(expr, vv->SP, vv->NbSP, z->SP, &z->NbSP, z->VP, &z->NbVP, vv->NbTimeStep, 1, 1);
extract(expr, vv->VP, vv->NbVP, view->SP, &view->NbSP, vv->NbTimeStep, 1, 3); extract(expr, vv->VP, vv->NbVP, z->SP, &z->NbSP, z->VP, &z->NbVP, vv->NbTimeStep, 1, 3);
extract(expr, vv->TP, vv->NbTP, view->SP, &view->NbSP, vv->NbTimeStep, 1, 9); extract(expr, vv->TP, vv->NbTP, z->SP, &z->NbSP, z->VP, &z->NbVP, vv->NbTimeStep, 1, 9);
// lines // lines
extract(expr, vv->SL, vv->NbSL, view->SL, &view->NbSL, vv->NbTimeStep, 2, 1); extract(expr, vv->SL, vv->NbSL, z->SL, &z->NbSL, z->VL, &z->NbVL, vv->NbTimeStep, 2, 1);
extract(expr, vv->VL, vv->NbVL, view->SL, &view->NbSL, vv->NbTimeStep, 2, 3); extract(expr, vv->VL, vv->NbVL, z->SL, &z->NbSL, z->VL, &z->NbVL, vv->NbTimeStep, 2, 3);
extract(expr, vv->TL, vv->NbTL, view->SL, &view->NbSL, vv->NbTimeStep, 2, 9); extract(expr, vv->TL, vv->NbTL, z->SL, &z->NbSL, z->VL, &z->NbVL, vv->NbTimeStep, 2, 9);
// triangles // triangles
extract(expr, vv->ST, vv->NbST, view->ST, &view->NbST, vv->NbTimeStep, 3, 1); extract(expr, vv->ST, vv->NbST, z->ST, &z->NbST, z->VT, &z->NbVT, vv->NbTimeStep, 3, 1);
extract(expr, vv->VT, vv->NbVT, view->ST, &view->NbST, vv->NbTimeStep, 3, 3); extract(expr, vv->VT, vv->NbVT, z->ST, &z->NbST, z->VT, &z->NbVT, vv->NbTimeStep, 3, 3);
extract(expr, vv->TT, vv->NbTT, view->ST, &view->NbST, vv->NbTimeStep, 3, 9); extract(expr, vv->TT, vv->NbTT, z->ST, &z->NbST, z->VT, &z->NbVT, vv->NbTimeStep, 3, 9);
// quadrangles // quadrangles
extract(expr, vv->SQ, vv->NbSQ, view->SQ, &view->NbSQ, vv->NbTimeStep, 4, 1); extract(expr, vv->SQ, vv->NbSQ, z->SQ, &z->NbSQ, z->VQ, &z->NbVQ, vv->NbTimeStep, 4, 1);
extract(expr, vv->VQ, vv->NbVQ, view->SQ, &view->NbSQ, vv->NbTimeStep, 4, 3); extract(expr, vv->VQ, vv->NbVQ, z->SQ, &z->NbSQ, z->VQ, &z->NbVQ, vv->NbTimeStep, 4, 3);
extract(expr, vv->TQ, vv->NbTQ, view->SQ, &view->NbSQ, vv->NbTimeStep, 4, 9); extract(expr, vv->TQ, vv->NbTQ, z->SQ, &z->NbSQ, z->VQ, &z->NbVQ, vv->NbTimeStep, 4, 9);
// tets // tets
extract(expr, vv->SS, vv->NbSS, view->SS, &view->NbSS, vv->NbTimeStep, 4, 1); extract(expr, vv->SS, vv->NbSS, z->SS, &z->NbSS, z->VS, &z->NbVS, vv->NbTimeStep, 4, 1);
extract(expr, vv->VS, vv->NbVS, view->SS, &view->NbSS, vv->NbTimeStep, 4, 3); extract(expr, vv->VS, vv->NbVS, z->SS, &z->NbSS, z->VS, &z->NbVS, vv->NbTimeStep, 4, 3);
extract(expr, vv->TS, vv->NbTS, view->SS, &view->NbSS, vv->NbTimeStep, 4, 9); extract(expr, vv->TS, vv->NbTS, z->SS, &z->NbSS, z->VS, &z->NbVS, vv->NbTimeStep, 4, 9);
// hexas // hexas
extract(expr, vv->SH, vv->NbSH, view->SH, &view->NbSH, vv->NbTimeStep, 8, 1); extract(expr, vv->SH, vv->NbSH, z->SH, &z->NbSH, z->VH, &z->NbVH, vv->NbTimeStep, 8, 1);
extract(expr, vv->VH, vv->NbVH, view->SH, &view->NbSH, vv->NbTimeStep, 8, 3); extract(expr, vv->VH, vv->NbVH, z->SH, &z->NbSH, z->VH, &z->NbVH, vv->NbTimeStep, 8, 3);
extract(expr, vv->TH, vv->NbTH, view->SH, &view->NbSH, vv->NbTimeStep, 8, 9); extract(expr, vv->TH, vv->NbTH, z->SH, &z->NbSH, z->VH, &z->NbVH, vv->NbTimeStep, 8, 9);
// prisms // prisms
extract(expr, vv->SI, vv->NbSI, view->SI, &view->NbSI, vv->NbTimeStep, 6, 1); extract(expr, vv->SI, vv->NbSI, z->SI, &z->NbSI, z->VI, &z->NbVI, vv->NbTimeStep, 6, 1);
extract(expr, vv->VI, vv->NbVI, view->SI, &view->NbSI, vv->NbTimeStep, 6, 3); extract(expr, vv->VI, vv->NbVI, z->SI, &z->NbSI, z->VI, &z->NbVI, vv->NbTimeStep, 6, 3);
extract(expr, vv->TI, vv->NbTI, view->SI, &view->NbSI, vv->NbTimeStep, 6, 9); extract(expr, vv->TI, vv->NbTI, z->SI, &z->NbSI, z->VI, &z->NbVI, vv->NbTimeStep, 6, 9);
// pyramids // pyramids
extract(expr, vv->SY, vv->NbSY, view->SY, &view->NbSY, vv->NbTimeStep, 5, 1); extract(expr, vv->SY, vv->NbSY, z->SY, &z->NbSY, z->VY, &z->NbVY, vv->NbTimeStep, 5, 1);
extract(expr, vv->VY, vv->NbVY, view->SY, &view->NbSY, vv->NbTimeStep, 5, 3); extract(expr, vv->VY, vv->NbVY, z->SY, &z->NbSY, z->VY, &z->NbVY, vv->NbTimeStep, 5, 3);
extract(expr, vv->TY, vv->NbTY, view->SY, &view->NbSY, vv->NbTimeStep, 5, 9); extract(expr, vv->TY, vv->NbTY, z->SY, &z->NbSY, z->VY, &z->NbVY, vv->NbTimeStep, 5, 9);
if(view->empty()) { if(view->empty()) {
RemoveViewByNumber(view->Num); RemoveViewByNumber(view->Num);
......
...@@ -148,14 +148,16 @@ Default value: @code{-1} ...@@ -148,14 +148,16 @@ Default value: @code{-1}
@end table @end table
@item Plugin(Evaluate) @item Plugin(Evaluate)
Plugin(Evaluate) sets the values associated with Plugin(Evaluate) sets the values associated
the `TimeStep'-th time step in the view `iView' with the `TimeStep'-th time step in the scalar
to the expression `Expression'. In addition to view `iView' to the expression `Expression'. In
the usual mathematical functions, `Expression' addition to the usual mathematical functions
can contain the symbols x, y, z and v, which (Exp, Log, Sqrt, Sin, Cos, Fabs, etc.) and
operators (+, -, *, /, ^), `Expression' can
contain the symbols x, y, z and v, which
represent the three spatial coordinates and the represent the three spatial coordinates and the
value of the field, respectively. If `iView' < 0, the value of the field, respectively. If `iView' < 0,
plugin is run on the current view. the plugin is run on the current view.
Plugin(Evaluate) is executed in-place. Plugin(Evaluate) is executed in-place.
...@@ -174,19 +176,28 @@ Default value: @code{-1} ...@@ -174,19 +176,28 @@ Default value: @code{-1}
@item Plugin(Extract) @item Plugin(Extract)
Plugin(Extract) extracts a combination of Plugin(Extract) extracts a combination of
components from the view `iView', as specified components from the view `iView'. If
by `Expression'. In addition to the usual `Expression1' or `Expression2' is empty, the
mathematical functions, `Expression' can contain plugin creates a scalar view using
the symbols v0, v1, v2, ..., vn, which represent `Expression0'; otherwise the plugin creates
the n components of the field. If `iView' < 0, the a vector view. In addition to the usual
mathematical functions (Exp, Log, Sqrt, Sin,
Cos, Fabs, etc.) and operators (+, -, *, /, ^),
the expressions can contain the symbols v0,
v1, v2, ..., vn, which represent the n
components of the field. If `iView' < 0, the
plugin is run on the current view. plugin is run on the current view.
Plugin(Extract) creates one new view. Plugin(Extract) creates one new view.
String options: String options:
@table @code @table @code
@item Expression @item Expression0
Default value: @code{"v0"} Default value: @code{"v0"}
@item Expression1
Default value: @code{""}
@item Expression2
Default value: @code{""}
@end table @end table
Numeric options: Numeric options:
@table @code @table @code
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment