LIGGGHTS 2.3.7, fix is in fix_mesh_surface_stress_servo.cpp

Submitted by AGl on Mon, 09/09/2013 - 14:34

Dear liggghts-developers,

the newly released 2.3.7 version of LIGGGHTS has the following changelog-entry:

> + Fixed a sign bug in fix mesh/surface/stress/servo.

as I understand, the fix is in src/fix_mesh_surface_stress_servo.cpp :

============================================
@@ -143,7 +143,7 @@
} else {
set_point_ = -force->numeric(arg[iarg_]); // the resultant force/torque/shear acts in opposite direction --> negative value
if (set_point_ == 0.) error->fix_error(FLERR,this,"'target_val' (desired force/torque) has to be != 0.0");
- set_point_inv_ = 1./set_point_;
+ set_point_inv_ = 1./abs(set_point_);
sp_style_ = CONSTANT;
}
iarg_++;
@@ -427,7 +427,7 @@ void FixMeshSurfaceStressServo::final_integrate()

set_point_ = -input->variable->compute_equal(sp_var_);
if (set_point_ == 0.) error->fix_error(FLERR,this,"Set point (desired force/torque/shear) has to be != 0.0");
- set_point_inv_ = 1./set_point_;
+ set_point_inv_ = 1./abs(set_point_);

============================================

I maybe wrong, but "abs-function" will convert the "set_point_"-variable from double to integer [1] and the float part of the value can be lost.

So, from my point of view, it should be "fabs" instead, which returns the variable of double-type [2].

[1] http://www.cplusplus.com/reference/cstdlib/abs/
[2] http://www.cplusplus.com/reference/cmath/fabs/

sbateman | Mon, 09/09/2013 - 17:30

The abs(int) function in cstdlib is only defined for integers. However, in your reference [1], there is a note at the top:
"In C++, this function is also overloaded in header for floating-point types (see cmath abs)"
and following that link shows an abs(double) convenience function (http://www.cplusplus.com/reference/cmath/abs/)

Plus, I don't get any warnings about the abs() double -> integer conversion when I compile. There are plenty of other warnings, but that's a separate issue. :)

aaigner's picture

aaigner | Mon, 09/09/2013 - 19:20

In school I have also learnt to use fabs(). That's why I thought that I had made a mistake.

Thank you, sbateman. You are right. abs() is overloaded for other data types. --> Everything is fine.
And yes.. there are plenty of warnings... :-)

cheers
Andi

AGl | Tue, 09/10/2013 - 08:51

You are right, but I do not see any explicit cmath include in the code (except only in surface_mesh.h, but it does not used in the discussed code.

PS Recently I had problems with abs, because it converted the variable into the integer.

aaigner's picture

aaigner | Tue, 09/10/2013 - 10:19

I discussed it with Christoph. And...

@AGI: You are right. There is no explicit cmath include, but the servo wall inherits it from surface_mesh.h. (surface_mesh.h -> tri_mesh.h -> fix_mesh_surface.h -> ...) That's why the code is working as desired at the moment.

Since the includes may change and I can not guarantee that the right abs()-function is used, I change it to fabs(). This change will be included in the next release.

Thanks for the hint and discussion.
Andi