From 63dc76ff15c1c8660f30e1ff1cfcb9c2f04db814 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Tue, 1 Aug 2023 12:00:50 +0200 Subject: Refactoring: instantiate WarpX class via MakeWarpX function (#4104) * move functions from main to WarpX class and make WarpX constructible only using factory method * instantiate WarpX via MakeWarpX static member function * test adding MakeWarpX to warpx_init in python wrapper * revert to the use of a simple pointer for the WarpX instance * fix issue * use finalize in python wrapper * change finalize order * move finalize * fix bug --- Source/WarpX.cpp | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'Source/WarpX.cpp') diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index a6e4f06a1..f5826fd93 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -232,11 +232,25 @@ bool WarpX::do_device_synchronize = false; WarpX* WarpX::m_instance = nullptr; +void WarpX::MakeWarpX () +{ + ParseGeometryInput(); + + ConvertLabParamsToBoost(); + ReadBCParams(); + +#ifdef WARPX_DIM_RZ + CheckGriddingForRZSpectral(); +#endif + + m_instance = new WarpX(); +} + WarpX& WarpX::GetInstance () { if (!m_instance) { - m_instance = new WarpX(); + MakeWarpX(); } return *m_instance; } @@ -244,14 +258,20 @@ WarpX::GetInstance () void WarpX::ResetInstance () { - delete m_instance; - m_instance = nullptr; + if (m_instance){ + delete m_instance; + m_instance = nullptr; + } } -WarpX::WarpX () +void +WarpX::Finalize() { - m_instance = this; + WarpX::ResetInstance(); +} +WarpX::WarpX () +{ ReadParameters(); BackwardCompatibility(); @@ -304,12 +324,6 @@ WarpX::WarpX () // Particle Boundary Buffer (i.e., scraped particles on boundary) m_particle_boundary_buffer = std::make_unique(); - // Diagnostics - multi_diags = std::make_unique(); - - /** create object for reduced diagnostics */ - reduced_diags = std::make_unique(); - Efield_aux.resize(nlevs_max); Bfield_aux.resize(nlevs_max); -- cgit v1.2.3