void
MAST::StructuralElementBase::_get_side_fe_and_qrule(const libMesh::Elem& e,
                                                    unsigned int s,
                                                    std::auto_ptr<libMesh::FEBase>& fe,
                                                    std::auto_ptr<libMesh::QBase>& qrule) {
    unsigned int nv = _system.n_vars();
    
    libmesh_assert (nv);
    libMesh::FEType fe_type = _system.variable_type(0); // all variables are assumed to be of same type
    
    
    for (unsigned int i=1; i != nv; ++i)
        libmesh_assert(fe_type == _system.variable_type(i));
    
    // Create an adequate quadrature rule
    fe.reset(libMesh::FEBase::build(e.dim(), fe_type).release());
    qrule.reset(fe_type.default_quadrature_rule
                (e.dim()-1,
                 _system.extra_quadrature_order).release());  // system extra quadrature
    fe->attach_quadrature_rule(qrule.get());
    fe->get_phi();
    fe->get_JxW();
    
    fe->reinit(&e, s);
}
void
MAST::StructuralElementBase::_init_fe_and_qrule( const libMesh::Elem& e) {
    
    unsigned int nv = _system.n_vars();
    
    libmesh_assert (nv);
    libMesh::FEType fe_type = _system.variable_type(0); // all variables are assumed to be of same type
    
    
    for (unsigned int i=1; i != nv; ++i)
        libmesh_assert(fe_type == _system.variable_type(i));
    
    // Create an adequate quadrature rule
    _fe.reset(libMesh::FEBase::build(e.dim(), fe_type).release());
    _qrule.reset(fe_type.default_quadrature_rule
                 (e.dim(),
                  _system.extra_quadrature_order +  // system extra quadrature
                  _property.extra_quadrature_order(e, fe_type)).release()); // elem extra quadrature
    _fe->attach_quadrature_rule(_qrule.get());
    _fe->get_phi();
    _fe->get_JxW();
    _fe->get_dphi();
    _fe->get_dxyzdxi();
    _fe->get_dxyzdeta();
    _fe->get_dxyzdzeta();
    
    _fe->reinit(&e);
}
std::auto_ptr<MAST::StructuralElementBase>
MAST::build_structural_element(libMesh::System& sys,
                               const libMesh::Elem& elem,
                               const MAST::ElementPropertyCardBase& p) {
    
    std::auto_ptr<MAST::StructuralElementBase> e;
    
    switch (elem.dim()) {
        case 1:
            e.reset(new MAST::StructuralElement1D(sys, elem, p));
            break;
            
        case 2:
            e.reset(new MAST::StructuralElement2D(sys, elem, p));
            break;
            
        case 3:
            e.reset(new MAST::StructuralElement3D(sys, elem, p));
            break;

        default:
            libmesh_error();
            break;
    }
    
    return e;
}
MAST::HeatConductionElementBase::
HeatConductionElementBase(MAST::SystemInitialization& sys,
                          const libMesh::Elem& elem,
                          const MAST::ElementPropertyCardBase& p,
                          const bool if_output_eval):
MAST::ElementBase(sys, elem),
_property(p) {

    MAST::LocalElemBase* rval = NULL;
    
    switch (elem.dim()) {
        case 1: {
            const MAST::ElementPropertyCard1D& p_1d =
            dynamic_cast<const MAST::ElementPropertyCard1D&>(p);
            rval = new MAST::Local1DElem(elem, p_1d.y_vector());
        }
            break;
            
        case 2:
            rval = new MAST::Local2DElem(elem);
            break;
            
        case 3:
            rval = new MAST::Local3DElem(elem);
            break;
            
        default:
            // should not get here.
            libmesh_error();
            break;
    }
    
    _local_elem.reset(rval);
    
    // now initialize the finite element data structures
    if (!if_output_eval)
        _init_fe_and_qrule(_local_elem->local_elem());
}
MAST::BendingOperatorType
MAST::ElementPropertyCard1D::bending_model(const libMesh::Elem& elem,
                                           const libMesh::FEType& fe) const {
    // for an EDGE2 element, default bending is Bernoulli. For all other elements
    // the default is Timoshenko. Otherwise it returns the model set for
    // this card.
    switch (elem.type()) {
        case libMesh::EDGE2:
            if ((fe.family == libMesh::LAGRANGE) &&
                (fe.order  == libMesh::FIRST) &&
                (_bending_model == MAST::DEFAULT_BENDING))
                return MAST::BERNOULLI;
            else
                return MAST::TIMOSHENKO;
            break;
            
        default:
            if (_bending_model == MAST::DEFAULT_BENDING)
                return MAST::TIMOSHENKO;
            else
                return _bending_model;
            break;
    }
}