Commit 9a682f9d authored by Thomas Witkowski's avatar Thomas Witkowski

Modified some files to make use of const FiniteElemSpace pointers, where this is possible.

parent 0d0838bd
......@@ -80,22 +80,18 @@ namespace AMDiS {
/// Destructor.
virtual ~BoundaryCondition() {}
/** \brief
* Adds the local boundary condition for elInfo to object.
* The dofIndices and localBound as well as nBasFcts are determined by
* the calling BoundaryManager.
*/
/// Adds the local boundary condition for elInfo to object.
/// The dofIndices and localBound as well as nBasFcts are determined by
// the calling BoundaryManager.
virtual void fillBoundaryCondition(DOFMatrix *matrix,
ElInfo *elInfo,
const DegreeOfFreedom *dofIndices,
const BoundaryType *localBound,
int nBasFcts) {}
/** \brief
* Adds the local boundary condition for elInfo to vector.
* The dofIndices and localBound as well as nBasFcts are determined by
* the calling BoundaryManager.
*/
/// Adds the local boundary condition for elInfo to vector.
/// The dofIndices and localBound as well as nBasFcts are determined by
/// the calling BoundaryManager.
virtual void fillBoundaryCondition(DOFVectorBase<double> *vector,
ElInfo *elInfo,
const DegreeOfFreedom *dofIndices,
......@@ -110,10 +106,8 @@ namespace AMDiS {
return 0.0;
}
/** \brief
* Returns whether the condition must be treated as Dirichlet condition
* while assemblage.
*/
/// Returns whether the condition must be treated as Dirichlet condition
/// while assemblage.
virtual bool isDirichlet()
{
return false;
......@@ -125,25 +119,21 @@ namespace AMDiS {
return false;
}
/** \brief
* In some situations it may be required to set Dirichlet boundary conditions,
* but not to apply them to the matrix. This is for example the case, if the
* boundary condition is set to a couple matrix. Then, the boundary conditions
* must be applied to the couple matrix, but they are set to all matrices in this
* row (to ensure that there are no other element entries in the Dirichlet boundary
* condition rows).
*/
/// In some situations it may be required to set Dirichlet boundary
/// conditions, but not to apply them to the matrix. This is for example the
/// case, if the boundary condition is set to a couple matrix. Then, the
/// boundary conditions must be applied to the couple matrix, but they are
/// set to all matrices in this row (to ensure that there are no other
/// element entries in the Dirichlet boundary condition rows).
virtual bool applyBoundaryCondition()
{
return true;
}
protected:
/** \brief
* Speciefies for which parts of the boundary the condition holds.
* This id corresponds to the boundary numbers spcified in the
* macro file.
*/
/// Speciefies for which parts of the boundary the condition holds.
/// This id corresponds to the boundary numbers spcified in the
/// macro file.
BoundaryType boundaryType;
/// FiniteElemSpace for this BoundaryCondition.
......
......@@ -38,7 +38,7 @@ namespace AMDiS {
status(0)
{}
void setFeSpace(FiniteElemSpace *row, FiniteElemSpace *col = NULL)
void setFeSpace(const FiniteElemSpace *row, const FiniteElemSpace *col = NULL)
{
rowFeSpace = row;
colFeSpace = col;
......@@ -66,12 +66,12 @@ namespace AMDiS {
return auxFeSpaces.size();
}
FiniteElemSpace *getRowFeSpace()
const FiniteElemSpace *getRowFeSpace()
{
return rowFeSpace;
}
FiniteElemSpace *getColFeSpace()
const FiniteElemSpace *getColFeSpace()
{
return colFeSpace;
}
......@@ -94,9 +94,9 @@ namespace AMDiS {
}
protected:
FiniteElemSpace *rowFeSpace;
const FiniteElemSpace *rowFeSpace;
FiniteElemSpace *colFeSpace;
const FiniteElemSpace *colFeSpace;
std::set<const FiniteElemSpace*> auxFeSpaces;
......
......@@ -20,8 +20,8 @@ namespace AMDiS {
DirichletBC::DirichletBC(BoundaryType type,
AbstractFunction<double, WorldVector<double> > *fct,
FiniteElemSpace *rowFeSpace,
FiniteElemSpace *colFeSpace,
const FiniteElemSpace *rowFeSpace,
const FiniteElemSpace *colFeSpace,
bool apply)
: BoundaryCondition(type, rowFeSpace, colFeSpace),
f(fct),
......
......@@ -45,8 +45,8 @@ namespace AMDiS {
/// Constructor.
DirichletBC(BoundaryType type,
AbstractFunction<double, WorldVector<double> > *fct,
FiniteElemSpace *rowFeSpace,
FiniteElemSpace *colFeSpace = NULL,
const FiniteElemSpace *rowFeSpace,
const FiniteElemSpace *colFeSpace = NULL,
bool apply = true);
/// Constructor.
......
......@@ -16,9 +16,9 @@
namespace AMDiS {
vector<const FiniteElemSpace*> getFeSpaces(Matrix<DOFMatrix*> &mat)
vector<const FiniteElemSpace*> getComponentFeSpaces(Matrix<DOFMatrix*> &mat)
{
FUNCNAME("getFeSpaces()");
FUNCNAME("getComponentFeSpaces()");
int nComponents = mat.getNumRows();
vector<const FiniteElemSpace*> result(nComponents);
......
......@@ -521,7 +521,7 @@ namespace AMDiS {
/// Returns a vector with the FE spaces of each row in the matrix. Thus, the
/// resulting vector may contain the same FE space multiple times.
vector<const FiniteElemSpace*> getFeSpaces(Matrix<DOFMatrix*> &mat);
vector<const FiniteElemSpace*> getComponentFeSpaces(Matrix<DOFMatrix*> &mat);
}
#endif // AMDIS_MATRIXVECTOR_H
......@@ -97,7 +97,7 @@ namespace AMDiS {
}
PeriodicBC::PeriodicBC(BoundaryType type, FiniteElemSpace *rowSpace)
PeriodicBC::PeriodicBC(BoundaryType type, const FiniteElemSpace *rowSpace)
: BoundaryCondition(type, rowSpace, NULL),
masterMatrix(NULL)
{
......
......@@ -88,7 +88,7 @@ namespace AMDiS {
{
public:
/// Constructor.
PeriodicBC(BoundaryType type, FiniteElemSpace *rowFeSpace);
PeriodicBC(BoundaryType type, const FiniteElemSpace *rowFeSpace);
~PeriodicBC();
......
......@@ -1586,9 +1586,7 @@ namespace AMDiS {
FUNCNAME("ProblemStat::addPeriodicBC()");
boundaryConditionSet = true;
FiniteElemSpace *feSpace = componentSpaces[row];
PeriodicBC *periodic = new PeriodicBC(type, feSpace);
PeriodicBC *periodic = new PeriodicBC(type, componentSpaces[row]);
if (systemMatrix && (*systemMatrix)[row][col])
(*systemMatrix)[row][col]->getBoundaryManager()->addBoundaryCondition(periodic);
......@@ -1628,7 +1626,7 @@ namespace AMDiS {
}
void ProblemStatSeq::assembleOnOneMesh(FiniteElemSpace *feSpace,
void ProblemStatSeq::assembleOnOneMesh(const FiniteElemSpace *feSpace,
Flag assembleFlag,
DOFMatrix *matrix,
DOFVector<double> *vector)
......
......@@ -256,7 +256,7 @@ namespace AMDiS {
/// This function assembles a DOFMatrix and a DOFVector for the case,
/// the meshes from row and col FE-space are equal.
void assembleOnOneMesh(FiniteElemSpace *feSpace,
void assembleOnOneMesh(const FiniteElemSpace *feSpace,
Flag assembleFlag,
DOFMatrix *matrix, DOFVector<double> *vector);
......@@ -321,7 +321,7 @@ namespace AMDiS {
}
/// Returns \ref feSpace_.
inline FiniteElemSpace* getFeSpace(int comp = 0)
inline const FiniteElemSpace* getFeSpace(int comp = 0)
{
FUNCNAME("ProblemStatSeq::getFeSpace()");
TEST_EXIT(comp < static_cast<int>(componentSpaces.size()) && comp >= 0)
......@@ -330,13 +330,13 @@ namespace AMDiS {
}
/// Returns \ref feSpaces.
inline vector<FiniteElemSpace*> getFeSpaces()
inline vector<const FiniteElemSpace*> getFeSpaces()
{
return feSpaces;
}
/// Returns \ref componentSpaces;
inline vector<FiniteElemSpace*> getComponentFeSpaces()
inline vector<const FiniteElemSpace*> getComponentFeSpaces()
{
return componentSpaces;
}
......@@ -428,12 +428,12 @@ namespace AMDiS {
}
/// Sets the FE space for the given component.
inline void setFeSpace(FiniteElemSpace *feSpace, int comp = 0)
inline void setFeSpace(const FiniteElemSpace *feSpace, int comp = 0)
{
feSpaces[comp] = feSpace;
}
void setComponentSpace(int comp, FiniteElemSpace *feSpace)
void setComponentSpace(int comp, const FiniteElemSpace *feSpace)
{
if (static_cast<int>(componentSpaces.size()) < nComponents)
componentSpaces.resize(nComponents);
......@@ -565,13 +565,13 @@ namespace AMDiS {
int nMeshes;
/// FE spaces of this problem.
vector<FiniteElemSpace*> feSpaces;
vector<const FiniteElemSpace*> feSpaces;
/// Meshes of this problem.
vector<Mesh*> meshes;
/// Pointer to the fe spaces for the different problem components
vector<FiniteElemSpace*> componentSpaces;
vector<const FiniteElemSpace*> componentSpaces;
/// Pointer to the meshes for the different problem components
vector<Mesh*> componentMeshes;
......
......@@ -24,8 +24,8 @@ namespace AMDiS {
RobinBC::RobinBC(BoundaryType type,
AbstractFunction<double, WorldVector<double> > *j,
AbstractFunction<double, WorldVector<double> > *alpha,
FiniteElemSpace *rowFeSpace_,
FiniteElemSpace *colFeSpace_)
const FiniteElemSpace *rowFeSpace_,
const FiniteElemSpace *colFeSpace_)
: BoundaryCondition(type, rowFeSpace_, colFeSpace_),
neumannOperators(NULL),
robinOperators(NULL)
......@@ -75,8 +75,8 @@ namespace AMDiS {
RobinBC::RobinBC(BoundaryType type,
DOFVectorBase<double> *j,
DOFVectorBase<double> *alpha,
FiniteElemSpace *rowFeSpace_,
FiniteElemSpace *colFeSpace_)
const FiniteElemSpace *rowFeSpace_,
const FiniteElemSpace *colFeSpace_)
: BoundaryCondition(type, rowFeSpace_, colFeSpace_),
neumannOperators(NULL),
robinOperators(NULL)
......@@ -125,8 +125,8 @@ namespace AMDiS {
RobinBC::RobinBC(BoundaryType type,
Operator* jOp, Operator* alphaOp,
FiniteElemSpace *rowFeSpace_,
FiniteElemSpace *colFeSpace_)
const FiniteElemSpace *rowFeSpace_,
const FiniteElemSpace *colFeSpace_)
: BoundaryCondition(type, rowFeSpace_, colFeSpace_),
neumannOperators(NULL),
robinOperators(NULL)
......
......@@ -45,21 +45,21 @@ namespace AMDiS {
RobinBC(BoundaryType type,
AbstractFunction<double, WorldVector<double> > *j,
AbstractFunction<double, WorldVector<double> > *alpha,
FiniteElemSpace *rowFeSpace,
FiniteElemSpace *colFeSpace = NULL);
const FiniteElemSpace *rowFeSpace,
const FiniteElemSpace *colFeSpace = NULL);
/// Constructor. \f$ j \f$ and \f$ alpha \f$ are given as DOFVectors.
RobinBC(BoundaryType type,
DOFVectorBase<double> *j,
DOFVectorBase<double> *alpha,
FiniteElemSpace *rowFeSpace,
FiniteElemSpace *colFeSpace = NULL);
const FiniteElemSpace *rowFeSpace,
const FiniteElemSpace *colFeSpace = NULL);
/// Constructor. \f$ j \f$ and \f$ alpha \f$ are given as Operator objects.
RobinBC(BoundaryType type,
Operator* jOp, Operator* alphaOp,
FiniteElemSpace *rowFeSpace,
FiniteElemSpace *colFeSpace = NULL);
const FiniteElemSpace *rowFeSpace,
const FiniteElemSpace *colFeSpace = NULL);
/// Implements BoundaryCondition::fillBoundaryCondition();
virtual void fillBoundaryCondition(DOFMatrix* matrix,
......@@ -96,15 +96,15 @@ namespace AMDiS {
public:
NeumannBC(BoundaryType type,
AbstractFunction<double, WorldVector<double> > *j,
FiniteElemSpace *rowFeSpace,
FiniteElemSpace *colFeSpace = NULL)
const FiniteElemSpace *rowFeSpace,
const FiniteElemSpace *colFeSpace = NULL)
: RobinBC(type, j, NULL, rowFeSpace, colFeSpace)
{}
NeumannBC(BoundaryType type,
DOFVectorBase<double> *j,
FiniteElemSpace *rowFeSpace,
FiniteElemSpace *colFeSpace = NULL)
const FiniteElemSpace *rowFeSpace,
const FiniteElemSpace *colFeSpace = NULL)
: RobinBC(type, j, NULL, rowFeSpace, colFeSpace)
{}
};
......
......@@ -17,7 +17,7 @@ namespace AMDiS {
void SystemVector::serialize(std::ostream &out)
{
int size = vectors.getSize();
int size = static_cast<int>(vectors.size());
SerUtil::serialize(out, size);
for (int i = 0; i < size; i++)
vectors[i]->serialize(out);
......@@ -26,7 +26,7 @@ namespace AMDiS {
void SystemVector::deserialize(std::istream &in)
{
int size, oldSize = vectors.getSize();
int size, oldSize = static_cast<int>(vectors.size());
SerUtil::deserialize(in, size);
vectors.resize(size);
for (int i = oldSize; i < size; i++)
......@@ -35,4 +35,14 @@ namespace AMDiS {
vectors[i]->deserialize(in);
}
vector<const FiniteElemSpace*> SystemVector::getComponentFeSpaces() const
{
vector<const FiniteElemSpace*> result(vectors.size());
for (unsigned int i = 0; i < vectors.size(); i++)
result[i] = vectors[i]->getFeSpace();
return result;
}
}
......@@ -36,57 +36,50 @@ namespace AMDiS {
public:
/// Constructor.
SystemVector(std::string name_,
std::vector<FiniteElemSpace*> feSpace_,
std::vector<const FiniteElemSpace*> feSpace_,
int size)
: name(name_),
feSpace(feSpace_),
vectors(size)
{
vectors.set(NULL);
}
vectors(size, NULL)
{}
/// Copy Constructor.
SystemVector(const SystemVector& rhs)
: name(rhs.getName()),
feSpace(rhs.getFeSpaces()),
vectors(rhs.getNumVectors())
vectors(rhs.getNumVectors(), NULL)
{
for (int i = 0; i < vectors.getSize(); i++)
for (unsigned int i = 0; i < vectors.size(); i++)
vectors[i] = new DOFVector<double>(*rhs.getDOFVector(i));
}
~SystemVector()
{
for (int i = 0; i < vectors.getSize(); i++)
for (unsigned int i = 0; i < vectors.size(); i++)
delete vectors[i];
}
void createNewDOFVectors(std::string name)
{
for (int i = 0; i < vectors.getSize(); i++)
vectors[i] = new DOFVector<double>(feSpace[i], "tmp");
}
/// Sets \ref vectors[index] = vec.
inline void setDOFVector(int index, DOFVector<double> *vec)
{
TEST_EXIT_DBG(index < vectors.getSize())("invalid index\n");
TEST_EXIT_DBG(index < static_cast<int>(vectors.size()))
("Invalid index %d!\n", index);
vectors[index] = vec;
}
/// Returns \ref vectors[index].
inline DOFVector<double> *getDOFVector(int index)
{
TEST_EXIT_DBG(index < vectors.getSize())("invalid index\n");
TEST_EXIT_DBG(index < static_cast<int>(vectors.size()))
("Invalid index %d!\n", index);
return vectors[index];
}
/// Returns \ref vectors[index].
inline const DOFVector<double> *getDOFVector(int index) const
{
TEST_EXIT_DBG(index < vectors.getSize())("invalid index\n");
TEST_EXIT_DBG(index < static_cast<int>(vectors.size()))
("Invalid index %d!\n", index);
return vectors[index];
}
......@@ -99,8 +92,7 @@ namespace AMDiS {
inline int getUsedSize() const
{
int totalSize = 0;
int size = vectors.getSize();
for (int i = 0; i < size; i++)
for (unsigned int i = 0; i < vectors.size(); i++)
totalSize += vectors[i]->getUsedSize();
return totalSize;
}
......@@ -108,32 +100,32 @@ namespace AMDiS {
/// Returns number of contained vectors.
inline int getNumVectors() const
{
return vectors.getSize();
return static_cast<int>(vectors.size());
}
inline int getSize() const
{
return vectors.getSize();
return static_cast<int>(vectors.size());
}
/// Returns the fe space for a given component.
inline FiniteElemSpace *getFeSpace(int i) const
inline const FiniteElemSpace *getFeSpace(int i) const
{
return feSpace[i];
}
/// Returns the fe spaces for all components.
inline std::vector<FiniteElemSpace*> getFeSpaces() const
inline std::vector<const FiniteElemSpace*> getFeSpaces() const
{
return feSpace;
}
/** \brief
* Here the system vector is interpreted as one large vector. The given
* is used as a global index which indicates a local vector number and
* a local index on this vector. The operator returns this local vector
* at the local index.
*/
vector<const FiniteElemSpace*> getComponentFeSpaces() const;
/// Here the system vector is interpreted as one large vector. The given
/// is used as a global index which indicates a local vector number and
/// a local index on this vector. The operator returns this local vector
/// at the local index.
inline double& operator[](int index)
{
int localIndex = index;
......@@ -162,22 +154,20 @@ namespace AMDiS {
/// Sets all entries in all vectors to value.
inline void set(double value)
{
int size = vectors.getSize();
for (int i = 0; i < size; i++)
for (unsigned int i = 0; i < vectors.size(); i++)
vectors[i]->set(value);
}
inline void setCoarsenOperation(CoarsenOperation op)
{
for (int i = 0; i < static_cast<int>(vectors.getSize()); i++)
for (int i = 0; i < static_cast<int>(vectors.size()); i++)
vectors[i]->setCoarsenOperation(op);
}
/// Sets all entries in all vectors to value.
inline SystemVector& operator=(double value)
{
int size = vectors.getSize();
for (int i = 0; i < size; i++)
for (int i = 0; i < static_cast<int>(vectors.size()); i++)
(*(vectors[i])) = value;
return *this;
}
......@@ -185,10 +175,11 @@ namespace AMDiS {
/// Assignement operator.
inline SystemVector& operator=(const SystemVector& rhs)
{
TEST_EXIT_DBG(rhs.vectors.getSize() == vectors.getSize())("invalied sizes\n");
int size = vectors.getSize();
for (int i = 0; i < size; i++)
TEST_EXIT_DBG(rhs.vectors.size() == vectors.size())("Invalied sizes!\n");
for (int i = 0; i < static_cast<int>(vectors.size()); i++)
(*(vectors[i])) = (*(rhs.getDOFVector(i)));
return *this;
}
......@@ -198,16 +189,15 @@ namespace AMDiS {
void copy(const SystemVector& rhs)
{
int size = vectors.getSize();
TEST_EXIT_DBG(size == rhs.getNumVectors())("invalid sizes\n");
int size = static_cast<int>(vectors.size());
TEST_EXIT_DBG(size == rhs.getNumVectors())("Invalid sizes!\n");
for (int i = 0; i < size; i++)
vectors[i]->copy(*(const_cast<SystemVector&>(rhs).getDOFVector(i)));
}
void interpol(std::vector<AbstractFunction<double, WorldVector<double> >*> *f)
{
int size = vectors.getSize();
for (int i = 0; i < size; i++)
for (unsigned int i = 0; i < vectors.size(); i++)
vectors[i]->interpol((*f)[i]);
}
......@@ -219,15 +209,14 @@ namespace AMDiS {
void print()
{
int size = vectors.getSize();
for (int i = 0; i < size; i++)
for (unsigned int i = 0; i < vectors.size(); i++)
vectors[i]->print();
}
int calcMemoryUsage()
{
int result = 0;
for (int i = 0; i < static_cast<int>(vectors.getSize()); i++)
for (unsigned int i = 0; i < vectors.size(); i++)
result += vectors[i]->calcMemoryUsage();
result += sizeof(SystemVector);
......@@ -241,10 +230,10 @@ namespace AMDiS {
std::string name;
/// Finite element space.
std::vector<FiniteElemSpace*> feSpace;
std::vector<const FiniteElemSpace*> feSpace;
/// Local dof vectors.
Vector<DOFVector<double>*> vectors;
std::vector<DOFVector<double>*> vectors;
};
......
......@@ -261,7 +261,7 @@ namespace AMDiS {
mpiCommGlobal.Allreduce(&sendValue, &recvAllValues, 1, MPI_INT, MPI_SUM);
if (recvAllValues != 0 || alwaysCreateNnzStructure) {
vector<const FiniteElemSpace*> feSpaces = getFeSpaces(seqMat);
vector<const FiniteElemSpace*> feSpaces = getComponentFeSpaces(seqMat);
interiorMap->setComputeMatIndex(!localMatrix);
interiorMap->update(feSpaces);
......
......@@ -110,40 +110,4 @@ namespace AMDiS {
VecScatterDestroy(&scatter);
}
vector<const FiniteElemSpace*> PetscSolver::getFeSpaces(SystemVector *vec)
{
FUNCNAME("PetscSolver::getFeSpaces()");
int nComponents = vec->getSize();
vector<const FiniteElemSpace*> result(nComponents);
for (int i = 0; i < nComponents; i++)
result[i] = vec->getFeSpace(i);
#if (DEBUG != 0)
// === In debug mode, we test if all FE spaces of the matrix are also ===
// === considered by the mesh distributor. ===
checkFeSpaces(result);
#endif
return result;
}
void PetscSolver::checkFeSpaces(vector<const FiniteElemSpace*>& feSpaces)
{
FUNCNAME("PetscSolver::checkFeSpaces()");
for (unsigned int i = 0; i < feSpaces.size(); i++) {
bool found = false;
for (unsigned int j = 0; j < meshDistributor->getFeSpaces().size(); j++)
if (feSpaces[i] == meshDistributor->getFeSpace(j)) {
found = true;
break;
}
TEST_EXIT(found)("FE spaces not found in mesh distributor!\n");
}
}