Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F68960922
test_solid_mechanics_model_bar_traction2d.cc
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
Sat, Jun 29, 16:23
Size
6 KB
Mime Type
text/x-c
Expires
Mon, Jul 1, 16:23 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
18653484
Attached To
rAKA akantu
test_solid_mechanics_model_bar_traction2d.cc
View Options
/**
* @file test_solid_mechanics_model.cc
* @author Nicolas Richart <nicolas.richart@epfl.ch>
* @date Tue Jul 27 14:34:13 2010
*
* @brief test of the class SolidMechanicsModel
*
* @section LICENSE
*
* <insert license here>
*
*/
/* -------------------------------------------------------------------------- */
#include <limits>
#include <fstream>
/* -------------------------------------------------------------------------- */
#include "aka_common.hh"
#include "mesh.hh"
#include "mesh_io.hh"
#include "mesh_io_msh.hh"
#include "solid_mechanics_model.hh"
#include "material.hh"
/* -------------------------------------------------------------------------- */
#ifdef AKANTU_USE_IOHELPER
# include "io_helper.h"
#endif
//AKANTU_USE_IOHELPER
#define CHECK_STRESS
int
main
(
int
argc
,
char
*
argv
[])
{
akantu
::
UInt
spatial_dimension
=
2
;
akantu
::
UInt
max_steps
=
10000
;
akantu
::
Real
time_factor
=
0.2
;
// akantu::Real epot, ekin;
akantu
::
Mesh
mesh
(
spatial_dimension
);
akantu
::
MeshIOMSH
mesh_io
;
mesh_io
.
read
(
"bar.msh"
,
mesh
);
akantu
::
SolidMechanicsModel
*
model
=
new
akantu
::
SolidMechanicsModel
(
mesh
);
akantu
::
UInt
nb_nodes
=
model
->
getFEM
().
getMesh
().
getNbNodes
();
akantu
::
UInt
nb_element
=
model
->
getFEM
().
getMesh
().
getNbElement
(
akantu
::
_triangle_1
);
/// model initialization
model
->
initVectors
();
/// set vectors to 0
memset
(
model
->
getForce
().
values
,
0
,
spatial_dimension
*
nb_nodes
*
sizeof
(
akantu
::
Real
));
memset
(
model
->
getVelocity
().
values
,
0
,
spatial_dimension
*
nb_nodes
*
sizeof
(
akantu
::
Real
));
memset
(
model
->
getAcceleration
().
values
,
0
,
spatial_dimension
*
nb_nodes
*
sizeof
(
akantu
::
Real
));
memset
(
model
->
getDisplacement
().
values
,
0
,
spatial_dimension
*
nb_nodes
*
sizeof
(
akantu
::
Real
));
model
->
readMaterials
(
"material.dat"
);
model
->
initMaterials
();
model
->
initModel
();
std
::
cout
<<
model
->
getMaterial
(
0
)
<<
std
::
endl
;
model
->
assembleMass
();
#ifdef AKANTU_USE_IOHELPER
/// set to 0 only for the first paraview dump
memset
(
model
->
getResidual
().
values
,
0
,
spatial_dimension
*
nb_nodes
*
sizeof
(
akantu
::
Real
));
memset
(
model
->
getMaterial
(
0
).
getStrain
(
akantu
::
_triangle_1
).
values
,
0
,
spatial_dimension
*
spatial_dimension
*
nb_element
*
sizeof
(
akantu
::
Real
));
memset
(
model
->
getMaterial
(
0
).
getStress
(
akantu
::
_triangle_1
).
values
,
0
,
spatial_dimension
*
spatial_dimension
*
nb_element
*
sizeof
(
akantu
::
Real
));
#endif
//AKANTU_USE_IOHELPER
/// boundary conditions
akantu
::
Real
eps
=
1e-16
;
for
(
akantu
::
UInt
i
=
0
;
i
<
nb_nodes
;
++
i
)
{
if
(
model
->
getFEM
().
getMesh
().
getNodes
().
values
[
spatial_dimension
*
i
]
>=
9
)
model
->
getDisplacement
().
values
[
spatial_dimension
*
i
]
=
(
model
->
getFEM
().
getMesh
().
getNodes
().
values
[
spatial_dimension
*
i
]
-
9
)
/
100.
;
if
(
model
->
getFEM
().
getMesh
().
getNodes
().
values
[
spatial_dimension
*
i
]
<=
eps
)
model
->
getBoundary
().
values
[
spatial_dimension
*
i
]
=
true
;
if
(
model
->
getFEM
().
getMesh
().
getNodes
().
values
[
spatial_dimension
*
i
+
1
]
<=
eps
||
model
->
getFEM
().
getMesh
().
getNodes
().
values
[
spatial_dimension
*
i
+
1
]
>=
1
-
eps
)
{
model
->
getBoundary
().
values
[
spatial_dimension
*
i
+
1
]
=
true
;
}
}
akantu
::
Real
time_step
=
model
->
getStableTimeStep
()
*
time_factor
;
std
::
cout
<<
"Time Step = "
<<
time_step
<<
"s"
<<
std
::
endl
;
model
->
setTimeStep
(
time_step
);
// model->setTimeStep(3.54379e-07);
#ifdef AKANTU_USE_IOHELPER
DumperParaview
dumper
;
dumper
.
SetMode
(
TEXT
);
dumper
.
SetPoints
(
model
->
getFEM
().
getMesh
().
getNodes
().
values
,
spatial_dimension
,
nb_nodes
,
"coordinates"
);
dumper
.
SetConnectivity
((
int
*
)
model
->
getFEM
().
getMesh
().
getConnectivity
(
akantu
::
_triangle_1
).
values
,
TRIANGLE1
,
nb_element
,
C_MODE
);
dumper
.
AddNodeDataField
(
model
->
getDisplacement
().
values
,
spatial_dimension
,
"displacements"
);
dumper
.
AddNodeDataField
(
model
->
getVelocity
().
values
,
spatial_dimension
,
"velocity"
);
dumper
.
AddNodeDataField
(
model
->
getResidual
().
values
,
spatial_dimension
,
"force"
);
dumper
.
AddElemDataField
(
model
->
getMaterial
(
0
).
getStrain
(
akantu
::
_triangle_1
).
values
,
spatial_dimension
*
spatial_dimension
,
"strain"
);
dumper
.
AddElemDataField
(
model
->
getMaterial
(
0
).
getStress
(
akantu
::
_triangle_1
).
values
,
spatial_dimension
*
spatial_dimension
,
"stress"
);
dumper
.
SetEmbeddedValue
(
"displacements"
,
1
);
dumper
.
SetPrefix
(
"paraview/"
);
dumper
.
Init
();
dumper
.
Dump
();
#endif
//AKANTU_USE_IOHELPER
#ifdef CHECK_STRESS
std
::
ofstream
outfile
;
outfile
.
open
(
"stress"
);
#endif
// CHECK_STRESS
model
->
setPotentialEnergyFlagOn
();
for
(
akantu
::
UInt
s
=
1
;
s
<=
max_steps
;
++
s
)
{
model
->
explicitPred
();
model
->
updateResidual
();
model
->
updateAcceleration
();
model
->
explicitCorr
();
// epot = model->getPotentialEnergy();
// ekin = model->getKineticEnergy();
// std::cout << s << " " << epot << " " << ekin << " " << epot + ekin
// << std::endl;
#ifdef CHECK_STRESS
akantu
::
Real
max_stress
=
std
::
numeric_limits
<
akantu
::
Real
>::
min
();
akantu
::
UInt
max_el
=
0
;
akantu
::
Real
*
stress
=
model
->
getMaterial
(
0
).
getStress
(
akantu
::
_triangle_1
).
values
;
for
(
akantu
::
UInt
i
=
0
;
i
<
nb_element
;
++
i
)
{
if
(
max_stress
<
stress
[
i
*
spatial_dimension
*
spatial_dimension
])
{
max_stress
=
stress
[
i
*
spatial_dimension
*
spatial_dimension
];
max_el
=
i
;
}
}
akantu
::
Real
*
coord
=
model
->
getFEM
().
getMesh
().
getNodes
().
values
;
akantu
::
Real
*
disp_val
=
model
->
getDisplacement
().
values
;
akantu
::
UInt
*
conn
=
model
->
getFEM
().
getMesh
().
getConnectivity
(
akantu
::
_triangle_1
).
values
;
akantu
::
UInt
nb_nodes_per_element
=
model
->
getFEM
().
getMesh
().
getNbNodesPerElement
(
akantu
::
_triangle_1
);
akantu
::
Real
*
coords
=
new
akantu
::
Real
[
spatial_dimension
];
akantu
::
Real
min_x
=
std
::
numeric_limits
<
akantu
::
Real
>::
max
();
akantu
::
Real
max_x
=
std
::
numeric_limits
<
akantu
::
Real
>::
min
();
akantu
::
Real
stress_range
=
5e7
;
for
(
akantu
::
UInt
el
=
0
;
el
<
nb_element
;
++
el
)
{
if
(
stress
[
el
*
spatial_dimension
*
spatial_dimension
]
>
max_stress
-
stress_range
)
{
akantu
::
UInt
el_offset
=
el
*
nb_nodes_per_element
;
memset
(
coords
,
0
,
spatial_dimension
*
sizeof
(
akantu
::
Real
));
for
(
akantu
::
UInt
n
=
0
;
n
<
nb_nodes_per_element
;
++
n
)
{
for
(
akantu
::
UInt
i
=
0
;
i
<
spatial_dimension
;
++
i
)
{
akantu
::
UInt
node
=
conn
[
el_offset
+
n
]
*
spatial_dimension
;
coords
[
i
]
+=
(
coord
[
node
+
i
]
+
disp_val
[
node
+
i
])
/
((
akantu
::
Real
)
nb_nodes_per_element
);
}
}
min_x
=
min_x
<
coords
[
0
]
?
min_x
:
coords
[
0
];
max_x
=
max_x
>
coords
[
0
]
?
max_x
:
coords
[
0
];
}
}
outfile
<<
s
<<
" "
<<
.5
*
(
min_x
+
max_x
)
<<
" "
<<
min_x
<<
" "
<<
max_x
<<
" "
<<
max_x
-
min_x
<<
" "
<<
max_stress
<<
std
::
endl
;
delete
[]
coords
;
#endif
// CHECK_STRESS
#ifdef AKANTU_USE_IOHELPER
if
(
s
%
100
==
0
)
dumper
.
Dump
();
#endif
//AKANTU_USE_IOHELPER
if
(
s
%
10
==
0
)
std
::
cout
<<
"passing step "
<<
s
<<
"/"
<<
max_steps
<<
std
::
endl
;
}
#ifdef CHECK_STRESS
outfile
.
close
();
#endif
// CHECK_STRESS
return
EXIT_SUCCESS
;
}
Event Timeline
Log In to Comment