Skip to content

Commit

Permalink
Squashed 'src/phast/PhreeqcRM/' changes from 6970571d..9b9ddd9c
Browse files Browse the repository at this point in the history
9b9ddd9c Merge commit '5d85dd465b957ad7c053024fe2b0ae7c24868093'
5d85dd46 Squashed 'src/' changes from 3e1a6641..64ab76fa
adba7870 BMI LoadDatabase fix (#191)
1e2069d2 Bumped wheel version

git-subtree-dir: src/phast/PhreeqcRM
git-subtree-split: 9b9ddd9c90e2a886409ace28b9e0e01acbac872c
  • Loading branch information
Darth Vader committed Feb 8, 2025
1 parent 5098247 commit 4e0cbe1
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 76 deletions.
13 changes: 3 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,15 @@ jobs:
compiler: intel-classic
version: '2021.10'

- name: Unset CC/CXX (Windows)
- name: Set CC/CXX (Windows)
if: runner.os == 'Windows'
shell: bash
run: |
echo "CC=" >> $GITHUB_ENV
echo "CXX=" >> $GITHUB_ENV
echo "CC=cl" >> $GITHUB_ENV
echo "CXX=cl" >> $GITHUB_ENV
- name: Install ninja valgrind (Linux)
if: ${{ runner.os == 'Linux' }}
#run: sudo apt-get install -y ninja-build valgrind libyaml-cpp-dev python3-numpy
run: |
sudo apt-get -y update
sudo apt-get install -y ninja-build valgrind
Expand Down Expand Up @@ -437,12 +436,6 @@ jobs:
python -m pip install pytest
# @todo if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Set up Visual Studio shell (Windows)
if: runner.os == 'Windows'
uses: egor-tensin/vs-shell@v2
with:
arch: x64

- name: Extract tarball
run: tar xvzf phreeqcrm-${{ env.VER_STRING }}.tar.gz

Expand Down
14 changes: 12 additions & 2 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ jobs:
- [cp38, v141]
- [cp39, v141]
- [cp310, v141]
- [pp310, v141]
- [cp311, v141]
- [cp312, v142]
- [cp313, v142]
# - [cp313t, v142]
- [pp310, v141]

exclude:
# cp313(i686) on ubuntu-20.04
- buildplat: [ubuntu-20.04, manylinux_i686, i686]
Expand Down Expand Up @@ -88,11 +90,19 @@ jobs:
run: |
python --version
# free some space to prevent reaching GHA disk space limits
- name: Clean docker images
if: runner.os == 'Linux'
run: |
docker system prune -a -f
df -h
- name: Setup QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v3
with:
platforms: all
image: tonistiigi/binfmt:qemu-v8.1.5
#platforms: all

- name: Build wheels (Linux)
if: ${{ runner.os == 'Linux' }}
Expand Down
66 changes: 42 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,12 @@ if(PHREEQCRM_FORTRAN_TESTING)
enable_language(Fortran)
endif()

# Include FetchContent module
include(FetchContent)

if(DEFINED SKBUILD)
# SKBUILD is defined when scikit-build-core is used to build python wheels (see pyproject.toml)

# Include FetchContent module
include(FetchContent)

# Fetch yaml-cpp
FetchContent_Declare(
yaml-cpp
URL https://github.com/jbeder/yaml-cpp/archive/refs/tags/0.8.0.tar.gz
)

# Make yaml-cpp available
FetchContent_MakeAvailable(yaml-cpp)


# Fetch zlib
FetchContent_Declare(
zlib
Expand All @@ -68,10 +58,28 @@ if(DEFINED SKBUILD)
# SKBUILD is defined when scikit-build-core is used to build python wheels (see pyproject.toml)
set(PHREEQCRM_WITH_YAML_CPP ON)
endif()
if(PHREEQCRM_WITH_YAML_CPP AND NOT DEFINED SKBUILD)
if(PHREEQCRM_WITH_YAML_CPP)
# Initialize a static build for yaml-cpp
# w/o the FORCE option the user can override using -DYAML_BUILD_SHARED_LIBS=ON
set(YAML_BUILD_SHARED_LIBS OFF CACHE STRING "")
# w/o the FORCE option the user can override using -DYAML_CPP_INSTALL=OFF
set(YAML_CPP_INSTALL ON CACHE STRING "")

# Fetch yaml-cpp
FetchContent_Declare(
yaml-cpp
URL https://github.com/jbeder/yaml-cpp/archive/refs/tags/0.8.0.tar.gz
OVERRIDE_FIND_PACKAGE
)

# The following will automatically forward through to FetchContent_MakeAvailable()
find_package(yaml-cpp REQUIRED)
if(yaml-cpp_FOUND)
message(STATUS "Found yaml-cpp: TRUE (found version \"${yaml-cpp_VERSION}\")")
if(DEFINED yaml-cpp_VERSION)
message(STATUS "Found yaml-cpp: TRUE (found version \"${yaml-cpp_VERSION}\")")
else()
message(STATUS "Found yaml-cpp: TRUE")
endif()
endif()
endif()

Expand Down Expand Up @@ -314,8 +322,8 @@ target_include_directories(PhreeqcRM
include(GenerateExportHeader)
generate_export_header(PhreeqcRM BASE_NAME IRM_DLL)

# c++11
target_compile_features(PhreeqcRM PUBLIC cxx_std_11)
# c++14
target_compile_features(PhreeqcRM PUBLIC cxx_std_14)

# iphreeqc defs
target_compile_definitions(PhreeqcRM PRIVATE SWIG_SHARED_OBJ)
Expand Down Expand Up @@ -526,13 +534,23 @@ if(STANDALONE_BUILD EQUAL 1 AND NOT DEFINED SKBUILD)
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/PhreeqcRM
)

install(TARGETS PhreeqcRM
EXPORT PhreeqcRMTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
if(PHREEQCRM_WITH_YAML_CPP AND yaml-cpp_FOUND)
install(TARGETS PhreeqcRM yaml-cpp
EXPORT PhreeqcRMTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
else()
install(TARGETS PhreeqcRM
EXPORT PhreeqcRMTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endif()

install(EXPORT PhreeqcRMTargets
FILE PhreeqcRMTargets.cmake
Expand Down
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ AC_PROG_AWK
AC_PROG_CPP
AC_PROG_LN_S

# c++11 is required
AX_CXX_COMPILE_STDCXX(11, [ext], [mandatory])
# c++14 is required
AX_CXX_COMPILE_STDCXX(14, [ext], [mandatory])

# Check if the fortran test should be included
AC_MSG_CHECKING([if Fortran test is added])
Expand Down
1 change: 0 additions & 1 deletion mamba.environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ dependencies:
- python
- pyyaml
- swig
- yaml-cpp
- cmake
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build-backend = "scikit_build_core.build"

[project]
name = "phreeqcrm"
version = "0.0.12"
version = "0.0.14"
description = "A reaction module for transport simulators based on the geochemical model PHREEQC."
readme = "README.md"
requires-python = ">=3.8"
Expand Down
20 changes: 14 additions & 6 deletions src/BMIPhreeqcRM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ void BMIPhreeqcRM::ClearBMISelectedOutput(void)
assert(this->var_man);
this->var_man->BMISelectedOutput.clear();
}
void BMIPhreeqcRM::Construct(PhreeqcRM::Initializer i)
void BMIPhreeqcRM::Construct()
{
if (constructed) return;
this->PhreeqcRM::Construct(i);
this->PhreeqcRM::Construct();
this->var_man = new VarManager((PhreeqcRM*)this);
#if defined(WITH_PYBIND11)
this->_initialized = true;
Expand Down Expand Up @@ -180,13 +180,13 @@ void BMIPhreeqcRM::Initialize(std::string config_file)
std::string keyword = it1++->second.as<std::string>();
if (keyword == "SetGridCellCount")
{
this->initializer.nxyz_arg = it1++->second.as<int>();
set_nxyz(it1++->second.as<int>());
found_nxyz = true;
}
if (keyword == "ThreadCount")
{
#if !defined(USE_MPI)
this->initializer.data_for_parallel_processing = it1++->second.as<int>();
set_data_for_parallel_processing(it1++->second.as<int>());
#endif
found_threads = true;
}
Expand All @@ -195,7 +195,7 @@ void BMIPhreeqcRM::Initialize(std::string config_file)
}
#endif

this->Construct(this->initializer);
this->Construct();
constructed = true;
#ifdef USE_YAML
if (config_file.size() != 0)
Expand Down Expand Up @@ -1321,6 +1321,14 @@ RMVARS BMIPhreeqcRM::GetEnum(const std::string name)
return RMVARS::NotFound;
};

//////////////////
/* ---------------------------------------------------------------------- */
IRM_RESULT
BMIPhreeqcRM::LoadDatabase(const std::string& database)
/* ---------------------------------------------------------------------- */
{
// reqd for swig-python
return this->PhreeqcRM::LoadDatabase(database);
}

//////////////////

4 changes: 3 additions & 1 deletion src/BMIPhreeqcRM.h
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,8 @@ class IRM_DLL_EXPORT BMIPhreeqcRM : public bmi::Bmi, public PhreeqcRM
// std::set<std::string> UpdateMap;
// std::set<std::string>& GetUpdateMap() { return UpdateMap; }

IRM_RESULT LoadDatabase(const std::string& database) override;

#if defined(WITH_PYBIND11)

py::array BMIPhreeqcRM::get_value(std::string name, py::array arr);
Expand All @@ -1297,7 +1299,7 @@ class IRM_DLL_EXPORT BMIPhreeqcRM : public bmi::Bmi, public PhreeqcRM
#endif

protected:
void Construct(Initializer initializer) override;
void Construct(void) override;

private:
//friend class RM_interface;
Expand Down
53 changes: 44 additions & 9 deletions src/PhreeqcRM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@
const MP_TYPE PhreeqcRM::default_data_for_parallel_processing = -1;
#endif

// Pimpl for initialization
class PhreeqcRM::Initializer
{

public:
Initializer() : nxyz_arg(default_nxyz), data_for_parallel_processing(default_data_for_parallel_processing), io(nullptr) {}
Initializer(int nxyz, MP_TYPE data, PHRQ_io *pio) : nxyz_arg(nxyz), data_for_parallel_processing(data), io(pio) {}

public:
int nxyz_arg;
MP_TYPE data_for_parallel_processing;
PHRQ_io *io;
};

//// static PhreeqcRM methods
/* ---------------------------------------------------------------------- */
Expand Down Expand Up @@ -169,7 +182,7 @@ PhreeqcRM::PhreeqcRM(int nxyz_arg, MP_TYPE data_for_parallel_processing, PHRQ_io
, mpi_worker_callback_c( nullptr )
, mpi_worker_callback_cookie( nullptr )
, species_save_on( false )
, initializer( nxyz_arg, data_for_parallel_processing, io )
, initializer(std::make_unique<PhreeqcRM::Initializer>(nxyz_arg, data_for_parallel_processing, io))
{
#ifdef USE_MPI
phreeqcrm_comm = data_for_parallel_processing;
Expand All @@ -188,24 +201,24 @@ PhreeqcRM::PhreeqcRM(int nxyz_arg, MP_TYPE data_for_parallel_processing, PHRQ_io
#ifdef USE_MPI
if (mpi_myself == 0)
{
this->Construct(this->initializer);
this->Construct();
MpiWorkerBreak();
}
else
{
MpiWorker();
}
#else
this->Construct(this->initializer);
this->Construct();
#endif
}
}

void PhreeqcRM::Construct(PhreeqcRM::Initializer i)
void PhreeqcRM::Construct()
{
int nxyz_arg = i.nxyz_arg;
MP_TYPE data_for_parallel_processing = i.data_for_parallel_processing;
//PHRQ_io *io = i.io;
int nxyz_arg = this->initializer->nxyz_arg;
MP_TYPE data_for_parallel_processing = this->initializer->data_for_parallel_processing;
//PHRQ_io* io = this->initializer->io;
#ifdef USE_MPI
if (mpi_myself == 0)
{
Expand Down Expand Up @@ -5631,7 +5644,8 @@ IRM_RESULT PhreeqcRM::InitializeYAML(std::string config)
if (keyword == "LoadDatabase")
{
std::string file = it1++->second.as< std::string >();
this->LoadDatabase(file);
// no need to check for initialization just call base class
this->PhreeqcRM::LoadDatabase(file);
continue;
}
if (keyword == "OpenFiles")
Expand Down Expand Up @@ -7035,7 +7049,7 @@ PhreeqcRM::MpiWorker()
case METHOD_CONSTRUCT:
if (debug_worker) std::cerr << "METHOD_CONSTRUCT" << std::endl;
{
this->Construct(this->initializer);
this->Construct();
}
break;
case METHOD_CREATEMAPPING:
Expand Down Expand Up @@ -13028,6 +13042,27 @@ PhreeqcRM::WarningMessage(const std::string &str)
this->phreeqcrm_io->warning_msg(str.c_str());
}
}
/* ---------------------------------------------------------------------- */
void
PhreeqcRM::set_data_for_parallel_processing(int value)
/* ---------------------------------------------------------------------- */
{
this->initializer->data_for_parallel_processing = value;
}
/* ---------------------------------------------------------------------- */
void
PhreeqcRM::set_nxyz(int value)
/* ---------------------------------------------------------------------- */
{
this->initializer->nxyz_arg = value;
}
/* ---------------------------------------------------------------------- */
void
PhreeqcRM::set_io(PHRQ_io *value)
/* ---------------------------------------------------------------------- */
{
this->initializer->io = value;
}



Expand Down
Loading

0 comments on commit 4e0cbe1

Please sign in to comment.