#/*****************************************************************************1# *2# * Elmer, A Finite Element Software for Multiphysical Problems3# *4# * Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland5# *6# * This program is free software; you can redistribute it and/or7# * modify it under the terms of the GNU General Public License8# * as published by the Free Software Foundation; either version 29# * of the License, or (at your option) any later version.10# *11# * This program is distributed in the hope that it will be useful,12# * but WITHOUT ANY WARRANTY; without even the implied warranty of13# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14# * GNU General Public License for more details.15# *16# * You should have received a copy of the GNU General Public License17# * along with this program (in file fem/GPL-2); if not, write to the18# * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,19# * Boston, MA 02110-1301, USA.20# *21# *****************************************************************************/2223/*******************************************************************************24*25* Elmerpost / MATC utilities.26*27*******************************************************************************28*29* Author: Juha Ruokolainen30*31* Address: CSC - IT Center for Science Ltd.32* Keilaranta 14, P.O. BOX 40533* 02101 Espoo, Finland34* Tel. +358 0 457 272335* Telefax: +358 0 457 230236* EMail: [email protected]37*38* Date: 6 Jun 199639*40* Modified by:41*42* Date of modification:43*44******************************************************************************/45464748/*49* $Id: matctcl.c,v 1.3 1999/06/03 14:12:40 jpr Exp $50*51* $Log: matctcl.c,v $52* Revision 1.3 1999/06/03 14:12:40 jpr53* *** empty log message ***54*55* Revision 1.2 1998/08/01 12:34:59 jpr56*57* Added Id, started Log.58*59*60*/6162#include "../elmerpost.h"63#include <tcl.h>64#include <tk.h>6566extern Tcl_Interp *TCLInterp;6768static VARIABLE *matc_tcl( VARIABLE *ptr )69{70VARIABLE *res = NULL;71char *command;7273int i,n;7475command = var_to_string(ptr);7677Tcl_GlobalEval( TCLInterp, command );7879FREEMEM( command );8081if ( TCLInterp->result && (n=strlen(TCLInterp->result))>0 )82{83res = var_temp_new( TYPE_STRING,1,n );84for( i=0; i<n; i++ ) M( res,0,i ) = TCLInterp->result[i];85}8687return res;88}8990static VARIABLE *matc_element( VARIABLE *ptr )91{92double *num = MATR(ptr);93char *str = NULL;9495int i,j,n,maxn=0;9697VARIABLE *res = NULL;9899element_t *elem = CurrentObject->ElementModel->Elements;100101if ( NEXT(ptr) ) str = var_to_string( NEXT(ptr) );102103if ( CurrentObject->ElementModel->NofElements <= 0 ) error( "element: no elements present.\n" );104105for( i=0; i<NCOL(ptr); i++ )106{107n = num[i];108if ( n < 0 || n >= CurrentObject->ElementModel->NofElements )109{110error( "element: Envalid element index: [%d].\n",n );111}112113maxn = MAX( maxn,elem[n].ElementType->NumberOfNodes );114}115116res = var_temp_new( TYPE_DOUBLE, NCOL(ptr), maxn );117118for( i=0; i<NCOL(ptr); i++ )119{120n = num[i];121for( j=0; j<elem[n].ElementType->NumberOfNodes; j++ )122{123M(res,i,j) = elem[n].Topology[j];124}125}126127if ( str ) FREEMEM( str );128129return res;130}131132int Matctcl_Init()133{134extern VARIABLE *elm_gradient(), *elm_divergence(),*elm_rotor_3D(),*elm_rotor_2D();135136#if 1137com_init(138"grad", FALSE, FALSE, elm_gradient, 1, 1,139"r = grad(f): compute gradient of a scalar variable f.\n"140);141142com_init(143"div", FALSE, FALSE, elm_divergence, 1, 1,144"r = div(v): compute divergence of a vector variable v.\n"145);146147com_init(148"curl3d", FALSE, FALSE, elm_rotor_3D, 1, 1,149"r = curl3d(v): compute curl of a vector variable v (in 3D).\n"150);151com_init(152"curl2d", FALSE, FALSE, elm_rotor_2D, 1, 1,153"r = curl2d(v): compute curl of a vector variable v (in 2D).\n"154);155#endif156157com_init(158"tcl", FALSE, FALSE, matc_tcl, 1, 1,159"str = tcl(str): execute a command in tcl part of ElmerPost.\n"160);161162com_init(163"element", FALSE, FALSE, matc_element, 1, 2,164"r = element(v): return element topology for elements given in vector v.\n"165);166167return TCL_OK;168}169170171