/usr/include/ITK-4.5/itkFEMSolverCrankNicolson.h is in libinsighttoolkit4-dev 4.5.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /*=========================================================================
*
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef __itkFEMSolverCrankNicolson_h
#define __itkFEMSolverCrankNicolson_h
#include "itkFEMSolver.h"
#include "itkFEMElementBase.h"
#include "itkFEMMaterialBase.h"
#include "itkFEMLoadBase.h"
#include "itkFEMLinearSystemWrapperVNL.h"
#include "vnl/vnl_sparse_matrix.h"
#include "vnl/vnl_matrix.h"
#include "vnl/vnl_vector.h"
#include "vnl/algo/vnl_svd.h"
#include "vnl/algo/vnl_cholesky.h"
#include <vnl/vnl_sparse_matrix_linear_system.h>
#include <cmath>
namespace itk
{
namespace fem
{
/**
* \class SolverCrankNicolson
* \brief FEM Solver for time dependent problems; uses Crank-Nicolson implicit discretization scheme.
*
* This is the main class used for solving FEM time-dependent problems.
* It solves the following problem:
*
* \f[
* ( M + \alpha*dt* K )*U_t=(M - (1.- \alpha)*dt* K)* U_{t-1} + dt*(\alpha*f_{n+1} + (1-\alpha)*f_n)
* \f]
*
* which is the Crank-Nicolson formulation of the static problem if \f$\alpha=0.5\f$.
* The static solution is gained if :
* \f$\rho = 0.0\f$; \f$\alpha = 1.0\f$; \f$dt = 1.0\f$;
* Practically, it is good to set rho to something small (for the itpack solver).
* The advantage of choosing \f$\alpha=0.5\f$ is that the solution is then stable for any
* choice of time step, dt. This class inherits and uses most of the Solver class
* functionality.
*
* Updated: The calls to to AssembleKandM (or AssembleK) and
* AssembleFforTimeStep (or AssembleF) are now handled internally
* by calling Update().
*
* FIXME:
* 1) We should also account for the contribution to the force from essential BCs.
* Basically there are terms involving \f$ M * (\dot g_b) \f$ and \f$ K * g_b \f$
* where\f$ g_b\f$ is the essential BC vector.
* \ingroup ITKFEM
*/
template <unsigned int TDimension = 3>
class SolverCrankNicolson : public Solver<TDimension>
{
public:
typedef SolverCrankNicolson Self;
typedef Solver<TDimension> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods) */
itkTypeMacro(SolverCrankNicolson, Solver<TDimension> );
typedef Element::Float Float;
/**
* Get/Set the use of the Mass Matrix for the solution
*/
itkSetMacro(UseMassMatrix, bool);
itkGetMacro(UseMassMatrix, bool);
/**
* Get the number of iterations run for the solver
*/
itkGetConstMacro(Iterations, unsigned int);
/**
* Reset the number of iterations for the solver. This
* will prompt the Solver to Assemble the master stiffness
* and mass matrix again. This is only generated before the
* first iteration.
*/
void ResetIterations(void)
{
m_Iterations = 0;
}
/**
* Add solution vector u to the corresponding nodal values, which are
* stored in node objects). This is standard post processing of the solution
*/
void AddToDisplacements(Float optimum = 1.0);
void AverageLastTwoDisplacements(Float t = 0.5);
void ZeroVector(int which = 0);
void PrintDisplacements();
void PrintForce();
/** Get the index for the current solution */
itkGetMacro(TotalSolutionIndex, unsigned int);
/** Get the index for the previous solution */
itkGetMacro(SolutionTMinus1Index, unsigned int);
/** Set stability step for the solution. Initialized to 0.5 */
itkSetMacro(Alpha, Float);
itkGetMacro(Alpha, Float);
/** Set density constant. */
itkSetMacro(Rho, Float);
itkGetMacro(Rho, Float);
/** Returns the time step used for dynamic problems. */
virtual Float GetTimeStep(void) const
{
return m_TimeStep;
}
/**
* Sets the time step used for dynamic problems.
*
* \param dt New time step.
*/
virtual void SetTimeStep(Float dt)
{
m_TimeStep = dt;
}
/** compute the current state of the right hand side and store the current force
* for the next iteration.
*/
void RecomputeForceVector(unsigned int index);
/* Finds a triplet that brackets the energy minimum. From Numerical
Recipes.*/
void FindBracketingTriplet(Float *a, Float *b, Float *c);
/** Finds the optimum value between the last two solutions
* and sets the current solution to that value. Uses Evaluate Residual;
*/
Float GoldenSection(Float tol = 0.01, unsigned int MaxIters = 25);
/* Brents method from Numerical Recipes. */
Float BrentsMethod(Float tol = 0.01, unsigned int MaxIters = 25);
Float EvaluateResidual(Float t = 1.0);
Float GetDeformationEnergy(Float t = 1.0);
inline Float GSSign(Float a, Float b)
{
return b > 0.0 ? vcl_fabs(a) : -1. * vcl_fabs(a);
}
inline Float GSMax(Float a, Float b)
{
return a > b ? a : b;
}
void SetEnergyToMin(Float xmin);
inline LinearSystemWrapper * GetLS()
{
return this->m_ls;
}
Float GetCurrentMaxSolution()
{
return m_CurrentMaxSolution;
}
/** Compute and print the minimum and maximum of the total solution
* and the last solution. */
void PrintMinMaxOfSolution();
protected:
SolverCrankNicolson();
~SolverCrankNicolson() { }
/** Method invoked by the pipeline in order to trigger the computation of
* the registration. */
void GenerateData();
/**
* Solve for the displacement vector u at a given time. Update the total solution as well.
*/
virtual void RunSolver(void);
/**
* helper initialization function before assembly but after generate GFN.
*/
void InitializeForSolution();
/**
* Assemble the master stiffness and mass matrix. We actually assemble
* the right hand side and left hand side of the implicit scheme equation.
*/
void AssembleKandM();
/**
* Assemble the master force vector at a given time.
*
* \param dim This is a parameter that can be passed to the function and is
normally used with isotropic elements to specify the
dimension for which the master force vector should be assembled.
*/
void AssembleFforTimeStep(int dim = 0);
Float m_TimeStep;
Float m_Rho;
Float m_Alpha;
Float m_CurrentMaxSolution;
bool m_UseMassMatrix;
unsigned int m_Iterations;
unsigned int m_ForceTIndex;
unsigned int m_ForceTotalIndex;
unsigned int m_ForceTMinus1Index;
unsigned int m_SolutionTIndex;
unsigned int m_SolutionTMinus1Index;
unsigned int m_SolutionVectorTMinus1Index;
unsigned int m_TotalSolutionIndex;
unsigned int m_DifferenceMatrixIndex;
unsigned int m_SumMatrixIndex;
unsigned int m_DiffMatrixBySolutionTMinus1Index;
private:
SolverCrankNicolson(const Self &); // purposely not implemented
void operator=(const Self &); // purposely not implemented
};
}
} // end namespace itk::fem
#ifndef ITK_MANUAL_INSTANTIATION
#include "itkFEMSolverCrankNicolson.hxx"
#endif
#endif // #ifndef __itkFEMSolverCrankNicolson_h
|