#! /usr/bin/env python3 # def biharmonic_exact_test ( ): #*****************************************************************************80 # ## biharmonic_exact_test() tests biharmonic_exact(). # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 01 August 2024 # # Author: # # John Burkardt # from numpy.random import default_rng import numpy as np import platform import scipy print ( '' ) print ( 'biharmonic_exact_test():' ) print ( ' python version: ' + platform.python_version ( ) ) print ( ' numpy version: ' + np.version.version ) print ( ' scipy version: ' + scipy.__version__ ) print ( ' Test biharmonic_exact().' ) rng = default_rng ( ) n = 5 X = rng.random ( size = n ) Y = rng.random ( size = n ) a = 1.0 b = 2.0 c = 3.0 d = 4.0 e = 5.0 f = 6.0 g = 7.0 # # Exact function 1. # print ( '' ) print ( ' Exact solution 1 residual at random points:' ) R = biharmonic_exact_r1 ( X, Y, a, b, c, d, e, f, g ) print ( R ) # # Exact function 2. # print ( '' ) print ( ' Exact solution 2 residual at random points:' ) R = biharmonic_exact_r2 ( X, Y, a, b, c, d, e, f, g ) print ( R ) # # Exact function 3. # print ( '' ) print ( ' Exact solution 3 residual at random points:' ) R = biharmonic_exact_r3 ( X, Y, a, b, c, d, e, f ) print ( R ) # # Terminate. # print ( '' ) print ( 'biharmonic_exact_test()' ) print ( ' Normal end of execution.' ) return def biharmonic_exact_r1 ( X, Y, a, b, c, d, e, f, g ): #*****************************************************************************80 # ## biharmonic_exact_r1() evaluates exact biharmonic residual for W(X,Y) #1. # # Discussion: # # Note the formula for W: # # W = ( a * np.cosh ( g * X ) \ # + b * np.sinh ( g * X ) \ # + c * X * np.cosh ( g * X ) \ # + d * X * np.sinh ( g * X ) ) \ # * \ # ( e * np.cos ( g * Y ) \ # + f * np.sin ( g * Y ) ) # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 01 August 2024 # # Author: # # John Burkardt # # Input: # # real X, Y: the coordinates of the points. # # real a, b, c, d, e, f, g: parameters. # # Output: # # real R: the residual evaluated at the points (X,Y). # import numpy as np Wxxxx = \ g**3 * ( e * np.cos ( g * Y ) + f * np.sin ( g * Y ) ) \ * \ ( a * g * np.cosh ( g * X ) \ + b * g * np.sinh ( g * X ) \ + c * g * X * np.cosh ( g * X ) \ + 4 * c * np.sinh ( g * X ) \ + d * g * X * np.sinh ( g * X ) \ + 4 * d * np.cosh ( g * X ) ) Wxxyy = \ -g**3 * ( e * np.cos ( g * Y ) + f * np.sin ( g * Y ) ) \ * \ ( a * g * np.cosh ( g * X ) \ + b * g * np.sinh ( g * X ) \ + c * g * X * np.cosh ( g * X ) \ + 2 * c * np.sinh ( g * X ) \ + d * g * X * np.sinh ( g * X ) \ + 2 * d * np.cosh ( g * X ) ) Wyyyy = \ g**4 * ( e * np.cos ( g * Y ) + f * np.sin ( g * Y ) ) \ * \ ( a * np.cosh ( g * X ) \ + b * np.sinh ( g * X ) \ + c * X * np.cosh ( g * X ) \ + d * X * np.sinh ( g * X ) ) R = Wxxxx + 2.0 * Wxxyy + Wyyyy return R def biharmonic_exact_r2 ( X, Y, a, b, c, d, e, f, g ): #*****************************************************************************80 # ## biharmonic_exact_r2() evaluates exact biharmonic residual for W(X,Y) #2. # # Discussion: # # Note the formula for W: # # W = ( a * np.cos ( g * X ) \ # + b * np.sin ( g * X ) \ # + c * X * np.cos ( g * X ) \ # + d * X * np.sin ( g * X ) ) \ # * # ( e * np.cosh ( g * Y ) \ # + f * np.sinh ( g * Y ) ) # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 01 August 2024 # # Author: # # John Burkardt # # Input: # # real X, Y: the coordinates of the points. # # real a, b, c, d, e, f, g: parameters. # # Output: # # real R: the residual evaluated at the points (X,Y). # import numpy as np Wxxxx = g**3 * ( e * np.cosh ( g * Y ) + f * np.sinh ( g * Y ) ) \ * \ ( a * g * np.cos ( g * X ) \ + b * g * np.sin ( g * X ) \ + c * g * X * np.cos ( g * X ) \ + 4 * c * np.sin ( g * X ) \ + d * g * X * np.sin ( g * X ) \ - 4 * d * np.cos ( g * X ) ) Wxxyy = - g**3 * ( e * np.cosh ( g * Y ) + f * np.sinh ( g * Y ) ) \ * \ ( a * g * np.cos ( g * X ) \ + b * g * np.sin ( g * X ) \ + c * g * X * np.cos ( g * X ) \ + 2 * c * np.sin ( g * X ) \ + d * g * X * np.sin ( g * X ) \ - 2 * d * np.cos ( g * X ) ) Wyyyy = g**4 * ( e * np.cosh ( g * Y ) + f * np.sinh ( g * Y ) ) \ * \ ( a * np.cos ( g * X ) \ + b * np.sin ( g * X ) \ + c * X * np.cos ( g * X ) \ + d * X * np.sin ( g * X ) ) R = Wxxxx + 2.0 * Wxxyy + Wyyyy return R def biharmonic_exact_r3 ( X, Y, a, b, c, d, e, f ): #*****************************************************************************80 # ## biharmonic_exact_r3() evaluates exact biharmonic residual for W(X,Y) #3. # # Discussion: # # Note the formula for W: # # R = sqrt ( ( X - e )**2 + ( Y - f )**2 ) # # W = a * R**2 * log ( R ) \ # + b * R**2 \ # + c * log ( R ) \ # + d # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 01 August 2024 # # Author: # # John Burkardt # # Input: # # real X, Y: the coordinates of the points. # # real a, b, c, d, e, f: parameters. # # Output: # # real R: the residual evaluated at the points (X,Y). # import numpy as np Wxxxx = 2 * ( 8 * a * ( e - X )**4 \ / ( ( e - X )**2 + ( f - Y )**2 )**2 - 12 * a * ( e - X )**2 \ / ( ( e - X )**2 + ( f - Y )**2 ) + 3 * a - 24 * c * ( e - X )**4 \ / ( ( e - X )**2 + ( f - Y )**2 )**3 + 24 * c * ( e - X )**2 \ / ( ( e - X )**2 + ( f - Y )**2 )**2 - 3 * c \ / ( ( e - X )**2 + ( f - Y )**2 ) ) \ / ( ( e - X )**2 + ( f - Y )**2 ) Wxxyy = 2 * ( 8 * a * ( e - X )**2 * ( f - Y )**2 \ / ( ( e - X )**2 + ( f - Y )**2 )**2 - 2 * a * ( e - X )**2 \ / ( ( e - X )**2 + ( f - Y )**2 ) - 2 * a * ( f - Y )**2 \ / ( ( e - X )**2 + ( f - Y )**2 ) + a - 24 * c * ( e - X )**2 * ( f - Y )**2 \ / ( ( e - X )**2 + ( f - Y )**2 )**3 + 4 * c * ( e - X )**2 \ / ( ( e - X )**2 + ( f - Y )**2 )**2 + 4 * c * ( f - Y )**2 \ / ( ( e - X )**2 + ( f - Y )**2 )**2 - c \ / ( ( e - X )**2 + ( f - Y )**2 ) ) \ / ( ( e - X )**2 + ( f - Y )**2 ) Wyyyy = 2 * ( 8 * a * ( f - Y )**4 \ / ( ( e - X )**2 + ( f - Y )**2 )**2 - 12 * a * ( f - Y )**2 \ / ( ( e - X )**2 + ( f - Y )**2 ) + 3 * a - 24 * c * ( f - Y )**4 \ / ( ( e - X )**2 + ( f - Y )**2 )**3 + 24 * c * ( f - Y )**2 \ / ( ( e - X )**2 + ( f - Y )**2 )**2 - 3 * c \ / ( ( e - X )**2 + ( f - Y )**2 ) ) \ / ( ( e - X )**2 + ( f - Y )**2 ) R = Wxxxx + 2.0 * Wxxyy + Wyyyy return R def biharmonic_exact_w1 ( X, Y, a, b, c, d, e, f, g ): #*****************************************************************************80 # ## biharmonic_exact1() evaluates exact biharmonic solution W(X,Y) #1. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 01 August 2024 # # Author: # # John Burkardt # # Input: # # real X, Y: the coordinates of the points. # # real a, b, c, d, e, f, g: parameters. # # Output: # # real W: the solution evaluated at the points (X,Y). # import numpy as np W = ( a * np.cosh ( g * X ) \ + b * np.sinh ( g * X ) \ + c * X * np.cosh ( g * X ) \ + d * X * np.sinh ( g * X ) ) \ * \ ( e * np.cos ( g * Y ) \ + f * np.sin ( g * Y ) ) return W def biharmonic_exact_w2 ( X, Y, a, b, c, d, e, f, g ): #*****************************************************************************80 # ## biharmonic_exact_w2() evaluates exact biharmonic solution W(X,Y) #2. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 01 August 2024 # # Author: # # John Burkardt # # Input: # # real X, Y: the coordinates of the points. # # real a, b, c, d, e, f, g: parameters. # # Output: # # real W: the solution evaluated at the points (X,Y). # import numpy as np W = ( a * np.cos ( g * X ) \ + b * np.sin ( g * X ) \ + c * X * np.cos ( g * X ) \ + d * X * np.sin ( g * X ) ) \ * \ ( e * np.cosh ( g * Y ) \ + f * np.sinh ( g * Y ) ) return W def biharmonic_exact_w3 ( X, Y, a, b, c, d, e, f ): #*****************************************************************************80 # ## biharmonic_exact_w3() evaluates exact biharmonic solution W(X,Y) #3. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 01 August 2024 # # Author: # # John Burkardt # # Input: # # real X, Y: the coordinates of the points. # # real a, b, c, d, e, f: parameters. # # Output: # # real W: the solution evaluated at the points (X,Y). # import numpy as np R = np.sqrt ( ( X - e )**2 + ( Y - f )**2 ) W = a * R**2 * np.log ( R ) \ + b * R**2 \ + c * np.log ( R ) \ + d return W def timestamp ( ): #*****************************************************************************80 # ## timestamp() prints the date as a timestamp. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 21 August 2019 # # Author: # # John Burkardt # import time t = time.time ( ) print ( time.ctime ( t ) ) return if ( __name__ == '__main__' ): timestamp ( ) biharmonic_exact_test ( ) timestamp ( )