Accelerated Complex-Step RAN LUO, The University of New Mexico, Finite Difference for WEIWEI XU, Zhejiang University TIANJIA SHAO, University of Leeds Expedient Deformable HONGYI XU, Google AI YIN YANG, Clemson University Simulation
Deformable Objects ❑ High-quality deformable simulation is important ❑ Well-known problem but computational expensive Nonlinearity: repeated evaluation of internal force and its gradient … [Xu et al, 2014] [Teng et al, 2015] [Zheng & James, 2012] [Zhao & Barbič , 2013]
Nonlinearity ❑ A key challenge is the nonlinearity Largely come from the strain energy Define strain-stress relation just based on the strain energy 𝐆 = 𝐉 + 𝜖𝐯 , , where 𝜖𝐲 ❑ More complicated energies are not uncommon [Martin et al, 2011] [Xu et al, 2015]
Will a Numerical Derivative Work? ❑ The best-known method is finite difference + = + + 2 ( ) ( ) ( ) ( ) O f x h f x f x h h 0 0 0 + − ( ) ( ) f x h f x + O 0 0 ( ) ( ) f x h 0 h ❑ Does not work in general due to the subtractive cancellation In theory, the smaller perturbation is, the better approximation we obtain In practice, smaller perturbation does not converge, explode at certain
Will a Numerical Derivative Work? Newton method
Will a Numerical Derivative Work? Forward difference
Rounding Error ❑ We have limited digits to represent a real number ❑ Precision depends on how many digits we could allocate a = − − 3 1999.99, 1999.99 1. 999 1 0 a a − = = 4 4.95 1 0 E round a = 3 | | 1 999 .9 9 a 1.99 9 10 ❑ Known as machine epsilon ( for double precision) 1.1 10 − 16 However, it is NOT the evil of finite difference True problem appears when we have a subtraction between two similar values
Subtractive Cancellation ❑ Another example and b = a = b = a = 3 3 1998.88, 1999.99, 1.99 8 10 1.99 9 10 − − − ( ) ( ) a b a b = E − subtraction | | a b − − − 3 (199 9.99 1.998) 10 (19 99.99 1998.88) = − 19 9.99 1998.8 9 8 = 0 . 1 ❑ Subtraction eliminates the first three significant digits Rounding eliminates the least important digit ❑ Bigger perturbation has bigger approximation error but smaller perturbation leads to subtractive cancellation
Complex Step Finite Difference (CSFD) ❑ Apply the perturbation with complex Tayler expansion + = + + O * * * 2 ( ) ( ) ( ) ( ) ( ) f x hi f x f x hi h 0 0 0 ( ) ( ) + = + + * * * 3 I m ( ) Im ( ) ( ) ( ) ( ) f x hi f x f x hi O h 0 0 0 ( ) + * I m ( ) f x hi 0 = + 2 ( ) ( ) O f x h 0 h
Complex Step Finite Difference (CSFD) ❑ We can have very small perturbation ( ) to fully 10 − 40 approach to the target The approximate error can be reduced to the same order of machine epsilon As accurate as analytic derivative x e = ( ) f x + + 4 2 1 x x − + − + 4 3 2 4 2 1 x x x x = x ( ) f x e + + 4 2 1 x x
Too Good to Be True? ❑ Promoting the original real function to a complex function Can be easily implemented especially given a good complex library It could also be expensive (orders of magnitude in some cases) ❑ CSFD can be accelerated A full complex promotion is a waste (only imaginary part is needed) Perturbation is a very small value, can be treated as an infinitesimal Higher order h term can be discarded
An Example ❑ Full promotion + + 2 2 k k i = → + = + 1/ * 1/ m m ( ) ( ) cos s in f x x f x hi r 0 0 0 m m ❑ Imaginary only Full promotion 13.1 sec ( ) + * I m ( ) f x hi Imaginary only 9.49 sec 1 0 = 1/ m si n r Infinitesimal trick 0.056 sec (233X) h h m Analytic 0.064 sec ❑ By treating h as an infinitesimal 1/ m 1 1 1 h r = = = 1/ 1/ 1/ m m m sin r r r h m h m h rm rm
Composite Functions ❑ Functions in real-world applications are complicated involving = A chain of binary operators ( ) ( ) ( ) ( ) f x f x f x f x 1 2 k = Nested operators ( ) ( ( ( ))) f x f f f 1 2 3 ❑ The key idea: isolate the propagation of imaginary perturbation ❑ Let etc., we have = + + + = + ( ) ( ) ( ) ( ) ( ) f x f x a b a a b b f x a b 1 2 1 1 2 1 1 2 1 1 1 Each time a new comes, number of addends doubles with an and a a b f k k k appended
Complicated Functions (cont.) ❑ The path to leaf determines the shape of an addend ❑ An is the real part value and is the perturbation (imaginary) a b k k We do not need any leaves with more than two b k We could pre-compute product of all a A = = k A a a a a a b b 1 2 3 1 2 3 2 a 3
Higher-order Derivative & Tensor ❑ Multi-complex number, recursively defined − = + 1 n n , , z z i z z 1 2 1 2 n ❑ We can have MC Tayler expansion, and MSCFD becomes ( ) + + + + Im ( ) f x hi hi hi 0 1 2 = n + ( ) 2 n ( ) ( ) O f x h n h ❑ Cauchy-Riemann formulation extends CSFD/MSCFD to tensor functions − − − 1 1 n n z z − − = + = 1 1 1 2 n n n z z z i − − 1 2 n 1 1 n n z z 2 1
Derivative of Matrix Inverse
Highly Accurate in Simulation
Intuitive Hyperelastic Simulation ❑ Hyperelastic models with minor implementation efforts ❑ CSFD/MSCFD further enables us to design customized energy ( ) − = − + − − 2/3 2 ( 3 ) log 1 4( 1) E J I J volume C 2
Intuitive Hyperelastic Simulation
More Customized Energy
Model Derivative for All
Convenient Inverse Design
Thank You We are hiring ☺ https://github.com/lrquad/MCSFD
Recommend
More recommend