Skip to content

Commit

Permalink
derive Dof from Flags
Browse files Browse the repository at this point in the history
  • Loading branch information
matekelemen committed Mar 17, 2024
1 parent fb6a735 commit e2ad332
Showing 1 changed file with 20 additions and 39 deletions.
59 changes: 20 additions & 39 deletions kratos/includes/dof.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "includes/define.h"
#include "containers/data_value_container.h"
#include "containers/nodal_data.h"
#include "containers/flags.h"
#include "includes/kratos_flags.h"

namespace Kratos
{
Expand Down Expand Up @@ -83,7 +85,7 @@ This class enables the system to work with different set of dofs and also
represents the Dirichlet condition assigned to each dof.
*/
template<class TDataType>
class Dof{
class Dof : public Flags {
public:
///@name Type Definitions
///@{
Expand Down Expand Up @@ -118,7 +120,7 @@ class Dof{
template<class TVariableType>
Dof(NodalData* pThisNodalData,
const TVariableType& rThisVariable)
: mIsFixed(false),
: Flags(),
mVariableType(DofTrait<TDataType, TVariableType>::Id),
mReactionType(DofTrait<TDataType, Variable<TDataType> >::Id),
mEquationId(IndexType()),
Expand Down Expand Up @@ -156,7 +158,7 @@ class Dof{
Dof(NodalData* pThisNodalData,
const TVariableType& rThisVariable,
const TReactionType& rThisReaction)
: mIsFixed(false),
: Flags(),
mVariableType(DofTrait<TDataType, TVariableType>::Id),
mReactionType(DofTrait<TDataType, TReactionType>::Id),
mEquationId(IndexType()),
Expand All @@ -175,7 +177,7 @@ class Dof{

//This default constructor is needed for serializer
Dof()
: mIsFixed(false),
: Flags(),
mVariableType(DofTrait<TDataType, Variable<TDataType> >::Id),
mReactionType(DofTrait<TDataType, Variable<TDataType> >::Id),
mIndex(),
Expand All @@ -185,15 +187,7 @@ class Dof{
}

/// Copy constructor.
Dof(Dof const& rOther)
: mIsFixed(rOther.mIsFixed),
mVariableType(rOther.mVariableType),
mReactionType(rOther.mReactionType),
mIndex(rOther.mIndex),
mEquationId(rOther.mEquationId),
mpNodalData(rOther.mpNodalData)
{
}
Dof(Dof const& rOther) = default;


/// Destructor.
Expand All @@ -205,17 +199,7 @@ class Dof{
///@{

/// Assignment operator.
Dof& operator=(Dof const& rOther)
{
mIsFixed = rOther.mIsFixed;
mEquationId = rOther.mEquationId;
mpNodalData = rOther.mpNodalData;
mIndex = rOther.mIndex;
mVariableType = rOther.mVariableType;
mReactionType = rOther.mReactionType;

return *this;
}
Dof& operator=(Dof const& rOther) = default;

template<class TVariableType>
typename TVariableType::Type& operator()(const TVariableType& rThisVariable, IndexType SolutionStepIndex = 0)
Expand Down Expand Up @@ -337,14 +321,14 @@ class Dof{
*/
void FixDof()
{
mIsFixed=true;
this->Set(FIXED);
}

/** Frees the degree of freedom
*/
void FreeDof()
{
mIsFixed=false;
this->Set(FIXED, false);
}

SolutionStepsDataContainerType* GetSolutionStepsData()
Expand Down Expand Up @@ -375,7 +359,7 @@ class Dof{

bool IsFixed() const
{
return mIsFixed;
return this->Is(FIXED);
}


Expand All @@ -390,7 +374,7 @@ class Dof{


/// Turn back information as a string.
std::string Info() const
std::string Info() const override
{
std::stringstream buffer;

Expand All @@ -403,13 +387,13 @@ class Dof{
}

/// Print information about this object.
void PrintInfo(std::ostream& rOStream) const
void PrintInfo(std::ostream& rOStream) const override
{
rOStream << Info();
}

/// Print object's data.
void PrintData(std::ostream& rOStream) const
void PrintData(std::ostream& rOStream) const override
{
rOStream << " Variable : " << GetVariable().Name() << std::endl;
rOStream << " Reaction : " << GetReaction().Name() << std::endl;
Expand All @@ -436,9 +420,6 @@ class Dof{
///@name Member Variables
///@{

/** True is is fixed */
int mIsFixed : 1;

int mVariableType : 4;

int mReactionType : 4;
Expand Down Expand Up @@ -486,9 +467,9 @@ class Dof{

friend class Serializer;

void save(Serializer& rSerializer) const
void save(Serializer& rSerializer) const override
{
rSerializer.save("IsFixed", static_cast<bool>(mIsFixed));
rSerializer.save("Flags", static_cast<Flags>(*this));
rSerializer.save("EquationId", static_cast<EquationIdType>(mEquationId));
rSerializer.save("NodalData", mpNodalData);
rSerializer.save("VariableType", static_cast<int>(mVariableType));
Expand All @@ -497,12 +478,12 @@ class Dof{

}

void load(Serializer& rSerializer)
void load(Serializer& rSerializer) override
{
std::string name;
bool is_fixed;
rSerializer.load("IsFixed", is_fixed);
mIsFixed=is_fixed;
Flags flags;
rSerializer.load("Flags", flags);
static_cast<Flags&>(*this) = flags;
EquationIdType equation_id;
rSerializer.load("EquationId", equation_id);
mEquationId = equation_id;
Expand Down

0 comments on commit e2ad332

Please sign in to comment.