Fixed: Loop in MxFiniteElement::write terminated one too early.

Changed: Let the MxFiniteElement constructor resize each of the Nx also.
Added: Small test program to check the printing and sizing.
This commit is contained in:
Knut Morten Okstad 2016-11-17 09:38:52 +01:00
parent a4f6334147
commit 7275a4fecc
3 changed files with 45 additions and 5 deletions

View File

@ -39,10 +39,22 @@ std::ostream& FiniteElement::write (std::ostream& os) const
} }
MxFiniteElement::MxFiniteElement (const std::vector<size_t>& n, size_t ip)
: FiniteElement(n.front(),ip)
{
Nx.resize(n.size()-1);
for (size_t b = 1; b < n.size(); b++)
Nx[b-1].resize(n[b]);
dNxdX.resize(Nx.size());
d2NxdX2.resize(Nx.size());
}
std::ostream& MxFiniteElement::write (std::ostream& os) const std::ostream& MxFiniteElement::write (std::ostream& os) const
{ {
this->FiniteElement::write(os); this->FiniteElement::write(os);
for (size_t b = 0; b+1 < Nx.size(); b++) for (size_t b = 0; b < Nx.size(); b++)
{ {
os <<"Basis "<< b+2 <<":\n"; os <<"Basis "<< b+2 <<":\n";
if (!Nx[b].empty()) os <<"N:"<< Nx[b]; if (!Nx[b].empty()) os <<"N:"<< Nx[b];

View File

@ -88,10 +88,8 @@ public:
class MxFiniteElement : public FiniteElement class MxFiniteElement : public FiniteElement
{ {
public: public:
//! \brief Default constructor. //! \brief The constructor initializes the size of each basis.
MxFiniteElement(const std::vector<size_t>& n, size_t i = 0) : MxFiniteElement(const std::vector<size_t>& n, size_t ip = 0);
FiniteElement(n.front(),i), Nx(n.size()-1), dNxdX(n.size()-1), d2NxdX2(n.size()-1)
{}
//! \brief Empty destructor. //! \brief Empty destructor.
virtual ~MxFiniteElement() {} virtual ~MxFiniteElement() {}

View File

@ -0,0 +1,30 @@
//==============================================================================
//!
//! \file TestFiniteElement.C
//!
//! \date Nov 17 2016
//!
//! \author Knut Morten Okstad / SINTEF
//!
//! \brief Unit tests for FiniteElement.
//!
//==============================================================================
#include "FiniteElement.h"
#include "gtest/gtest.h"
TEST(TestFiniteElement, Print)
{
FiniteElement fe1(4);
MxFiniteElement fe2({3,2,4});
std::cout << fe1 << std::endl;
std::cout << fe2 << std::endl;
ASSERT_EQ((int)fe1.N.size(),4);
ASSERT_EQ((int)fe2.basis(1).size(),3);
ASSERT_EQ((int)fe2.basis(2).size(),2);
ASSERT_EQ((int)fe2.basis(3).size(),4);
}