Skip to content

Commit

Permalink
Merge pull request #41 from HSU-HPC/refactor-Macroscopic2CouplingCell
Browse files Browse the repository at this point in the history
Rename MacroscopicCell to CouplingCell
  • Loading branch information
Thinkpiet authored Feb 21, 2024
2 parents 81acf22 + cc274e5 commit 174effc
Show file tree
Hide file tree
Showing 177 changed files with 3,835 additions and 3,830 deletions.
20 changes: 10 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,10 @@ set(CLANGFORMAT_SOURCES
"tarch/la/Matrix.h"
"tarch/TarchDefinitions.h"
"coupling/services/MultiMDCellService.h"
"coupling/services/MacroscopicCellServiceMacroOnly.h"
"coupling/services/MacroscopicCellService.cpph"
"coupling/services/MacroscopicCellTraversalWrappers.cpph"
"coupling/services/MacroscopicCellService.h"
"coupling/services/CouplingCellServiceMacroOnly.h"
"coupling/services/CouplingCellService.cpph"
"coupling/services/CouplingCellTraversalWrappers.cpph"
"coupling/services/CouplingCellService.h"
"coupling/ErrorEstimation.h"
"coupling/ParticleInsertion.h"
"coupling/SetGivenVelocity4MomentumInsertion.h"
Expand Down Expand Up @@ -543,7 +543,7 @@ set(CLANGFORMAT_SOURCES
"coupling/python-binding/mamico.cpp"
"coupling/python-binding/conversion.h"
"coupling/NoParticleInsertion.h"
"coupling/MacroscopicCellPlotter.h"
"coupling/CouplingCellPlotter.h"
"coupling/NoMomentumInsertion.h"
"coupling/cell-mappings/ComputeKineticEnergyMapping.h"
"coupling/cell-mappings/MoleculeExtractor.h"
Expand Down Expand Up @@ -596,9 +596,9 @@ set(CLANGFORMAT_SOURCES
"coupling/paralleltopology/ZYXTopology.h"
"coupling/paralleltopology/XYZTopology.h"
"coupling/paralleltopology/ParallelTopologyFactory.h"
"coupling/datastructures/MacroscopicCells.h"
"coupling/datastructures/MacroscopicCell.h"
"coupling/datastructures/MacroscopicCells.cpph"
"coupling/datastructures/CouplingCells.h"
"coupling/datastructures/CouplingCell.h"
"coupling/datastructures/CouplingCells.cpph"
"coupling/datastructures/Molecule.h"
"coupling/MultiMDMediator.h"
"coupling/configurations/ParticleInsertionConfiguration.h"
Expand All @@ -608,9 +608,9 @@ set(CLANGFORMAT_SOURCES
"coupling/configurations/MaMiCoConfiguration.cpph"
"coupling/configurations/MomentumInsertionConfiguration.h"
"coupling/configurations/ParallelTopologyConfiguration.h"
"coupling/configurations/MacroscopicCellConfiguration.h"
"coupling/configurations/CouplingCellConfiguration.h"
"coupling/configurations/ParticleInsertionConfiguration.cpp"
"coupling/configurations/MacroscopicCellConfiguration.cpph"
"coupling/configurations/CouplingCellConfiguration.cpph"
"coupling/configurations/MaMiCoConfiguration.h"
"coupling/configurations/ThermostatConfiguration.h"
"coupling/configurations/TimeIntegrationConfiguration.h"
Expand Down
20 changes: 10 additions & 10 deletions coupling/AdditiveMomentumInsertion.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "coupling/MomentumInsertion.h"
#include "coupling/cell-mappings/ComputeMassMapping.h"
#include "coupling/cell-mappings/SetMomentumMapping.h"
#include "coupling/datastructures/MacroscopicCell.h"
#include "coupling/datastructures/CouplingCell.h"
#include "tarch/la/Vector.h"

/** @brief everything necessary for coupling operations, is defined in here */
Expand All @@ -17,10 +17,10 @@ template <class LinkedCell, unsigned int dim> class AdditiveMomentumInsertion;
}

/** This class allows to add momentum to molecules. In each MD timestep, it
* takes a respective fraction from the momentum buffer of a macroscopic cell
* and adds this momentum to the molecules of the macroscopic cell.
* takes a respective fraction from the momentum buffer of a coupling cell
* and adds this momentum to the molecules of the coupling cell.
* @brief used to manipulate the momentum/velocity of the molecules contained
* in a macroscopic cell.
* in a coupling cell.
* @tparam LinkedCell the LinkedCell class is given by the implementation of
* linked cells in the molecular dynamics simulation
* @tparam dim the integer dim refers to the spacial dimension of the
Expand All @@ -45,15 +45,15 @@ template <class LinkedCell, unsigned int dim> class coupling::AdditiveMomentumIn
* @returns 1 */
virtual unsigned int getTimeIntervalPerMomentumInsertion() const { return 1; }

/** inserts the momentum of the macroscopic cell and distributes it over all
/** inserts the momentum of the coupling cell and distributes it over all
* molecules. This method does not conserve the kinetic energy of the
* respective macroscopic cell. To conserve the energy as well, see the
* respective coupling cell. To conserve the energy as well, see the
* description of MomentumController on details how to do that.
* @brief inserts momentum to the cell
* @param cell macroscopic cell to insert momentum to
* @param currentMacroscopicCellIndex macroscopic cell index of the cell */
virtual void insertMomentum(coupling::datastructures::MacroscopicCellWithLinkedCells<LinkedCell, dim>& cell,
const unsigned int& currentMacroscopicCellIndex) const {
* @param cell coupling cell to insert momentum to
* @param currentCouplingCellIndex coupling cell index of the cell */
virtual void insertMomentum(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell,
const unsigned int& currentCouplingCellIndex) const {
const unsigned int timeIntervalMomentumInsertion = getTimeIntervalPerMomentumInsertion();
// determine fraction of momentum that is to be inserted in this frame
double fraction = 1.0 / ((_numberMDTimestepsPerCouplingCycle / timeIntervalMomentumInsertion) +
Expand Down
16 changes: 8 additions & 8 deletions coupling/BoundaryForceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
#ifndef _MOLECULARDYNAMICS_COUPLING_BOUNDARYFORCECONTROLLER_H_
#define _MOLECULARDYNAMICS_COUPLING_BOUNDARYFORCECONTROLLER_H_

#include "coupling/datastructures/MacroscopicCell.h"
#include "coupling/datastructures/CouplingCell.h"
#include "coupling/interface/MDSolverInterface.h"

namespace coupling {
template <class LinkedCell, unsigned int dim> class BoundaryForceController;
}

/** There is an interface method applyBoundaryForce which triggers potential
* boundary forcing in each macroscopic cell that is located at the very outer
* MD boundary (first layer of non-ghost macroscopic cells).
* boundary forcing in each coupling cell that is located at the very outer
* MD boundary (first layer of non-ghost coupling cells).
* @brief controller for forces acting at open MD boundaries
* @tparam LinkedCell the LinkedCell class is given by the implementation of
* linked cells in the molecular dynamics simulation
Expand All @@ -30,14 +30,14 @@ template <class LinkedCell, unsigned int dim> class coupling::BoundaryForceContr
/**@brief A simple destructor*/
virtual ~BoundaryForceController() {}

/** iterates over all linked cells of the given macroscopic cell and applies
/** iterates over all linked cells of the given coupling cell and applies
* the cellmapping for the boundary force
* @brief applies the boundary force on a boundary cell
* @param cell the macroscopic boundary cell to apply the boundary force
* @param currentLocalMacroscopicCellIndex the index of the macroscopic cell
* @param cell the boundary coupling cell to apply the boundary force
* @param currentLocalCouplingCellIndex the index of the coupling cell
*/
virtual void applyBoundaryForce(coupling::datastructures::MacroscopicCellWithLinkedCells<LinkedCell, dim>& cell,
const unsigned int& currentLocalMacroscopicCellIndex) = 0;
virtual void applyBoundaryForce(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell,
const unsigned int& currentLocalCouplingCellIndex) = 0;

/** @brief calculates the potential energy for a given position
* @param position the position for which the potential energy will be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@
// This file is part of the Mamico project. For conditions of distribution
// and use, please see the copyright notice in Mamico's main folder, or at
// www5.in.tum.de/mamico
#ifndef _MOLECULARDYNAMICS_COUPLING_MACROSCOPICCELLPLOTTER_H_
#define _MOLECULARDYNAMICS_COUPLING_MACROSCOPICCELLPLOTTER_H_
#ifndef _MOLECULARDYNAMICS_COUPLING_COUPLINGCELLPLOTTER_H_
#define _MOLECULARDYNAMICS_COUPLING_COUPLINGCELLPLOTTER_H_

#include "coupling/IndexConversion.h"
#include "coupling/KineticEnergyController.h"
#include "coupling/cell-mappings/ComputeMassMapping.h"
#include "coupling/cell-mappings/ComputeMomentumMapping.h"
#include "coupling/cell-mappings/VTKMoleculePlotter.h"
#include "coupling/datastructures/MacroscopicCells.h"
#include "coupling/datastructures/CouplingCells.h"
#include "coupling/interface/MDSolverInterface.h"
#include "tarch/la/Vector.h"
#include <fstream>
#include <sstream>

namespace coupling {
template <class LinkedCell, unsigned int dim> class MacroscopicCellPlotter;
template <class LinkedCell, unsigned int dim> class CouplingCellPlotter;
}

/** @brief plots the macroscopic cell data.
/** @brief plots the coupling cell data.
* @author Philipp Neumann
* @tparam LinkedCell the LinkedCell class is given by the implementation of
* linked cells in the molecular dynamics simulation
* @tparam dim refers to the spacial dimension of the simulation, can be 1, 2,
* or 3*/
template <class LinkedCell, unsigned int dim> class coupling::MacroscopicCellPlotter {
template <class LinkedCell, unsigned int dim> class coupling::CouplingCellPlotter {
public:
/** @brief a simple constructor
* @param ID the id of the md simulation
* @param filename name for the file
* @param rank mpi rank of the current process
* @param t number of time step to plot
* @param indexConversion indexConversion instance of the current simulation
* @param cells macroscopic cells to plot
* @param cells coupling cells to plot
* @param mdSolverInterface interface of the md solver */
MacroscopicCellPlotter(unsigned int ID, std::string filename, unsigned int rank, unsigned int t, const coupling::IndexConversion<dim>& indexConversion,
coupling::datastructures::MacroscopicCells<LinkedCell, dim>& cells,
coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface) {
CouplingCellPlotter(unsigned int ID, std::string filename, unsigned int rank, unsigned int t, const coupling::IndexConversion<dim>& indexConversion,
coupling::datastructures::CouplingCells<LinkedCell, dim>& cells,
coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface) {
plotMoleculeFile(ID, filename, rank, t, cells, mdSolverInterface);
plotMacroscopicCellFile(ID, filename, rank, t, indexConversion, cells, mdSolverInterface);
plotCouplingCellFile(ID, filename, rank, t, indexConversion, cells, mdSolverInterface);
}

/** @brief a simple destructor*/
~MacroscopicCellPlotter() {}
~CouplingCellPlotter() {}

private:
/** the file will contain the velocity, position, and potentials of the
Expand All @@ -54,10 +54,10 @@ template <class LinkedCell, unsigned int dim> class coupling::MacroscopicCellPlo
* @param filename name for the file
* @param rank mpi rank of the current process
* @param t number of time step to plot
* @param cells macroscopic cells to plot
* @param cells coupling cells to plot
* @param mdSolverInterface interface of the md solver */
void plotMoleculeFile(unsigned int ID, std::string filename, unsigned int rank, unsigned int t,
coupling::datastructures::MacroscopicCells<LinkedCell, dim>& cells,
coupling::datastructures::CouplingCells<LinkedCell, dim>& cells,
coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface) {
// open files
std::ofstream moleculeFile;
Expand All @@ -81,7 +81,7 @@ template <class LinkedCell, unsigned int dim> class coupling::MacroscopicCellPlo
break;
}
Writer4Molecules writer(moleculeVelocities, moleculePositions, moleculePotentials, appendFloatZeros, mdSolverInterface);
cells.applyToLocalNonGhostMacroscopicCellsWithLinkedCells(writer);
cells.applyToLocalNonGhostCouplingCellsWithLinkedCells(writer);
// open file and write info
open(ID, filename, "Molecules", rank, t, moleculeFile);
moleculeFile << "# vtk DataFile Version 2.0" << std::endl;
Expand All @@ -105,18 +105,18 @@ template <class LinkedCell, unsigned int dim> class coupling::MacroscopicCellPlo
moleculeFile.close();
}

/** @brief writes molecule information + macroscopic cell information to VTK
/** @brief writes molecule information + coupling cell information to VTK
* file.
* @param ID the id of the md simulation
* @param filename name for the file
* @param rank mpi rank of the current process
* @param t number of time step to plot
* @param indexConversion indexConversion instance of the current simulation
* @param cells macroscopic cells to plot
* @param cells coupling cells to plot
* @param mdSolverInterface interface of the md solver */
void plotMacroscopicCellFile(unsigned int ID, std::string filename, unsigned int rank, unsigned int t, const coupling::IndexConversion<dim>& indexConversion,
coupling::datastructures::MacroscopicCells<LinkedCell, dim>& cells,
coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface) {
void plotCouplingCellFile(unsigned int ID, std::string filename, unsigned int rank, unsigned int t, const coupling::IndexConversion<dim>& indexConversion,
coupling::datastructures::CouplingCells<LinkedCell, dim>& cells,
coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface) {
// stringstreams for all cell properties of interest
std::stringstream microscopicMasses;
microscopicMasses << "SCALARS microscopicMassBuffer float 1" << std::endl;
Expand Down Expand Up @@ -158,18 +158,17 @@ template <class LinkedCell, unsigned int dim> class coupling::MacroscopicCellPlo
}
// number of points
const tarch::la::Vector<3, unsigned int> numberCells =
coupling::initRange<dim>(indexConversion.getLocalNumberMacroscopicCells() + tarch::la::Vector<dim, unsigned int>(2));
coupling::initRange<dim>(indexConversion.getLocalNumberCouplingCells() + tarch::la::Vector<dim, unsigned int>(2));
tarch::la::Vector<3, double> original(0.0);
for (unsigned int d = 0; d < dim; d++) {
original[d] =
indexConversion.getGlobalMDDomainOffset()[d] - 0.5 * indexConversion.getMacroscopicCellSize()[d] +
indexConversion.getAverageLocalNumberMacroscopicCells()[d] * indexConversion.getThisProcess()[d] * indexConversion.getMacroscopicCellSize()[d];
original[d] = indexConversion.getGlobalMDDomainOffset()[d] - 0.5 * indexConversion.getCouplingCellSize()[d] +
indexConversion.getAverageLocalNumberCouplingCells()[d] * indexConversion.getThisProcess()[d] * indexConversion.getCouplingCellSize()[d];
}
// open file
open(ID, filename, "MacroscopicCells", rank, t, ofCell);
open(ID, filename, "CouplingCells", rank, t, ofCell);
Writer4Cells writer(microscopicMasses, macroscopicMasses, microscopicMomenta, macroscopicMomenta, meanVelocities, masses, energies, temperatures,
appendFloatZeros, indexConversion, mdSolverInterface);
cells.applyToAllLocalMacroscopicCellsWithLinkedCells(writer);
cells.applyToAllLocalCouplingCellsWithLinkedCells(writer);
ofCell << "# vtk DataFile Version 2.0" << std::endl;
ofCell << "generated by MaMiCo (Philipp Neumann)" << std::endl;
ofCell << "ASCII" << std::endl << std::endl;
Expand All @@ -182,7 +181,7 @@ template <class LinkedCell, unsigned int dim> class coupling::MacroscopicCellPlo
ofCell << std::endl;
ofCell << "SPACING ";
for (unsigned int d = 0; d < dim; d++) {
ofCell << indexConversion.getMacroscopicCellSize()[d] << " ";
ofCell << indexConversion.getCouplingCellSize()[d] << " ";
}
for (unsigned int d = dim; d < 3; d++) {
ofCell << "1.0 ";
Expand Down Expand Up @@ -229,12 +228,12 @@ template <class LinkedCell, unsigned int dim> class coupling::MacroscopicCellPlo
ss << filename << "_" << fileType << "_" << ID << "_" << rank << "_" << t << ".vtk";
of.open(ss.str().c_str());
if (!of.is_open()) {
std::cout << "ERROR coupling::MacroscopicCellPlotter: Could not open file " << ss.str() << "!" << std::endl;
std::cout << "ERROR coupling::CouplingCellPlotter: Could not open file " << ss.str() << "!" << std::endl;
exit(EXIT_FAILURE);
}
}

/** @brief class for writing macroscopic cell data to stringstreams.
/** @brief class for writing coupling cell data to stringstreams.
* @author Philipp Neumann*/
class Writer4Cells {
public:
Expand Down Expand Up @@ -272,11 +271,11 @@ template <class LinkedCell, unsigned int dim> class coupling::MacroscopicCellPlo
void endCellIteration() {}

/** @brief writes the data from the cell to the stringstreams
* @param cell macroscopic cell
* @param index linearised index of the macroscopic cell*/
void apply(coupling::datastructures::MacroscopicCellWithLinkedCells<LinkedCell, dim>& cell, const unsigned int& index) {
* @param cell coupling cell
* @param index linearised index of the coupling cell*/
void apply(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, const unsigned int& index) {
// compute local quantities from molecules, if this is an inner cell
const tarch::la::Vector<dim, unsigned int> end = _indexConversion.getLocalNumberMacroscopicCells() + tarch::la::Vector<dim, unsigned int>(1);
const tarch::la::Vector<dim, unsigned int> end = _indexConversion.getLocalNumberCouplingCells() + tarch::la::Vector<dim, unsigned int>(1);
const tarch::la::Vector<dim, unsigned int> localIndex = _indexConversion.getLocalVectorCellIndex(index);
bool isInnerCell = true;
for (unsigned int d = 0; d < dim; d++) {
Expand Down Expand Up @@ -343,7 +342,7 @@ template <class LinkedCell, unsigned int dim> class coupling::MacroscopicCellPlo
const coupling::IndexConversion<dim>& _indexConversion;
};

/** We make use of the traversal callback pattern of MacroscopicCells.
/** We make use of the traversal callback pattern of CouplingCells.
* @brief class for writing molecule data to stringstreams.
* @author Philipp Neumann */
class Writer4Molecules {
Expand All @@ -368,8 +367,8 @@ template <class LinkedCell, unsigned int dim> class coupling::MacroscopicCellPlo
* writer to the cells */
void endCellIteration() {}

/** @brief aplication of the vtkMoleculePlotter to the macroscopic cells*/
void apply(coupling::datastructures::MacroscopicCellWithLinkedCells<LinkedCell, dim>& cell, const unsigned int& index) {
/** @brief aplication of the vtkMoleculePlotter to the coupling cells*/
void apply(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, const unsigned int& index) {
coupling::cellmappings::VTKMoleculePlotter<LinkedCell, dim> vtkMoleculePlotter(_moleculeVelocities, _moleculePositions, _moleculePotentials,
_appendFloatZeros, _mdSolverInterface);
cell.iterateConstCells(vtkMoleculePlotter);
Expand All @@ -395,4 +394,4 @@ template <class LinkedCell, unsigned int dim> class coupling::MacroscopicCellPlo
unsigned int _moleculeCounter;
};
};
#endif // _MOLECULARDYNAMICS_COUPLING_MACROSCOPICCELLPLOTTER_H_
#endif // _MOLECULARDYNAMICS_COUPLING_COUPLINGCELLPLOTTER_H_
4 changes: 2 additions & 2 deletions coupling/CouplingMDDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
#else
#define COUPLING_MD_PARALLEL COUPLING_MD_NO
#endif
// message tags for MPI parallelisation. For each MacroscopicCellService, we add
// message tags for MPI parallelisation. For each CouplingCellService, we add
// the ID of the cell service to the tags from below to yield a unique tag for
// each operation. this currently supports a maximum of <10M instances of
// MacroscopicCellService.
// CouplingCellService.
#define TAG_FROM_MD2MACRO 100000
#define TAG_FROM_MACRO2MD 500000

Expand Down
Loading

0 comments on commit 174effc

Please sign in to comment.