PhreeqcUsers Discussion Forum

Conceptual Models => Incorporation PHREEQC in programming languages => Topic started by: Zhaoyang on August 18, 2021, 09:47:25 AM

Title: Compiling PhreeqcRM
Post by: Zhaoyang on August 18, 2021, 09:47:25 AM
Dear all,

I am a beginner working on coupling PhreeqcRM with a transport model. I met a problem when compiling PhreeqcRM. I can build ALL_BUILD and INSTALL successfully as indicated in README.TXT. However, an error occurred when building RUN_TESTS (see attached screenshot). Does anyone know how to slove this problem? Thanks in advance.

Best regards,
Zhaoyang Luo
Title: Re: Compiling PhreeqcRM
Post by: dlparkhurst on August 18, 2021, 09:01:03 PM
When you get the errror, if you look along the bottom of Visual Studio, there is a row of tabs. I think the "Error List" tab is being shown. If you click the "Output" tab, you will see more information about the error.

You may see this error:

1>CMake Error at cmake_install.cmake:37 (file):
1>  file cannot create directory: C:/Program Files (x86)/PhreeqcRM/lib.  Maybe
1>  need administrative privileges.

If so, you may need to rerun CMake and set the variable MAKE_INSTALL_PREFIX. I usually use ./INSTALL.
Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on August 19, 2021, 07:55:12 AM
Hi,

I have checked the Output tab (attached below) and found that the error isn't the one you have mentioned. Despite this, I have rerun Cmake and reset the variable MAKE_INSTALL_PREFIX, but it still does't work.

Best regards,
Zhaoyang
 
Title: Re: Compiling PhreeqcRM
Post by: dlparkhurst on August 19, 2021, 02:17:59 PM
I guess you will have to get some debugging practice.

Build debug PhreeqcRM. Set the configuration to Debug and compile ALL_BUILD.

Set TestRM to be the startup project. Right click on TestRM and "Set as Startup Project".

Right click on TestRM and choose build. I think this should say the project is up to date.

Go to the Debug tab at the top and start debugging. The file main.cpp calls a set of tests in sequence, but I suspect it fails before or in the first test.
 

Title: Re: Compiling PhreeqcRM
Post by: charlton on August 19, 2021, 03:19:38 PM
Hi,

Please upload your CMakeCache.txt file.  It should be located at D:\PhreeqcRM2\CMakeCache.txt.

Scott
Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on August 19, 2021, 03:37:26 PM
Hi, attached is the file you need. Thanks a lot.
Title: Re: Compiling PhreeqcRM
Post by: charlton on August 19, 2021, 03:59:02 PM
Sorry, that's the wrong file.  Its the CMakeCache.txt file.  It should be located in the same directory as the PhreeqcRM.sln file.
Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on August 19, 2021, 04:00:27 PM
Dear Parkhurst,

I have tried several methods you have mentioned, but it still doesn't work. Actually, I have compiled it successfully before. Afetr renewing the Fortran compiler, it fais in building RUN_TESTS. It is strange.

Best regards,
Zhaoyang
Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on August 19, 2021, 04:27:42 PM
Hi, I am sorry for the mistake. I think attached is the right one. Thanks a lot. Best regards, Zhaoyang
Title: Re: Compiling PhreeqcRM
Post by: dlparkhurst on August 19, 2021, 05:21:50 PM
Scott will probably figure it out, but I suggested compiling and debugging the project TestRM, not RUN_TESTS.
Title: Re: Compiling PhreeqcRM
Post by: charlton on August 19, 2021, 05:40:27 PM
I think I was able to reproduce your problem.  I'm guessing your new fortran compiler is the one from intel oneapi.  If it is you'll need to add
C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\redist\intel64_win\compiler
to your path or copy the dlls located in that directory to the location of your executable (exe).

Before doing this you should do as David suggested and try to debug the TestRM project.  You should get something like the attached image.

Scott
Title: Re: Compiling PhreeqcRM
Post by: charlton on August 19, 2021, 05:48:48 PM
I forgot to mention that you also should make your installation directory different from your build directory.  Here's how I normally do it:

Source (PhreeqcRM_SOURCE_DIR):
D:/Downloads/phreeqc/phreeqcrm-3.7.0-15749

Build (PhreeqcRM_BINARY_DIR):
D:/Downloads/phreeqc/phreeqcrm-3.7.0-15749/_build

