Gridin_COMSOL_mphtxt cannot import my mesh

240 views
Skip to first unread message

Yufei Fang

unread,
Mar 6, 2024, 4:48:21 AM3/6/24
to deal.II User Group
I'm trying to import the mesh from COMSOL to triangulation.

comsol_4IaAE9lQVf.png
it's an air-supported membrane structure, the mesh consists of free triangular or free quad. both are failed.
here is my code:
"
void run3D()
{
Triangulation<3> triangulation;
GridIn<3> grid_in;
grid_in.attach_triangulation(triangulation);
std::ifstream input_file("../resource/3D.mphtxt");
grid_in.read_comsol_mphtxt(input_file);

std::ofstream out("grid3D.vtk");
GridOut       grid_out;
grid_out.write_vtk(triangulation, out);
std::cout << "Grid written to grid.vtk" << std::endl;
}

int main()
{
run3D();
}
"
the error is:
"
An error occurred in line <2264> of file </home/fomebody/dealii-9.5.1/source/grid/tria.cc> in function
    static void dealii::internal::TriangulationImplementation::Implementation::create_triangulation(const std::vector<dealii::Point<spacedim> >&, const std::vector<dealii::CellData<dim> >&, const dealii::SubCellData&, dealii::Triangulation<dim, spacedim>&) [with int dim = 3; int spacedim = 3]
The violated condition was:
    cells.size() > 0
Additional information:
    No cells given
"
my question is:
1. how to import such a mesh into dealii;
2. the tutorial said triangular and tetrahedral cannot be imported in dealii, but i can import triangular or tetrahedral element by gridin_COMSOL_mphtxt, is it controdicory?

Wolfgang Bangerth

unread,
Mar 7, 2024, 2:11:56 AM3/7/24
to dea...@googlegroups.com
On 3/5/24 23:03, Yufei Fang wrote:
> "
> void run3D()
> {
> Triangulation<3> triangulation;
> GridIn<3> grid_in;
> grid_in.attach_triangulation(triangulation);
> std::ifstream input_file("../resource/3D.mphtxt");
> grid_in.read_comsol_mphtxt(input_file);
>
> std::ofstream out("grid3D.vtk");
> GridOut       grid_out;
> grid_out.write_vtk(triangulation, out);
> std::cout << "Grid written to grid.vtk" << std::endl;
> }
>
> int main()
> {
> run3D();
> }
> "
> the error is:
> "

This looks reasonable. Can you send us the 3D.mphtxt file?


> 2. the tutorial said triangular and tetrahedral cannot be imported in dealii,
> but i can import triangular or tetrahedral element by gridin_COMSOL_mphtxt, is
> it controdicory?

deal.II used to use only quadrilaterals and hexahedra until not so long ago,
so the statement about not supporting triangular and tetrahedral meshes was
correct. But it is no longer; can you point out where exactly you found this
statement?

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/


Luca Heltai

unread,
Mar 7, 2024, 2:33:30 AM3/7/24
to dea...@googlegroups.com
If I understood correctly, you are trying to import a two-dimensional grid embedded in a three dimensional space. Does your code work if you use a Triangulation<2,3>?

The error you show indicates you are using a Triangulation<3>.

Luca

> Il giorno 7 mar 2024, alle ore 08:11, Wolfgang Bangerth <bang...@colostate.edu> ha scritto:
> --
> The deal.II project is located at http://www.dealii.org/
> For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
> --- You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to dealii+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/d85193f8-5cd8-4dca-bb96-faabacc0ee9c%40colostate.edu.

Yufei Fang

unread,
Mar 8, 2024, 2:56:52 AM3/8/24
to deal.II User Group
Professor Bangerth, thanks for your reply,
here are my code and mesh file. Sir Luca is right that I am trying to import a two-dimensional grid embedded in a three dimensional space. However, it didnt work out after using a use a Triangulation<2,3> and the error is:
"
error: cannot convert ‘dealii::Triangulation<2, 3>’ to ‘dealii::Triangulation<3, 3>&’
   38 |         grid_in.attach_triangulation(triangulation);
      |                                      ^~~~~~~~~~~~~
      |                                      |
      |                                      dealii::Triangulation<2, 3>
In file included from /home/fomebody/myDealii/0308_test_comsolinair/test.cc:6:
/home/fomebody/dealii-9.5.1/include/deal.II/grid/grid_in.h:361:54: note:   initializing argument 1 of ‘void dealii::GridIn<dim, spacedim>::attach_triangulation(dealii::Triangulation<dim, spacedim>&) [with int dim = 3; int spacedim = 3]’
  361 |   attach_triangulation(Triangulation<dim, spacedim> &tria);
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
"
> But it is no longer; can you point out where exactly you found thisstatement?
I can't find the exact place, maybe some linking in the step-5. I can recall that that page contains a tool for transformation from triangualr to quadraliteral.
test.cc
3D.mphtxt

陈敏

unread,
Mar 8, 2024, 2:57:14 AM3/8/24
to dea...@googlegroups.com
Hi Yufei Fang,

changing the origin code to the followeing will be  ok.


void run3D()
{
Triangulation<2,3> triangulation;
GridIn<2,3> grid_in;

grid_in.attach_triangulation(triangulation);
std::ifstream input_file("../resource/3D.mphtxt");
grid_in.read_comsol_mphtxt(input_file);

std::ofstream out("grid3D.vtk");
GridOut       grid_out;
grid_out.write_vtk(triangulation, out);
std::cout << "Grid written to grid.vtk" << std::endl;
}

int main()
{
run3D();
}


Chen

Yufei Fang <sjt...@gmail.com> 于2024年3月6日周三 17:48写道:
--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
---
You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dealii+un...@googlegroups.com.

Wolfgang Bangerth

unread,
Mar 8, 2024, 12:17:45 PM3/8/24
to dea...@googlegroups.com


On 3/7/24 23:22, Yufei Fang wrote:
> error: cannot convert ‘dealii::Triangulation<2, 3>’ to
> ‘dealii::Triangulation<3, 3>&’
>    38 |         grid_in.attach_triangulation(triangulation);
>       |                                      ^~~~~~~~~~~~~
>       |                                      |
>       |                                      dealii::Triangulation<2, 3>
> In file included from
> /home/fomebody/myDealii/0308_test_comsolinair/test.cc:6:
> /home/fomebody/dealii-9.5.1/include/deal.II/grid/grid_in.h:361:54: note:
>   initializing argument 1 of ‘void dealii::GridIn<dim,
> spacedim>::attach_triangulation(dealii::Triangulation<dim, spacedim>&)
> [with int dim = 3; int spacedim = 3]’

You will need GridIn<2,3> as well, not GridIn<3>.

Best
W.

Yufei Fang

unread,
Mar 11, 2024, 8:50:46 AM3/11/24
to deal.II User Group
Professor Bangerth, thanks for your reply,
I changed the code to
"
Triangulation<2,3> triangulation;
GridIn<2,3> grid_in;
"
However, it still doesn't work, and the error message is the same as before:

"
An error occurred in line <2264> of file </home/fomebody/dealii-9.5.1/source/grid/tria.cc> in function
    static void dealii::internal::TriangulationImplementation::Implementation::create_triangulation(const std::vector<dealii::Point<spacedim> >&, const std::vector<dealii::CellData<dim> >&, const dealii::SubCellData&, dealii::Triangulation<dim, spacedim>&) [with int dim = 2; int spacedim = 3]

The violated condition was:
    cells.size() > 0
Additional information:
    No cells given
"
😭
Can you help me check where the problem is?

Yufei Fang

unread,
Mar 11, 2024, 8:50:53 AM3/11/24
to deal.II User Group
Sir Chen, thanks for your reply,

