ChElementSpring visualization

35 views
Skip to first unread message

Fran Bottero

unread,
Jun 6, 2022, 7:28:01 AM6/6/22
to ProjectChrono

Hi there!


I am trying to visualise spring elements (ChElementSpring) on irrlicht app, but it has been quite impossible for me. I found some examples and I could replicate them and visualise some links as springs (ChLinkTSDA), but it is not what I need because this kind of links need two bodies to be created, and that is so inefficient for my model.

I was looking for a way to visualise the spring created between two nodes, my system is currently working. For simple models is possible to understand what is happening just with the representation of the nodes as dots, but if I want to make it more complex, will be so much easier to comprehend if I can see the springs on the irrlicht app.

On my script, first of all, I create some nodes and elements:


// Upper:
auto nodeA = chrono_types::make_shared<ChNodeFEAxyz>(ChVector<>(0, Ly, 0));
nodeA->SetMass(m);
mesh->AddNode(nodeA);

// Right:
auto nodeB = chrono_types::make_shared<ChNodeFEAxyz>(ChVector<>(Lx, 0, 0));
nodeB->SetMass(m);
mesh->AddNode(nodeB);

(…)

// Upper-Right
auto springAB = chrono_types::make_shared<ChElementSpring>();
springAB->SetNodes(nodeA, nodeB);
springAB->SetSpringK(K);
springAB->SetDamperR(0);
mesh->AddElement(springAB);


Then I represent the nodes as dots, as you can see in the following code:


auto visGlyph = chrono_types::make_shared<ChVisualizationFEAmesh>(*(mesh.get()));

visGlyph->SetFEMglyphType(ChVisualizationFEAmesh::E_GLYPH_NODE_DOT_POS);
visGlyph->SetFEMdataType(ChVisualizationFEAmesh::E_PLOT_NONE);
visGlyph->SetSymbolsThickness(0.02);
mesh->AddAsset(visGlyph);

 

I also tried to represent the springs, as I did it before for other kind of elements (for example with ChBeamEulerAdvance) but I do not know how to configurate them. Is there any option or function to do it? I do not need something complex, with a simple line is enough.


Thanks!

Fran

Radu Serban

unread,
Jun 6, 2022, 7:43:02 AM6/6/22
to ProjectChrono

Hi Fran,

 

If rendering a line between the two nodes is good enough, you can simply call the function drawSegment() within your simulation loop (before the call to EndScene) and pass it the locations of the two nodes you want connected.
As an example, look at demo_IRR_gears.

 

--Radu

--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/e5a30dc1-37ed-4d2e-b0e9-607c9186279fn%40googlegroups.com.

Radu Serban

unread,
Jun 7, 2022, 4:30:43 AM6/7/22
to ProjectChrono

Fran,

 

Not with the current Chrono code.

But why not do something like:

 

std::vector<std::shared_ptr<ChElementSpring>> springs;

 

// Create spring elements, add to mesh, add to list

auto spring1 = chrono_types::make_shared<ChElementSpring>();

spring1->SetNodes(nodeA, nodeB);

mesh->AddElement(spring1);

springs.push_back(spring1);

 

auto spring2 = …

springs.push_back(spring2);

 

// Simulation loop

while(…) {

    for (const auto& s : spring) {

    tools::drawSegment(vis.get(), s->GetNode(0)->GetPos(), s->GetNode(1)->GetPos());

    }

}

 

--Radu

 

P.S. Please continue conversations on the user mailing list. Thanks

 

From: Fran Bottero <franb...@gmail.com>
Sent: Tuesday, June 7, 2022 10:12 AM
To: Radu Serban <ser...@wisc.edu>
Subject: Mensaje privado sobre: [chrono] ChElementSpring visualization

 

Great,

 

Yes its good  enough and it's working, just one more question, as I have to join several number of nodes following an predefined order (that I indicated when I create the springs), is it possible to do it outside the while loop (for example, adding another propertie to the  ChElementSpring)?

 

Thanks,

 

Fran

Fran Bottero

unread,
Jun 7, 2022, 7:44:26 AM6/7/22
to ProjectChrono
Radu,

Yes, I tried to do something similar. ChElementSpring has the function GetNodeN(int n), but this returns a ChNodeFEAbase (I don't know why is programmed like that, because to create the spring you need two ChNodeFEAxyz), and here it is not implemented the function GetPos() or GetX0() as in other kind of nodes types.

I tried also creating a vector of nodes but its not an option becouse of the order that they follow, the right solution would be similar to what you said before, I need to extract the  nodes from the element, but I am not able to programate it.

Thanks,

Fran

Radu Serban

unread,
Jun 7, 2022, 8:10:14 AM6/7/22
to ProjectChrono

Fran,

 

Indeed. 
GetNodeN must return a ChNodeFEAbase because it is a virtual method of the base class ChElementBase.

 

You need to cast the nodes to the proper type to get their positions.  Something like:

    for (const auto& s : spring) {

        tools::drawSegment(vis.get(),

                                             std::static_pointer_cast<ChNodeFEAxyz>(s->GetNode(0))->GetPos(),

                                             std::static_pointer_cast<ChNodeFEAxyz>(s->GetNode(1))->GetPos());

Fran Bottero

unread,
Jun 7, 2022, 8:23:56 AM6/7/22
to ProjectChrono
Perfect,

I was trying to do a static_cast, I didn't know that it was possible to do a static_pointer_cast. Now its working correctly.

Thank you very much Radu,
Reply all
Reply to author
Forward
0 new messages