Package sfc :: Package common :: Module names
[hide private]
[frames] | no frames]

Source Code for Module sfc.common.names

 1  #!/usr/bin/env python 
 2  # -*- coding: utf-8 -*- 
 3  """ 
 4  This module contains tools for consistent naming of classes. 
 5  """ 
 6   
 7  # Copyright (C) 2008-2009 Martin Sandve Alnes and Simula Resarch Laboratory 
 8  # 
 9  # This file is part of SyFi. 
10  # 
11  # SyFi is free software: you can redistribute it and/or modify 
12  # it under the terms of the GNU General Public License as published by 
13  # the Free Software Foundation, either version 2 of the License, or 
14  # (at your option) any later version. 
15  # 
16  # SyFi is distributed in the hope that it will be useful, 
17  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
18  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
19  # GNU General Public License for more details. 
20  # 
21  # You should have received a copy of the GNU General Public License 
22  # along with SyFi. If not, see <http://www.gnu.org/licenses/>. 
23  # 
24  # First added:  2008-08-12 
25  # Last changed: 2009-04-23 
26   
27  import re 
28  import hashlib 
29   
30 -def hashit(obj):
31 "Return a hash string for an object." 32 return hashlib.md5(obj).hexdigest().lower()
33
34 -def short_name(prefix, name, max_name_length = 60):
35 "Limit string length by computing a hash of it if it is too long." 36 if len(name) > max_name_length: 37 name = hashit(name) 38 return prefix + name
39
40 -def base_element_classname(element):
41 #return "%s_%s_%d" % (element.family, element.cell, element.degree) 42 s = repr(element).strip() 43 s = re.sub("[^\w]", "_", s) 44 s = re.sub("_+", "_", s) 45 s = s.strip("_") 46 return s
47
48 -def finite_element_classname(element):
49 return short_name("fe_", base_element_classname(element))
50
51 -def dof_map_classname(element):
52 return short_name("dm_", base_element_classname(element))
53
54 -def integral_classname(integral, form_name):
55 m = integral.measure() 56 prefix = "%s_integral_%s" % (m.domain_type(), m.domain_id()) 57 return short_name(prefix, form_name)
58
59 -def form_classname(form_signature, options):
60 if options.code.form.name: 61 form_name = options.code.form.name 62 else: 63 form_name = hashit(form_signature + repr(options)) 64 return short_name("form_", form_name)
65