From 59ed7eccf05d3fe14c8659d6fd2755bd5e997567 Mon Sep 17 00:00:00 2001 From: eap Date: Mon, 10 Nov 2008 13:44:56 +0000 Subject: [PATCH] + DualMESHTests.cxx --- src/INTERP_KERNEL/Test/DualMESHTests.cxx | 189 +++++++++++++++++++++++ src/INTERP_KERNEL/Test/DualMESHTests.hxx | 45 ++++++ src/INTERP_KERNEL/Test/Makefile.am | 4 +- 3 files changed, 236 insertions(+), 2 deletions(-) create mode 100644 src/INTERP_KERNEL/Test/DualMESHTests.cxx create mode 100644 src/INTERP_KERNEL/Test/DualMESHTests.hxx diff --git a/src/INTERP_KERNEL/Test/DualMESHTests.cxx b/src/INTERP_KERNEL/Test/DualMESHTests.cxx new file mode 100644 index 000000000..733d3240b --- /dev/null +++ b/src/INTERP_KERNEL/Test/DualMESHTests.cxx @@ -0,0 +1,189 @@ +// File : DualMESHTests.cxx +// Created : Thu Nov 6 17:13:23 2008 +// Author : Edward AGAPOV (eap) + +#include "DualMESHTests.hxx" +#include "MEDMEM_Field.hxx" +#include "MEDMEM_Meshing.hxx" + +using namespace MEDMEM; +using namespace INTERP_KERNEL; + +namespace INTERP_TEST +{ + //================================================================================ + /** + * Test 2D DualMESH + */ + //================================================================================ + + void DualMESHTests::test_DualMESH_2D() + { + string data_dir = getenv("MED_ROOT_DIR"); + string filename = data_dir + "/share/salome/resources/med/square1_split1.med"; + cout << endl << "Input mesh: " << filename << endl; + + MESH* inputMesh = 0; + CPPUNIT_ASSERT_NO_THROW(inputMesh = new MESH(MED_DRIVER,filename,"Mesh_2_1")); + + MESH* dualMesh = 0; + CPPUNIT_ASSERT_NO_THROW(dualMesh = new DualMESH(*inputMesh)); + + // store dual mesh + char* tmpEnv = getenv("TMP"); + string tmp_dir = "/tmp"; + if ( tmpEnv && strlen(tmpEnv) ) + tmp_dir = tmpEnv; + filename = tmp_dir + "/dualMesh_2D.med"; + cout << "Dual mesh: " << filename << endl; + + dualMesh->addDriver( MED_DRIVER, filename, dualMesh->getName() ); + CPPUNIT_ASSERT_NO_THROW( dualMesh->write() ); + + // compare mesh areas + + SUPPORT sup1( inputMesh ), sup2( dualMesh ); + + FIELD* areaField1 = inputMesh->getArea( ¹ ); + FIELD* areaField2 = dualMesh->getArea( ² ); + + double area1 = 0., area2 = 0.; + int i, nb; + nb = sup1.getNumberOfElements()[0]; + for ( i = 1; i <= nb; ++i ) + area1 += areaField1->getValueIJ( i, 1 ); + nb = sup2.getNumberOfElements()[0]; + for ( i = 1; i <= nb; ++i ) + area2 += areaField2->getValueIJ( i, 1 ); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(area1, area2, 1e-6); + + delete areaField1; + delete areaField2; + delete inputMesh; + delete dualMesh; + } + + //================================================================================ + /** + * Test 3D DualMESH + */ + //================================================================================ + + void DualMESHTests::test_DualMESH_3D() { + + // Create tetra mesh + // ------------------ + + MESHING myMeshing ; + myMeshing.setName("tetras") ; + myMeshing.setMeshDimension( 3 ); + + + // define coordinates + int SpaceDimension = 3 ; + int NumberOfNodes = 9 ; + double Coordinates[27] = { + 0.0, 0.0, 200.0, + 0.0, 0.0, 0.0, + 0.0, 200.0, 200.0, + 0.0, 200.0, 0.0, + 200.0, 0.0, 200.0, + 200.0, 0.0, 0.0, + 200.0, 200.0, 200.0, + 200.0, 200.0, 0.0, + 100.0, 100.0, 100.0 + }; + myMeshing.setCoordinates(SpaceDimension,NumberOfNodes,Coordinates, + "CARTESIAN",MED_FULL_INTERLACE); + string Names[3] = { "X","Y","Z" } ; + myMeshing.setCoordinatesNames(Names); + string Units[3] = { "cm","cm","cm" } ; + myMeshing.setCoordinatesUnits(Units) ; + + // define conectivities + + const int NumberOfTypes = 1; + medGeometryElement Types[NumberOfTypes] = {MED_TETRA4}; + const int NumberOfElements[NumberOfTypes] = {12}; + + myMeshing.setNumberOfTypes(NumberOfTypes,MED_CELL); + myMeshing.setTypes(Types,MED_CELL); + myMeshing.setNumberOfElements(NumberOfElements,MED_CELL); + + const int sizeTetra = 12*4 ; + int ConnectivityTetra[sizeTetra]= { + 9, 2, 8, 4, + 7, 1, 9, 3, + 8, 5, 6, 9, + 7, 9, 5, 8, + 7, 9, 1, 5, + 7, 9, 8, 4, + 9, 2, 4, 1, + 5, 2, 6, 9, + 2, 8, 6, 9, + 1, 4, 9, 3, + 9, 2, 1, 5, + 4, 7, 9, 3 + }; + myMeshing.setConnectivity(ConnectivityTetra,MED_CELL,MED_TETRA4); + + // store input mesh + char* tmpEnv = getenv("TMP"); + string tmp_dir = "/tmp"; + if ( tmpEnv && strlen(tmpEnv) ) + tmp_dir = tmpEnv; + string filename = tmp_dir + "/tetra.med"; + cout << endl << "Input mesh: " << filename << endl; + + int drv = myMeshing.addDriver( MED_DRIVER, filename, myMeshing.getName() ); + CPPUNIT_ASSERT_NO_THROW( myMeshing.write(drv) ); + + // -------------- + // TEST DualMESH + // -------------- + + MESH* dualMesh = 0; + CPPUNIT_ASSERT_NO_THROW(dualMesh = new DualMESH( myMeshing )); + + // store dual mesh + filename = tmp_dir + "/dualMesh_3D.med"; + cout << "Dual mesh: " << filename << endl; + + drv = dualMesh->addDriver( MED_DRIVER, filename, dualMesh->getName() ); + CPPUNIT_ASSERT_NO_THROW( dualMesh->write(drv) ); + + // compare mesh volumes + + SUPPORT sup1( &myMeshing ), sup2( dualMesh ); + + FIELD* volField1 = myMeshing.getVolume( ¹ ); + FIELD* volField2 = dualMesh->getVolume( ² ); + + double vol1 = 0., vol2 = 0.; + int i, nb; + nb = sup1.getNumberOfElements()[0]; + for ( i = 1; i <= nb; ++i ) + vol1 += volField1->getValueIJ( i, 1 ); + nb = sup2.getNumberOfElements()[0]; + for ( i = 1; i <= nb; ++i ) + vol2 += volField2->getValueIJ( i, 1 ); + + // polyhedres are not convex, so precision is low - 5% + CPPUNIT_ASSERT_DOUBLES_EQUAL(vol1, vol2, 0.05 * vol1); + + delete volField1; + delete volField2; + delete dualMesh; + } + + + void DualMESHTests::setUp() + { + } + + + void DualMESHTests::tearDown() + { + } +} diff --git a/src/INTERP_KERNEL/Test/DualMESHTests.hxx b/src/INTERP_KERNEL/Test/DualMESHTests.hxx new file mode 100644 index 000000000..5d00d9aab --- /dev/null +++ b/src/INTERP_KERNEL/Test/DualMESHTests.hxx @@ -0,0 +1,45 @@ +// File : DualMESHTests.hxx +// Created : Thu Nov 6 17:11:27 2008 +// Author : Edward AGAPOV (eap) + + +#ifndef DualMESHTests_HeaderFile +#define DualMESHTests_HeaderFile + +#include +#include "../DualMESH.hxx" + +namespace INTERP_TEST +{ + + /** + * \brief Test suite testing DualMESH class. + * + */ + class DualMESHTests : public CppUnit::TestFixture + { + + CPPUNIT_TEST_SUITE( DualMESHTests ); + CPPUNIT_TEST( test_DualMESH_2D ); + CPPUNIT_TEST( test_DualMESH_3D ); + CPPUNIT_TEST_SUITE_END(); + + + public: + void setUp(); + + void tearDown(); + + // tests + void test_DualMESH_2D(); + void test_DualMESH_3D(); + + }; + + + + +} + + +#endif diff --git a/src/INTERP_KERNEL/Test/Makefile.am b/src/INTERP_KERNEL/Test/Makefile.am index a8211b8f5..e0b31aed8 100644 --- a/src/INTERP_KERNEL/Test/Makefile.am +++ b/src/INTERP_KERNEL/Test/Makefile.am @@ -49,7 +49,7 @@ EXTRA_DIST += \ MultiElement3DSurfTests.hxx \ TestingUtils.hxx \ perf_test.sh \ - DualMESHTests.cxx + DualMESHTests.hxx CLEANFILES = \ UnitTestsResult @@ -67,7 +67,7 @@ dist_libInterpKernelTest_la_SOURCES= \ QuadraticPlanarInterpTest.cxx \ QuadraticPlanarInterpTest2.cxx \ QuadraticPlanarInterpTest3.cxx \ - QuadraticPlanarInterpTest4.cxx\ + QuadraticPlanarInterpTest4.cxx \ DualMESHTests.cxx libInterpKernelTest_la_CPPFLAGS = @CPPUNIT_INCLUDES@ $(MED2_INCLUDES) $(HDF5_INCLUDES) \ -- 2.39.2