diff --git a/Plugin/Evaluate.cpp b/Plugin/Evaluate.cpp index 45c793c010cf2770d76562fbf36dcf21677699e4..8f31759fb0e4271a08f215f47d7df6279f66a7e0 100644 --- a/Plugin/Evaluate.cpp +++ b/Plugin/Evaluate.cpp @@ -1,4 +1,4 @@ -// $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 // @@ -67,8 +67,8 @@ void GMSH_EvaluatePlugin::getInfos(char *author, char *copyright, strcpy(copyright, "DGR (www.multiphysics.com)"); strcpy(help_text, "Plugin(Evaluate) sets the values associated\n" - "with the `TimeStep'-th time step in the view\n" - "`iView' to the expression `Expression'. In\n" + "with the `TimeStep'-th time step in the scalar\n" + "view `iView' to the expression `Expression'. In\n" "addition to the usual mathematical functions\n" "(Exp, Log, Sqrt, Sin, Cos, Fabs, etc.) and\n" "operators (+, -, *, /, ^), `Expression' can\n" diff --git a/Plugin/Extract.cpp b/Plugin/Extract.cpp index 7808e801c977c10ea2884daf6b2440769d9dc69a..44469f91a5059f62333d9ee58eab05e4815549c2 100644 --- a/Plugin/Extract.cpp +++ b/Plugin/Extract.cpp @@ -1,4 +1,4 @@ -// $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 // @@ -37,7 +37,9 @@ StringXNumber ExtractOptions_Number[] = { }; StringXString ExtractOptions_String[] = { - {GMSH_FULLRC, "Expression", NULL, "v0"} + {GMSH_FULLRC, "Expression0", NULL, "v0"}, + {GMSH_FULLRC, "Expression1", NULL, ""}, + {GMSH_FULLRC, "Expression2", NULL, ""} }; extern "C" @@ -64,14 +66,17 @@ void GMSH_ExtractPlugin::getInfos(char *author, char *copyright, char *help_text strcpy(copyright, "DGR (www.multiphysics.com)"); strcpy(help_text, "Plugin(Extract) extracts a combination of\n" - "components from the view `iView', as specified\n" - "by `Expression'. In addition to the usual\n" + "components from the view `iView'. If\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" "Cos, Fabs, etc.) and operators (+, -, *, /, ^),\n" - "`Expression' can contain the symbols v0, v1,\n" - "v2, ..., vn, which represent the n components\n" - "of the field. If `iView' < 0, the plugin is\n" - "run on the current view.\n" + "the expressions can contain the symbols v0,\n" + "v1, v2, ..., vn, which represent the n\n" + "components of the field. If `iView' < 0, the\n" + "plugin is run on the current view.\n" "\n" "Plugin(Extract) creates one new view.\n"); } @@ -101,36 +106,56 @@ void GMSH_ExtractPlugin::catchErrorMessage(char *errorMessage) const strcpy(errorMessage, "Extract failed..."); } -static void extract(char *expr, List_T *inList, int inNb, - List_T *outList, int *outNb, +static void extract(char *expr[3], List_T *inList, int inNb, + List_T *outListScalar, int *outNbScalar, + List_T *outListVector, int *outNbVector, int nbTime, int nbNod, int nbComp) { if(!inNb) 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; // otherwise, we only allow to extract single components #if defined(HAVE_MATH_EVAL) - void *f = evaluator_create(expr); - if(!f){ - Msg(GERROR, "Invalid expression '%s'", expr); - return; + void *f[3]; + for(int i = 0; i < outNbComp; i++){ + f[i] = evaluator_create(expr[i]); + if(!f[i]){ + Msg(GERROR, "Invalid expression '%s'", expr[i]); + return; + } } #else - int comp; - if (!strcmp(expr, "v0")) comp = 0; - else if(!strcmp(expr, "v1")) comp = 1; - else if(!strcmp(expr, "v2")) comp = 2; - else if(!strcmp(expr, "v3")) comp = 3; - else if(!strcmp(expr, "v4")) comp = 4; - else if(!strcmp(expr, "v5")) comp = 5; - else if(!strcmp(expr, "v6")) comp = 6; - else if(!strcmp(expr, "v7")) comp = 7; - else if(!strcmp(expr, "v8")) comp = 8; - else{ - Msg(GERROR, "Invalid expression '%s'", expr); - return; + int comp[3]; + for(int i = 0; i < outNbComp; i++){ + if (!strcmp(expr[i], "v0")) comp[i] = 0; + else if(!strcmp(expr[i], "v1")) comp[i] = 1; + else if(!strcmp(expr[i], "v2")) comp[i] = 2; + else if(!strcmp(expr[i], "v3")) comp[i] = 3; + else if(!strcmp(expr[i], "v4")) comp[i] = 4; + else if(!strcmp(expr[i], "v5")) comp[i] = 5; + else if(!strcmp(expr[i], "v6")) comp[i] = 6; + else if(!strcmp(expr[i], "v7")) comp[i] = 7; + else if(!strcmp(expr[i], "v8")) comp[i] = 8; + else{ + Msg(GERROR, "Invalid expression '%s'", expr[i]); + return; + } } #endif @@ -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]); for(int l = nbComp; l < 9; l++) d[l] = 0.; + for(int l = 0; l < outNbComp; l++){ #if defined(HAVE_MATH_EVAL) - 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] }; - res = evaluator_evaluate(f, sizeof(names)/sizeof(names[0]), names, values); + 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] }; + res = evaluator_evaluate(f[l], sizeof(names)/sizeof(names[0]), names, values); #else - res = d[comp]; + res = d[comp[l]]; #endif - List_Add(outList, &res); + List_Add(outList, &res); + } } } (*outNb)++; } #if defined(HAVE_MATH_EVAL) - evaluator_destroy(f); + for(int i = 0; i < outNbComp; i++) + evaluator_destroy(f[i]); #endif } Post_View *GMSH_ExtractPlugin::execute(Post_View * v) { 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; if(v && iView < 0) @@ -183,39 +213,40 @@ Post_View *GMSH_ExtractPlugin::execute(Post_View * v) // FIXME: this is not secure: if BeginView forces a post.list // reallocation, vv is wrong Post_View *view = BeginView(1); + Post_View *z = view; // points - extract(expr, vv->SP, vv->NbSP, view->SP, &view->NbSP, vv->NbTimeStep, 1, 1); - extract(expr, vv->VP, vv->NbVP, view->SP, &view->NbSP, vv->NbTimeStep, 1, 3); - extract(expr, vv->TP, vv->NbTP, view->SP, &view->NbSP, vv->NbTimeStep, 1, 9); - // lines - extract(expr, vv->SL, vv->NbSL, view->SL, &view->NbSL, vv->NbTimeStep, 2, 1); - extract(expr, vv->VL, vv->NbVL, view->SL, &view->NbSL, vv->NbTimeStep, 2, 3); - extract(expr, vv->TL, vv->NbTL, view->SL, &view->NbSL, vv->NbTimeStep, 2, 9); - // triangles - extract(expr, vv->ST, vv->NbST, view->ST, &view->NbST, vv->NbTimeStep, 3, 1); - extract(expr, vv->VT, vv->NbVT, view->ST, &view->NbST, vv->NbTimeStep, 3, 3); - extract(expr, vv->TT, vv->NbTT, view->ST, &view->NbST, vv->NbTimeStep, 3, 9); - // quadrangles - extract(expr, vv->SQ, vv->NbSQ, view->SQ, &view->NbSQ, vv->NbTimeStep, 4, 1); - extract(expr, vv->VQ, vv->NbVQ, view->SQ, &view->NbSQ, vv->NbTimeStep, 4, 3); - extract(expr, vv->TQ, vv->NbTQ, view->SQ, &view->NbSQ, vv->NbTimeStep, 4, 9); - // tets - extract(expr, vv->SS, vv->NbSS, view->SS, &view->NbSS, vv->NbTimeStep, 4, 1); - extract(expr, vv->VS, vv->NbVS, view->SS, &view->NbSS, vv->NbTimeStep, 4, 3); - extract(expr, vv->TS, vv->NbTS, view->SS, &view->NbSS, vv->NbTimeStep, 4, 9); - // hexas - extract(expr, vv->SH, vv->NbSH, view->SH, &view->NbSH, vv->NbTimeStep, 8, 1); - extract(expr, vv->VH, vv->NbVH, view->SH, &view->NbSH, vv->NbTimeStep, 8, 3); - extract(expr, vv->TH, vv->NbTH, view->SH, &view->NbSH, vv->NbTimeStep, 8, 9); - // prisms - extract(expr, vv->SI, vv->NbSI, view->SI, &view->NbSI, vv->NbTimeStep, 6, 1); - extract(expr, vv->VI, vv->NbVI, view->SI, &view->NbSI, vv->NbTimeStep, 6, 3); - extract(expr, vv->TI, vv->NbTI, view->SI, &view->NbSI, vv->NbTimeStep, 6, 9); - // pyramids - extract(expr, vv->SY, vv->NbSY, view->SY, &view->NbSY, vv->NbTimeStep, 5, 1); - extract(expr, vv->VY, vv->NbVY, view->SY, &view->NbSY, vv->NbTimeStep, 5, 3); - extract(expr, vv->TY, vv->NbTY, view->SY, &view->NbSY, vv->NbTimeStep, 5, 9); + extract(expr, vv->SP, vv->NbSP, z->SP, &z->NbSP, z->VP, &z->NbVP, vv->NbTimeStep, 1, 1); + extract(expr, vv->VP, vv->NbVP, z->SP, &z->NbSP, z->VP, &z->NbVP, vv->NbTimeStep, 1, 3); + extract(expr, vv->TP, vv->NbTP, z->SP, &z->NbSP, z->VP, &z->NbVP, vv->NbTimeStep, 1, 9); + // lines + extract(expr, vv->SL, vv->NbSL, z->SL, &z->NbSL, z->VL, &z->NbVL, vv->NbTimeStep, 2, 1); + extract(expr, vv->VL, vv->NbVL, z->SL, &z->NbSL, z->VL, &z->NbVL, vv->NbTimeStep, 2, 3); + extract(expr, vv->TL, vv->NbTL, z->SL, &z->NbSL, z->VL, &z->NbVL, vv->NbTimeStep, 2, 9); + // triangles + extract(expr, vv->ST, vv->NbST, z->ST, &z->NbST, z->VT, &z->NbVT, vv->NbTimeStep, 3, 1); + extract(expr, vv->VT, vv->NbVT, z->ST, &z->NbST, z->VT, &z->NbVT, vv->NbTimeStep, 3, 3); + extract(expr, vv->TT, vv->NbTT, z->ST, &z->NbST, z->VT, &z->NbVT, vv->NbTimeStep, 3, 9); + // quadrangles + extract(expr, vv->SQ, vv->NbSQ, z->SQ, &z->NbSQ, z->VQ, &z->NbVQ, vv->NbTimeStep, 4, 1); + extract(expr, vv->VQ, vv->NbVQ, z->SQ, &z->NbSQ, z->VQ, &z->NbVQ, vv->NbTimeStep, 4, 3); + extract(expr, vv->TQ, vv->NbTQ, z->SQ, &z->NbSQ, z->VQ, &z->NbVQ, vv->NbTimeStep, 4, 9); + // tets + extract(expr, vv->SS, vv->NbSS, z->SS, &z->NbSS, z->VS, &z->NbVS, vv->NbTimeStep, 4, 1); + extract(expr, vv->VS, vv->NbVS, z->SS, &z->NbSS, z->VS, &z->NbVS, vv->NbTimeStep, 4, 3); + extract(expr, vv->TS, vv->NbTS, z->SS, &z->NbSS, z->VS, &z->NbVS, vv->NbTimeStep, 4, 9); + // hexas + extract(expr, vv->SH, vv->NbSH, z->SH, &z->NbSH, z->VH, &z->NbVH, vv->NbTimeStep, 8, 1); + extract(expr, vv->VH, vv->NbVH, z->SH, &z->NbSH, z->VH, &z->NbVH, vv->NbTimeStep, 8, 3); + extract(expr, vv->TH, vv->NbTH, z->SH, &z->NbSH, z->VH, &z->NbVH, vv->NbTimeStep, 8, 9); + // prisms + extract(expr, vv->SI, vv->NbSI, z->SI, &z->NbSI, z->VI, &z->NbVI, vv->NbTimeStep, 6, 1); + extract(expr, vv->VI, vv->NbVI, z->SI, &z->NbSI, z->VI, &z->NbVI, vv->NbTimeStep, 6, 3); + extract(expr, vv->TI, vv->NbTI, z->SI, &z->NbSI, z->VI, &z->NbVI, vv->NbTimeStep, 6, 9); + // pyramids + extract(expr, vv->SY, vv->NbSY, z->SY, &z->NbSY, z->VY, &z->NbVY, vv->NbTimeStep, 5, 1); + extract(expr, vv->VY, vv->NbVY, z->SY, &z->NbSY, z->VY, &z->NbVY, vv->NbTimeStep, 5, 3); + extract(expr, vv->TY, vv->NbTY, z->SY, &z->NbSY, z->VY, &z->NbVY, vv->NbTimeStep, 5, 9); if(view->empty()) { RemoveViewByNumber(view->Num); diff --git a/doc/texinfo/opt_plugin.texi b/doc/texinfo/opt_plugin.texi index 12d05456065db6e9a9aceea942a26e9212c2183a..6590dbb88589acf81aa44fd77611524c76d3a84f 100644 --- a/doc/texinfo/opt_plugin.texi +++ b/doc/texinfo/opt_plugin.texi @@ -148,14 +148,16 @@ Default value: @code{-1} @end table @item Plugin(Evaluate) -Plugin(Evaluate) sets the values associated with -the `TimeStep'-th time step in the view `iView' -to the expression `Expression'. In addition to -the usual mathematical functions, `Expression' -can contain the symbols x, y, z and v, which +Plugin(Evaluate) sets the values associated +with the `TimeStep'-th time step in the scalar +view `iView' to the expression `Expression'. In +addition to the usual mathematical functions +(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 -value of the field, respectively. If `iView' < 0, the -plugin is run on the current view. +value of the field, respectively. If `iView' < 0, +the plugin is run on the current view. Plugin(Evaluate) is executed in-place. @@ -174,19 +176,28 @@ Default value: @code{-1} @item Plugin(Extract) Plugin(Extract) extracts a combination of -components from the view `iView', as specified -by `Expression'. In addition to the usual -mathematical functions, `Expression' can contain -the symbols v0, v1, v2, ..., vn, which represent -the n components of the field. If `iView' < 0, the +components from the view `iView'. If +`Expression1' or `Expression2' is empty, the +plugin creates a scalar view using +`Expression0'; otherwise the plugin creates +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(Extract) creates one new view. String options: @table @code -@item Expression +@item Expression0 Default value: @code{"v0"} +@item Expression1 +Default value: @code{""} +@item Expression2 +Default value: @code{""} @end table Numeric options: @table @code