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

Expose Dof Index #13161

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Expose Dof Index #13161

wants to merge 1 commit into from

Conversation

matekelemen
Copy link
Contributor

@matekelemen matekelemen commented Feb 22, 2025

A requirement for solving #13160. This PR makes it possible to refer to Dofs with two integers (node ID, dof index within node) instead of a direct pointer.

Copy link
Member

@loumalouomega loumalouomega left a comment

Choose a reason for hiding this comment

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

Expose into python too, LGTM

@RiccardoRossi
Copy link
Member

Btw, I have no issues with this PR (other than the comment from @loumalouomega).

There might be a problem with the usage though: as i remember the list of dofs is dynamic, so that if you add or remove dof the index will change

@matekelemen
Copy link
Contributor Author

matekelemen commented Feb 23, 2025

There might be a problem with the usage though: as i remember the list of dofs is dynamic, so that if you add or remove dof the index will change

That's fine. What I need is the index of the Dof's variable within the VariablesList of the node and as far as I see, the order in there does not change during extension.

int AddDof(VariableData const* pThisDofVariable){
for(std::size_t dof_index = 0 ; dof_index < mDofVariables.size() ; dof_index++){
if(*mDofVariables[dof_index] == *pThisDofVariable){
return static_cast<int>(dof_index);
}
}
#ifdef KRATOS_DEBUG
if(OpenMPUtils::IsInParallel() != 0)
KRATOS_ERROR << "attempting to call AddDof for: " << pThisDofVariable << ". Unfortunately the Dof was not added before and the operations is not threadsafe (this function is being called within a parallel region)" << std::endl;
#endif
mDofVariables.push_back(pThisDofVariable);
mDofReactions.push_back(nullptr);
KRATOS_DEBUG_ERROR_IF(mDofVariables.size()>64) << "Adding too many dofs to the node. Each node only can store 64 Dofs." << std::endl;
return mDofVariables.size() - 1;
}

I'll extend the docstring to clarify what mIndex really is.

EDIT: actually, that reordering is a problem. Is there are reason why Node::mDofs is kept ordered? All accesses use a linear search instead of a binary one.

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.

3 participants