Skip to content

Commit

Permalink
Interface to call project once every step.
Browse files Browse the repository at this point in the history
Inclusion of Dispersion in that scheme.
  • Loading branch information
ykempf committed Feb 22, 2017
1 parent 1cbee6f commit 78da501
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 40 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ version.o: version.cpp
${CMP} ${CXXFLAGS} ${FLAGS} -c version.cpp

amr_refinement_criteria.o: ${DEPS_COMMON} velocity_blocks.h amr_refinement_criteria.h amr_refinement_criteria.cpp object_factory.h
${CMP} ${CXXFLAGS} ${FLAGS} ${MATHFLAGS} -c amr_refinement_criteria.cpp
${CMP} ${CXXFLAGS} ${FLAGS} ${MATHFLAGS} -c amr_refinement_criteria.cpp ${INC_DCCRG}

memoryallocation.o: memoryallocation.cpp
${CMP} ${CXXFLAGS} ${FLAGS} -c memoryallocation.cpp ${INC_PAPI}
Expand Down Expand Up @@ -287,7 +287,7 @@ ionosphere.o: ${DEPS_SYSBOUND} sysboundary/ionosphere.h sysboundary/ionosphere.c


mesh_data_container.o: ${DEPS_COMMON} mesh_data_container.h mesh_data.h
${CMP} ${CXXFLAGS} ${FLAGS} ${MATHFLAGS} -c mesh_data_container.cpp ${INC_VLSV}
${CMP} ${CXXFLAGS} ${FLAGS} ${MATHFLAGS} -c mesh_data_container.cpp ${INC_VLSV} ${INC_DCCRG}

project_boundary.o: ${DEPS_SYSBOUND} sysboundary/project_boundary.h sysboundary/project_boundary.cpp
${CMP} ${CXXFLAGS} ${FLAGS} ${MATHFLAGS} -c sysboundary/project_boundary.cpp ${INC_DCCRG} ${INC_ZOLTAN} ${INC_BOOST} ${INC_EIGEN}
Expand Down Expand Up @@ -402,7 +402,7 @@ poisson_test.o: ${DEPS_COMMON} ${DEPS_CELL} projects/project.h projects/project.
$(CMP) $(CXXFLAGS) ${MATHFLAGS} $(FLAGS) -std=c++0x -c projects/Poisson/poisson_test.cpp ${INC_DCCRG} ${INC_ZOLTAN} ${INC_BOOST} ${INC_EIGEN}

spatial_cell.o: ${DEPS_CELL} spatial_cell.cpp
$(CMP) $(CXXFLAGS) ${MATHFLAGS} $(FLAGS) -std=c++0x -c spatial_cell.cpp $(INC_BOOST) ${INC_EIGEN} ${INC_VECTORCLASS}
$(CMP) $(CXXFLAGS) ${MATHFLAGS} $(FLAGS) -std=c++0x -c spatial_cell.cpp $(INC_BOOST) ${INC_DCCRG} ${INC_EIGEN} ${INC_VECTORCLASS}

ifeq ($(MESH),AMR)
vlasovmover.o: ${DEPS_VLSVMOVER_AMR}
Expand Down
100 changes: 64 additions & 36 deletions projects/Dispersion/Dispersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/* NOTE
* The following piece of code has to be pasted into the main loop in vlasiator.cpp
* to run the Dispersion project and get proper bin output files.
* This should be kept here for future reference and reuse!!
phiprof::stop("Propagate",computedCells,"Cells");
if(P::projectName == "Dispersion") {
vector<Real> localRho(P::xcells_ini, 0.0),
outputRho(P::xcells_ini, 0.0),
localPerBy(P::xcells_ini, 0.0),
outputPerBy(P::xcells_ini, 0.0);
for(uint i=0; i<cells.size(); i++) {
if(cells[i] <= P::xcells_ini) {
localPerBy[cells[i] - 1] = mpiGrid[cells[i]]->parameters[CellParams::PERBY];
localRho[cells[i] - 1] = mpiGrid[cells[i]]->parameters[CellParams::RHO];
}
}
MPI_Reduce(&(localPerBy[0]), &(outputPerBy[0]), P::xcells_ini, MPI_DOUBLE, MPI_SUM, MASTER_RANK, MPI_COMM_WORLD);
MPI_Reduce(&(localRho[0]), &(outputRho[0]), P::xcells_ini, MPI_DOUBLE, MPI_SUM, MASTER_RANK, MPI_COMM_WORLD);
if(myRank == MASTER_RANK) {
FILE* outputFile = fopen("perByt.bin", "ab");
fwrite(&(outputPerBy[0]), sizeof(outputPerBy[0]), P::xcells_ini, outputFile);
fclose(outputFile);
outputFile = fopen("rhot.bin", "ab");
fwrite(&(outputRho[0]), sizeof(outputRho[0]), P::xcells_ini, outputFile);
fclose(outputFile);
}
}
//Move forward in time
++P::tstep;
P::t += P::dt;
*/

