FEM: elmer unit tests, add SI units file writing test
This commit is contained in:
@@ -265,6 +265,7 @@ SET(FemTestsElmer_SRCS
|
||||
femtest/data/elmer/__init__.py
|
||||
femtest/data/elmer/box_static_mm.sif
|
||||
femtest/data/elmer/ccxcantilever_faceload_mm.sif
|
||||
femtest/data/elmer/ccxcantilever_faceload_1_si.sif
|
||||
femtest/data/elmer/ccxcantilever_nodeload_mm.sif
|
||||
femtest/data/elmer/ccxcantilever_prescribeddisplacement_mm.sif
|
||||
femtest/data/elmer/group_mesh.geo
|
||||
|
||||
@@ -56,23 +56,24 @@ class TestSolverElmer(unittest.TestCase):
|
||||
testtools.get_fem_test_home_dir(),
|
||||
"elmer"
|
||||
)
|
||||
|
||||
# make sure std FreeCAD unit system mm/kg/s is used
|
||||
# set Units
|
||||
# since in Elmer writer the FreeCAD pref is used, here we need to set the FreeCAD pref
|
||||
# the use of FreeCAD.Units.setScheme would not take affect because the pref is not changed
|
||||
# see https://forum.freecadweb.org/viewtopic.php?t=48451
|
||||
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units")
|
||||
self.unit_schema = param.GetInt("UserSchema")
|
||||
if self.unit_schema != 0:
|
||||
fcc_print("Unit schema: {}. Set unit schema to 0 (mm/kg/s)".format(self.unit_schema))
|
||||
param.SetInt("UserSchema", 0)
|
||||
self.saved_unit_schema = param.GetInt("UserSchema")
|
||||
|
||||
# ********************************************************************************************
|
||||
def tearDown(
|
||||
self
|
||||
):
|
||||
# set back unit unit schema
|
||||
if self.unit_schema != 0:
|
||||
fcc_print("Set unit schema back to {}".format(self.unit_schema))
|
||||
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units")
|
||||
unit_schema = param.GetInt("UserSchema")
|
||||
if unit_schema != self.saved_unit_schema:
|
||||
fcc_print("Reset unit schema back to {}".format(self.saved_unit_schema))
|
||||
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units")
|
||||
param.SetInt("UserSchema", self.unit_schema)
|
||||
param.SetInt("UserSchema", self.saved_unit_schema)
|
||||
|
||||
# tearDown is executed after every test
|
||||
FreeCAD.closeDocument(self.document.Name)
|
||||
@@ -92,10 +93,23 @@ class TestSolverElmer(unittest.TestCase):
|
||||
))
|
||||
|
||||
# ********************************************************************************************
|
||||
def test_box_static(
|
||||
def set_unit_schema(
|
||||
self,
|
||||
new_unit_schema=0
|
||||
):
|
||||
fcc_print(
|
||||
"\nSaved unit schema: {}. Set unit schema to {}."
|
||||
.format(self.saved_unit_schema, new_unit_schema)
|
||||
)
|
||||
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units")
|
||||
param.SetInt("UserSchema", new_unit_schema)
|
||||
|
||||
# ********************************************************************************************
|
||||
def test_box_static_mm(
|
||||
self
|
||||
):
|
||||
fcc_print("")
|
||||
self.set_unit_schema(0) # mm/kg/s
|
||||
|
||||
# set up the Elmer static analysis example
|
||||
from femexamples.boxanalysis_static import setup
|
||||
@@ -133,7 +147,7 @@ class TestSolverElmer(unittest.TestCase):
|
||||
self.assertFalse(ret, "STARTINFO write file test failed.\n{}".format(ret))
|
||||
|
||||
fcc_print("Test writing case file")
|
||||
casefile_given = join(self.test_file_dir, base_name + "_mm" + self.ending)
|
||||
casefile_given = join(self.test_file_dir, base_name + self.ending)
|
||||
casefile_totest = join(analysis_dir, self.infilename + self.ending)
|
||||
# fcc_print("Comparing {} to {}".format(casefile_given, casefile_totest))
|
||||
ret = testtools.compare_files(casefile_given, casefile_totest)
|
||||
@@ -147,28 +161,41 @@ class TestSolverElmer(unittest.TestCase):
|
||||
self.assertFalse(ret, "GMSH geo write file test failed.\n{}".format(ret))
|
||||
|
||||
# ********************************************************************************************
|
||||
def test_ccxcantilever_faceload(
|
||||
def test_ccxcantilever_faceload_mm(
|
||||
self
|
||||
):
|
||||
fcc_print("")
|
||||
self.set_unit_schema(0) # mm/kg/s
|
||||
from femexamples.ccx_cantilever_faceload import setup
|
||||
setup(self.document, "elmer")
|
||||
self.input_file_writing_test(get_namefromdef("test_"))
|
||||
|
||||
# ********************************************************************************************
|
||||
def test_ccxcantilever_nodeload(
|
||||
def test_ccxcantilever_faceload_1_si(
|
||||
self
|
||||
):
|
||||
fcc_print("")
|
||||
self.set_unit_schema(1) # SI-units m/kg/s
|
||||
from femexamples.ccx_cantilever_faceload import setup
|
||||
setup(self.document, "elmer")
|
||||
self.input_file_writing_test(get_namefromdef("test_"))
|
||||
|
||||
# ********************************************************************************************
|
||||
def test_ccxcantilever_nodeload_mm(
|
||||
self
|
||||
):
|
||||
fcc_print("")
|
||||
self.set_unit_schema(0) # mm/kg/s
|
||||
from femexamples.ccx_cantilever_nodeload import setup
|
||||
setup(self.document, "elmer")
|
||||
self.input_file_writing_test(get_namefromdef("test_"))
|
||||
|
||||
# ********************************************************************************************
|
||||
def test_ccxcantilever_prescribeddisplacement(
|
||||
def test_ccxcantilever_prescribeddisplacement_mm(
|
||||
self
|
||||
):
|
||||
fcc_print("")
|
||||
self.set_unit_schema(0) # mm/kg/s
|
||||
from femexamples.ccx_cantilever_prescribeddisplacement import setup
|
||||
setup(self.document, "elmer")
|
||||
self.input_file_writing_test(get_namefromdef("test_"))
|
||||
@@ -199,7 +226,7 @@ class TestSolverElmer(unittest.TestCase):
|
||||
# compare input file with the given one
|
||||
inpfile_given = join(
|
||||
self.test_file_dir,
|
||||
base_name + "_mm" + self.ending
|
||||
base_name + self.ending
|
||||
)
|
||||
inpfile_totest = join(
|
||||
working_dir,
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
Check Keywords Warn
|
||||
|
||||
Header
|
||||
Mesh DB "."
|
||||
End
|
||||
|
||||
Solver 1
|
||||
Bubbles = Logical False
|
||||
Calculate Pangle = Logical False
|
||||
Calculate Principal = Logical False
|
||||
Calculate Strains = Logical False
|
||||
Calculate Stresses = Logical False
|
||||
Displace mesh = Logical False
|
||||
Eigen Analysis = Logical False
|
||||
Eigen System Values = Integer 5
|
||||
Equation = String "Elasticity"
|
||||
Exec Solver = String "Always"
|
||||
Linear System Abort Not Converged = Logical False
|
||||
Linear System Convergence Tolerance = Real 1e-08
|
||||
Linear System Iterative Method = String "BiCGStab"
|
||||
Linear System Max Iterations = Integer 500
|
||||
Linear System Precondition Recompute = Integer 1
|
||||
Linear System Preconditioning = String "ILU0"
|
||||
Linear System Residual Output = Integer 1
|
||||
Linear System Solver = String "Iterative"
|
||||
Optimize Bandwidth = Logical True
|
||||
Procedure = File "StressSolve" "StressSolver"
|
||||
Stabilize = Logical True
|
||||
Steady State Convergence Tolerance = Real 1e-05
|
||||
Variable = String "Displacement"
|
||||
Variable DOFs = Integer 3
|
||||
End
|
||||
|
||||
Simulation
|
||||
BDF Order = Integer 1
|
||||
Coordinate Mapping(3) = Integer 1 2 3
|
||||
Coordinate Scaling = Real 0.001
|
||||
Coordinate System = String "Cartesian 3D"
|
||||
Output Intervals = Integer 1
|
||||
Simulation Type = String "Steady state"
|
||||
Steady State Max Iterations = Integer 1
|
||||
Steady State Min Iterations = Integer 0
|
||||
Timestepping Method = String "BDF"
|
||||
Use Mesh Names = Logical True
|
||||
End
|
||||
|
||||
Constants
|
||||
End
|
||||
|
||||
Body 1
|
||||
Equation = Integer 1
|
||||
Material = Integer 1
|
||||
Name = String "Solid1"
|
||||
End
|
||||
|
||||
Material 1
|
||||
Poisson ratio = Real 0.3
|
||||
Youngs Modulus = Real 210000000000.0
|
||||
End
|
||||
|
||||
Equation 1
|
||||
Active Solvers(2) = Integer 1 2
|
||||
End
|
||||
|
||||
Solver 2
|
||||
Coordinate Scaling Revert = Logical True
|
||||
Equation = String "ResultOutput"
|
||||
Exec Solver = String "After simulation"
|
||||
Output File Name = File "case"
|
||||
Procedure = File "ResultOutputSolve" "ResultOutputSolver"
|
||||
Vtu Format = Logical True
|
||||
End
|
||||
|
||||
Boundary Condition 1
|
||||
Displacement 1 = Real 0.0
|
||||
Displacement 2 = Real 0.0
|
||||
Displacement 3 = Real 0.0
|
||||
Name = String "Face1"
|
||||
End
|
||||
|
||||
Boundary Condition 2
|
||||
Force 1 = Real -0.0
|
||||
Force 1 Normalize by Area = Logical True
|
||||
Force 2 = Real -0.0
|
||||
Force 2 Normalize by Area = Logical True
|
||||
Force 3 = Real -9000000.0
|
||||
Force 3 Normalize by Area = Logical True
|
||||
Name = String "Face2"
|
||||
End
|
||||
|
||||
Reference in New Issue
Block a user