I changed the code to
"
Triangulation<2,3> triangulation;
GridIn<2,3> grid_in;
"
However, it still doesn't work, and the error message is the same as before:
"
An error occurred in line <2264> of file </home/fomebody/dealii-9.5.1/source/grid/tria.cc> in function
    static void dealii::internal::TriangulationImplementation::Implementation::create_triangulation(const std::vector<dealii::Point<spacedim> >&, const std::vector<dealii::CellData<dim> >&, const dealii::SubCellData&, dealii::Triangulation<dim, spacedim>&) [with int dim = 2; int spacedim = 3]

The violated condition was:
    cells.size() > 0
Additional information:
    No cells given
"
😭
Here is my .mphtxt, can you help me check where the problem is?
3D.mphtxt

Wolfgang Bangerth

unread,
Mar 21, 2024, 11:11:25 PM3/21/24
to dea...@googlegroups.com

Yufei:
I looked at your input file, and the error message is correct. The relevant
part of 3D.mphtxt looks as follows:

```
1 # number of element types

# Type #0

3 edg # type name


2 # number of vertices per element
24584 # number of elements
# Elements
0 1
2 1
...
```

What this part of the file says is "there is only one type of cells", "all
cells have type 3 (edges)" where edge=1d line segments, and "here are 24584
cells of this type", with each of the line segments described by two vertex
numbers.

In other words, the file you saved only contains line segments in 3d, but no
quadrilaterals or triangles. You'll have to figure out how to save the
information you really want, namely cells, rather than just these edges.

Best
W.



On 3/10/24 23:50, Yufei Fang wrote:
> *** Caution: EXTERNAL Sender ***
> comsol_4IaAE9lQVf.png
> it's an air-supported membrane structure, the mesh consists of free
> triangular or free quad. both are failed.
> *here is my code:*
> https://groups.google.com/d/msgid/dealii/6e0e1c38-5aef-4b9a-bddc-a14a8bc07f0bn%40googlegroups.com <https://groups.google.com/d/msgid/dealii/6e0e1c38-5aef-4b9a-bddc-a14a8bc07f0bn%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> The deal.II project is located at http://www.dealii.org/
> <http://www.dealii.org/>
> For mailing list/forum options, see
> https://groups.google.com/d/forum/dealii?hl=en
> <https://groups.google.com/d/forum/dealii?hl=en>
> ---
> You received this message because you are subscribed to the Google Groups
> "deal.II User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to dealii+un...@googlegroups.com
> <mailto:dealii+un...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/dealii/065ad604-64c8-45c2-bad3-9df142c870f2n%40googlegroups.com <https://groups.google.com/d/msgid/dealii/065ad604-64c8-45c2-bad3-9df142c870f2n%40googlegroups.com?utm_medium=email&utm_source=footer>.

Yufei Fang

unread,
Mar 27, 2024, 8:12:55 AM3/27/24
to deal.II User Group
Dear Professor Bangerth,
I appreciate the effort and time you dedicated to reviewing and addressing the error I encountered. Your guidance has been beneficial. Following your advice, I have updated the mesh file to incorporate triangles. The file now has the following structure:
"""
3 # number of vertices per element
16308 # number of elements
# Elements
0 2 1
3 1 2
1 3 5 
...
"""
However, this modification has led to a new error message:
"""
An error occurred in line <1557> of file </dssg/opt/icelake/linux-centos8-icelake/gcc-9.3.0/dealii-9.4.0/src/dealii-9.4.0/source/grid/grid_in.cc> in function
    void dealii::GridIn<dim, spacedim>::read_comsol_mphtxt(std::istream&) [with int dim = 2; int spacedim = 3; std::istream = std::basic_istream<char>]
The violated condition was:
    s == "4 Mesh"

Additional information:
    You are trying to use functionality in deal.II that is currently not
    implemented. In many cases, this indicates that there simply didn't
    appear much of a need for it, or that the author of the original code
    did not have the time to implement a particular case. If you hit this
    exception, it is therefore worth the time to look into the code to
    find out whether you may be able to implement the missing
    functionality. If you do, please consider providing a patch to the
    deal.II development sources (see the deal.II website on how to
    contribute).

Stacktrace:
-----------
#0  /dssg/opt/icelake/linux-centos8-icelake/gcc-9.3.0/dealii-9.4.0/install/deal/lib/libdeal_II.g.so.9.4.0: dealii::GridIn<2, 3>::read_comsol_mphtxt(std::istream&)
#1  ./test: run3D()
#2  ./test: main
--------------------------------------------------------
"""
Attached are my updated .mphtxt and .cc files. Could you kindly assist in identifying the source of the issue?
test.cc
3D.mphtxt

