Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

exact format in mphtxt file.

Please login with a confirmed email address before reporting spam

I want to export mesh data from COMSOL so that I can run my own FE solver to compare FE results.

I find importing FE results to COMSOL is relatively simple.
But reading mphtxt is not.

as an example, i am reading "reactive_muffler.mphtxt" from COMSOL. (for simplicity, I didnt write whole lines)

==================================================
.....
3 # number of element types
# Type #0
3 vtx # type name

1 # number of nodes per element
10 # number of elements
# Elements


# Type #1
3 edg # type name

2 # number of nodes per element
68 # number of elements
# Elements


# Type #2
3 tri # type name

3 # number of nodes per element
252 # number of elements
# Elements


252 # number of domains
# Domains
==========================================================

here are my questions.

1. from the above example, can I assume

Type #0 == vtx element
Type #1 == edg element
Type #2 == tri element

2. what do integers in fromt of elem type represent ?

3 vtx # type name
3 edg # type name
3 tri # type name


3. In the following line, can i assume that this is ono-to-one relation of 'elem # - subdomain # in the model'? (in this reactive_muffler example, i see 3 subdomains)


252 # number of domains
# Domains
1 element 1 is in the subdomain #1
1 element 2 is in the subdomain #1
2 element 3 is in the subdomain #2
3 element 4 is in the subdomain #3
.


4. i am writing a fortran code to read a mphtxt file.
the line '3 tri # type name' is a fixed format? that is,

one digit intger + three letter elem format (like tri, edg,...) + '#' + 'type name'

any suggestions on reading mphtxt file using fortran?

my situation tells me that i wont deal with FE elem other than '2D 9 node' == quadrilateral (quad2) at this point.




5. where i can find more detailed info about mphtxt?

document "6 The Multiphysics COMSOL Files" didnt help me that much.




well. i hope i describe my question clearly....

and thanks in advance for any comments.




10 Replies Last Post 2011年11月2日 GMT-4 09:42

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年3月11日 GMT-5 05:22
Hi,
if I well understand you need to export mesh data. If so, you can extract data by using matlab.
Try the following:
1. export fem structure; then, from matlab:
2. nodes=get(fem.mesh,'p'); ele=get(fem.mesh,'el')
3. finally, format this data based on your needs.

Hope this may help

Regards

Pasquale
Hi, if I well understand you need to export mesh data. If so, you can extract data by using matlab. Try the following: 1. export fem structure; then, from matlab: 2. nodes=get(fem.mesh,'p'); ele=get(fem.mesh,'el') 3. finally, format this data based on your needs. Hope this may help Regards Pasquale

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年3月11日 GMT-5 12:02
Hi,

Thanks for your reply.

The thing is that I want to avoid using matlab.

I know its a lot easier if i can use matlab but at this point i;d like to use just mphtxt file forms.

Thanks anyway
Hi, Thanks for your reply. The thing is that I want to avoid using matlab. I know its a lot easier if i can use matlab but at this point i;d like to use just mphtxt file forms. Thanks anyway

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年3月12日 GMT-5 01:54
Hi,
Following are the answers to some of your questions:
1) Yes, your assumption is correct.
2) The number represents the number of characters in the string (e.g. 'tri') that follows the number. E.g. 4 quad
3) I am afraid that I did not understand this question. From what I can make out of the code that you had provided: there is one subdomain with 252 elements of triangular shape and each triangle defined by 3 mesh points.
4) Whatever follows after # is basically a comment and can be disregarded.
5) See the 'femmesh' function in the documentation. You can try to figure out a lot of the stuffs by looking at the file for a very simple mesh, say a rectangular mesh with 4 elements only.
Best wishes,
Saswati
Hi, Following are the answers to some of your questions: 1) Yes, your assumption is correct. 2) The number represents the number of characters in the string (e.g. 'tri') that follows the number. E.g. 4 quad 3) I am afraid that I did not understand this question. From what I can make out of the code that you had provided: there is one subdomain with 252 elements of triangular shape and each triangle defined by 3 mesh points. 4) Whatever follows after # is basically a comment and can be disregarded. 5) See the 'femmesh' function in the documentation. You can try to figure out a lot of the stuffs by looking at the file for a very simple mesh, say a rectangular mesh with 4 elements only. Best wishes, Saswati

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年12月6日 GMT-5 14:23
Hi Saswati,

I have read your other post also related to mphtxt files. I am also trying to import an externally generated mesh into COMSOL. I was able to understand the meanings of the records in mphtxt. However, the import operation is failing with an error (the error message does not give any details about what is wrong). I see no mistake in header records that define the data types ( like 3 obj, 3 tet, 3 vtx,... kind of lines).

I guess the problem is in defining the domain information.I defined each type as a new domain, i.e. for example, say there are 10 nodes and 10 domains for nodes; 5 triangles and 5 domains for triangles, 2 tets and 2 domains for tets.

(1) How did you define your domain information in the mphtxt files? Should there be less number of domains compared to number of elements of each type (vtx, edg, tri, etc.)?

(2) Does the mesh is reprocessed once imported into COMSOL, i.e. the total number and numbering sequence of nodes, elements and domains will change on import with the default import options?

My aim is to define some node and boundary sets (using the domains option) upon which I will define a subsequent boundary condition (in a MATLAB script file).

Thanks,
Kodanda
Hi Saswati, I have read your other post also related to mphtxt files. I am also trying to import an externally generated mesh into COMSOL. I was able to understand the meanings of the records in mphtxt. However, the import operation is failing with an error (the error message does not give any details about what is wrong). I see no mistake in header records that define the data types ( like 3 obj, 3 tet, 3 vtx,... kind of lines). I guess the problem is in defining the domain information.I defined each type as a new domain, i.e. for example, say there are 10 nodes and 10 domains for nodes; 5 triangles and 5 domains for triangles, 2 tets and 2 domains for tets. (1) How did you define your domain information in the mphtxt files? Should there be less number of domains compared to number of elements of each type (vtx, edg, tri, etc.)? (2) Does the mesh is reprocessed once imported into COMSOL, i.e. the total number and numbering sequence of nodes, elements and domains will change on import with the default import options? My aim is to define some node and boundary sets (using the domains option) upon which I will define a subsequent boundary condition (in a MATLAB script file). Thanks, Kodanda

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年12月6日 GMT-5 14:53
well...it seems like my job at the time was A LOT simpler than what you want to do now.....

for me, once i understood the detailed formats of the file, it was a simple reading process...

say in the file

.....
2580 # number of domains >>>>> this means i have to do 2580 line readings....
# Domains
.....

another example.

......
# Type #1
3 edg # type name
2 # number of nodes per element
9358 # number of elements >>>>> i read 9358 lines of 2 integer numbers.
# Elements
.....

.....
# Type #2
4 quad # type name
4 # number of nodes per element >>>>> i read 81616 lines of 4 integer numbers....
81616 # number of elements
# Elements
......




for your second question, for my job, i dont think it changed any indexes during importing.


=====


well. i am not sure i was that much helpful....
its been a while....


well...it seems like my job at the time was A LOT simpler than what you want to do now..... for me, once i understood the detailed formats of the file, it was a simple reading process... say in the file ..... 2580 # number of domains >>>>> this means i have to do 2580 line readings.... # Domains ..... another example. ...... # Type #1 3 edg # type name 2 # number of nodes per element 9358 # number of elements >>>>> i read 9358 lines of 2 integer numbers. # Elements ..... ..... # Type #2 4 quad # type name 4 # number of nodes per element >>>>> i read 81616 lines of 4 integer numbers.... 81616 # number of elements # Elements ...... for your second question, for my job, i dont think it changed any indexes during importing. ===== well. i am not sure i was that much helpful.... its been a while....

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年12月7日 GMT-5 15:52
Hi,

thanks for you reply.

Finally, I figured out the way to deal with domains. I would like to share my experience here. Hope it comes handy to you at some point or for other forum members.

It is important to note that:
(1) a mesh when imported into COMSOL will be enriched to create the necessary information. A full mesh in 3D will contain elements of dimensions 0, 1, 2 and 3 (vertices, edges, faces and elements) + their domain numbers + parameters. If any of these are not supplied in full, COMSOL will try to enrich the information.

(2) During import, a few control parameters may sometimes alter the number of elements and domain informaiton given by the user.

(3) There can be any number of domains<=the number of corresponding N-D element (N=0,1,2,3). Some combinations of user defined domain IDs for the elements cannot be enriched by COMSOL. However, an empty domain field works with mphtxt files most of the times as far as I know.

For manipulating or defining certain domain groups, I used empty/serially numbered domain IDs and imported into COMSOL via MATLAB (of course, java class files can also be used in Ver>4.0 to import mphtxt). This will enrich the mesh data, creating also the domain information. This domain information can be excessed by the query function model.mesh.getElemEntity(). Similarly, other mesh data (coordinates, vertices, edges,elements... ) can also be fetched into local arrays through similar functions.

