FEM: solver settings, small code improvements and some comments

This commit is contained in:
Bernd Hahnebach
2019-03-29 18:41:44 +01:00
committed by wmayer
parent 36fb597ad9
commit 7b03eff1b6

View File

@@ -1,5 +1,6 @@
# ***************************************************************************
# * Copyright (c) 2017 Markus Hovorka <m.hovorka@live.de> *
# * Copyright (c) 2019 Bernd Hahnebach <bernd@bimstatik.org> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
@@ -20,28 +21,34 @@
# ***************************************************************************
__title__ = "FreeCAD FEM solver settings"
__author__ = "Markus Hovorka"
__author__ = "Markus Hovorka, Bernd Hahnebach"
__url__ = "http://www.freecadweb.org"
## \addtogroup FEM
# @{
import distutils.spawn
'''
parameter in FreeCAD can be edited in two ways, either in the
Preferences: menu Edit --> Preferences
or
Parameter editor: menu Tools --> Edit parameter
'''
import FreeCAD
# working directory: possible choices
TEMPORARY = "temporary"
BESIDE = "beside"
CUSTOM = "custom"
# FEM parameter location path
_PARAM_PATH = "User parameter:BaseApp/Preferences/Mod/Fem/"
_GENERAL_PARAM = _PARAM_PATH + "General"
_CCX_PARAM = _PARAM_PATH + "Ccx"
_ELMER_PARAM = _PARAM_PATH + "Elmer"
_Z88_PARAM = _PARAM_PATH + "Z88"
# ******** binary parameter **********************************************************************
class _BinaryDlg(object):
def __init__(self, default, param, useDefault, customPath):
@@ -51,34 +58,58 @@ class _BinaryDlg(object):
self.customPath = customPath
def getBinary(self):
# get the parameter object where the paramete are saved in
paramObj = FreeCAD.ParamGet(self.param)
# set the binary path to the FreeCAD defaults, ATM pure unix shell commands without path names are used
# TODO see todo on useDefault later in this module
binary = self.default
FreeCAD.Console.PrintLog('Solver binary path: {} \n'.format(binary))
# check if useDefault is set to True
# if True the standard binary path will be overwritten with a user binary path
if not paramObj.GetBool(self.useDefault, True):
binary = paramObj.GetString(self.customPath)
FreeCAD.Console.PrintLog('Solver binary path: {} \n'.format(binary))
return distutils.spawn.find_executable(binary)
# get the whole binary path name for the given command or binary path and return it
from distutils.spawn import find_executable as find_bin
return find_bin(binary)
'''
default:
default command to run the binary, this one is taken if the UseStandardXXXLocation is not given or set to True
param:
path where these settings are saved, in FEM normally one path in one Tab in Preferences GUI
useDefault:
the UseStandardXXXLocation parameter identifier
if this parameter is set to True FreeCAD standards for the binary are used, or FreeCAD tries to find the binary
TODO: see method setup_ccx in ccx tools module, which sets up ccx binary for various os
customPath:
the xxxBinaryPath parameter identifier
binary path given by the user
'''
_BINARIES = {
"Calculix": _BinaryDlg(
default="ccx",
param=_CCX_PARAM,
param=_PARAM_PATH + "Ccx",
useDefault="UseStandardCcxLocation",
customPath="ccxBinaryPath"),
"ElmerSolver": _BinaryDlg(
default="ElmerSolver",
param=_ELMER_PARAM,
param=_PARAM_PATH + "Elmer",
useDefault="UseStandardElmerLocation",
customPath="elmerBinaryPath"),
"ElmerGrid": _BinaryDlg(
default="ElmerGrid",
param=_ELMER_PARAM,
param=_PARAM_PATH + "Elmer",
useDefault="UseStandardGridLocation",
customPath="gridBinaryPath"),
"Z88": _BinaryDlg(
default="z88r",
param=_Z88_PARAM,
param=_PARAM_PATH + "Z88",
useDefault="UseStandardZ88Location",
customPath="z88BinaryPath"),
}
@@ -96,6 +127,7 @@ def getBinary(name):
return None
# ******** working directory parameter ***********************************************************
def getCustomDir():
param = FreeCAD.ParamGet(_GENERAL_PARAM)
return param.GetString("CustomDirectoryPath")