Wolfgang Bangerth

unread,
Mar 28, 2024, 2:40:15 PM3/28/24
to dea...@googlegroups.com
On 3/25/24 00:13, Yufei Fang wrote:
>
> I appreciate the effort and time you dedicated to reviewing and addressing the
> error I encountered. Your guidance has been beneficial. Following your advice,
> I have updated the mesh file to incorporate triangles. The file now has the
> following structure:
> """
> 3 # number of vertices per element
> 16308 # number of elements
> # Elements
> 0 2 1
> 3 1 2
> 1 3 5
> ...
> """
> However, this modification has led to a new error message:
> """
> An error occurred in line <1557> of file
> </dssg/opt/icelake/linux-centos8-icelake/gcc-9.3.0/dealii-9.4.0/src/dealii-9.4.0/source/grid/grid_in.cc> in function
>     void dealii::GridIn<dim, spacedim>::read_comsol_mphtxt(std::istream&)
> [with int dim = 2; int spacedim = 3; std::istream = std::basic_istream<char>]
> *The violated condition was:
>     s == "4 Mesh"*
> Additional information:
>     You are trying to use functionality in deal.II that is currently not
>     implemented. In many cases, this indicates that there simply didn't
>     appear much of a need for it, or that the author of the original code
>     did not have the time to implement a particular case. If you hit this
>     exception, it is therefore worth the time to look into the code to
>     find out whether you may be able to implement the missing
>     functionality. If you do, please consider providing a patch to the
>     deal.II development sources (see the deal.II website on how to
>     contribute).

Yufei:
the error indicates that the deal.II version you are using (9.4) had not yet
implemented the ability to read triangle meshes. But this is already fixed in
9.5, I believe, and I verified that the mesh can be properly read with the
current development version. You'll either have to update to 9.5, or use
quadrilateral meshes instead (which I *think* should work in 9.4, but am not
entirely sure).

Best
W.

Yufei Fang

unread,
Mar 29, 2024, 11:23:54 PM3/29/24
to deal.II User Group
Dear Professor Bangerth,

I am delighted to inform you that I have successfully imported my grid into deal.II, marking a significant milestone in my project. This achievement is foundational for my subsequent analyses using deal.II, and I couldn't have reached this point without your invaluable assistance. Thank you once again for your generous support and expert guidance.

Best regards,
Yufei Fang
paraview_qFQKH85Q3m.png

陈敏

unread,
Mar 31, 2024, 11:59:33 AM3/31/24
to dea...@googlegroups.com
Yufei Fang:

The selection of exporting data should by careful.
image.png
Chen

Yufei Fang <sjt...@gmail.com> 于2024年3月27日周三 20:12写道:

Yufei Fang

unread,
Apr 2, 2024, 3:38:28 AM4/2/24
to deal.II User Group
Sir Chen,
Thank you for your assistance; it was precisely what I needed to export a mesh with either 3 or 4 vertices. It appears you also use COMSOL, suggesting our research interests might overlap. Perhaps we could communicate further on this topic.

Best regards,
Yufei Fang

Reply all
Reply to author
Forward
0 new messages