Install (CMAKE_INSTALL_PREFIX):
D:/Downloads/phreeqc/phreeqcrm-3.7.0-15749/_build/INSTALL
Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on August 20, 2021, 08:31:20 AM
Hi Scott,

Thank you very much for your kindly help. Yes, I use the compiler from intel oneapi now. I have compiled the TestRM project and it says the project is up to date.
In addition, I have checked that path you mentioned, but didn't see the compiler in that path (attached screenshot).

Cheers,
Zhaoyang
Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on August 20, 2021, 09:32:49 AM
Hi, Scoot,

I have made the installation directory different from the build directory, but it doesn't work. The INSTALL is empty.

Cheers,
Zhaoyang
Title: Re: Compiling PhreeqcRM
Post by: charlton on August 20, 2021, 02:46:43 PM
Hi Zhaoyang,

I'm glad you shared that screenshot of the cmake-gui.  It looks like you installed oneapi on the D: drive instead of where I assumed you installed it (the C: drive).  So you'll need to add D:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\redist\intel64_win\compiler to your PATH environment variable for the RUN_TESTS to work.

Scott
Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on August 21, 2021, 02:58:08 PM
Dear Scott,

I have added the D:\Program Files\Intel oneAPI\compiler\latest\windows\redist\intel64_win\compiler to my PATH environment variable and then the RUN_TESTS works. Thank you very much for your help.

Best,
Zhaoyang
Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on August 25, 2021, 10:01:37 AM
Dear Parkhurst and Scott,

I met a problem when running FortranAdvect (screenshot below). In addition, I want to know which input files should be prepared when coupling PhreeqcRM with the transport model.
Thanks for your help in advance.

Best regards,
Zhaoyang
Title: Re: Compiling PhreeqcRM
Post by: dlparkhurst on August 25, 2021, 03:14:23 PM
Perhaps you did not set one of the variables in CMake. PHREEQCRM_FORTRAN_TESTING is near the bottom of the list in CMake.

There is a README.txt file in the doc directory of the PhreeqcRM installation that gives information about compiling and using the PhreeqcRM library. See section F.3 for using in your Fortran program.

Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on August 26, 2021, 08:03:53 AM
Dear Parkhurst,

Thanks for your help. Actually, I do included PHREEQCRM_FORTRAN_TESTING in Cmake (attached screenshot).

Best regards,
Zhaoyang
Title: Re: Compiling PhreeqcRM
Post by: dlparkhurst on August 26, 2021, 02:58:04 PM
You said:
===
I have added the D:\Program Files\Intel oneAPI\compiler\latest\windows\redist\intel64_win\compiler to my PATH environment variable and then the RUN_TESTS works. Thank you very much for your help.
===

If you have set Fortran testing, then FortranAdvection must have worked, for RUN_TESTS to work.
Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on August 26, 2021, 04:31:31 PM
Ok. Since I am working on coupling PhreeqcRM with a transport model, I want to know how PhreeqcRM works in a separate project. Therefore, I try to run FortranAdvection after building ALL_BUILD and RUN_TESTS. I thought it can give me some hints what I should do about the couping. Thanks for your help.

Best regards,
Zhaoyang
Title: Re: Compiling PhreeqcRM
Post by: dlparkhurst on August 26, 2021, 05:25:00 PM
The program PHAST uses PhreeqcRM. At risk of getting more tangled in CMake/Visual Studio, you can download the batch version of PHAST and run CMake, you should be able to compile PHAST. The project for phast3 should be an example of what you need.

It is not ideal because there are other projects that are not needed (phastinput for example), and PhreeqcRM src is also included. The intention is for you to have a .sln solution that compiles your program, and then links to the library you compiled with the PhreeqcRM distribution, so that you only need to keep track of your code and you do not touch the source for PhreeqcRM.
Title: Re: Compiling PhreeqcRM
Post by: dlparkhurst on August 26, 2021, 09:28:34 PM
Here is a simpler option.

If you create a Visual Studio Fortran, console solution including the following main program and the interface file RM_interface.F90, you need only ensure the following:

(1) Compile the debug version of PhreeqcRM and run Install.

(2) Make sure that the configuration of your new solution is for Debug x64.

To set properties in the solution, one option is to right click on the project and scroll down to Properties.

(3) Set the preprocessor option Fortran->Preprocessor->Preprocess Source Files YES

