Question regarding namespace and shared pointers in pychrono

42 views
Skip to first unread message

André Marinho

unread,
Nov 10, 2021, 9:05:12 AM11/10/21
to ProjectChrono
Hello,

I made avaliable the class ChLoadXYZROTnodeXYZROTnodeBushingGeneric in a compiled python interface, but I am getting a type error when trying to instantiate it. The issue seems to come from the namespace difference between the type of the object and the type expected in the method signature in the module. The error is as follows:
_core.ChLoadXYZROTnodeXYZROTnodeBushingGeneric_swiginit(self, _core.new_ChLoadXYZROTnodeXYZROTnodeBushingGeneric(mnodeA, mnodeB, abs_application, mstiffness, mdamping))
TypeError: in method 'new_ChLoadXYZROTnodeXYZROTnodeBushingGeneric', argument 1 of type 'std::shared_ptr< fea::ChNodeFEAxyzrot >'
The flow for the code is as follows:
# Creates system and mesh
system = core.ChSystemSMC()
system.Set_G_acc(m_acc=core.VNULL)
mesh = fea.ChMesh()

# Creates nodes and adds them to mesh
node1 = fea.ChNodeFEAxyzrot(core.ChFrameD(core.ChVectorD(0., 0., 0.)))
node2 = fea.ChNodeFEAxyzrot(core.ChFrameD(core.ChVectorD(0., 0., 0.)))
node2.SetForce(core.ChVectorD(0., 5000., 0.))  # Force at node2 (y-direction)
mesh.AddNode(node1)
mesh.AddNode(node2)

system.Add(mesh)

# Creates fixed body
truss = core.ChBody()
truss.SetBodyFixed(True)
system.Add(truss)

# Links node to truss
linkA = core.ChLinkMateGeneric()
linkA.Initialize(node1, truss, False, node1.Frame(), truss.GetAssetsFrame())

system.Add(linkA)

# Creates load container for bushing load
load_container = core.ChLoadContainer()
system.Add(load_container)

# Stiffness and damping matrices
K_matrix = core.ChMatrixDynamicD(6, 6)
R_matrix = core.ChMatrixDynamicD(6, 6)

for i in range(6):
    K_matrix[i, i] = 1e5

for i in range(6):
    for j in range(6):
        R_matrix[i, j] = 1e-3

ch_bushing = core.ChLoadXYZROTnodeXYZROTnodeBushingGeneric(
    mnodeA=node1,
    mnodeB=node2,
    abs_application=core.ChFrameD(core.ChVectorD(0., 0., 0.)),
    mstiffness=K_matrix,
    mdamping=R_matrix)

load_container.Add(newload=ch_bushing)
The created nodes have the following value:
node1 = {ChNodeFEAxyzrot} <pychrono.fea.ChNodeFEAxyzrot; proxy of <Swig Object of type 'std::shared_ptr< chrono::fea::ChNodeFEAxyzrot > 
Bellow is the method signature taken from core.py module:
def __init__(self, mnodeA, mnodeB, abs_application, mstiffness, mdamping):
    r"""__init__(ChLoadXYZROTnodeXYZROTnodeBushingGeneric self, std::shared_ptr< fea::ChNodeFEAxyzrot > mnodeA, std::shared_ptr< fea::ChNodeFEAxyzrot > mnodeB, ChFrameD abs_application, chrono::ChMatrixConstRef mstiffness, chrono::ChMatrixConstRef mdamping) -> ChLoadXYZROTnodeXYZROTnodeBushingGeneric"""
    _core.ChLoadXYZROTnodeXYZROTnodeBushingGeneric_swiginit(self, _core.new_ChLoadXYZROTnodeXYZROTnodeBushingGeneric(mnodeA, mnodeB, abs_application, mstiffness, mdamping))
So the error seems to come from the difference in the signature of the Swig Object in the created node (std::shared_ptr< chrono::fea::ChMesh >>) and the one expected in the method (std::shared_ptr< fea::ChMesh >), but I don't know how to solve this namespace problem.

Thank you in advance.

André Marinho

ben...@wisc.edu

unread,
Nov 12, 2021, 12:37:48 PM11/12/21
to ProjectChrono
Hi Andre,
I wrapped the missing Loads. Please note that those are now under the fea namespace (since they use fea nodes) hence, to ue them, call:

ch_bushing = fea.ChLoadXYZROTnodeXYZROTnodeBushingGeneric(

Best,
Simon

André Marinho

unread,
Nov 15, 2021, 6:28:21 AM11/15/21
to ProjectChrono
Hi Simon,

Thank you for wrapping the missing load. I am alrealdy using it, and so far works as expected.

Best,

André
Reply all
Reply to author
Forward
0 new messages