File: ForceTorqueRecorder.cpp

package info (click to toggle)
yade 2026.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,448 kB
  • sloc: cpp: 97,645; python: 52,173; sh: 677; makefile: 162
file content (44 lines) | stat: -rw-r--r-- 1,128 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "ForceTorqueRecorder.hpp"

namespace yade { // Cannot have #include directive inside.

YADE_PLUGIN((ForceRecorder)(TorqueRecorder));

CREATE_LOGGER(ForceRecorder);
void ForceRecorder::action()
{
	totalForce = Vector3r::Zero();
	FOREACH(Body::id_t id, ids)
	{
		if (!(scene->bodies->exists(id))) continue;
		totalForce += scene->forces.getForce(id);
	};

	//Save data to a file
	out << scene->iter << " " << totalForce[0] << " " << totalForce[1] << " " << totalForce[2] << " " << totalForce.norm() << "\n";
	out.close();
}

CREATE_LOGGER(TorqueRecorder);
void TorqueRecorder::action()
{
	totalTorque      = 0;
	Vector3r tmpAxis = rotationAxis.normalized();

	FOREACH(Body::id_t id, ids)
	{
		if (!(scene->bodies->exists(id))) continue;
		Body* b = Body::byId(id, scene).get();

		Vector3r tmpPos       = b->state->pos;
		Vector3r radiusVector = tmpAxis.cross(tmpAxis.cross(tmpPos - zeroPoint));

		totalTorque += tmpAxis.dot(scene->forces.getTorque(id) + radiusVector.cross(scene->forces.getForce(id)));
	};

	//Save data to a file
	out << scene->iter << " " << totalTorque << "\n";
	out.close();
}

} // namespace yade