1 |
|
2 |
/* $Id$ */ |
3 |
|
4 |
/******************************************************* |
5 |
* |
6 |
* Copyright 2003-2007 by ACceSS MNRF |
7 |
* Copyright 2007 by University of Queensland |
8 |
* |
9 |
* http://esscc.uq.edu.au |
10 |
* Primary Business: Queensland, Australia |
11 |
* Licensed under the Open Software License version 3.0 |
12 |
* http://www.opensource.org/licenses/osl-3.0.php |
13 |
* |
14 |
*******************************************************/ |
15 |
|
16 |
/**************************************************************/ |
17 |
|
18 |
/* Finley: Mesh */ |
19 |
|
20 |
/**************************************************************/ |
21 |
|
22 |
#include "Mesh.h" |
23 |
#include "IndexList.h" |
24 |
|
25 |
/**************************************************************/ |
26 |
|
27 |
/* returns a reference to the matrix pattern */ |
28 |
|
29 |
Paso_SystemMatrixPattern* Finley_getPattern(Finley_Mesh *mesh,bool_t reduce_row_order, bool_t reduce_col_order) { |
30 |
Paso_SystemMatrixPattern *out=NULL; |
31 |
Finley_resetError(); |
32 |
/* make sure that the requested pattern is available */ |
33 |
if (reduce_row_order) { |
34 |
if (reduce_col_order) { |
35 |
if (mesh->ReducedReducedPattern==NULL) mesh->ReducedReducedPattern=Finley_makePattern(mesh,reduce_row_order,reduce_col_order); |
36 |
} else { |
37 |
if (mesh->ReducedFullPattern==NULL) mesh->ReducedFullPattern=Finley_makePattern(mesh,reduce_row_order,reduce_col_order); |
38 |
} |
39 |
} else { |
40 |
if (reduce_col_order) { |
41 |
if (mesh->FullReducedPattern==NULL) mesh->FullReducedPattern=Finley_makePattern(mesh,reduce_row_order,reduce_col_order); |
42 |
} else { |
43 |
if (mesh->FullFullPattern==NULL) mesh->FullFullPattern=Finley_makePattern(mesh,reduce_row_order,reduce_col_order); |
44 |
} |
45 |
} |
46 |
if (Finley_noError()) { |
47 |
if (reduce_row_order) { |
48 |
if (reduce_col_order) { |
49 |
out=Paso_SystemMatrixPattern_reference(mesh->ReducedReducedPattern); |
50 |
} else { |
51 |
out=Paso_SystemMatrixPattern_reference(mesh->ReducedFullPattern); |
52 |
} |
53 |
} else { |
54 |
if (reduce_col_order) { |
55 |
out=Paso_SystemMatrixPattern_reference(mesh->FullReducedPattern); |
56 |
} else { |
57 |
out=Paso_SystemMatrixPattern_reference(mesh->FullFullPattern); |
58 |
} |
59 |
} |
60 |
} |
61 |
return out; |
62 |
} |
63 |
Paso_SystemMatrixPattern* Finley_makePattern(Finley_Mesh *mesh,bool_t reduce_row_order, bool_t reduce_col_order) { |
64 |
double time0; |
65 |
Paso_SystemMatrixPattern* out=NULL; |
66 |
Paso_Pattern *main_pattern = NULL, *col_couple_pattern=NULL, *row_couple_pattern=NULL; |
67 |
Paso_Connector *col_connector, *row_connector; |
68 |
Finley_IndexList* index_list=NULL; |
69 |
Finley_NodeMapping *colMap=NULL, *rowMap=NULL; |
70 |
Paso_Distribution *colDistribution=NULL, *rowDistribution=NULL; |
71 |
|
72 |
index_t i; |
73 |
Finley_resetError(); |
74 |
time0=Finley_timer(); |
75 |
|
76 |
if (reduce_col_order) { |
77 |
colMap=mesh->Nodes->reducedDegreesOfFreedomMapping; |
78 |
colDistribution=mesh->Nodes->reducedDegreesOfFreedomDistribution; |
79 |
col_connector=mesh->Nodes->reducedDegreesOfFreedomConnector; |
80 |
|
81 |
} else { |
82 |
colMap=mesh->Nodes->degreesOfFreedomMapping; |
83 |
colDistribution=mesh->Nodes->degreesOfFreedomDistribution; |
84 |
col_connector=mesh->Nodes->degreesOfFreedomConnector; |
85 |
} |
86 |
|
87 |
if (reduce_row_order) { |
88 |
rowMap=mesh->Nodes->reducedDegreesOfFreedomMapping; |
89 |
rowDistribution=mesh->Nodes->reducedDegreesOfFreedomDistribution; |
90 |
row_connector=mesh->Nodes->reducedDegreesOfFreedomConnector; |
91 |
} else { |
92 |
rowMap=mesh->Nodes->degreesOfFreedomMapping; |
93 |
rowDistribution=mesh->Nodes->degreesOfFreedomDistribution; |
94 |
row_connector=mesh->Nodes->degreesOfFreedomConnector; |
95 |
} |
96 |
|
97 |
index_list=TMPMEMALLOC(rowMap->numTargets,Finley_IndexList); |
98 |
if (! Finley_checkPtr(index_list)) { |
99 |
|
100 |
#pragma omp parallel private(i) |
101 |
{ |
102 |
#pragma omp for schedule(static) |
103 |
for(i=0;i<rowMap->numTargets;++i) { |
104 |
index_list[i].extension=NULL; |
105 |
index_list[i].n=0; |
106 |
} |
107 |
/* insert contributions from element matrices into colums index index_list: */ |
108 |
Finley_IndexList_insertElements(index_list,mesh->Elements, |
109 |
reduce_row_order,rowMap->target,reduce_col_order,colMap->target); |
110 |
Finley_IndexList_insertElements(index_list,mesh->FaceElements, |
111 |
reduce_row_order,rowMap->target,reduce_col_order,colMap->target); |
112 |
Finley_IndexList_insertElements(index_list,mesh->ContactElements, |
113 |
reduce_row_order,rowMap->target,reduce_col_order,colMap->target); |
114 |
Finley_IndexList_insertElements(index_list,mesh->Points, |
115 |
reduce_row_order,rowMap->target,reduce_col_order,colMap->target); |
116 |
|
117 |
} |
118 |
|
119 |
/* create pattern */ |
120 |
main_pattern=Finley_IndexList_createPattern(0,Paso_Distribution_getMyNumComponents(rowDistribution),index_list, |
121 |
0,Paso_Distribution_getMyNumComponents(colDistribution), |
122 |
0); |
123 |
col_couple_pattern=Finley_IndexList_createPattern(0,Paso_Distribution_getMyNumComponents(rowDistribution),index_list, |
124 |
Paso_Distribution_getMyNumComponents(colDistribution),colMap->numTargets, |
125 |
-Paso_Distribution_getMyNumComponents(colDistribution)); |
126 |
row_couple_pattern=Finley_IndexList_createPattern(Paso_Distribution_getMyNumComponents(rowDistribution),rowMap->numTargets,index_list, |
127 |
0,Paso_Distribution_getMyNumComponents(colDistribution), |
128 |
0); |
129 |
|
130 |
/* if everthing is in order we can create the return value */ |
131 |
if (Finley_noError()) { |
132 |
out=Paso_SystemMatrixPattern_alloc(PATTERN_FORMAT_DEFAULT, |
133 |
rowDistribution, |
134 |
colDistribution, |
135 |
main_pattern, |
136 |
col_couple_pattern, |
137 |
row_couple_pattern, |
138 |
col_connector, |
139 |
row_connector); |
140 |
} |
141 |
/* clean up */ |
142 |
if (index_list!=NULL) { |
143 |
#pragma omp parallel for private(i) |
144 |
for(i=0;i<rowMap->numTargets;++i) Finley_IndexList_free(index_list[i].extension); |
145 |
} |
146 |
TMPMEMFREE(index_list); |
147 |
Paso_Pattern_free(main_pattern); |
148 |
Paso_Pattern_free(col_couple_pattern); |
149 |
Paso_Pattern_free(row_couple_pattern); |
150 |
} |
151 |
#ifdef Finley_TRACE |
152 |
printf("timing: mesh to matrix pattern: %.4e sec\n",Finley_timer()-time0); |
153 |
#endif |
154 |
Paso_MPIInfo_noError(mesh->MPIInfo); |
155 |
return out; |
156 |
} |