diff --git a/.gitignore b/.gitignore index 4a9dc6f..93537e8 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,9 @@ pyvnt.egg-info manual_tests/ manual_debug/ +linux64GccDPInt32Opt/ +bin/ + **/__pycache__/* .vscode pyrightconfig.json @@ -20,6 +23,8 @@ __pycache__/ # C extensions *.so +*.dep +*.o # Distribution / packaging .Python diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..a3fc1b4 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,4 @@ +include pyvnt/Converter/Reader/cpp_src/dictionaryFile/lib/dictionaryFile.so +include pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/bin/dictionaryFileChecker.so +include pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/lib/dictionaryFileIterator.so +include pyvnt/Converter/Reader/cpp_src/libOpenFOAM.so diff --git a/pyvnt/Converter/Reader/__init__.py b/pyvnt/Converter/Reader/__init__.py new file mode 100644 index 0000000..4efecc8 --- /dev/null +++ b/pyvnt/Converter/Reader/__init__.py @@ -0,0 +1,68 @@ + +import os +from pyvnt.Container.node import Node_C +from .dictionaryFileIterator import DictionaryFileIterator +from .dictionaryFile import DictionaryFile + + +def read(filepath : str, verifyFile: bool = True) -> Node_C: + ''' + Reads dictionary file from the given filepath and returns a node tree + representation of it. + ''' + file = DictionaryFile(filepath, verifyFile) + itr = DictionaryFileIterator(file) + + path = file.filepath + + root_name = path.split('/')[-1] + # print(root_name) + + root = _createTree(root_name, itr) + itr.close() + file.close() + + return root + + +def _createTree(parentName: str, itr: DictionaryFileIterator) -> Node_C: + ''' + Recursively traverse the openfoam's dictionary data structure and create the + node-tree structure. + ''' + data = {} + while itr.hasEntry(): + key = itr.getCurrentEntryKeyword() + value = None + + # print(f"{key}, {itr.isCurrentEntryList()}") + + if itr.isCurrentEntryDict(): + # print(key) + itr.stepIn() + value = _createTree(key, itr) + itr.stepOut() + else: + value = itr.getKeyData() + # print(value) + + print(key) + # print(f"{key}, {type(value)}") + data[key] = value + itr.step() + + # create node + children = [] + itms = [] + + for key, val in data.items(): + if isinstance(val,Node_C): + children.append(val) + else: + itms.append(val) + + node = Node_C(parentName, None, children, *itms) + + return node + + diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFile/Make/files b/pyvnt/Converter/Reader/cpp_src/dictionaryFile/Make/files new file mode 100644 index 0000000..4117b6e --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFile/Make/files @@ -0,0 +1,4 @@ + +dictionaryFile.C + +LIB = ./lib/dictionaryFile \ No newline at end of file diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFile/Make/options b/pyvnt/Converter/Reader/cpp_src/dictionaryFile/Make/options new file mode 100644 index 0000000..47589bc --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFile/Make/options @@ -0,0 +1,4 @@ + +LIB_LIBS = \ + -L$FOAM_LIBBIN \ + -lOpenFOAM \ No newline at end of file diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFile/dictionaryFile.C b/pyvnt/Converter/Reader/cpp_src/dictionaryFile/dictionaryFile.C new file mode 100644 index 0000000..3207520 --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFile/dictionaryFile.C @@ -0,0 +1,48 @@ + +#include "fileName.H" +#include "IFstream.H" +#include "dictionary.H" + +#include "dictionaryFile.H" +#include "dictionaryFile_PythonInterface.H" + + +DictionaryFile::DictionaryFile(const char* filepath) +{ + Foam::fileName dictPath(filepath); + Foam::IFstream dictFileStream(dictPath); + mDictPtr = new Foam::dictionary(dictFileStream); +} + +DictionaryFile::~DictionaryFile() +{ + delete mDictPtr; +} + +// void DictionaryFile::printEntry(const char* key) +// { +// Foam::word keyname(key); +// std::cout +// << "dictionaryName : " << mDictPtr->name().toAbsolute() << " " +// << mDictPtr->lookupEntry(keyname, false, false).keyword() +// << std::endl; +// } + +// API FUNCTIONS=============================================================== +void* openDictionaryFile(const char* filepath) +{ + DictionaryFile* dictFile = new DictionaryFile(filepath); + return dictFile; +} + +void closeDictionaryFile(void* dictionaryFile) +{ + DictionaryFile* dictFile = static_cast(dictionaryFile); + delete dictFile; +} + +// void printDictionary(void* dictionaryFile) +// { +// DictionaryFile* dictFile = static_cast(dictionaryFile); +// dictFile->printEntry("key1"); +// } \ No newline at end of file diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFile/dictionaryFile.H b/pyvnt/Converter/Reader/cpp_src/dictionaryFile/dictionaryFile.H new file mode 100644 index 0000000..5217481 --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFile/dictionaryFile.H @@ -0,0 +1,15 @@ + +#pragma once + + +class DictionaryFile +{ +public: + Foam::dictionary* mDictPtr; + + DictionaryFile(const char* filepath); + ~DictionaryFile(); + // void* getIterator(); + // void printEntry(const char* key); +}; + diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFile/dictionaryFile_PythonInterface.H b/pyvnt/Converter/Reader/cpp_src/dictionaryFile/dictionaryFile_PythonInterface.H new file mode 100644 index 0000000..85c4649 --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFile/dictionaryFile_PythonInterface.H @@ -0,0 +1,14 @@ + +#pragma once + + +extern "C" +{ + +void* openDictionaryFile(const char* filepath); +void closeDictionaryFile(void* dictionaryFile); +// void* getIterator(void* dictionaryFile); +// void printDictionary(void* dictionaryFile); +} + + diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFile/lnInclude/dictionaryFile.C b/pyvnt/Converter/Reader/cpp_src/dictionaryFile/lnInclude/dictionaryFile.C new file mode 120000 index 0000000..d94fe62 --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFile/lnInclude/dictionaryFile.C @@ -0,0 +1 @@ +../dictionaryFile.C \ No newline at end of file diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFile/lnInclude/dictionaryFile.H b/pyvnt/Converter/Reader/cpp_src/dictionaryFile/lnInclude/dictionaryFile.H new file mode 120000 index 0000000..0d6cdd0 --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFile/lnInclude/dictionaryFile.H @@ -0,0 +1 @@ +../dictionaryFile.H \ No newline at end of file diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFile/lnInclude/dictionaryFile_PythonInterface.H b/pyvnt/Converter/Reader/cpp_src/dictionaryFile/lnInclude/dictionaryFile_PythonInterface.H new file mode 120000 index 0000000..0176c31 --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFile/lnInclude/dictionaryFile_PythonInterface.H @@ -0,0 +1 @@ +../dictionaryFile_PythonInterface.H \ No newline at end of file diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/Make/files b/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/Make/files new file mode 100644 index 0000000..b3e0f01 --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/Make/files @@ -0,0 +1,4 @@ + +dictionaryFileChecker.C + +EXE = ./bin/dictionaryFileChecker \ No newline at end of file diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/Make/linux64GccDPInt32Opt/dictionaryFileChecker.C.dep b/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/Make/linux64GccDPInt32Opt/dictionaryFileChecker.C.dep new file mode 100644 index 0000000..d538d41 --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/Make/linux64GccDPInt32Opt/dictionaryFileChecker.C.dep @@ -0,0 +1,278 @@ +$(OBJECTS_DIR)/dictionaryFileChecker.C.dep: \ +dictionaryFileChecker.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/fileName.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IFstream.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/dictionary.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/word.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/fileNameI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ISstream.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/className.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/entry.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IDLList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DLList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/HashTable.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ITstream.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/wordReList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Pair.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/dictionaryTemplates.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/string.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/wordI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Istream.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DynamicList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ISstreamI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/defineDebugSwitch.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/keyType.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/autoPtr.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ILList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DLListBase.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/label.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/uLabel.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/HashTableI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/HashTable.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/tokenList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/wordRe.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/List.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/FixedList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/primitiveEntry.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/char.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Hasher.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/stringI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IOstream.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/token.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DynamicListI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DynamicList.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/debug.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/functionName.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/variable.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/keyTypeI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/autoPtrI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UILList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ILList.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/bool.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DLListBaseI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LList.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/int.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/labelSpecific.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/uint.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/error.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Tuple2.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/HashTableIO.C \ +$(WM_PROJECT_DIR)/src/OSspecific/POSIX/lnInclude/regExp.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/wordReI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ListI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/List.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Hash.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/FixedListI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/FixedList.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/InfoProxy.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/primitiveEntryTemplates.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/scalar.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/verbatimString.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/refCount.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/typeInfo.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/runTimeSelectionTables.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/tokenI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/functionNameI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/variableI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UILList.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ILListIO.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/pTraits.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/direction.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LListIO.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/int32.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/int64.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/uint32.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/uint64.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/messageStream.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/errorManip.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Ostream.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/nullObject.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/zero.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UListI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UList.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ListLoopM.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/PtrList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/SLList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IndirectList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UIndirectList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/BiIndirectList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/contiguous.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ListIO.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/FixedListIO.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IStringStream.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/OStringStream.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/floatScalar.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/doubleScalar.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/longDoubleScalar.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/verbatimStringI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UILListIO.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/INew.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/OSstream.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/nullObjectI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/zeroI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Swap.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UListIO.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UPtrList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/PtrListI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/PtrList.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/SLListBase.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IndirectListI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UIndirectListI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UIndirectListIO.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/BiIndirectListI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/doubleFloat.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Scalar.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/OSstreamI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UPtrListI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UPtrList.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/tmp.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/SLPtrList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/PtrListIO.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/SLListBaseI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/products.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UPtrListIO.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/tmpI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LPtrList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LPtrList.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LPtrListIO.C \ + +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/fileName.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IFstream.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/dictionary.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/word.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/fileNameI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ISstream.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/className.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/entry.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IDLList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DLList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/HashTable.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ITstream.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/wordReList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Pair.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/dictionaryTemplates.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/string.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/wordI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Istream.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DynamicList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ISstreamI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/defineDebugSwitch.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/keyType.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/autoPtr.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ILList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DLListBase.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/label.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/uLabel.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/HashTableI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/HashTable.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/tokenList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/wordRe.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/List.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/FixedList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/primitiveEntry.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/char.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Hasher.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/stringI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IOstream.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/token.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DynamicListI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DynamicList.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/debug.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/functionName.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/variable.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/keyTypeI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/autoPtrI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UILList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ILList.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/bool.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DLListBaseI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LList.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/int.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/labelSpecific.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/uint.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/error.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Tuple2.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/HashTableIO.C : +$(WM_PROJECT_DIR)/src/OSspecific/POSIX/lnInclude/regExp.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/wordReI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ListI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/List.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Hash.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/FixedListI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/FixedList.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/InfoProxy.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/primitiveEntryTemplates.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/scalar.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/verbatimString.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/refCount.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/typeInfo.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/runTimeSelectionTables.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/tokenI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/functionNameI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/variableI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UILList.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ILListIO.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/pTraits.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/direction.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LListIO.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/int32.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/int64.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/uint32.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/uint64.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/messageStream.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/errorManip.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Ostream.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/nullObject.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/zero.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UListI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UList.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ListLoopM.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/PtrList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/SLList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IndirectList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UIndirectList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/BiIndirectList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/contiguous.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ListIO.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/FixedListIO.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IStringStream.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/OStringStream.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/floatScalar.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/doubleScalar.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/longDoubleScalar.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/verbatimStringI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UILListIO.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/INew.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/OSstream.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/nullObjectI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/zeroI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Swap.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UListIO.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UPtrList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/PtrListI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/PtrList.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/SLListBase.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IndirectListI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UIndirectListI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UIndirectListIO.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/BiIndirectListI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/doubleFloat.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Scalar.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/OSstreamI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UPtrListI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UPtrList.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/tmp.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/SLPtrList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/PtrListIO.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/SLListBaseI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/products.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UPtrListIO.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/tmpI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LPtrList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LPtrList.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LPtrListIO.C : + diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/Make/linux64GccDPInt32Opt/dictionaryFileChecker.o b/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/Make/linux64GccDPInt32Opt/dictionaryFileChecker.o new file mode 100644 index 0000000..c6af2c6 Binary files /dev/null and b/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/Make/linux64GccDPInt32Opt/dictionaryFileChecker.o differ diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/Make/linux64GccDPInt32Opt/files b/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/Make/linux64GccDPInt32Opt/files new file mode 100644 index 0000000..386f14a --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/Make/linux64GccDPInt32Opt/files @@ -0,0 +1,4 @@ + +SOURCE += dictionaryFileChecker.C + +EXE = ./bin/dictionaryFileChecker \ No newline at end of file diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/Make/options b/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/Make/options new file mode 100644 index 0000000..7f9fcd2 --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/Make/options @@ -0,0 +1,5 @@ + + +EXE_LIBS = \ + -L$FOAM_LIBBIN \ + -lOpenFOAM \ No newline at end of file diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/bin/dictionaryFileChecker b/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/bin/dictionaryFileChecker new file mode 100755 index 0000000..f97572e Binary files /dev/null and b/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/bin/dictionaryFileChecker differ diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/dictionaryFileChecker.C b/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/dictionaryFileChecker.C new file mode 100644 index 0000000..d08d22f --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFileChecker/dictionaryFileChecker.C @@ -0,0 +1,54 @@ + +#include "fileName.H" +#include "IFstream.H" +#include "dictionary.H" + + +Foam::dictionary* dictPtr = nullptr; + + +bool openDictionary(const char* filepath); +void closeDictionary(); + + +int main(int argc, char* argv[]){ + + if( argc != 2 ){ + return 1; + } + + bool isOpen = openDictionary(argv[1]); + closeDictionary(); + + return (isOpen ? 0 : 1); +} + + +bool openDictionary(const char* filepath) +{ + if( dictPtr != nullptr ) + { + closeDictionary(); + } + + Foam::fileName dictPath(filepath); + Foam::IFstream dictFileStream(dictPath); + + if( dictFileStream.closed() or dictFileStream.bad() ) + { + return false; + } + + dictPtr = new Foam::dictionary(dictFileStream); + return true; +} + + +void closeDictionary() +{ + if( dictPtr != nullptr ) + { + delete dictPtr; + dictPtr = nullptr; + } +} \ No newline at end of file diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/Make/files b/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/Make/files new file mode 100644 index 0000000..29166f8 --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/Make/files @@ -0,0 +1,3 @@ +dictionaryFileIterator.C + +LIB = ./lib/dictionaryFileIterator \ No newline at end of file diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/Make/options b/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/Make/options new file mode 100644 index 0000000..e11a1db --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/Make/options @@ -0,0 +1,7 @@ + +EXE_INC = \ + -I../dictionaryFile + +LIB_LIBS = \ + -L$FOAM_LIBBIN \ + -lOpenFOAM \ No newline at end of file diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/dictionaryFileIterator.C b/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/dictionaryFileIterator.C new file mode 100644 index 0000000..f697f56 --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/dictionaryFileIterator.C @@ -0,0 +1,395 @@ + +#include +#include + +#include "fileName.H" +#include "IFstream.H" +#include "dictionary.H" +#include "token.H" + +#include "dictionaryFile.H" +#include "dictionaryFileIterator.H" +#include "dictionaryFileIterator_PythonInterface.H" + + +inline DictionaryFileIterator* toDictionaryFileIteratorPtr(void* dictFileItr) +{ + return static_cast(dictFileItr); +} + +// ============================================================================ +// Python Interface Functions +// ============================================================================ +void* createIterator(void* dictFilePtr) +{ + DictionaryFile* dictFile = static_cast(dictFilePtr); + DictionaryFileIterator* itr = new DictionaryFileIterator(dictFile); + return itr; +} + +void deleteIterator(void* dictFileItr) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + delete itr; +} + +bool hasEntry(void* dictFileItr) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->hasEntry(); +} + +bool step(void* dictFileItr) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->step(); +} + +bool stepIn(void* dictFileItr) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->stepIn(); +} + +bool stepOut(void* dictFileItr) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->stepOut(); +} + +const char* getCurrentEntryKeyword(void* dictFileItr) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->getCurrentEntryKeyword(); +} + +bool isCurrentEntryDict(void* dictFileItr) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->isCurrentEntryDict(); +} + +bool isCurrentEntryList(void* dictFileItr) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->isCurrentEntryList(); +} + +int getCurrentEntryValueCount(void* dictFileItr) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->getCurrentEntryValueCount(); +} + +int getCurrentEntryValueTypeAt(void* dictFileItr, int index) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->getCurrentEntryValueTypeAt(index); +} + +const char* getCurrentEntryValueAt_String(void* dictFileItr, int index) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->getCurrentEntryValueAt_String(index); +} + +char getCurrentEntryValueAt_Character(void* dictFileItr, int index) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->getCurrentEntryValueAt_Character(index); +} + +int getCurrentEntryValueAt_Integer(void* dictFileItr, int index) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->getCurrentEntryValueAt_Integer(index); +} + +float getCurrentEntryValueAt_Float(void* dictFileItr, int index) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->getCurrentEntryValueAt_Float(index); +} + +double getCurrentEntryValueAt_Double(void* dictFileItr, int index) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->getCurrentEntryValueAt_Double(index); +} + +long double getCurrentEntryValueAt_LongDouble(void* dictFileItr, int index) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->getCurrentEntryValueAt_LongDouble(index); +} + + + + +// ============================================================================ +// DictionaryFileIterator Functions +// ============================================================================ + +DictionaryFileIterator::DictionaryFileIterator(DictionaryFile* dictFile) +{ + mDictFilePtr = dictFile; + + Foam::dictionary* dictPtr = dictFile->mDictPtr; + mDictStack.push(std::make_pair(dictPtr, dictPtr->begin())); +} + +DictionaryFileIterator::~DictionaryFileIterator() +{ + mDictFilePtr = nullptr; +} + +const Foam::token& DictionaryFileIterator::getCurrentEntryTokenAt(int index) +{ + if( index < 0 or mDictStack.empty() ) + return UNDEFINED_TOKEN; + + dictInfo& top = mDictStack.top(); + Foam::dictionary* currDictPtr = top.first; + Foam::dictionary::iterator& currIter = top.second; + + if( currIter == currDictPtr->end() ) + return UNDEFINED_TOKEN; + + if( currIter().isDict() ) + return UNDEFINED_TOKEN; + + if( index >= currIter().stream().size() ) + return UNDEFINED_TOKEN; + + Foam::tokenList& tokens = currIter().stream(); + return tokens[index]; +} + +bool DictionaryFileIterator::hasEntry() +{ + if( mDictStack.empty() ) + return false; + + dictInfo& top = mDictStack.top(); + Foam::dictionary* currDictPtr = top.first; + Foam::dictionary::iterator& currIter = top.second; + + return (currIter != currDictPtr->end()); +} + +bool DictionaryFileIterator::step() +{ + if( mDictStack.empty() ) + return false; + + dictInfo& top = mDictStack.top(); + Foam::dictionary* currDictPtr = top.first; + Foam::dictionary::iterator& currIter = top.second; + + if( currIter == currDictPtr->end() ) + return false; + + ++currIter; + + if( currIter == currDictPtr->end() ) + return false; + + return true; +} + +bool DictionaryFileIterator::stepIn() +{ + if( mDictStack.empty() ) + return false; + + dictInfo& top = mDictStack.top(); + Foam::dictionary* currDictPtr = top.first; + Foam::dictionary::iterator& currIter = top.second; + + if( currIter == currDictPtr->end() ) + return false; + + if( not currIter().isDict() ) + return false; + + Foam::dictionary* subDictPtr = currDictPtr->subDictPtr(currIter().keyword()); + mDictStack.push(std::make_pair(subDictPtr, subDictPtr->begin())); + return true; +} + +bool DictionaryFileIterator::stepOut() +{ + if( mDictStack.empty() ) + return false; + + // to disallow stepping out of root dictionary. + if( mDictStack.size() == 1 ) + return false; + + mDictStack.pop(); + + return true; +} + +const char* DictionaryFileIterator::getCurrentEntryKeyword() +{ + if( mDictStack.empty() ) + return EMPTY_STRING; + + dictInfo& top = mDictStack.top(); + Foam::dictionary* currDictPtr = top.first; + Foam::dictionary::iterator& currIter = top.second; + + if( currIter == currDictPtr->end() ) + return EMPTY_STRING; + + return currIter().keyword().c_str(); +} + +bool DictionaryFileIterator::isCurrentEntryDict() +{ + if( mDictStack.empty() ) + return false; + + dictInfo& top = mDictStack.top(); + Foam::dictionary* currDictPtr = top.first; + Foam::dictionary::iterator& currIter = top.second; + + if( currIter == currDictPtr->end() ) + return false; + + return currIter().isDict(); +} + +bool DictionaryFileIterator::isCurrentEntryList() +{ + if( mDictStack.empty() ) + return false; + + dictInfo& top = mDictStack.top(); + Foam::dictionary* currDictPtr = top.first; + Foam::dictionary::iterator& currIter = top.second; + + if( currIter == currDictPtr->end() ) + return false; + + return currIter().isDict(); +} + +int DictionaryFileIterator::getCurrentEntryValueCount() +{ + if( mDictStack.empty() ) + return 0; + + dictInfo& top = mDictStack.top(); + Foam::dictionary* currDictPtr = top.first; + Foam::dictionary::iterator& currIter = top.second; + + if( currIter == currDictPtr->end() ) + return 0; + + if( currIter().isDict() ) + return 0; + + return currIter().stream().size(); +} + +int DictionaryFileIterator::getCurrentEntryValueTypeAt(int index) +{ + const Foam::token& tkn = getCurrentEntryTokenAt(index); + int type = UNDEFINED; + + switch( tkn.type() ) + { + case Foam::token::tokenType::WORD: + type = STRING; + break; + + case Foam::token::tokenType::STRING: + type = STRING; + break; + + case Foam::token::tokenType::VERBATIMSTRING: + type = STRING; + break; + + case Foam::token::tokenType::FUNCTIONNAME: + type = STRING; + break; + + case Foam::token::tokenType::VARIABLE: + type = STRING; + break; + + case Foam::token::tokenType::LABEL: + type = INTEGER; + break; + + case Foam::token::tokenType::FLOAT_SCALAR: + type = FLOAT; + break; + + case Foam::token::tokenType::DOUBLE_SCALAR: + type = DOUBLE; + break; + + case Foam::token::tokenType::LONG_DOUBLE_SCALAR: + type = LONG_DOUBLE; + break; + + case Foam::token::tokenType::PUNCTUATION: + type = PUNCTUATION; + break; + + case Foam::token::tokenType::UNDEFINED: + type = UNDEFINED; + break; + + case Foam::token::tokenType::ERROR: + type = UNDEFINED; + break; + + case Foam::token::tokenType::COMPOUND: + type = UNDEFINED; + break; + } + + return type; +} + +const char* DictionaryFileIterator::getCurrentEntryValueAt_String(int index) +{ + const Foam::token& tkn = getCurrentEntryTokenAt(index); + return tkn.anyStringToken().c_str(); +} + +char DictionaryFileIterator::getCurrentEntryValueAt_Character(int index) +{ + const Foam::token& tkn = getCurrentEntryTokenAt(index); + return tkn.pToken(); +} + +int DictionaryFileIterator::getCurrentEntryValueAt_Integer(int index) +{ + const Foam::token& tkn = getCurrentEntryTokenAt(index); + return tkn.labelToken(); +} + +float DictionaryFileIterator::getCurrentEntryValueAt_Float(int index) +{ + const Foam::token& tkn = getCurrentEntryTokenAt(index); + return tkn.floatScalarToken(); +} + +double DictionaryFileIterator::getCurrentEntryValueAt_Double(int index) +{ + const Foam::token& tkn = getCurrentEntryTokenAt(index); + return tkn.doubleScalarToken(); +} + +long double DictionaryFileIterator::getCurrentEntryValueAt_LongDouble(int index) +{ + const Foam::token& tkn = getCurrentEntryTokenAt(index); + return tkn.doubleScalarToken(); +} + diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/dictionaryFileIterator.H b/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/dictionaryFileIterator.H new file mode 100644 index 0000000..8ca8885 --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/dictionaryFileIterator.H @@ -0,0 +1,39 @@ +#pragma once + + +typedef std::pair dictInfo; +const char* EMPTY_STRING = ""; +Foam::token UNDEFINED_TOKEN = Foam::token::undefinedToken; + + +class DictionaryFileIterator +{ +public: + DictionaryFileIterator(DictionaryFile* dictPtr); + ~DictionaryFileIterator(); + + bool hasEntry(); + bool step(); + bool stepIn(); + bool stepOut(); + + const char* getCurrentEntryKeyword(); + bool isCurrentEntryDict(); + bool isCurrentEntryList(); + int getCurrentEntryValueCount(); + int getCurrentEntryValueTypeAt(int index); + + const char* getCurrentEntryValueAt_String(int index); + char getCurrentEntryValueAt_Character(int index); + int getCurrentEntryValueAt_Integer(int index); + float getCurrentEntryValueAt_Float(int index); + double getCurrentEntryValueAt_Double(int index); + long double getCurrentEntryValueAt_LongDouble(int index); + +private: + DictionaryFile* mDictFilePtr; + std::stack mDictStack; + + const Foam::token& getCurrentEntryTokenAt(int index); +}; + diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/dictionaryFileIterator_PythonInterface.H b/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/dictionaryFileIterator_PythonInterface.H new file mode 100644 index 0000000..0134d2d --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/dictionaryFileIterator_PythonInterface.H @@ -0,0 +1,36 @@ + +extern "C" +{ + +enum ValueType{ + STRING = 0, + INTEGER, + FLOAT, + DOUBLE, + LONG_DOUBLE, + PUNCTUATION, + UNDEFINED, +}; + +void* createIterator(void* dictFilePtr); +void deleteIterator(void* dictFileItr); + +bool hasEntry(void* dictFileItr); +bool step(void* dictFileItr); +bool stepIn(void* dictFileItr); +bool stepOut(void* dictFileItr); + +const char* getCurrentEntryKeyword(void* dictFileItr); +bool isCurrentEntryDict(void* dictFileItr); +bool isCurrentEntryList(void* dictFileItr); +int getCurrentEntryValueCount(void* dictFileItr); +int getCurrentEntryValueTypeAt(void* dictFileItr, int index); + +const char* getCurrentEntryValueAt_String(void* dictFileItr, int index); +char getCurrentEntryValueAt_Character(void* dictFileItr, int index); +int getCurrentEntryValueAt_Integer(void* dictFileItr, int index); +float getCurrentEntryValueAt_Float(void* dictFileItr, int index); +double getCurrentEntryValueAt_Double(void* dictFileItr, int index); +long double getCurrentEntryValueAt_LongDouble(void* dictFileItr, int index); + +} \ No newline at end of file diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/lnInclude/dictionaryFileIterator.C b/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/lnInclude/dictionaryFileIterator.C new file mode 120000 index 0000000..197be33 --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/lnInclude/dictionaryFileIterator.C @@ -0,0 +1 @@ +../dictionaryFileIterator.C \ No newline at end of file diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/lnInclude/dictionaryFileIterator.H b/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/lnInclude/dictionaryFileIterator.H new file mode 120000 index 0000000..3f461a7 --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/lnInclude/dictionaryFileIterator.H @@ -0,0 +1 @@ +../dictionaryFileIterator.H \ No newline at end of file diff --git a/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/lnInclude/dictionaryFileIterator_PythonInterface.H b/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/lnInclude/dictionaryFileIterator_PythonInterface.H new file mode 120000 index 0000000..d10e8a4 --- /dev/null +++ b/pyvnt/Converter/Reader/cpp_src/dictionaryFileIterator/lnInclude/dictionaryFileIterator_PythonInterface.H @@ -0,0 +1 @@ +../dictionaryFileIterator_PythonInterface.H \ No newline at end of file diff --git a/pyvnt/Converter/Reader/dictionaryFile.py b/pyvnt/Converter/Reader/dictionaryFile.py new file mode 100644 index 0000000..89374c2 --- /dev/null +++ b/pyvnt/Converter/Reader/dictionaryFile.py @@ -0,0 +1,56 @@ + +import os, errno + +from . import fileUtils +from .sharedLibs import DictionaryFileLib +from .exceptions import ( + InvalidDictionaryFileError, + ClosedDictionaryFileError, +) + + +class DictionaryFile: + def __init__(self, filepath: str, verifyFile: bool = True): + self.filepath = os.path.abspath(filepath) + + if not os.path.isfile(self.filepath): + raise FileNotFoundError( + errno.ENOENT, + os.strerror(errno.ENOENT), + self.filepath + ) + + if verifyFile: + isValid, error = fileUtils.verifyDictionaryFile(self.filepath) + if not isValid: + raise InvalidDictionaryFileError(self.filepath, error) + + self.__codec = 'ascii' + self.__fileptr = DictionaryFileLib.openDictionaryFile( + bytes(self.filepath, self.__codec) + ) + + def close(self): + ''' + Closes the file by deleting the C++ DictionaryFile object from memory. + ''' + if self.__fileptr is None: + raise ClosedDictionaryFileError(self.filepath) + + DictionaryFileLib.closeDictionaryFile(self.__fileptr) + self.__fileptr = None + + def isOpen(self) -> bool: + ''' + Check if file is open or not. + ''' + return self.__fileptr is not None + + def getFilePointer(self) -> int: + ''' + Get the pointer to C++ DictionaryFile object. + ''' + if not self.isOpen(): + raise ClosedDictionaryFileError(self.filepath) + return self.__fileptr + diff --git a/pyvnt/Converter/Reader/dictionaryFileIterator.py b/pyvnt/Converter/Reader/dictionaryFileIterator.py new file mode 100644 index 0000000..7dc8310 --- /dev/null +++ b/pyvnt/Converter/Reader/dictionaryFileIterator.py @@ -0,0 +1,366 @@ + +from enum import Enum +from pyvnt import ( + Key_C, + Int_P, + Flt_P, + Str_P, + Enm_P, + Dim_Set_P, + List_CP, + Value_P +) + +from .exceptions import ( + InvalidTraversalOperation, + ClosedDictionaryFileError, + ClosedDictionaryFileIteratorError, + IteratorOutOfRange, + InvalidPrimitiveEntryOperation, + InvalidDictionaryEntryOperation, +) +from .sharedLibs import DictionaryFileIteratorLib +from .dictionaryFile import DictionaryFile + + +INT_MIN = -99999999 +INT_MAX = 99999999 +CODEC = 'ascii' + + +class ValueType(Enum): + STRING = 0 + INTEGER = 1 + FLOAT = 2 + DOUBLE = 3 + LONG_DOUBLE = 4 + PUNCTUATION = 5 + UNDEFINED = 6 + + +class DictionaryFileIterator: + ''' + A uni-directional, read-only iterator to recursively traverse the OpenFOAM's + dictionary structure. It traverses the structure entry by entry. Dictionary + entries can be stepped in and stepped out of and primitive entries(non + dictionary entries) can be read. + ''' + def __init__(self, file: DictionaryFile): + self.file = file + if not file.isOpen(): + raise ClosedDictionaryFileError(self.file.filepath) + self.__iteratorPtr = DictionaryFileIteratorLib.createIterator( + self.file.getFilePointer() + ) + + def __checkValidity(self): + ''' + Checks if the iterator and file are open or not. + ''' + if not self.file.isOpen(): + raise ClosedDictionaryFileError(self.file.filepath) + if not self.isOpen(): + raise ClosedDictionaryFileIteratorError + + def close(self): + ''' + Closes the iterator. + ''' + if self.__iteratorPtr is None: + raise ClosedDictionaryFileIteratorError + DictionaryFileIteratorLib.deleteIterator(self.__iteratorPtr) + self.__iteratorPtr = None + + def isOpen(self) -> bool: + ''' + Checks if iterator is open or not. + ''' + return self.__iteratorPtr is not None + + def hasEntry(self) -> bool: + ''' + Checks if the iterator is currently pointing to an entry or not. + ''' + self.__checkValidity() + return DictionaryFileIteratorLib.hasEntry(self.__iteratorPtr) + + def step(self): + ''' + Moves the iterator to the next entry in current dictionary. For the last + entry in a dictionary moves the iterator out of range. + Raises an error if called when iterator is out of range. + ''' + self.__checkValidity() + if not self.hasEntry(): + raise IteratorOutOfRange + DictionaryFileIteratorLib.step(self.__iteratorPtr) + + def stepIn(self): + ''' + Steps into a dictionary entry and moves the iterator to first entry in it. + Raises an error if iterator is out of range. + Raises an error if current entry is not a dictionary entry. + ''' + self.__checkValidity() + if not self.hasEntry(): + raise IteratorOutOfRange + + if not self.isCurrentEntryDict(): + raise InvalidPrimitiveEntryOperation + + DictionaryFileIteratorLib.stepIn(self.__iteratorPtr) + + def stepOut(self): + ''' + Steps out from current dictionary and moves the iterator to the entry in + parent dictionary from where step in occured. + Raises an error when stepping out of root dictionary. + ''' + self.__checkValidity() + stepOutOccured = DictionaryFileIteratorLib.stepOut(self.__iteratorPtr) + + if not stepOutOccured: + raise InvalidTraversalOperation( + 'Cannot step out of root dictionary.' + ) + + def getCurrentEntryKeyword(self) -> str: + ''' + Returns a string representing the name of the key of current entry. + Raises an error if the iterator is out of range. + ''' + self.__checkValidity() + + if not self.hasEntry(): + raise IteratorOutOfRange + + keyword = str( + DictionaryFileIteratorLib.getCurrentEntryKeyword(self.__iteratorPtr), + CODEC + ) + + return keyword + + def isCurrentEntryDict(self) -> bool: + ''' + Checks if current entry is a 'dictionary entry' or a 'primitive entry(non + dictionary entry).' + Raises an error if iterator is out of range. + ''' + self.__checkValidity() + + if not self.hasEntry(): + raise IteratorOutOfRange + + return DictionaryFileIteratorLib.isCurrentEntryDict(self.__iteratorPtr) + + def isCurrentEntryList(self) -> bool: + ''' + Checks if current entry is a 'list entry' or a 'primitive entry(non + dictionary entry).' + Raises an error if iterator is out of range. + ''' + self.__checkValidity() + + if not self.hasEntry(): + raise IteratorOutOfRange + + return DictionaryFileIteratorLib.isCurrentEntryList(self.__iteratorPtr) + + def getValues(self) -> list[Value_P]: + ''' + Returns a list of 'Value_P' objects for the values in current entry. + Raises an error if iterator is out of range. + Raises an error if current entry is not primitive entry. + ''' + self.__checkValidity() + + if not self.hasEntry(): + raise IteratorOutOfRange + + if self.isCurrentEntryDict(): + raise InvalidDictionaryEntryOperation + + stack = [[]] + + for index in range(self.__getCurrentEntryValueCount()): + val = self.__getValueAt(index) + if val == '(' or val == '[': + stack.append([]) + elif val == ')': + popped = stack.pop() + prop = List_CP(f'val{index+1}', elems=[popped]) + stack[-1].append(prop) + elif val == ']': + popped = tuple(stack.pop()) + prop = Dim_Set_P(f'val{index+1}', popped) + stack[-1].append(prop) + # elif val == '{': + # stack.append([]) # TODO: Figure out to iterate thtough dictionaries nested inside a list + # elif val == '}': + # popped = tuple(stack.pop()) + # prop = Enm_P(f'val{index+1}', popped) + # stack[-1].append(prop) + elif val == ',': + pass + else: + prop = self.__getValuePropertyAt(index) + stack[-1].append(prop) + # print(stack) + + return stack[0] + + def getRawValues(self) -> list: + ''' + Return list of raw python objects for the values in current entry. + ''' + self.__checkValidity() + return [val.giveVal() for val in self.getValues()] + + def getKeyData(self) -> Key_C: + ''' + Returns 'Key_C' object for the current entry. + Raises an error if iterator is out of range. + Raises an error if current entry is not primitive entry. + ''' + self.__checkValidity() + + if not self.hasEntry(): + raise IteratorOutOfRange + + if self.isCurrentEntryDict(): + raise InvalidDictionaryEntryOperation + + key = self.getCurrentEntryKeyword() + values = self.getValues() + + # print(f"key: {key}, values: {values}") + return Key_C(key, *values) + + def __getCurrentEntryValueCount(self) -> int: + ''' + Returns the number of value tokens in the current entry. The tokens also + includes characters like comma(,) and brackets((),[]). + ''' + return DictionaryFileIteratorLib.getCurrentEntryValueCount(self.__iteratorPtr) + + def __getCurrentEntryValueTypeAt(self, index: int) -> ValueType: + ''' + Returns the ValueType of token at a given index in values of an entry. + ''' + valType = ValueType( + DictionaryFileIteratorLib.getCurrentEntryValueTypeAt( + self.__iteratorPtr, + index + ) + ) + return valType + + def __getCurrentEntryValueAt_String(self, index : int) -> str: + ''' + Get token at given index as a 'str'. + The ValueType of this token should be of type 'str'. + ''' + val = DictionaryFileIteratorLib.getCurrentEntryValueAt_String( + self.__iteratorPtr, + index + ) + + return str(val, CODEC) + + def __getCurrentEntryValueAt_Character(self, index : int) -> str: + ''' + Get token at given index as a 'character'. + The ValueType of this token should be of type 'character'. + ''' + val = DictionaryFileIteratorLib.getCurrentEntryValueAt_Character( + self.__iteratorPtr, + index + ) + return str(val, CODEC) + + def __getCurrentEntryValueAt_Integer(self, index : int) -> int: + ''' + Get token at given index as a 'integer'. + The ValueType of this token should be of type 'integer' + ''' + return DictionaryFileIteratorLib.getCurrentEntryValueAt_Integer( + self.__iteratorPtr, + index + ) + + def __getCurrentEntryValueAt_Float(self, index : int) -> float: + ''' + Get token at given index as a 'float'. + The ValueType of this token should be of type 'float' + ''' + return DictionaryFileIteratorLib.getCurrentEntryValueAt_Float( + self.__iteratorPtr, + index + ) + + def __getCurrentEntryValueAt_Double(self, index : int) -> float: + ''' + Get token at given index as a 'float'. + The ValueType of this token should be of type 'float' + ''' + return DictionaryFileIteratorLib.getCurrentEntryValueAt_Double( + self.__iteratorPtr, + index + ) + + def __getCurrentEntryValueAt_LongDouble(self, index : int) -> float: + ''' + Get token at given index as a 'float'. + The ValueType of this token should be of type 'float' + ''' + return DictionaryFileIteratorLib.getCurrentEntryValueAt_LongDouble( + self.__iteratorPtr, + index + ) + + def __getValueAt(self, index : int, valType: ValueType = None): + ''' + Returns a python object for value at the given index. + ''' + if valType is None: + valType = self.__getCurrentEntryValueTypeAt(index) + value = None + + if valType == ValueType.STRING: + value = self.__getCurrentEntryValueAt_String(index) + elif valType == ValueType.PUNCTUATION: + value = self.__getCurrentEntryValueAt_Character(index) + # print(f"Punctuation 1 here: {value}") + elif valType == ValueType.INTEGER: + value = self.__getCurrentEntryValueAt_Integer(index) + elif valType == ValueType.FLOAT: + value = self.__getCurrentEntryValueAt_Float(index) + elif valType == ValueType.DOUBLE: + value = self.__getCurrentEntryValueAt_Double(index) + elif valType == ValueType.LONG_DOUBLE: + value = self.__getCurrentEntryValueAt_LongDouble(index) + + # print(value) + + return value + + def __getValuePropertyAt(self, index : int) -> Value_P: + ''' + Returns a Value_P object for value at the given index. + ''' + valType = self.__getCurrentEntryValueTypeAt(index) + val = self.__getValueAt(index, valType) + + if valType == ValueType.INTEGER: + return Int_P(f'val{index+1}', val, INT_MIN, INT_MAX) + + if valType == ValueType.FLOAT or \ + valType == ValueType.DOUBLE or \ + valType == ValueType.LONG_DOUBLE: + return Flt_P(f'val{index+1}', val, float('-inf'), float('inf')) + + if valType == ValueType.STRING: + return Enm_P(f'val{index+1}', {val}, val) + + return Str_P(f'val{index+1}', 'Invalid') diff --git a/pyvnt/Converter/Reader/exceptions.py b/pyvnt/Converter/Reader/exceptions.py new file mode 100644 index 0000000..f060dd2 --- /dev/null +++ b/pyvnt/Converter/Reader/exceptions.py @@ -0,0 +1,66 @@ + + +class InvalidDictionaryFileError(Exception): + ''' + Invalid syntax in Dictionary File. + ''' + def __init__(self, filepath: str, openfoamErrorMessage: str): + self.filepath = filepath + self.openfoamErrorMessage = openfoamErrorMessage + + def __str__(self): + return f"Error occured while parsing the file : {self.filepath}\n {self.openfoamErrorMessage}" + + +class InvalidTraversalOperation(Exception): + ''' + Generic Invalid Traversal Operation. + ''' + def __init__(self, msg: str): + self.msg = msg + + def __str__(self): + return self.msg + + +class ClosedDictionaryFileError(Exception): + ''' + Dictionary File closed. + ''' + def __init__(self, filepath: str): + self.filepath = filepath + + def __str__(self): + return f"Cannot operate on a closed file : {self.filepath}" + + +class ClosedDictionaryFileIteratorError(Exception): + ''' + DictionaryFileIterator closed. + ''' + def __str__(self): + return f"Cannot operate with a closed iterator" + + +class IteratorOutOfRange(Exception): + ''' + DictionaryFileIterator is out of range. + ''' + def __str__(self): + return f"Iterator has moved beyond last entry in current dictionary" + + +class InvalidPrimitiveEntryOperation(Exception): + ''' + Invalid operation for a primitive entry. + ''' + def __str__(self): + return f"Invalid operation for primitive entry" + + +class InvalidDictionaryEntryOperation(Exception): + ''' + Invalid operation for a dictionary entry. + ''' + def __str__(self): + return "Invalid operation for dictionary entry" \ No newline at end of file diff --git a/pyvnt/Converter/Reader/fileUtils.py b/pyvnt/Converter/Reader/fileUtils.py new file mode 100644 index 0000000..3391970 --- /dev/null +++ b/pyvnt/Converter/Reader/fileUtils.py @@ -0,0 +1,22 @@ + +import os +import subprocess as sp + + +EXECUTABLE_PATH = os.path.join( + os.path.dirname(__file__), + 'cpp_src/dictionaryFileChecker/bin/dictionaryFileChecker' +) + + +def verifyDictionaryFile(filepath : str) -> tuple[bool, str]: + ''' + Checks if the given file follows the syntax of OpenFOAM's dictionary files. + Uses the custom utility 'dictionaryFileChecker' in a subprocess. The call to + this function is blocking as it waits for the subprocess to exit. + ''' + args = (EXECUTABLE_PATH, filepath) + res = sp.run(args, stdout=sp.PIPE, stderr=sp.STDOUT) + isValid = (res.returncode == 0) and (len(res.stdout) == 0) + output = str(res.stdout, encoding='ascii') + return (isValid, output) diff --git a/pyvnt/Converter/Reader/reader_tests/dicts/allPossibleValuesDict b/pyvnt/Converter/Reader/reader_tests/dicts/allPossibleValuesDict new file mode 100644 index 0000000..46925d2 --- /dev/null +++ b/pyvnt/Converter/Reader/reader_tests/dicts/allPossibleValuesDict @@ -0,0 +1,8 @@ + + +key1 word1 word2 "string1"; +key2 12 -35; +key3 1.23 1e-05 1e-25 1e+25; +key4 ( 4, 2, 5 ); +key5 [ 0, 1, 0, 0, 0, 0, 0 ]; +key6 ; diff --git a/pyvnt/Converter/Reader/reader_tests/dicts/duplicateEntryDict b/pyvnt/Converter/Reader/reader_tests/dicts/duplicateEntryDict new file mode 100644 index 0000000..3ed5cf5 --- /dev/null +++ b/pyvnt/Converter/Reader/reader_tests/dicts/duplicateEntryDict @@ -0,0 +1,9 @@ + + +key1 value1 value2; + +key2 value1 value2; + +key1 value3; + + diff --git a/pyvnt/Converter/Reader/reader_tests/dicts/emptyDict b/pyvnt/Converter/Reader/reader_tests/dicts/emptyDict new file mode 100644 index 0000000..e69de29 diff --git a/pyvnt/Converter/Reader/reader_tests/dicts/fvSchemes b/pyvnt/Converter/Reader/reader_tests/dicts/fvSchemes new file mode 100644 index 0000000..a527b84 --- /dev/null +++ b/pyvnt/Converter/Reader/reader_tests/dicts/fvSchemes @@ -0,0 +1,57 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 10 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + location "system"; + object fvSchemes; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +ddtSchemes +{ + default Euler; +} + +gradSchemes +{ + default Gauss linear; +} + +divSchemes +{ + default none; + div(phi,U) Gauss upwind; + div(phid,p) Gauss upwind; + div(phi,K) Gauss linear; + div(phi,k) Gauss upwind; + div(phi,epsilon) Gauss upwind; + div(U) Gauss linear; + div(((rho*nuEff)*dev2(T(grad(U))))) Gauss linear; + div(phi,Yi_h) Gauss upwind; +} + +laplacianSchemes +{ + default Gauss linear orthogonal; +} + +interpolationSchemes +{ + default linear; +} + +snGradSchemes +{ + default orthogonal; +} + + + +// ************************************************************************* // diff --git a/pyvnt/Converter/Reader/reader_tests/dicts/increasingValueCountDict b/pyvnt/Converter/Reader/reader_tests/dicts/increasingValueCountDict new file mode 100644 index 0000000..12727fc --- /dev/null +++ b/pyvnt/Converter/Reader/reader_tests/dicts/increasingValueCountDict @@ -0,0 +1,5 @@ + + +key1 val1; +key2 val1 val2; +key3 (val2); \ No newline at end of file diff --git a/pyvnt/Converter/Reader/reader_tests/dicts/invalidDict b/pyvnt/Converter/Reader/reader_tests/dicts/invalidDict new file mode 100644 index 0000000..d671291 --- /dev/null +++ b/pyvnt/Converter/Reader/reader_tests/dicts/invalidDict @@ -0,0 +1,6 @@ + + +key1 value1; + +5 9; + diff --git a/pyvnt/Converter/Reader/reader_tests/dicts/simpleDict b/pyvnt/Converter/Reader/reader_tests/dicts/simpleDict new file mode 100644 index 0000000..39a4c7e --- /dev/null +++ b/pyvnt/Converter/Reader/reader_tests/dicts/simpleDict @@ -0,0 +1,44 @@ + + +key1 25; + +key2 35.8 67; + +key3 value1; + +<<<<<<< HEAD +<<<<<<< HEAD +// key5 +// ( +// key30 +// { +// key31 value1; +// key32 value2; +// } +// ); + +key6 +( + value3 , value4 , value5 +); + +======= +>>>>>>> acb2eb0 (fixed merge conflict) +======= +>>>>>>> 2a673f5 (fixed merge conflict) +key4 +{ + key41 value1; +} + + + + +<<<<<<< HEAD +<<<<<<< HEAD +======= + +>>>>>>> acb2eb0 (fixed merge conflict) +======= + +>>>>>>> 2a673f5 (fixed merge conflict) diff --git a/pyvnt/Converter/Reader/reader_tests/dicts/singleDictionaryEntryContainingSinglePrimitiveEntryDict b/pyvnt/Converter/Reader/reader_tests/dicts/singleDictionaryEntryContainingSinglePrimitiveEntryDict new file mode 100644 index 0000000..ec506e1 --- /dev/null +++ b/pyvnt/Converter/Reader/reader_tests/dicts/singleDictionaryEntryContainingSinglePrimitiveEntryDict @@ -0,0 +1,6 @@ + + +key1 +{ + key1 value; +} \ No newline at end of file diff --git a/pyvnt/Converter/Reader/reader_tests/dicts/singleEmptyDictionaryEntryDict b/pyvnt/Converter/Reader/reader_tests/dicts/singleEmptyDictionaryEntryDict new file mode 100644 index 0000000..4cdaf5c --- /dev/null +++ b/pyvnt/Converter/Reader/reader_tests/dicts/singleEmptyDictionaryEntryDict @@ -0,0 +1,5 @@ + +key1 +{ + +} \ No newline at end of file diff --git a/pyvnt/Converter/Reader/reader_tests/dicts/singlePrimitiveEntryDict b/pyvnt/Converter/Reader/reader_tests/dicts/singlePrimitiveEntryDict new file mode 100644 index 0000000..d70b285 --- /dev/null +++ b/pyvnt/Converter/Reader/reader_tests/dicts/singlePrimitiveEntryDict @@ -0,0 +1,3 @@ + + +key1 val1; \ No newline at end of file diff --git a/pyvnt/Converter/Reader/reader_tests/dicts/testDictionary b/pyvnt/Converter/Reader/reader_tests/dicts/testDictionary new file mode 100644 index 0000000..58cb34e --- /dev/null +++ b/pyvnt/Converter/Reader/reader_tests/dicts/testDictionary @@ -0,0 +1,37 @@ + + +key1 word1; + +key2 word1 word2 word3; + +key3 "string1" word2; + +key4 12 -35; + +key5 1.23 1e+24 1e-05 1e-25 1e+25; + +key6 ( 4, 2, 5 ); + +key8 [ 0, 1, 0, 0, 0, 0, 0 ]; + +key9 +{ + key1 value1; + key2 value2; + key3 + { + key1 value1; + key2 + { + key1 value1; + key2 value2; + } + } +} + +key10 +{ +} + +key11 ((1,2,3),(4,5,6),(7,8,9)); + diff --git a/pyvnt/Converter/Reader/reader_tests/dicts/twoPrimitiveEntryDict b/pyvnt/Converter/Reader/reader_tests/dicts/twoPrimitiveEntryDict new file mode 100644 index 0000000..3e09d90 --- /dev/null +++ b/pyvnt/Converter/Reader/reader_tests/dicts/twoPrimitiveEntryDict @@ -0,0 +1,4 @@ + + +key1 value1; +key2 value2; \ No newline at end of file diff --git a/pyvnt/Converter/Reader/reader_tests/dicts/warnDict b/pyvnt/Converter/Reader/reader_tests/dicts/warnDict new file mode 100644 index 0000000..4537310 --- /dev/null +++ b/pyvnt/Converter/Reader/reader_tests/dicts/warnDict @@ -0,0 +1,3 @@ + +[1,2]; + diff --git a/pyvnt/Converter/Reader/reader_tests/printDict.py b/pyvnt/Converter/Reader/reader_tests/printDict.py new file mode 100644 index 0000000..e037bbc --- /dev/null +++ b/pyvnt/Converter/Reader/reader_tests/printDict.py @@ -0,0 +1,35 @@ + +import os +import sys +<<<<<<< HEAD +<<<<<<< HEAD +from pyvnt import read, show_tree, writeTo +======= +from pyvnt import read +>>>>>>> acb2eb0 (fixed merge conflict) +======= +from pyvnt import read +>>>>>>> 2a673f5 (fixed merge conflict) + + +dictFilesFolder = os.path.join(os.path.dirname(__file__), 'dicts') +dictFile = os.path.join(dictFilesFolder, 'simpleDict') + + +if len(sys.argv) > 1: + dictFile = os.path.join(dictFilesFolder, sys.argv[1]) + +<<<<<<< HEAD +<<<<<<< HEAD +tree = read(dictFile) + +show_tree(tree) +writeTo(tree, 'reader_test') +======= +tree = dw.read(dictFile) +tree.dispTree() +>>>>>>> acb2eb0 (fixed merge conflict) +======= +tree = dw.read(dictFile) +tree.dispTree() +>>>>>>> 2a673f5 (fixed merge conflict) diff --git a/pyvnt/Converter/Reader/reader_tests/test_DictionaryFile.py b/pyvnt/Converter/Reader/reader_tests/test_DictionaryFile.py new file mode 100644 index 0000000..076e446 --- /dev/null +++ b/pyvnt/Converter/Reader/reader_tests/test_DictionaryFile.py @@ -0,0 +1,55 @@ + +import os +import unittest +import dictionarywrapper.exceptions as dwexception +from dictionarywrapper.dictionaryFile import DictionaryFile + + +DICT_FOLDER = os.path.join(os.path.dirname(__file__), 'dicts/') + + +class TestDictionaryFile(unittest.TestCase): + + def test_init_for_non_existing_file(self): + filepath = '' + with self.assertRaises(FileNotFoundError): + DictionaryFile(filepath) + + def test_init_for_invalid_dictionary_file(self): + filepath = os.path.join(DICT_FOLDER, 'invalidDict') + with self.assertRaises(dwexception.InvalidDictionaryFileError): + DictionaryFile(filepath) + + def test_init_for_warning_dictionary_file(self): + filepath = os.path.join(DICT_FOLDER, 'warnDict') + with self.assertRaises(dwexception.InvalidDictionaryFileError): + DictionaryFile(filepath) + + def test_isOpen(self): + filepath = os.path.join(DICT_FOLDER, 'simpleDict') + file = DictionaryFile(filepath) + self.assertIsInstance(file.isOpen(), bool) + self.assertTrue(file.isOpen()) + file.close() + self.assertIsInstance(file.isOpen(), bool) + self.assertFalse(file.isOpen()) + + def test_close(self): + filepath = os.path.join(DICT_FOLDER, 'simpleDict') + file = DictionaryFile(filepath) + file.close() + self.assertFalse(file.isOpen()) + with self.assertRaises(dwexception.ClosedDictionaryFileError): + file.close() + + def test_getFilePointer(self): + filepath = os.path.join(DICT_FOLDER, 'simpleDict') + file = DictionaryFile(filepath) + self.assertIsInstance(file.getFilePointer(), int) + self.assertNotEqual(0, file.getFilePointer()) + file.close() + with self.assertRaises(dwexception.ClosedDictionaryFileError): + file.getFilePointer() + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/pyvnt/Converter/Reader/reader_tests/test_DictionaryFileIterator.py b/pyvnt/Converter/Reader/reader_tests/test_DictionaryFileIterator.py new file mode 100644 index 0000000..3d82704 --- /dev/null +++ b/pyvnt/Converter/Reader/reader_tests/test_DictionaryFileIterator.py @@ -0,0 +1,86 @@ +# todo : tests for all methods for dictionaryFileIterator + +import os +import unittest + +from pyvnt import PropertyString, PropertyInt, PropertyFloat + +import dictionarywrapper.exceptions as dwexception +from dictionarywrapper.dictionaryFileIterator import DictionaryFileIterator +from dictionarywrapper.dictionaryFile import DictionaryFile + +DICT_FOLDER = os.path.join(os.path.dirname(__file__), 'dicts/') + + +class TestDictionaryFileIterator(unittest.TestCase): + + @classmethod + def setUpClass(cls): + filesToOpen = [ + 'simpleDict', + 'emptyDict', + 'singlePrimitiveEntryDict', + 'twoPrimitiveEntryDict', + ] + cls.files = {} + + for file in filesToOpen: + cls.files[file] = DictionaryFile(os.path.join(DICT_FOLDER, file)) + + @classmethod + def tearDownClass(cls): + for file in cls.files.values(): + file.close() + + def test_init_on_closed_file(self): + file = DictionaryFile(os.path.join(DICT_FOLDER, 'simpleDict')) + file.close() + with self.assertRaises(dwexception.ClosedDictionaryFileError): + DictionaryFileIterator(file) + + def test_init_on_open_file(self): + itr = DictionaryFileIterator(TestDictionaryFileIterator.files['simpleDict']) + self.assertIsInstance(itr.file, DictionaryFile) + self.assertIsInstance(itr._DictionaryFileIterator__iteratorPtr, int) + self.assertNotEqual(itr._DictionaryFileIterator__iteratorPtr, 0) + + def test_private_checkValidity(self): + # check for closed iterator + itr1 = DictionaryFileIterator(TestDictionaryFileIterator.files['simpleDict']) + itr1.close() + with self.assertRaises(dwexception.ClosedDictionaryFileIteratorError): + itr1._DictionaryFileIterator__checkValidity() + + # check for closed file + file = DictionaryFile(os.path.join(DICT_FOLDER, 'simpleDict')) + itr2 = DictionaryFileIterator(file) + file.close() + with self.assertRaises(dwexception.ClosedDictionaryFileError): + itr2._DictionaryFileIterator__checkValidity() + + # check for valid case which is - open file and open iterator + itr3 = DictionaryFileIterator(TestDictionaryFileIterator.files['simpleDict']) + self.assertEqual(itr3._DictionaryFileIterator__checkValidity(), None) + + def test_isOpen(self): + itr = DictionaryFileIterator(TestDictionaryFileIterator.files['simpleDict']) + self.assertIsInstance(itr.isOpen(), bool) + self.assertTrue(itr.isOpen()) + itr.close() + self.assertIsInstance(itr.isOpen(), bool) + self.assertFalse(itr.isOpen()) + + def test_close(self): + itr = DictionaryFileIterator(TestDictionaryFileIterator.files['simpleDict']) + itr.close() + self.assertFalse(itr.isOpen()) + with self.assertRaises(dwexception.ClosedDictionaryFileIteratorError): + itr.close() + + def test_hasEntry(self): + pass + + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/pyvnt/Converter/Reader/reader_tests/test_fileUtils.py b/pyvnt/Converter/Reader/reader_tests/test_fileUtils.py new file mode 100644 index 0000000..2fec3ae --- /dev/null +++ b/pyvnt/Converter/Reader/reader_tests/test_fileUtils.py @@ -0,0 +1,43 @@ + +import os +import unittest +import dictionarywrapper.fileUtils as fileUtils + +DICT_FOLDER = os.path.join(os.path.dirname(__file__), 'dicts/') + + +class TestFileUtils(unittest.TestCase): + + def test_invalid_dictionary_file(self): + filepath = os.path.join(DICT_FOLDER, 'invalidDict') + res = fileUtils.verifyDictionaryFile(filepath) + self.assertIsInstance(res, tuple) + isValid, error = res + self.assertIsInstance(isValid, bool) + self.assertFalse(isValid) + self.assertIsInstance(error, str) + self.assertNotEqual(len(error), 0) + + def test_warning_dictionary_file(self): + filepath = os.path.join(DICT_FOLDER, 'warnDict') + res = fileUtils.verifyDictionaryFile(filepath) + self.assertIsInstance(res, tuple) + isValid, error = res + self.assertIsInstance(isValid, bool) + self.assertFalse(isValid) + self.assertIsInstance(error, str) + self.assertNotEqual(len(error), 0) + + def test_valid_dictionary_file(self): + filepath = os.path.join(DICT_FOLDER, 'simpleDict') + res = fileUtils.verifyDictionaryFile(filepath) + self.assertIsInstance(res, tuple) + isValid, error = res + self.assertIsInstance(isValid, bool) + self.assertTrue(isValid) + self.assertIsInstance(error, str) + self.assertEqual(len(error), 0) + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/pyvnt/Converter/Reader/sharedLibs.py b/pyvnt/Converter/Reader/sharedLibs.py new file mode 100644 index 0000000..7a94f54 --- /dev/null +++ b/pyvnt/Converter/Reader/sharedLibs.py @@ -0,0 +1,154 @@ + + +import ctypes +import os + + +class DictionaryFileLib: + _libFilePath = os.path.join( + os.path.dirname(__file__), + "cpp_src/dictionaryFile/lib/dictionaryFile.so" + ) + _lib = ctypes.CDLL(_libFilePath) + openDictionaryFile = _lib.openDictionaryFile + closeDictionaryFile = _lib.closeDictionaryFile + +# _function_signature_dict = { +# 'openDictionaryFile' : (ctypes.c_char_p, ctypes.c_void_p), +# 'closeDictionaryFile' : (ctypes.c_void_p, None) +# } + + +# _libs = [DictionaryFileLib] + +# for lib in _libs: +# func_names = [attr for attr in dir(lib) if not attr.startswith('_')] +# print(func_names) +# for func in func_names: +# if func in lib._function_signature_dict: +# argtypes, restype = lib._function_signature_dict[func] +# lib.__dict__[func].argtypes = argtypes +# lib.__dict__[func].restype = restype + + + +DictionaryFileLib.openDictionaryFile.argtypes = [ctypes.c_char_p] +DictionaryFileLib.openDictionaryFile.restype = ctypes.c_void_p + +DictionaryFileLib.closeDictionaryFile.argtypes = [ctypes.c_void_p] +DictionaryFileLib.closeDictionaryFile.restype = None + + + +class DictionaryFileIteratorLib: + _libFilePath = os.path.join( + os.path.dirname(__file__), + "cpp_src/dictionaryFileIterator/lib/dictionaryFileIterator.so" + ) + _lib = ctypes.CDLL(_libFilePath) + createIterator = _lib.createIterator + deleteIterator = _lib.deleteIterator + hasEntry = _lib.hasEntry + step = _lib.step + stepIn = _lib.stepIn + stepOut = _lib.stepOut + getCurrentEntryKeyword = _lib.getCurrentEntryKeyword + isCurrentEntryDict = _lib.isCurrentEntryDict + isCurrentEntryList = _lib.isCurrentEntryList + getCurrentEntryValueCount = _lib.getCurrentEntryValueCount + getCurrentEntryValueTypeAt = _lib.getCurrentEntryValueTypeAt + getCurrentEntryValueAt_String = _lib.getCurrentEntryValueAt_String + getCurrentEntryValueAt_Character = _lib.getCurrentEntryValueAt_Character + getCurrentEntryValueAt_Integer = _lib.getCurrentEntryValueAt_Integer + getCurrentEntryValueAt_Float = _lib.getCurrentEntryValueAt_Float + getCurrentEntryValueAt_Double = _lib.getCurrentEntryValueAt_Double + getCurrentEntryValueAt_LongDouble = _lib.getCurrentEntryValueAt_LongDouble + + +DictionaryFileIteratorLib.createIterator.argtypes = [ctypes.c_void_p] +DictionaryFileIteratorLib.createIterator.restype = ctypes.c_void_p + +DictionaryFileIteratorLib.deleteIterator.argtypes = [ctypes.c_void_p] +DictionaryFileIteratorLib.deleteIterator.restype = None + +DictionaryFileIteratorLib.hasEntry.argtypes = [ctypes.c_void_p] +DictionaryFileIteratorLib.hasEntry.restype = ctypes.c_bool + +DictionaryFileIteratorLib.step.argtypes = [ctypes.c_void_p] +DictionaryFileIteratorLib.step.restype = ctypes.c_bool + +DictionaryFileIteratorLib.stepIn.argtypes = [ctypes.c_void_p] +DictionaryFileIteratorLib.stepIn.restype = ctypes.c_bool + +DictionaryFileIteratorLib.stepOut.argtypes = [ctypes.c_void_p] +DictionaryFileIteratorLib.stepOut.restype = ctypes.c_bool + +DictionaryFileIteratorLib.getCurrentEntryKeyword.argtypes = [ctypes.c_void_p] +DictionaryFileIteratorLib.getCurrentEntryKeyword.restype = ctypes.c_char_p + +DictionaryFileIteratorLib.isCurrentEntryDict.argtypes = [ctypes.c_void_p] +DictionaryFileIteratorLib.isCurrentEntryDict.restype = ctypes.c_bool + +DictionaryFileIteratorLib.isCurrentEntryList.argtypes = [ctypes.c_void_p] +DictionaryFileIteratorLib.isCurrentEntryList.restype = ctypes.c_bool + + +DictionaryFileIteratorLib.getCurrentEntryValueCount.argtypes = [ + ctypes.c_void_p +] +DictionaryFileIteratorLib.getCurrentEntryValueCount.restype = ctypes.c_int + + +DictionaryFileIteratorLib.getCurrentEntryValueTypeAt.argtypes = [ + ctypes.c_void_p, + ctypes.c_int +] +DictionaryFileIteratorLib.getCurrentEntryValueTypeAt.restype = ctypes.c_int + + +DictionaryFileIteratorLib.getCurrentEntryValueAt_String.argtypes = [ + ctypes.c_void_p, + ctypes.c_int +] +DictionaryFileIteratorLib.getCurrentEntryValueAt_String.restype \ + = ctypes.c_char_p + + +DictionaryFileIteratorLib.getCurrentEntryValueAt_Character.argtypes = [ + ctypes.c_void_p, + ctypes.c_int +] +DictionaryFileIteratorLib.getCurrentEntryValueAt_Character.restype \ + = ctypes.c_char + + +DictionaryFileIteratorLib.getCurrentEntryValueAt_Integer.argtypes = [ + ctypes.c_void_p, + ctypes.c_int +] +DictionaryFileIteratorLib.getCurrentEntryValueAt_Integer.restype \ + = ctypes.c_int + + +DictionaryFileIteratorLib.getCurrentEntryValueAt_Float.argtypes = [ + ctypes.c_void_p, + ctypes.c_int +] +DictionaryFileIteratorLib.getCurrentEntryValueAt_Float.restype \ + = ctypes.c_float + + +DictionaryFileIteratorLib.getCurrentEntryValueAt_Double.argtypes = [ + ctypes.c_void_p, + ctypes.c_int +] +DictionaryFileIteratorLib.getCurrentEntryValueAt_Double.restype \ + = ctypes.c_double + + +DictionaryFileIteratorLib.getCurrentEntryValueAt_LongDouble.argtypes = [ + ctypes.c_void_p, + ctypes.c_int +] +DictionaryFileIteratorLib.getCurrentEntryValueAt_LongDouble.restype \ + = ctypes.c_longdouble diff --git a/pyvnt/Converter/Writer/writer.py b/pyvnt/Converter/Writer/writer.py index b3f632f..0862232 100644 --- a/pyvnt/Converter/Writer/writer.py +++ b/pyvnt/Converter/Writer/writer.py @@ -22,7 +22,7 @@ def writeTo(root, path): ''' file_name = root.name - ptt = r".txt$" + ptt = r"$.txt" if re.search(ptt, file_name): raise ValueError("File name cannot have .txt extension") diff --git a/pyvnt/Reference/error_classes.py b/pyvnt/Reference/error_classes.py index 5db3495..62dd668 100755 --- a/pyvnt/Reference/error_classes.py +++ b/pyvnt/Reference/error_classes.py @@ -106,4 +106,11 @@ def __init__(self, length: int): def __str__(self): return f"Length of values should be 7. Length of given list is {self.length}" +class VersionError(Exception): + def __init__(self, version: str): + self.version = version + + def __str__(self): + return f"Version {self.version} does not match supported version" + diff --git a/pyvnt/__init__.py b/pyvnt/__init__.py index e652ef8..6ed0824 100755 --- a/pyvnt/__init__.py +++ b/pyvnt/__init__.py @@ -9,3 +9,5 @@ from pyvnt.utils import * from pyvnt.utils.show_tree import * +from pyvnt.Converter.Reader import read + diff --git a/pyvnt/utils/check_deps.py b/pyvnt/utils/check_deps.py new file mode 100644 index 0000000..9ad315d --- /dev/null +++ b/pyvnt/utils/check_deps.py @@ -0,0 +1,24 @@ +import subprocess, re +from pyvnt.Reference.error_classes import VersionError +''' +This function checks for the existence of an external software package. +''' + +def check_package(name, version): + + pkg_cmd = "" + if name == "OpenFOAM": + pkg_cmd = "blockMesh" + + try: + res = subprocess.check_output([pkg_cmd, "-help"], text=True, shell=True) + + match = re.search(r"OpenFOAM-(\d+)", res) + + v = match.group(1) + + if v != version: + raise VersionError(v) + except Exception as e: + print(e) + print("OpenFOAM might not be installed or its environment might not be active") \ No newline at end of file diff --git a/reader_testsimpleDict.txt b/reader_testsimpleDict.txt new file mode 100644 index 0000000..1137527 --- /dev/null +++ b/reader_testsimpleDict.txt @@ -0,0 +1,9 @@ +key1 25; +key2 35.8 67; +key3 value1; +key6 ( value3 value4 value5 ); +key4 +{ + key41 value1; +} + diff --git a/requirements.txt b/requirements.txt index c768b33..7611457 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ anytree==2.12.1 build==1.2.1 dataclasses==0.6 iniconfig==2.0.0 -numpy==1.26.4 +numpy==2.0.1 packaging==24.0 pluggy==1.5.0 pyproject_hooks==1.1.0 diff --git a/setup.py b/setup.py index 3d39964..22b2c52 100755 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ # ])], packages=find_packages(include=['pyvnt', 'pyvnt.*']), # py_modules=['pyvnt'], - # include_package_data=True, + include_package_data=True, # package_data={'': ['./pyvnt/Converter/cpp_src/dictionaryFile/lib/dictionaryFile.so', './pyvnt/Converter/cpp_src/dictionaryFileIterator/lib/dictionaryFileIterator.so']}, install_requires=['anytree', 'dataclasses'], keywords=['python'],