Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
robotran
mbsysc
Commits
a3f9ac52
Commit
a3f9ac52
authored
Aug 07, 2019
by
Louis Beauloye
Browse files
[Ctypes] Free memory + user all id
parent
e46af8d3
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
MBsysC/mbs_interface/MBsysPy/mbs_utilities.py
View file @
a3f9ac52
...
...
@@ -23,6 +23,11 @@ def set_output(var , file_name):
file_name_c
=
file_name
.
encode
(
'utf-8'
)
libutilities
.
set_output
(
var
,
file_name_c
)
def
callback_undefined
(
function_name
=
None
):
print
(
"undefined functions: "
+
function_name
)
return
MBsysC/mbs_interface/MBsysPy/mbsyspy/mbs_data.py
View file @
a3f9ac52
This diff is collapsed.
Click to expand it.
MBsysC/mbs_interface/MBsysPy/mbsyspy/mbs_dirdyn.py
View file @
a3f9ac52
This diff is collapsed.
Click to expand it.
MBsysC/mbs_interface/MBsysPy/mbsyspy/mbs_part.py
View file @
a3f9ac52
...
...
@@ -26,6 +26,9 @@ import numpy as np
# importing libraries
from
..mbsysc_loader.loadlibs
import
libmodules
# importing utilities function
from
..mbs_utilities
import
callback_undefined
# importing wrapping function
from
..mbsysc_loader.callback
import
user_cons_hJ_wrap
...
...
@@ -35,7 +38,7 @@ from ..mbsysc_loader.callback import mbs_cons_hJ_wrap
#==============================================================================
# Global parameter of the current module
#==============================================================================
__DEBUG__
=
Tru
e
__DEBUG__
=
Fals
e
__MODULE_DIR__
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
...
...
@@ -44,7 +47,25 @@ __MODULE_DIR__ = os.path.dirname(os.path.abspath(__file__))
#==============================================================================
class
MbsPart
(
object
):
"""
Class of the coordinate partitioning module
Attributes
----------
n_qu : int
Number of independent variable needed.
n_qv: int
Number of dependent variable needed.
n_hu : int
Number of independent constraint.
n_hv : int
Number of redundant constraint
q_closed : ndarray
Array with the generalized coordinate in closed configuration
(constraints solved)
"""
def
__init__
(
self
,
mbs
,
user_path
=
None
,
symbolic_path
=
None
):
if
__DEBUG__
:
print
(
"DEBUG>> Creating MbsPart struct for "
+
mbs
.
mbs_name
+
"' MBS."
)
self
.
mbs_part_ptr
=
libmodules
.
mbs_new_part
(
mbs
.
mbs_data_ptr
)
...
...
@@ -78,9 +99,7 @@ class MbsPart(object):
# pointers list to avoid garbage collecting
self
.
ptrs_to_user_fcts
=
dict
()
# [0]: user_cons_hJ
self
.
ptrs_to_symb_fcts
=
dict
()
# [1]: mbs_cons_hJ
# Storing project function pointer
self
.
user_cons_hJ
=
None
...
...
@@ -109,7 +128,7 @@ class MbsPart(object):
Load the user functions in which some of the arguments are
dependent of MbsPart module instance. The functions will be
assigned to the MbsData instance when the 'run' function
s
is called
assigned to the MbsData instance when the 'run' function is called
and unassigned at the end.
The loader user functions are :
...
...
@@ -125,7 +144,6 @@ class MbsPart(object):
path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
template_path
,
user_file
))
module
=
imp
.
load_source
(
user_file
[:
-
3
],
path
)
self
.
user_cons_hJ
=
module
.
user_cons_hJ
self
.
ptrs_to_user_fcts
[
"user_cons_hJ"
]
=
user_cons_hJ_wrap
(
lambda
h
,
Jac
,
mbs
,
tsim
:
self
.
__callback_user_cons_hJ
(
self
.
user_cons_hJ
,
h
,
Jac
,
tsim
))
return
def
__load_symbolic_fct__
(
self
,
symbolic_path
):
...
...
@@ -134,7 +152,7 @@ class MbsPart(object):
Load the symb functions in which some of the arguments are
dependent of MbsPart module instance. The functions will be
assigned to the MbsData instance when the 'run' function
s
is called
assigned to the MbsData instance when the 'run' function is called
and unassigned at the end.
The loader user functions are :
...
...
@@ -151,7 +169,27 @@ class MbsPart(object):
path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
template_path
,
symb_file
))
module
=
imp
.
load_source
(
symb_file
[:
-
3
],
path
)
self
.
mbs_cons_hJ
=
module
.
cons_hJ
return
def
__assign_user_fct__
(
self
):
"""
Assign user function where some args depend on MbsPart module.
"""
self
.
ptrs_to_user_fcts
[
"user_cons_hJ"
]
=
user_cons_hJ_wrap
(
lambda
h
,
Jac
,
mbs
,
tsim
:
self
.
__callback_user_cons_hJ
(
self
.
user_cons_hJ
,
h
,
Jac
,
tsim
))
self
.
mbs
.
user_cons_hJ
=
self
.
user_cons_hJ
self
.
mbs
.
mbs_data_ptr
.
contents
.
user_cons_hJ
=
self
.
ptrs_to_user_fcts
[
"user_cons_hJ"
]
return
def
__assign_symbolic_fct__
(
self
):
"""
Assign symbolic function where some args depend on MbsPart module.
"""
self
.
ptrs_to_symb_fcts
[
"mbs_cons_hJ"
]
=
mbs_cons_hJ_wrap
(
lambda
h
,
Jac
,
mbs
,
tsim
:
self
.
__callback_mbs_cons_hJ
(
self
.
mbs_cons_hJ
,
h
,
Jac
))
self
.
mbs
.
mbs_cons_hJ
=
self
.
mbs_cons_hJ
self
.
mbs
.
mbs_data_ptr
.
contents
.
mbs_cons_hJ
=
self
.
ptrs_to_symb_fcts
[
"mbs_cons_hJ"
]
return
# Callback function for function with advanced arguments
...
...
@@ -165,22 +203,51 @@ class MbsPart(object):
__h
=
np
.
ctypeslib
.
as_array
(
h
,
(
self
.
mbs
.
Ncons
+
1
,))
__Jac
=
np
.
ctypeslib
.
as_array
(
Jac
[
0
],
(
self
.
mbs
.
Ncons
+
1
,
self
.
mbs
.
njoint
+
1
))
fun
(
__h
,
__Jac
,
self
.
mbs
)
def
__del__
(
self
):
libmodules
.
mbs_delete_part
(
self
.
mbs_part_ptr
)
if
__DEBUG__
:
print
(
"DEBUG>> MbsPart pointer deleted"
)
def
__unassign_user_fct__
(
self
):
"""
Unassign user function where some args depend on MbsPart module.
"""
self
.
ptrs_to_user_fcts
=
{}
self
.
mbs
.
user_cons_hJ
=
None
self
.
mbs
.
mbs_data_ptr
.
contents
.
user_cons_hJ
=
user_cons_hJ_wrap
(
lambda
h
,
Jac
,
mbs
,
tsim
:
callback_undefined
(
"user_cons_hJ"
))
return
def
__unassign_symbolic_fct__
(
self
):
"""
Unassign symbolic function where some args depend on MbsPart module.
"""
self
.
ptrs_to_symb_fcts
=
{}
self
.
mbs
.
mbs_cons_hJ
=
None
self
.
mbs
.
mbs_data_ptr
.
contents
.
mbs_cons_hJ
=
mbs_cons_hJ_wrap
(
lambda
h
,
Jac
,
mbs
,
tsim
:
callback_undefined
(
"mbs_cons_hJ"
))
return
def
run
(
self
):
# Assing required user functions
self
.
mbs
.
user_cons_hJ
=
self
.
user_cons_hJ
self
.
mbs
.
mbs_data_ptr
.
contents
.
user_cons_hJ
=
self
.
ptrs_to_user_fcts
[
"user_cons_hJ"
]
self
.
__assign_user_fct__
()
self
.
mbs
.
__assign_user_fct__
()
# Assing required symbolic functions
self
.
mbs
.
mbs_cons_hJ
=
self
.
mbs_cons_hJ
self
.
mbs
.
mbs_data_ptr
.
contents
.
mbs_cons_hJ
=
self
.
ptrs_to_symb_fcts
[
"mbs_cons_hJ"
]
self
.
__assign_symbolic_fct__
()
self
.
mbs
.
__assign_symb_fct__
()
libmodules
.
mbs_run_part
(
self
.
mbs_part_ptr
,
self
.
mbs
.
mbs_data_ptr
)
# Anassign functions
self
.
mbs
.
user_cons_hJ
=
None
self
.
mbs
.
mbs_data_ptr
.
contents
.
user_cons_hJ
=
user_cons_hJ_wrap
(
lambda
h
,
Jac
,
mbs
,
tsim
:
self
.
mbs
.
callback_undefined
(
"user_cons_hJ"
))
# Anassing required symbolic functions
self
.
mbs
.
mbs_cons_hJ
=
None
self
.
mbs
.
mbs_data_ptr
.
contents
.
mbs_cons_hJ
=
mbs_cons_hJ_wrap
(
lambda
h
,
Jac
,
mbs
,
tsim
:
self
.
mbs
.
callback_undefined
(
"mbs_cons_hJ"
))
# Unassign functions
self
.
__unassign_user_fct__
()
self
.
mbs
.
__unassign_user_fct__
()
# Unassign required symbolic functions
self
.
__unassign_symbolic_fct__
()
self
.
mbs
.
__unassign_symb_fct__
()
def
set_options
(
self
,
**
kwargs
):
"""
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment