Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
amdis
amdis-core
Commits
289b2b9a
Commit
289b2b9a
authored
Dec 16, 2017
by
Praetorius, Simon
Browse files
working version of dune-functions assembling
parent
7668c6b7
Changes
57
Hide whitespace changes
Inline
Side-by-side
dune/amdis/AdaptInfo.hpp
View file @
289b2b9a
#pragma once
// std c++ headers
#include
<algorithm>
#include
<cmath>
#include
<limits>
#include
<string>
#include
<vector>
...
...
@@ -82,7 +84,7 @@ namespace AMDiS
public:
/// Constructor.
AdaptInfo
(
std
::
string
name
,
int
size
=
1
);
explicit
AdaptInfo
(
std
::
string
name
,
int
size
=
1
);
/// Destructor.
virtual
~
AdaptInfo
()
{}
...
...
@@ -427,7 +429,7 @@ namespace AMDiS
if
(
nTimesteps
>
0
)
return
!
(
timestepNumber
<
nTimesteps
);
return
!
(
std
::
abs
(
time
-
endTime
)
>
DBL_TOL
);
return
!
(
std
::
abs
(
time
-
endTime
)
>
std
::
numeric_limits
<
double
>::
epsilon
()
);
}
...
...
dune/amdis/Assembler.inc.hpp
View file @
289b2b9a
...
...
@@ -4,6 +4,8 @@
#include
<dune/amdis/utility/TreePath.hpp>
#include
<dune/amdis/utility/Visitor.hpp>
#include
<dune/amdis/Math.hpp>
namespace
AMDiS
{
template
<
class
Traits
>
...
...
@@ -65,7 +67,7 @@ void Assembler<Traits>::assemble(
for
(
std
::
size_t
i
=
0
;
i
<
localView
.
size
();
++
i
)
{
auto
const
row
=
localIndexSet
.
index
(
i
);
for
(
std
::
size_t
j
=
0
;
j
<
localView
.
size
();
++
j
)
{
if
(
elementMatrix
(
i
,
j
)
!=
0.0
)
{
if
(
std
::
abs
(
elementMatrix
(
i
,
j
)
)
>
threshold
<
double
>
)
{
auto
const
col
=
localIndexSet
.
index
(
j
);
matrix
(
row
,
col
)
+=
elementMatrix
(
i
,
j
);
}
...
...
@@ -74,7 +76,7 @@ void Assembler<Traits>::assemble(
// add element-vector to system-vector
for
(
std
::
size_t
i
=
0
;
i
<
localView
.
size
();
++
i
)
{
if
(
elementVector
[
i
]
!=
0.0
)
{
if
(
std
::
abs
(
elementVector
[
i
]
)
>
threshold
<
double
>
)
{
auto
const
idx
=
localIndexSet
.
index
(
i
);
rhs
[
idx
]
+=
elementVector
[
i
];
}
...
...
dune/amdis/CreatorMap.hpp
View file @
289b2b9a
...
...
@@ -2,6 +2,7 @@
// std c++ headers
#include
<map>
#include
<string>
// AMDiS includes
#include
<dune/amdis/CreatorInterface.hpp>
...
...
dune/amdis/DirichletBC.hpp
View file @
289b2b9a
#pragma once
#include
<functional>
#include
<list>
#include
<type_traits>
#include
<vector>
...
...
dune/amdis/FileWriter.hpp
View file @
289b2b9a
#pragma once
#include
<string>
//#include <vector>
//#include <array>
#include
<memory>
#include
<dune/functions/functionspacebases/lagrangebasis.hh>
...
...
@@ -80,7 +78,8 @@ namespace AMDiS
template
<
class
W
>
void
writeVertexData
(
Dune
::
TypeTree
::
LeafNodeTag
,
index_t
<
0
>
,
W
write
)
{
using
namespace
Dune
::
Functions
::
BasisBuilder
;
using
Dune
::
Functions
::
BasisBuilder
::
makeBasis
;
using
Dune
::
Functions
::
BasisBuilder
::
lagrange
;
auto
fct
=
makeDiscreteFunction
(
basis_
,
treePath_
,
vector_
);
auto
p1basis
=
makeBasis
(
basis_
->
gridView
(),
lagrange
<
1
>
());
...
...
@@ -97,7 +96,11 @@ namespace AMDiS
template
<
std
::
size_t
C
,
class
W
>
void
writeVertexData
(
Dune
::
TypeTree
::
PowerNodeTag
,
index_t
<
C
>
,
W
write
)
{
using
namespace
Dune
::
Functions
::
BasisBuilder
;
using
Dune
::
Functions
::
BasisBuilder
::
makeBasis
;
using
Dune
::
Functions
::
BasisBuilder
::
lagrange
;
using
Dune
::
Functions
::
BasisBuilder
::
power
;
using
Dune
::
Functions
::
BasisBuilder
::
flatLexicographic
;
assert
(
C
==
dow
);
auto
fct
=
makeDiscreteFunction
(
basis_
,
treePath_
,
vector_
);
...
...
@@ -116,78 +119,6 @@ namespace AMDiS
template
<
class
NodeTag
,
std
::
size_t
C
,
class
W
>
void
writeVertexData
(
NodeTag
,
index_t
<
C
>
,
W
)
{}
#if 0
/// default write method for time-depended data
template <class SystemVectorType>
void write(double time, SystemVectorType const& solutions)
{
vtkWriter->clear();
// copy dofvector to vertex data
forEach(range_<0, nComponents>, [this, &solutions](const auto _i)
{
this->dofVector2vertexVector(solutions, std::get<_i>(data_vectors));
vtkSeqWriter->addVertexData(std::get<_i>(data_vectors), names[_i]);
});
vtkSeqWriter->write(time/*, Dune::VTK::appendedraw*/);
}
/// default write method for stationary data
template <class SystemVectorType>
void write(SystemVectorType const& solutions)
{
vtkWriter->clear();
// copy dofvector to vertex data
forEach(range_<0, nComponents>, [this, &solutions](const auto _i)
{
this->dofVector2vertexVector(solutions, std::get<_i>(data_vectors));
vtkWriter->addVertexData(std::get<_i>(data_vectors), names[_i]);
});
vtkWriter->pwrite(filename, dir, "" /*, Dune::VTK::appendedraw*/);
}
template <class DOFVector, class Vector>
void dofVector2vertexVector(DOFVector const& dofvector, Vector& data)
{
using Geometry = typename MeshView::template Codim<0>::Geometry;
using RefElements = Dune::ReferenceElements<typename Geometry::ctype, Geometry::mydimension>;
data.resize(meshView.size(dim));
auto const& indexSet = meshView.indexSet();
auto const& feSpace = dofvector.getFeSpace();
auto localView = feSpace.localView();
auto localIndexSet = feSpace.localIndexSet();
// copy data to P1-vector
for (auto const& element : elements(meshView)) {
localView.bind(element);
localIndexSet.bind(localView);
auto const& localBasis = localView.tree().finiteElement().localBasis();
auto const& refElement = RefElements::general(element.type());
std::vector<Dune::FieldVector<double,1> > shapeValues;
std::size_t nVertices = element.subEntities(dim);
for (std::size_t i = 0; i < nVertices; ++i) {
auto const& v = element.template subEntity<dim>(i);
auto pos = refElement.position(i, dim);
localBasis.evaluateFunction(pos, shapeValues);
std::size_t idx = indexSet.index(v);
data[idx] = 0.0;
for (std::size_t j = 0; j < shapeValues.size(); ++j) {
const auto global_idx = localIndexSet.index(j);
data[idx] += dofvector[global_idx] * shapeValues[j];
}
}
}
}
#endif
private:
std
::
shared_ptr
<
GlobalBasis
>
basis_
;
TreePath
treePath_
;
...
...
dune/amdis/FiniteElementSpaces.hpp
View file @
289b2b9a
...
...
@@ -39,7 +39,7 @@ namespace AMDiS
using
Element
=
typename
GridView
::
template
Codim
<
0
>
::
Entity
;
public:
FiniteElementSpaces
(
std
::
shared_ptr
<
FeSpaces
>
const
&
feSpaces
)
explicit
FiniteElementSpaces
(
std
::
shared_ptr
<
FeSpaces
>
const
&
feSpaces
)
:
feSpaces_
(
feSpaces
)
,
localViews_
(
mapTuple
([](
auto
const
&
basis
)
{
return
basis
.
localView
();
},
*
feSpaces
))
,
localIndexSets_
(
mapTuple
([](
auto
const
&
basis
)
{
return
basis
.
localIndexSet
();
},
*
feSpaces
))
...
...
dune/amdis/Flag.hpp
View file @
289b2b9a
#pragma once
#include
<cstdint>
namespace
AMDiS
{
/** \ingroup Common
...
...
@@ -15,7 +17,7 @@ namespace AMDiS
constexpr
Flag
()
=
default
;
/// Constructs a Flag initialized by f
constexpr
Flag
(
const
unsigned
long
f
)
constexpr
Flag
(
const
std
::
uint64_t
f
)
:
flags
(
f
)
{}
...
...
@@ -52,7 +54,7 @@ namespace AMDiS
}
/// Set \ref flags
constexpr
void
setFlags
(
const
unsigned
long
f
)
constexpr
void
setFlags
(
const
std
::
uint64_t
f
)
{
flags
=
f
;
}
...
...
@@ -64,7 +66,7 @@ namespace AMDiS
}
/// Sets \ref flags to \ref flags | f
constexpr
void
setFlag
(
const
unsigned
long
f
)
constexpr
void
setFlag
(
const
std
::
uint64_t
f
)
{
flags
|=
f
;
}
...
...
@@ -76,7 +78,7 @@ namespace AMDiS
}
/// Sets \ref flags to \ref flags & ~f
constexpr
void
unsetFlag
(
const
unsigned
long
f
)
constexpr
void
unsetFlag
(
const
std
::
uint64_t
f
)
{
flags
&=
~
f
;
}
...
...
@@ -87,7 +89,7 @@ namespace AMDiS
flags
&=
~
f
.
flags
;
}
constexpr
unsigned
long
getFlags
()
const
constexpr
std
::
uint64_t
getFlags
()
const
{
return
flags
;
}
...
...
@@ -170,7 +172,7 @@ namespace AMDiS
protected:
/// Internal flag representation
unsigned
long
flags
=
0
;
std
::
uint64_t
flags
=
0
;
};
}
// end namespace AMDiS
dune/amdis/Initfile.cpp
View file @
289b2b9a
...
...
@@ -56,8 +56,8 @@ namespace AMDiS
test_exit
(
file_exists
(
fn
),
"init-file '"
,
fn
,
"' cannot be opened for reading"
);
using
namespace
boost
::
property_tree
;
json_parser
::
read_json
(
fn
,
pt
);
using
boost
::
property_tree
::
json_parser
::
read_json
;
read_json
(
fn
,
pt
);
}
...
...
dune/amdis/Initfile.hpp
View file @
289b2b9a
...
...
@@ -265,7 +265,7 @@ namespace AMDiS
/// save singlett-data to file with filename fn
static
void
save
(
std
::
string
/*fn*/
)
{
using
namespace
boost
::
property_tree
;
//
using boost::property_tree
::json_parser
;
// json_parser::write_jason(fn, singlett().pt);
}
...
...
dune/amdis/LocalAssembler.hpp
View file @
289b2b9a
...
...
@@ -23,7 +23,7 @@ namespace AMDiS
using
LocalGeometry
=
typename
Impl
::
Get
<
LocalContext
>::
Geometry
;
public:
LocalAssembler
(
int
degree
,
FirstOrderType
type
=
GRD_PHI
)
explicit
LocalAssembler
(
int
degree
,
FirstOrderType
type
=
GRD_PHI
)
:
degree_
(
degree
)
,
type_
(
type
)
{}
...
...
dune/amdis/Math.hpp
View file @
289b2b9a
#pragma once
#include
<algorithm>
#include
<cmath>
#include
<cstdint>
#include
<limits>
#include
<string>
#include
<type_traits>
#include
<cmath>
#include
<cfloat>
namespace
AMDiS
{
...
...
@@ -101,8 +103,12 @@ namespace AMDiS
s
=
""
;
}
template
<
class
T
>
constexpr
T
threshold
=
T
(
1.e-16
);
//Math::sqr(std::numeric_limits<T>::epsilon());
/// Calculates factorial of i
constexpr
unsigned
long
factorial
(
unsigned
long
i
)
constexpr
std
::
uint64_t
factorial
(
std
::
uint64_t
i
)
{
return
i
<=
1
?
1
:
i
*
factorial
(
i
-
1
);
}
...
...
@@ -128,8 +134,4 @@ namespace AMDiS
constexpr
double
m_sqrt2
=
1.41421356237309504880
;
constexpr
double
m_sqrt1_2
=
0.70710678118654752440
;
// tolerance for floating point comparison
#define DBL_TOL DBL_EPSILON
#define FLT_TOL FLT_EPSILON
}
// end namespace AMDiS
dune/amdis/Mesh.hpp
View file @
289b2b9a
#pragma once
#ifdef HAVE_CONFIG_H
#include
"config.h"
#endif
#include
<array>
#include
<memory>
#include
<string>
#include
<dune/common/filledarray.hh>
#include
<dune/common/fvector.hh>
...
...
dune/amdis/Operator.hpp
View file @
289b2b9a
...
...
@@ -134,10 +134,28 @@ namespace AMDiS
{
element_
=
&
element
;
geometry_
=
&
geometry
;
for
(
auto
*
operatorTerm
:
zeroOrder
)
operatorTerm
->
bind
(
element
);
for
(
auto
*
operatorTerm
:
firstOrderGrdPhi
)
operatorTerm
->
bind
(
element
);
for
(
auto
*
operatorTerm
:
firstOrderGrdPsi
)
operatorTerm
->
bind
(
element
);
for
(
auto
*
operatorTerm
:
secondOrder
)
operatorTerm
->
bind
(
element
);
}
void
unbind
()
{
for
(
auto
*
operatorTerm
:
zeroOrder
)
operatorTerm
->
unbind
();
for
(
auto
*
operatorTerm
:
firstOrderGrdPhi
)
operatorTerm
->
unbind
();
for
(
auto
*
operatorTerm
:
firstOrderGrdPsi
)
operatorTerm
->
unbind
();
for
(
auto
*
operatorTerm
:
secondOrder
)
operatorTerm
->
unbind
();
element_
=
nullptr
;
geometry_
=
nullptr
;
}
...
...
dune/amdis/Operator.inc.hpp
View file @
289b2b9a
#pragma once
#include
<algorithm>
#include
<list>
namespace
AMDiS
{
template
<
class
GridView
,
class
LocalContext
>
...
...
@@ -45,7 +48,7 @@ getQuadratureDegree(Dune::GeometryType t, LocalGeometry const& geometry, int ord
int
maxTermDegree
=
0
;
for
(
OperatorTermType
*
term
:
*
terms
)
maxTermDegree
=
std
::
max
(
maxTermDegree
,
term
->
getDegree
(
t
));
maxTermDegree
=
std
::
max
(
maxTermDegree
,
term
->
getDegree
());
int
degree
=
psiDegree_
+
phiDegree_
+
maxTermDegree
;
if
(
t
.
isSimplex
())
...
...
dune/amdis/OperatorTermBase.hpp
View file @
289b2b9a
#pragma once
#ifdef HAVE_CONFIG_H
#include
"config.h"
#endif
#include
<vector>
#include
<type_traits>
...
...
@@ -24,8 +20,12 @@ namespace AMDiS
static
constexpr
int
dow
=
LocalContext
::
Geometry
::
coorddimension
;
using
QuadratureRule
=
QuadratureRuleFactory_t
<
LocalContext
,
double
,
dim
>
;
using
Element
=
typename
Impl
::
Get
<
LocalContext
>::
Entity
;
public:
virtual
void
bind
(
Element
const
&
element
)
=
0
;
virtual
void
unbind
()
=
0
;
// initialize operator-term on the current element
virtual
void
init
(
LocalContext
const
&
element
,
QuadratureRule
const
&
points
)
=
0
;
...
...
@@ -62,7 +62,7 @@ namespace AMDiS
// return the polynomial degree, necessary to intergrate the operator-term
// on an element accurately
virtual
int
getDegree
(
Dune
::
GeometryType
const
&
t
)
const
=
0
;
virtual
int
getDegree
()
const
=
0
;
};
...
...
@@ -83,16 +83,24 @@ namespace AMDiS
{
using
Super
=
OperatorTerm
<
LocalContext
>
;
using
QuadratureRule
=
typename
Super
::
QuadratureRule
;
using
Element
=
typename
Super
::
Element
;
static
constexpr
int
dow
=
Super
::
dow
;
public:
/// Constructor, stores a copy of the expression `expr` and of the traits `traits`.
GenericOperatorTerm
(
Expression
const
&
expr
,
Traits
traits
=
{})
explicit
GenericOperatorTerm
(
Expression
const
&
expr
,
Traits
traits
=
{})
:
expr
(
expr
)
,
traits
(
traits
)
{}
virtual
void
bind
(
Element
const
&
element
)
final
{
expr
.
bind
(
element
);
}
virtual
void
unbind
()
final
{}
/// \brief Initialize the expression on the current (inside-)element, in the quadrature points.
/**
* This initialization does not only bind the operator-term to the inside-element,
...
...
@@ -102,21 +110,21 @@ namespace AMDiS
* Note: For entities the expression is bound to the `element` directly, but
* for intersections, the expression is bound to inside-entity of the element.
**/
virtual
void
init
(
LocalContext
const
&
element
,
QuadratureRule
const
&
points
)
override
virtual
void
init
(
LocalContext
const
&
element
,
QuadratureRule
const
&
points
)
final
{
expr
.
init
(
get_entity
(
element
),
points
);
}
/// Calculates `expr[iq] * test * trial`
virtual
double
eval
(
std
::
size_t
iq
,
Dune
::
FieldVector
<
double
,
1
>
const
&
test
)
const
override
Dune
::
FieldVector
<
double
,
1
>
const
&
test
)
const
final
{
return
Evaluate
::
zot
(
_cat
{},
traits
,
expr
[
iq
],
test
);
}
/// Calculates `expr[iq] * test * grad(trial)`, maybe partial derivative only.
virtual
double
eval
(
std
::
size_t
iq
,
Dune
::
FieldVector
<
double
,
dow
>
const
&
grad_test
)
const
override
Dune
::
FieldVector
<
double
,
dow
>
const
&
grad_test
)
const
final
{
return
Evaluate
::
fot
(
_cat
{},
traits
,
expr
[
iq
],
grad_test
);
}
...
...
@@ -125,7 +133,7 @@ namespace AMDiS
/// Calculates `expr[iq] * test * trial`
virtual
double
eval
(
std
::
size_t
iq
,
Dune
::
FieldVector
<
double
,
1
>
const
&
test
,
Dune
::
FieldVector
<
double
,
1
>
const
trial
)
const
override
Dune
::
FieldVector
<
double
,
1
>
const
trial
)
const
final
{
return
Evaluate
::
zot
(
_cat
{},
traits
,
expr
[
iq
],
test
,
trial
);
}
...
...
@@ -133,7 +141,7 @@ namespace AMDiS
/// Calculates `expr[iq] * test * grad(trial)`, maybe partial derivative only.
virtual
double
eval
(
std
::
size_t
iq
,
Dune
::
FieldVector
<
double
,
1
>
const
&
test
,
Dune
::
FieldVector
<
double
,
dow
>
const
&
grad_trial
)
const
override
Dune
::
FieldVector
<
double
,
dow
>
const
&
grad_trial
)
const
final
{
return
Evaluate
::
fot
(
_cat
{},
traits
,
expr
[
iq
],
grad_trial
,
test
);
}
...
...
@@ -141,7 +149,7 @@ namespace AMDiS
/// Calculates `expr[iq] * grad(test) * trial`, maybe partial derivative only.
virtual
double
eval
(
std
::
size_t
iq
,
Dune
::
FieldVector
<
double
,
dow
>
const
&
grad_test
,
Dune
::
FieldVector
<
double
,
1
>
const
trial
)
const
override
Dune
::
FieldVector
<
double
,
1
>
const
trial
)
const
final
{
return
Evaluate
::
fot
(
_cat
{},
traits
,
expr
[
iq
],
grad_test
,
trial
);
}
...
...
@@ -149,15 +157,15 @@ namespace AMDiS
/// Calculates `expr[iq] * grad(test) * grad(trial)`, maybe partial derivatives only.
virtual
double
eval
(
std
::
size_t
iq
,
Dune
::
FieldVector
<
double
,
dow
>
const
&
grad_test
,
Dune
::
FieldVector
<
double
,
dow
>
const
&
grad_trial
)
const
override
Dune
::
FieldVector
<
double
,
dow
>
const
&
grad_trial
)
const
final
{
return
Evaluate
::
sot
(
_cat
{},
traits
,
expr
[
iq
],
grad_test
,
grad_trial
);
}
/// Returns the polynomial degree of the expression
virtual
int
getDegree
(
Dune
::
GeometryType
const
&
t
)
const
override
virtual
int
getDegree
(
)
const
final
{
return
expr
.
getDegree
(
t
);
return
expr
.
getDegree
();
}
private:
...
...
dune/amdis/ProblemInstat.hpp
View file @
289b2b9a
#pragma once
#include
<string>
#include
<dune/amdis/ProblemInstatBase.hpp>
#include
<dune/amdis/ProblemStat.hpp>
#include
<dune/amdis/common/Utility.hpp>
...
...
dune/amdis/ProblemInstat.inc.hpp
View file @
289b2b9a
#pragma once
#include
"ProblemInstat.hpp"
#include
<string>
#include
<vector>
#include
<dune/amdis/AdaptInfo.hpp>
namespace
AMDiS
{
...
...
dune/amdis/ProblemStat.hpp
View file @
289b2b9a
#pragma once
#ifdef HAVE_CONFIG_H
#include
"config.h"
#endif
#include
<tuple>
#include
<string>
#include
<memory>
#include
<list>
#include
<map>
#include
<memory>
#include
<string>
#include
<tuple>
#include
<utility>
#include
<vector>
#include
<dune/common/fvector.hh>
#include
<dune/common/fmatrix.hh>
...
...
@@ -83,7 +81,7 @@ namespace AMDiS
* Parameters read by ProblemStat, with name 'PROB'
* PROB->names: \ref componentNames
**/
ProblemStat
(
std
::
string
name
)
explicit
ProblemStat
(
std
::
string
name
)
:
StandardProblemIteration
(
dynamic_cast
<
ProblemStatBase
&>
(
*
this
))
,
name
(
name
)
{
...
...
@@ -94,10 +92,10 @@ namespace AMDiS
/// Constructor taking additionally a reference to a mesh that is used
/// instead of the default created mesh, \ref ProblemStat
ProblemStat
(
std
::
string
name
,
Grid
&
grid
)
ProblemStat
(
std
::
string
name
,
Grid
*
grid
Ptr
)
:
ProblemStat
(
name
)
{
this
->
grid
=
std
::
shared_ptr
<
Grid
>
(
&
grid
,
optional_delete
(
false
));
this
->
grid
=
std
::
shared_ptr
<
Grid
>
(
grid
Ptr
,
optional_delete
(
false
));
componentGrids
.
resize
(
nComponents
,
this
->
grid
.
get
());
gridName
=
""
;
...
...
dune/amdis/ProblemStat.inc.hpp
View file @
289b2b9a
#pragma once
#include
<map>
#include
<string>
#include
<utility>
#include
<dune/typetree/childextraction.hh>
#include
<dune/amdis/AdaptInfo.hpp>
...
...
dune/amdis/StandardProblemIteration.hpp
View file @
289b2b9a
...
...
@@ -17,7 +17,7 @@ namespace AMDiS
{
public:
/// constructor
StandardProblemIteration
(
ProblemStatBase
&
prob
)
explicit
StandardProblemIteration
(
ProblemStatBase
&
prob
)
:
problem
(
prob
)
{}
...
...
Prev
1
2
3
Next
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment