Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
INMOST
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Terekhov
INMOST
Commits
9c33d2c1
Commit
9c33d2c1
authored
Mar 29, 2017
by
Kirill Terekhov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Residual class annotation in inmost_autodiff.h
parent
b2fb0655
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
157 additions
and
103 deletions
+157
-103
Source/Autodiff/autodiff.cpp
Source/Autodiff/autodiff.cpp
+80
-0
Source/Headers/inmost_autodiff.h
Source/Headers/inmost_autodiff.h
+77
-103
No files found.
Source/Autodiff/autodiff.cpp
View file @
9c33d2c1
...
...
@@ -401,6 +401,86 @@ namespace INMOST
return
ret
;
}
#endif //USE_MESH
#if defined(USE_SOLVER)
void
Residual
::
GetInterval
(
INMOST_DATA_ENUM_TYPE
&
start
,
INMOST_DATA_ENUM_TYPE
&
end
)
const
{
start
=
residual
.
GetFirstIndex
();
end
=
residual
.
GetLastIndex
();
}
void
Residual
::
SetInterval
(
INMOST_DATA_ENUM_TYPE
beg
,
INMOST_DATA_ENUM_TYPE
end
)
{
jacobian
.
SetInterval
(
beg
,
end
);
residual
.
SetInterval
(
beg
,
end
);
}
void
Residual
::
ClearResidual
()
{
for
(
Sparse
::
Vector
::
iterator
it
=
residual
.
Begin
();
it
!=
residual
.
End
();
++
it
)
(
*
it
)
=
0.0
;
}
void
Residual
::
ClearJacobian
()
{
for
(
Sparse
::
Matrix
::
iterator
it
=
jacobian
.
Begin
();
it
!=
jacobian
.
End
();
++
it
)
it
->
Clear
();
}
void
Residual
::
Clear
()
{
#if defined(USE_OMP)
#pragma omp for
#endif //USE_OMP
for
(
int
k
=
(
int
)
GetFirstIndex
();
k
<
(
int
)
GetLastIndex
();
++
k
)
{
residual
[
k
]
=
0.0
;
jacobian
[
k
].
Clear
();
}
}
INMOST_DATA_REAL_TYPE
Residual
::
Norm
()
{
INMOST_DATA_REAL_TYPE
ret
=
0
;
#if defined(USE_OMP)
#pragma omp parallel for reduction(+:ret)
#endif //USE_OMP
for
(
int
k
=
(
int
)
GetFirstIndex
();
k
<
(
int
)
GetLastIndex
();
++
k
)
ret
+=
residual
[
k
]
*
residual
[
k
];
#if defined(USE_MPI)
INMOST_DATA_REAL_TYPE
tmp
=
ret
;
MPI_Allreduce
(
&
tmp
,
&
ret
,
1
,
INMOST_MPI_DATA_REAL_TYPE
,
MPI_SUM
,
jacobian
.
GetCommunicator
());
#endif
return
sqrt
(
ret
);
}
Residual
&
Residual
::
operator
=
(
Residual
const
&
other
)
{
jacobian
=
other
.
jacobian
;
residual
=
other
.
residual
;
return
*
this
;
}
void
Residual
::
Rescale
()
{
#if defined(USE_OMP)
#pragma omp parallel for
#endif //USE_OMP
for
(
int
k
=
(
int
)
GetFirstIndex
();
k
<
(
int
)
GetLastIndex
();
++
k
)
{
INMOST_DATA_REAL_TYPE
norm
=
0.0
;
for
(
INMOST_DATA_ENUM_TYPE
q
=
0
;
q
<
jacobian
[
k
].
Size
();
++
q
)
norm
+=
jacobian
[
k
].
GetValue
(
q
)
*
jacobian
[
k
].
GetValue
(
q
);
norm
=
sqrt
(
norm
);
if
(
norm
)
{
norm
=
1.0
/
norm
;
residual
[
k
]
*=
norm
;
for
(
INMOST_DATA_ENUM_TYPE
q
=
0
;
q
<
jacobian
[
k
].
Size
();
++
q
)
jacobian
[
k
].
GetValue
(
q
)
*=
norm
;
}
}
}
Residual
::
Residual
(
std
::
string
name
,
INMOST_DATA_ENUM_TYPE
start
,
INMOST_DATA_ENUM_TYPE
end
,
INMOST_MPI_Comm
_comm
)
:
jacobian
(
name
,
start
,
end
,
_comm
),
residual
(
name
,
start
,
end
,
_comm
)
{
}
Residual
::
Residual
(
const
Residual
&
other
)
:
jacobian
(
other
.
jacobian
),
residual
(
other
.
residual
)
{
}
#endif //USE_SOLVER
};
#endif //USE_AUTODIFF
Source/Headers/inmost_autodiff.h
View file @
9c33d2c1
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment