]> SALOME platform Git repositories - tools/solverlab.git/commitdiff
Salome HOME
Added new test for field creation and saving
authormichael <michael@localhost.localdomain>
Sat, 30 Oct 2021 20:38:14 +0000 (22:38 +0200)
committermichael <michael@localhost.localdomain>
Sat, 30 Oct 2021 20:38:14 +0000 (22:38 +0200)
CDMATH/tests/swig/CMakeLists.txt
CDMATH/tests/swig/testFieldCreationAndSave.py [new file with mode: 0644]

index 416c484f988ceaf5552da13b98e1dddc231b0068..c71fa8786ca0d4a6b0116fe921450881a1fdfff5 100755 (executable)
@@ -11,19 +11,19 @@ ADD_TEST(TestsCDMATHSwig ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/mainTe
 if (CDMATH_WITH_PETSC)
     ADD_TEST(TestsLinearSolverSwig ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/linearSolverTests.py)
     INSTALL(FILES linearSolverTests.py DESTINATION bin/unit_tests)
-
-
-else (CDMATH_WITH_PETSC)
 endif (CDMATH_WITH_PETSC)
 
 
-if (CDMATH_WITH_PYTHON AND CDMATH_WITH_POSTPRO)
+if (CDMATH_WITH_POSTPRO)
   ADD_TEST(Tests_VTK_routines ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_VTK_routines.py)
 
   ADD_TEST(Tests_PV_routines ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_PV_routines.py)
 
   add_subdirectory (BoySurface)
-endif ()
 
-INSTALL(FILES ${MESH_MED}  mainTests.py test_VTK_routines.py test_PV_routines.py DESTINATION bin/unit_tests)
+
+  ADD_TEST(Tests_Field_Creation_And_Saving_routines ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/testFieldCreationAndSave.py )
+
+  INSTALL(FILES ${MESH_MED}  mainTests.py test_VTK_routines.py test_PV_routines.py testFieldCreationAndSave.py DESTINATION bin/unit_tests)
+endif (CDMATH_WITH_POSTPRO)
 
diff --git a/CDMATH/tests/swig/testFieldCreationAndSave.py b/CDMATH/tests/swig/testFieldCreationAndSave.py
new file mode 100644 (file)
index 0000000..d7f5e50
--- /dev/null
@@ -0,0 +1,71 @@
+#!/usr/bin/env python3
+# -*-coding:utf-8 -*
+
+from math import sqrt
+import cdmath
+
+print("Loading a triangular mesh of a 2D square")
+filename = "./meshSquare"
+M=cdmath.Mesh(filename+".med")
+
+print("Checking boundary group names")
+boundaryFaceGroupNames=M.getNameOfFaceGroups()
+boundaryNodeGroupNames=M.getNameOfNodeGroups()
+print(len(boundaryFaceGroupNames), " Boundary Face Group detected : ", boundaryFaceGroupNames)
+print(len(boundaryNodeGroupNames), " Boundary Node Group detected : ", boundaryNodeGroupNames)
+
+assert(len(boundaryFaceGroupNames)==5)
+assert(len(boundaryNodeGroupNames)==5)
+
+assert boundaryFaceGroupNames[0]=="Top"
+assert boundaryFaceGroupNames[1]=="Right"
+assert boundaryFaceGroupNames[2]=="Left"
+assert boundaryFaceGroupNames[3]=="Bottom"
+assert boundaryFaceGroupNames[4]=="Boundary"
+
+assert boundaryNodeGroupNames[0]=="Top"
+assert boundaryNodeGroupNames[1]=="Right"
+assert boundaryNodeGroupNames[2]=="Left"
+assert boundaryNodeGroupNames[3]=="Bottom"
+assert boundaryNodeGroupNames[4]=="Boundary"
+
+#Extract domain sizes
+xmin = M.getXMin()
+xmax = M.getXMax()
+ymin = M.getYMin()
+ymax = M.getYMax()
+
+radius = min(xmax-xmin,ymax-ymin)/4
+xcentre = (xmax+xmin)/2
+ycentre = (ymax+ymin)/2
+
+nbCells = M.getNumberOfCells()
+nbNodes = M.getNumberOfNodes()
+
+# Create scalar fields
+temperature_field_cells = cdmath.Field("Temperature", cdmath.CELLS, M, 1)
+temperature_field_nodes = cdmath.Field("Temperature", cdmath.NODES, M, 1)
+Tin  = 300
+Tout = 400
+
+for i in range(nbCells):
+    x = M.getCell(i).x()
+    y = M.getCell(i).y()
+    distance = sqrt( (x - xcentre) * (x - xcentre) + (y - ycentre) * (y - ycentre) )
+    if distance < radius:
+        temperature_field_cells[i] = Tin
+    else:
+        temperature_field_cells[i] = Tout
+
+temperature_field_cells.writeMED(filename, False)
+
+for i in range(nbNodes):
+    x = M.getNode(i).x()
+    y = M.getNode(i).y()
+    distance = sqrt( (x - xcentre) * (x - xcentre) + (y - ycentre) * (y - ycentre) )
+    if distance < radius:
+        temperature_field_nodes[i] = Tin
+    else:
+        temperature_field_nodes[i] = Tout
+
+temperature_field_nodes.writeMED(filename, False)