Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/post/src/modules/matctcl.c
3203 views
1
#/*****************************************************************************
2
# *
3
# * Elmer, A Finite Element Software for Multiphysical Problems
4
# *
5
# * Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland
6
# *
7
# * This program is free software; you can redistribute it and/or
8
# * modify it under the terms of the GNU General Public License
9
# * as published by the Free Software Foundation; either version 2
10
# * of the License, or (at your option) any later version.
11
# *
12
# * This program is distributed in the hope that it will be useful,
13
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# * GNU General Public License for more details.
16
# *
17
# * You should have received a copy of the GNU General Public License
18
# * along with this program (in file fem/GPL-2); if not, write to the
19
# * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
# * Boston, MA 02110-1301, USA.
21
# *
22
# *****************************************************************************/
23
24
/*******************************************************************************
25
*
26
* Elmerpost / MATC utilities.
27
*
28
*******************************************************************************
29
*
30
* Author: Juha Ruokolainen
31
*
32
* Address: CSC - IT Center for Science Ltd.
33
* Keilaranta 14, P.O. BOX 405
34
* 02101 Espoo, Finland
35
* Tel. +358 0 457 2723
36
* Telefax: +358 0 457 2302
37
* EMail: [email protected]
38
*
39
* Date: 6 Jun 1996
40
*
41
* Modified by:
42
*
43
* Date of modification:
44
*
45
******************************************************************************/
46
47
48
49
/*
50
* $Id: matctcl.c,v 1.3 1999/06/03 14:12:40 jpr Exp $
51
*
52
* $Log: matctcl.c,v $
53
* Revision 1.3 1999/06/03 14:12:40 jpr
54
* *** empty log message ***
55
*
56
* Revision 1.2 1998/08/01 12:34:59 jpr
57
*
58
* Added Id, started Log.
59
*
60
*
61
*/
62
63
#include "../elmerpost.h"
64
#include <tcl.h>
65
#include <tk.h>
66
67
extern Tcl_Interp *TCLInterp;
68
69
static VARIABLE *matc_tcl( VARIABLE *ptr )
70
{
71
VARIABLE *res = NULL;
72
char *command;
73
74
int i,n;
75
76
command = var_to_string(ptr);
77
78
Tcl_GlobalEval( TCLInterp, command );
79
80
FREEMEM( command );
81
82
if ( TCLInterp->result && (n=strlen(TCLInterp->result))>0 )
83
{
84
res = var_temp_new( TYPE_STRING,1,n );
85
for( i=0; i<n; i++ ) M( res,0,i ) = TCLInterp->result[i];
86
}
87
88
return res;
89
}
90
91
static VARIABLE *matc_element( VARIABLE *ptr )
92
{
93
double *num = MATR(ptr);
94
char *str = NULL;
95
96
int i,j,n,maxn=0;
97
98
VARIABLE *res = NULL;
99
100
element_t *elem = CurrentObject->ElementModel->Elements;
101
102
if ( NEXT(ptr) ) str = var_to_string( NEXT(ptr) );
103
104
if ( CurrentObject->ElementModel->NofElements <= 0 ) error( "element: no elements present.\n" );
105
106
for( i=0; i<NCOL(ptr); i++ )
107
{
108
n = num[i];
109
if ( n < 0 || n >= CurrentObject->ElementModel->NofElements )
110
{
111
error( "element: Envalid element index: [%d].\n",n );
112
}
113
114
maxn = MAX( maxn,elem[n].ElementType->NumberOfNodes );
115
}
116
117
res = var_temp_new( TYPE_DOUBLE, NCOL(ptr), maxn );
118
119
for( i=0; i<NCOL(ptr); i++ )
120
{
121
n = num[i];
122
for( j=0; j<elem[n].ElementType->NumberOfNodes; j++ )
123
{
124
M(res,i,j) = elem[n].Topology[j];
125
}
126
}
127
128
if ( str ) FREEMEM( str );
129
130
return res;
131
}
132
133
int Matctcl_Init()
134
{
135
extern VARIABLE *elm_gradient(), *elm_divergence(),*elm_rotor_3D(),*elm_rotor_2D();
136
137
#if 1
138
com_init(
139
"grad", FALSE, FALSE, elm_gradient, 1, 1,
140
"r = grad(f): compute gradient of a scalar variable f.\n"
141
);
142
143
com_init(
144
"div", FALSE, FALSE, elm_divergence, 1, 1,
145
"r = div(v): compute divergence of a vector variable v.\n"
146
);
147
148
com_init(
149
"curl3d", FALSE, FALSE, elm_rotor_3D, 1, 1,
150
"r = curl3d(v): compute curl of a vector variable v (in 3D).\n"
151
);
152
com_init(
153
"curl2d", FALSE, FALSE, elm_rotor_2D, 1, 1,
154
"r = curl2d(v): compute curl of a vector variable v (in 2D).\n"
155
);
156
#endif
157
158
com_init(
159
"tcl", FALSE, FALSE, matc_tcl, 1, 1,
160
"str = tcl(str): execute a command in tcl part of ElmerPost.\n"
161
);
162
163
com_init(
164
"element", FALSE, FALSE, matc_element, 1, 2,
165
"r = element(v): return element topology for elements given in vector v.\n"
166
);
167
168
return TCL_OK;
169
}
170
171