#include <cstdlib>
#include <iostream>
#include <iomanip>
Expand Down Expand Up @@ -122,6 +86,70 @@ namespace projects {
RP::get("Dispersion.maxwCutoff", this->maxwCutoff);
}

void Dispersion::endTimeStep(
cuint& myRank,
const std::vector<CellID>& localCells,
const dccrg::Dccrg<spatial_cell::SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid
) const {
vector<Real> localRho(P::xcells_ini, 0.0),
outputRho(P::xcells_ini, 0.0),
localPerBx(P::xcells_ini, 0.0),
outputPerBx(P::xcells_ini, 0.0),
localPerBy(P::xcells_ini, 0.0),
outputPerBy(P::xcells_ini, 0.0),
localPerBz(P::xcells_ini, 0.0),
outputPerBz(P::xcells_ini, 0.0),
localEx(P::xcells_ini, 0.0),
outputEx(P::xcells_ini, 0.0),
localEy(P::xcells_ini, 0.0),
outputEy(P::xcells_ini, 0.0),
localEz(P::xcells_ini, 0.0),
outputEz(P::xcells_ini, 0.0);
for(uint i=0; i<localCells.size(); i++) {
if(localCells[i] <= P::xcells_ini) {
localPerBx[localCells[i] - 1] = mpiGrid[localCells[i]]->parameters[CellParams::PERBX];
localPerBy[localCells[i] - 1] = mpiGrid[localCells[i]]->parameters[CellParams::PERBY];
localPerBz[localCells[i] - 1] = mpiGrid[localCells[i]]->parameters[CellParams::PERBZ];
localRho[localCells[i] - 1] = mpiGrid[localCells[i]]->parameters[CellParams::RHO];
localEx[localCells[i] - 1] = mpiGrid[localCells[i]]->parameters[CellParams::EX];
localEy[localCells[i] - 1] = mpiGrid[localCells[i]]->parameters[CellParams::EY];
localEz[localCells[i] - 1] = mpiGrid[localCells[i]]->parameters[CellParams::EZ];
}
}

MPI_Reduce(&(localPerBx[0]), &(outputPerBx[0]), P::xcells_ini, MPI_DOUBLE, MPI_SUM, MASTER_RANK, MPI_COMM_WORLD);
MPI_Reduce(&(localPerBy[0]), &(outputPerBy[0]), P::xcells_ini, MPI_DOUBLE, MPI_SUM, MASTER_RANK, MPI_COMM_WORLD);
MPI_Reduce(&(localPerBz[0]), &(outputPerBz[0]), P::xcells_ini, MPI_DOUBLE, MPI_SUM, MASTER_RANK, MPI_COMM_WORLD);
MPI_Reduce(&(localEx[0]), &(outputEx[0]), P::xcells_ini, MPI_DOUBLE, MPI_SUM, MASTER_RANK, MPI_COMM_WORLD);
MPI_Reduce(&(localEy[0]), &(outputEy[0]), P::xcells_ini, MPI_DOUBLE, MPI_SUM, MASTER_RANK, MPI_COMM_WORLD);
MPI_Reduce(&(localEz[0]), &(outputEz[0]), P::xcells_ini, MPI_DOUBLE, MPI_SUM, MASTER_RANK, MPI_COMM_WORLD);
MPI_Reduce(&(localRho[0]), &(outputRho[0]), P::xcells_ini, MPI_DOUBLE, MPI_SUM, MASTER_RANK, MPI_COMM_WORLD);

if(myRank == MASTER_RANK) {
FILE* outputFile = fopen("perBxt.bin", "ab");
fwrite(&(outputPerBx[0]), sizeof(outputPerBx[0]), P::xcells_ini, outputFile);
fclose(outputFile);
outputFile = fopen("perByt.bin", "ab");
fwrite(&(outputPerBy[0]), sizeof(outputPerBy[0]), P::xcells_ini, outputFile);
fclose(outputFile);
outputFile = fopen("perBzt.bin", "ab");
fwrite(&(outputPerBz[0]), sizeof(outputPerBz[0]), P::xcells_ini, outputFile);
fclose(outputFile);
outputFile = fopen("rhot.bin", "ab");
fwrite(&(outputRho[0]), sizeof(outputRho[0]), P::xcells_ini, outputFile);
fclose(outputFile);
outputFile = fopen("Ext.bin", "ab");
fwrite(&(outputEx[0]), sizeof(outputEx[0]), P::xcells_ini, outputFile);
fclose(outputFile);
outputFile = fopen("Eyt.bin", "ab");
fwrite(&(outputEy[0]), sizeof(outputEy[0]), P::xcells_ini, outputFile);
fclose(outputFile);
outputFile = fopen("Ezt.bin", "ab");
fwrite(&(outputEz[0]), sizeof(outputEz[0]), P::xcells_ini, outputFile);
fclose(outputFile);
}
}

