~ubuntu-branches/ubuntu/saucy/rheolef/saucy

« back to all changes in this revision

Viewing changes to nfem/plib/element.cc

  • Committer: Bazaar Package Importer
  • Author(s): Pierre Saramito
  • Date: 2011-03-23 11:14:26 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20110323111426-cjvhey7lxt6077ty
Tags: 5.93-1
* New upstream release (minor changes):
  - some extra warning message deleted in heap_allocator
  - graphic output with mayavi2 fixed
  - add doc refman in .info and .pdf format

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
///
20
20
/// =========================================================================
21
21
#include "rheolef/element.h"
 
22
#include "rheolef/basis_on_lattice.h"
22
23
 
23
24
namespace rheolef {
24
25
 
25
26
template<class T>
26
 
element_rep<T>::element_rep (std::string name) 
27
 
 : _name(name),
 
27
element_rep<T>::element_rep (std::string name, std::string numb) 
 
28
 : _name((numb != "") ? numb : name),
28
29
   _b(name),
29
 
   _numb(name+"_numbering"),
30
 
   _tr_p1("P1")
31
 
{
 
30
   _numb( ((numb != "") ? numb : name) + "_numbering"),
 
31
   _tr_p1("P1"),
 
32
   _tr_p1_value()
 
33
{
 
34
   _tr_p1_value.set (_b, _tr_p1);
 
35
}
 
36
// ----------------------------------------------------------------------------
 
37
// node associated to a dof: local (K,loc_idof) argument
 
38
// ----------------------------------------------------------------------------
 
39
template<class T>
 
40
template<class M>
 
41
basic_point<T>
 
42
element_rep<T>::x_dof (const geo_element& K, size_type loc_idof, const geo_basic<T,M>& omega) const
 
43
{
 
44
    // TODO: only P1 transformation supported : isoparametric not yet !
 
45
    warning_macro ("x_dof("<<name()<<") on K"<< K.dis_ie());
 
46
    basis_on_nodal_basis::const_iterator first = _tr_p1_value.begin(K,loc_idof);
 
47
    basis_on_nodal_basis::const_iterator last  = _tr_p1_value.end  (K,loc_idof);
 
48
    point x;
 
49
    size_type dim = omega.dimension();
 
50
    for (size_type k = 0; first != last; first++, k++) {
 
51
        const point& ak = omega.vertex (K[k]);
 
52
        Float ck = (*first);
 
53
        warning_macro ("coef["<<k<<"]="<<ck);
 
54
        for (size_type i = 0; i < dim; i++) {
 
55
          x[i] += ck * ak[i];
 
56
        }
 
57
    }
 
58
    return x;
 
59
}
 
60
// ----------------------------------------------------------------------------
 
61
// node associated to a dof: "idof" argument
 
62
// ----------------------------------------------------------------------------
 
63
template<class T>
 
64
template<class M>
 
65
basic_point<T>
 
66
element_rep<T>::x_dof (size_type idof, const geo_basic<T,M>& omega) const
 
67
{
 
68
    if (name() == "P1") {
 
69
        return omega.vertex (idof);
 
70
    } else if (name() == "P0") {
 
71
        const geo_element& K = omega[idof];
 
72
        basic_point<T> x;
 
73
        for (size_type iloc = 0, nloc = K.size(); iloc < nloc; iloc++) {
 
74
          x += omega.dis_vertex (K[iloc]);
 
75
        }
 
76
        x /= K.size();
 
77
        warning_macro ("x_dof = " << x);
 
78
        return x;
 
79
    } else if (name() == "P1d") {
 
80
        size_type nvert_per_elt;
 
81
        switch (omega.map_dimension()) {
 
82
          case 0: {
 
83
            nvert_per_elt = 1;
 
84
            break;
 
85
          }
 
86
          case 1: {
 
87
            nvert_per_elt = 2;
 
88
            break;
 
89
          }
 
90
          case 2: {
 
91
            if (omega.dis_size_by_variant()[reference_element::t] != 0) {
 
92
              nvert_per_elt = 3;
 
93
            } else {
 
94
              nvert_per_elt = 4;
 
95
            }
 
96
            break;
 
97
          }
 
98
          case 3:
 
99
          default: {
 
100
            if (omega.dis_size_by_variant()[reference_element::T] != 0) {
 
101
              nvert_per_elt = 4;
 
102
            } else if (omega.dis_size_by_variant()[reference_element::P] != 0) {
 
103
              nvert_per_elt = 6;
 
104
            } else {
 
105
              nvert_per_elt = 8;
 
106
            }
 
107
          }
 
108
        }
 
109
        // TODO: extend P1d mixed (t,q) or (T,P,H) meshes: nvert_per_elt is no more constant
 
110
        size_type ie   = idof/nvert_per_elt;
 
111
        size_type iloc = idof - ie*nvert_per_elt;
 
112
        const geo_element& K = omega[ie];
 
113
        size_type dis_iv = K[iloc];
 
114
        const basic_point<T>& x = omega.dis_vertex(dis_iv);
 
115
        return x;
 
116
    } else {
 
117
        // TODO: extend P2
 
118
        error_macro ("unsupported x_dof for \""<<name()<<"\" element");
 
119
        return basic_point<T>();
 
120
    }
32
121
}
33
122
// ----------------------------------------------------------------------------
34
123
// instanciation in library
37
126
template class element_rep<Float>;
38
127
template class lagrange<Float>;
39
128
 
 
129
template
 
130
basic_point<Float> element_rep<Float>::x_dof (const geo_element& K, size_type loc_idof, const geo_basic<Float,sequential>& omeqa) const;
 
131
template
 
132
basic_point<Float> element_rep<Float>::x_dof (size_type idof, const geo_basic<Float,sequential>& omeqa) const;
 
133
 
 
134
#ifdef _RHEOLEF_HAVE_MPI
 
135
template
 
136
basic_point<Float> element_rep<Float>::x_dof (const geo_element& K, size_type loc_idof, const geo_basic<Float,distributed>& omeqa) const;
 
137
template
 
138
basic_point<Float> element_rep<Float>::x_dof (size_type idof, const geo_basic<Float,distributed>& omeqa) const;
 
139
#endif // _RHEOLEF_HAVE_MPI
40
140
 
41
141
} // namespace rheolef