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
e54f9f74
Commit
e54f9f74
authored
16 years ago
by
Christophe Geuzaine
Browse files
Options
Downloads
Patches
Plain Diff
replace touchSubmatrix() & co with copy() full code now works without GSL (even ho)
parent
47938373
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Numeric/FunctionSpace.cpp
+3
-4
3 additions, 4 deletions
Numeric/FunctionSpace.cpp
Numeric/GmshMatrix.h
+68
-77
68 additions, 77 deletions
Numeric/GmshMatrix.h
with
71 additions
and
81 deletions
Numeric/FunctionSpace.cpp
+
3
−
4
View file @
e54f9f74
...
@@ -130,8 +130,7 @@ Double_Matrix generatePascalSerendipityTetrahedron(int order)
...
@@ -130,8 +130,7 @@ Double_Matrix generatePascalSerendipityTetrahedron(int order)
}
}
Double_Matrix
monomialsMaxOrder
=
generateMonomialSubspace
(
3
,
order
);
Double_Matrix
monomialsMaxOrder
=
generateMonomialSubspace
(
3
,
order
);
int
nbMaxOrder
=
monomialsMaxOrder
.
size1
();
int
nbMaxOrder
=
monomialsMaxOrder
.
size1
();
monomials
.
copy
(
monomialsMaxOrder
,
0
,
nbMaxOrder
,
0
,
3
,
index
,
0
);
monomials
.
submatrix
(
index
,
nbMaxOrder
,
0
,
3
).
memcpy
(
monomialsMaxOrder
);
return
monomials
;
return
monomials
;
}
}
...
@@ -147,7 +146,7 @@ Double_Matrix generatePascalTetrahedron(int order)
...
@@ -147,7 +146,7 @@ Double_Matrix generatePascalTetrahedron(int order)
for
(
int
p
=
0
;
p
<=
order
;
p
++
)
{
for
(
int
p
=
0
;
p
<=
order
;
p
++
)
{
Double_Matrix
monOrder
=
generateMonomialSubspace
(
3
,
p
);
Double_Matrix
monOrder
=
generateMonomialSubspace
(
3
,
p
);
int
nb
=
monOrder
.
size1
();
int
nb
=
monOrder
.
size1
();
monomials
.
submatrix
(
index
,
nb
,
0
,
3
).
memcpy
(
monOrder
);
monomials
.
copy
(
monOrder
,
0
,
nb
,
0
,
3
,
index
,
0
);
index
+=
nb
;
index
+=
nb
;
}
}
...
@@ -511,7 +510,7 @@ Double_Matrix gmshGeneratePointsTriangle(int order, bool serendip)
...
@@ -511,7 +510,7 @@ Double_Matrix gmshGeneratePointsTriangle(int order, bool serendip)
Double_Matrix
inner
=
gmshGeneratePointsTriangle
(
order
-
3
,
serendip
);
Double_Matrix
inner
=
gmshGeneratePointsTriangle
(
order
-
3
,
serendip
);
inner
.
scale
(
1.
-
3.
*
dd
);
inner
.
scale
(
1.
-
3.
*
dd
);
inner
.
add
(
dd
);
inner
.
add
(
dd
);
point
.
submatrix
(
index
,
nbPoints
-
index
,
0
,
2
).
memcpy
(
inner
);
point
.
copy
(
inner
,
0
,
nbPoints
-
index
,
0
,
2
,
index
,
0
);
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Numeric/GmshMatrix.h
+
68
−
77
View file @
e54f9f74
...
@@ -93,7 +93,6 @@ class Gmsh_Matrix
...
@@ -93,7 +93,6 @@ class Gmsh_Matrix
if
((
temp
=
fabs
((
*
this
)(
i
,
j
)))
>
big
)
big
=
temp
;
if
((
temp
=
fabs
((
*
this
)(
i
,
j
)))
>
big
)
big
=
temp
;
if
(
big
==
0.
)
{
if
(
big
==
0.
)
{
delete
[]
vv
;
delete
[]
vv
;
Msg
::
Error
(
"Zero pivot in LU factorization"
);
return
false
;
return
false
;
}
}
vv
[
i
]
=
1.
/
big
;
vv
[
i
]
=
1.
/
big
;
...
@@ -149,7 +148,7 @@ class Gmsh_Matrix
...
@@ -149,7 +148,7 @@ class Gmsh_Matrix
~
Gmsh_Matrix
()
{
if
(
_data
)
delete
[]
_data
;
}
~
Gmsh_Matrix
()
{
if
(
_data
)
delete
[]
_data
;
}
inline
int
size1
()
const
{
return
_r
;
}
inline
int
size1
()
const
{
return
_r
;
}
inline
int
size2
()
const
{
return
_c
;
}
inline
int
size2
()
const
{
return
_c
;
}
Gmsh_Matrix
<
SCALAR
>
&
operator
=
(
const
Gmsh_Matrix
<
SCALAR
>
&
other
)
Gmsh_Matrix
<
SCALAR
>
&
operator
=
(
const
Gmsh_Matrix
<
SCALAR
>
&
other
)
{
{
if
(
this
!=
&
other
){
if
(
this
!=
&
other
){
_r
=
other
.
_r
;
_r
=
other
.
_r
;
...
@@ -171,6 +170,13 @@ class Gmsh_Matrix
...
@@ -171,6 +170,13 @@ class Gmsh_Matrix
{
{
return
_data
[
i
+
_r
*
j
];
return
_data
[
i
+
_r
*
j
];
}
}
void
copy
(
const
Gmsh_Matrix
<
SCALAR
>
&
a
,
int
i0
,
int
ni
,
int
j0
,
int
nj
,
int
desti0
,
int
destj0
)
{
for
(
int
i
=
i0
,
desti
=
desti0
;
i
<
i0
+
ni
;
i
++
,
desti
++
)
for
(
int
j
=
j0
,
destj
=
destj0
;
j
<
j0
+
nj
;
j
++
,
destj
++
)
(
*
this
)(
desti
,
destj
)
=
a
(
i
,
j
);
}
inline
void
mult
(
const
Gmsh_Matrix
<
SCALAR
>
&
b
,
Gmsh_Matrix
<
SCALAR
>
&
c
)
inline
void
mult
(
const
Gmsh_Matrix
<
SCALAR
>
&
b
,
Gmsh_Matrix
<
SCALAR
>
&
c
)
{
{
c
.
scale
(
0.
);
c
.
scale
(
0.
);
...
@@ -192,6 +198,30 @@ class Gmsh_Matrix
...
@@ -192,6 +198,30 @@ class Gmsh_Matrix
{
{
for
(
int
i
=
0
;
i
<
_r
*
_c
;
i
++
)
_data
[
i
]
=
m
;
for
(
int
i
=
0
;
i
<
_r
*
_c
;
i
++
)
_data
[
i
]
=
m
;
}
}
inline
void
scale
(
const
double
s
)
{
if
(
s
==
0.
)
for
(
int
i
=
0
;
i
<
_r
*
_c
;
++
i
)
_data
[
i
]
=
0.
;
else
for
(
int
i
=
0
;
i
<
_r
*
_c
;
++
i
)
_data
[
i
]
*=
s
;
}
inline
void
add
(
const
double
&
a
)
{
for
(
int
i
=
0
;
i
<
_r
*
_c
;
++
i
)
_data
[
i
]
+=
a
;
}
inline
void
add
(
const
Gmsh_Matrix
<
SCALAR
>
&
m
)
{
for
(
int
i
=
0
;
i
<
size1
();
i
++
)
for
(
int
j
=
0
;
j
<
size2
();
j
++
)
(
*
this
)(
i
,
j
)
+=
m
(
i
,
j
);
}
inline
void
mult
(
const
Gmsh_Vector
<
SCALAR
>
&
x
,
Gmsh_Vector
<
SCALAR
>
&
y
)
{
y
.
scale
(
0.
);
for
(
int
i
=
0
;
i
<
_r
;
i
++
)
for
(
int
j
=
0
;
j
<
_c
;
j
++
)
y
.
_data
[
i
]
+=
(
*
this
)(
i
,
j
)
*
x
(
j
);
}
inline
bool
lu_solve
(
const
Gmsh_Vector
<
SCALAR
>
&
rhs
,
Gmsh_Vector
<
SCALAR
>
&
result
)
inline
bool
lu_solve
(
const
Gmsh_Vector
<
SCALAR
>
&
rhs
,
Gmsh_Vector
<
SCALAR
>
&
result
)
{
{
int
*
indx
=
new
int
[
_c
];
int
*
indx
=
new
int
[
_c
];
...
@@ -240,47 +270,17 @@ class Gmsh_Matrix
...
@@ -240,47 +270,17 @@ class Gmsh_Matrix
}
}
return
cof
;
return
cof
;
}
}
inline
void
mult
(
const
Gmsh_Vector
<
SCALAR
>
&
x
,
Gmsh_Vector
<
SCALAR
>
&
y
)
{
y
.
scale
(
0.
);
for
(
int
i
=
0
;
i
<
_r
;
i
++
)
for
(
int
j
=
0
;
j
<
_c
;
j
++
)
y
.
_data
[
i
]
+=
(
*
this
)(
i
,
j
)
*
x
(
j
);
}
SCALAR
determinant
()
const
SCALAR
determinant
()
const
{
{
Gmsh_Matrix
<
SCALAR
>
copy
=
*
this
;
Gmsh_Matrix
<
SCALAR
>
tmp
=
*
this
;
SCALAR
factor
=
1.
;
SCALAR
factor
=
1.
;
int
*
indx
=
new
int
[
_c
];
int
*
indx
=
new
int
[
_c
];
if
(
!
copy
.
_lu_decomposition
(
indx
,
factor
))
return
0.
;
if
(
!
tmp
.
_lu_decomposition
(
indx
,
factor
))
return
0.
;
SCALAR
det
=
factor
;
SCALAR
det
=
factor
;
for
(
int
i
=
0
;
i
<
_c
;
i
++
)
det
*=
copy
(
i
,
i
);
for
(
int
i
=
0
;
i
<
_c
;
i
++
)
det
*=
tmp
(
i
,
i
);
delete
[]
indx
;
delete
[]
indx
;
return
det
;
return
det
;
}
}
inline
Gmsh_Matrix
<
SCALAR
>
submatrix
(
int
i0
,
int
ni
,
int
j0
,
int
nj
)
const
{
Msg
::
Fatal
(
"submatrix not implemented yet for Gmsh_Matrix"
);
Gmsh_Matrix
<
SCALAR
>
subm
(
ni
,
nj
);
return
subm
;
}
inline
void
scale
(
const
double
s
)
{
if
(
s
==
0.
)
for
(
int
i
=
0
;
i
<
_r
*
_c
;
++
i
)
_data
[
i
]
=
0.
;
else
for
(
int
i
=
0
;
i
<
_r
*
_c
;
++
i
)
_data
[
i
]
*=
s
;
}
inline
void
add
(
const
double
&
a
)
{
for
(
int
i
=
0
;
i
<
_r
*
_c
;
++
i
)
_data
[
i
]
+=
a
;
}
inline
void
add
(
const
Gmsh_Matrix
<
SCALAR
>
&
m
)
{
for
(
int
i
=
0
;
i
<
size1
();
i
++
)
for
(
int
j
=
0
;
j
<
size2
();
j
++
)
(
*
this
)(
i
,
j
)
+=
m
(
i
,
j
);
}
};
};
#if defined(HAVE_GSL)
#if defined(HAVE_GSL)
...
@@ -332,7 +332,6 @@ class GSL_Vector
...
@@ -332,7 +332,6 @@ class GSL_Vector
class
GSL_Matrix
class
GSL_Matrix
{
{
private:
private:
gsl_matrix_view
_view
;
gsl_matrix
*
_data
;
gsl_matrix
*
_data
;
public:
public:
GSL_Matrix
(
int
r
,
int
c
)
{
_data
=
gsl_matrix_calloc
(
r
,
c
);
}
GSL_Matrix
(
int
r
,
int
c
)
{
_data
=
gsl_matrix_calloc
(
r
,
c
);
}
...
@@ -342,12 +341,11 @@ class GSL_Matrix
...
@@ -342,12 +341,11 @@ class GSL_Matrix
_data
=
gsl_matrix_calloc
(
other
.
_data
->
size1
,
other
.
_data
->
size2
);
_data
=
gsl_matrix_calloc
(
other
.
_data
->
size1
,
other
.
_data
->
size2
);
gsl_matrix_memcpy
(
_data
,
other
.
_data
);
gsl_matrix_memcpy
(
_data
,
other
.
_data
);
}
}
GSL_Matrix
(
gsl_matrix_view
view
)
:
_view
(
view
),
_data
(
&
_view
.
matrix
)
{}
GSL_Matrix
()
:
_data
(
0
)
{}
GSL_Matrix
()
:
_data
(
0
)
{}
~
GSL_Matrix
()
{
if
(
_data
&&
_data
->
owner
==
1
)
gsl_matrix_free
(
_data
);
}
~
GSL_Matrix
()
{
if
(
_data
&&
_data
->
owner
==
1
)
gsl_matrix_free
(
_data
);
}
inline
int
size1
()
const
{
return
_data
->
size1
;
}
inline
int
size1
()
const
{
return
_data
->
size1
;
}
inline
int
size2
()
const
{
return
_data
->
size2
;
}
inline
int
size2
()
const
{
return
_data
->
size2
;
}
GSL_Matrix
&
operator
=
(
const
GSL_Matrix
&
other
)
GSL_Matrix
&
operator
=
(
const
GSL_Matrix
&
other
)
{
{
if
(
&
other
!=
this
){
if
(
&
other
!=
this
){
if
(
_data
)
gsl_matrix_free
(
_data
);
if
(
_data
)
gsl_matrix_free
(
_data
);
...
@@ -368,6 +366,13 @@ class GSL_Matrix
...
@@ -368,6 +366,13 @@ class GSL_Matrix
{
{
return
*
gsl_matrix_ptr
(
_data
,
i
,
j
);
return
*
gsl_matrix_ptr
(
_data
,
i
,
j
);
}
}
void
copy
(
const
GSL_Matrix
&
a
,
int
i0
,
int
ni
,
int
j0
,
int
nj
,
int
desti0
,
int
destj0
)
{
for
(
int
i
=
i0
,
desti
=
desti0
;
i
<
i0
+
ni
;
i
++
,
desti
++
)
for
(
int
j
=
j0
,
destj
=
destj0
;
j
<
j0
+
nj
;
j
++
,
destj
++
)
(
*
this
)(
desti
,
destj
)
=
a
(
i
,
j
);
}
inline
void
mult
(
const
GSL_Matrix
&
b
,
GSL_Matrix
&
c
)
inline
void
mult
(
const
GSL_Matrix
&
b
,
GSL_Matrix
&
c
)
{
{
gsl_blas_dgemm
(
CblasNoTrans
,
CblasNoTrans
,
1.
,
_data
,
b
.
_data
,
0.
,
c
.
_data
);
gsl_blas_dgemm
(
CblasNoTrans
,
CblasNoTrans
,
1.
,
_data
,
b
.
_data
,
0.
,
c
.
_data
);
...
@@ -381,6 +386,23 @@ class GSL_Matrix
...
@@ -381,6 +386,23 @@ class GSL_Matrix
{
{
gsl_matrix_set_all
(
_data
,
m
);
gsl_matrix_set_all
(
_data
,
m
);
}
}
inline
void
scale
(
const
double
s
)
{
if
(
s
==
0.
)
gsl_matrix_set_zero
(
_data
);
else
gsl_matrix_scale
(
_data
,
s
);
}
inline
void
add
(
const
double
&
a
)
{
gsl_matrix_add_constant
(
_data
,
a
);
}
inline
void
add
(
const
GSL_Matrix
&
m
)
{
gsl_matrix_add
(
_data
,
m
.
_data
);
}
inline
void
mult
(
const
GSL_Vector
&
x
,
GSL_Vector
&
b
)
{
gsl_blas_dgemv
(
CblasNoTrans
,
1.
,
_data
,
x
.
_data
,
0.
,
b
.
_data
);
}
inline
bool
lu_solve
(
const
GSL_Vector
&
rhs
,
GSL_Vector
&
result
)
inline
bool
lu_solve
(
const
GSL_Vector
&
rhs
,
GSL_Vector
&
result
)
{
{
int
s
;
int
s
;
...
@@ -407,54 +429,23 @@ class GSL_Matrix
...
@@ -407,54 +429,23 @@ class GSL_Matrix
int
ni
=
size1
();
int
ni
=
size1
();
int
nj
=
size2
();
int
nj
=
size2
();
GSL_Matrix
cof
(
ni
-
1
,
nj
-
1
);
GSL_Matrix
cof
(
ni
-
1
,
nj
-
1
);
if
(
i
>
0
)
{
for
(
int
I
=
0
;
I
<
ni
;
I
++
){
if
(
j
>
0
)
for
(
int
J
=
0
;
J
<
nj
;
J
++
){
cof
.
submatrix
(
0
,
i
,
0
,
j
).
if
(
J
!=
j
&&
I
!=
i
)
memcpy
(
submatrix
(
0
,
i
,
0
,
j
));
cof
(
I
<
i
?
I
:
I
-
1
,
J
<
j
?
J
:
J
-
1
)
=
(
*
this
)(
I
,
J
);
if
(
j
<
nj
-
1
)
}
cof
.
submatrix
(
0
,
i
,
j
,
nj
-
j
-
1
).
memcpy
(
submatrix
(
0
,
i
,
j
+
1
,
nj
-
j
-
1
));
}
if
(
i
<
ni
-
1
)
{
if
(
j
<
nj
-
1
)
cof
.
submatrix
(
i
,
ni
-
i
-
1
,
j
,
nj
-
j
-
1
).
memcpy
(
submatrix
(
i
+
1
,
ni
-
i
-
1
,
j
+
1
,
nj
-
j
-
1
));
if
(
j
>
0
)
cof
.
submatrix
(
i
,
ni
-
i
-
1
,
0
,
j
).
memcpy
(
submatrix
(
i
+
1
,
ni
-
i
-
1
,
0
,
j
));
}
}
return
cof
;
return
cof
;
}
}
inline
void
mult
(
const
GSL_Vector
&
x
,
GSL_Vector
&
b
)
{
gsl_blas_dgemv
(
CblasNoTrans
,
1.
,
_data
,
x
.
_data
,
0.
,
b
.
_data
);
}
double
determinant
()
const
double
determinant
()
const
{
{
GSL_Matrix
copy
=
*
this
;
GSL_Matrix
tmp
=
*
this
;
gsl_permutation
*
p
=
gsl_permutation_alloc
(
size1
());
gsl_permutation
*
p
=
gsl_permutation_alloc
(
size1
());
int
s
;
int
s
;
gsl_linalg_LU_decomp
(
copy
.
_data
,
p
,
&
s
);
gsl_linalg_LU_decomp
(
tmp
.
_data
,
p
,
&
s
);
gsl_permutation_free
(
p
);
gsl_permutation_free
(
p
);
return
gsl_linalg_LU_det
(
copy
.
_data
,
s
);
return
gsl_linalg_LU_det
(
tmp
.
_data
,
s
);
}
}
inline
GSL_Matrix
submatrix
(
int
i0
,
int
ni
,
int
j0
,
int
nj
)
const
{
return
GSL_Matrix
(
gsl_matrix_submatrix
(
_data
,
i0
,
j0
,
ni
,
nj
));
}
inline
void
scale
(
const
double
s
)
{
if
(
s
==
0.
)
gsl_matrix_set_zero
(
_data
);
else
gsl_matrix_scale
(
_data
,
s
);
}
inline
void
add
(
const
double
&
a
)
{
gsl_matrix_add_constant
(
_data
,
a
);
}
inline
void
add
(
const
GSL_Matrix
&
m
)
{
gsl_matrix_add
(
_data
,
m
.
_data
);
}
};
};
typedef
GSL_Matrix
Double_Matrix
;
typedef
GSL_Matrix
Double_Matrix
;
...
...
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