(4) For the linker options in Linker->general properties->Additional Library Directories, add the path to the INSTALL\lib directory of PhreeqcRM.

(5) For Linker->Input->Additional Dependencies, add the library PhreeqcRMd.lib

You should be able to compile and run the Hello program.

Code: [Select]
    program Hello
    USE PhreeqcRM
    implicit none
    integer :: status
    integer :: nxyz
    integer :: nthreads
    integer :: rm_id

    nthreads = 3
    nxyz = 12
    rm_id = RM_Create(nxyz, nthreads)
    status = RM_ScreenMessage(rm_id, "Hello world.")
    status = RM_Destroy(rm_id)

    end program Hello
Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on August 26, 2021, 10:13:17 PM
Dear Parkhurst,

Thank you very much for your help. I will do as you suggested.

Best regards,
Zhaoyang
Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on August 28, 2021, 08:23:16 PM
Dear Parkhurst,

Thank you very much for your help. I have run the simply example from you successfully and known how to include PhreeqcRM in my own project. However, I have another two questions. The first is that the transport model I adopted is based on the grid, while Phreeqcrm is based on the cell. Therefore, my idea is that I can caucuate the values of cell based on the nearby grids and then transfer them to the reactive model. Is it right?
Another question is about the boundary condition and initial condition. Do I need to set the boundary condition and initial condition for both the transport model and reactive model or just for the transport model? According to my understanding, I just need to set the boundary condition and initial condition for the transport model.
Thanks for your help in advance.

Best regards,
Zhaoyang
Title: Re: Compiling PhreeqcRM
Post by: dlparkhurst on August 29, 2021, 04:38:08 AM
PhreeqcRM does not really have any geometrical definitions. Your multicomponent transport model has concentrations for points in space. The plan is to transfer concentrations after a transport step from your transport model to PhreeqcRM, run chemical reactions on those concentrations, and return the modified concentrations to the transport model for another transport step.

You must set up initial conditions in PhreeqcRM, including solution compositions and any reactants like EQUILIBRIUM_PHASES, SURFACES, KINETICS, etc. using the method RM_InitialPhreeqc2Module. You probably want to use RM_RunCells (with a zero time step) to equilibrate the solutions with the reactants. You will then transfer the concentrations to your transport model with RM_GetConcentrations. You must do it in this order because PhreeqcRM requires three of the transported quantities to be H, O, and charge. In general, you will not know these concentrations (and total concentrations of other elements) except through PhreeqcRM. RM_GetConcentrations will provide the concentrations needed for your first transport step.

See advection_f90.F90 for a typical initialization and time stepping sequence. That example demonstrates the use of most of the frequently used PhreeqcRM methods.
Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on August 31, 2021, 01:08:54 PM
Dear Parkhurst,

Thanks for your explanations. Everything works well on my own laptop. Therefore, I try to build and install PhreeqcRM in my office computer using the same platform (Visual Studio 19 + Intel OneAPI). However, even though I choose PHREEQCRM_FORTRAN_TESTING in Cmake, the project won't include the Fortran module (CMakeCache.txt attached). It is wired. Do you have any idea on this? Thanks for your help in advance.

Best regards,
Zhaoyang
Title: Re: Compiling PhreeqcRM
Post by: charlton on August 31, 2021, 05:09:16 PM
Hi Zhaoyang,

Did you re-run cmake on your office computer?

Scott
Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on August 31, 2021, 08:00:25 PM
Hi, Scott,

Yes, I compiled PhreeqcRM successfully in my own laptop before and then want to install PhreeqcRM in my office computer. Unfortunately, it can't include the Fortran module. I am sure I did exactly the same steps in my office computer. Thanks for your help.

Best regards,
Zhaoyang
Title: Re: Compiling PhreeqcRM
Post by: charlton on August 31, 2021, 08:13:32 PM
Hi Zhaoyang,

Did you copy the build directory from your laptop onto your office computer (d:/PhreeqcRM/build)?  If so, try deleting everything in the build directory and running cmake again.  If this doens't work, let me know and I'll guide you through a CLI (command line interface) build.

Scott
Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on September 01, 2021, 07:39:22 AM
Hi, Scott,

Thanks for your reminding. I recall that I have built and installed PhreeqcRM in my office computer with an old version of Intel Fortran before. Now, I deleted everything and rebuilt it again. It works. Thanks for your help and have a nice day.

