Debian Codegraph @

tools/physicalModeling/mesh2faust/vega/libraries/stvk/StVKInternalForces.h

raw symbols SCIP
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 #ifndef _STVKINTERNALFORCES_H_
30 #define _STVKINTERNALFORCES_H_
31
32 /*
33
34 Given a 3D volumetric mesh, and a vector of displacements of its vertices,
35 the classes StVKInternalForces, StVKStiffnessMatrix and StVKHessianTensor
36 compute internal elastic strain energy, internal forces, tangent stiffness
37 matrices, and the second derivative of internal forces (the Hessian), under
38 an isotropic geometrically nonlinear Finite Element Method (FEM) elastic model.
39 Large deformations are therefore supported ("geometric nonlinearities").
40 The strain-stress relationship is linear (the St. Venant-Kirchhoff model).
41 Material parameters (Young's modulus, Poisson ratio, mass density) can be set
42 for each individual mesh element, and can therefore vary across the mesh.
43
44 Supported volumetric mesh types:
45 1. Tetrahedral meshes
46 2. Meshes consisting of cubes, obtained by voxelizing a triangle geometry
47 (the cubes are a subset of a regular 3D grid; all cubes are axis-aligned and
48 of the same size)
49
50 Multi-threaded versions of the classes are also available ("MT" suffix).
51 They use POSIX threads ("pthreads") - which are available under Unix, Mac OS X,
52 and also Windows. The code is thread-safe. The computation of the following
53 quantities is multi-threaded: internal forces, tangent stiffness matrix,
54 strain energy. With large meshes, these routines achieve almost linear scaling
55 (tested on a 8-core CPU).
56
57 We were able to run the code under Unix, Max OS X, and Windows.
58
59 This code was designed for interactive simulation, but can also be used offline.
60 The routines were optimized for speed. Our multi-threaded implementation is
61 interactive up to about several thousand tetrahedra.
62
63 The code also supports reduced FEM deformable models ([Barbic and James 2005],
64 SIGGRAPH 2005). The corresponding classes use "Reduced" in their name. So, this
65 code essentially gives two separate simulators: full simulations (no reduction),
66 and reduced simulations.
67
68 With tet meshes, there is a choice between a low-memory implementation and a
69 high-memory implementation. With a few thousand tetrahedra (depending on the
70 size and availability of your memory), you can gain a small speedup (e.g. 1.5x)
71 by using a high-memory version (see StVKTetHighMemoryABCD.h).
72
73 Note: all matrices are stored in the column-major order (same format as in LAPACK).
74
75 */
76
77 #include "volumetricMesh.h"
78 #include "StVKElementABCD.h"
79
80 class StVKInternalForces
81 {
82 public:
83
84 // before creating this class, you must first create the volumetric mesh, and the precomputed integrals
85 // you can use the StVKElementABCDLoader.h header file to create the "precomputedABCDIntegrals"
86 StVKInternalForces(VolumetricMesh * volumetricMesh, StVKElementABCD * precomputedABCDIntegrals, bool addGravity=false, double g=9.81);
87 virtual ~StVKInternalForces();
88
89 // both vertex displacements and internal forces refer to the vertices of the simulation mesh
90 // they must be (pre-allocated) vectors of length 3 * numVertices
91 // the internal forces are returned with the sign corresponding to f_int(x) on the left side of the equation M * x'' + f_int(x) = f_ext
92 // i.e., the computed internal forces are negatives of the actual physical internal forces acting on the material
93 virtual void ComputeForces(const double * vertexDisplacements, double * internalForces);
94
95 // enables or disables the gravity (note: you can also set this in the constructor; use this routine to turn the gravity on/off during the simulation)
96 void SetGravity(bool addGravity) { this->addGravity = addGravity; InitGravity(); } // if addGravity is enabled, ComputeForces will subtract the gravity force from the internal forces (note: subtraction, not addition, is used because the internal forces are returned with the sign as described in the f_int(x) comment above)
97
98 virtual double ComputeEnergy(const double * vertexDisplacements); // get the nonlinear elastic strain energy
99
100 inline VolumetricMesh * GetVolumetricMesh() { return volumetricMesh; }
101 inline StVKElementABCD * GetPrecomputedIntegrals() { return precomputedIntegrals; }
102
103 // === advanced routines below ===
104 double ComputeEnergyContribution(const double * vertexDisplacements, int elementLow, int elementHigh, double * buffer = NULL); // compute the contribution to strain energy due to the specified elements; needs a buffer for internal calculations; you can pass NULL (and then an internal buffer will be used), or pass your own buffer (useful with multi-threading)
105 void AddLinearTermsContribution(const double * vertexDisplacements, double * forces, int elementLow=-1, int elementHigh=-1);
106 void AddQuadraticTermsContribution(const double * vertexDisplacements, double * forces, int elementLow=-1, int elementHigh=-1);
107 void AddCubicTermsContribution(const double * vertexDisplacements, double * forces, int elementLow=-1, int elementHigh=-1);
108
109 protected:
110 VolumetricMesh * volumetricMesh;
111 StVKElementABCD * precomputedIntegrals;
112
113 double * gravityForce;
114 bool addGravity;
115 double g;
116 void InitGravity(); // aux function
117
118 double * buffer;
119 int numElementVertices;
120
121 void ResetVector(double * vec); // aux function
122
123 double * lambdaLame;
124 double * muLame;
125 };
126
127 #endif
128