Welcome
Guest
Forum Home
Login
Register
PhreeqcUsers Discussion Forum
»
Beginners
»
Installation questions
»
phreeqc_rm fails when a cocnentraiton vector is given as a pointer
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: phreeqc_rm fails when a cocnentraiton vector is given as a pointer (Read 2439 times)
oatteia
Top Contributor
Posts: 32
phreeqc_rm fails when a cocnentraiton vector is given as a pointer
«
on:
09/11/20 10:53 »
Hello,
I am using wsl for windows, so linux, installation of phreeqc_rm was ok and the acess to the library is ok too
I am trying to couple phreeqc-rm with openfoam (also c++), my main routine is the openfoam one which will make the transport step.
I first start by creating the phreeqc_rm as an object of the my_data class with an init function, this work and I can have access to it, whether from the main function as my_data->phreeqcrm_ptr or the same in a basic_callback.
I tried to make a runCells and GetConcentrations (or Set) inside the init function it works
However I tested weveral things which did not work with the same error : a segmentation fault
- I create a vector c in my main function and sent it as an argument to the init
- I create a vector c in my main function and use my_data->phreeqcrm_ptr->GetConcentrations
- I create the same vector, build a pointer that refers to this vector and use in init a reference to *c
- I create the same vector, build a pointer that refers to this vector and use it in a basic_callaback
said in other words it seems that for concentraiotn swhen the vector is not created at the same place as the build of phreeqc_rm it sends a segmentation fault
sincerely
Olivier
Logged
dlparkhurst
Global Moderator
Posts: 3935
Re: phreeqc_rm fails when a cocnentraiton vector is given as a pointer
«
Reply #1 on:
09/11/20 15:41 »
Sorry, it is difficult to debug your program remotely.
The example advection_cpp.cpp in the Tests directory uses most of the relevant methods of PhreeqcRM. Try to follow the outline of this program as closely as possible. If the tests ran successfully during the compilation process, this program will work correctly. I would start by getting it to run with your environment and Makefile.
PhreeqcRM has parallelization built in, which means that there are several IPhreeqc instances, either in the same process (OpenMP), or distributed among processes (MPI). You should start by using only one worker process with OpenMP, to avoid some of the complications of parallelization.
If you can make a very simple example of your problem, I will take a look, although I have limited access to Linux these days.
«
Last Edit: 09/11/20 16:05 by dlparkhurst
»
Logged
oatteia
Top Contributor
Posts: 32
Re: phreeqc_rm fails when a cocnentraiton vector is given as a pointer
«
Reply #2 on:
10/11/20 12:25 »
Hi,
thanks for your fast reply, I enclose an example made of two files (uses initChem.pqi and phreeqc.dat in the same folder). In order to communicate, I use a pointer to store concentration c in my_phrm (a my_data object). The ph_start() function works and I am able to retrieve the concentrations in main. In callback the my_phrm object works as it knows the database, nb of compounds.. but when trying to runCElls or gGet/SetConcentrations do not work, with segmentation fault
sincerely
Olivier
Logged
dlparkhurst
Global Moderator
Posts: 3935
Re: phreeqc_rm fails when a cocnentraiton vector is given as a pointer
«
Reply #3 on:
10/11/20 17:04 »
In the method start_ph, you have defined the object my_phrm as an automatic variable. Its scope is for the duration of the method start_ph; same with the way phreeqc_rm is defined.
Both my_phrm and phreeqc_rm need to be allocated with "new" to have them persist beyond the scope of start_ph.
Here is a quick hack of your program.
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
PhreeqcUsers Discussion Forum
»
Beginners
»
Installation questions
»
phreeqc_rm fails when a cocnentraiton vector is given as a pointer