Which files to compile in linux for particle replacement tutorial?

satri
satri Altair Community Member
edited April 16 in Community Q&A

Hello 

I am trying to run an edem simulation on linux i have an API of particle replacement tutorial to get a ".so" file

I tried to compile all files but i kept getting errors when I do this (I have made sure all the lines are in one line so that i can compile and generate a ".so" file)

g++ -g -std=c++11 -O2 -shared -fPIC

-I/DEM/altair/EDEM/src/Api/Factories/

-I/DEM/altair/EDEM/src/Api/ParticleBodyForce/

-I/DEM/altair/EDEM/src/Api/Core/

-I/DEM/altair/EDEM/src/Misc/

CCustomParticleBodyForce.h CParticleList.h CRemoval.cpp CRemoval.h CReplacementFactory.cpp CReplacementFactory.h Removal.cpp ReplacementFactory.cpp -o Project1.so

But when i do this i get the ".so" file


g++ -g -std=c++11 -O2 -shared -fPIC

-I/DEM/altair/EDEM/src/Api/Factories/

-I/DEM/altair/EDEM/src/Api/ParticleBodyForce/

-I/DEM/altair/EDEM/src/Api/Core/

-I/DEM/altair/EDEM/src/Misc/

Removal.cpp CRemoval.cpp -o Project1.so

But when i run the simulation this does not work. Note I do not have any problems in logic because the entire simulation runs without any problem in windows

Please tell me what is the mistake here and how do i know what files to compile in Linux because windows automatically takes care of all the files on visual studio 

Tagged:

