Skip to content

Commit

Permalink
FEM: unittest, get rid of duplicates and move them to helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
berndhahnebach authored and yorikvanhavre committed May 27, 2017
1 parent 288406d commit 661fdbd
Showing 1 changed file with 22 additions and 31 deletions.
53 changes: 22 additions & 31 deletions src/Mod/Fem/TestFem.py
Expand Up @@ -28,7 +28,6 @@
import FemToolsCcx
import FreeCAD
import ObjectsFem
import csv
import tempfile
import unittest

Expand Down Expand Up @@ -63,10 +62,6 @@
spine_volumes_file = test_file_dir + '/spine_volumes.csv'


def fcc_print(message):
FreeCAD.Console.PrintMessage('{} \n'.format(message))


class FemTest(unittest.TestCase):
def setUp(self):
try:
Expand Down Expand Up @@ -131,20 +126,8 @@ def create_new_solver(self):
self.active_doc.recompute()

def create_new_mesh(self):
self.mesh = import_csv_mesh(mesh_points_file, mesh_volumes_file)
self.mesh_object = self.active_doc.addObject('Fem::FemMeshObject', mesh_name)
self.mesh = Fem.FemMesh()
with open(mesh_points_file, 'r') as points_file:
reader = csv.reader(points_file)
for p in reader:
self.mesh.addNode(float(p[1]), float(p[2]), float(p[3]), int(p[0]))

with open(mesh_volumes_file, 'r') as volumes_file:
reader = csv.reader(volumes_file)
for v in reader:
self.mesh.addVolume([int(v[2]), int(v[1]), int(v[3]), int(v[4]), int(v[5]),
int(v[7]), int(v[6]), int(v[9]), int(v[8]), int(v[10])],
int(v[0]))

self.mesh_object.FemMesh = self.mesh
self.active_doc.recompute()

Expand Down Expand Up @@ -352,20 +335,8 @@ def create_new_solver(self):
self.active_doc.recompute()

def create_new_mesh(self):
self.mesh = import_csv_mesh(spine_points_file, spine_volumes_file)
self.mesh_object = self.active_doc.addObject('Fem::FemMeshObject', mesh_name)
self.mesh = Fem.FemMesh()
with open(spine_points_file, 'r') as points_file:
reader = csv.reader(points_file)
for p in reader:
self.mesh.addNode(float(p[1]), float(p[2]), float(p[3]), int(p[0]))

with open(spine_volumes_file, 'r') as volumes_file:
reader = csv.reader(volumes_file)
for v in reader:
self.mesh.addVolume([int(v[2]), int(v[1]), int(v[3]), int(v[4]), int(v[5]),
int(v[7]), int(v[6]), int(v[9]), int(v[8]), int(v[10])],
int(v[0]))

self.mesh_object.FemMesh = self.mesh
self.active_doc.recompute()

Expand Down Expand Up @@ -503,6 +474,26 @@ def tearDown(self):


# helpers
def fcc_print(message):
FreeCAD.Console.PrintMessage('{} \n'.format(message))


def import_csv_mesh(import_points_file, import_volumes_file):
import csv
the_fem_mesh = Fem.FemMesh()
with open(import_points_file, 'r') as points_file:
reader = csv.reader(points_file)
for p in reader:
the_fem_mesh.addNode(float(p[1]), float(p[2]), float(p[3]), int(p[0]))
with open(import_volumes_file, 'r') as volumes_file:
reader = csv.reader(volumes_file)
for v in reader:
the_fem_mesh.addVolume([int(v[2]), int(v[1]), int(v[3]), int(v[4]), int(v[5]),
int(v[7]), int(v[6]), int(v[9]), int(v[8]), int(v[10])],
int(v[0]))
return the_fem_mesh


def compare_inp_files(file_name1, file_name2):
file1 = open(file_name1, 'r')
f1 = file1.readlines()
Expand Down

0 comments on commit 661fdbd

Please sign in to comment.