Skip to content

Commit cc2aa18

Browse files
committed
added time refinement for E
1 parent b918929 commit cc2aa18

File tree

9 files changed

+148
-246
lines changed

9 files changed

+148
-246
lines changed

src/amr/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ set( SOURCES_INC
1111
data/field/coarsening/field_coarsen_index_weight.hpp
1212
data/field/coarsening/coarsen_weighter.hpp
1313
data/field/coarsening/default_field_coarsener.hpp
14-
data/field/coarsening/magnetic_field_coarsener.hpp
1514
data/field/coarsening/electric_field_coarsener.hpp
1615
data/field/field_data.hpp
1716
data/field/field_data_factory.hpp

src/amr/data/field/coarsening/electric_field_coarsener.hpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88

99
#include <SAMRAI/hier/Box.h>
10+
#include <cstddef>
1011
#include <stdexcept>
1112

1213
namespace PHARE::amr
@@ -35,7 +36,7 @@ class ElectricFieldCoarsener
3536
ElectricFieldCoarsener(std::array<core::QtyCentering, dimension> const centering,
3637
SAMRAI::hier::Box const& sourceBox,
3738
SAMRAI::hier::Box const& destinationBox,
38-
SAMRAI::hier::IntVector const& ratio)
39+
SAMRAI::hier::IntVector const& /*ratio*/)
3940
: centering_{centering}
4041
, sourceBox_{sourceBox}
4142
, destinationBox_{destinationBox}
@@ -52,15 +53,9 @@ class ElectricFieldCoarsener
5253

5354
core::Point<int, dimension> fineStartIndex;
5455

55-
fineStartIndex[dirX] = coarseIndex[dirX] * this->ratio_;
56-
57-
if constexpr (dimension > 1)
56+
for (auto i = std::size_t{0}; i < dimension; ++i)
5857
{
59-
fineStartIndex[dirY] = coarseIndex[dirY] * this->ratio_;
60-
if constexpr (dimension > 2)
61-
{
62-
fineStartIndex[dirZ] = coarseIndex[dirZ] * this->ratio_;
63-
}
58+
fineStartIndex[i] = coarseIndex[i] * this->ratio_;
6459
}
6560

6661
fineStartIndex = AMRToLocal(fineStartIndex, sourceBox_);

src/amr/data/field/coarsening/magnetic_field_coarsener.hpp

Lines changed: 0 additions & 140 deletions
This file was deleted.

src/amr/messengers/hybrid_hybrid_messenger_strategy.hpp

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "synchronizer_pool.hpp"
1313
#include "amr/data/field/coarsening/field_coarsen_operator.hpp"
1414
#include "amr/data/field/coarsening/default_field_coarsener.hpp"
15-
#include "amr/data/field/coarsening/magnetic_field_coarsener.hpp"
1615
#include "amr/data/field/coarsening/electric_field_coarsener.hpp"
1716
#include "amr/data/field/refine/field_refiner.hpp"
1817
#include "amr/data/field/refine/magnetic_field_refiner.hpp"
@@ -100,7 +99,6 @@ namespace amr
10099

101100
template<typename Policy>
102101
using BaseCoarsenOp = FieldCoarsenOperator<GridLayoutT, GridT, Policy>;
103-
using MagneticCoarsenOp = BaseCoarsenOp<MagneticFieldCoarsener<dimension>>;
104102
using DefaultCoarsenOp = BaseCoarsenOp<DefaultFieldCoarsener<dimension>>;
105103
using ElectricFieldCoarsenOp = BaseCoarsenOp<ElectricFieldCoarsener<dimension>>;
106104

@@ -118,6 +116,7 @@ namespace amr
118116
resourcesManager_->registerResources(Jold_);
119117
resourcesManager_->registerResources(NiOld_);
120118
resourcesManager_->registerResources(ViOld_);
119+
resourcesManager_->registerResources(Eold_);
121120
}
122121

123122
virtual ~HybridHybridMessengerStrategy() = default;
@@ -138,6 +137,7 @@ namespace amr
138137
resourcesManager_->allocate(Jold_, patch, allocateTime);
139138
resourcesManager_->allocate(NiOld_, patch, allocateTime);
140139
resourcesManager_->allocate(ViOld_, patch, allocateTime);
140+
resourcesManager_->allocate(Eold_, patch, allocateTime);
141141
}
142142

143143

@@ -328,21 +328,6 @@ namespace amr
328328
patchGhostPartRefiners_.fill(levelNumber, initDataTime);
329329

330330

