From ab874af5f6e32c4c272a8f1116f33a6656833bf9 Mon Sep 17 00:00:00 2001 From: Knut Morten Okstad Date: Tue, 22 Dec 2015 14:45:00 +0100 Subject: [PATCH] Added: Initialization of member nsd in the IntegrandBase constructor. Changed: Using sprintf instead of stringstream, since that is used elsewhere. Changed: IntegrandBase::getNoSpaceDim does not need to be virtual. Changed: Static function Ierror removed. --- src/ASM/IntegrandBase.C | 50 +++++++++++++++++------------------------ src/ASM/IntegrandBase.h | 21 ++++++++--------- 2 files changed, 31 insertions(+), 40 deletions(-) diff --git a/src/ASM/IntegrandBase.C b/src/ASM/IntegrandBase.C index e544e92e..010be248 100644 --- a/src/ASM/IntegrandBase.C +++ b/src/ASM/IntegrandBase.C @@ -19,21 +19,9 @@ #include "Field.h" #include "Fields.h" #include -#include #include -/*! - \brief Convenience function writing error message for non-implemented methods. -*/ - -static bool Ierror (const char* name) -{ - std::cerr <<" *** IntegrandBase::"<< name <<" not implemented."<< std::endl; - return false; -} - - /*! The default implementation returns an ElmMats object with one left-hand-side matrix (unless we are doing a boundary integral) and one right-hand-side @@ -126,7 +114,7 @@ bool IntegrandBase::initElementBou (const std::vector& MNPC, const std::vector& basis_sizes, LocalIntegral& elmInt) { - std::vector MNPC1(MNPC.begin(), MNPC.begin()+elem_sizes.front()); + std::vector MNPC1(MNPC.begin(),MNPC.begin()+elem_sizes.front()); return this->initElementBou(MNPC1,elmInt); } @@ -134,7 +122,8 @@ bool IntegrandBase::initElementBou (const std::vector& MNPC, bool IntegrandBase::evalSol (Vector& s, const FiniteElement& fe, const Vec3& X, const std::vector& MNPC) const { - return Ierror("evalSol(Vector&,const FiniteElement& fe,const Vec3&,...)"); + std::cerr << __PRETTY_FUNCTION__ <<": Not implemented."<< std::endl; + return false; } @@ -143,26 +132,29 @@ bool IntegrandBase::evalSol (Vector& s, const MxFiniteElement& fe, const std::vector& elem_sizes, const std::vector& basis_sizes) const { - std::vector MNPC1(MNPC.begin(), MNPC.begin()+elem_sizes.front()); + std::vector MNPC1(MNPC.begin(),MNPC.begin()+elem_sizes.front()); return this->evalSol(s,fe,X,MNPC1); } -bool IntegrandBase::evalSol (Vector& s, const TensorFunc& asol, const Vec3& X) const +bool IntegrandBase::evalSol (Vector& s, const TensorFunc& asol, + const Vec3& X) const { s = Vector(asol(X).ptr(),nsd*nsd); return true; } -bool IntegrandBase::evalSol (Vector& s, const STensorFunc& asol, const Vec3& X) const +bool IntegrandBase::evalSol (Vector& s, const STensorFunc& asol, + const Vec3& X) const { s = Vector(asol(X).ptr(),nsd*(nsd+1)/2); return true; } -bool IntegrandBase::evalSol (Vector& s, const VecFunc& asol, const Vec3& X) const +bool IntegrandBase::evalSol (Vector& s, const VecFunc& asol, + const Vec3& X) const { s = Vector(asol(X).ptr(),nsd); return true; @@ -200,22 +192,20 @@ Vector* IntegrandBase::getNamedVector (const std::string& name) const return it == myFields.end() ? nullptr : it->second; } -std::string IntegrandBase::getField1Name(size_t idx, const char* prefix) const + +std::string IntegrandBase::getField1Name (size_t idx, const char* prefix) const { - std::stringstream stream; - if(prefix) - stream << prefix << " "; - stream << "primary solution " << idx+1; - return stream.str(); + char name[32]; + sprintf(name,"primary solution %lu",1+idx); + return prefix ? prefix + std::string(" ") + name : name; } -std::string IntegrandBase::getField2Name(size_t idx, const char* prefix) const + +std::string IntegrandBase::getField2Name (size_t idx, const char* prefix) const { - std::stringstream stream; - if(prefix) - stream << prefix << " "; - stream << "secondary solution " << idx+1; - return stream.str(); + char name[32]; + sprintf(name,"secondary solution %lu",1+idx); + return prefix ? prefix + std::string(" ") + name : name; } diff --git a/src/ASM/IntegrandBase.h b/src/ASM/IntegrandBase.h index e856da90..4acccee9 100644 --- a/src/ASM/IntegrandBase.h +++ b/src/ASM/IntegrandBase.h @@ -41,7 +41,7 @@ class IntegrandBase : public Integrand { protected: //! \brief The default constructor is protected to allow sub-classes only. - IntegrandBase() : npv(1), m_mode(SIM::INIT) {} + IntegrandBase(unsigned short int n = 0) : nsd(n), npv(1), m_mode(SIM::INIT) {} public: //! \brief Empty destructor. @@ -87,6 +87,7 @@ public: // Element-level initialization interface // ====================================== + using Integrand::getLocalIntegral; //! \brief Returns a local integral contribution object for the given element. //! \param[in] nen Number of nodes on element //! \param[in] iEl Global element number (1-based) @@ -217,19 +218,19 @@ public: //! \brief Returns a pointer to an Integrand for nodal force evaluation. virtual ForceBase* getForceIntegrand() const { return 0; } - //! \brief Returns number of spatial dimensions. - virtual size_t getNoSpaceDim() const { return nsd; } + //! \brief Returns the number of spatial dimensions. + size_t getNoSpaceDim() const { return nsd; } //! \brief Returns the number of primary/secondary solution field components. virtual size_t getNoFields(int = 2) const { return 0; } //! \brief Returns the name of a primary solution field component. - //! \param[in] idx Identifier integer for multiple solutions - //! \param[in] prefix Field names will start with this string - virtual std::string getField1Name(size_t idx, const char* prefix = 0) const ; + //! \param[in] idx Field component index + //! \param[in] prefix Name prefix for all components + virtual std::string getField1Name(size_t idx, const char* prefix = 0) const; //! \brief Returns the name of a secondary solution field component. - //! \param[in] idx Identifier integer for multiple solutions - //! \param[in] prefix Field names will start with this string - virtual std::string getField2Name(size_t idx, const char* prefix = 0) const ; + //! \param[in] idx Field component index + //! \param[in] prefix Name prefix for all components + virtual std::string getField2Name(size_t idx, const char* prefix = 0) const; //! \brief Returns the number of solution vectors. size_t getNoSolutions() const { return primsol.size(); } @@ -268,9 +269,9 @@ private: protected: unsigned short int nsd; //!< Number of spatial dimensions (1,2 or, 3) - Vectors primsol; //!< Primary solution vectors for current patch unsigned short int npv; //!< Number of primary solution variables per node SIM::SolutionMode m_mode; //!< Current solution mode + Vectors primsol; //!< Primary solution vectors for current patch };