| 1 | /************************************************************************* |
| 2 | * * |
| 3 | * Vega FEM Simulation Library Version 3.1 * |
| 4 | * * |
| 5 | * "StVK" 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 "StVKTetABCD.h" |
| 30 | |
| 31 | StVKTetABCD::StVKTetABCD(TetMesh * tetMesh) |
| 32 | { |
| 33 | int numElements = tetMesh->getNumElements(); |
| 34 | int totalCoefficientSize = (sizeof(elementData) * numElements); |
| 35 | |
| 36 | elementsData = (elementData*) malloc (sizeof(elementData) * numElements); |
| 37 | |
| 38 | for(int el=0; el<numElements; el++) |
| 39 | { |
| 40 | Vec3d vertices[4]; |
| 41 | for(int i=0; i<4; i++) |
| 42 | vertices[i] = tetMesh->getVertex(el, i); |
| 43 | StVKSingleTetABCD(vertices, &elementsData[el]); |
| 44 | } |
| 45 | |
| 46 | printf("Total tet ABCD coefficient size: %G Mb.\n", |
| 47 | 1.0 * totalCoefficientSize / 1024 / 1024); |
| 48 | } |
| 49 | |
| 50 | StVKTetABCD::~StVKTetABCD() |
| 51 | { |
| 52 | free(elementsData); |
| 53 | } |
| 54 | |
| 55 | void StVKTetABCD::StVKSingleTetABCD(Vec3d vtx[4], elementData * target) |
| 56 | { |
| 57 | double det = TetMesh::getTetDeterminant(vtx[0], vtx[1], vtx[2], vtx[3]); |
| 58 | target->volume = fabs(det / 6); |
| 59 | |
| 60 | for(int i=0; i<4; i++) |
| 61 | for(int j=0; j<3; j++) |
| 62 | { |
| 63 | Vec3d columns[2]; |
| 64 | int countI = 0; |
| 65 | for(int ii=0; ii<4; ii++) |
| 66 | { |
| 67 | if (ii == i) |
| 68 | continue; |
| 69 | int countJ = 0; |
| 70 | for(int jj=0; jj<3; jj++) |
| 71 | { |
| 72 | if (jj == j) |
| 73 | continue; |
| 74 | |
| 75 | columns[countJ][countI] = vtx[ii][jj]; |
| 76 | countJ++; |
| 77 | } |
| 78 | int sign = (((i + j) % 2) == 0) ? -1 : 1; |
| 79 | target->Phig[i][j] = 1.0 * sign * dot(Vec3d(1,1,1), cross(columns[0],columns[1])) / det; |
| 80 | countI++; |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void StVKTetABCD::AllocateElementIterator(void ** elementIterator) |
| 86 | { |
| 87 | ElementCache * cache = new ElementCache(); |
| 88 | *elementIterator = cache; |
| 89 | } |
| 90 | |
| 91 | void StVKTetABCD::ReleaseElementIterator(void * elementIterator) |
| 92 | { |
| 93 | ElementCache * cache = (ElementCache *) elementIterator; |
| 94 | delete(cache); |
| 95 | } |
| 96 | |
| 97 | void StVKTetABCD::PrepareElement(int el, void * elementIterator) |
| 98 | { |
| 99 | ElementCache * cache = (ElementCache *) elementIterator; |
| 100 | cache->elementPointer = &elementsData[el]; |
| 101 | for(int i=0; i<4; i++) |
| 102 | for(int j=0; j<4; j++) |
| 103 | (cache->dots)[i][j] = dot(cache->elementPointer->Phig[i], cache->elementPointer->Phig[j]); |
| 104 | } |
| 105 | |
| 106 | Mat3d StVKTetABCD::A(void * elementIterator, int i, int j) |
| 107 | { |
| 108 | ElementCache * cache = (ElementCache *) elementIterator; |
| 109 | return cache->elementPointer->volume * tensorProduct(cache->elementPointer->Phig[i], cache->elementPointer->Phig[j]); |
| 110 | } |
| 111 | |
| 112 | double StVKTetABCD::B(void * elementIterator, int i, int j) |
| 113 | { |
| 114 | ElementCache * cache = (ElementCache *) elementIterator; |
| 115 | return cache->elementPointer->volume * cache->dots[i][j]; |
| 116 | } |
| 117 | |
| 118 | Vec3d StVKTetABCD::C(void * elementIterator, int i, int j, int k) |
| 119 | { |
| 120 | ElementCache * cache = (ElementCache *) elementIterator; |
| 121 | return cache->elementPointer->volume * cache->dots[j][k] * cache->elementPointer->Phig[i]; |
| 122 | } |
| 123 | |
| 124 | double StVKTetABCD::D(void * elementIterator, int i, int j, int k, int l) |
| 125 | { |
| 126 | ElementCache * cache = (ElementCache *) elementIterator; |
| 127 | return cache->elementPointer->volume * cache->dots[i][j] * cache->dots[k][l]; |
| 128 | } |
| 129 |