// ============================================================================ // == == // == AMDiS - Adaptive multidimensional simulations == // == == // ============================================================================ // == == // == crystal growth group == // == == // == Stiftung caesar == // == Ludwig-Erhard-Allee 2 == // == 53175 Bonn == // == germany == // == == // ============================================================================ // == == // == http://www.caesar.de/cg/AMDiS == // == == // ============================================================================ /** \file ParallelDomainProblem.h */ #ifndef AMDIS_PARALLELDOMAINPROBLEM_H #define AMDIS_PARALLELDOMAINPROBLEM_H #include #include #include #include "ProblemTimeInterface.h" #include "ProblemIterationInterface.h" #include "FiniteElemSpace.h" #include "AdaptInfo.h" #include "InteriorBoundary.h" #include "AMDiS_fwd.h" #include "petsc.h" #include "petscsys.h" #include "petscao.h" #include "mpi.h" namespace AMDiS { class ParMetisPartitioner; class ParallelDomainProblemBase : public ProblemIterationInterface, public ProblemTimeInterface { public: ParallelDomainProblemBase(const std::string& name, ProblemIterationInterface *iterationIF, ProblemTimeInterface *timeIF, FiniteElemSpace *feSpace, RefinementManager *refineManager); virtual ~ParallelDomainProblemBase() {} virtual void initParallelization(AdaptInfo *adaptInfo); void exitParallelization(AdaptInfo *adaptInfo); /// Set for each element on the partitioning level the number of leaf elements. double setElemWeights(AdaptInfo *adaptInfo); void partitionMesh(AdaptInfo *adaptInfo); virtual void setTime(AdaptInfo *adaptInfo) {} virtual void initTimestep(AdaptInfo *adaptInfo) {} virtual void closeTimestep(AdaptInfo *adaptInfo) {} virtual void solveInitialProblem(AdaptInfo *adaptInfo) {} virtual void transferInitialSolution(AdaptInfo *adaptInfo) {} virtual void beginIteration(AdaptInfo *adaptInfo) { iterationIF->beginIteration(adaptInfo); } virtual Flag oneIteration(AdaptInfo *adaptInfo, Flag toDo = FULL_ITERATION) { ERROR_EXIT("Not implemented!\n"); return 0; } virtual void endIteration(AdaptInfo *adaptInfo) { iterationIF->endIteration(adaptInfo); } virtual int getNumProblems() { return 0; } inline virtual const std::string& getName() { return name; } /// Returns \ref nRankDOFs, the number of DOFs in the rank mesh. int getNumberRankDOFs() { return nRankDOFs; } void fillPetscMatrix(DOFMatrix *mat, DOFVector *vec); void solvePetscMatrix(DOFVector *vec); virtual ProblemStatBase *getProblem(int number = 0) { return NULL; } virtual void serialize(std::ostream&) {} virtual void deserialize(std::istream&) {} protected: /** \brief * Determine the interior boundaries, i.e. boundaries between ranks, and store * all information about them in \ref interiorBoundary. */ void createInteriorBoundaryInfo(std::vector& rankDOFs, std::map& boundaryDOFs); /// Removes all macro elements from the mesh that are not part of ranks partition. void removeMacroElements(); void createLocalGlobalNumbering(std::vector& rankDOFs, std::map& boundaryDOFs, int& nRankDOFs, int& nOverallDOFs); void updateLocalGlobalNumbering(int& nRankDOFs, int& nOverallDOFs); /** \brief * This function traverses the whole mesh, i.e. before it is really partitioned, * and collects information about which DOF corresponds to which rank. * * @param[out] partionDOFs Stores to each DOF pointer the set of ranks the DOF is * part of. * @param[out] rankDOFs Stores all rank DOFs. * @param[out] boundaryDOFs Stores all DOFs in ranks partition that are on an * interior boundary but correspond to another rank. */ void createDOFMemberInfo(std::map >& partitionDOFs, std::vector& rankDOFs, std::map& boundaryDOFs); protected: /// ProblemIterationInterface *iterationIF; /// ProblemTimeInterface *timeIF; /// The rank of the current process. int mpiRank; /// Overall number of processes. int mpiSize; /** \brief * MPI communicator collected all processes, which should * be used for calculation. The Debug procces is not included * in this communicator. */ MPI::Intracomm mpiComm; /// Name of the problem (as used in the init files) std::string name; /// Finite element space of the problem. FiniteElemSpace *feSpace; /// Mesh of the problem. Mesh *mesh; /// Refinement manager for the mesh. RefinementManager *refinementManager; /// Pointer to the paritioner which is used to devide a mesh into partitions. ParMetisPartitioner *partitioner; /// Weights for the elements, i.e., the number of leaf elements within this element. std::map elemWeights; /// Is true, if the mesh was not partitioned before, otherwise it's false. bool initialPartitionMesh; /** \brief * Stores to every coarse element index the number of the partition it * corresponds to. */ std::map partitionVec; /** \brief * Stores an old partitioning of elements. To every element index the number * of the parition it corresponds to is stored. */ std::map oldPartitionVec; Mat petscMatrix; Vec petscRhsVec; Vec petscSolVec; /// Number of DOFs in the rank mesh. int nRankDOFs; /** \brief * Defines the interioir boundaries of the domain that result from partitioning * the whole mesh. */ InteriorBoundary interiorBoundary; /** \brief * This map contains for each rank the list of dofs the current rank must send * to exchange solution dofs at the interior boundaries. */ std::map > sendDofs; /** \brief * This map contains for each rank the list of dofs from which the current rank * must receive solution values of dofs at the interior boundaries. */ std::map > recvDofs; /// Maps local to global dof indices. std::map mapLocalGlobalDOFs; /// Maps global to local dof indices. std::map mapGlobalLocalDOFs; /** \brief * Maps all DOFs in ranks partition to a bool value. If it is true, the DOF is * owned by the rank. Otherwise, its an interior boundary DOF that is owned by * another rank. */ std::map isRankDOF; }; class ParallelDomainProblemScal : public ParallelDomainProblemBase { public: ParallelDomainProblemScal(const std::string& name, ProblemScal *problem, ProblemInstatScal *problemInstat); void initParallelization(AdaptInfo *adaptInfo); virtual Flag oneIteration(AdaptInfo *adaptInfo, Flag toDo = FULL_ITERATION); protected: ProblemScal *probScal; }; } #endif // AMDIS_PARALLELDOMAINPROBLEM_H