Skip to content

Instantly share code, notes, and snippets.

@H0R5E
Last active August 30, 2023 20:04
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save H0R5E/162ffb929d946e9ccf1c9202e30c9b92 to your computer and use it in GitHub Desktop.
Save H0R5E/162ffb929d946e9ccf1c9202e30c9b92 to your computer and use it in GitHub Desktop.
Guide and helper scripts for compiling Delft3D FM with Visual Studio 2019 and Intel oneAPI [ARCHIVED]

Delft3D Flexible Mesh Compilation

This is a short guide for compiling and testing the Delft3D Flexible Mesh solver.

Download Delft3D source code

Required Software

  1. sliksvn

First, ensure you have an username and password for the SVN repository by registering on the Delft3D website.

After registering, install sliksvn and grab the Get-Delft3D-Tag.ps1 Powershell script, provided in this repo, for downloading a Delft3D tag to a directory of your choosing (we'll call it \path\to\Delft3D-68819). Run the script from a Powershell window (as administrator) as follows:

PS > .\Get-Delft3D-Tag.ps1 68819 <user> \path\to\Delft3D-68819

Remember to replace <user> with your username. Optionally, the flag -PWD can be added with your password, otherwise you will be prompted to enter it. If you can't run the script, you might need grant yourself permissions, as follows:

PS > Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

I strongly recommended continuing with a copy of the downloaded source code, because if something goes wrong it is easier to restart with a clean copy. To make a copy at the path \path\to\Delft3D, use the svn export command:

PS > svn export \path\to\Delft3D-68819 \path\to\Delft3D

We will use this copy at \path\to\Delft3D for the remainder of this guide.

Install Anaconda, Visual Studio and the Intel FORTRAN compiler

Required Software

  1. Anaconda Python
  2. Visual Studio
  3. Intel oneAPI Base Toolkit
  4. Intel oneAPI HPC Toolkit

Follow the default installation instructions for Anaconda Python.

For Visual Studio, choose the "Desktop development with C++" workload and ensure the following additional components are selected:

  1. C++ MFC for latest v142 build tools (x86 & x64)
  2. C++/CLI support for v142 build tools (Latest)
  3. C++ Modules for v142 build tools (x64/x86 – experimental)

See the SciVision guide for installing the Intel FORTRAN compiler using Intel oneAPI.

Prepare Visual Studio Solution

First copy the prepare_sln_auto.py script into the \path\to\Delft3D\src directory.

Now, run the script from an Anaconda3 Powershell prompt (open from the Anaconda3 Start menu folder):

(base) PS > cd \path\to\Delft3D\src
(base) PS > python prepare_sln_auto.py
...
Visual Studio  Version : 2019
.Net Framework Version : v4.6.1
Intel oneAPI Version : 2021
Solution path :

Compile with Visual Studio

  1. Open Visual Studio
  2. Open the dflowfm_open.sln file in the src directory.
  3. Change the configuration from "Debug" to "Release"
  4. Change the platform from "Win32" to "x64"
  5. Select "Build Solution" from the "Build" menu
  6. Wait...

Test

Required Software

  1. dflowfm-flume

The compilation can be tested using the provided dflowfm-flume example, downloaded to some path referred to here as \path\to\dflowfm-flume. Run the example from a Powershell prompt as follows:

PS > cd \path\to\dflowfm-flume\FlowFM\input
PS > & '\path\to\Delft3D\src\bin\x64\dflowfm\scripts\run_dflowfm.bat' .\FlowFM.mdu
...
** INFO   : Opened file : DFM_OUTPUT_FlowFM\FlowFM_numlimdt.xyz
** INFO   : Closed file : DFM_OUTPUT_FlowFM\FlowFM_numlimdt.xyz
** INFO   :

Post-Process

Copy the plot_map_u.py script into the \path\to\Flume.dsproj_data\FlowFM\output directory. For the script to work, create a conda environment for dfm_tools using an Anaconda3 Powershell prompt:

(base) PS > conda create -n _delft3D -y pip python git matplotlib netCDF4 numpy pandas scipy
(base) PS > conda activate _delft3D
(_delft3D) PS > python -m pip install git+https://github.com/openearth/dfm_tools.git

Now move to the output directory and run:

(_delft3D) PS > cd \path\to\Flume.dsproj_data\FlowFM\output
(_delft3D) PS > python plot_map_u.py FlowFM_map.nc
<#
.Description
Checkout a given Delft3D-FM tag from the Delft3D SVN repository.
.PARAMETER TAG
Tag number to checkout.
.PARAMETER USERNAME
Username for accessing the Delft3D SVN repository.
.PARAMETER PATH
PATH to store checkout.
.PARAMETER PWD
Password for accessing the Delft3D SVN repository (prompted if not entered).
.INPUTS
None.
.OUTPUTS
None.
.LINK
https://gist.github.com/H0R5E/162ffb929d946e9ccf1c9202e30c9b92
.LINK
https://oss.deltares.nl/web/delft3d/source-code
#>
param ([Parameter(Mandatory=$true, Position=0)]
[int]
$TAG,
[Parameter(Mandatory=$true, Position=1)]
[String[]]
$USERNAME,
[Parameter(Mandatory=$true, Position=2)]
[String[]]
$PATH,
[String[]]
$PWD)
if ($PWD -eq $null) {
$securedPWD = Read-Host "Please enter your password" -AsSecureString
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($securedPWD)
$PWD = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)
}
svn checkout --username "$USERNAME" --password "$PWD" "https://svn.oss.deltares.nl/repos/delft3d/tags/delft3dfm/$TAG" "$PATH"
if ($LASTEXITCODE -eq 1) {
$BASE = (Get-Item -Path '.\' -Verbose).FullName
cd "$PATH"
do{
svn cleanup; svn update
} while ($LASTEXITCODE -eq 1)
cd "$BASE"
}
<#
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
#>
# -*- coding: utf-8 -*-
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
# of the public at large and to the detriment of our heirs and
# successors. We intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to this
# software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# For more information, please refer to <http://unlicense.org/>
import sys
import matplotlib.pyplot as plt
from dfm_tools.get_nc import get_netdata, plot_netmapdata, get_ncmodeldata
def main(file_nc_map):
ugrid_all = get_netdata(file_nc=file_nc_map)
data_frommap_wl = get_ncmodeldata(file_nc=file_nc_map,
varname='mesh2d_ucxa',
timestep=1)
fig, ax = plt.subplots()
pc = plot_netmapdata(ugrid_all.verts,
values=data_frommap_wl[0,:],
linewidth=0.5,
cmap="jet")
plot_netmapdata(ugrid_all.verts,
linewidth=0.5,
color="black",
facecolor="None")
pc.set_clim([-0.5,1])
fig.colorbar(pc, ax=ax)
ax.set_title('%s (%s)'%(data_frommap_wl.var_varname,
data_frommap_wl.var_ncvarobject.units))
ax.set_aspect('equal')
plt.show()
if __name__ == "__main__":
main(sys.argv[1])
# Copyright adri.mourits@deltares.nl 2017
# Copyright Mathew Topper 2020-2021
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import os
import glob
import sys
import shutil
import subprocess
import itertools
if sys.version_info < (3, 0, 0):
# To avoid problems with encoding:
# - Use codecs.open instead of open (Python 2.x only)
# - open files with encoding='utf-8' (Both Python 2.x and 3.x)
# - Do not use str(line) on lines read from file
from codecs import open as open
import _winreg as winreg
else:
import winreg
# toolsversion specifies the vs tools version
toolsversion = {}
toolsversion[2010] = "4.0"
toolsversion[2012] = "4.0"
toolsversion[2013] = "12.0"
toolsversion[2014] = "12.0"
toolsversion[2015] = "14.0"
toolsversion[2016] = "14.0"
toolsversion[2017] = "15.0"
toolsversion[2019] = "15.0"
# platformtoolset specifies the vs platform toolset version
platformtoolset = {}
platformtoolset[2010] = ""
platformtoolset[2012] = "v110"
platformtoolset[2013] = "v120"
platformtoolset[2014] = "v120"
platformtoolset[2015] = "v140"
platformtoolset[2016] = "v140"
platformtoolset[2017] = "v141"
platformtoolset[2019] = "v142"
def subkeys(path, hkey=winreg.HKEY_LOCAL_MACHINE, flags=0):
with winreg.OpenKey(hkey, path, 0, winreg.KEY_READ|flags) as k:
try:
for i in itertools.count():
yield winreg.EnumKey(k, i)
except WindowsError:
pass
def get_oneAPI_compilers_major_version():
key = "SOFTWARE\\WOW6432Node\\Intel\\1AProducts\\Compilers"
versions = []
for subkey in subkeys(key):
REG_PATH = key + "\\" + subkey
registry_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
REG_PATH,
0,
winreg.KEY_READ)
majorvalue, regtype = winreg.QueryValueEx(registry_key, "MajorVersion")
versions.append(majorvalue)
if not versions:
raise ValueError("Intel oneAPI not found")
return max(versions)
def get_vs_version():
cmd = '"%ProgramFiles(x86)%\\Microsoft Visual Studio\\Installer\\vswhere.exe"'
result = subprocess.check_output(cmd, shell=True)
lines = result.split(b"\n")
for line in lines:
words = line.split(b":")
if words[0] == b"catalog_productLineVersion":
return int(words[1])
raise ValueError("Visual Studio not found")
def get_net_version():
folder = ("C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\"
"Framework\\.NETFramework")
try:
dirlist = [item for item in os.listdir(folder) if
os.path.isdir(os.path.join(folder, item))]
except WindowsError:
dirlist = []
if not dirlist:
raise ValueError(".NET Framework Pack not found")
if "v4.X" in dirlist: dirlist.remove("v4.X")
return sorted(dirlist)[-1]
def getUCRTSDKdir(vs):
vsintalldir = "VS{}INSTALLDIR".format(vs)
getucrtdir = (
'"'
+ str(os.environ.get(vsintalldir))
+ "\\VC\\Auxiliary\\Build\\vcvarsall.bat"
+ '" amd64&&set UniversalCRTSdkDir'
)
sys.stdout.write("Trying to execute: " + getucrtdir + " ...\n")
try:
result = subprocess.check_output(getucrtdir, shell=True)
except Exception as e:
result = ""
sys.stdout.write(
"\n\n *** ERROR: Execution failed; is VisualStudio "
+ str(vs)
+ " installed?\n"
)
sys.stdout.write(" *** Python reported: " + str(e) + "\n\n")
# If python 2, decode to string
try:
result = result.decode("utf-8")
except AttributeError:
pass
ucrtpos = result.rfind("UniversalCRTSdkDir=")
if ucrtpos == -1:
# Fallback: it should be this:
sys.stdout.write("ucrtdir not found; set to default value\n")
ucrtdir = "c:\\Program Files (x86)\\Windows Kits\\10\\Lib\\"
else:
ucrtdir = result[ucrtpos + 19 :]
# Remove the trailing slash and the newline-character behind it
lastslash = ucrtdir.rfind("\\")
if lastslash != -1:
ucrtdir = ucrtdir[:lastslash]
sys.stdout.write("ucrtdir found: " + ucrtdir + "\n")
return ucrtdir
def getUCRTlibdir(vs):
ucrtlibdir = {}
ucrtlibtemplate = "$(UniversalCRTSdkDir)Lib\\{}\\ucrt\\{}"
# Only for VS2015 or higher
if vs < 2015:
return "$(OSS_UCRTLIBDIR)"
# To get the ucrt directory: execute the matching getucrtdir string,
# catch the stdout of that command,
# check whether UniversalCRTSdkDir is in that string,
# if so, get the value behind the '='-sign
ucrtdir = getUCRTSDKdir(vs)
# Search in subdir Lib for directories starting with a digit and
# containing at least one "."
searchstring = os.path.join(ucrtdir, "Lib", "[0-9]*.*")
versions = glob.glob(searchstring)
if len(versions) <= 0:
# Fallback: it should be this:
ucrtversion = "10.0.10586.0"
sys.stdout.write(
"No versions found, using default version:" + ucrtversion + "\n"
)
else:
# Choose the highest version number
versions.sort(reverse=True)
ucrtversion = versions[0]
ucrtversion = os.path.basename(ucrtversion)
sys.stdout.write("Versions found, using: " + ucrtversion + "\n")
# Inside ucrtlibdir, replace all occurences of UCRTLIBDIRVERSIONNUMBER by
# ucrtversion
ucrtlibdir[32] = str(ucrtlibtemplate).format(ucrtversion, "x86")
ucrtlibdir[64] = str(ucrtlibtemplate).format(ucrtversion, "x64")
return ucrtlibdir
# process_solution_file ====================================
# process a VisualStudio Solution File (and underlying projects)
# Pass only file names, no full path names. It assumed that both
# files are in fixed locations (see below).
def process_solution_file(sln, slntemplate, vs, fw, oa, ucrtlibdir):
# Copy the solution template file to the solution file
sys.stdout.write("Creating file " + sln + " ...\n")
scriptdir = os.path.dirname(os.path.abspath(__file__))
topdir = scriptdir
# target file:
sln = os.path.join(topdir, sln)
# source template file:
slntemplate = os.path.join(topdir, slntemplate)
shutil.copyfile(slntemplate, sln)
# Collect the project files referenced in the solution file
projectfiles = []
# Read sln file:
# Put the full file contents in filin_contents
with open(sln, "r", encoding="utf-8") as filinhandle:
filin_contents = filinhandle.readlines()
# Scan the contents and rewrite the full solution file
with open(sln, "w", encoding="utf-8") as filouthandle:
for line in filin_contents:
# Search for project file references
pp = line.split('"')
for subline in pp:
if (
max(
subline.find(".vfproj"),
subline.find(".vcxproj"),
subline.find(".vcproj"),
subline.find(".csproj"),
)
!= -1
):
projectfiles.append(subline)
# Changes to the sln file based on VS version
startpos = line.find(
"Microsoft Visual Studio Solution File, Format Version"
)
if startpos == 0:
if vs == 2010:
line = "Microsoft Visual Studio Solution File, Format Version 11.00\r\n"
elif vs == 2012:
line = "Microsoft Visual Studio Solution File, Format Version 12.00\r\n"
elif vs == 2013:
line = "Microsoft Visual Studio Solution File, Format Version 12.00\r\n"
elif vs == 2014:
line = "Microsoft Visual Studio Solution File, Format Version 12.00\r\n"
elif vs == 2015:
line = "Microsoft Visual Studio Solution File, Format Version 12.00\r\n"
elif vs == 2016:
line = "Microsoft Visual Studio Solution File, Format Version 12.00\r\n"
elif vs == 2017:
line = "Microsoft Visual Studio Solution File, Format Version 12.00\r\n"
elif vs == 2019:
line = "Microsoft Visual Studio Solution File, Format Version 12.00\r\n"
# else:
# leave line unchanged
startpos = line.find("# Visual Studio")
if startpos == 0:
if vs == 2010:
line = "# Visual Studio 2010\r\n"
elif vs == 2012:
line = "# Visual Studio 2012\r\n"
elif vs == 2013:
line = "# Visual Studio 2013\r\n"
elif vs == 2014:
line = "# Visual Studio 2014\r\n"
elif vs == 2015:
line = "# Visual Studio 2015\r\n"
elif vs == 2016:
line = "# Visual Studio 2016\r\n"
elif vs == 2017:
line = "# Visual Studio 2017\r\n"
elif vs == 2019:
line = "# Visual Studio 2019\r\n"
# else:
# leave line unchanged
filouthandle.write(line)
# Process all project files referenced in the sln file
for pfile in projectfiles:
pfile = os.path.join(topdir, pfile)
sys.stdout.write("Processing file " + pfile + " ...\n")
if os.path.isfile(pfile):
process_project_file(pfile, vs, fw, oa, ucrtlibdir)
else:
sys.stdout.write("ERROR: File does not exists:" + pfile + "\n")
sys.stdout.write("...Finished.\n")
sys.stdout.write('Ready to be used: "' + sln + '"\n')
# process_project_file ====================================
# process a VisualStudio Project File
def process_project_file(pfile,
vs,
fw,
oa,
ucrtlibdir,
remove_petsc=True):
# Type (F/C/C#) and related flags are set based on the file extension
ptype = "unknown"
config_tag = "unknown"
config_val32 = "unknown"
config_val64 = "unknown"
compilervar = "$(IFORT_COMPILER{:02})".format(oa % 100)
oneapivar = "$(ONEAPI_ROOT)"
if pfile.find("vfproj") != -1:
ptype = "fortran"
config_tag = "Configuration Name="
config_val32 = "Win32"
config_val64 = "x64"
redistdir = compilervar + "redist\\{}\\compiler\\&quot"
mkldir = oneapivar + "mkl\\latest\\redist\\{}\\&quot"
libdir = compilervar + "\\compiler\\lib\\{}"
elif pfile.find("vcxproj") != -1:
ptype = "c"
config_tag = "ItemDefinitionGroup Condition="
config_val32 = "Win32"
config_val64 = "x64"
redistdir = compilervar + "redist\\{}\\compiler\\"
mkldir = oneapivar + "mkl\\latest\\redist\\{}\\"
libdir = compilervar + "\\compiler\\lib\\{}"
elif pfile.find("vcproj") != -1 or pfile.find("csproj") != -1:
ptype = "csharp"
config_tag = "PropertyGroup Condition="
config_val32 = "x86"
config_val64 = "x64"
# Put the full file contents in filin_contents
with open(pfile, "r", encoding="utf-8") as filinhandle:
filin_contents = filinhandle.readlines()
# Scan the contents and rewrite the full file
configuration = 0
with open(pfile, "w", encoding="utf-8") as filouthandle:
fixing_petsc = False
for line in filin_contents:
# Remove petsc source file
if remove_petsc:
if 'solve_petsc.F90' in line:
fixing_petsc = True
if fixing_petsc:
startpos = line.find(
'<FileConfiguration Name="Release|x64"')
if startpos != -1:
line = line[:startpos + 37] + \
' ExcludedFromBuild="true">\n'
fixing_petsc = False
#
# ToolsVersion
# Skip this change when vs=0
if vs != 0:
startpos = line.find("ToolsVersion=")
if startpos != -1:
parts = line.split('"')
i = 0
for part in parts:
if part.find("ToolsVersion=") != -1:
parts[i + 1] = toolsversion[vs]
i += 1
line = '"'.join(parts)
# FrameworkVersion
# Skip this change when fw=0
if fw != 0:
startpos = line.find("<TargetFrameworkVersion>")
if startpos != -1:
endpos = line.find("</TargetFrameworkVersion>")
line = line[:startpos + 24] + fw + line[endpos:]
# PlatformToolSet:
# Skip this change when vs=0
# Search for line with <PlatformToolset>
if vs != 0:
startpos = line.find("<PlatformToolset>")
if startpos != -1:
endpos = line.find("</PlatformToolset>")
line = (
line[:startpos + 17]
+ platformtoolset[vs]
+ line[endpos:]
)
# config_tag, to set configuration
startpos = line.find(config_tag)
if startpos != -1:
if line.find(config_val32) != -1:
configuration = 32
arch = "ia32"
archwin = "ia32_win"
elif line.find(config_val64) != -1:
configuration = 64
arch = "intel64"
archwin = "intel64_win"
# IFORT_COMPILER ...
startpos = line.find("$(IFORT_COMPILER")
if startpos != -1:
if oa == -999:
sys.exit(
"ERROR: Fortran compiler specification is being used "
"while not defined.")
split_char = ";"
if line.find("oss-install") != -1:
#
# ... in argument of oss-install
if ptype == "c":
split_char = '"'
parts = line.split(split_char)
i = 0
lastFound = -1
it = 0
for part in parts:
lastFound = part.find(
"$(IFORT_COMPILER", lastFound + 1
)
if lastFound != -1:
tempStr = ""
while lastFound != -1:
if it == 0:
tempStr += redistdir.format(archwin)
lastFound = part.find(
"$(IFORT_COMPILER", lastFound + 1
)
elif it == 1:
tempStr += mkldir.format(arch)
lastFound = part.find(
"$(IFORT_COMPILER", lastFound + 1
)
elif it > 1:
break
it += 1
parts[i] = tempStr
i += 1
else:
parts[i] = part
i += 1
del parts[i:]
line = split_char.join(parts)
if line.find("AdditionalLibraryDirectories") != -1:
# ... in specification of AdditionalLibrarieDirectories
parts = line.split(split_char)
added = False
i = 0
for part in parts:
startpos = part.find("$(IFORT_COMPILER")
if startpos != -1:
if not added:
parts[i] = parts[i][:startpos] + libdir.format(
arch
)
added = True
i += 1
# else:
# remove this part
else:
parts[i] = part
i += 1
del parts[i:]
line = split_char.join(parts)
else:
# Unclear context of using IFORT_COMPILER
# Just replace the version number at the end
startpos = startpos + 16
endpos = startpos + 2
line = line[:startpos] + '{:02}'.format(oa % 100) + \
line[endpos:]
# UCRTlibdir
# Search string to be replaced: two options: "$(OSS_UCRTLIBDIR)"
# and "$(UniversalCRTSdkDir)lib\..."
#
# $(OSS_UCRTLIBDIR) => $(UniversalCRTSdkDir)lib\...
startpos = line.find("$(OSS_UCRTLIBDIR)")
if startpos != -1:
endpos = startpos + 17
else:
# $(UniversalCRTSdkDir)lib\... => $(OSS_UCRTLIBDIR)
startpos = line.find("$(UniversalCRTSdkDir)")
if startpos != -1:
quotepos = line[startpos:].find('"')
if quotepos == -1:
quotepos = 999
colonpos = line[startpos:].find(";")
if colonpos == -1:
colonpos = 999
endpos = startpos + min(quotepos, colonpos)
# Replace by the correct string. Assumption:
# "UCRTLIBDIRVERSIONNUMBER" is replaced by the correct
# versionnumber when applicable, by executing getUCRTlibdir
if startpos != -1:
line = (
line[:startpos] + ucrtlibdir[configuration] + line[endpos:]
)
# Remove PETSC
if remove_petsc:
startpos = line.find("HAVE_PETSC;")
if startpos != -1:
endpos = startpos + 11
line = line[:startpos] + line[endpos:]
filouthandle.write(line)
def process_cmd_file(cmd):
if not os.path.isfile(cmd): return
sys.stdout.write("Updating file " + cmd + " ...\n")
# Read cmd file:
# Put the full file contents in filin_contents
with open(cmd, "r", encoding="utf-8") as filinhandle:
filin_contents = filinhandle.readlines()
# Scan the contents and rewrite
with open(cmd, "w", encoding="utf-8") as filouthandle:
for line in filin_contents:
if ("!mkl_redist_dir!mkl_" in line and
'.1.dll' not in line): line = line.replace('.dll', '.1.dll')
filouthandle.write(line)
sys.stdout.write("...Finished.\n")
sys.stdout.write('Ready to be used: "' + cmd + '"\n')
def main(templateSolutionPath=""):
vs = get_vs_version()
fw = get_net_version()
oa = get_oneAPI_compilers_major_version()
UCRTlibdir = getUCRTlibdir(vs)
scripts64 = os.path.join("scripts_lgpl", "win64")
conf_process = lambda fout, fin: process_solution_file(fout,
fin,
vs,
fw,
oa,
UCRTlibdir)
if not templateSolutionPath:
conf_process("delft3d_open.sln",
os.path.join("scripts_lgpl",
"win64",
"delft3d_open_template.sln"))
conf_process("dflowfm_open.sln",
os.path.join("engines_gpl",
"dflowfm",
"scripts",
"template",
"dflowfm_open_template.sln"))
conf_process("dimr_open.sln",
os.path.join("engines_gpl",
"dimr",
"scripts",
"template",
"dimr_open_template.sln"))
# TODO: Consider making this optional via cmdline args:
conf_process("io_netcdf.sln",
os.path.join(scripts64, "io_netcdf_template.sln"))
conf_process("nefis.sln",
os.path.join(scripts64, "nefis_template.sln"))
conf_process("utils_lgpl.sln",
os.path.join(scripts64, "utils_lgpl_template.sln"))
conf_process("tests.sln",
os.path.join(scripts64, "tests_template.sln"))
else:
slnName = os.path.basename(templateSolutionPath).replace(
"_template", "")
conf_process(slnName, templateSolutionPath)
conf_process("ec_module.sln",
os.path.join(scripts64, "ec_module_template.sln"))
process_cmd_file(os.path.join(scripts64, "oss-post_build.cmd"))
process_cmd_file(os.path.join(scripts64, "oss-install_x64.cmd"))
sys.stdout.write("\n")
sys.stdout.write("Visual Studio Version : " + str(vs) + "\n")
sys.stdout.write(".Net Framework Version : " + str(fw) + "\n")
sys.stdout.write("Intel oneAPI Version : " + str(oa) + "\n")
sys.stdout.write("Solution path : " + templateSolutionPath + "\n")
return
if __name__ == "__main__":
main()
@H0R5E
Copy link
Author

H0R5E commented Nov 11, 2021

@elappala, better to have the discussion here I think. I was confused because you were posting under the Compiling Deflt3D using Windows Subsystem for Linux README. I'm going to delete the comments there, as they are not relevant.

So, regarding your question:

Your git post is for delft3dfm - I assume I can follow the same process for the other Delft3D kernels (water quality, etc?
If you have the scripts to prepare the solutions for them I would appreciate them

There should be another solution file named delft3d_open.sln in the src directory and this solution should compile the other modules.

@elappala
Copy link

elappala commented Nov 11, 2021 via email

@elappala
Copy link

elappala commented Nov 16, 2021 via email

@H0R5E
Copy link
Author

H0R5E commented Nov 16, 2021

Eric, I don't think you can send attachments through email; you'd have to use the web interface. Anyway, I'm not sure I would be much help if the cause is oneAPI installation errors. The only thing I can think of is making sure that you install Visual Studio before oneAPI or it won't integrate properly.

One option to try is that if you've got a compiled version on one machine, the files should be portable to another (assuming both virtual machines use the same architecture).

@GEMSS3D
Copy link

GEMSS3D commented Aug 14, 2022

Hi Matthew,
First of all, many thanks for providing such videos. It is always a challenge to compile DELF3TD codes unless one follows it up regularly with updates and forums etc. I recently reviewed your youtube video to use oneapi with delf3d codes. I followed your steps and I am having problems with full compilation. When I checked, what is happening is all files with extension .svn are not getting used properly resulting in not able to find related .rc, .h or .f90 files. I had to manually do the checks. I put it in the user forum and some one pointed me that it could be oneapi version. I was using 2022 version. I uninstalled 2022 version and installed 2021.2 version and I still have the same problem. I could not anaconda python to run your solution.py file. I have to use another python version such as arcgis. This is the only difference between your approach and my approach.

Can you please suggest as what the problem could be? Thanks. Venkat

@H0R5E
Copy link
Author

H0R5E commented Aug 16, 2022

@GEMSS3D, I'm afraid that this guide is now out of date, as Deltares have moved to using CMake to build Delft3D FM. Can I recommend that you read the official guide.

Sorry I can't be more help. I am going to archive this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment