Beginners > Installation questions

YAML compilation successful, but YAMLPhreeqcRM can not be called

(1/1)

Yongqiang:
Hi David and Chalton,

I followed your instruction and successfully installed the YAML version phreeqcrm. Run the make check and passed all tests.
However, I encountered the following errors when compile code:

--- Code: ---WriteYAMLFile_cpp.cpp: In function ?void WriteYAMLFile_cpp()?:
WriteYAMLFile_cpp.cpp:17:9: error: ?YAMLPhreeqcRM? was not declared in this scope; did you mean ?PhreeqcRM??
   17 |         YAMLPhreeqcRM yrm;
      |         ^~~~~~~~~~~~~
      |         PhreeqcRM
WriteYAMLFile_cpp.cpp:20:9: error: ?yrm? was not declared in this scope
   20 |         yrm.YAMLSetGridCellCount(nxyz);
      |         ^~~
make: *** [/scratch3/che458/of/OpenFOAM-v2412/wmake/rules/General/transform:38: Make/linux64GccDPInt32Opt/WriteYAMLFile_cpp.o] Error 1

--- End code ---

The full code is

--- Code: ---#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "PhreeqcRM.h"
#include "IPhreeqc.hpp"
#include "IPhreeqcPhast.h"
#include <algorithm>
#include "YAMLPhreeqcRM.h"
#include "YAML_interface_C.h"

using namespace std;

void WriteYAMLFile_cpp(void)
{
YAMLPhreeqcRM yrm;
int nxyz = 40;
// Set GridCellCount
yrm.YAMLSetGridCellCount(nxyz);

int nthreads = 3;
// Set ThreadCount
yrm.YAMLThreadCount(nthreads);

// Set some properties
yrm.YAMLSetErrorHandlerMode(1);
yrm.YAMLSetComponentH2O(false);
yrm.YAMLSetRebalanceFraction(0.5);
yrm.YAMLSetRebalanceByCell(true);
yrm.YAMLUseSolutionDensityVolume(false);
yrm.YAMLSetPartitionUZSolids(false);
// Open files
yrm.YAMLSetFilePrefix("AdvectBMI_cpp");
yrm.YAMLOpenFiles();

// Set concentration units
yrm.YAMLSetUnitsSolution(2);           // 1, mg/L; 2, mol/L; 3, kg/kgs
yrm.YAMLSetUnitsPPassemblage(1);       // 0, mol/L cell; 1, mol/L water; 2 mol/L rock
yrm.YAMLSetUnitsExchange(1);           // 0, mol/L cell; 1, mol/L water; 2 mol/L rock
yrm.YAMLSetUnitsSurface(1);            // 0, mol/L cell; 1, mol/L water; 2 mol/L rock
yrm.YAMLSetUnitsGasPhase(1);           // 0, mol/L cell; 1, mol/L water; 2 mol/L rock
yrm.YAMLSetUnitsSSassemblage(1);       // 0, mol/L cell; 1, mol/L water; 2 mol/L rock
yrm.YAMLSetUnitsKinetics(1);           // 0, mol/L cell; 1, mol/L water; 2 mol/L rock

// Set conversion from seconds to user units (days) Only affects one print statement
double time_conversion = 1.0 / 86400;
yrm.YAMLSetTimeConversion(time_conversion);
// Set representative volume
std::vector<double> rv(nxyz, 1.0);
yrm.YAMLSetRepresentativeVolume(rv);
// Set density
std::vector<double> density(nxyz, 1.0);
yrm.YAMLSetDensityUser(density);
// Set initial porosity
std::vector<double> por(nxyz, 0.2);
yrm.YAMLSetPorosity(por);
// Set initial saturation
std::vector<double> sat(nxyz, 1.0);
yrm.YAMLSetSaturationUser(sat);
// Set cells to print chemistry when print chemistry is turned on
std::vector<int> print_chemistry_mask(nxyz, 0);
for (int i = 0; i < nxyz / 2; i++)
{
print_chemistry_mask[i] = 1;
}
yrm.YAMLSetPrintChemistryMask(print_chemistry_mask);

// Demonstation of mapping, two equivalent rows by symmetry
std::vector<int> grid2chem;
grid2chem.resize(nxyz, -1);
for (int i = 0; i < nxyz / 2; i++)
{
grid2chem[i] = i;
grid2chem[i + nxyz / 2] = i;
}
yrm.YAMLCreateMapping(grid2chem);

// Set printing of chemistry file
yrm.YAMLSetPrintChemistryOn(false, true, false); // workers, initial_phreeqc, utility
// Load database
yrm.YAMLLoadDatabase("phreeqc.dat");

// Run file to define solutions and reactants for initial conditions, selected output
bool workers = true;             // Worker instances do the reaction calculations for transport
bool initial_phreeqc = true;     // InitialPhreeqc instance accumulates initial and boundary conditions
bool utility = true;             // Utility instance is available for processing
yrm.YAMLRunFile(workers, initial_phreeqc, utility, "advect.pqi");

// Clear contents of workers and utility
initial_phreeqc = false;
std::string input = "DELETE; -all";
yrm.YAMLRunString(workers, initial_phreeqc, utility, input.c_str());
// Define additional output variables
yrm.YAMLAddOutputVars("AddOutputVars", "true");
// Determine number of components to transport
yrm.YAMLFindComponents();
// set array of initial conditions
std::vector<int> ic1, ic2;
ic1.resize(nxyz * 7, -1);
ic2.resize(nxyz * 7, -1);
std::vector<double> f1;
f1.resize(nxyz * 7, 1.0);
for (int i = 0; i < nxyz; i++)
{
ic1[i] = 1;              // Solution 1
ic1[nxyz + i] = -1;      // Equilibrium phases none
ic1[2 * nxyz + i] = 1;     // Exchange 1
ic1[3 * nxyz + i] = -1;    // Surface none
ic1[4 * nxyz + i] = -1;    // Gas phase none
ic1[5 * nxyz + i] = -1;    // Solid solutions none
ic1[6 * nxyz + i] = -1;    // Kinetics none
}
yrm.YAMLInitialPhreeqc2Module(ic1, ic2, f1);
// No mixing is defined, so the following is equivalent
//yrm.YAMLInitialPhreeqc2Module(ic1);

// alternative for setting initial conditions
// cell number in first argument (-1 indicates last solution, 40 in this case)
// in advect.pqi and any reactants with the same number--
// Equilibrium phases, exchange, surface, gas phase, solid solution, and (or) kinetics--
// will be written to cells 18 and 19 (0 based)
std::vector<int> module_cells;
module_cells.push_back(18);
module_cells.push_back(19);
yrm.YAMLInitialPhreeqcCell2Module(-1, module_cells);
// Initial equilibration of cells
double time_step = 0.0;  // no kinetics
yrm.YAMLSetTimeStep(time_step);
double time = 0.0;
yrm.YAMLSetTime(time);
yrm.YAMLRunCells();
yrm.YAMLSetTimeStep(86400);

// Write YAML file
std::string YAML_filename = "AdvectBMI_cpp.yaml";
yrm.WriteYAMLDoc(YAML_filename);
yrm.Clear();
};


int main()
{

     WriteYAMLFile_cpp();
     std::cout << "Done! "<<std::endl;
}
--- End code ---

dlparkhurst:
I don't know if this will fix the problem, but you should not include "YAML_interface_C.h"; it is for C programs.

Here are the header files used in WriteYAMLFile_cpp.cpp in the Tests subdirectory.


--- Code: ---#include "PhreeqcRM.h"
#include "IPhreeqc.hpp"
#include "IPhreeqcPhast.h"
#include "yaml-cpp/yaml.h"
#include "YAMLPhreeqcRM.h"

--- End code ---

Yongqiang:
Thanks, David.
The header files were changed accordingly. However, the same errors popped up.

