Skip to content

Commit aac9b10

Browse files
authored
Simplify initializations in GMGPolar::setup (#187)
1 parent 35f113e commit aac9b10

File tree

1 file changed

+59
-74
lines changed

1 file changed

+59
-74
lines changed

include/GMGPolar/setup.h

Lines changed: 59 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ void GMGPolar<DomainGeometry, DensityProfileCoefficients>::setup()
5454
levels_.clear();
5555
levels_.reserve(number_of_levels_);
5656

57-
int level_depth = 0;
5857
auto finest_levelCache = std::make_unique<LevelCache>(*finest_grid, density_profile_coefficients_, domain_geometry_,
5958
cache_density_profile_coefficients_, cache_domain_geometry_);
60-
levels_.emplace_back(level_depth, std::move(finest_grid), std::move(finest_levelCache), extrapolation_, FMG_);
59+
levels_.emplace_back(0, std::move(finest_grid), std::move(finest_levelCache), extrapolation_, FMG_);
6160

62-
for (level_depth = 1; level_depth < number_of_levels_; level_depth++) {
61+
for (int level_depth = 1; level_depth < number_of_levels_; level_depth++) {
6362
auto current_grid = std::make_unique<PolarGrid>(coarseningGrid(levels_[level_depth - 1].grid()));
6463
auto current_levelCache =
6564
std::make_unique<LevelCache>(*current_grid, density_profile_coefficients_, domain_geometry_,
@@ -81,84 +80,70 @@ void GMGPolar<DomainGeometry, DensityProfileCoefficients>::setup()
8180
if (verbose_ > 0)
8281
printSettings();
8382

84-
// -------------------------------------------------------
85-
// Initializing various operators based on the level index
83+
// ------------------------------------------------ //
84+
// Define residual operator on all multigrid levels //
85+
// ------------------------------------------------ //
8686
for (int level_depth = 0; level_depth < number_of_levels_; level_depth++) {
87-
// ---------------------- //
88-
// Level 0 (finest Level) //
89-
// ---------------------- //
90-
if (level_depth == 0) {
91-
auto start_setup_smoother = std::chrono::high_resolution_clock::now();
92-
switch (extrapolation_) {
93-
case ExtrapolationType::NONE:
94-
full_grid_smoothing_ = true;
95-
levels_[level_depth].initializeSmoothing(domain_geometry_, density_profile_coefficients_,
96-
DirBC_Interior_, max_omp_threads_,
97-
stencil_distribution_method_);
98-
break;
99-
case ExtrapolationType::IMPLICIT_EXTRAPOLATION:
100-
full_grid_smoothing_ = false;
101-
levels_[level_depth].initializeExtrapolatedSmoothing(domain_geometry_, density_profile_coefficients_,
102-
DirBC_Interior_, max_omp_threads_,
103-
stencil_distribution_method_);
104-
break;
105-
case ExtrapolationType::IMPLICIT_FULL_GRID_SMOOTHING:
106-
full_grid_smoothing_ = true;
107-
levels_[level_depth].initializeSmoothing(domain_geometry_, density_profile_coefficients_,
108-
DirBC_Interior_, max_omp_threads_,
109-
stencil_distribution_method_);
110-
break;
111-
case ExtrapolationType::COMBINED:
112-
full_grid_smoothing_ = true;
113-
levels_[level_depth].initializeSmoothing(domain_geometry_, density_profile_coefficients_,
114-
DirBC_Interior_, max_omp_threads_,
115-
stencil_distribution_method_);
116-
levels_[level_depth].initializeExtrapolatedSmoothing(domain_geometry_, density_profile_coefficients_,
117-
DirBC_Interior_, max_omp_threads_,
118-
stencil_distribution_method_);
119-
break;
120-
default:
121-
full_grid_smoothing_ = false;
122-
levels_[level_depth].initializeSmoothing(domain_geometry_, density_profile_coefficients_,
123-
DirBC_Interior_, max_omp_threads_,
124-
stencil_distribution_method_);
125-
levels_[level_depth].initializeExtrapolatedSmoothing(domain_geometry_, density_profile_coefficients_,
126-
DirBC_Interior_, max_omp_threads_,
127-
stencil_distribution_method_);
128-
break;
129-
}
130-
auto end_setup_smoother = std::chrono::high_resolution_clock::now();
131-
t_setup_smoother_ += std::chrono::duration<double>(end_setup_smoother - start_setup_smoother).count();
132-
levels_[level_depth].initializeResidual(domain_geometry_, density_profile_coefficients_, DirBC_Interior_,
133-
max_omp_threads_, stencil_distribution_method_);
87+
levels_[level_depth].initializeResidual(domain_geometry_, density_profile_coefficients_, DirBC_Interior_,
88+
max_omp_threads_, stencil_distribution_method_);
89+
}
90+
91+
// ----------------------------------------- //
92+
// Build direct solver on the coarsest level //
93+
// ----------------------------------------- //
94+
auto start_setup_directSolver = std::chrono::high_resolution_clock::now();
95+
levels_[number_of_levels_ - 1].initializeDirectSolver(domain_geometry_, density_profile_coefficients_,
96+
DirBC_Interior_, max_omp_threads_,
97+
stencil_distribution_method_);
98+
auto end_setup_directSolver = std::chrono::high_resolution_clock::now();
99+
t_setup_directSolver_ += std::chrono::duration<double>(end_setup_directSolver - start_setup_directSolver).count();
100+
101+
// ---------------------------------------------------------- //
102+
// Build the full-grid smoother and the extrapolated smoother //
103+
// ---------------------------------------------------------- //
104+
auto start_setup_smoother = std::chrono::high_resolution_clock::now();
105+
106+
bool do_full_grid_smoothing = false;
107+
bool do_extrapolated_smoothing = false;
108+
109+
switch (extrapolation_) {
110+
111+
case ExtrapolationType::NONE:
112+
do_full_grid_smoothing = true;
113+
break;
114+
115+
case ExtrapolationType::IMPLICIT_EXTRAPOLATION:
116+
do_extrapolated_smoothing = true;
117+
break;
118+
119+
case ExtrapolationType::IMPLICIT_FULL_GRID_SMOOTHING:
120+
do_full_grid_smoothing = true;
121+
break;
122+
123+
case ExtrapolationType::COMBINED:
124+
do_full_grid_smoothing = true;
125+
do_extrapolated_smoothing = true;
126+
break;
127+
}
128+
129+
full_grid_smoothing_ = do_full_grid_smoothing;
130+
131+
if (number_of_levels_ > 1) {
132+
if (do_full_grid_smoothing) {
133+
levels_[0].initializeSmoothing(domain_geometry_, density_profile_coefficients_, DirBC_Interior_,
134+
max_omp_threads_, stencil_distribution_method_);
134135
}
135-
// -------------------------- //
136-
// Level n-1 (coarsest Level) //
137-
// -------------------------- //
138-
else if (level_depth == number_of_levels_ - 1) {
139-
auto start_setup_directSolver = std::chrono::high_resolution_clock::now();
140-
levels_[level_depth].initializeDirectSolver(domain_geometry_, density_profile_coefficients_,
141-
DirBC_Interior_, max_omp_threads_,
142-
stencil_distribution_method_);
143-
auto end_setup_directSolver = std::chrono::high_resolution_clock::now();
144-
t_setup_directSolver_ +=
145-
std::chrono::duration<double>(end_setup_directSolver - start_setup_directSolver).count();
146-
levels_[level_depth].initializeResidual(domain_geometry_, density_profile_coefficients_, DirBC_Interior_,
147-
max_omp_threads_, stencil_distribution_method_);
136+
if (do_extrapolated_smoothing) {
137+
levels_[0].initializeExtrapolatedSmoothing(domain_geometry_, density_profile_coefficients_, DirBC_Interior_,
138+
max_omp_threads_, stencil_distribution_method_);
148139
}
149-
// ------------------- //
150-
// Intermediate levels //
151-
// ------------------- //
152-
else {
153-
auto start_setup_smoother = std::chrono::high_resolution_clock::now();
140+
for (int level_depth = 1; level_depth < number_of_levels_ - 1; level_depth++) {
154141
levels_[level_depth].initializeSmoothing(domain_geometry_, density_profile_coefficients_, DirBC_Interior_,
155142
max_omp_threads_, stencil_distribution_method_);
156-
auto end_setup_smoother = std::chrono::high_resolution_clock::now();
157-
t_setup_smoother_ += std::chrono::duration<double>(end_setup_smoother - start_setup_smoother).count();
158-
levels_[level_depth].initializeResidual(domain_geometry_, density_profile_coefficients_, DirBC_Interior_,
159-
max_omp_threads_, stencil_distribution_method_);
160143
}
161144
}
145+
auto end_setup_smoother = std::chrono::high_resolution_clock::now();
146+
t_setup_smoother_ += std::chrono::duration<double>(end_setup_smoother - start_setup_smoother).count();
162147

163148
auto end_setup = std::chrono::high_resolution_clock::now();
164149
t_setup_total_ = std::chrono::duration<double>(end_setup - start_setup).count();

0 commit comments

Comments
 (0)