Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Derive Dof from Flags #12196

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 18 additions & 40 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));
KRATOS_SERIALIZE_SAVE_BASE_CLASS(rSerializer, Flags);
rSerializer.save("EquationId", static_cast<EquationIdType>(mEquationId));
rSerializer.save("NodalData", mpNodalData);
rSerializer.save("VariableType", static_cast<int>(mVariableType));
Expand All @@ -497,12 +478,9 @@ 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;
KRATOS_SERIALIZE_LOAD_BASE_CLASS(rSerializer, Flags);
EquationIdType equation_id;
rSerializer.load("EquationId", equation_id);
mEquationId = equation_id;
Expand Down
2 changes: 1 addition & 1 deletion kratos/includes/kratos_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ KRATOS_CREATE_FLAG(BLOCKED, 36);
KRATOS_CREATE_FLAG(MARKER, 35);
KRATOS_CREATE_FLAG(PERIODIC, 34);
KRATOS_CREATE_FLAG(WALL, 33);
// KRATOS_CREATE_FLAG(,32);
KRATOS_CREATE_FLAG(FIXED, 32);
// KRATOS_CREATE_FLAG(,31);
// KRATOS_CREATE_FLAG(,30);

Expand Down
Loading