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 dftfe::uInt 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<dftfe::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<dftfe::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 dftfe::uInt 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 */
146 void
148 dealii::parallel::distributed::Triangulation<3> &parallelTriangulationA,
149 dealii::parallel::distributed::Triangulation<3> &parallelTriangulationB);
150
151 /**
152 * @brief generates reset meshes to the last mesh generated by auto mesh approach. This
153 * is used in Gaussian update of meshes during electrostatics
154 */
155 void
157 const std::vector<std::vector<double>> &domainBoundingVectors,
158 const bool generateSerialTria);
159
160
161 /**
162 * @brief serialize the triangulations and the associated solution vectors
163 *
164 * @param [input]feOrder finite element polynomial order of the dofHandler on which solution
165 * vectors are based upon
166 * @param [input]nComponents number of components of the dofHandler on which solution
167 * vectors are based upon
168 * @param [input]solutionVectors vector of parallel distributed solution vectors to be serialized
169 * @param [input]interpoolComm This communicator is used to ensure serialization
170 * happens only in k point pool
171 * @param [input]interBandGroupComm This communicator to ensure serialization happens
172 * only in band group
173 */
174 void
176 std::string path,
177 const dftfe::uInt feOrder,
178 const dftfe::uInt nComponents,
179 const std::vector<const distributedCPUVec<double> *> &solutionVectors,
180 const MPI_Comm &interpoolComm,
181 const MPI_Comm &interBandGroupComm);
182
183 /**
184 * @brief de-serialize the triangulations and the associated solution vectors
185 *
186 * @param [input]feOrder finite element polynomial order of the dofHandler on which solution
187 * vectors to be de-serialized are based upon
188 * @param [input]nComponents number of components of the dofHandler on which solution
189 * vectors to be de-serialized are based upon
190 * @param [output]solutionVectors vector of parallel distributed de-serialized solution vectors. The
191 * vector length must match the input vector length used in the call to
192 * saveTriangulationSolutionVectors
193 */
194 void
196 std::string path,
197 const dftfe::uInt feOrder,
198 const dftfe::uInt nComponents,
199 std::vector<distributedCPUVec<double> *> &solutionVectors);
200
201 /**
202 * @brief internal function which generates a parallel and serial mesh using a adaptive refinement strategy.
203 *
204 */
205 void
207 dealii::parallel::distributed::Triangulation<3> &parallelTriangulation,
208 dealii::parallel::distributed::Triangulation<3> &serialTriangulation,
209 std::vector<std::vector<bool>> &parallelTriaCurrentRefinement,
210 std::vector<std::vector<bool>> &serialTriaCurrentRefinement,
211 const bool generateSerialTria = false,
212 const bool enableManualRepartitioning = false);
213
214 private:
215 /**
216 * @brief internal function which generates a coarse mesh which is required for the load function call in
217 * restarts.
218 *
219 */
220 void
222 dealii::parallel::distributed::Triangulation<3> &parallelTriangulation);
223
224 /**
225 * @brief internal function which sets refinement flags based on a custom created algorithm
226 *
227 * @return bool boolean flag is any local cell has refinement flag set
228 */
229 bool
231 dealii::parallel::distributed::Triangulation<3> &parallelTriangulation,
232 std::vector<dftfe::uInt> &locallyOwnedCellsRefineFlags,
233 std::map<dealii::CellId, dftfe::uInt> &cellIdToCellRefineFlagMapLocal,
234 const bool smoothenCellsOnPeriodicBoundary = false,
235 const double smootheningFactor = 2.0);
236
237 /**
238 * @brief internal function which sets refinement flags to have consistent refinement across periodic
239 * boundary
240 *
241 * @return bool boolean flag is any local cell has refinement flag set
242 */
243 bool
245 dealii::parallel::distributed::Triangulation<3> &parallelTriangulation,
246 std::vector<dftfe::uInt> &locallyOwnedCellsRefineFlags,
247 std::map<dealii::CellId, dftfe::uInt> &cellIdToCellRefineFlagMapLocal);
248
249 /**
250 * @brief check that triangulation has consistent refinement across periodic boundary including
251 * for ghost cells
252 *
253 */
254 bool
256 dealii::parallel::distributed::Triangulation<3> &parallelTriangulation);
257
258
259 /**
260 * @brief check that FEOrder=1 dofHandler using the triangulation has parallel consistent
261 * combined hanging node and periodic constraints
262 *
263 */
264 bool
266 dealii::parallel::distributed::Triangulation<3> &parallelTriangulation);
267
268
269 /**
270 * @brief internal function which refines the serial mesh based on refinement flags from parallel mesh.
271 * This ensures that we get the same mesh in serial and parallel.
272 *
273 */
274 void
276 const std::map<dealii::CellId, dftfe::uInt>
277 &cellIdToCellRefineFlagMapLocal,
278 const MPI_Comm &mpi_comm,
279 dealii::parallel::distributed::Triangulation<3> &serialTriangulation,
280 const dealii::parallel::distributed::Triangulation<3>
281 &parallelTriangulation,
282 std::vector<bool> &serialTriaCurrentRefinement);
283
284 /**
285 * @brief internal function to serialize support triangulations. No solution data is attached to them
286 */
287 void
288 saveSupportTriangulations(std::string path);
289
290 /**
291 * @brief internal function to de-serialize support triangulations. No solution data is read from them
292 */
293 void
294 loadSupportTriangulations(std::string path);
295
296 //
297 // data members
298 //
299 dealii::parallel::distributed::Triangulation<3>
301 dealii::parallel::distributed::Triangulation<3>
303 dealii::parallel::distributed::Triangulation<3>
305
306 std::vector<std::vector<bool>> d_parallelTriaCurrentRefinement;
307 std::vector<std::vector<bool>> d_serialTriaCurrentRefinement;
308
309
310 std::vector<std::vector<double>> d_atomPositions;
311 std::vector<std::vector<double>> d_imageAtomPositions;
312 std::vector<std::vector<double>> d_meshSizes;
313 std::vector<dftfe::Int> d_imageIds;
314 std::vector<double> d_nearestAtomDistances;
315 std::vector<std::vector<double>> d_domainBoundingVectors;
317
318 /// FEOrder to be used for checking parallel consistency of periodic+hanging
319 /// node constraints
321
323
324 //
325 // parallel objects
326 //
327 const MPI_Comm d_mpiCommParent;
328 const MPI_Comm mpi_communicator;
329 const MPI_Comm interpoolcomm;
330 const MPI_Comm interBandGroupComm;
333 dealii::ConditionalOStream pcout;
334
335 //
336 // compute-time logger
337 //
338 dealii::TimerOutput computing_timer;
339 };
340
341} // namespace dftfe
342#endif
Namespace which declares the input parameters and the functions to parse them from the input paramete...
Definition dftParameters.h:36
dealii::parallel::distributed::Triangulation< 3 > & getParallelMeshMoved()
returns reference to parallel moved triangulation
std::vector< std::vector< bool > > d_parallelTriaCurrentRefinement
Definition triangulationManager.h:306
const MPI_Comm interpoolcomm
Definition triangulationManager.h:329
void saveTriangulationsSolutionVectors(std::string path, const dftfe::uInt feOrder, const dftfe::uInt nComponents, const std::vector< const distributedCPUVec< double > * > &solutionVectors, const MPI_Comm &interpoolComm, const MPI_Comm &interBandGroupComm)
serialize the triangulations and the associated solution vectors
std::vector< dftfe::Int > d_imageIds
Definition triangulationManager.h:313
void loadTriangulationsSolutionVectors(std::string path, const dftfe::uInt feOrder, const dftfe::uInt nComponents, std::vector< distributedCPUVec< double > * > &solutionVectors)
de-serialize the triangulations and the associated solution vectors
std::vector< std::vector< double > > d_domainBoundingVectors
Definition triangulationManager.h:315
std::vector< std::vector< double > > d_atomPositions
Definition triangulationManager.h:310
void refineSerialMesh(const std::map< dealii::CellId, dftfe::uInt > &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....
const dftfe::uInt n_mpi_processes
Definition triangulationManager.h:332
const dftParameters & d_dftParams
Definition triangulationManager.h:322
const dftfe::uInt this_mpi_process
Definition triangulationManager.h:331
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 dftfe::uInt d_max_refinement_steps
Definition triangulationManager.h:316
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...
const dftfe::uInt d_FEOrder
Definition triangulationManager.h:320
bool checkConstraintsConsistency(dealii::parallel::distributed::Triangulation< 3 > &parallelTriangulation)
check that FEOrder=1 dofHandler using the triangulation has parallel consistent combined hanging node...
void generateCoarseMeshesForRestart(const std::vector< std::vector< double > > &atomLocations, const std::vector< std::vector< double > > &imageAtomLocations, const std::vector< dftfe::Int > &imageIds, const std::vector< double > &nearestAtomDistances, const std::vector< std::vector< double > > &domainBoundingVectors, const bool generateSerialTria)
generates the coarse meshes for restart.
bool consistentPeriodicBoundaryRefinement(dealii::parallel::distributed::Triangulation< 3 > &parallelTriangulation, std::vector< dftfe::uInt > &locallyOwnedCellsRefineFlags, std::map< dealii::CellId, dftfe::uInt > &cellIdToCellRefineFlagMapLocal)
internal function which sets refinement flags to have consistent refinement across periodic boundary
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...
void generateAutomaticMeshApriori(const dealii::DoFHandler< 3 > &dofHandler, dealii::parallel::distributed::Triangulation< 3 > &parallelTriangulation, const std::vector< distributedCPUVec< double > > &eigenVectorsArrayIn, const dftfe::uInt FEOrder)
returns generates A-posteriori refined mesh
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
triangulationManager(const MPI_Comm &mpi_comm_parent, const MPI_Comm &mpi_comm_domain, const MPI_Comm &interpoolcomm, const MPI_Comm &interBandGroupComm, const dftfe::uInt FEOrder, const dftParameters &dftParams)
Constructor.
dealii::ConditionalOStream pcout
Definition triangulationManager.h:333
const MPI_Comm interBandGroupComm
Definition triangulationManager.h:330
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:300
std::vector< std::vector< bool > > d_serialTriaCurrentRefinement
Definition triangulationManager.h:307
dealii::TimerOutput computing_timer
Definition triangulationManager.h:338
bool refinementAlgorithmA(dealii::parallel::distributed::Triangulation< 3 > &parallelTriangulation, std::vector< dftfe::uInt > &locallyOwnedCellsRefineFlags, std::map< dealii::CellId, dftfe::uInt > &cellIdToCellRefineFlagMapLocal, const bool smoothenCellsOnPeriodicBoundary=false, const double smootheningFactor=2.0)
internal function which sets refinement flags based on a custom created algorithm
dealii::parallel::distributed::Triangulation< 3 > d_serialTriangulationUnmoved
Definition triangulationManager.h:304
std::vector< std::vector< double > > d_meshSizes
Definition triangulationManager.h:312
const MPI_Comm mpi_communicator
Definition triangulationManager.h:328
const MPI_Comm d_mpiCommParent
Definition triangulationManager.h:327
void generateSerialUnmovedAndParallelMovedUnmovedMesh(const std::vector< std::vector< double > > &atomLocations, const std::vector< std::vector< double > > &imageAtomLocations, const std::vector< dftfe::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< std::vector< double > > d_imageAtomPositions
Definition triangulationManager.h:311
dealii::parallel::distributed::Triangulation< 3 > & getSerialMeshUnmoved()
returns constant reference to serial unmoved triangulation
std::vector< double > d_nearestAtomDistances
Definition triangulationManager.h:314
dealii::parallel::distributed::Triangulation< 3 > d_parallelTriangulationMoved
Definition triangulationManager.h:302
Definition pseudoPotentialToDftfeConverter.cc:34
dealii::LinearAlgebra::distributed::Vector< elem_type, dealii::MemorySpace::Host > distributedCPUVec
Definition headers.h:92
std::uint32_t uInt
Definition TypeConfig.h:10