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

Improve assert message for non-matching reference cell types #16020

Merged

Conversation

mschreter
Copy link
Contributor

@mschreter mschreter commented Sep 20, 2023

This PR suggest to improve the assert message if two reference cell types don't match, from

(old) 

An error occurred in line <2644> of file </scratch/lib/dealii/include/deal.II/dofs/dof_accessor.templates.h> in function
    const dealii::FiniteElement<dimension_, space_dimension_>& dealii::DoFCellAccessor<dim, spacedim, lda>::get_fe() const [with int dimension_ = 2; int space_dimension_ = 3; bool level_dof_access = false]
The violated condition was: 
    this->reference_cell() == fe.reference_cell()
Additional information: 
    The reference-cell type of the cell does not match the one of the
    finite element!

to

(new)
--------------------------------------------------------
An error occurred in line <2641> of file </home/magdalena/code/external_libs/dealii-work/include/deal.II/dofs/dof_accessor.templates.h> in function
    const dealii::FiniteElement<dimension_, space_dimension_>& dealii::DoFCellAccessor<dim, spacedim, lda>::get_fe() const [with int dimension_ = 2; int space_dimension_ = 3; bool level_dof_access = false]
The violated condition was: 
    this->reference_cell() == fe.reference_cell()
Additional information: 
    The reference-cell type of Tri does not match with Quad. This could
    happen if one object (e.g. Triangulation) holds reference cells from a hexahedral mesh and
    the other one (e.g. FiniteElement) from a simplex mesh.

This can happen if one attaches a simplex triangulation to the DoFHandler and subsequently calls DoFHandler::distribute_dofs(fe) with a FE type for hexahedral elements, e.g. FE_Q<dim>.

@tinhvo-TUM @peterrum FYI

@mschreter mschreter force-pushed the add_exc_nonmatching_reference_cell_types branch from 98cbe90 to 6145b8d Compare September 20, 2023 13:34
include/deal.II/grid/reference_cell.h Outdated Show resolved Hide resolved
@mschreter mschreter changed the title Improve assert message for unmatching reference cell types Improve assert message for non-matching reference cell types Sep 20, 2023
@mschreter mschreter force-pushed the add_exc_nonmatching_reference_cell_types branch from 6145b8d to 48b47c7 Compare September 20, 2023 13:37
@peterrum
Copy link
Member

/rebuild

Comment on lines +2639 to +2640
internal::ExcNonMatchingReferenceCellTypes(this->reference_cell(),
fe.reference_cell()));
Copy link
Member

Choose a reason for hiding this comment

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

Let's not invent a whole new exception class for just one place. This is more easily done in the following way:

Suggested change
internal::ExcNonMatchingReferenceCellTypes(this->reference_cell(),
fe.reference_cell()));
ExcMessage ("The reference-cell type used on this cell (" + this->reference_cell().to_string() +
") does not match the reference-cell type of the finite element associated with this cell (" +
fe.reference_cell.to_string()
+ "). Did you accidentally use simplex elements on hypercube meshes (or the other way around), or "
"are you using a mixed mesh and assigned a simplex element to a hypercube cell "
"(or the other way around) via the "
"active_fe_index?"));

Copy link
Member

Choose a reason for hiding this comment

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

I would suggest to keep the class, since, if I remember correctly, there are other places, where it could be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By performing a quick search I could at least replace one additional assert message. I'll have a deeper look if there are more relevant places. Then we can decide.

Copy link
Member

Choose a reason for hiding this comment

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

If you need a new class, use DeclExceptionMessage instead of doing it by hand, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@mschreter mschreter force-pushed the add_exc_nonmatching_reference_cell_types branch from dcdc123 to c1e3ede Compare September 20, 2023 14:40
Comment on lines 2702 to 2706
<< "The reference-cell type of " << arg1.to_string()
<< " does not match with " << arg2.to_string() << ". "
<< "This could happen if one object (e.g. Triangulation) holds "
<< "reference cells from a hexahedral mesh and the other one "
<< "(e.g. FiniteElement) from a simplex mesh.");
Copy link
Member

Choose a reason for hiding this comment

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

I still think that this message is too specific. What do you think of the text I had in the other comment?

Copy link
Contributor Author

@mschreter mschreter Sep 20, 2023

Choose a reason for hiding this comment

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

Excellent, thanks, I like it and adopted it. I got so caught up in the other part that I didn't notice the changes in the text initially :-).

@mschreter mschreter force-pushed the add_exc_nonmatching_reference_cell_types branch from c1e3ede to 98f8db1 Compare September 20, 2023 22:32
@bangerth bangerth merged commit d926290 into dealii:master Sep 21, 2023
15 checks passed
@bangerth
Copy link
Member

Excellent, thank you!

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.

None yet

3 participants