Answers

  • Stephen Cole
    Stephen Cole
    Altair Employee
    edited April 4

    Hi Shyam,


    Are there any errors our outputs shown when compiling?  

    What happens when you run the simulation, are there any errors/outputs?


    Regards

    Stephen

  • satri
    satri Altair Community Member
    edited April 4

    I am not seeing any errors in compiling. I got the ".so" file but when i run the simulation it does not add meta particles. I thought i was not including any body force files while compiling. That's why i am asking this question.

  • Stephen Cole
    Stephen Cole
    Altair Employee
    edited April 4

    I am not seeing any errors in compiling. I got the ".so" file but when i run the simulation it does not add meta particles. I thought i was not including any body force files while compiling. That's why i am asking this question.

    Hi Shyam,

    Could you confirm the model has been loaded into the simulation, this should be in the Custom Factory and Particle Body Force areas?

    If you had an existing simulation with the models loaded and copy this to Linux it will run without any changes so long as the .dll and .so are named the same.  I notice in your script it's compiled as Project1.so, you may need to rename or reload this to EDEM if it hasn't been setup already.


    Regards

    Stephen

     

  • satri
    satri Altair Community Member
    edited April 4

    Hi Shyam,

    Could you confirm the model has been loaded into the simulation, this should be in the Custom Factory and Particle Body Force areas?

    If you had an existing simulation with the models loaded and copy this to Linux it will run without any changes so long as the .dll and .so are named the same.  I notice in your script it's compiled as Project1.so, you may need to rename or reload this to EDEM if it hasn't been setup already.


    Regards

    Stephen

     

    So that is the problem because when i compiled the cpp I followed method 2 and compiled only two cpp files whereas when i followed method 1 i kept getting errors.

    so Project1.so is not visible in Plugin Factory, its only visible in the Body Force section. So that's why i am asking if I am compiling the correct files in Linux or not?

    image

  • Stephen Cole
    Stephen Cole
    Altair Employee
    edited April 4

    So that is the problem because when i compiled the cpp I followed method 2 and compiled only two cpp files whereas when i followed method 1 i kept getting errors.

    so Project1.so is not visible in Plugin Factory, its only visible in the Body Force section. So that's why i am asking if I am compiling the correct files in Linux or not?

    image

    Hi Shyam,

     

    What were the errors in method 1, were these shown when compiling?  Method 2 doesn't include all the files you need, I would expect the missing GETFACTINTERFACEVERSION  is in "ReplacementFactory.cpp", but you would need to include all the files like you have in example 1 for it to be able to load.

     

    Regards

    Stephen

  • satri
    satri Altair Community Member
    edited April 4

    This is the error in method 1

    image

    I am loading the core file this error does not come up in Windows at all..So I am confused as to why this error pops up on Linux

  • satri
    satri Altair Community Member
    edited April 4

    I even included this file IPluginParticleBodyForceV3_4_0_.h and tried

    image

  • Stephen Cole
    Stephen Cole
    Altair Employee
    edited April 4

    I even included this file IPluginParticleBodyForceV3_4_0_.h and tried

    image

    Hi Shyam,

     

    It's not missing files as far as I can see but it's giving an error about the contents of the file, specifically the CCustomParticleBodyForce.h file.

    As to why Visual Studio on Windows doesn't give an error it's not easy to say, although the end product is the same, different compilers work in different ways.  This may be a warning on Windows but an error on Linux.

    What I suspect it is for the first case is that IGeometryManagerAPI is included in the header file but not used. VS is maybe clever enough to see that it isn't used and just ignore it but GCC sees it as an error.  What I'd recommend is searching for that geometry manager reference in the Body Force .h file, check if it's used or declared anywhere else and if it isn't just comment it out.

    Second error is about the configfortimestep function, it looks like this is used but it doesn't like the 'override' component.  I'd check if this is declared more than once in the code and/or check the formatting of this compared to other similar functions that don't give errors.

     

    Regards

    Stephen

  • satri
    satri Altair Community Member
    edited April 4

    Hello Stephen,

    So i got rid of the error and now it is getting stuck on a file which is existing. I have read the cpp documentation and am not sure why is this a problem in linux

    I have two different files that i am using as preference files to give two different coordinate chains but it keeps giving me an error saying particle cluster data not found. Please tell me why is this the case. It does not happen in Windows at all. I am using the same program

  • satri
    satri Altair Community Member
    edited April 4

    The program gets stuck on line 63.

    https://cplusplus.com/reference/fstream/ifstream/ifstream/

    I have followed the documentation and written the program.

    It is able to recognise the file in windows but not on linux why is that the case

    I even got rid of the if statement and tried to run it the simulation crashes in linux

    Please tell me what is going on i am not able to pin point why such a thing would occor

  • satri
    satri Altair Community Member
    edited April 5

    i even did doc2unix and converted the preferencefile to UNIX format. This is so absurd. Please tell me why this happens. I don't know how to  even comprehend where to look for a non-existent error.

  • satri
    satri Altair Community Member
    edited April 5

    Hey can anyone please tell me how to resolve this because I am not sure how to even start debugging this when the file is already present

  • Stephen Cole
    Stephen Cole
    Altair Employee
    edited April 5

    Hey can anyone please tell me how to resolve this because I am not sure how to even start debugging this when the file is already present

    Hi Shyam, Could you confirm what the issue is?  It's not clear to me from the message above what the setup is that you have and the error is.

    You mention it gets stuck on line 63, how did you confirm this?

     

    From my understanding if you load the .so file and the error message "Preference file 1 not found" is shown then it's clear the code is working 'as designed', that the library is compiled and that it's returning 'false' on line 65.  You could confirm/debug this by changing the error message string and recompiling to check it's entering that part of the code.

    That then helps determine the issue, you could try a different method to determine if the file exists. e.g.

    https://stackoverflow.com/questions/1647557/ifstream-how-to-tell-if-specified-file-doesnt-exist

    Or instead of passing the .txt file through getPreferenceFileName and then to setup you hard code this in.  Change  prefFile1 = PREFS_FILE1.c_str(); to   specially write in the path to the file on your machine. This isn't very good generally but helps with debugging to determine where the issue is.  If it reads the file by hard-coding in the file path then we know in which function the problem is.

     

    Regards

    Stephen

  • satri
    satri Altair Community Member
    edited April 5

    So I open EDEM in GUI mode for debugging purposes in Linux

    Now when i attach Project1 as a custom factory the very first message that pops up is "Preference file 1 not found" This message should not pop up in the first place in Linux because I already have the Preference_File in the same folder as that of the simulation.

    I do not get this message in Windows at all. That is what is bothering me, How come what works well for Windows does not work for Linux? Now i am doubting myself did i do any mistake in Windows?

    Why does this error pop up on Linux not on Windows? 

  • satri
    satri Altair Community Member
    edited April 8

    Hi Shyam, Could you confirm what the issue is?  It's not clear to me from the message above what the setup is that you have and the error is.

    You mention it gets stuck on line 63, how did you confirm this?

     

    From my understanding if you load the .so file and the error message "Preference file 1 not found" is shown then it's clear the code is working 'as designed', that the library is compiled and that it's returning 'false' on line 65.  You could confirm/debug this by changing the error message string and recompiling to check it's entering that part of the code.

    That then helps determine the issue, you could try a different method to determine if the file exists. e.g.

    https://stackoverflow.com/questions/1647557/ifstream-how-to-tell-if-specified-file-doesnt-exist

    Or instead of passing the .txt file through getPreferenceFileName and then to setup you hard code this in.  Change  prefFile1 = PREFS_FILE1.c_str(); to   specially write in the path to the file on your machine. This isn't very good generally but helps with debugging to determine where the issue is.  If it reads the file by hard-coding in the file path then we know in which function the problem is.

     

    Regards

    Stephen

    Hardcoding defeats the purpose of having a pref file.  

    Please tell me what is wrong in doing like this. I don't see any mistake from cpp perspective

  • satri
    satri Altair Community Member
    edited April 9

    Hi Shyam, Could you confirm what the issue is?  It's not clear to me from the message above what the setup is that you have and the error is.

    You mention it gets stuck on line 63, how did you confirm this?

     

    From my understanding if you load the .so file and the error message "Preference file 1 not found" is shown then it's clear the code is working 'as designed', that the library is compiled and that it's returning 'false' on line 65.  You could confirm/debug this by changing the error message string and recompiling to check it's entering that part of the code.

    That then helps determine the issue, you could try a different method to determine if the file exists. e.g.

    https://stackoverflow.com/questions/1647557/ifstream-how-to-tell-if-specified-file-doesnt-exist

    Or instead of passing the .txt file through getPreferenceFileName and then to setup you hard code this in.  Change  prefFile1 = PREFS_FILE1.c_str(); to   specially write in the path to the file on your machine. This isn't very good generally but helps with debugging to determine where the issue is.  If it reads the file by hard-coding in the file path then we know in which function the problem is.

     

    Regards

    Stephen

    Hello Stephen,

    Can you please tell me what is wrong with this way of doing?

    Why do i get errors in linux? because as far as logic and syntax go nothing is wrong with this

  • Stephen Cole
    Stephen Cole
    Altair Employee
    edited April 10

    Hello Stephen,

    Can you please tell me what is wrong with this way of doing?

    Why do i get errors in linux? because as far as logic and syntax go nothing is wrong with this

    Hi Shyam,

    If you are seeing that specific error message "Preference file 1 not found" then the code must be entering the following section:

    prefFile1 = PREFS_FILE1.c_str();     ifstream prefsFile(prefFile1);       if(!prefsFile) { string errorMessage = "Preference file 1 not found"; strncpy(customMsg, errorMessage.c_str(), NApi::FILE_PATH_MAX_LENGTH); return false; }

     

    It looks OK to me but the output strongly indicates there is an error somewhere with the file path, which requires some form of debugging.  You could follow the full debugging guide for Linux outlined here but that is typically better if only developing on Linux.  I'd recommend doing some simpler debugging steps such as:

    •  hard-coding the file path in - this should tell you if the path is passed to this part of the code correctly
    • you could replace the  "Preference file 2 not found"; message with prefFile1[] as a string so you can tell what is been interpreted
    • You could change the location of the simulation files to another folder to see if this is folder specific
      • Other things to check are file paths, are there any special characters in the file paths (folder you have the EDEM and pref .txt file in) that could be causing problems?

    Regarding the difference between windows and Linux just to confirm you are using identical code?  You mentioned above that there were problems compiling in Linux and changes were made, did you also apply those changes in the Windows version and confirm it also works on Windows with the changes?

    Regards

    Stephen

  • satri
    satri Altair Community Member
    edited April 15

    Hi Shyam,

    If you are seeing that specific error message "Preference file 1 not found" then the code must be entering the following section:

    prefFile1 = PREFS_FILE1.c_str();     ifstream prefsFile(prefFile1);       if(!prefsFile) { string errorMessage = "Preference file 1 not found"; strncpy(customMsg, errorMessage.c_str(), NApi::FILE_PATH_MAX_LENGTH); return false; }

     

    It looks OK to me but the output strongly indicates there is an error somewhere with the file path, which requires some form of debugging.  You could follow the full debugging guide for Linux outlined here but that is typically better if only developing on Linux.  I'd recommend doing some simpler debugging steps such as:

    •  hard-coding the file path in - this should tell you if the path is passed to this part of the code correctly
    • you could replace the  "Preference file 2 not found"; message with prefFile1[] as a string so you can tell what is been interpreted
    • You could change the location of the simulation files to another folder to see if this is folder specific
      • Other things to check are file paths, are there any special characters in the file paths (folder you have the EDEM and pref .txt file in) that could be causing problems?

    Regarding the difference between windows and Linux just to confirm you are using identical code?  You mentioned above that there were problems compiling in Linux and changes were made, did you also apply those changes in the Windows version and confirm it also works on Windows with the changes?

    Regards

    Stephen

    Hey so i hardcode the file path and now i am getting this error.

    image

    the source of this error is in this file and it has to do with the version

    image

    I have no idea how to fix this It has something to do with versions. 

    Please tell me how to fix this. I don't want to mess with the versions so i am asking you

    On a side note

    I believe the root of the problem is the APIs put up on this website were not tested for its working in Linux. It would be really helpful for users if you could please check its working on Linux systems not just Windows

     

  • Stephen Cole
    Stephen Cole
    Altair Employee
    edited April 15

    Hey so i hardcode the file path and now i am getting this error.

    image

    the source of this error is in this file and it has to do with the version

    image

    I have no idea how to fix this It has something to do with versions. 

    Please tell me how to fix this. I don't want to mess with the versions so i am asking you

    On a side note

    I believe the root of the problem is the APIs put up on this website were not tested for its working in Linux. It would be really helpful for users if you could please check its working on Linux systems not just Windows

     

    Hi Shyam,


    When you recompiled after hardcoding the path did you include ReplacementFactory.cpp in the files you compiled?  


    Regards

    Stephen

  • satri
    satri Altair Community Member
    edited April 15

    Hi Shyam,


    When you recompiled after hardcoding the path did you include ReplacementFactory.cpp in the files you compiled?  


    Regards

    Stephen

    Ok i see my mistake. I did not include that file. Now i am getting back the same error. Pref file 1 not found even if i hard code the path. I really do not want to hard code the values. it completely defeats the purpose of having two pref files.

    There is nothing wrong with the syntax and the file is present how is Windows able to resolve this and not linux. this is not good. having to waste time on something that is working 

  • satri
    satri Altair Community Member
    edited April 15

    Hi Shyam,


    When you recompiled after hardcoding the path did you include ReplacementFactory.cpp in the files you compiled?  


    Regards

    Stephen

    Even if hardcoding works that is not the solution to the problem. Because i will have to hardcode the values for all the simulations in linux in the future which i do not want to do. we need to fix the root of the problem not put a bandage.

  • satri
    satri Altair Community Member
    edited April 15

    Hi Shyam,


    When you recompiled after hardcoding the path did you include ReplacementFactory.cpp in the files you compiled?  


    Regards

    Stephen

    Also the debug tools do not work for setup. it will aid me to debug the simulation during the run. I don't know how that will help me to fix the setup issues

  • Stephen Cole
    Stephen Cole
    Altair Employee
    edited April 15

    Also the debug tools do not work for setup. it will aid me to debug the simulation during the run. I don't know how that will help me to fix the setup issues

    Hi Shyam,


    If you can upload the files, including test case for the preference files I'll take a look.

    Hardcoding the file does help with the debugging process, as now you have eliminated one source of error.

     

    Regards

    Stephen

  • satri
    satri Altair Community Member
    edited April 15

    Hi Shyam,


    If you can upload the files, including test case for the preference files I'll take a look.

    Hardcoding the file does help with the debugging process, as now you have eliminated one source of error.

     

    Regards

    Stephen

    i deleted those files and wanted to upload new files.

    its working when I hard-coded both paths. It was my mistake earlier that when i hardcoded only one path i was getting error saying the path 2 is not found. Based on that i concluded that this will keep happening for all the files in linux

    I had hardcoded only path 1 when i hard coded path 2 it works. but this is an interim fix.

    Imagine if i have 10 different file paths because i want fibers of different sizes i will have to hard code all the paths this will be a problem. is there a way to generalize the code?

  • Stephen Cole
    Stephen Cole
    Altair Employee
    edited April 16

    i deleted those files and wanted to upload new files.

    its working when I hard-coded both paths. It was my mistake earlier that when i hardcoded only one path i was getting error saying the path 2 is not found. Based on that i concluded that this will keep happening for all the files in linux

    I had hardcoded only path 1 when i hard coded path 2 it works. but this is an interim fix.

    Imagine if i have 10 different file paths because i want fibers of different sizes i will have to hard code all the paths this will be a problem. is there a way to generalize the code?

    Hi Shyam,

    I don't see the updated code but in the version you previously provided if I change to the default method I only get the error message about preference file 2.

    What looks to be happening is that you are reading 2 files.  EDEM gives you the file path and adds the file name to this path which gives us prefsFile1 as path + filename.  Here I just replaced the absolute path with the default method used in EDEM.

    bool CReplacementFactory::setup(NApiCore::IApiManager_1_0& apiManager,                            const char prefFile[],                            char customMsg[NApi::ERROR_MSG_MAX_LENGTH]) {  	ifstream prefsFile1(prefFile);  	if (!prefsFile1) 	{ 		string errorMessage = "Prefs file 1 not found"; 		strncpy(customMsg, errorMessage.c_str(), NApi::FILE_PATH_MAX_LENGTH); 		return false; 	} 	else 	{               ...         }

    However I see the "Preference file 2 not found" error which occurs with this code:

     

    	const string CReplacementFactory::PREFS_FILE2 = "Particle_Cluster_Data2.txt"; prefFile1 = PREFS_FILE2.c_str(); 	std::ifstream prefsFile2(prefFile1); 	 	if(prefsFile2.is_open()) 	{ ... 	} 	} 	else 		{ 		string errorMessage = "Preference file ###2 not found"; 		strncpy(customMsg, errorMessage.c_str(), NApi::FILE_PATH_MAX_LENGTH); 		return false; 	}

     

    What it looks like here is that you are overwriting the path and filename (prefFile1) with just the filename, so EDEM can't find the location of the file.

     

    I changed this in the attached code (line 97) 

    //first find path to prefs file 1 	std::string Path; 	string prefFile2 = prefFile; 	//find name of prefs file 1 	string::size_type idx = prefFile2.find(PREFS_FILE1); 	//delete name of prefs file 1 so we just have the path 	Path = prefFile2.substr(0, idx); 	//add name of prefs file 2 so we have full path + name 	prefFile2 = Path + PREFS_FILE2.c_str();  	std::ifstream prefsFile2(prefFile);  	if (!prefsFile2) 	{ 		string errorMessage = "Prefs file 2 not found"; 		strncpy(customMsg, errorMessage.c_str(), NApi::FILE_PATH_MAX_LENGTH); 		return false; 	} 	else 	{ ... }

     

    This then reads both files OK.  The example doesn't seem to create any particles (on windows or linux) however the files area read OK as far as I can see.


    Regards

    Stephen