Skip to content

changes to make it possible to build under Windows#7212

Draft
GitPaean wants to merge 14 commits into
OPM:masterfrom
GitPaean:windows
Draft

changes to make it possible to build under Windows#7212
GitPaean wants to merge 14 commits into
OPM:masterfrom
GitPaean:windows

Conversation

@GitPaean

@GitPaean GitPaean commented Jul 1, 2026

Copy link
Copy Markdown
Member

@GitPaean GitPaean added the manual:irrelevant This PR is a minor fix and should not appear in the manual label Jul 1, 2026
@GitPaean GitPaean requested a review from Copilot July 1, 2026 14:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a set of portability fixes intended to make opm-simulators build successfully under Windows/MSVC (coordinated with related changes in opm-common and opm-grid).

Changes:

  • Add/adjust includes and path-string conversions to avoid MSVC/Windows filesystem and standard library incompatibilities.
  • Rework several OpenMP loops to MSVC-compatible “canonical” forms and address MSVC-specific template/type issues.
  • Introduce Windows-specific fallbacks/workarounds for missing POSIX APIs/macros (signals, ffs, S_ISDIR, allocation).

Reviewed changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
tests/test_parallelwellinfo.cpp Adds missing <numeric> include.
tests/test_outputdir.cpp Converts std::filesystem::path to .string() for std::string variables.
tests/test_networkpressure.cpp Adds MPI global fixture initialization for tests under MPI.
tests/models/test_tasklets_failure.cpp Adds Windows process-spawn alternative to fork()-based failure test.
opm/simulators/wells/WellInterfaceFluidSystem.cpp Adds <numeric> include for standard algorithms.
opm/simulators/wells/GasLiftStage2.cpp Adds <numeric> include for standard algorithms.
opm/simulators/utils/satfunc/SatfuncConsistencyChecks.hpp Refactors nested type / container choices to work around MSVC completeness issues.
opm/simulators/utils/satfunc/SatfuncConsistencyChecks.cpp Updates implementation to match the moved violation-sample type.
opm/simulators/utils/ParallelFileMerger.cpp Uses .string() instead of .native() for Windows narrow-string handling.
opm/simulators/linalg/getQuasiImpesWeights.hpp Rewrites OpenMP range-for over chunks into index-based loops (MSVC/OpenMP compatibility).
opm/simulators/linalg/DILU.hpp Adjusts OpenMP loop bounds to avoid MSVC /openmp:llvm ICE.
opm/simulators/flow/Transmissibility_impl.hpp Rewrites chunk loop into index-based OpenMP-compatible form.
opm/simulators/flow/TracerModel.hpp Rewrites chunk loops into index-based OpenMP-compatible forms.
opm/simulators/flow/SimulatorSerializer.cpp Converts filesystem path to string when assigning to loadFile_.
opm/simulators/flow/rescoup/ReservoirCouplingSpawnSlaves.hpp Adjusts argv construction API to accept narrow strings for Windows.
opm/simulators/flow/rescoup/ReservoirCouplingSpawnSlaves.cpp Keeps narrow path string alive and avoids path::c_str() wchar_t issues on Windows.
opm/simulators/flow/RegionPhasePVAverage.cpp Adds <numeric> include.
opm/simulators/flow/NonlinearSystemBlackOilReservoir.hpp Works around Windows STRICT macro collision with enum values.
opm/simulators/flow/NlddReporting.hpp Converts output paths to .string() for writers expecting std::string.
opm/simulators/flow/KeywordValidation.hpp Adds <stdexcept> include for exception types.
opm/simulators/flow/GenericOutputBlackoilModule.cpp Moves a local enum to namespace scope to avoid MSVC template instantiation issues.
opm/simulators/flow/FIBlackoilModel.hpp Rewrites chunk loops into index-based OpenMP-compatible forms.
opm/simulators/flow/FacePropertiesTPSA_impl.hpp Rewrites chunk loops into index-based OpenMP-compatible form.
opm/simulators/flow/ConvergenceOutputConfiguration.cpp Adjusts regex tokenization to avoid MSVC initializer-list and iterator issues.
opm/simulators/flow/Banners.cpp Introduces Windows memory/user retrieval (but still needs additional Windows guards to compile).
opm/models/utils/terminal.cpp Guards signals not available on Windows/MSVC.
opm/models/utils/simulatorutils.cpp Defines S_ISDIR for MSVC where missing.
opm/models/utils/parametersystem.hpp Makes namespace stripping robust to MSVC className() prefixes.
opm/models/utils/alignedallocator.hh Uses _aligned_malloc/_aligned_free on MSVC.
opm/models/pvs/pvsprimaryvariables.hh Adds MSVC ffs() implementation via _BitScanForward.
opm/models/io/vtkmultiwriter.hh Converts path::filename() to .string() for std::string.
opm/models/tpsa/tpsamodel.hpp Rewrites chunk loop into index-based OpenMP-compatible form.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread opm/simulators/flow/Banners.cpp Outdated
Comment on lines +36 to +44
@@ -37,13 +37,29 @@
#include <thread>
#include <unistd.h>

#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#endif
Comment thread opm/simulators/flow/Banners.cpp Outdated
@@ -58,7 +74,11 @@ void printPRTHeader(const int nprocs, const int nthreads,
const double megabyte = 1024 * 1024;
unsigned num_cpu = std::thread::hardware_concurrency();
struct utsname arch;
Comment on lines 134 to 138
#if defined(_WIN32)
# undef STRICT
# undef RELAXED
#endif
enum class DebugFlags {
Comment thread opm/simulators/linalg/getQuasiImpesWeights.hpp Outdated
Comment thread opm/simulators/linalg/getQuasiImpesWeights.hpp Outdated
Comment thread opm/simulators/flow/TracerModel.hpp Outdated
Comment thread opm/simulators/flow/TracerModel.hpp Outdated
Comment thread opm/models/tpsa/tpsamodel.hpp Outdated
Comment on lines +142 to +150
if (argc > 1 && std::strcmp(argv[1], "--child") == 0) {
execute();
return 0; // execute() is expected to exit(EXIT_FAILURE) before reaching here
}
std::cout << "Checking failure of child process with parent process" << std::endl;
const intptr_t status = _spawnl(_P_WAIT, argv[0], argv[0], "--child",
static_cast<const char*>(nullptr));
assert(status == EXIT_FAILURE); // Check that the child exited with EXIT_FAILURE
}
Comment on lines 80 to 84
const char* user = getlogin();
#endif
std::time_t now = std::time(0);
struct std::tm tstruct;
char tmstr[80];
GitPaean added 9 commits July 1, 2026 23:06
- SatfuncConsistencyChecks: the std::array->std::vector change (an MSVC
  workaround) silently dropped the "violations_ always has NumLevels entries"
  invariant for moved-from objects, since moving a vector leaves it empty and a
  reused source would then index violations_[index(level)] out of bounds.
  Restore the source to NumLevels in the move ctor and move-assignment.
- NonlinearSystemBlackOilReservoir.hpp: scope the Windows STRICT/RELAXED #undef
  with #pragma push_macro/pop_macro so it no longer strips the Windows SDK
  STRICT definition from the rest of the translation unit.
…NG guard to WIN32 and reuse shared MpiFixture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

manual:irrelevant This PR is a minor fix and should not appear in the manual

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants