Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
block_adjust_cpu.cpp
Go to the documentation of this file.
1/*
2 * This file is part of Vlasiator.
3 * Copyright 2010-2024 Finnish Meteorological Institute and University of Helsinki
4 *
5 * For details of usage, see the COPYING file and read the "Rules of the Road"
6 * at http://www.physics.helsinki.fi/vlasiator/
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23#include "spatial_cell_cpu.hpp"
24#include "block_adjust_cpu.hpp"
25#include "../object_wrapper.h"
27
28namespace spatial_cell {
34 dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
35 const vector<CellID>& cells,
36 const uint popID) {
37
38 if (cells.size()==0) {
39 return;
40 }
41
42 // int computeId {phiprof::initializeTimer("Compute with_content_list")};
43 #pragma omp parallel
44 {
45 // phiprof::Timer timer {computeId};
46 #pragma omp for schedule(dynamic)
47 for (uint i=0; i<cells.size(); ++i) {
48 mpiGrid[cells[i]]->updateSparseMinValue(popID);
49 mpiGrid[cells[i]]->update_velocity_block_content_lists(popID);
50 }
51 // timer.stop();
52 } // end parallel region
53 }
54
56 dccrg::Dccrg<spatial_cell::SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
57 const vector<CellID>& cellsToAdjust,
58 const uint popID
59 ) {
60
61 const size_t n_cells = cellsToAdjust.size();
62 if (n_cells==0) {
63 return;
64 }
65
66 // int adjustId {phiprof::initializeTimer("Adjusting blocks")};
67 #pragma omp parallel
68 {
69 // phiprof::Timer timer {adjustId};
70 #pragma omp for schedule(dynamic)
71 for (size_t i=0; i < n_cells; ++i) {
72 Real density_pre_adjust=0.0;
73 Real density_post_adjust=0.0;
74 CellID cell_id=cellsToAdjust[i];
75 SpatialCell* cell = mpiGrid[cell_id];
76 vector<SpatialCell*> neighbor_ptrs;
77 // gather spatial neighbor list and gather vector with pointers to cells
78 const auto* neighbors = mpiGrid.get_neighbors_of(cell_id, Neighborhoods::NEAREST);
79 // Note: at AMR refinement boundaries this can cause blocks to propagate further
80 // than absolutely required. Face neighbours, however, are not enough as we must
81 // account for diagonal propagation.
82
83 std::unordered_set<CellID> uniqueNeighbors;
84 uniqueNeighbors.reserve(neighbors->size());
85 // find only unique neighbor cells
86 for ( const auto& [neighbor_id, dir] : *neighbors) {
87 if ((neighbor_id != 0) && (neighbor_id != cell_id)) {
88 uniqueNeighbors.insert(neighbor_id);
89 }
90 }
91 neighbor_ptrs.reserve(uniqueNeighbors.size());
92 for ( const CellID neighbor_id : uniqueNeighbors) {
93 neighbor_ptrs.push_back(mpiGrid[neighbor_id]);
94 }
95
96 if (getObjectWrapper().particleSpecies[popID].sparse_conserve_mass) {
97 for (size_t i=0; i<cell->get_number_of_velocity_blocks(popID)*WID3; ++i) {
98 density_pre_adjust += cell->get_data(popID)[i];
99 }
100 }
101
102 cell->adjust_velocity_blocks(neighbor_ptrs,popID);
103
104 if (getObjectWrapper().particleSpecies[popID].sparse_conserve_mass) {
105 for (size_t i=0; i<cell->get_number_of_velocity_blocks(popID)*WID3; ++i) {
106 density_post_adjust += cell->get_data(popID)[i];
107 }
108 if (density_post_adjust != 0.0) {
109 for (size_t i=0; i<cell->get_number_of_velocity_blocks(popID)*WID3; ++i) {
110 cell->get_data(popID)[i] *= density_pre_adjust/density_post_adjust;
111 }
112 }
113 }
114 }
115 // timer.stop();
116 } // end parallel region
117 }
118
119} //namespace
for i
Definition Dispersion.m:24
vmesh::LocalID get_number_of_velocity_blocks(const uint popID) const
void adjust_velocity_blocks(const std::vector< SpatialCell * > &spatial_neighbors, const uint popID, bool doDeleteEmptyBlocks=true)
Realf * get_data(const uint popID)
const int WID3
Definition common.h:517
float Real
Definition definitions.h:41
uint64_t CellID
Definition definitions.h:54
ObjectWrapper & getObjectWrapper()
Definition main.cpp:33
void adjust_velocity_blocks_in_cells(dccrg::Dccrg< spatial_cell::SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const vector< CellID > &cellsToAdjust, const uint popID)
void update_velocity_block_content_lists(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const vector< CellID > &cells, const uint popID)