Salome HOME
7a2c28e53daf61bc30bdbcd20f8e774b0ccb6649
[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
22 s1=2709
23 s2=2848
24 f=file("InterpKernelGaussCoords.cxx","r")
25 lines=[elt[:-1] for elt in f.readlines()[s1:s2]]
26 pat0=re.compile("void[\s]+GaussInfo\:\:([^\(]+)\([\s]*\)[\s]*$")
27 pat1=re.compile("[\s]*\{[\s]*$")
28 pat2=re.compile("[\s]+LOCAL_COORD_MACRO_BEGIN[\s]*\;[\s]*$")
29 m0=pat0.match(lines[0])
30 m1=pat1.match(lines[1])
31 m2=pat2.match(lines[2])
32 if (not m0) or (not m1) or (not m2):
33     raise Exception("Invalid first lines")
34 offsetLines=3
35 patEnd=re.compile("[\s]+LOCAL_COORD_MACRO_END[\s]*\;[\s]*$")
36 mEnd=patEnd.match(lines[-1])
37 if not mEnd:
38     raise Exception("Invalid end lines")
39 #
40 nbLines=len(lines)-4
41 casePat=re.compile("[\s]+case[\s]+([\d]+)\:[\s]*$")
42 entries=filter(lambda (i,x): casePat.match(x),enumerate(lines[offsetLines:-1]))
43 #
44 nbPts=len(entries)
45 if nbLines%nbPts!=0:
46     raise Exception("Invalid lines nb !")
47 dim=nbLines/nbPts-2
48 if dim<1 or dim>3:
49     raise Exception("Ooops invalid dim !")
50 entries=[(i,int(casePat.match(elt).group(1))) for i,elt in entries]
51 assert(set([elt[1] for elt in entries])==set(range(nbPts)))
52 #
53 partEndEntries=re.compile("[\s]*break[\s]*\;[\s]*$")
54 zePat=re.compile("[\s]+coords\[([\d]+)\][\s]*=[\s]*([\-]?[\d]+[\.]?[\d]*)[\s]*\;[\s]*$")
55 zeTab=(nbPts*dim)*[None]
56 for lineId,ptId in entries:
57     endLine=lines[offsetLines+lineId+1+dim]
58     assert(partEndEntries.match(endLine))
59     for j in xrange(dim):
60         curLine=lines[offsetLines+lineId+1+j]
61         m=zePat.match(curLine)
62         assert(m)
63         assert(int(m.group(1))==j)
64         zeTab[ptId*dim+j]=m.group(2)
65         pass
66     pass
67 assert(None not in zeTab)
68 patInit="Init"
69 assert(m0.group(1)[-len(patInit):]==patInit)
70 varName="%s_REF"%((m0.group(1)[:-len(patInit)]).upper())
71 print("const double %s[%d]={%s};"%(varName,len(zeTab),", ".join(zeTab)))
72 for i in xrange(nbPts):
73     print("  case %d:"%(i))
74     for j in xrange(dim):
75         print("    coords[%d] = %s[%d];"%(j,varName,i*dim+j))
76         pass
77     print("    break;")
78