Debian Codegraph @

tools/physicalModeling/mesh2faust/vega/libraries/volumetricMesh/generateTetMeshFromCubicMesh.cpp

raw symbols SCIP
1 /*************************************************************************
2 * *
3 * Vega FEM Simulation Library Version 3.1 *
4 * *
5 * "volumetricMesh" library , Copyright (C) 2007 CMU, 2009 MIT, 2016 USC *
6 * All rights reserved. *
7 * *
8 * Code author: Jernej Barbic *
9 * http://www.jernejbarbic.com/code *
10 * *
11 * Research: Jernej Barbic, Fun Shing Sin, Daniel Schroeder, *
12 * Doug L. James, Jovan Popovic *
13 * *
14 * Funding: National Science Foundation, Link Foundation, *
15 * Singapore-MIT GAMBIT Game Lab, *
16 * Zumberge Research and Innovation Fund at USC *
17 * *
18 * This library is free software; you can redistribute it and/or *
19 * modify it under the terms of the BSD-style license that is *
20 * included with this library in the file LICENSE.txt *
21 * *
22 * This library is distributed in the hope that it will be useful, *
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file *
25 * LICENSE.TXT for more details. *
26 * *
27 *************************************************************************/
28
29 #include "generateTetMeshFromCubicMesh.h"
30
31 TetMesh * GenerateTetMeshFromCubicMesh::Generate(CubicMesh * cubicMesh, double E, double nu, double density)
32 {
33 int numVertices;
34 double * vertices;
35 int numCubicElements;
36 int numElementVertices;
37 int * cubicElements;
38
39 cubicMesh->exportMeshGeometry(&numVertices, &vertices, &numCubicElements, &numElementVertices, &cubicElements);
40
41 int numTetElements = 6 * numCubicElements;
42 int * tetElements = (int*) malloc (sizeof(int) * 4 * numTetElements);
43
44 int tetSubdivision[6][4] = {
45 { 0, 1, 3, 4 },
46 { 1, 3, 4, 5 },
47 { 3, 4, 5, 7 },
48 { 1, 2, 3, 5 },
49 { 2, 5, 6, 7 },
50 { 2, 3, 5, 7 }
51 };
52
53 for(int i=0; i<numCubicElements; i++)
54 {
55 int * cubicElement = &cubicElements[8*i];
56 for(int tet=0; tet<6; tet++)
57 {
58 int tetIndex = 6*i+tet;
59 for(int vtx=0; vtx<4; vtx++)
60 {
61 int localVertexIndex = tetSubdivision[tet][vtx];
62 tetElements[4*tetIndex+vtx] = cubicElement[localVertexIndex];
63 }
64 }
65 }
66
67 TetMesh * tetMesh = new TetMesh(numVertices, vertices, numTetElements, tetElements, E, nu, density);
68
69 free(tetElements);
70 free(cubicElements);
71 free(vertices);
72
73 return tetMesh;
74 }
75