331-
// regriding will fill the new level wherever it has points that overlap
332-
// old level. This will include its level border points.
333-
// These new level border points will thus take values that where previous
334-
// domain values. Magnetic flux is thus not necessarily consistent with
335-
// the Loring et al. method to sync the induction between coarse and fine faces.
336-
// Specifically, we need all fine faces to have equal magnetic field and also
337-
// equal to that of the shared coarse face.
338-
// This means that we now need to fill ghosts and border included
339-
340-
if (!isRegriddingL0)
341-
{
342-
auto& E = hybridModel.state.electromag.E;
343-
elecGhostsRefiners_.fill(E, levelNumber, initDataTime);
344-
}
345-
346331
// we now call only levelGhostParticlesOld.fill() and not .regrid()
347332
// regrid() would refine from next coarser in regions of level not overlaping
348333
// oldLevel, but copy from domain particles of oldLevel where there is an
@@ -638,19 +623,23 @@ namespace amr
638623
for (auto& patch : level)
639624
{
640625
auto dataOnPatch = resourcesManager_->setOnPatch(
641-
*patch, hybridModel.state.J, hybridModel.state.ions, Jold_, NiOld_, ViOld_);
626+
*patch, hybridModel.state.electromag, hybridModel.state.J,
627+
hybridModel.state.ions, Jold_, NiOld_, ViOld_, Eold_);
642628

643629
resourcesManager_->setTime(Jold_, *patch, currentTime);
644630
resourcesManager_->setTime(NiOld_, *patch, currentTime);
645631
resourcesManager_->setTime(ViOld_, *patch, currentTime);
632+
resourcesManager_->setTime(Eold_, *patch, currentTime);
646633

647634
auto& J = hybridModel.state.J;
648635
auto& Vi = hybridModel.state.ions.velocity();
649636
auto& Ni = hybridModel.state.ions.chargeDensity();
637+
auto& E = hybridModel.state.electromag.E;
650638

651639
Jold_.copyData(J);
652640
ViOld_.copyData(Vi);
653641
NiOld_.copyData(Ni);
642+
Eold_.copyData(E);
654643
}
655644
}
656645

@@ -707,7 +696,7 @@ namespace amr
707696
double const syncTime) override
708697
{
709698
refluxSchedules[fineLevelNumber]->coarsenData();
710-
ghostRefluxedSchedules[coarserLevelNumber]->fillData(syncTime);
699+
patchGhostRefluxedSchedules[coarserLevelNumber]->fillData(syncTime);
711700
}
712701

713702
// after coarsening, domain nodes have been updated and therefore patch ghost nodes
@@ -751,11 +740,13 @@ namespace amr
751740
return keys;
752741
};
753742

754-
elecSharedNodesRefiners_.addStaticRefiners(info->ghostElectric, EfieldNodeRefineOp_,
755-
makeKeys(info->ghostElectric));
743+
elecSharedNodesRefiners_.addTimeRefiners(info->ghostElectric, info->ghostElectric,
744+
core::VecFieldNames{Eold_},
745+
EfieldNodeRefineOp_, fieldTimeOp_);
756746

757-
elecGhostsRefiners_.addStaticRefiners(info->ghostElectric, EfieldRefineOp_,
758-
makeKeys(info->ghostElectric));
747+
elecGhostsRefiners_.addTimeRefiners(info->ghostElectric, info->ghostElectric,
748+
core::VecFieldNames{Eold_}, EfieldRefineOp_,
749+
fieldTimeOp_);
759750

