Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
FEM: code formating, max line length < 100, fem solver
  • Loading branch information
berndhahnebach committed May 20, 2019
1 parent 454729f commit 1d50736
Show file tree
Hide file tree
Showing 10 changed files with 994 additions and 296 deletions.
169 changes: 145 additions & 24 deletions src/Mod/Fem/femsolver/calculix/solver.py
Expand Up @@ -58,16 +58,27 @@ def __init__(self, obj):
super(Proxy, self).__init__(obj)
obj.Proxy = self

# fem_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem/General") # not needed ATM
# not needed ATM
# fem_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem/General")
ccx_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem/Ccx")

obj.addProperty("App::PropertyEnumeration", "AnalysisType", "Fem", "Type of the analysis")
obj.addProperty(
"App::PropertyEnumeration",
"AnalysisType",
"Fem",
"Type of the analysis"
)
obj.AnalysisType = ANALYSIS_TYPES
analysis_type = ccx_prefs.GetInt("AnalysisType", 0)
obj.AnalysisType = ANALYSIS_TYPES[analysis_type]

choices_geom_nonlinear = ["linear", "nonlinear"]
obj.addProperty("App::PropertyEnumeration", "GeometricalNonlinearity", "Fem", "Set geometrical nonlinearity")
obj.addProperty(
"App::PropertyEnumeration",
"GeometricalNonlinearity",
"Fem",
"Set geometrical nonlinearity"
)
obj.GeometricalNonlinearity = choices_geom_nonlinear
nonlinear_geom = ccx_prefs.GetBool("NonlinearGeometry", False)
if nonlinear_geom is True:
Expand All @@ -76,43 +87,93 @@ def __init__(self, obj):
obj.GeometricalNonlinearity = choices_geom_nonlinear[0] # linear

choices_material_nonlinear = ["linear", "nonlinear"]
obj.addProperty("App::PropertyEnumeration", "MaterialNonlinearity", "Fem", "Set material nonlinearity (needs geometrical nonlinearity)")
obj.addProperty(
"App::PropertyEnumeration",
"MaterialNonlinearity",
"Fem",
"Set material nonlinearity (needs geometrical nonlinearity)"
)
obj.MaterialNonlinearity = choices_material_nonlinear
obj.MaterialNonlinearity = choices_material_nonlinear[0]

obj.addProperty("App::PropertyIntegerConstraint", "EigenmodesCount", "Fem", "Number of modes for frequency calculations")
obj.addProperty(
"App::PropertyIntegerConstraint",
"EigenmodesCount",
"Fem",
"Number of modes for frequency calculations"
)
noe = ccx_prefs.GetInt("EigenmodesCount", 10)
obj.EigenmodesCount = (noe, 1, 100, 1)

obj.addProperty("App::PropertyFloatConstraint", "EigenmodeLowLimit", "Fem", "Low frequency limit for eigenmode calculations")
obj.addProperty(
"App::PropertyFloatConstraint",
"EigenmodeLowLimit",
"Fem",
"Low frequency limit for eigenmode calculations"
)
ell = ccx_prefs.GetFloat("EigenmodeLowLimit", 0.0)
obj.EigenmodeLowLimit = (ell, 0.0, 1000000.0, 10000.0)

obj.addProperty("App::PropertyFloatConstraint", "EigenmodeHighLimit", "Fem", "High frequency limit for eigenmode calculations")
obj.addProperty(
"App::PropertyFloatConstraint",
"EigenmodeHighLimit",
"Fem",
"High frequency limit for eigenmode calculations"
)
ehl = ccx_prefs.GetFloat("EigenmodeHighLimit", 1000000.0)
obj.EigenmodeHighLimit = (ehl, 0.0, 1000000.0, 10000.0)

obj.addProperty("App::PropertyIntegerConstraint", "IterationsThermoMechMaximum", "Fem", "Maximum Number of thermo mechanical iterations in each time step before stopping jobs")
obj.addProperty(
"App::PropertyIntegerConstraint",
"IterationsThermoMechMaximum",
"Fem",
"Maximum Number of thermo mechanical iterations in each time step before stopping job"
)
niter = ccx_prefs.GetInt("AnalysisMaxIterations", 200)
obj.IterationsThermoMechMaximum = niter

obj.addProperty("App::PropertyFloatConstraint", "TimeInitialStep", "Fem", "Initial time steps")
obj.addProperty(
"App::PropertyFloatConstraint",
"TimeInitialStep",
"Fem",
"Initial time steps"
)
ini = ccx_prefs.GetFloat("AnalysisTimeInitialStep", 1.0)
obj.TimeInitialStep = ini

obj.addProperty("App::PropertyFloatConstraint", "TimeEnd", "Fem", "End time analysis")
obj.addProperty(
"App::PropertyFloatConstraint",
"TimeEnd",
"Fem",
"End time analysis"
)
eni = ccx_prefs.GetFloat("AnalysisTime", 1.0)
obj.TimeEnd = eni

obj.addProperty("App::PropertyBool", "ThermoMechSteadyState", "Fem", "Choose between steady state thermo mech or transient thermo mech analysis")
obj.addProperty(
"App::PropertyBool",
"ThermoMechSteadyState",
"Fem",
"Choose between steady state thermo mech or transient thermo mech analysis"
)
sted = ccx_prefs.GetBool("StaticAnalysis", True)
obj.ThermoMechSteadyState = sted

obj.addProperty("App::PropertyBool", "IterationsControlParameterTimeUse", "Fem", "Use the user defined time incrementation control parameter")
obj.addProperty(
"App::PropertyBool",
"IterationsControlParameterTimeUse",
"Fem",
"Use the user defined time incrementation control parameter"
)
use_non_ccx_iterations_param = ccx_prefs.GetInt("UseNonCcxIterationParam", False)
obj.IterationsControlParameterTimeUse = use_non_ccx_iterations_param

obj.addProperty("App::PropertyBool", "SplitInputWriter", "Fem", "Split writing of ccx input file")
obj.addProperty(
"App::PropertyBool",
"SplitInputWriter",
"Fem",
"Split writing of ccx input file"
)
split = ccx_prefs.GetBool("SplitInputWriter", False)
obj.SplitInputWriter = split

Expand All @@ -138,28 +199,88 @@ def __init__(self, obj):
'D_D': 1.5,
'W_G': None}
p = ccx_default_time_incrementation_control_parameter
p_iter = '{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}'.format(p['I_0'], p['I_R'], p['I_P'], p['I_C'], p['I_L'], p['I_G'], '', p['I_A'], '', '')
p_cutb = '{0},{1},{2},{3},{4},{5},{6},{7}'.format(p['D_f'], p['D_C'], p['D_B'], p['D_A'], '', '', p['D_D'], '')
obj.addProperty("App::PropertyString", "IterationsControlParameterIter", "Fem", "User defined time incrementation iterations control parameter")
p_iter = '{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}'.format(
p['I_0'],
p['I_R'],
p['I_P'],
p['I_C'],
p['I_L'],
p['I_G'],
'',
p['I_A'],
'',
''
)
p_cutb = '{0},{1},{2},{3},{4},{5},{6},{7}'.format(
p['D_f'],
p['D_C'],
p['D_B'],
p['D_A'],
'',
'',
p['D_D'],
''
)
obj.addProperty(
"App::PropertyString",
"IterationsControlParameterIter",
"Fem",
"User defined time incrementation iterations control parameter"
)
obj.IterationsControlParameterIter = p_iter
obj.addProperty("App::PropertyString", "IterationsControlParameterCutb", "Fem", "User defined time incrementation cutbacks control parameter")
obj.addProperty(
"App::PropertyString",
"IterationsControlParameterCutb",
"Fem",
"User defined time incrementation cutbacks control parameter"
)
obj.IterationsControlParameterCutb = p_cutb

stringIterationsUserDefinedIncrementations = "Set to True to switch off the ccx automatic incrementation completely (ccx parameter DIRECT). Use with care. Analysis may not converge!"
obj.addProperty("App::PropertyBool", "IterationsUserDefinedIncrementations", "Fem", stringIterationsUserDefinedIncrementations)
stringIterationsUserDefinedIncrementations = (
"Set to True to switch off the ccx automatic incrementation completely "
"(ccx parameter DIRECT). Use with care. Analysis may not converge!"
)
obj.addProperty(
"App::PropertyBool",
"IterationsUserDefinedIncrementations",
"Fem",
stringIterationsUserDefinedIncrementations)
obj.IterationsUserDefinedIncrementations = False

stringIterationsUserDefinedTimeStepLength = "Set to True to use the user defined time steps. The time steps are set with TimeInitialStep and TimeEnd"
obj.addProperty("App::PropertyBool", "IterationsUserDefinedTimeStepLength", "Fem", stringIterationsUserDefinedTimeStepLength)
stringIterationsUserDefinedTimeStepLength = (
"Set to True to use the user defined time steps. "
"The time steps are set with TimeInitialStep and TimeEnd"
)
obj.addProperty(
"App::PropertyBool",
"IterationsUserDefinedTimeStepLength",
"Fem",
stringIterationsUserDefinedTimeStepLength
)
obj.IterationsUserDefinedTimeStepLength = False

known_ccx_solver_types = ["default", "spooles", "iterativescaling", "iterativecholesky"]
obj.addProperty("App::PropertyEnumeration", "MatrixSolverType", "Fem", "Type of solver to use")
known_ccx_solver_types = [
"default",
"spooles",
"iterativescaling",
"iterativecholesky"
]
obj.addProperty(
"App::PropertyEnumeration",
"MatrixSolverType",
"Fem",
"Type of solver to use"
)
obj.MatrixSolverType = known_ccx_solver_types
solver_type = ccx_prefs.GetInt("Solver", 0)
obj.MatrixSolverType = known_ccx_solver_types[solver_type]

