Commit ade6bd99 authored by Praetorius, Simon's avatar Praetorius, Simon

correction of ProblemStat, i.e. an intermediate layer for standardProblemIteration added

parent 72990c0d
......@@ -360,43 +360,9 @@ namespace AMDiS {
using super::getName;
protected:
// /// Name of this problem.
// std::string name;
//
// /// Number of problem components
// int nComponents;
/// unqiue mesh-dimension for all problems
int dim;
// /** \brief
// * Number of problem meshes. If all components are defined on the same mesh,
// * this number is 1. Otherwise, this variable is the number of different meshes
// * within the problem.
// */
// int nMeshes;
// /// FE spaces of this problem.
// std::vector<FiniteElemSpace*> feSpaces;
//
// /// Meshes of this problem.
// std::vector<Mesh*> meshes;
// /** \brief
// * All actions of mesh refinement are performed by refinementManager.
// * If new refinement algorithms should be realized, one has to override
// * RefinementManager and give one instance of it to AdaptStationary.
// */
// RefinementManager *refinementManager;
//
// /** \brief
// * All actions of mesh coarsening are performed by coarseningManager.
// * If new coarsening algorithms should be realized, one has to override
// * CoarseningManager and give one instance of it to AdaptStationary.
// */
// CoarseningManager *coarseningManager;
std::vector<ProblemStatType*> problems;
};
......
......@@ -56,8 +56,7 @@ namespace AMDiS {
ProblemStatSeq::ProblemStatSeq(string nameStr,
ProblemIterationInterface *problemIteration)
: StandardProblemIteration(this),
name(nameStr),
: name(nameStr),
nComponents(-1),
nAddComponents(0),
nMeshes(0),
......@@ -826,18 +825,6 @@ namespace AMDiS {
}
Flag ProblemStatSeq::oneIteration(AdaptInfo *adaptInfo, Flag toDo)
{
for (int i = 0; i < nComponents; i++)
if (adaptInfo->spaceToleranceReached(i))
adaptInfo->allowRefinement(false, i);
else
adaptInfo->allowRefinement(true, i);
return StandardProblemIteration::oneIteration(adaptInfo, toDo);
}
void ProblemStatSeq::buildAfterCoarsen(AdaptInfo *adaptInfo, Flag flag,
bool asmMatrix, bool asmVector)
{
......
......@@ -55,8 +55,7 @@ namespace AMDiS {
* This class defines the stationary problem definition in sequential
* computations. For parallel computations, see \ref ParallelProblemStatBase.
**/
class ProblemStatSeq : public ProblemStatBase,
public StandardProblemIteration
class ProblemStatSeq : public ProblemStatBase
{
protected:
// Defines a mapping type from dof indices to world coordinates.
......@@ -695,7 +694,29 @@ namespace AMDiS {
};
#ifndef HAVE_PARALLEL_DOMAIN_AMDIS
typedef ProblemStatSeq ProblemStat;
struct ProblemStat : public ProblemStatSeq,
public StandardProblemIteration
{
typedef ProblemStatSeq super;
using super::getName;
ProblemStat(std::string nameStr,
ProblemIterationInterface *problemIteration = NULL)
: super(nameStr, problemIteration),
StandardProblemIteration(this)
{ }
Flag oneIteration(AdaptInfo *adaptInfo, Flag toDo)
{
for (int i = 0; i < getNumComponents(); i++)
if (adaptInfo->spaceToleranceReached(i))
adaptInfo->allowRefinement(false, i);
else
adaptInfo->allowRefinement(true, i);
return StandardProblemIteration::oneIteration(adaptInfo, toDo);
}
};
#endif
}
......
......@@ -77,7 +77,29 @@ namespace AMDiS
} // end namespace Parallel
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
typedef Parallel::ParallelProblemStat ProblemStat;
struct ProblemStat : public Parallel::ParallelProblemStat,
public StandardProblemIteration
{
typedef Parallel::ParallelProblemStat super;
using super::getName;
ProblemStat(std::string nameStr,
ProblemIterationInterface *problemIteration = NULL)
: super(nameStr, problemIteration),
StandardProblemIteration(this)
{ }
Flag oneIteration(AdaptInfo *adaptInfo, Flag toDo)
{
for (int i = 0; i < getNumComponents(); i++)
if (adaptInfo->spaceToleranceReached(i))
adaptInfo->allowRefinement(false, i);
else
adaptInfo->allowRefinement(true, i);
return StandardProblemIteration::oneIteration(adaptInfo, toDo);
}
};
#endif
} // end namespace AMDiS
......
This diff is collapsed.
......@@ -13,14 +13,14 @@
#endif
#include "Expressions.h"
#include "MGProblemStat.h"
#include "ProblemStat.h"
using namespace AMDiS;
class PfcPC : public base_problems::detail::PhaseFieldCrystal<MGProblemStat>
class PfcPC : public base_problems::detail::PhaseFieldCrystal<ProblemStat>
{
public:
typedef base_problems::detail::PhaseFieldCrystal<MGProblemStat> super;
typedef base_problems::detail::PhaseFieldCrystal<ProblemStat> super;
public:
PfcPC(std::string name) : super(name) { }
......
#pragma once
#include <AMDiS.h>
#include <SignedDistFunctors.h>
#include <kdtree_nanoflann_dof.h>
using namespace AMDiS;
inline void getRandomPositions(size_t N, double xmin, double xmax, double ymin, double ymax, std::vector<WorldVector<double> >& pos)
{
WorldVector<double> x;
pos.clear();
for (size_t i = 0; i < N; i++) {
bool nearParticle = true;
int k = 0;
AMDiS::Random rnd0((xmin+xmax)/2.0, (xmax-xmin)/2.0);
AMDiS::Random rnd1((ymin+ymax)/2.0, (ymax-ymin)/2.0);
while (nearParticle || k < 20) {
x[0] = rnd0(x);
x[1] = rnd1(x);
nearParticle = false;
for (size_t j = 0; j < pos.size(); j++) {
nearParticle = nearParticle || AMDiS::norm(pos[j]-x) < 4.0*M_PI/sqrt(3.0) || x[0] > xmax || x[0] < xmin || x[1] > ymax || x[1] < ymin;
if (nearParticle)
break;
}
k++;
}
pos.push_back(x);
}
}
inline void getRegularPositions(double xmin, double xmax, double ymin, double ymax, double d, std::vector<WorldVector<double> >& pos)
{
WorldVector<double> p;
pos.clear();
for (double x = xmin; x <= xmax; x+= d) {
for (double y = ymin; y <= ymax; y+= d) {
p[0] = x;
p[1] = y;
pos.push_back(p);
}
}
}
inline void getRegularPositions2(double xmin, double xmax, double ymin, double ymax, double d, double pert, std::vector<WorldVector<double> >& pos)
{
WorldVector<double> p;
pos.clear();
AMDiS::Random rnd(0.0, pert);
for (double x = xmin; x <= xmax; x+= d) {
for (double y = ymin; y <= ymax; y+= d) {
p[0] = x + rnd(p);
p[1] = y + rnd(p);
pos.push_back(p);
}
}
}
inline void getHexagonalPositions(double xmin, double xmax, double ymin, double ymax, double d, std::vector<WorldVector<double> >& pos)
{
WorldVector<double> p;
pos.clear();
for (int i = 0; i < 2; i++) {
for (double x = xmin; x <= xmax; x+= d) {
for (double y = ymin; y <= ymax; y+= std::sqrt(3.0)*d) {
p[0] = x;
p[1] = y;
pos.push_back(p);
}
}
xmin += 0.5*d;
ymin += 0.5*std::sqrt(3.0)*d;
}
}
inline void getHexagonalPositions(double xmin, double xmax, double ymin, double ymax, double d, double pert, std::vector<WorldVector<double> >& pos)
{
WorldVector<double> p;
pos.clear();
AMDiS::Random rnd(0.0, pert);
for (int i = 0; i < 2; i++) {
for (double x = xmin; x <= xmax; x+= d) {
for (double y = ymin; y <= ymax; y+= std::sqrt(3.0)*d) {
p[0] = x + rnd(p);
p[1] = y + rnd(p);
pos.push_back(p);
}
}
xmin += 0.5*d;
ymin += 0.5*std::sqrt(3.0)*d;
}
}
inline void initPositions(std::string name, std::vector<WorldVector<double> >& pos)
{
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
Parallel::StdMpi<std::vector<WorldVector<double> > > stdMpi(MPI::COMM_WORLD, true);
if (MPI::COMM_WORLD.Get_rank() == 0) {
#endif
double d = 4.0*M_PI/sqrt(3.0);
double height = 10.0, width = 10.0;
Parameters::get(name + "->d",d);
Parameters::get("height",height);
Parameters::get("width",width);
size_t nParticles = 10;
Parameters::get(name + "->number of particles",nParticles);
bool randomPositions = true;
Parameters::get(name + "->random particle positions",randomPositions);
int regularPositions = 0;
Parameters::get(name + "->regular particle positions",regularPositions);
std::vector<double> box;
Parameters::get(name + "->random particle box",box);
if (box.size() != 4) {
box.push_back(-width/2.0+0.5*d); box.push_back(width/2.0-0.5*d);
box.push_back(-height/2.0+0.5*d); box.push_back(height/2.0-0.5*d);
}
if (randomPositions) {
nParticles = std::min( static_cast<size_t>(floor((box[1]-box[0])/d)*floor((box[3]-box[2])/d)), nParticles );
std::cout << "try to place " << nParticles << " particles into the box!\n";
getRandomPositions(nParticles,box[0],box[1],box[2],box[3],pos);
} else if (regularPositions == 1) { // square lattice
getRegularPositions(box[0],box[1],box[2],box[3],d,pos);
} else if (regularPositions == 2) { // perturbed square lattice
double pert = 0.1*d;
Parameters::get(name + "->regular particle positions->perturbation", pert);
box[0]-=pert; box[1]+=pert;
getRegularPositions2(box[0],box[1],box[2],box[3],d,pert, pos);
} else if (regularPositions == 3) { // hexagonal lattice
getHexagonalPositions(box[0],box[1],box[2],box[3],d,pos);
} else if (regularPositions == 4) { // perturbed hexagonal lattice
double pert = 0.1*d;
Parameters::get(name + "->regular particle positions->perturbation", pert);
box[0]-=pert; box[1]+=pert;
getHexagonalPositions(box[0],box[1],box[2],box[3],d,pert,pos);
} else {
WorldVector<double> x;
for (size_t i = 0; i < nParticles; i++) {
Parameters::get(name + "->position[" + boost::lexical_cast<std::string>(i) + "]",x);
pos.push_back(x);
}
}
MSG("nr particles global: %d\n", pos.size());
int domain = 0;
Parameters::get(name + "->restrict to domain",domain);
if (domain == 1) {
WorldVector<double> center;
double radius = 1.0;
Parameters::get(name + "->restrict to domain->center",center);
Parameters::get(name + "->restrict to domain->radius",radius);
AbstractFunction<double, WorldVector<double> >* dist = new Circle(radius, center);
std::vector<WorldVector<double> > pos_;
for (size_t i = 0; i < pos.size(); i++) {
if ((*dist)(pos[i]) < 0.0)
pos_.push_back(pos[i]);
}
std::swap(pos, pos_);
MSG("nr particles restricted: %d\n", pos.size());
}
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
for (int i = 1; i < MPI::COMM_WORLD.Get_size(); i++)
stdMpi.send(i, pos);
} else {
stdMpi.recv(0);
}
stdMpi.startCommunication();
if (MPI::COMM_WORLD.Get_rank() != 0)
pos = stdMpi.getRecvData(0);
#endif
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment