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

[Core] Derive Dof from Flags #12196

wants to merge 5 commits into from

Conversation

matekelemen
Copy link
Contributor

See #11916

Changes

  • derive Dof from Flags
  • add new flag FIXED
  • replace the mIsFixed boolean member with the FIXED flag
  • adjust the serialization/deserialization of Dof to include Flags

@loumalouomega
Copy link
Member

Fine from my side, but this must be approved by technical committee. In any case I hope the performance penalty is not super high

Copy link
Member

@RiccardoRossi RiccardoRossi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is actually a good idea. One problem is that how flags are implemented as of now they occupy 2 doubles, so it is a memory increase. Nevertheless the idea is definitely worth exploring

@matekelemen
Copy link
Contributor Author

This PR will also open the possibility to make the StructuralMechanicsApplication a bit more consistent.

def AddDofs(self):
# Append formulation-related DOFs and reactions
dofs_and_reactions_to_add = []
dofs_and_reactions_to_add.append(["DISPLACEMENT_X", "REACTION_X"])
dofs_and_reactions_to_add.append(["DISPLACEMENT_Y", "REACTION_Y"])
dofs_and_reactions_to_add.append(["DISPLACEMENT_Z", "REACTION_Z"])
if self.settings["rotation_dofs"].GetBool():
dofs_and_reactions_to_add.append(["ROTATION_X", "REACTION_MOMENT_X"])
dofs_and_reactions_to_add.append(["ROTATION_Y", "REACTION_MOMENT_Y"])
dofs_and_reactions_to_add.append(["ROTATION_Z", "REACTION_MOMENT_Z"])
if self.settings["volumetric_strain_dofs"].GetBool():
dofs_and_reactions_to_add.append(["VOLUMETRIC_STRAIN", "REACTION_STRAIN"])
if self.settings["displacement_control"].GetBool():
dofs_and_reactions_to_add.append(["LOAD_FACTOR", "PRESCRIBED_DISPLACEMENT"])
# Append user-defined DOFs and reactions in the ProjectParameters
auxiliary_solver_utilities.AddAuxiliaryDofsToDofsWithReactionsList(
self.settings["auxiliary_dofs_list"],
self.settings["auxiliary_reaction_list"],
dofs_and_reactions_to_add)
KratosMultiphysics.VariableUtils.AddDofsList(dofs_and_reactions_to_add, self.main_model_part)
KratosMultiphysics.Logger.PrintInfo("::[MechanicalSolver]:: ", "DOF's ADDED")

StructuralMechanicsSolver always adds 3D DoFs regardless of the problem's domain size, which results in a mismatch between Dofs stored in nodes and those that are constructed by BuilderAndSolver. In 2D problems, the Z component of vector Dofs are added to Nodes, but their equation ID is never set (meaning that they're always 0).

One possible solution to this issue is setting ACTIVE on Dofs that make it into the B&S.

@matekelemen
Copy link
Contributor Author

matekelemen commented Mar 17, 2024

One problem is that how flags are implemented as of now they occupy 2 doubles

I was wondering about that, and got quite confused about what the purpose of Flags::mIsDefined is.

BlockType mIsDefined; /// Bitmask representing defined flags.
BlockType mFlags; /// Bitmask representing flag values.

I'd usually assume that a flag is either set or it isn't, but kratos Flags can actually have 3 states:

  • not defined, not set
  • defined, not set
  • defined, set

@RiccardoRossi Do we ever make a distinction between flags that are neither defined nor set, and flags that are defined but not set?

@loumalouomega
Copy link
Member

One problem is that how flags are implemented as of now they occupy 2 doubles

I was wondering about that, and got quite confused about what the purpose of Flags::mIsDefined is.

BlockType mIsDefined; /// Bitmask representing defined flags.
BlockType mFlags; /// Bitmask representing flag values.

I'd usually assume that a flag is either set or it isn't, but kratos Flags can actually have 3 states:

* not defined, not set

* defined, not set

* defined, set

@RiccardoRossi Do we ever make a distinction between flags that are neither defined nor set, and flags that are defined but not set?

If you remove the defined/not defined you will break a lot of code, because someone (like me) assumed that and we did developments assuming that logic.

@ddiezrod
Copy link
Contributor

One problem is that how flags are implemented as of now they occupy 2 doubles

I was wondering about that, and got quite confused about what the purpose of Flags::mIsDefined is.

BlockType mIsDefined; /// Bitmask representing defined flags.
BlockType mFlags; /// Bitmask representing flag values.

I'd usually assume that a flag is either set or it isn't, but kratos Flags can actually have 3 states:

  • not defined, not set
  • defined, not set
  • defined, set

@RiccardoRossi Do we ever make a distinction between flags that are neither defined nor set, and flags that are defined but not set?

Yes, if I remember correctly an element is considered ACTIVE (so we have to compute its local matrix and rhs) if the flag is not defined or if it is set to ACTIVE

return IsDefined(ACTIVE) ? Is(ACTIVE) : true;
(I think this is exactly the case you were talking about)

@loumalouomega
Copy link
Member

One problem is that how flags are implemented as of now they occupy 2 doubles

I was wondering about that, and got quite confused about what the purpose of Flags::mIsDefined is.

BlockType mIsDefined; /// Bitmask representing defined flags.
BlockType mFlags; /// Bitmask representing flag values.

I'd usually assume that a flag is either set or it isn't, but kratos Flags can actually have 3 states:

  • not defined, not set
  • defined, not set
  • defined, set

@RiccardoRossi Do we ever make a distinction between flags that are neither defined nor set, and flags that are defined but not set?

Yes, if I remember correctly an element is considered ACTIVE (so we have to compute its local matrix and rhs) if the flag is not defined or if it is set to ACTIVE

return IsDefined(ACTIVE) ? Is(ACTIVE) : true;

(I think this is exactly the case you were talking about)

And not just that, in Contact I use it for an advance logic, for the frictional contact. I guess I can rewrite it, but It woul not be trivial.

@matekelemen
Copy link
Contributor Author

matekelemen commented Mar 18, 2024

Ah well ¯\_(ツ)_/¯

Anyway, reducing the footprint of Flags is not necessary for this PR. That said, I should probably shuffle the order of member variables around to improve alignment.

@loumalouomega
Copy link
Member

Ah well ¯_(ツ)_/¯

Anyway, reducing the footprint of Flags is not necessary for this PR

Sotty :P

@matekelemen
Copy link
Contributor Author

I should probably shuffle the order of member variables around to improve alignment.

well nope, it's already the smallest it can be.

@pooyan-dadvand can you please review?

kratos/includes/dof.h Outdated Show resolved Hide resolved
kratos/includes/dof.h Outdated Show resolved Hide resolved
kratos/includes/dof.h Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants