DFT-FE 1.1.0-pre
Density Functional Theory With Finite-Elements
Loading...
Searching...
No Matches
triangulationManager.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (c) 2017-2025 The Regents of the University of Michigan and DFT-FE
4// authors.
5//
6// This file is part of the DFT-FE code.
7//
8// The DFT-FE code is free software; you can use it, redistribute
9// it, and/or modify it under the terms of the GNU Lesser General
10// Public License as published by the Free Software Foundation; either
11// version 2.1 of the License, or (at your option) any later version.
12// The full text of the license can be found in the file LICENSE at
13// the top level of the DFT-FE distribution.
14//
15// ---------------------------------------------------------------------
16
17#ifndef triangulationManager_H_
18#define triangulationManager_H_
19#include "headers.h"
20#include "dftParameters.h"
21
22
23namespace dftfe
24{
25 /**
26 * @brief This class generates and stores adaptive finite element meshes for the real-space dft problem.
27 *
28 * The class uses an adpative mesh generation strategy to generate finite
29 * element mesh for given domain based on five input parameters: BASE MESH
30 * SIZE, ATOM BALL RADIUS, MESH SIZE ATOM BALL, MESH SIZE NEAR ATOM and MAX
31 * REFINEMENT STEPS (Refer to utils/dftParameters.cc for their corresponding
32 * internal variable names). Additionaly, this class also applies periodicity
33 * to mesh. The class stores two types of meshes: moved and unmoved. They are
34 * essentially the same meshes, except that we move the nodes of the moved
35 * mesh (in the meshMovement class) such that the atoms lie on the nodes.
36 * However, once the mesh is moved, dealii has issues using that mesh for
37 * further refinement, which is why we also carry an unmoved triangulation.
38 *
39 * @author Phani Motamarri, Sambit Das, Krishnendu Ghosh
40 */
42 {
43 public:
44 /** @brief Constructor.
45 *
46 * @param mpi_comm_parent parent mpi communicator
47 * @param mpi_comm_domain domain decomposition mpi communicator
48 * @param interpool_comm mpi interpool communicator over k points
49 * @param interBandGroupComm mpi interpool communicator over band groups
50 */
51 triangulationManager(const MPI_Comm & mpi_comm_parent,
52 const MPI_Comm & mpi_comm_domain,
53 const MPI_Comm & interpoolcomm,
54 const MPI_Comm & interBandGroupComm,
55 const unsigned int FEOrder,
56 const dftParameters &dftParams);
57
58
59 /**
60 * triangulationManager destructor
61 */
63
64 /** @brief generates parallel moved and unmoved meshes, and serial unmoved mesh.
65 *
66 * @param atomLocations vector containing cartesian coordinates at atoms with
67 * respect to origin (center of domain).
68 * @param imageAtomLocations vector containing cartesian coordinates of image
69 * atoms with respect to origin.
70 * @param domainBoundingVectors vector of domain bounding vectors (refer to
71 * description of input parameters.
72 * @param generateSerialMesh bool to toggle to generation of serial tria
73 */
74 void
76 const std::vector<std::vector<double>> &atomLocations,
77 const std::vector<std::vector<double>> &imageAtomLocations,
78 const std::vector<int> & imageIds,
79 const std::vector<double> & nearestAtomDistances,
80 const std::vector<std::vector<double>> &domainBoundingVectors,
81 const bool generateSerialTria);
82
83
84
85 /** @brief generates the coarse meshes for restart.
86 *
87 * @param atomLocations vector containing cartesian coordinates at atoms with
88 * respect to origin (center of domain).
89 * @param imageAtomLocations vector containing cartesian coordinates of image
90 * atoms with respect to origin.
91 * @param domainBoundingVectors vector of domain bounding vectors (refer to
92 * description of input parameters.
93 * @param generateSerialMesh bool to toggle to generation of serial tria
94 */
95 void
97 const std::vector<std::vector<double>> &atomLocations,
98 const std::vector<std::vector<double>> &imageAtomLocations,
99 const std::vector<int> & imageIds,
100 const std::vector<double> & nearestAtomDistances,
101 const std::vector<std::vector<double>> &domainBoundingVectors,
102 const bool generateSerialTria);
103
104
105 /**
106 * @brief returns generates A-posteriori refined mesh
107 *
108 * @param dofHandler corresponds to starting mesh which has to refined
109 * @param parallelTriangulation corresponds to starting triangulation
110 * @param eigenVectorsArrayIn solution vectors used to compute errors in each cell required for refinement
111 * @param FEOrder finite-element interpolating polynomial
112 */
113 void
115 const dealii::DoFHandler<3> & dofHandler,
116 dealii::parallel::distributed::Triangulation<3> &parallelTriangulation,
117 const std::vector<distributedCPUVec<double>> & eigenVectorsArrayIn,
118 const unsigned int FEOrder);
119
120
121 /**
122 * @brief returns constant reference to serial unmoved triangulation
123 *
124 */
125 dealii::parallel::distributed::Triangulation<3> &
127
128 /**
129 * @brief returns reference to parallel moved triangulation
130 *
131 */
132 dealii::parallel::distributed::Triangulation<3> &
134
135 /**
136 * @brief returns constant reference to parallel unmoved triangulation
137 *
138 */
139 dealii::parallel::distributed::Triangulation<3> &
141
142 /**
143 * @brief resets the vertices of meshB moved to vertices of meshA.
144 *
145 */
147 dealii::parallel::distributed::Triangulation<3> &parallelTriangulationA,
148 dealii::parallel::distributed::Triangulation<3> &parallelTriangulationB);
149
150 /**
151 * @brief generates reset meshes to the last mesh generated by auto mesh approach. This
152 * is used in Gaussian update of meshes during electrostatics
153 */
154 void
156 const std::vector<std::vector<double>> &domainBoundingVectors,
157 const bool generateSerialTria);
158
159
160 /**
161 * @brief serialize the triangulations and the associated solution vectors
162 *
163 * @param [input]feOrder finite element polynomial order of the dofHandler on which solution
164 * vectors are based upon
165 * @param [input]nComponents number of components of the dofHandler on which solution
166 * vectors are based upon
167 * @param [input]solutionVectors vector of parallel distributed solution vectors to be serialized
168 * @param [input]interpoolComm This communicator is used to ensure serialization
169 * happens only in k point pool
170 * @param [input]interBandGroupComm This communicator to ensure serialization happens
171 * only in band group
172 */
173 void
175 std::string path,
176 const unsigned int feOrder,
177 const unsigned int nComponents,
178 const std::vector<const distributedCPUVec<double> *> &solutionVectors,
179 const MPI_Comm & interpoolComm,
180 const MPI_Comm & interBandGroupComm);
181
182 /**
183 * @brief de-serialize the triangulations and the associated solution vectors
184 *
185 * @param [input]feOrder finite element polynomial order of the dofHandler on which solution
186 * vectors to be de-serialized are based upon
187 * @param [input]nComponents number of components of the dofHandler on which solution
188 * vectors to be de-serialized are based upon
189 * @param [output]solutionVectors vector of parallel distributed de-serialized solution vectors. The
190 * vector length must match the input vector length used in the call to
191 * saveTriangulationSolutionVectors
192 */
193 void
195 std::string path,
196 const unsigned int feOrder,
197 const unsigned int nComponents,
198 std::vector<distributedCPUVec<double> *> &solutionVectors);
199
200 /**
201 * @brief internal function which generates a parallel and serial mesh using a adaptive refinement strategy.
202 *
203 */
205 dealii::parallel::distributed::Triangulation<3> &parallelTriangulation,
206 dealii::parallel::distributed::Triangulation<3> &serialTriangulation,
207 std::vector<std::vector<bool>> &parallelTriaCurrentRefinement,
208 std::vector<std::vector<bool>> &serialTriaCurrentRefinement,
209 const bool generateSerialTria = false,
210 const bool enableManualRepartitioning = false);
211
212 private:
213 /**
214 * @brief internal function which generates a coarse mesh which is required for the load function call in
215 * restarts.
216 *
217 */
219 dealii::parallel::distributed::Triangulation<3> &parallelTriangulation);
220
221 /**
222 * @brief internal function which sets refinement flags based on a custom created algorithm
223 *
224 * @return bool boolean flag is any local cell has refinement flag set
225 */
227 dealii::parallel::distributed::Triangulation<3> &parallelTriangulation,
228 std::vector<unsigned int> & locallyOwnedCellsRefineFlags,
229 std::map<dealii::CellId, unsigned int> &cellIdToCellRefineFlagMapLocal,
230 const bool smoothenCellsOnPeriodicBoundary = false,
231 const double smootheningFactor = 2.0);
232
233 /**
234 * @brief internal function which sets refinement flags to have consistent refinement across periodic
235 * boundary
236 *
237 * @return bool boolean flag is any local cell has refinement flag set
238 */
240 dealii::parallel::distributed::Triangulation<3> &parallelTriangulation,
241 std::vector<unsigned int> & locallyOwnedCellsRefineFlags,
242 std::map<dealii::CellId, unsigned int> &cellIdToCellRefineFlagMapLocal);
243
244 /**
245 * @brief check that triangulation has consistent refinement across periodic boundary including
246 * for ghost cells
247 *
248 */
250 dealii::parallel::distributed::Triangulation<3> &parallelTriangulation);
251
252
253 /**
254 * @brief check that FEOrder=1 dofHandler using the triangulation has parallel consistent
255 * combined hanging node and periodic constraints
256 *
257 */
259 dealii::parallel::distributed::Triangulation<3> &parallelTriangulation);
260
261
262 /**
263 * @brief internal function which refines the serial mesh based on refinement flags from parallel mesh.
264 * This ensures that we get the same mesh in serial and parallel.
265 *
266 */
267 void
269 const std::map<dealii::CellId, unsigned int>
270 & cellIdToCellRefineFlagMapLocal,
271 const MPI_Comm &mpi_comm,
272 dealii::parallel::distributed::Triangulation<3> &serialTriangulation,
273 const dealii::parallel::distributed::Triangulation<3>
274 & parallelTriangulation,
275 std::vector<bool> &serialTriaCurrentRefinement);
276
277 /**
278 * @brief internal function to serialize support triangulations. No solution data is attached to them
279 */
280 void
281 saveSupportTriangulations(std::string path);
282
283 /**
284 * @brief internal function to de-serialize support triangulations. No solution data is read from them
285 */
286 void
287 loadSupportTriangulations(std::string path);
288
289 //
290 // data members
291 //
292 dealii::parallel::distributed::Triangulation<3>
294 dealii::parallel::distributed::Triangulation<3>
296 dealii::parallel::distributed::Triangulation<3>
298
299 std::vector<std::vector<bool>> d_parallelTriaCurrentRefinement;
300 std::vector<std::vector<bool>> d_serialTriaCurrentRefinement;
301
302
303 std::vector<std::vector<double>> d_atomPositions;
304 std::vector<std::vector<double>> d_imageAtomPositions;
305 std::vector<std::vector<double>> d_meshSizes;
306 std::vector<int> d_imageIds;
307 std::vector<double> d_nearestAtomDistances;
308 std::vector<std::vector<double>> d_domainBoundingVectors;
309 const unsigned int d_max_refinement_steps = 40;
310
311 /// FEOrder to be used for checking parallel consistency of periodic+hanging
312 /// node constraints
313 const unsigned int d_FEOrder;
314
316
317 //
318 // parallel objects
319 //
320 const MPI_Comm d_mpiCommParent;
321 const MPI_Comm mpi_communicator;
322 const MPI_Comm interpoolcomm;
323 const MPI_Comm interBandGroupComm;
324 const unsigned int this_mpi_process;
325 const unsigned int n_mpi_processes;
326 dealii::ConditionalOStream pcout;
327
328 //
329 // compute-time logger
330 //
331 dealii::TimerOutput computing_timer;
332 };
333
334} // namespace dftfe
335#endif
Namespace which declares the input parameters and the functions to parse them from the input paramete...
Definition dftParameters.h:35
void loadTriangulationsSolutionVectors(std::string path, const unsigned int feOrder, const unsigned int nComponents, std::vector< distributedCPUVec< double > * > &solutionVectors)
de-serialize the triangulations and the associated solution vectors
dealii::parallel::distributed::Triangulation< 3 > & getParallelMeshMoved()
returns reference to parallel moved triangulation
std::vector< int > d_imageIds
Definition triangulationManager.h:306
std::vector< std::vector< bool > > d_parallelTriaCurrentRefinement
Definition triangulationManager.h:299
triangulationManager(const MPI_Comm &mpi_comm_parent, const MPI_Comm &mpi_comm_domain, const MPI_Comm &interpoolcomm, const MPI_Comm &interBandGroupComm, const unsigned int FEOrder, const dftParameters &dftParams)
Constructor.
const MPI_Comm interpoolcomm
Definition triangulationManager.h:322
std::vector< std::vector< double > > d_domainBoundingVectors
Definition triangulationManager.h:308
std::vector< std::vector< double > > d_atomPositions
Definition triangulationManager.h:303
void generateCoarseMeshesForRestart(const std::vector< std::vector< double > > &atomLocations, const std::vector< std::vector< double > > &imageAtomLocations, const std::vector< int > &imageIds, const std::vector< double > &nearestAtomDistances, const std::vector< std::vector< double > > &domainBoundingVectors, const bool generateSerialTria)
generates the coarse meshes for restart.
void saveTriangulationsSolutionVectors(std::string path, const unsigned int feOrder, const unsigned int nComponents, const std::vector< const distributedCPUVec< double > * > &solutionVectors, const MPI_Comm &interpoolComm, const MPI_Comm &interBandGroupComm)
serialize the triangulations and the associated solution vectors
const dftParameters & d_dftParams
Definition triangulationManager.h:315
const unsigned int d_FEOrder
Definition triangulationManager.h:313
void refineSerialMesh(const std::map< dealii::CellId, unsigned int > &cellIdToCellRefineFlagMapLocal, const MPI_Comm &mpi_comm, dealii::parallel::distributed::Triangulation< 3 > &serialTriangulation, const dealii::parallel::distributed::Triangulation< 3 > &parallelTriangulation, std::vector< bool > &serialTriaCurrentRefinement)
internal function which refines the serial mesh based on refinement flags from parallel mesh....
dealii::parallel::distributed::Triangulation< 3 > & getParallelMeshUnmoved()
returns constant reference to parallel unmoved triangulation
void saveSupportTriangulations(std::string path)
internal function to serialize support triangulations. No solution data is attached to them
bool checkPeriodicSurfaceRefinementConsistency(dealii::parallel::distributed::Triangulation< 3 > &parallelTriangulation)
check that triangulation has consistent refinement across periodic boundary including for ghost cells
const unsigned int this_mpi_process
Definition triangulationManager.h:324
void generateResetMeshes(const std::vector< std::vector< double > > &domainBoundingVectors, const bool generateSerialTria)
generates reset meshes to the last mesh generated by auto mesh approach. This is used in Gaussian upd...
bool checkConstraintsConsistency(dealii::parallel::distributed::Triangulation< 3 > &parallelTriangulation)
check that FEOrder=1 dofHandler using the triangulation has parallel consistent combined hanging node...
void generateCoarseMesh(dealii::parallel::distributed::Triangulation< 3 > &parallelTriangulation)
internal function which generates a coarse mesh which is required for the load function call in resta...
bool consistentPeriodicBoundaryRefinement(dealii::parallel::distributed::Triangulation< 3 > &parallelTriangulation, std::vector< unsigned int > &locallyOwnedCellsRefineFlags, std::map< dealii::CellId, unsigned int > &cellIdToCellRefineFlagMapLocal)
internal function which sets refinement flags to have consistent refinement across periodic boundary
void generateMesh(dealii::parallel::distributed::Triangulation< 3 > &parallelTriangulation, dealii::parallel::distributed::Triangulation< 3 > &serialTriangulation, std::vector< std::vector< bool > > &parallelTriaCurrentRefinement, std::vector< std::vector< bool > > &serialTriaCurrentRefinement, const bool generateSerialTria=false, const bool enableManualRepartitioning=false)
internal function which generates a parallel and serial mesh using a adaptive refinement strategy.
void loadSupportTriangulations(std::string path)
internal function to de-serialize support triangulations. No solution data is read from them
void generateAutomaticMeshApriori(const dealii::DoFHandler< 3 > &dofHandler, dealii::parallel::distributed::Triangulation< 3 > &parallelTriangulation, const std::vector< distributedCPUVec< double > > &eigenVectorsArrayIn, const unsigned int FEOrder)
returns generates A-posteriori refined mesh
dealii::ConditionalOStream pcout
Definition triangulationManager.h:326
const MPI_Comm interBandGroupComm
Definition triangulationManager.h:323
bool refinementAlgorithmA(dealii::parallel::distributed::Triangulation< 3 > &parallelTriangulation, std::vector< unsigned int > &locallyOwnedCellsRefineFlags, std::map< dealii::CellId, unsigned int > &cellIdToCellRefineFlagMapLocal, const bool smoothenCellsOnPeriodicBoundary=false, const double smootheningFactor=2.0)
internal function which sets refinement flags based on a custom created algorithm
void resetMesh(dealii::parallel::distributed::Triangulation< 3 > &parallelTriangulationA, dealii::parallel::distributed::Triangulation< 3 > &parallelTriangulationB)
resets the vertices of meshB moved to vertices of meshA.
dealii::parallel::distributed::Triangulation< 3 > d_parallelTriangulationUnmoved
Definition triangulationManager.h:293
std::vector< std::vector< bool > > d_serialTriaCurrentRefinement
Definition triangulationManager.h:300
const unsigned int d_max_refinement_steps
Definition triangulationManager.h:309
dealii::TimerOutput computing_timer
Definition triangulationManager.h:331
dealii::parallel::distributed::Triangulation< 3 > d_serialTriangulationUnmoved
Definition triangulationManager.h:297
std::vector< std::vector< double > > d_meshSizes
Definition triangulationManager.h:305
const unsigned int n_mpi_processes
Definition triangulationManager.h:325
const MPI_Comm mpi_communicator
Definition triangulationManager.h:321
const MPI_Comm d_mpiCommParent
Definition triangulationManager.h:320
std::vector< std::vector< double > > d_imageAtomPositions
Definition triangulationManager.h:304
dealii::parallel::distributed::Triangulation< 3 > & getSerialMeshUnmoved()
returns constant reference to serial unmoved triangulation
void generateSerialUnmovedAndParallelMovedUnmovedMesh(const std::vector< std::vector< double > > &atomLocations, const std::vector< std::vector< double > > &imageAtomLocations, const std::vector< int > &imageIds, const std::vector< double > &nearestAtomDistances, const std::vector< std::vector< double > > &domainBoundingVectors, const bool generateSerialTria)
generates parallel moved and unmoved meshes, and serial unmoved mesh.
std::vector< double > d_nearestAtomDistances
Definition triangulationManager.h:307
dealii::parallel::distributed::Triangulation< 3 > d_parallelTriangulationMoved
Definition triangulationManager.h:295
Definition pseudoPotentialToDftfeConverter.cc:34
dealii::LinearAlgebra::distributed::Vector< elem_type, dealii::MemorySpace::Host > distributedCPUVec
Definition headers.h:92