Best regards,
Zhaoyang
Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on November 18, 2021, 10:00:56 AM
Dear all,

I have run my solution successfully with Debug x64. To accelerate the calculation, I want to change it to Release x64. Thus, I tried to install PhreeqcRM.sln based on Release x64. After installing, I linked my solution to PhreeqcRM.lib since there is no PhreeqcRMd.lib. However, it didn't work. Does anyone know how to solve this problem? Any help will be appreciated.

Best regards,
Zhaoyang
Title: Re: Compiling PhreeqcRM
Post by: dlparkhurst on November 18, 2021, 03:27:48 PM
First, you can compile and install both PhreeqcRMd.lib and PhreeqcRM.lib from the same solution.

If you have indeed compiled PhreeqcRM.lib, then, as you say, you need to define the directory in the Properties->General->Additional Library Directories, and the library (PhreeqcRM.lib) in Properties->General->Input->Additional Dependencies. However, make sure, at the top of the properties screen, make sure the configuration is set to Release and Platform is x64. Your application must also be compiled for the Release configuration.
Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on November 19, 2021, 09:15:07 AM
Thanks for your reply.

I met the same problem (the first post in this topic) when compling RUN_TESTS based on Release x64 (attached screenshot and CMakeCache.txt file). As suggested by Scott before, the problem is solved by adding D:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\redist\intel64_win\compiler to the PATH environment variable. This path has already been added to the PATH environment variable, but the problem is still there. To finish installing PhreeqcRM, I only built ALL_BUILD and INSTALL. As a result, I only have PhreeqcRM.lib.

Suprisingly, this problem also occurred when compling RUN_TESTS based on Debug x64. It has been solved before following Scott's suggestion. In this case, I only have PhreeqcRMd.lib after building ALL_BUILD and INSTALL. Before, when finishing to build ALL_BUILD, RUN_TESTS and INSTALL, I have both PhreeqcRMd.lib and PhreeqcRM.lib.

Best regards,
Zhaoyang
Title: Re: Compiling PhreeqcRM
Post by: dlparkhurst on November 19, 2021, 05:46:24 PM
You are wearing out my patience. It is not really our responsibility to debug your issues.

Build RUN_TESTS and switch from the "Error List" tab to the "Output" tab, which is located at the very bottom of the VS screen. Post the result.
Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on November 21, 2021, 09:24:03 AM
Sorry, I didn't mean it, and I also struggled with this problem for a few days. Attached is the "Output" tab. Thanks for your help again.
Title: Re: Compiling PhreeqcRM
Post by: charlton on November 21, 2021, 07:04:20 PM
Hi Zhaoyang,

Can you try running the test from the command line.  It should tell you if you're missing any dlls.

Scott
Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on November 22, 2021, 08:47:25 PM
Hi, Scott,

Thanks for your reply. Unfortunately, I don't know how to do this. Could you please give me some hints? Thanks in advance.

Best regrads,
Zhaoyang
Title: Re: Compiling PhreeqcRM
Post by: dlparkhurst on November 22, 2021, 11:53:27 PM
Right click on the Windows icon at the bottom left of the screen.

Click Run.

Type "cmd"

Type "cd d:\PhreeqcRM\Build\Tests"

Type Release\TestRM.exe

Post any error messages.

In addition, let us know if you use git for version control.
Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on November 23, 2021, 08:40:50 PM
After finishing all the steps, it says "Can't locate the input point for_stop_core_quite in the dynamic library d:\PhreeqcRM\Build\Tests\Release\TestRM.exe " (attached screenshot). Note that I built it successfully based on Release x64 on the office computer today. I guess this error is because of my own laptop, although it used to work. Maybe I changed some settings in my own laptop, but I am not aware of them. In addition, I don't use git for version control.
Thanks for your help again.
Title: Re: Compiling PhreeqcRM
Post by: dlparkhurst on November 23, 2021, 10:29:18 PM
Here is the result of a search for for_stop_core_quiet:

community.intel.com/t5/Intel-Fortran-Compiler/the-procedure-entry-point-for-stop-core-quiet-could-not-be/m-p/1265262#M155073
Title: Re: Compiling PhreeqcRM
Post by: Zhaoyang on November 25, 2021, 03:11:56 PM
It works now. Thank you very much!