User defined spring law?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

User defined spring law?

willstring
Hello! I was just wondering if there was any way to write a user-defined function for the spring law in Gran00?  I’ve converted all of the element pairs to springs using ConvertElementPairToSpring which works great for standard linear springs, but ideally I'd like to implement a piecewise (e.g. trapezoidal) spring law.

Thank you!
Reply | Threaded
Open this post in threaded view
|

Re: User defined spring law?

Damien André
Administrator
Of course, you can! But you must write it in C++. I will show you the main steps.

Creating a new bond named "CustomSpring"

First, go to "granoo/Lib/GranOO/DEM/Bond" and copy the files "Spring.hpp" and "Spring.cpp" and rename them by "CustomSpring.hpp" and "CustomSpring.cpp"

Edit these files and replace all the occurences of "Spring" by "CustomSpring".

Edit the "CustomSpring.cpp", go to the "Process()" method and do-want-you-want here

Creating a plugIn that convert elementpair in "CustomSping"

go to "granoo/Lib/GranOO/PlugIn/" and copy the files "ConvertElementPairToSpring.hpp" and "ConvertElementPairToSpring.cpp" and rename them by "ConvertElementPairToCustomSpring.hpp" and "ConvertElementPairToCustomSpring.hpp"

Again, Edit these files and replace all the occurences of "Spring" by "CustomSpring".

Now, don'f forget to recompile granoo
Reply | Threaded
Open this post in threaded view
|

Re: User defined spring law?

willstring
Thank you!

I should also be able to just edit Spring.cpp directly right AND recompile granoo?

As a first shot I tried just zeroing out the spring forces entirely (see bold lines below) to make sure it does something.  However I get the same result as before and the springs are still creating a nonzero force!  That is, the spring forces don't get zero'd out and follow the stiffness that I input

      // we add the asymetric option
      if (Spring::GetCurrentElongation() >= 0.)
        Fe *= attractiveCoeff_;
      else
        Fe *= repulsiveCoeff_;
      Fe=Fe*0;
      Fa=Fa*0;

      Physic::ParticleInteraction::forceOn1_ =  (Fe+Fa);
      Physic::ParticleInteraction::forceOn2_ = (-Fe-Fa);

It appears to be recompiling granoo correctly, it always reaches 100% but takes some time.  I also tried adding & removing an intentional error in Spring.cpp and the compiler catches it, to check that it is actually compiling the file I edited.  I also tried running 'make clean' but still no luck.

Am I missing something here?  Do I need to purge the installation somehow...?





Reply | Threaded
Open this post in threaded view
|

Re: User defined spring law?

willstring
OK nevermind the last message, I tried your way by creating the CustomSpring files and recompiling which makes it to 100% (see screenshot).

However now when I try to run my input file it says:

An error occured while reading the <PlugIn> element with raw text :
'<PlugIn Id="_ConvertElementPairToCustomSpring" Stiffness=".3000000" RestitutionCoeff="0.500000" />'
The plugIn '_ConvertElementPairToCustomSpring does not exist




Any ideas here??



Reply | Threaded
Open this post in threaded view
|

Re: User defined spring law?

Damien André
Administrator
Hello, you must also recompile all the executables that you use

Hope this help, Damien
Reply | Threaded
Open this post in threaded view
|

Re: User defined spring law?

willstring
Hello!  Thank you again for the help.

I had tried also recompiling the project executables as well, first clearing out the build directory, with no luck. Is it possible that the project executables are for some reason pointing to an old granoo executable?

At this point it could be worth just re-installing... but how to cleanly purge and remove the old installation first?

See attached log:

root@jupiter8:/home/will/g/018/build# rm -rf *
root@jupiter8:/home/will/g/018/build# ls
root@jupiter8:/home/will/g/018/build# cmake ../
-- The C compiler identification is GNU 9.3.0
m-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake (found suitable version "1.71.0", minimum required is "1.53.0") found components: chrono program_options serialization regex system filesystem iostreams thread
-- The imported target "vtkHashSource" references the file
   "/usr/bin/vtkHashSource-6.3"
but this file does not exist.  Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
   "/usr/lib/cmake/vtk-6.3/VTKTargets.cmake"
but not all the files it references.

-- The imported target "vtkParseOGLExt" references the file
   "/usr/bin/vtkParseOGLExt-6.3"
but this file does not exist.  Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
   "/usr/lib/cmake/vtk-6.3/VTKTargets.cmake"
but not all the files it references.

-- The imported target "vtkEncodeString" references the file
   "/usr/bin/vtkEncodeString-6.3"
but this file does not exist.  Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
   "/usr/lib/cmake/vtk-6.3/VTKTargets.cmake"
but not all the files it references.

-- The imported target "vtkGUISupportQt" references the file
   "/usr/lib/x86_64-linux-gnu/libvtkGUISupportQt-6.3.so.6.3.0"
but this file does not exist.  Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
   "/usr/lib/cmake/vtk-6.3/VTKTargets.cmake"
but not all the files it references.

-- The imported target "vtkGUISupportQtOpenGL" references the file
   "/usr/lib/x86_64-linux-gnu/libvtkGUISupportQtOpenGL-6.3.so.6.3.0"
but this file does not exist.  Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
   "/usr/lib/cmake/vtk-6.3/VTKTargets.cmake"
but not all the files it references.

-- The imported target "vtkGUISupportQtSQL" references the file
   "/usr/lib/x86_64-linux-gnu/libvtkGUISupportQtSQL-6.3.so.6.3.0"
