]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Python examples in doc.
authorageay <ageay>
Thu, 12 Apr 2012 08:10:15 +0000 (08:10 +0000)
committerageay <ageay>
Thu, 12 Apr 2012 08:10:15 +0000 (08:10 +0000)
doc/doxygen/CMakeLists.txt
doc/doxygen/Doxyfile_med_user.in
doc/doxygen/medcouplingexamples.dox [deleted file]
doc/doxygen/medcouplingexamples.doxy [new file with mode: 0644]
src/MEDCoupling/MEDCouplingFieldDouble.cxx
src/MEDCoupling_Swig/CMakeLists.txt
src/MEDCoupling_Swig/MEDCouplingExamplesTest.py [new file with mode: 0644]

index ae0a28b154c1a67b0b9fe520a4eb0ce92899423c..9a72b7e2136e85c19ef72c3a7e1718c8f34e5c9e 100644 (file)
@@ -32,8 +32,13 @@ FOREACH(indoxfile ${indoxfiles})
   CONFIGURE_FILE(${input} ${output})
   MESSAGE(STATUS "Creation of ${output}")
 ENDFOREACH(indoxfile ${indoxfiles})
+FILE(TO_NATIVE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/medcouplingexamples.doxy" input)
+FILE(TO_NATIVE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/BuildPyExamplesFromCPP.py" pythondocexamplesgenerator)
+FILE(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}" output)
 
-ADD_CUSTOM_TARGET(usr_docs ${DOXYGEN_EXECUTABLE} Doxyfile_med_user
+ADD_CUSTOM_TARGET(usr_docs
+  COMMAND ${PYTHON_EXECUTABLE} ${pythondocexamplesgenerator} ${input} ${output}
+  COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile_med_user
   COMMAND ${PYTHON_EXECUTABLE} -c "import shutil, sys; shutil.rmtree(r'''${CMAKE_INSTALL_PREFIX}/share/doc/salome/gui/MED''', True); shutil.copytree(r'''${CMAKE_CURRENT_BINARY_DIR}/doc_ref_user/html''', r'''${CMAKE_INSTALL_PREFIX}/share/doc/salome/gui/MED'''); shutil.copy(r'''${CMAKE_CURRENT_SOURCE_DIR}/images/head.png''', r'''${CMAKE_INSTALL_PREFIX}/share/doc/salome/gui/MED''')"
   VERBATIM 
   WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}             
index 8163cbdcda827dc9dd788cebd602a53a58152b21..33b8d58738f982daa3f132f79cd34286ab7adc66 100644 (file)
@@ -68,7 +68,8 @@ WARN_LOGFILE           = log_user
 #---------------------------------------------------------------------------
 # configuration options related to the input files
 #---------------------------------------------------------------------------
-INPUT                  = @srcdir@ \
+INPUT                  = @builddir@ \
+                        @srcdir@ \
                          @srcdir@/../../src/ParaMEDMEM \
                          @srcdir@/../../src/INTERP_KERNEL \
                         @srcdir@/../../src/INTERP_KERNEL/Bases \
@@ -136,6 +137,7 @@ EXCLUDE                = CVS
 EXCLUDE_PATTERNS       = *~
 EXAMPLE_PATH           = @srcdir@/../../src/ParaMEDMEM \
                         @srcdir@/../../src/MEDCoupling/Test \
+                        @srcdir@/../../src//MEDCoupling_Swig \
                          @srcdir@/../../doc/MEDMEM \
                          @srcdir@/../../src/MEDMEMBinTest \
                          @srcdir@/../../src/MEDMEM
diff --git a/doc/doxygen/medcouplingexamples.dox b/doc/doxygen/medcouplingexamples.dox
deleted file mode 100644 (file)
index 5c542ae..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*!
-\page medcouplingcppexamples <br><h1> MEDCoupling C++ examples </h1>
-
-\anchor cpp_mcfielddouble_subpart1
-<br><h2>Creation of a sub part of a field</h2>
-<br><h3>Creation of a sub part of a field on cells</h3>
-\snippet MEDCouplingExamplesTest.cxx CppSnippetFieldDoubleBuildSubPart1_1
-The field on cells \b f1 lies on a mesh containg 5 cells and 9 nodes.          
-So this field \b f1 contains 5 tuples of 2 components each (10 values).
-Now let's create a subfield on cells \b f2 from \b f1.
-\snippet MEDCouplingExamplesTest.cxx CppSnippetFieldDoubleBuildSubPart1_2
-
-\b f1 is a field on cells, \ref ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart "buildSubPart" method performs an extraction on cells too.
-
-So the array \b part1 lists ids on cells.
-
-- cell #0 of \b f2 is the same cell of cell #2 of \b f1
-- cell #1 of \b f2 is the same cell of cell #1 of \b f1
-- cell #2 of \b f2 is the same cell of cell #4 of \b f1
-
-So \b f2 contains 3 tuples with 2 components.
-
-The underlying mesh of \b f2 contains a newly created mesh with 3 cells (not as \b mesh1 in \b f1) and 9 nodes (as \b mesh1 in \b f1).
-\n For fields on cells the number of tuples of the returned field is always equal to the number of ids given in input (here \b part1).
-\nOnly fields on cells have this particular behaviour.
-
-<br><h3>Creation of a sub part of a field on nodes</h3>
-\snippet MEDCouplingExamplesTest.cxx CppSnippetFieldDoubleBuildSubPart1_3
-The field on nodes \b f1 lies on a mesh containg 5 cells and 9 nodes.
-So this field \b f1 contains 9 tuples of 2 components each (18 values).
-Now let's create a subfield on nodes \b f2 from \b f1.
-\snippet MEDCouplingExamplesTest.cxx CppSnippetFieldDoubleBuildSubPart1_4
-
-\b f1 is a field on nodes, but \ref ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart "buildSubPart" method performs an extraction on \b cells.
-
-After the call of \ref ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart "buildSubPart" on node field \b f1, f1 will be reduced on a
-submesh of \b mesh1 containing cells whoses ids are in \b part2.
-So contrary to fields on cells, it is normal for fields on nodes that number of tuples of the returned field of \ref ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart "buildSubPart" 
-method does not match the size of the input array (here \b part2).
-
-*/
diff --git a/doc/doxygen/medcouplingexamples.doxy b/doc/doxygen/medcouplingexamples.doxy
new file mode 100644 (file)
index 0000000..777ecf8
--- /dev/null
@@ -0,0 +1,41 @@
+/*!
+\page medcouplingcppexamples <br><h1> MEDCoupling C++ examples </h1>
+
+\anchor cpp_mcfielddouble_subpart1
+<br><h2>Creation of a sub part of a field</h2>
+<br><h3>Creation of a sub part of a field on cells</h3>
+\snippet MEDCouplingExamplesTest.cxx CppSnippetFieldDoubleBuildSubPart1_1
+The field on cells \b f1 lies on a mesh containg 5 cells and 9 nodes.          
+So this field \b f1 contains 5 tuples of 2 components each (10 values).
+Now let's create a subfield on cells \b f2 from \b f1.
+\snippet MEDCouplingExamplesTest.cxx CppSnippetFieldDoubleBuildSubPart1_2
+
+\b f1 is a field on cells, \ref ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart "buildSubPart" method performs an extraction on cells too.
+
+So the array \b part1 lists ids on cells.
+
+- cell #0 of \b f2 is the same cell of cell #2 of \b f1
+- cell #1 of \b f2 is the same cell of cell #1 of \b f1
+- cell #2 of \b f2 is the same cell of cell #4 of \b f1
+
+So \b f2 contains 3 tuples with 2 components.
+
+The underlying mesh of \b f2 contains a newly created mesh with 3 cells (not as \b mesh1 in \b f1) and 9 nodes (as \b mesh1 in \b f1).
+\n For fields on cells the number of tuples of the returned field is always equal to the number of ids given in input (here \b part1).
+\nOnly fields on cells have this particular behaviour.
+
+<br><h3>Creation of a sub part of a field on nodes</h3>
+\snippet MEDCouplingExamplesTest.cxx CppSnippetFieldDoubleBuildSubPart1_3
+The field on nodes \b f1 lies on a mesh containg 5 cells and 9 nodes.
+So this field \b f1 contains 9 tuples of 2 components each (18 values).
+Now let's create a subfield on nodes \b f2 from \b f1.
+\snippet MEDCouplingExamplesTest.cxx CppSnippetFieldDoubleBuildSubPart1_4
+
+\b f1 is a field on nodes, but \ref ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart "buildSubPart" method performs an extraction on \b cells.
+
+After the call of \ref ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart "buildSubPart" on node field \b f1, \b f1 will be reduced on a
+submesh of \b mesh1 containing cells whoses ids are in \b part2. So here the number of cells of \b f2 is 2 and the number of nodes is 4.
+\nSo contrary to fields on cells, it is normal for fields on nodes that number of tuples of the returned field of \ref ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart "buildSubPart" 
+method does not match the size of the input array (here \b part2).
+
+*/
index 30500a0f4b59963fe8fd9ab8475e01d99fc8a0ca..070680bc3e3d98bc78eb03468dec48c8349f4e90 100644 (file)
@@ -398,6 +398,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const DataArrayInt
  * will contain 6 tuples and this field will lie on this restricted mesh.
  * 
  * \ref cpp_mcfielddouble_subpart1 "Here a C++ example."
+ *
+ * \ref py_mcfielddouble_subpart1 "Here a Python example."
  */
 MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const int *partBg, const int *partEnd) const throw(INTERP_KERNEL::Exception)
 {
index 834976089e0ebfd0a60718c4ac96d62bac6dbd90..1490d516d625886d10a861b32e52a4c9a7016f1b 100644 (file)
@@ -52,4 +52,5 @@ INSTALL(FILES MEDCoupling.i MEDCouplingRemapper.i MEDCouplingTypemaps.i DESTINAT
 INSTALL_AND_COMPILE_PYTHON_FILE("${PYFILES_TO_INSTALL}" ${MED_salomescript_PYTHON})
 
 ADD_TEST(MEDCouplingBasicsTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MEDCouplingBasicsTest.py)
+ADD_TEST(MEDCouplingExamplesTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MEDCouplingExamplesTest.py)
 ADD_TEST(MEDCouplingRemapperTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MEDCouplingRemapperTest.py)
diff --git a/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py b/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py
new file mode 100644 (file)
index 0000000..dcbc4d2
--- /dev/null
@@ -0,0 +1,140 @@
+#  -*- coding: iso-8859-1 -*-
+# Copyright (C) 2007-2011  CEA/DEN, EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+from MEDCoupling import *
+import unittest
+
+class MEDCouplingBasicsTest(unittest.TestCase):
+    def testExampleFieldDoubleBuildSubPart1(self):
+        from MEDCouplingDataForTest import MEDCouplingDataForTest
+#! [PySnippetFieldDoubleBuildSubPart1_1]
+        mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
+        f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
+        f1.setTime(2.3,5,6);
+        f1.setMesh(mesh1);
+        array=DataArrayDouble.New();
+        arr1=[3.,103.,4.,104.,5.,105.,6.,106.,7.,107.]
+        array.setValues(arr1,mesh1.getNumberOfCells(),2);
+        f1.setArray(array);
+## ! [PySnippetFieldDoubleBuildSubPart1_1]
+## ! [PySnippetFieldDoubleBuildSubPart1_2]
+        part1=[2,1,4]
+        f2=f1.buildSubPart(part1);
+## ! [PySnippetFieldDoubleBuildSubPart1_2]
+        f2.zipCoords()
+        self.failUnlessEqual(3,f2.getNumberOfTuples());
+        self.failUnlessEqual(2,f2.getNumberOfComponents());
+        expected1=[5.,105.,4.,104.,7.,107.]
+        for i in xrange(6):
+            self.assertAlmostEqual(f2.getIJ(0,i),expected1[i],12);
+            pass
+        self.failUnlessEqual(3,f2.getMesh().getNumberOfCells());
+        self.failUnlessEqual(6,f2.getMesh().getNumberOfNodes());
+        self.failUnlessEqual(2,f2.getMesh().getSpaceDimension());
+        self.failUnlessEqual(2,f2.getMesh().getMeshDimension());
+        m2C=f2.getMesh();
+        self.failUnlessEqual(13,m2C.getMeshLength());
+        expected2=[0.2, -0.3, 0.7, -0.3, 0.2, 0.2, 0.7, 0.2, 0.2, 0.7, 0.7, 0.7]
+        for i in xrange(12):
+            self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12);
+            pass
+        expected3=[3,2,3,1,3,0,2,1,4,4,5,3,2]
+        self.failUnlessEqual(expected3,list(m2C.getNodalConnectivity().getValues()));
+        expected4=[0,4,8,13]
+        self.failUnlessEqual(expected4,list(m2C.getNodalConnectivityIndex().getValues()));
+        # Test with field on nodes.
+## ! [PySnippetFieldDoubleBuildSubPart1_3]
+        f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
+        f1.setTime(2.3,5,6);
+        f1.setMesh(mesh1);
+        array=DataArrayDouble.New();
+        arr2=[3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.]
+        array.setValues(arr2,mesh1.getNumberOfNodes(),2);
+        f1.setArray(array);
+## ! [PySnippetFieldDoubleBuildSubPart1_3]
+## ! [PySnippetFieldDoubleBuildSubPart1_4]
+        part2=[1,2]
+        f2=f1.buildSubPart(part2);
+## ! [PySnippetFieldDoubleBuildSubPart1_4]
+        self.failUnlessEqual(4,f2.getNumberOfTuples());
+        self.failUnlessEqual(2,f2.getNumberOfComponents());
+        expected5=[4.,104.,5.,105.,7.,107.,8.,108.]
+        for i in xrange(8):
+            self.assertAlmostEqual(f2.getIJ(0,i),expected5[i],12);
+            pass
+        self.failUnlessEqual(2,f2.getMesh().getNumberOfCells());
+        self.failUnlessEqual(4,f2.getMesh().getNumberOfNodes());
+        self.failUnlessEqual(2,f2.getMesh().getSpaceDimension());
+        self.failUnlessEqual(2,f2.getMesh().getMeshDimension());
+        m2C=f2.getMesh();
+        self.failUnlessEqual(8,m2C.getMeshLength());
+        for i in xrange(8):#8 is not an error
+            self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12);
+            pass
+        self.failUnlessEqual(expected3[:4],list(m2C.getNodalConnectivity().getValues())[4:]);
+        self.failUnlessEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[:4]);
+        self.failUnlessEqual(expected4[:3],list(m2C.getNodalConnectivityIndex().getValues()));
+        #idem previous because nodes of cell#4 are not fully present in part3
+        part3=[1,2]
+        arrr=DataArrayInt.New();
+        arrr.setValues(part3,2,1);
+        f2=f1.buildSubPart(arrr);
+        self.failUnlessEqual(4,f2.getNumberOfTuples());
+        self.failUnlessEqual(2,f2.getNumberOfComponents());
+        for i in xrange(8):
+            self.assertAlmostEqual(f2.getIJ(0,i),expected5[i],12);
+            pass
+        self.failUnlessEqual(2,f2.getMesh().getNumberOfCells());
+        self.failUnlessEqual(4,f2.getMesh().getNumberOfNodes());
+        self.failUnlessEqual(2,f2.getMesh().getSpaceDimension());
+        self.failUnlessEqual(2,f2.getMesh().getMeshDimension());
+        m2C=f2.getMesh();
+        self.failUnlessEqual(8,m2C.getMeshLength());
+        for i in xrange(8):#8 is not an error
+            self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12);
+            pass
+        self.failUnlessEqual(expected3[:4],list(m2C.getNodalConnectivity().getValues())[4:8]);
+        self.failUnlessEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[:4]);
+        self.failUnlessEqual(expected4[:3],list(m2C.getNodalConnectivityIndex().getValues()));
+        part4=[1,2,4]
+        f2=f1.buildSubPart(part4);
+        self.failUnlessEqual(6,f2.getNumberOfTuples());
+        self.failUnlessEqual(2,f2.getNumberOfComponents());
+        expected6=[4.,104.,5.,105.,7.,107.,8.,108.,10.,110.,11.,111.]
+        for i in xrange(12):
+            self.assertAlmostEqual(f2.getIJ(0,i),expected6[i],12);
+            pass
+        self.failUnlessEqual(3,f2.getMesh().getNumberOfCells());
+        self.failUnlessEqual(6,f2.getMesh().getNumberOfNodes());
+        self.failUnlessEqual(2,f2.getMesh().getSpaceDimension());
+        self.failUnlessEqual(2,f2.getMesh().getMeshDimension());
+        m2C=f2.getMesh();
+        self.failUnlessEqual(13,m2C.getMeshLength());
+        for i in xrange(12):
+            self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12);
+            pass
+        self.failUnlessEqual(expected3[0:4],list(m2C.getNodalConnectivity().getValues())[4:8]);
+        self.failUnlessEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[0:4]);
+        self.failUnlessEqual(expected3[8:13],list(m2C.getNodalConnectivity().getValues())[8:13]);
+        self.failUnlessEqual(expected4,list(m2C.getNodalConnectivityIndex().getValues()));
+        pass
+    pass
+
+unittest.main()