Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F68344055
test_patch_westergaard.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Jun 26, 23:48
Size
4 KB
Mime Type
text/x-python
Expires
Fri, Jun 28, 23:48 (2 d)
Engine
blob
Format
Raw Data
Handle
18567625
Attached To
rTAMAAS tamaas
test_patch_westergaard.py
View Options
#!/usr/bin/env python
# coding: utf-8
# -----------------------------------------------------------------------------
# @author Lucas Frérot <lucas.frerot@epfl.ch>
#
# @section LICENSE
#
# Copyright (©) 2016 EPFL (Ecole Polytechnique Fédérale de
# Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
# Solides)
#
# Tamaas is free software: you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# Tamaas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Tamaas. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------
from
__future__
import
division
,
print_function
import
numpy
as
np
from
numpy.linalg
import
norm
import
tamaas
as
tm
def
constructSinProfile
(
size
,
mode
,
amplitude
):
x
=
np
.
linspace
(
0
,
1
,
size
,
endpoint
=
False
)
y
=
np
.
linspace
(
0
,
1
,
size
,
endpoint
=
False
)
x
,
y
=
np
.
meshgrid
(
x
,
y
,
indexing
=
'ij'
)
surface
=
amplitude
*
np
.
sin
(
2
*
np
.
pi
*
x
*
mode
[
0
])
*
np
.
sin
(
2
*
np
.
pi
*
y
*
mode
[
1
])
return
surface
.
copy
()
def
constructCosProfile
(
size
,
mode
,
amplitude
):
x
=
np
.
linspace
(
0
,
1
,
size
,
endpoint
=
False
)
y
=
np
.
linspace
(
0
,
1
,
size
,
endpoint
=
False
)
x
,
y
=
np
.
meshgrid
(
x
,
y
,
indexing
=
'ij'
)
surface
=
amplitude
*
np
.
cos
(
2
*
np
.
pi
*
x
*
mode
[
0
])
*
np
.
cos
(
2
*
np
.
pi
*
y
*
mode
[
1
])
return
surface
.
copy
()
def
test_patch_westergaard
():
tm
.
initialize
()
E
=
3.
nu
=
0.
E_star
=
E
/
(
1
-
nu
**
2
)
grid_size
=
6
modes
=
np
.
array
([
2
,
1
])
input_pressure
=
constructSinProfile
(
grid_size
,
modes
,
1
)
model
=
tm
.
ModelFactory
.
createModel
(
tm
.
model_type
.
basic_2d
,
[
1.
,
1.
],
[
grid_size
,
grid_size
])
model
.
setElasticity
(
E
,
nu
)
model
.
getTraction
()[:,
:]
=
input_pressure
[:,
:]
model
.
solveNeumann
()
output_displ
=
model
.
getDisplacement
()
solution
=
constructSinProfile
(
grid_size
,
modes
,
1
/
(
np
.
pi
*
E_star
*
norm
(
modes
)))
error
=
norm
(
solution
-
output_displ
)
/
norm
(
solution
)
assert
error
<
1e-15
,
"Neumann error = {}"
.
format
(
error
)
output_displ
[:,
:]
=
solution
[:,
:]
model
.
solveDirichlet
()
error
=
norm
(
input_pressure
-
model
.
getTraction
())
/
norm
(
input_pressure
)
assert
error
<
1e-15
,
"Dirichlet error = {}"
.
format
(
error
)
tm
.
finalize
()
def
test_patch_westergaard_surface
():
def
constructSinProfile
(
size
,
mode
,
amplitude
):
x
=
np
.
linspace
(
0
,
1
,
size
,
endpoint
=
False
)
y
=
np
.
linspace
(
0
,
1
,
size
,
endpoint
=
False
)
x
,
y
=
np
.
meshgrid
(
x
,
y
,
indexing
=
'ij'
)
surface
=
amplitude
*
np
.
sin
(
2
*
np
.
pi
*
x
*
mode
)
return
surface
.
copy
()
def
constructCosProfile
(
size
,
mode
,
amplitude
):
x
=
np
.
linspace
(
0
,
1
,
size
,
endpoint
=
False
)
y
=
np
.
linspace
(
0
,
1
,
size
,
endpoint
=
False
)
x
,
y
=
np
.
meshgrid
(
x
,
y
,
indexing
=
'ij'
)
surface
=
amplitude
*
np
.
cos
(
2
*
np
.
pi
*
x
*
mode
)
return
surface
.
copy
()
tm
.
initialize
()
E
=
3.
nu
=
0.
E_star
=
E
/
(
1
-
nu
**
2
)
mu
=
E
/
(
2
*
(
1
+
nu
))
grid_size
=
4
input_pressure
=
constructCosProfile
(
grid_size
,
1
,
1
)
model
=
tm
.
ModelFactory
.
createModel
(
tm
.
model_type
.
surface_2d
,
[
1.
,
1.
],
[
grid_size
,
grid_size
])
model
.
setElasticity
(
E
,
nu
)
model
.
getTraction
()[:,
:,
2
]
=
input_pressure
[:,
:]
model
.
solveNeumann
()
output_displ
=
model
.
getDisplacement
()
solution
=
np
.
zeros_like
(
output_displ
)
solution
[:,
:,
2
]
=
constructCosProfile
(
grid_size
,
1
,
1
/
(
np
.
pi
*
E_star
))
solution
[:,
:,
0
]
=
constructSinProfile
(
grid_size
,
1
,
-
(
1
-
2
*
nu
)
/
(
4
*
mu
*
np
.
pi
))
error
=
norm
(
solution
-
output_displ
)
/
norm
(
solution
)
assert
error
<
1e-15
,
"Neumann error = {}"
.
format
(
error
)
if
__name__
==
"__main__"
:
test_patch_westergaard
()
Event Timeline
Log In to Comment