Skip to content
Commits on Source (5)
What:
Library, solver and utilities for avalanche modelling using finiteArea.
Author:
Matthias Rauter <matthias@rauter.it>
who kindly supplied and ported the code from the original
implementation using foam-extend to OpenFOAM-1712.
License:
Same terms as OpenFOAM.
Licensed under GNU General Public License <http://www.gnu.org/licenses/>.
This diff is collapsed.
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 Matthias Rauter
Copyright (C) 2019-2020 Matthias Rauter
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -34,10 +34,10 @@ Author
#include <sstream>
#include <limits>
#include <cmath>
// #include <cstring>
// #include <arpa/inet.h>
#include <regex>
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
gridfile::gridfile()
{
debug = 0;
......@@ -74,6 +74,9 @@ gridfile::gridfile(const double &xllcenter, const double &yllcenter,
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
gridfile::~gridfile()
{
if (v_ != nullptr)
......@@ -84,6 +87,9 @@ gridfile::~gridfile()
v_ = nullptr;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
std::ostream &gridfile::log() const
{
return std::cout;
......@@ -109,7 +115,7 @@ void gridfile::clear()
std::string gridfile::info() const
{
std::stringstream ss;
std::ostringstream ss;
ss << "Gridfile " << this->filename_ << ":" << std::endl
<< "nrows = " << this->nrows_ << std::endl
......@@ -219,8 +225,8 @@ int gridfile::read(std::string filename)
std::getline(pFile, line);
j = 0;
#if 0
// The following part is very flexible but slow
/*
while (std::regex_search (line, match, e) and j < this->ncols) {
try
{
......@@ -233,10 +239,10 @@ int gridfile::read(std::string filename)
}
line = match.suffix().str();
}
*/
#endif
//This is faster
std::stringstream ss(line);
std::istringstream ss(line);
while (j < this->ncols_) {
double val;
......
......@@ -5,7 +5,8 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 Matthias Rauter
Copyright (C) 2019-2020 Matthias Rauter
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -34,26 +35,63 @@ Author
#include <sstream>
#include <limits>
#include <cmath>
#include <string.h>
#include <arpa/inet.h>
#include <cstdint>
#include <cstring>
#include <stdexcept>
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
template <class T>
std::string vec2string(std::vector<T> v)
namespace
{
std::stringstream ss;
ss << v.size() << "(";
for (auto it = v.begin() ; it != v.end(); ++it)
// Local implementation of ntohl to avoid dependency on
// <arpa/inet.h> or <winsock.h>
//
// Compare with OpenFOAM endian::swap32()
static inline uint32_t ntohl(uint32_t u)
{
#if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
return u;
#elif (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
# ifdef __GNUC__
return __builtin_bswap32(u);
#else
return
(
(((u) & 0xff000000) >> 24) // 3 -> 0
| (((u) & 0x00ff0000) >> 8) // 2 -> 1
| (((u) & 0x0000ff00) << 8) // 2 <- 1
| (((u) & 0x000000ff) << 24) // 3 <- 0
);
#endif
#else
# error "__BYTE_ORDER__ is not BIG or LITTLE endian"
#endif
}
template<class T>
static std::string vec2string(const std::vector<T>& v)
{
std::ostringstream ss;
unsigned i = 0;
ss << v.size() << '(';
for (const T& val : v)
{
ss << *it;
if (it+1 != v.end()) ss << ",";
if (i++) ss << ',';
ss << val;
}
ss << ")";
ss << ')';
return ss.str();
}
} // End anonymous namespace
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
shapefile::shapefile(type shptype)
{
......@@ -63,6 +101,8 @@ shapefile::shapefile(type shptype)
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
int shapefile::pointcount(int recordIndex, int partIndex) const
{
if (partIndex < this->partcount(recordIndex)-1)
......@@ -298,13 +338,13 @@ void shapefile::calcBoundingBox()
std::string shapefile::info() const
{
std::stringstream ss;
std::ostringstream ss;
ss << "Shapefile " << filename_ << ":" << std::endl
<< "Type = " << shptype_ << std::endl
<< "Shape count = " << recordcount_ << std::endl
<< "Parts count = " << vec2string<int>(shapeparts_) << std::endl << std::endl;
<< "Parts count = " << vec2string<int>(shapeparts_) << std::endl
<< std::endl;
for (unsigned int i=0; i<recordcount_; i++)
{
......@@ -312,7 +352,8 @@ std::string shapefile::info() const
<< "Parts start = " << vec2string<int>(pn_[i]) << std::endl
<< "Part types = " << vec2string<int>(pt_[i]) << std::endl
<< "x-coords = " << vec2string<double>(px_[i]) << std::endl
<< "y-coords = " << vec2string<double>(py_[i]) << std::endl << std::endl;
<< "y-coords = " << vec2string<double>(py_[i]) << std::endl
<< std::endl;
}
ss << "Field count = " << fieldcount_ << std:: endl
......@@ -327,13 +368,15 @@ std::string shapefile::info() const
ss << "Field " << i << ": " << std::endl
<< "Field Name = " << fn_[i] << std::endl
<< "Field Type = " << ft_[i] << std::endl
<< "Field Legnth/Decimals = " << fl_[i] << "," << fd_[i] << std::endl << std::endl;
<< "Field Length/Decimals = " << fl_[i] << "," << fd_[i] << std::endl
<< std::endl;
}
for (unsigned int i=0; i<recordcount_; i++)
{
ss << "Field values records #" << i << " = " << vec2string<double>(v_[i]) << std::endl;
ss << "Field string records #" << i << " = " << vec2string<std::string>(c_[i]) << std::endl;
}
return ss.str();
}
......@@ -346,7 +389,9 @@ int shapefile::read(std::string filename)
std::vector<int> recordPositions;
std::ifstream input(filename+".shx", std::ios::binary);
std::ifstream input;
input.open(filename+".shx", std::ios::binary);
if (!input.is_open())
{
return 0;
......@@ -377,14 +422,12 @@ int shapefile::read(std::string filename)
input.close();
input = std::ifstream(filename+".shp", std::ios::binary );
input.open(filename+".shp", std::ios::binary);
if (!input.is_open())
{
return 0;
}
buffer = std::vector<char>(std::istreambuf_iterator<char>(input), {});
buffer = std::vector<char>(std::istreambuf_iterator<char>(input), {});
c = &buffer[0];
bufferlength = buffer.size();
......@@ -716,8 +759,7 @@ int shapefile::read(std::string filename)
input.close();
input = std::ifstream(filename+".dbf", std::ios::binary );
input.open(filename+".dbf", std::ios::binary);
if (!input.is_open())
{
return 0;
......@@ -895,7 +937,8 @@ int shapefile::write(std::string filename)
this->filename_ = filename;
std::ofstream output(filename+".shp", std::ios::binary );
std::ofstream output;
output.open(filename+".shp", std::ios::binary);
int totlength = 100;
......@@ -1003,7 +1046,7 @@ int shapefile::write(std::string filename)
uint32_t ft(ntohl(9994));
uint32_t empty(ntohl(0));
uint32_t empty(0);
uint32_t fl(ntohl(totlength/2));
uint32_t version(1000);
......@@ -1169,11 +1212,7 @@ int shapefile::write(std::string filename)
}
output.close();
output = std::ofstream(filename+".shx", std::ios::binary );
output.open(filename+".shx", std::ios::binary);
totlength = 100+this->recordcount_*8;
fl = ntohl(totlength/2);
......@@ -1208,10 +1247,7 @@ int shapefile::write(std::string filename)
output.close();
output = std::ofstream(filename+".dbf", std::ios::binary );
output.open(filename+".dbf", std::ios::binary);
uint32_t numrecords(this->recordcount_);
uint16_t headersize(33 + this->fieldcount_*32);
......
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/LogFunctions # Tutorial log-file functions
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/LogFunctions # Tutorial logfile functions
#------------------------------------------------------------------------------
echo "--------"
removeLogs
echo "Cleaning tutorials"
foamCleanTutorials cases
foamCleanTutorials -self
echo "--------"
......
#!/bin/sh
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/LogFunctions # Tutorial log-file functions
#------------------------------------------------------------------------------
# Collect log files as 'testLoopReport'
collectLogs
#------------------------------------------------------------------------------
#!/bin/sh
cd "${0%/*}" || exit # Run from this directory
## . ${WM_PROJECT_DIR:?}/bin/tools/LogFunctions # Tutorial logfile functions
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | www.openfoam.com
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2017 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
# <http://www.gnu.org/licenses/>.
#
# Script
# Allrun
#
# Description
# Run tutorial cases and summarize the outcome as 'testLoopReport'
#
#------------------------------------------------------------------------------
cd ${0%/*} || exit 1 # Run from this directory
usage()
{
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE
usage: ${0##*/} [OPTION]
options:
-collect Collect logs only. Can be useful for aborted runs.
-help print the usage
Run tutorial cases and summarize the outcome as 'testLoopReport'
USAGE
exit 1
}
#------------------------------------------------------------------------------
unset optCollectOnly
# Parse options
while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help)
usage
;;
-collect)
optCollectOnly=true
;;
-test) # Known options that should be passed through
break
;;
-*)
usage "unknown option: $1"
;;
*)
break
;;
esac
shift
done
#------------------------------------------------------------------------------
. $WM_PROJECT_DIR/bin/tools/LogFunctions # Tutorial log-file functions
# Any tests...
if [ -z "$optCollectOnly" ]
then
foamRunTutorials -skipFirst $* # Run tutorials recursively
fi
foamRunTutorials -skipFirst $* # Run tutorials recursively
collectLogs
## collectLogs
#------------------------------------------------------------------------------
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/CleanFunctions # Tutorial clean functions
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/CleanFunctions # Tutorial clean functions
#------------------------------------------------------------------------------
cleanCase0
cleanFaMesh
......
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/RunFunctions # Tutorial run functions
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions
#------------------------------------------------------------------------------
runApplication slopeMesh
......
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/RunFunctions # Tutorial run functions
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions
#------------------------------------------------------------------------------
runApplication slopeMesh
......
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/CleanFunctions # Tutorial clean functions
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/CleanFunctions # Tutorial clean functions
#------------------------------------------------------------------------------
cleanCase0
cleanFaMesh
......
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/RunFunctions # Tutorial run functions
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions
#------------------------------------------------------------------------------
runApplication slopeMesh
......
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/RunFunctions # Tutorial run functions
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions
#------------------------------------------------------------------------------
runApplication slopeMesh
......
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/CleanFunctions # Tutorial clean functions
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/CleanFunctions # Tutorial clean functions
#------------------------------------------------------------------------------
rm -rf constant/surface.stl
cleanCase0
......
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/RunFunctions # Tutorial run functions
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions
#------------------------------------------------------------------------------
runApplication gridToSTL
......
#!/bin/sh
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/CleanFunctions # Tutorial clean functions
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/CleanFunctions # Tutorial clean functions
#------------------------------------------------------------------------------
rm -rf constant/surface.stl
......
#!/bin/sh
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions
#------------------------------------------------------------------------------
runApplication gridToSTL
......
#!/bin/sh
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions
#------------------------------------------------------------------------------
runApplication gridToSTL
......@@ -17,5 +17,4 @@ runParallel $(getApplication)
runApplication reconstructPar
#------------------------------------------------------------------------------
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/CleanFunctions # Tutorial clean functions
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/CleanFunctions # Tutorial clean functions
#------------------------------------------------------------------------------
cleanCase0
cleanFaMesh
......
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/RunFunctions # Tutorial run functions
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions
#------------------------------------------------------------------------------
runApplication blockMesh
......