1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
|
% mesh.mw
% MWrap bindings for Mesh.
%
% Copyright (c) 2007 David Bindel
% See the file COPYING for copying permissions
$ #include "mesh.h"
// ----
@function mobj = Mesh_create(ndm, maxndf, maxnen)
% mobj = Mesh_create(ndm, maxndf, maxnen)
%
% Create a new mesh object.
% ndm - Number of spatial dimensions
% maxndf - Maximum number of dofs per node
% maxnen - Maximum number of elements per node
# Mesh* mobj = new Mesh(int ndm, int maxndf, int maxnen);
// ----
@function Mesh_delete(mobj)
% Mesh_delete(mobj)
%
% Delete an existing mesh object.
# delete(Mesh* mobj);
// ----
@function ndm = Mesh_ndm(mobj)
% ndm = Mesh_ndm(mobj)
%
% Get the number of spatial dimensions for the mesh
# int ndm = mobj->Mesh.ndm();
// ----
@function maxndf = Mesh_maxndf(mobj)
% maxndf = Mesh_maxndf(mobj)
%
% Get the maximum number of nodal dofs for the mesh
# int maxndf = mobj->Mesh.maxndf();
// ----
@function maxnen = Mesh_maxnen(mobj)
% maxnen = Mesh_maxnen(mobj)
%
% Get the maximum number of nodes per element for the mesh
# int maxnen = mobj->Mesh.maxnen();
// ----
@function numelt = Mesh_numelt(mobj)
% numelt = Mesh_numelt(mobj)
%
% Get the number of elements in the mesh.
# int numelt = mobj->Mesh.numelt();
// ----
@function numnp = Mesh_numnp(mobj)
% numnp = Mesh_numnp(mobj)
%
% Get the number of nodes in the mesh
# int numnp = mobj->Mesh.numnp();
// ----
@function numid = Mesh_numid(mobj)
% numid = Mesh_numid(mobj)
%
% Get the number of active dofs in the mesh
# int numid = mobj->Mesh.numid();
// ----
@function x = Mesh_x(mobj, i)
% Mesh_x(mobj, i)
%
% Get the coordinates of mesh node i. If the node number is omitted,
% get the coordinates for all nodes in the mesh.
if nargin == 2
i = i-1;
# int ndm = mobj->Mesh.ndm();
# double[ndm] x = mobj->Mesh.x(int i);
else
# int numnp = mobj->Mesh.numnp();
# int ndm = mobj->Mesh.ndm();
# double[ndm,numnp] x = mobj->Mesh.x();
end
// ----
@function ix = Mesh_ix(mobj, i)
% Mesh_ix(mobj, i)
%
% Get the connectivity of element i. If the element number is omitted,
% get the connectivity for all elements in the mesh.
if nargin == 2
i = i-1;
# int maxnen = mobj->Mesh.maxndf();
# int[maxnen] ix = mobj->Mesh.ix(int i);
else
# int numelt = mobj->Mesh.numelt();
# int maxnen = mobj->Mesh.maxnen();
# int[maxnen,numelt] ix = mobj->Mesh.ix();
end
ix = ix+1;
// ----
@function id = Mesh_id(mobj, i)
% Mesh_id(mobj, i)
%
% Get the degrees of freedom for element i. If the element number is omitted,
% get the degrees of freedom for all elements in the mesh.
if nargin == 2
i = i - 1;
# int maxndf = mobj->Mesh.maxndf();
# int[maxndf] id = mobj->Mesh.id(int i);
else
# int numnp = mobj->Mesh.numnp();
# int maxndf = mobj->Mesh.maxndf();
# int[maxndf,numnp] id = mobj->Mesh.id();
end
id = id + 1;
// ----
@function u = Mesh_u(mobj, i)
% Mesh_u(mobj, i)
%
% Get the displacement of mesh node i. If the node number is omitted,
% get the displacements for all nodes in the mesh.
if nargin == 2
i = i-1;
# int maxndf = mobj->Mesh.maxndf();
# double[maxndf] u = mobj->Mesh.u(int i);
else
# int numnp = mobj->Mesh.numnp();
# int maxndf = mobj->Mesh.maxndf();
# double[maxndf,numnp] u = mobj->Mesh.u();
end
// ----
@function f = Mesh_f(mobj, i)
% Mesh_f(mobj, i)
%
% Get the forces for mesh node i. If the node number is omitted,
% get the forces for all nodes in the mesh.
if nargin == 2
i = i-1;
# int maxndf = mobj->Mesh.maxndf();
# double[maxndf] f = mobj->Mesh.f(int i);
else
# int numnp = mobj->Mesh.numnp();
# int maxndf = mobj->Mesh.maxndf();
# double[maxndf,numnp] f = mobj->Mesh.f();
end
// ----
@function bc = Mesh_bc(mobj, i)
% Mesh_bc(mobj, i)
%
% Get the boundary codes of mesh node i. If the node number is omitted,
% get the boundary codes for all nodes in the mesh.
if nargin == 2
i = i-1;
# int maxndf = mobj->Mesh.maxndf();
# char[maxndf] bc = mobj->Mesh.bc(int i);
else
# int numnp = mobj->Mesh.numnp();
# int maxndf = mobj->Mesh.maxndf();
# char[maxndf,numnp] bc = mobj->Mesh.bc();
end
// ----
@function bv = Mesh_bv(mobj, i)
% Mesh_bv(mobj, i)
%
% Get the boundary values of mesh node i. If the node number is omitted,
% get the boundary values for all nodes in the mesh.
if nargin == 2
i = i-1;
# int maxndf = mobj->Mesh.maxndf();
# double[maxndf] bv = mobj->Mesh.bv(int i);
else
# int numnp = mobj->Mesh.numnp();
# int maxndf = mobj->Mesh.maxndf();
# double[maxndf,numnp] bv = mobj->Mesh.bv();
end
// ----
@function Mesh_set_ur(mobj, ur)
% Mesh_set_ur(mobj, ur)
%
% Set reduced displacement vector
numid = Mesh_numid(mobj);
# mobj->Mesh.set_ur(input double[numid] ur);
// ----
@function ur = Mesh_get_ur(mobj)
% ur = Mesh_get_ur(mobj)
%
% Get reduced displacement vector
numid = Mesh_numid(mobj);
# mobj->Mesh.get_ur(output double[numid] ur);
// ----
@function Mesh_set_bc(mobj, bc, i, j)
% Mesh_set_bc(mobj, bc, i, j)
%
% Set the boundary codes of mesh node i. If the node number is omitted,
% set the boundary codes for all nodes in the mesh.
$[
void set_bc(Mesh* mesh, char bc, int i, int j)
{
mesh->bc(i,j) = bc;
}
void set_bc(Mesh* mesh, char* bc)
{
int numnp = mesh->numnp();
int maxndf = mesh->maxndf();
for (int j = 0; j < numnp; ++j)
for (int i = 0; i < maxndf; ++i)
mesh->bc(i,j) = bc[i+j*maxndf];
}
$]
if nargin == 4
i = i-1;
j = j-1;
# int maxndf = mobj->Mesh.maxndf();
# set_bc(Mesh* mobj, char bc, int i, int j);
else
# int numnp = mobj->Mesh.numnp();
# int maxndf = mobj->Mesh.maxndf();
# set_bc(Mesh* mobj, char[maxndf,numnp] bc);
end
// ----
@function Mesh_set_bv(mobj, bv, i, j)
% Mesh_set_bv(mobj, bv, i, j)
%
% Set the boundary codes of mesh node i. If the node number is omitted,
% set the boundary codes for all nodes in the mesh.
$[
void set_bv(Mesh* mesh, double bv, int i, int j)
{
mesh->bv(i,j) = bv;
}
void set_bv(Mesh* mesh, double* bv)
{
int numnp = mesh->numnp();
int maxndf = mesh->maxndf();
for (int j = 0; j < numnp; ++j)
for (int i = 0; i < maxndf; ++i)
mesh->bv(i,j) = bv[i+j*maxndf];
}
$]
if nargin == 4
i = i-1;
j = j-1;
# int maxndf = mobj->Mesh.maxndf();
# set_bv(Mesh* mobj, double bv, int i, int j);
else
# int numnp = mobj->Mesh.numnp();
# int maxndf = mobj->Mesh.maxndf();
# set_bv(Mesh* mobj, double[maxndf,numnp] bv);
end
// ----
@function numid = Mesh_initialize(mobj)
% numid = Mesh_initialize(mobj)
%
% Initialize the mesh object after completion of X/IX arrays.
# int numid = mobj->Mesh.initialize();
// ----
@function numid = Mesh_assign_ids(mobj)
% numid = Mesh_assign_ids(mobj)
%
% Assign identifiers to active degrees of freedom in the mesh.
# int numid = mobj->Mesh.assign_ids();
// ----
@function F = Mesh_assemble_F(mobj)
% F = Mesh_assemble_F(mobj)
%
% Assemble system residual force vector.
numid = Mesh_numid(mobj);
# mobj->Mesh.assemble_F();
# mobj->Mesh.get_fr(output double[numid] F);
// ----
@function K = Mesh_assemble_K(mobj)
% K = Mesh_assemble_K(mobj)
%
% Assemble system stiffness matrix.
numid = Mesh_numid(mobj);
Ka = Assembler_create(numid, numid);
# mobj->Mesh.assemble_K(MatrixAssembler* Ka);
K = Assembler_get(Ka);
Assembler_delete(Ka);
// ----
@function id = Mesh_add_node(mobj, x)
% id = Mesh_add_node(mobj, x)
%
% Build a new node at position x and return the index.
# int ndm = mobj->Mesh.ndm();
# int id = mobj->Mesh.add_node(double[ndm] x);
id = id + 1;
// ----
@function id = Mesh_add_element(mobj, etype, nodes)
% id = Mesh_add_element(mobj, etype, nodes)
%
% Build a new element of type etype connected to the indicated nodes,
% and return the index.
numnp = length(nodes);
nodes = nodes-1;
# int id = mobj->Mesh.add_element(EType* etype, int[numnp] nodes, int numnp);
id = id + 1;
// ----
@function Mesh_load(mobj, etype, x, ix)
% Mesh_load(mobj, material, x, ix)
%
% Add a new batch of elements
% material - Material type
% x - Coordinates of nodes in new elements
% ix - Connectivity array for new elements
# int ndm = mobj->Mesh.ndm();
ids = zeros(1,size(x,2));
for j = 1:size(x,2)
xj = x(:,j);
# int id = mobj->Mesh.add_node(double[ndm] xj);
ids(j) = id;
end
numnp = size(ix,1);
for j = 1:size(ix,2)
ixj = ids(ix(:,j));
# int id = mobj->Mesh.add_element(EType* etype, int[numnp] ixj, int numnp);
end
|