| 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 _STVKHESSIANTENSOR_H_ |
| 30 | #define _STVKHESSIANTENSOR_H_ |
| 31 | |
| 32 | /* |
| 33 | The second derivative (Hessian tensor) of internal elastic forces. |
| 34 | See also StVKInternalForces.h . |
| 35 | */ |
| 36 | |
| 37 | #include "triple.h" |
| 38 | #include "sparseMatrix.h" |
| 39 | #include "volumetricMesh.h" |
| 40 | #include "StVKElementABCD.h" |
| 41 | #include "StVKStiffnessMatrix.h" |
| 42 | |
| 43 | class StVKHessianTensor |
| 44 | { |
| 45 | public: |
| 46 | |
| 47 | StVKHessianTensor(StVKStiffnessMatrix * stVKStiffnessMatrix); |
| 48 | virtual ~StVKHessianTensor(); |
| 49 | |
| 50 | inline int numVertices() { return numVertices_; } |
| 51 | inline int numElements() { return numElements_; } |
| 52 | |
| 53 | // uses the Hessian tensor to approximate the change in the tangent stiffness matrix, if configuration is changed from u to u + du (du is assumed small) |
| 54 | // any required Hessian tensor quantities (in configuration u) are computed automatically |
| 55 | virtual void ComputeStiffnessMatrixCorrection(double * u, double * du, SparseMatrix * dK); |
| 56 | |
| 57 | // compute the vector result=(H:u)v, where H is the Hessian in the zero deformation configuration |
| 58 | // high-memory version; must call ComputeHessianAtZero before calling EvaluateHessianQuadraticForm |
| 59 | int ComputeHessianAtZero(int verbose=1); |
| 60 | int SaveHessianAtZeroToFile(const char * filename); |
| 61 | void EvaluateHessianQuadraticForm(double * u, double * v, double * result); |
| 62 | |
| 63 | // compute the vector result=(H:u)v, where H is the Hessian in the zero deformation configuration |
| 64 | // low-memory version; no need to call ComputeHessianAtZero, but longer computation times for smaller meshes |
| 65 | void EvaluateHessianQuadraticFormDirect(double * u, double * v, double * result); |
| 66 | |
| 67 | // computes (H:u)v, for all pairs of columns of the matrix Ulin; k is the number of columns of Ulin |
| 68 | // the first numRigidModes columns will not be used for this computation |
| 69 | // result is the output matrix; must be pre-allocated with (k-numRigidModes) * (k-numRigidModes+1) / 2 columns |
| 70 | // low-memory version; no need to call ComputeHessianAtZero |
| 71 | void EvaluateHessianQuadraticFormDirectAll(double * Ulin, int k, double * result, int numRigidModes=0, int verbose=1); |
| 72 | |
| 73 | // low-level routines (advanced use) |
| 74 | void AddQuadraticTermsContribution(double * u, double * du, SparseMatrix * dK, int elementLow=-1, int elementHigh=-1); |
| 75 | void AddCubicTermsContribution(double * u, double * du, SparseMatrix * dK, int elementLow=-1, int elementHigh=-1); |
| 76 | |
| 77 | protected: |
| 78 | int numVertices_; |
| 79 | int numElements_; |
| 80 | |
| 81 | StVKStiffnessMatrix * stVKStiffnessMatrix; |
| 82 | VolumetricMesh * volumetricMesh; |
| 83 | StVKElementABCD * precomputedIntegrals; |
| 84 | |
| 85 | int numElementVertices; |
| 86 | |
| 87 | typedef triple<int,int,int> triIndex; |
| 88 | typedef std::map<triIndex,double*> hessianType; |
| 89 | hessianType hessian; |
| 90 | void AddTensor3x3x3Block(int v1, int v2, int v3, Vec3d & vec, int type); |
| 91 | |
| 92 | double * lambdaLame; |
| 93 | double * muLame; |
| 94 | }; |
| 95 | |
| 96 | #endif |
| 97 |