Particle Body Force User Defined Libraries
A Contact Model UDL consists of a shared library file and, optionally, a file containing preferences. Using the EDEM API, you can write and compile custom particle body forces as a User Defined Library (UDL) written in C/C++.
- Create a directory in which you want to save the new Particle Body Force project.
-
Copy the following header files into the directory that you have created:
IPlug-inParticleBodyForce.hPlug-inParticleBodyForceCore.hIPlug-inParticleBodyForceV3_9_0.hPlug-inConstants.hHelpers.h
-
Create a new class (
CNewParticleBodyForce) derived from the Particle Body Force interface you want to use (for example,IPlug-inParticleBodyForceV3_9_0). -
Save the class declaration to a header file (for
example,
CNewParticleBodyForce.h). -
Implement all the methods defined in your header file and save as a
.cppfile (for example,CNewParticleBodyForce.cpp). -
Create a new
.cppfile with implementations of the methods inPlug-inParticleBodyForceCore.h. -
Save this file as
NewParticleBodyForce.cpp. -
Create a new
.cppfile with implementations of the methods inPlug-inParticleBodyForceCore.h. -
Save this file as
NewParticleBodyForce.cpp. -
Use command line or create a makefile (or equivalent) to build and compile
.dll(Windows) or.so(Linux) library files. -
Ensure that the library and optional preferences file are saved in the Plug-in
model folder (as specified in ), or in the same folder as the
simulation_name.demfile (only applicable for EDEM versions 2025.1 and higher). - Start EDEM and then select the required Particle Body Force Model category from the Interaction dropdown list in the Physics section.
-
Click the + dropdown list and then select the new
Particle Body Force Model .
The following methods are available in the Particle Body Force Model interface
IPlug-inParticleBodyForceV3_9_0:Method Description Type getPreferenceFileNameRetrieves the name of the config file used by the UDL. Setup setApiParametersTemplateAllows you to set up the plug-in parameter values. They can be modified from the UI. Setup setFilePathCalled inside the starting()method to provide the plug-in with the full simulation path (including the simulation file name).Setup getGpuFileNameInitializes the GPU plug-in by accepting the file name without an extension. If empty, the model will not be supported on the GPU solver. Setup getGpuSourceSizeYou must set the size of the chararray, which contains the CUDA source code. iflibraryProvidesGpuSourceis enabled.Setup getGpuSourceYou must set the chararray with the CUDA source code, iflibraryProvidesGpuSourceis enabled.Setup setupInitializes the plug-in by reading any config files, opening temporary files, generating data structures, or other setup tasks. Setup startingCalled once at the start of a simulation to indicate that processing is about to begin and the model should allocate any temporary storage and retrieve any required file/API/sockethandles.Simulation stoppingCalled once at the end of a simulation to indicate that processing is complete and the model should free any temporary storage and close/release file/api/sockethandles.Simulation externalForceUsed to add particle body forces (such as electromagnetic or drag forces) to particles. This function is called every single time step for every single particle. Simulation configForTimeStepCalled during processing, at the start of each Time Step. Not used for CUDA solvers, but must be implemented in the CUDA file. Simulation getNumberOfRequiredPropertiesReturns the number of custom properties this UDL wants to register with the system. Setup getDetailsForPropertyRetrieves details for a given property. These properties will then be registered with the system if they do not conflict with the existing properties. Setup getParticleParameterDataRetrieves particle parameter data in buffer format. Setup getSimulationParameterDataRetrieves simulation parameter data in buffer format. Setup setApiManagerCalled once during the loading of the API to set the apiManager.Setup processParticleOfInterestProcesses particles that were marked for additional processing in the externalForcecall. Particle modifications are not allowed.Simulation Note: The methods of type 'Setup' are called once at the start of the simulation, whereas, those of type 'Simulation' are called during the simulation. For more information about how the methods are called, see the Help included in the EDEM installation folder.