55// Licensed under CeCILL 2.1 License, see COPYING for more information
66// ***********************************************************************************
77
8-
9-
8+ #include < memory>
109#include < string>
1110#include < vector>
1211
@@ -106,20 +105,6 @@ void SelfGravity::Init(Input &input, DataBlock *datain) {
106105 }
107106 }
108107
109- // Update internal boundaries in case of domain decomposition
110- #ifdef WITH_MPI
111- for (int dir = 0 ; dir < DIMENSIONS ; dir++) {
112- if (data->mygrid ->nproc [dir]>1 ) {
113- if (this ->data ->lbound [dir]==internal ) {
114- this ->lbound [dir] = Laplacian::internalgrav;
115- }
116- if (this ->data ->rbound [dir]==internal) {
117- this ->rbound [dir] = Laplacian::internalgrav;
118- }
119- }
120- }
121- #endif
122-
123108 // Update solver when provided
124109 if (input.CheckEntry (" SelfGravity" ," solver" ) >= 0 ) {
125110 std::string strSolver = input.Get <std::string>(" SelfGravity" ," solver" ,0 );
@@ -162,29 +147,28 @@ void SelfGravity::Init(Input &input, DataBlock *datain) {
162147 }
163148
164149 // Make the Laplacian operator
165- laplacian = Laplacian (data, lbound, rbound, this ->havePreconditioner );
150+ laplacian = std::make_unique< Laplacian> (data, lbound, rbound, this ->havePreconditioner );
166151
167- np_tot = laplacian. np_tot ;
152+ np_tot = laplacian-> np_tot ;
168153
169154 // Instantiate the bicgstab solver
170155 if (solver == BICGSTAB || solver == PBICGSTAB) {
171- iterativeSolver = new Bicgstab (laplacian, targetError, maxiter,
172- laplacian. np_tot , laplacian. beg , laplacian. end );
156+ iterativeSolver = new Bicgstab (* laplacian. get () , targetError, maxiter,
157+ laplacian-> np_tot , laplacian-> beg , laplacian-> end );
173158 } else if (solver == CG || solver == PCG) {
174- iterativeSolver = new Cg (laplacian, targetError, maxiter,
175- laplacian. np_tot , laplacian. beg , laplacian. end );
159+ iterativeSolver = new Cg (* laplacian. get () , targetError, maxiter,
160+ laplacian-> np_tot , laplacian-> beg , laplacian-> end );
176161 } else if (solver == MINRES || solver == PMINRES) {
177- iterativeSolver = new Minres (laplacian,
162+ iterativeSolver = new Minres (* laplacian. get () ,
178163 targetError, maxiter,
179- laplacian. np_tot , laplacian. beg , laplacian. end );
164+ laplacian-> np_tot , laplacian-> beg , laplacian-> end );
180165 } else {
181- real step = laplacian. ComputeCFL ();
182- iterativeSolver = new Jacobi (laplacian, targetError, maxiter, step,
183- laplacian. np_tot , laplacian. beg , laplacian. end );
166+ real step = laplacian-> ComputeCFL ();
167+ iterativeSolver = new Jacobi (* laplacian. get () , targetError, maxiter, step,
168+ laplacian-> np_tot , laplacian-> beg , laplacian-> end );
184169 }
185170
186171
187-
188172 // Arrays initialisation
189173 this ->density = IdefixArray3D<real> (" Density" , this ->np_tot [KDIR],
190174 this ->np_tot [JDIR],
@@ -246,7 +230,7 @@ void SelfGravity::ShowConfig() {
246230 }
247231
248232 if (this ->lbound [IDIR] == Laplacian::LaplacianBoundaryType::origin) {
249- idfx::cout << " SelfGravity: using origin boundary with " << laplacian. loffset [IDIR]
233+ idfx::cout << " SelfGravity: using origin boundary with " << laplacian-> loffset [IDIR]
250234 << " additional radial points." << std::endl;
251235 }
252236
@@ -268,9 +252,9 @@ void SelfGravity::InitSolver() {
268252
269253 // Initialise the density field
270254 // todo: check bounds
271- int ioffset = laplacian. loffset [IDIR];
272- int joffset = laplacian. loffset [JDIR];
273- int koffset = laplacian. loffset [KDIR];
255+ int ioffset = laplacian-> loffset [IDIR];
256+ int joffset = laplacian-> loffset [JDIR];
257+ int koffset = laplacian-> loffset [KDIR];
274258
275259 idefix_for (" InitDensity" , data->beg [KDIR], data->end [KDIR],
276260 data->beg [JDIR], data->end [JDIR],
@@ -300,13 +284,13 @@ void SelfGravity::InitSolver() {
300284 // divide density by preconditionner if we're doing the preconditionned version
301285 if (havePreconditioner) {
302286 int ibeg, iend, jbeg, jend, kbeg, kend;
303- ibeg = laplacian. beg [IDIR];
304- iend = laplacian. end [IDIR];
305- jbeg = laplacian. beg [JDIR];
306- jend = laplacian. end [JDIR];
307- kbeg = laplacian. beg [KDIR];
308- kend = laplacian. end [KDIR];
309- IdefixArray3D<real> P = laplacian. precond ;
287+ ibeg = laplacian-> beg [IDIR];
288+ iend = laplacian-> end [IDIR];
289+ jbeg = laplacian-> beg [JDIR];
290+ jend = laplacian-> end [JDIR];
291+ kbeg = laplacian-> beg [KDIR];
292+ kend = laplacian-> end [KDIR];
293+ IdefixArray3D<real> P = laplacian-> precond ;
310294 idefix_for (" Precond density" , kbeg, kend, jbeg, jend, ibeg, iend,
311295 KOKKOS_LAMBDA (int k, int j, int i) {
312296 density (k, j, i) = density (k,j,i) / P (k,j,i);
@@ -330,11 +314,6 @@ void SelfGravity::InitSolver() {
330314 throw std::runtime_error (msg.str ());
331315 }
332316
333-
334- #ifdef DEBUG_GRAVITY
335- WriteField (rhoFile, density);
336- #endif
337-
338317 idfx::popRegion ();
339318}
340319
@@ -344,15 +323,15 @@ void SelfGravity::SubstractMeanDensity() {
344323
345324 // Loading needed attributes
346325 IdefixArray3D<real> density = this ->density ;
347- IdefixArray3D<real> dV = laplacian. dV ;
326+ IdefixArray3D<real> dV = laplacian-> dV ;
348327
349328 int ibeg, iend, jbeg, jend, kbeg, kend;
350- ibeg = laplacian. beg [IDIR];
351- iend = laplacian. end [IDIR];
352- jbeg = laplacian. beg [JDIR];
353- jend = laplacian. end [JDIR];
354- kbeg = laplacian. beg [KDIR];
355- kend = laplacian. end [KDIR];
329+ ibeg = laplacian-> beg [IDIR];
330+ iend = laplacian-> end [IDIR];
331+ jbeg = laplacian-> beg [JDIR];
332+ jend = laplacian-> end [JDIR];
333+ kbeg = laplacian-> beg [KDIR];
334+ kend = laplacian-> end [KDIR];
356335
357336 // Do the reduction on a vector
358337 MyVector meanDensityVector;
@@ -386,59 +365,22 @@ void SelfGravity::SubstractMeanDensity() {
386365 density (k, j, i) -= mean;
387366 });
388367
389- #ifdef DEBUG_GRAVITY
390- idfx::cout << " SelfGravity:: Average value " << mean << " substracted to density" << std::endl;
391- #endif
392-
393368 idfx::popRegion ();
394369}
395370
396371void SelfGravity::EnrollUserDefBoundary (Laplacian::UserDefBoundaryFunc myFunc) {
397- laplacian. EnrollUserDefBoundary (myFunc);
372+ laplacian-> EnrollUserDefBoundary (myFunc);
398373}
399374
400375
401376
402-
403- #ifdef DEBUG_GRAVITY
404- // This routine is for debugging purpose
405- void SelfGravity::WriteField (std::ofstream &stream, IdefixArray3D<real> &in, int index) {
406- stream.precision (15 );
407- stream << std::scientific;// << index;
408- for (int i = 0 ; i < this ->np_tot [IDIR] ; i++) {
409- stream << in (0 ,0 ,i) << " \t " ;
410- }
411- stream << std::endl;
412- }
413-
414- void SelfGravity::WriteField (std::ofstream &stream, IdefixArray1D<real> &in, int index) {
415- stream.precision (15 );
416- stream << std::scientific;// << index;
417- for (int i = 0 ; i < this ->np_tot [IDIR] ; i++) {
418- stream << in (i) << " \t " ;
419- }
420- stream << std::endl;
421- }
422- #endif
423-
424377void SelfGravity::SolvePoisson () {
425378 idfx::pushRegion (" SelfGravity::SolvePoisson" );
426379
427380 Kokkos::Timer timer;
428381
429382 elapsedTime -= timer.seconds ();
430383
431- #ifdef DEBUG_GRAVITY
432- rhoFile.open (" rho.dat" ,std::ios::trunc);
433- potentialFile.open (" potential.dat" ,std::ios::trunc);
434- geometryFile.open (" geometry.dat" ,std::ios::trunc);
435- WriteField (geometryFile,this ->x [IDIR]);
436- WriteField (geometryFile,this ->dx [IDIR]);
437- WriteField (geometryFile,this ->A [IDIR]);
438- WriteField (geometryFile,this ->dV );
439- geometryFile.close ();
440- #endif
441-
442384 InitSolver (); // (Re)initialise the solver
443385
444386 this ->nsteps = iterativeSolver->Solve (potential, density);
@@ -472,19 +414,6 @@ void SelfGravity::SolvePoisson() {
472414
473415 currentError = iterativeSolver->GetError ();
474416
475- #ifdef DEBUG_GRAVITY
476- WriteField (potentialFile,potential,n);
477- if (this ->convStatus == true ) {
478- idfx::cout << " SelfGravity:: Reached convergence after " << n << " iterations" << std::endl;
479- rhoFile.close ();
480- potentialFile.close ();
481- } else if (n == maxiter) {
482- idfx::cout << " SelfGravity:: Reached max iter" << std::endl;
483- rhoFile.close ();
484- potentialFile.close ();
485- IDEFIX_WARNING (" SelfGravity:: Failed to converge before reaching max iter" );
486- }
487- #endif
488417
489418 elapsedTime += timer.seconds ();
490419 idfx::popRegion ();
@@ -499,12 +428,12 @@ void SelfGravity::AddSelfGravityPotential(IdefixArray3D<real> &phiP) {
499428 real gravCst = this ->data ->gravity ->gravCst ;
500429
501430 // Updating ghost cells before to return potential
502- laplacian. SetBoundaries (potential);
431+ laplacian-> SetBoundaries (potential);
503432
504433 // Adding self-gravity contribution
505- int ioffset = laplacian. loffset [IDIR];
506- int joffset = laplacian. loffset [JDIR];
507- int koffset = laplacian. loffset [KDIR];
434+ int ioffset = laplacian-> loffset [IDIR];
435+ int joffset = laplacian-> loffset [JDIR];
436+ int koffset = laplacian-> loffset [KDIR];
508437 idefix_for (" AddSelfGravityPotential" , 0 , data->np_tot [KDIR],
509438 0 , data->np_tot [JDIR],
510439 0 , data->np_tot [IDIR],
0 commit comments