760751
currentSharedNodesRefiners_.addTimeRefiners(info->ghostCurrent, info->modelCurrent,
761752
core::VecFieldNames{Jold_},
@@ -814,9 +805,6 @@ namespace amr
814805

815806
void registerSyncComms(std::unique_ptr<HybridMessengerInfo> const& info)
816807
{
817-
magnetoSynchronizers_.add(info->modelMagnetic, magneticCoarseningOp_,
818-
info->modelMagnetic.vecName);
819-
820808
electroSynchronizers_.add(info->modelElectric, electricFieldCoarseningOp_,
821809
info->modelElectric.vecName);
822810

@@ -1057,6 +1045,7 @@ namespace amr
10571045
VecFieldT Jold_{stratName + "_Jold", core::HybridQuantity::Vector::J};
10581046
VecFieldT ViOld_{stratName + "_VBulkOld", core::HybridQuantity::Vector::V};
10591047
FieldT NiOld_{stratName + "_NiOld", core::HybridQuantity::Scalar::rho};
1048+
VecFieldT Eold_{stratName + "_Eold", core::HybridQuantity::Vector::E};
10601049

10611050

10621051
//! ResourceManager shared with other objects (like the HybridModel)
@@ -1154,7 +1143,6 @@ namespace amr
11541143

11551144
using CoarsenOperator_ptr = std::shared_ptr<SAMRAI::hier::CoarsenOperator>;
11561145
CoarsenOperator_ptr fieldCoarseningOp_{std::make_shared<DefaultCoarsenOp>()};
1157-
CoarsenOperator_ptr magneticCoarseningOp_{std::make_shared<MagneticCoarsenOp>()};
11581146
CoarsenOperator_ptr electricFieldCoarseningOp_{std::make_shared<ElectricFieldCoarsenOp>()};
11591147

11601148
MagneticRefinePatchStrategy<ResourcesManagerT, FieldDataT> magneticRefinePatchStrategy_{

src/amr/messengers/refiner_pool.hpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ namespace amr
6666
std::shared_ptr<SAMRAI::hier::TimeInterpolateOperator>& timeOp);
6767

6868

69+
void addTimeRefiners(std::vector<core::VecFieldNames> const& destinations,
70+
std::vector<core::VecFieldNames> const& sources,
71+
core::VecFieldNames const& oldSource,
72+
std::shared_ptr<RefineOperator>& refineOp,
73+
std::shared_ptr<SAMRAI::hier::TimeInterpolateOperator>& timeOp);
6974

7075
/**
7176
* add a refiner that will use time and spatial interpolation.
@@ -126,7 +131,7 @@ namespace amr
126131

127132
/** @brief executes a regridding for all quantities in the pool.*/
128133
virtual void regrid(std::shared_ptr<SAMRAI::hier::PatchHierarchy> const& hierarchy,
129-
const int levelNumber,
134+
int const levelNumber,
130135
std::shared_ptr<SAMRAI::hier::PatchLevel> const& oldLevel,
131136
double const initDataTime)
132137
{
@@ -215,6 +220,20 @@ namespace amr
215220
}
216221
}
217222

223+
template<typename ResourcesManager, RefinerType Type>
224+
void RefinerPool<ResourcesManager, Type>::addTimeRefiners(
225+
std::vector<core::VecFieldNames> const& destinations,
226+
std::vector<core::VecFieldNames> const& sources, core::VecFieldNames const& oldSource,
227+
std::shared_ptr<RefineOperator>& refineOp,
228+
std::shared_ptr<SAMRAI::hier::TimeInterpolateOperator>& timeOp)
229+
{
230+
for (std::size_t i = 0; i < destinations.size(); ++i)
231+
{
232+
addTimeRefiner(destinations[i], sources[i], oldSource, refineOp, timeOp,
233+
destinations[i].vecName);
234+
}
235+
}
236+
218237
template<typename ResourcesManager, RefinerType Type>
219238
void RefinerPool<ResourcesManager, Type>::addTimeRefiner(
220239
core::VecFieldNames const& ghost, core::VecFieldNames const& model,

src/amr/multiphysics_integrator.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,14 +575,15 @@ namespace solver
575575
toCoarser.synchronize(fineLevel);
576576

577577
// refluxing
578+
auto& fineSolver = getSolver_(ilvl);
578579
auto iCoarseLevel = ilvl - 1;
579580
auto& coarseLevel = *hierarchy->getPatchLevel(iCoarseLevel);
580581
auto& coarseSolver = getSolver_(iCoarseLevel);
581582
auto& coarseModel = getModel_(iCoarseLevel);
582583

583584
toCoarser.reflux(iCoarseLevel, ilvl, syncTime);
584585
coarseSolver.reflux(coarseModel, coarseLevel, syncTime);
585-
coarseSolver.resetFluxSum(coarseModel, fineLevel);
586+
fineSolver.resetFluxSum(coarseModel, fineLevel);
586587

587588
// recopy (patch) ghosts
588589
toCoarser.postSynchronize(coarseModel, coarseLevel, syncTime);

src/amr/solvers/solver_ppc.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,12 +535,17 @@ void SolverPPC<HybridModel, AMR_Types>::average_(level_t& level, ModelViews_t& v
535535
{
536536
PHARE_LOG_SCOPE(1, "SolverPPC::average_");
537537

538+
TimeSetter setTime{views, newTime};
539+
538540
for (auto& state : views)
539541
{
540542
PHARE::core::average(state.electromag.B, state.electromagPred.B, state.electromagAvg.B);
541543
PHARE::core::average(state.electromag.E, state.electromagPred.E, state.electromagAvg.E);
542544
}
543545

546+
setTime([](auto& state) -> auto& { return state.electromagAvg.B; });
547+
setTime([](auto& state) -> auto& { return state.electromagAvg.E; });
548+
544549
// the following will fill E on all edges of all ghost cells, including those
545550
// on domain border. For level ghosts, electric field will be obtained from
546551
// next coarser level E average

0 commit comments

Comments
 (0)