obj.addProperty("App::PropertyBool", "BeamShellResultOutput3D", "Fem", "Output 3D results for 1D and 2D analysis ")
obj.addProperty(
"App::PropertyBool",
"BeamShellResultOutput3D",
"Fem",
"Output 3D results for 1D and 2D analysis "
)
dimout = ccx_prefs.GetBool("BeamShellOutput", False)
obj.BeamShellResultOutput3D = dimout

Expand Down
87 changes: 65 additions & 22 deletions src/Mod/Fem/femsolver/calculix/tasks.py
Expand Up @@ -96,7 +96,8 @@ class Solve(run.Solve):

def run(self):
if not _inputFileName:
# TODO do not run solver, do not try to read results in a smarter way than an Exception
# TODO do not run solver
# do not try to read results in a smarter way than an Exception
raise Exception('Error on writing CalculiX input file.\n')
self.pushStatus("Executing solver...\n")
binary = settings.get_binary("Calculix")
Expand All @@ -118,7 +119,8 @@ class Results(run.Results):

def run(self):
if not _inputFileName:
# TODO do not run solver, do not try to read results in a smarter way than an Exception
# TODO do not run solver
# do not try to read results in a smarter way than an Exception
raise Exception('Error on writing CalculiX input file.\n')
prefs = FreeCAD.ParamGet(
"User parameter:BaseApp/Preferences/Mod/Fem/General")
Expand Down Expand Up @@ -173,29 +175,70 @@ def __init__(self, analysis):
self.mesh = mesh
else:
if FreeCAD.GuiUp:
QtGui.QMessageBox.critical(None, "Missing prerequisite", message)
QtGui.QMessageBox.critical(
None,
"Missing prerequisite",
message
)
raise Exception(message + '\n')

# get member
self.materials_linear = self.get_several_member('Fem::Material')
self.materials_nonlinear = self.get_several_member('Fem::MaterialMechanicalNonlinear')

self.beam_sections = self.get_several_member('Fem::FemElementGeometry1D')
self.beam_rotations = self.get_several_member('Fem::FemElementRotation1D')
self.fluid_sections = self.get_several_member('Fem::FemElementFluid1D')
self.shell_thicknesses = self.get_several_member('Fem::FemElementGeometry2D')

self.constraints_contact = self.get_several_member('Fem::ConstraintContact')
self.constraints_displacement = self.get_several_member('Fem::ConstraintDisplacement')
self.constraints_fixed = self.get_several_member('Fem::ConstraintFixed')
self.constraints_force = self.get_several_member('Fem::ConstraintForce')
self.constraints_heatflux = self.get_several_member('Fem::ConstraintHeatflux')
self.constraints_initialtemperature = self.get_several_member('Fem::ConstraintInitialTemperature')
self.constraints_planerotation = self.get_several_member('Fem::ConstraintPlaneRotation')
self.constraints_pressure = self.get_several_member('Fem::ConstraintPressure')
self.constraints_selfweight = self.get_several_member('Fem::ConstraintSelfWeight')
self.constraints_temperature = self.get_several_member('Fem::ConstraintTemperature')
self.constraints_transform = self.get_several_member('Fem::ConstraintTransform')
# materials
self.materials_linear = self.get_several_member(
'Fem::Material'
)
self.materials_nonlinear = self.get_several_member(
'Fem::MaterialMechanicalNonlinear'
)

# geometries
self.beam_sections = self.get_several_member(
'Fem::FemElementGeometry1D'
)
self.beam_rotations = self.get_several_member(
'Fem::FemElementRotation1D'
)
self.fluid_sections = self.get_several_member(
'Fem::FemElementFluid1D'
)
self.shell_thicknesses = self.get_several_member(
'Fem::FemElementGeometry2D'
)

# constraints
self.constraints_contact = self.get_several_member(
'Fem::ConstraintContact'
)
self.constraints_displacement = self.get_several_member(
'Fem::ConstraintDisplacement'
)
self.constraints_fixed = self.get_several_member(
'Fem::ConstraintFixed'
)
self.constraints_force = self.get_several_member(
'Fem::ConstraintForce'
)
self.constraints_heatflux = self.get_several_member(
'Fem::ConstraintHeatflux'
)
self.constraints_initialtemperature = self.get_several_member(
'Fem::ConstraintInitialTemperature'
)
self.constraints_planerotation = self.get_several_member(
'Fem::ConstraintPlaneRotation'
)
self.constraints_pressure = self.get_several_member(
'Fem::ConstraintPressure'
)
self.constraints_selfweight = self.get_several_member(
'Fem::ConstraintSelfWeight'
)
self.constraints_temperature = self.get_several_member(
'Fem::ConstraintTemperature'
)
self.constraints_transform = self.get_several_member(
'Fem::ConstraintTransform'
)

def get_several_member(self, t):
return femutils.get_several_member(self.analysis, t)
Expand Down

0 comments on commit 1d50736

Please sign in to comment.