Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gmsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Larry Price
gmsh
Commits
159af57d
Commit
159af57d
authored
16 years ago
by
Stefen Guzik
Browse files
Options
Downloads
Patches
Plain Diff
To lighten Partition.h
parent
03909a7a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Mesh/PartitionObjects.h
+195
-0
195 additions, 0 deletions
Mesh/PartitionObjects.h
with
195 additions
and
0 deletions
Mesh/PartitionObjects.h
0 → 100644
+
195
−
0
View file @
159af57d
// Gmsh - Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to <gmsh@geuz.org>.
#ifndef _PARTITIONOBJECT_H_
#define _PARTITIONOBJECT_H_
#include
<map>
#include
<vector>
#include
"MElement.h"
#include
"Message.h"
/*******************************************************************************
*
* Class GrVertex
*
* Purpose
* =======
*
* Provides a graph vertex and edges (connected vertices)
*
******************************************************************************/
class
GrVertex
{
int
grEdge
[
6
];
public:
const
int
index
;
// This is the creation index, *not* the
// index in 'adjncy'
private:
unsigned
short
size
;
unsigned
short
sizeC
;
// Complete size (all possible 'grEdge')
public:
GrVertex
(
const
int
_index
,
const
unsigned
short
_size
)
:
index
(
_index
),
size
(
0
),
sizeC
(
_size
)
{
}
int
add
(
const
int
v
)
{
grEdge
[
size
++
]
=
v
;
}
unsigned
write
(
std
::
vector
<
int
>
&
vec
)
const
{
switch
(
size
)
{
case
6
:
vec
.
push_back
(
grEdge
[
5
]);
case
5
:
vec
.
push_back
(
grEdge
[
4
]);
case
4
:
vec
.
push_back
(
grEdge
[
3
]);
case
3
:
vec
.
push_back
(
grEdge
[
2
]);
case
2
:
vec
.
push_back
(
grEdge
[
1
]);
case
1
:
vec
.
push_back
(
grEdge
[
0
]);
}
return
size
;
}
bool
complete
()
const
{
return
size
==
sizeC
;
}
};
typedef
std
::
map
<
MElement
*
,
GrVertex
>
GrVertexMap
;
/*******************************************************************************
*
* Class Graph
*
* Purpose
* =======
*
* Graph of the mesh for partitioning purposes
*
* Notes
* =====
*
* - A "graph vertex" is a mesh element.
* - A "graph edge" is a face between two elements.
*
******************************************************************************/
class
Graph
{
public:
std
::
vector
<
int
>
xadj
;
// Indices into 'adjncy' for each graph
// vertex
std
::
vector
<
int
>
adjncy
;
// Connectivity between graph vertex
// xadj[i] and its neighbour graph
// vertices.
std
::
vector
<
int
>
section
;
// For separate partitioning of
// different parts of the mesh
std
::
vector
<
int
>
partition
;
// The partitions output from the
// partitioner
std
::
vector
<
MElement
*>
element
;
// The element corresponding to each
// graph vertex in 'xadj'
private:
unsigned
cIndex
;
// An index for created graph vertices
// (used externally)
unsigned
numGrVert
;
// Number of graph vertices currently
// stored. This is incremented as graph
// vertices are written to xadj;
unsigned
totalGrVert
;
// The total number of graph vertices
// over all sections
int
*
c2w
;
// This array is used to translate the
// creation index of a graph vertex into
// the write index. The write index is
// the location a vertex is written to
// 'xadj'. 'adjcny' originally contains
// creations indices and will need to be
// translated.
public:
Graph
()
:
cIndex
(
0
),
numGrVert
(
0
),
totalGrVert
(
0
)
{
}
Graph
(
const
unsigned
_totalGrVert
,
const
unsigned
totalGrEdge
)
:
cIndex
(
0
),
numGrVert
(
0
)
{
allocate
(
_totalGrVert
,
totalGrEdge
);
}
// Get number of vertices
int
getNumVertex
()
const
{
return
numGrVert
;
}
// Get total number of vertices. This should be used if the graph is not yet
// built.
int
getTotalNumVertex
()
const
{
return
totalGrVert
;
}
// Reserve/resize memory for the graph
void
allocate
(
const
unsigned
_totalGrVert
,
const
unsigned
totalGrEdge
)
{
totalGrVert
=
_totalGrVert
;
xadj
.
resize
(
_totalGrVert
+
1
);
adjncy
.
reserve
(
2
*
totalGrEdge
);
partition
.
resize
(
_totalGrVert
);
element
.
resize
(
_totalGrVert
);
c2w
=
new
int
[
_totalGrVert
];
}
// Adds a graph vertex
void
add
(
const
GrVertexMap
::
const_iterator
&
grVertMapIt
)
{
const
int
i
=
numGrVert
++
;
xadj
[
i
]
=
adjncy
.
size
();
grVertMapIt
->
second
.
write
(
adjncy
);
element
[
i
]
=
grVertMapIt
->
first
;
// Translated vertex numbers start from 1
c2w
[
grVertMapIt
->
second
.
index
]
=
i
+
1
;
}
void
markSection
()
{
section
.
push_back
(
numGrVert
);
}
// Returns the next index for a graph vertex
int
getNextIndex
()
{
return
cIndex
++
;
}
// Returns a write index for a given creation index
int
convertC2W
(
const
int
c
)
const
{
return
c2w
[
c
];
}
// Close the adjacency arrays (also deletes c2w)
void
close
()
{
if
(
numGrVert
!=
totalGrVert
)
{
Msg
::
Warning
(
"Internal error - Graph vertices are missing"
);
}
xadj
[
numGrVert
]
=
adjncy
.
size
();
const
int
nAdj
=
adjncy
.
size
();
for
(
int
i
=
0
;
i
!=
nAdj
;
++
i
)
adjncy
[
i
]
=
c2w
[
adjncy
[
i
]];
delete
[]
c2w
;
}
// If partition is stored as short, repopulate as int. 1 is also added since
// Chaco numbers sections from 1.
void
short2int
()
{
short
*
ps
=
reinterpret_cast
<
short
*>
(
&
partition
[
0
])
+
numGrVert
;
for
(
int
i
=
numGrVert
;
i
--
;)
partition
[
i
]
=
*--
ps
+
1
;
}
};
/*******************************************************************************
*
* Struct BoElemGr
*
* Purpose
* =======
*
* Provides data for a vector of boundary elements (dimension DIM-1) and
* the corresponding graph vertex from which they should obtain a partition
* index from. In other words this vector relates boundary elements to the
* interior elements.
*
******************************************************************************/
struct
BoElemGr
{
MElement
*
elem
;
// The boundary element
int
grVert
;
// Vertex in the graph assigned to the
// neighbour interior element
BoElemGr
(
MElement
*
const
_elem
,
const
int
_grVert
)
:
elem
(
_elem
),
grVert
(
_grVert
)
{
}
};
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment