Problem in tutorial with new interaction Implementation

Asked by Diego Peinado Martín

Hello, first of all, thanks a lot to Steffen for the tutorial regarding coding new interactions. It contains a lot of information I've missed. As I copied everything from ElasticInteraction, I did also a ElasticInteractionGroup (that seems not neccesary, and other things probably wrong).
Nevertheless, I have the development code, so it has yet the HertzianInteraction yet. I compiled the code, and the problem is that when I try to run an example, I have the same error than with my own interaction:

File "two_particles.py", line 51, in <module>
    HertzianElasticPrms(
NameError: name 'HertzianElasticPrms' is not defined

So, the problem probably is how I do the calling. Probably is something so evident that I can not see it. The code in the script that calls the interaction is:

sim.createInteractionGroup(
   HertzianElasticPrms(
      name = "HertzSpheres",
      YoungE = 10000.0,
   nu = 0.3
   )
)

The name HertzianElasticPrms is what appears in the export function:

      boost::python::class_<HertzianElasticPrmsPy,boost::python::bases<InteractionPrmsPy> >(
        "HertzianElasticPrms",
        "Parameters for Hertzian elastic contact interactions.",
        boost::python::init<const std::string &, double, double>(
          (
            arg("name"),
            arg("E"),
     arg("nu")
          ),
          "@type name: string\n"
          "@kwarg name: Name assigned to this group of interactions.\n"
          "@type E: float\n"
          "@kwarg E: Young's modulus used for force calculation.\n"
          "@type nu: float\n"
          "@kwarg nu: poisson ratio used for force calculation.\n"
        )
      )
      .def(
        "getName",
        &HertzianElasticPrmsPy::getName,
        boost::python::return_value_policy<boost::python::copy_const_reference>()
      )
      ;
I've checked the Makefile to see if it's included in the libraries, and it is. So, I can not see where is the error.

Thanks in advance and best regards,

Question information

Language:
English Edit question
Status:
Solved
For:
ESyS-Particle Edit question
Assignee:
No assignee Edit question
Solved by:
Diego Peinado Martín
Solved:
Last query:
Last reply:
Revision history for this message
Dion Weatherley (d-weatherley) said :
#1

Hi Diego,

Did you try my suggestion from this question:
https://answers.launchpad.net/esys-particle/+question/84850
to start from scratch with the build? i.e.

1/ 'make uninstall'
2/ 'make distclean'
3/ rerun your configure command
4/ make
5/ make install

If the code compiles fine, then I suspect you are having problems during dynamic linking. This can happen sometimes when you have compiled and installed ESyS-Particle multiple times on the same machine.

Another way you can quickly check whether the new interaction has been linked correctly is to run python interactively, import esys.lsm, then type dir():

1/ python
2/ from esys.lsm import *
3/ dir()

If you see HertzianElasticPrms listed then everything should be fine. If it isn't listed then a re-build from scratch is recommended as a first step. If that still doesn't work, try installing ESyS-Particle in a different directory using the '--prefix' argument in configure. When you test the new installation, remember to update your PATH, LD_LIBRARY_PATH and PYTHONPATH to include the directories to your new installation.

Cheers,

Dion.

Revision history for this message
Diego Peinado Martín (diego-peinado) said :
#2

Thankyou Dion. I've finally found the error. The problem was a non clean previous uninstallation. I do not know why, but I had one installation of the Python libraries in /usr/lib/pyhon2.6/dist-packages, and the new ones are always pointing to /usr/local/lib/python2.6/dist-packages. So, when I uninstalled the whole code, only this last directory was emptied and deleted, but the former one was kept. I do not know when I did that, but the same error I have in two different computers, workstation at work and my laptop for playing around on weekends.

So, I would like to share this with other users because it has delayed me around one month (well, only the few time I can dedicate to Esys during one month).

Thanks to Dion and Steffen for helping me with the new interactions.