Salome HOME
Ready for Salome9/py3 - Thanks a lot Gilles
[tools/medcoupling.git] / src / INTERP_KERNEL / GaussPoints / CleanUpGauss.py
1 # Copyright (C) 2007-2017  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 # Author : Anthony Geay (EDF R&D)
19
20 import re
21 import sys
22
23 s1=2709
24 s2=2848
25 f=file("InterpKernelGaussCoords.cxx","r")
26 lines=[elt[:-1] for elt in f.readlines()[s1:s2]]
27 pat0=re.compile("void[\s]+GaussInfo\:\:([^\(]+)\([\s]*\)[\s]*$")
28 pat1=re.compile("[\s]*\{[\s]*$")
29 pat2=re.compile("[\s]+LOCAL_COORD_MACRO_BEGIN[\s]*\;[\s]*$")
30 m0=pat0.match(lines[0])
31 m1=pat1.match(lines[1])
32 m2=pat2.match(lines[2])
33 if (not m0) or (not m1) or (not m2):
34     raise Exception("Invalid first lines")
35 offsetLines=3
36 patEnd=re.compile("[\s]+LOCAL_COORD_MACRO_END[\s]*\;[\s]*$")
37 mEnd=patEnd.match(lines[-1])
38 if not mEnd:
39     raise Exception("Invalid end lines")
40 #
41 nbLines=len(lines)-4
42 casePat=re.compile("[\s]+case[\s]+([\d]+)\:[\s]*$")
43 entries=[i_x for i_x in enumerate(lines[offsetLines:-1]) if casePat.match(i_x[1])]
44 #
45 nbPts=len(entries)
46 if nbLines%nbPts!=0:
47     raise Exception("Invalid lines nb !")
48 dim=nbLines/nbPts-2
49 if dim<1 or dim>3:
50     raise Exception("Ooops invalid dim !")
51 entries=[(i,int(casePat.match(elt).group(1))) for i,elt in entries]
52 assert({elt[1] for elt in entries} == set(range(nbPts)))
53 #
54 partEndEntries=re.compile("[\s]*break[\s]*\;[\s]*$")
55 zePat=re.compile("[\s]+coords\[([\d]+)\][\s]*=[\s]*([\-]?[\d]+[\.]?[\d]*)[\s]*\;[\s]*$")
56 zeTab=(nbPts*dim)*[None]
57 for lineId,ptId in entries:
58     endLine=lines[offsetLines+lineId+1+dim]
59     assert(partEndEntries.match(endLine))
60     for j in range(dim):
61         curLine=lines[offsetLines+lineId+1+j]
62         m=zePat.match(curLine)
63         assert(m)
64         assert(int(m.group(1))==j)
65         zeTab[ptId*dim+j]=m.group(2)
66         pass
67     pass
68 assert(None not in zeTab)
69 patInit="Init"
70 assert(m0.group(1)[-len(patInit):]==patInit)
71 varName="%s_REF"%((m0.group(1)[:-len(patInit)]).upper())
72 print(("const double %s[%d]={%s};"%(varName,len(zeTab),", ".join(zeTab))))
73 for i in range(nbPts):
74     print(("  case %d:"%(i)))
75     for j in range(dim):
76         print(("    coords[%d] = %s[%d];"%(j,varName,i*dim+j)))
77         pass
78     print("    break;")
79