Real Dispersion::getDistribValue(creal& vx,creal& vy, creal& vz) const {
creal mass = physicalconstants::MASS_PROTON;
creal kb = physicalconstants::K_B;
Expand Down
5 changes: 5 additions & 0 deletions projects/Dispersion/Dispersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ namespace projects {
static void addParameters(void);
virtual void getParameters(void);
virtual void setCellBackgroundField(spatial_cell::SpatialCell* cell) const;
virtual void endTimeStep(
cuint& myRank,
const std::vector<CellID>& localCells,
const dccrg::Dccrg<spatial_cell::SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid
) const;
protected:
Real getDistribValue(creal& vx, creal& vy, creal& vz) const;
virtual void calcCellParameters(spatial_cell::SpatialCell* cell,creal& t);
Expand Down
5 changes: 5 additions & 0 deletions projects/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,11 @@ namespace projects {
exit(1);
}

void Project::endTimeStep(
cuint& myRank,
const std::vector<CellID>& localCells,
const dccrg::Dccrg<spatial_cell::SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid
) const { }

void Project::setCell(SpatialCell* cell) {
// Set up cell parameters:
Expand Down
9 changes: 9 additions & 0 deletions projects/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#define PROJECT_H

#include "../spatial_cell.hpp"
#include <dccrg.hpp>
#include <dccrg_cartesian_geometry.hpp>

namespace projects {
class Project {
Expand All @@ -42,6 +44,13 @@ namespace projects {
/*! Initialize project. Can be used, e.g., to read in parameters from the input file. */
virtual bool initialize();

/*! Perform some operation at each time step in the main program loop. */
virtual void endTimeStep(
cuint& myRank,
const std::vector<CellID>& localCells,
const dccrg::Dccrg<spatial_cell::SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid
) const;

bool initialized();

/*! set background field, should set it for all cells.
Expand Down
6 changes: 5 additions & 1 deletion vlasiator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,11 @@ int main(int argn,char* args[]) {
);

phiprof::stop("Propagate",computedCells,"Cells");


phiprof::start("Project endTimeStep");
project->endTimeStep(myRank, cells, mpiGrid);
phiprof::stop("Project endTimeStep");

// Check timestep
if (P::dt < P::bailout_min_dt) {
stringstream s;
Expand Down

0 comments on commit 78da501

Please sign in to comment.