Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerWorkflows/FreeCADBatchFEMTools/tests/cubemeshtest/cubemeshtest.py
3206 views
1
import argparse
2
import os
3
import subprocess
4
5
description = 'Writes parameters to file cubemeshtestparameters.txt and runs cubemeshtest_freecadscript.py with FreeCAD.'
6
description += ' Edge length of cube is 200 (diameter 200 with spheres). Distance between two cubes (spheres) is 20.'
7
8
ps_help = 'Is points used for finding boundaries and solids (section and common search otherwise)'
9
af_help = 'Appends execution times to file cubemeshtestexecutiontimes.txt if used'
10
11
parser = argparse.ArgumentParser(description=description)
12
parser.add_argument('-n', '--number_of_cubes', type=int, required=True)
13
parser.add_argument('-m', '--cube_mesh_size', type=float, default=50.0)
14
parser.add_argument('-fb', '--find_boundaries', action='store_true')
15
parser.add_argument('-fs', '--find_solids', action='store_true')
16
parser.add_argument('-ca', '--create_air', action='store_true', help='Is air created around cubes')
17
parser.add_argument('-am', '--air_mesh_size', type=float, help='If not given cube_mesh_size is used')
18
parser.add_argument('-ps', '--point_search', action='store_true', help=ps_help)
19
parser.add_argument('-s', '--spheres', action='store_true', help='Use spheres instead of cubes')
20
parser.add_argument('-af', '--append_file', action='store_true', help=af_help)
21
parser.add_argument('-fe', '--freecad-executable', type=str, default="FreeCAD", help='give the path to FreeCAD executable')
22
23
args = parser.parse_args()
24
25
directory = os.path.dirname(os.path.realpath(__file__))
26
freecadscript_name = os.path.join(directory, 'cubemeshtest_freecadscript.py')
27
if not os.path.isfile(freecadscript_name):
28
print("cubemeshtest_freecadscript.py does not exist, check that you are in correct directory")
29
else:
30
with open(os.path.join(directory, 'cubemeshtestparameters.txt'), 'w') as f:
31
f.write('{} {} {} {} {} {} {} {} {}'.format(args.number_of_cubes, args.cube_mesh_size, args.find_boundaries,
32
args.find_solids, args.create_air, args.air_mesh_size,
33
args.point_search, args.spheres, args.append_file))
34
try:
35
p = subprocess.Popen([args.freecad_executable, '-c', freecadscript_name])
36
p.communicate()
37
except Exception:
38
print("Running FreeCAD failed!!! Try to give the correct FreeCAD executable as an argument (--freecad-executable, -fe)")
39
40