~chaffra/fiat/main

« back to all changes in this revision

Viewing changes to FIAT/P0.py

  • Committer: kirby
  • Date: 2005-05-31 15:03:57 UTC
  • Revision ID: devnull@localhost-20050531150357-n7ka5987yo6ylpaz
[project @ 2005-05-31 15:03:57 by kirby]
Initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Written by Robert C. Kirby
 
2
# Copyright 2005 by The University of Chicago
 
3
# Distributed under the LGPL license
 
4
# This work is partially supported by the US Department of Energy
 
5
# under award number DE-FG02-04ER25650
 
6
 
 
7
# last edited 16 May 2005
 
8
import shapes, dualbasis, polynomial, Numeric, points, functional
 
9
import functionalset
 
10
 
 
11
class P0Dual( dualbasis.DualBasis ):
 
12
    def __init__( self , shape , U ):
 
13
        # get barycenter
 
14
        vs = shapes.vertices[shape]
 
15
        bary = Numeric.average( Numeric.array( map( Numeric.array , \
 
16
                                                   vs.values() ) ) )
 
17
        
 
18
        self.pts = ( tuple(bary) , )
 
19
        ls = [ functional.PointEvaluation( U , bary ) ]
 
20
        entity_ids = { }
 
21
        d = shapes.dims[ shape ]
 
22
        for i in range(d):
 
23
            entity_ids[i] = {}
 
24
            for j in shapes.entity_range(shape,i):
 
25
                entity_ids[i][j] = {}
 
26
        entity_ids[d] = { 0 : [ 0 ] }
 
27
 
 
28
        fset = functionalset.FunctionalSet( U , ls )
 
29
 
 
30
        dualbasis.DualBasis.__init__( self , fset , entity_ids )
 
31
 
 
32
class P0( polynomial.FiniteElement ):
 
33
    def __init__( self , shape ):
 
34
        U = polynomial.OrthogonalPolynomialSet( shape , 0 )
 
35
        Udual = P0Dual( shape , U )
 
36
        polynomial.FiniteElement.__init__( self , Udual , U )
 
37
 
 
38
class VecP0Dual( dualbasis.DualBasis ):
 
39
    def __init__( self , shape , U ):
 
40
        # get barycenter
 
41
        d = shapes.dimension( shape )
 
42
        nc = U.tensor_shape()[0]
 
43
        vs = shapes.vertices[ shape ]
 
44
        bary = Numeric.average( Numeric.array( map( Numeric.array , \
 
45
                                                    vs.values() ) ) )
 
46
        self.pts = ( tuple(bary) , )
 
47
        ls = [ functional.ComponentPointEvaluation( U , c , bary ) \
 
48
               for c in range( d ) ]
 
49
        entity_ids = {}
 
50
        for i in range(d):
 
51
            entity_ids[i] = {}
 
52
            for j in shapes.entity_range( shape , i ):
 
53
                entity_ids[i][j] = {}
 
54
        entity_ids[d] = { 0 : range( len(ls) ) }
 
55
 
 
56
        fset = functionalset.FunctionalSet( U , ls )
 
57
 
 
58
        dualbasis.DualBasis.__init__( self , fset , entity_ids , nc )
 
59
 
 
60
class VecP0( polynomial.FiniteElement ):
 
61
    def __init__( self , shape , nc=None ):
 
62
        U = polynomial.OrthogonalPolynomialArraySet( shape , 0 , nc )
 
63
        Udual = VecP0Dual( shape , U )
 
64
        polynomial.FiniteElement.__init__( self , Udual , U )
 
65