CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   mode of a data set (https://www.cfd-online.com/Forums/main/6934-mode-data-set.html)

m malik December 17, 2003 08:54

mode of a data set
 
Specifically, my problem is finite element mesh related: finding the maximum number of elements that share a common node. I guess it is basically a problem of finding the mode of a large set of numbers. Would like to know of some C/C++/Fortran code for this purpse. Thanks.

Ananda Himansu December 17, 2003 13:50

Re: mode of a data set -- fortran pseudocode
 
! answer by enumeration, message board reformats my post by weird rules, forces me to use double-line spacing below

subroutine max_cells_of_nodes (max_cells, num_elements, num_nodes, max_vertices, num_vertices, nodes_of_elements)

implicit none

! global variable declarations follow

! global variables except for max_cells are assumed to be assigned values in calling routine before calling current routine

integer :: max_cells, num_elements, num_nodes, max_vertices

! (max_vertices = maxval(num_vertices))

integer, dimension(num_elements) :: num_vertices

integer, dimension(max_vertices, num_elements) :: nodes_of_elements

! local variable declarations follow

integer, dimension(num_nodes) :: num_cells

! num_cells is an auxiliary array to track number of elements incident on each node

integer :: element, vertex, this_node

do element = 1, num_elements

do vertex = 1, num_vertices(element)

this_node = nodes_of_elements(vertex, element)

num_cells(this_node) = num_cells(this_node)+1

end do

end do

max_cells = maxval(num_cells)

! max_cells is the maximum number of elements that share a common node

end subroutine max_cells_of_nodes

Nashat December 17, 2003 13:59

Re: mode of a data set
 
Check out Rainald Lohner's book:

Applied CFD Techniques: An Introduction Based on Finite Element Methods.


Ananda Himansu December 19, 2003 15:37

Re: mode of a data set -- fortran pseudocode
 
whoops, of course there is a bug in my code :) that's what you get for programming in a hurry and not testing!

i forgot to initialize the num_cells array. the following statement should be inserted just before the "do element = 1, num_elements" loop:

num_cells = 0

m malik December 20, 2003 09:18

Re: mode of a data set -- fortran pseudocode
 
Thanks. I had noticed that in your first mail.


All times are GMT -4. The time now is 09:32.