Once we have the correct information, we can group domains according to custom conditions by defining selections: model.create.selection('sel1'). One can either save the model as a mph file or can directly run the script ( I guess) by connecting to comsol server.

cheers,
kodanda
Hi, thanks for you reply. Finally, I figured out the way to deal with domains. I would like to share my experience here. Hope it comes handy to you at some point or for other forum members. It is important to note that: (1) a mesh when imported into COMSOL will be enriched to create the necessary information. A full mesh in 3D will contain elements of dimensions 0, 1, 2 and 3 (vertices, edges, faces and elements) + their domain numbers + parameters. If any of these are not supplied in full, COMSOL will try to enrich the information. (2) During import, a few control parameters may sometimes alter the number of elements and domain informaiton given by the user. (3) There can be any number of domains4.0 to import mphtxt). This will enrich the mesh data, creating also the domain information. This domain information can be excessed by the query function model.mesh.getElemEntity(). Similarly, other mesh data (coordinates, vertices, edges,elements... ) can also be fetched into local arrays through similar functions. Once we have the correct information, we can group domains according to custom conditions by defining selections: model.create.selection('sel1'). One can either save the model as a mph file or can directly run the script ( I guess) by connecting to comsol server. cheers, kodanda

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年12月7日 GMT-5 16:26
Hi

I would like to remind you that importing mesh data into comsol is not the foreseen COMSOL method, as the mesh is the last operation AFTER you have defined the physics and the BC's on the COMSOL geometrial domains and boundaries.

So if you go the traditional FEM tool way of importing the mesh and then define physics and BCs and want to use COMSOL, you must first group your mesh elements into "domains" and the boundary nodes into "boundaries" (which is not a trivial case) v3.5a managed in some cases to import and transform a mesh data set into domains and boundaries from Nastran Neutral files into COSMOL geometry but often with errors and mostly with many many small domains which makes the handlig of the model rather heavy.

I know that a certain number of geometrical models are only obtained as meshed geometry (i.e scanner images etc), then you should ask yourself if its not easier to group elements into larger items first in your own software, based on your prior knowledge of which elements represent the same "material", it might be more efficient, or use some of the existing third party translation software tools from COMSOs main site

--
Good luck
Ivar
Hi I would like to remind you that importing mesh data into comsol is not the foreseen COMSOL method, as the mesh is the last operation AFTER you have defined the physics and the BC's on the COMSOL geometrial domains and boundaries. So if you go the traditional FEM tool way of importing the mesh and then define physics and BCs and want to use COMSOL, you must first group your mesh elements into "domains" and the boundary nodes into "boundaries" (which is not a trivial case) v3.5a managed in some cases to import and transform a mesh data set into domains and boundaries from Nastran Neutral files into COSMOL geometry but often with errors and mostly with many many small domains which makes the handlig of the model rather heavy. I know that a certain number of geometrical models are only obtained as meshed geometry (i.e scanner images etc), then you should ask yourself if its not easier to group elements into larger items first in your own software, based on your prior knowledge of which elements represent the same "material", it might be more efficient, or use some of the existing third party translation software tools from COMSOs main site -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年12月8日 GMT-5 04:53
Hi,

You are completely right and I have been facing the difficulties outlined in your previous post.

Generating domains in the COMSOL way is definitely not a trivial task. One can easily group elements into domains (of same material etc.), but making domains of boundaries involves a complicated topological analysis, for example identifying boundaries with similar curvatures as one domain. Just grouping all uninterested boundaries into one domain (or into arbitrary domains) has often resulted in import errors, simply due to the violation of topological rules whatever they are.

On the other hand with arbitrarily shaped bodies, leaving the control to COMSOL to generate domain information has often resulted not only in large number of domains but also in unwanted combinations of the boundaries.

A work around is that:
By defining each node/edge/face as a separate domain, this job is made simple. Now one can define "selections" of "Domains" to impose certain conditions. This work around makes the model bulky, which is of concern sometimes.

Cheers,
Kodanda