but this file does not exist.  Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
   "/usr/lib/cmake/vtk-6.3/VTKTargets.cmake"
but not all the files it references.

-- The imported target "vtkViewsQt" references the file
   "/usr/lib/x86_64-linux-gnu/libvtkViewsQt-6.3.so.6.3.0"
but this file does not exist.  Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
   "/usr/lib/cmake/vtk-6.3/VTKTargets.cmake"
but not all the files it references.

-- The imported target "vtkGUISupportQtWebkit" references the file
   "/usr/lib/x86_64-linux-gnu/libvtkGUISupportQtWebkit-6.3.so.6.3.0"
but this file does not exist.  Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
   "/usr/lib/cmake/vtk-6.3/VTKTargets.cmake"
but not all the files it references.

-- The imported target "vtkRenderingQt" references the file
   "/usr/lib/x86_64-linux-gnu/libvtkRenderingQt-6.3.so.6.3.0"
but this file does not exist.  Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
   "/usr/lib/cmake/vtk-6.3/VTKTargets.cmake"
but not all the files it references.

-- Found GranOO: libGranOO.a (found suitable version "2.0.0", minimum required is "2.0")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/will/g/018/build


root@jupiter8:/home/will/g/018/build# make
Scanning dependencies of target vacuum.exe
[ 25%] Building CXX object CMakeFiles/vacuum.exe.dir/Main.cpp.o
[ 50%] Building CXX object CMakeFiles/vacuum.exe.dir/PlugIn_BuildDomain.cpp.o
/home/will/g/018/PlugIn_BuildDomain.cpp: In member function ‘virtual void PlugIn_BuildDomain::Run()’:
/home/will/g/018/PlugIn_BuildDomain.cpp:92:21: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
   92 |  char * directory = "/home/will/g/";
      |                     ^~~~~~~~~~~~~~~
/home/will/g/018/PlugIn_BuildDomain.cpp:162:30: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]
  162 |   for (unsigned int i = 0; i < npoints; ++i)
      |                            ~~^~~~~~~~~
/home/will/g/018/PlugIn_BuildDomain.cpp:216:25: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]
  216 |  for (unsigned int i=0;i<npoints;i++)
      |                        ~^~~~~~~~
/home/will/g/018/PlugIn_BuildDomain.cpp:85:16: warning: unused variable ‘step’ [-Wunused-variable]
   85 |   const double step = length_/double(number_ - 1);
      |                ^~~~
[ 75%] Building CXX object CMakeFiles/vacuum.exe.dir/PlugIn_InitSensor.cpp.o
[100%] Linking CXX executable vacuum.exe
[100%] Built target vacuum.exe
root@jupiter8:/home/will/g/018/build# cd ..
root@jupiter8:/home/will/g/018# ./build/vacuum.exe input001.inp
                               
  \    /_ | _ _ ._ _  _  _|_ _
   \/\/(/_|(_(_)| | |(/_  |_(_)
                               
  _|_|_|                          _|_|    _|_|  
_|      _|  _|_|    _|_|_|  _|_|_|   _|    _|  _|   _|
_|  _|_|  _|_|    _|  _|  _|    _| _|    _|  _|   _|
_|    _|  _|      _|  _|  _|    _| _|    _|  _|   _|
  _|_|_|  _|        _|_|_|  _|    _|  _|_|    _|_|  

Version 2.0.0
GranOO is a Discrete Element Method workbench.
Copyright (C) 2011-2017 JLC, DA, JG, CH and IO.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.
For details about the license see http://www.gnu.org/licenses/.
Enjoy !


[INIT] Starting to read the input file
[INIT][...]
Now reading '/home/will/g/018/input001.inp'
Now reading <GranOO> in input file "input001.inp", version = 2.0
[INIT][Reading GranOO...]
InputFile       : /home/will/g/018/input001.inp
OutputDirectory : Results_001
TotIteration    : 16000
TotTime         : 0.000000e+00
TimeStep        : 2.500000e-05
ThreadNumber    : 1
[INIT][Reading PreProcessing...]
Found PlugIn 'BuildDomain'
[INIT][Reading PreProcessing...]
[ERROR]
####################################################
# An error was encountered ! The program must stop #
####################################################
You have to fix this problem, you may browse the source files to get more informations...
line      : 129
in file   : /home/will/granoo/tags/2.0/Lib/GranOO/libUtil/PlugInManager.cpp
condition : 'PlugIn::Exist(Id, 0)'
======================
-- Attached message --
======================
Problem while reading 'input001.inp' file.
An error occured while reading the <PlugIn> element with raw text :
'<PlugIn Id="_ConvertElementPairToCustomSpring" Stiffness=".3000000" RestitutionCoeff="0.500000" />'
The plugIn '_ConvertElementPairToCustomSpring does not exist
==> You must fix your 'input001.inp' file <==
vacuum.exe: /home/will/granoo/tags/2.0/Lib/GranOO/libUtil/Macro.cpp:65: static void GranOO::Util::AssertMsg::RaiseUserAssertion(int, const string&, const string&, const string&): Assertion `0' failed.
Aborted (core dumped)
root@jupiter8:/home/will/g/018#


Reply | Threaded
Open this post in threaded view
|

Re: User defined spring law?

willstring
In reply to this post by willstring
NEVERMIND FIXED IT!!

Thanks for the help-- just re-installed granoo.  
Reply | Threaded
Open this post in threaded view
|

Re: User defined spring law?

Damien André
Administrator
GOOD ! ^^'