Thanks,
Yongqiang

Yongqiang:
the following is the make file:

--- Code: ---# Define variables for cleaner Makefile



CXX = g++                      # C++ Compiler



CXXFLAGS = -Wall -std=c++17    # Compiler flags (warnings, C++ standard)





# Include directories

# -I/opt/boost/1.80.0/include: Path to Boost headers (ADJUST THIS PATH)

INCLUDE_DIRS = -I/home/che458/phreeqcrmBMI/installation/include -I/home/che458/yaml-cpp/installation/include





# Library directories

# -L./external_libs: Path to where your .so or .a files are located

LIB_DIRS = -L/home/che458/phreeqcrmBMI/installation/lib64 -L/home/che458/yaml-cpp/installation/lib64





# Libraries to link

# -lboost_system: Links libboost_system.so (or .a)

LIBS = -lphreeqcrm -lyaml-cpp





# Name of the executable to be built

TARGET = my_program





# Source file(s)

SRCS = WriteYAMLFile_cpp.cpp





# Object file(s) - derived from source files

OBJS = $(SRCS:.cpp=.o) # This converts my_program.cpp to my_program.o





.PHONY: all clean run # Declare phony targets that don't represent actual files





# Default target: builds the program

all: $(TARGET)





# Rule to link the executable

$(TARGET): $(OBJS)

@echo "Linking $(TARGET)..."

$(CXX) $(OBJS) $(LIB_DIRS) $(LIBS) -o $@





# Rule to compile C++ source files into object files

%.o: %.cpp

@echo "Compiling $<..."

$(CXX) $(CXXFLAGS) $(INCLUDE_DIRS) -c $< -o $@





# Rule to clean up generated files

clean:

@echo "Cleaning up..."

[member=1460]rm[/member] -f $(TARGET) $(OBJS)





# Rule to compile and run in one go (optional, for convenience)

run: all

@echo "Running $(TARGET)..."

# Note: LD_LIBRARY_PATH might be needed if libexternal.so is not in a standard path

# export LD_LIBRARY_PATH=./external_libs:$$LD_LIBRARY_PATH && ./$(TARGET)

./$(TARGET)
--- End code ---

The following is the files generated through "make install":

--- Code: ---Warn: could not determine prefix for system-openmpi
***
assuming you already have already run
module load miniconda
***

che458@petrichor-login:~/phreeqcrmBMI/installation> ls
include  lib64  share
che458@petrichor-login:~/phreeqcrmBMI/installation> cd include/
che458@petrichor-login:~/phreeqcrmBMI/installation/include> ls
BMIPhreeqcRM.h       IPhreeqcPhast.h  Parser.h          VarManager.h
BMIVariant.h         IrmResult.h      PhreeqcRM.h       YAMLPhreeqcRM.h
BMI_interface_C.h    Keywords.h       RMVARS.h          YAML_interface_C.h
BMI_interface_F.h    NameDouble.h     RM_interface_C.h  YAML_interface_F.h
IPhreeqc.h           PHRQ_base.h      StorageBin.h      bmi.hxx
IPhreeqc.hpp         PHRQ_exports.h   System.h          irm_dll_export.h
IPhreeqcCallbacks.h  PHRQ_io.h        Var.h             phrqtype.h
che458@petrichor-login:~/phreeqcrmBMI/installation/include> cd ../lib64/
che458@petrichor-login:~/phreeqcrmBMI/installation/lib64> ls
libphreeqcrm-3.8.7.so  libphreeqcrm.a  libphreeqcrm.la  libphreeqcrm.so
che458@petrichor-login:~/phreeqcrmBMI/installation/lib64>


--- End code ---

charlton:
You need to add the USE_YAML definition to your CXXFLAGS variable (see the first line in YAMLPhreeqcRM.h) ie:

CXXFLAGS = -Wall -std=c++17 -DUSE_YAML   # Compiler flags (warnings, C++ standard)

Scott

Navigation

[0] Message Index

Go to full version