Hi, You are completely right and I have been facing the difficulties outlined in your previous post. Generating domains in the COMSOL way is definitely not a trivial task. One can easily group elements into domains (of same material etc.), but making domains of boundaries involves a complicated topological analysis, for example identifying boundaries with similar curvatures as one domain. Just grouping all uninterested boundaries into one domain (or into arbitrary domains) has often resulted in import errors, simply due to the violation of topological rules whatever they are. On the other hand with arbitrarily shaped bodies, leaving the control to COMSOL to generate domain information has often resulted not only in large number of domains but also in unwanted combinations of the boundaries. A work around is that: By defining each node/edge/face as a separate domain, this job is made simple. Now one can define "selections" of "Domains" to impose certain conditions. This work around makes the model bulky, which is of concern sometimes. Cheers, Kodanda

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2011年11月2日 GMT-4 07:26
Hi Pasquale,
I found the two lines below very useful for my application (thanks for this information). I'm interesting in finding the shortest path between two points using the obtained mesh data via applying Dijkstra's algorithm. I know that nodes content the coordinates of the mesh vertices. However, I’m quite confusing in getting the edge information (arc) that I need to construct an array (B) which explains the relationship between the mesh vertices (i.e. B(n,m) is nonzero (=1) if and only if an edge connects point n to point m. Could you please ASAP offer such details, if it is possible.

1. export fem structure; then, from matlab:
2. nodes=get(fem.mesh,'p'); ele=get(fem.mesh,'el')

Regards,
Omar
Hi Pasquale, I found the two lines below very useful for my application (thanks for this information). I'm interesting in finding the shortest path between two points using the obtained mesh data via applying Dijkstra's algorithm. I know that nodes content the coordinates of the mesh vertices. However, I’m quite confusing in getting the edge information (arc) that I need to construct an array (B) which explains the relationship between the mesh vertices (i.e. B(n,m) is nonzero (=1) if and only if an edge connects point n to point m. Could you please ASAP offer such details, if it is possible. 1. export fem structure; then, from matlab: 2. nodes=get(fem.mesh,'p'); ele=get(fem.mesh,'el') Regards, Omar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2011年11月2日 GMT-4 09:42
Hi,
I do not understand why you need to get the shortest path between two nodes. Please give me more details.

Anyway any mesh data can be assumed as a graph. There are many textbooks covering the graph theory topic (see, for example, Deo - Graph Theory with Applications to Engineering and Computer Science). The first step is to convert the element-mesh representation into the edge-graph representation.
For example, let's assume you have triangular mesh elements. First of all you have to calculate the adjacency matrix of the graph. The matlab pseudo-code is:

function A=getAdjacencyMatrix(Faces)

%-INPUT
%-Faces: element ids

%-OUTPUT
%-A: adjacency matrix

nvert=max(max(Faces));
nface=size(Faces,1);

A=sparse(nvert,nvert);
for I=1:nface
face=Faces(I,:); % i-th face
A(face(1),face(2))=A(face(1),face(2))+1;
A(face(1),face(3))=A(face(1),face(3))+1;
A(face(3),face(2))=A(face(3),face(2))+1;
end
A=A+A'; % symmetric condition (edge (i,j)==(j,i))

Having such a matrix you may implement the shortest path algorithm of any other working on edge data.

Hope this help

If you need more details please have a look at "Franciosa et al., Advanced User-Interaction with GUIs in MatLAB, in Engineering Education and Research Using MATLAB"

Good luck

Pasquale
Hi, I do not understand why you need to get the shortest path between two nodes. Please give me more details. Anyway any mesh data can be assumed as a graph. There are many textbooks covering the graph theory topic (see, for example, Deo - Graph Theory with Applications to Engineering and Computer Science). The first step is to convert the element-mesh representation into the edge-graph representation. For example, let's assume you have triangular mesh elements. First of all you have to calculate the adjacency matrix of the graph. The matlab pseudo-code is: function A=getAdjacencyMatrix(Faces) %-INPUT %-Faces: element ids %-OUTPUT %-A: adjacency matrix nvert=max(max(Faces)); nface=size(Faces,1); A=sparse(nvert,nvert); for I=1:nface face=Faces(I,:); % i-th face A(face(1),face(2))=A(face(1),face(2))+1; A(face(1),face(3))=A(face(1),face(3))+1; A(face(3),face(2))=A(face(3),face(2))+1; end A=A+A'; % symmetric condition (edge (i,j)==(j,i)) Having such a matrix you may implement the shortest path algorithm of any other working on edge data. Hope this help If you need more details please have a look at "Franciosa et al., Advanced User-Interaction with GUIs in MatLAB, in Engineering Education and Research Using MATLAB" Good luck Pasquale

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.