1#ifndef _MOLECULARDYNAMICS_COUPLING_SOLVERS_FINITEDIFFERENCE_H_
2#define _MOLECULARDYNAMICS_COUPLING_SOLVERS_FINITEDIFFERENCE_H_
4#include "coupling/solvers/NumericalSolver.h"
5#include "tarch/la/Vector.h"
43 std::cout <<
"The FiniteDifferenceSolver was requested in a parallel manner. It will be run sequentially, since it doesn't support parallel runs. "
51#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
53 std::cout <<
"tau=" << 1.0 /
_omega << std::endl;
58 std::cout << x <<
"," << y <<
"," << z <<
"FLAG=" <<
_flag[
get(x, y, z)] << std::endl;
65 std::cout <<
"ERROR FiniteDifferenceSolver: nullptr!" << std::endl;
84 const int timesteps = floor(dt /
_dt + 0.5);
85 if (fabs(timesteps *
_dt - dt) /
_dt > 1.0e-8) {
86 std::cout <<
"ERROR FiniteDifferenceSolver::advance(): time steps and dt do not match!" << std::endl;
89 for (
int i = 0; i < timesteps; i++) {
102#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
103 if ((pos[0] < domainOffset[0]) || (pos[0] > domainOffset[0] +
_domainSizeX *
_dx) || (pos[1] < domainOffset[1]) ||
105 std::cout <<
"ERROR FiniteDifferenceSolver::getVelocity(): Position " << pos <<
" out of range!" << std::endl;
112 for (
unsigned int d = 0; d < 3; d++) {
113 coords[d] = (
unsigned int)((
_dx + pos[d] - domainOffset[d]) /
_dx);
115 const int index =
get(coords[0], coords[1], coords[2]);
118 for (
int d = 0; d < 3; d++) {
119 vel[d] =
_vel[3 * index + d];
134#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
135 if ((pos[0] < domainOffset[0]) || (pos[0] > domainOffset[0] +
_domainSizeX *
_dx) || (pos[1] < domainOffset[1]) ||
137 std::cout <<
"ERROR FiniteDifferenceSolver::getDensity(): Position " << pos <<
" out of range!" << std::endl;
141 for (
unsigned int d = 0; d < 3; d++) {
142 coords[d] = (
unsigned int)((
_dx + pos[d] - domainOffset[d]) /
_dx);
144 const int index =
get(coords[0], coords[1], coords[2]);
158 for (
auto pair : md2macroBuffer) {
161 std::tie(couplingCell, idx) = pair;
167#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
168 std::cout <<
"Process coords: " <<
_coords <<
": GlobalCellCoords for index ";
169 std::cout << I01{idx} <<
": " << globalCellCoords << std::endl;
171 const int index =
get(globalCellCoords[0], globalCellCoords[1], globalCellCoords[2]);
172#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
174 std::cout <<
"ERROR FiniteDifferenceSolver::setMDBoundaryValues(): Cell " << index <<
" is no MD boundary cell!" << std::endl;
182 for (
unsigned int d = 0; d < 3; d++) {
183 _vel[3 * index + d] = localVel[d];
195#pragma omp parallel for
196 for (
int i = 0; i <
_yO; i++) {
206#pragma omp parallel for
defines the cell type with cell-averaged quantities only (no linked cells).
Definition CouplingCell.h:29
const tarch::la::Vector< dim, double > & getMacroscopicMomentum() const
Definition CouplingCell.h:64
const double & getMacroscopicMass() const
Definition CouplingCell.h:58
provides access to coupling cells, which may belong to different indexing domains
Definition FlexibleCellContainer.h:30
implements a simple one-dimensional finite-diffference solver for the Couette flow.
Definition FDCouetteSolver.h:20
void setBeyondWall()
updates the velocities at boundaries
Definition FDCouetteSolver.h:194
virtual void setWallVelocity(const tarch::la::Vector< 3, double > wallVelocity) override
changes the velocity at the moving wall (z=0)
Definition FDCouetteSolver.h:126
double * _velold
the velocity field from the last time step
Definition FDCouetteSolver.h:219
const double _omega
factor for the finite difference stencil = dt*kinVisc/(dx*dx)
Definition FDCouetteSolver.h:215
void setMDBoundaryValues(coupling::datastructures::FlexibleCellContainer< 3 > &md2macroBuffer) override
applies the values received from the MD-solver within the conntinuum solver
Definition FDCouetteSolver.h:154
FiniteDifferenceSolver(const double channelheight, tarch::la::Vector< 3, double > wallVelocity, const double kinVisc, const double dx, const double dt, const int plotEveryTimestep, const std::string filestem, const tarch::la::Vector< 3, unsigned int > processes)
a simple constructor
Definition FDCouetteSolver.h:35
tarch::la::Vector< 3, double > _wallVelocity
velocity of moving wall of Couette flow
Definition FDCouetteSolver.h:217
~FiniteDifferenceSolver()
a simple destructor
Definition FDCouetteSolver.h:71
void advance(double dt) override
advances one time step dt in time and triggers vtk plot if required
Definition FDCouetteSolver.h:80
tarch::la::Vector< 3, double > getVelocity(tarch::la::Vector< 3, double > pos) const override
gets the velocity at a given position
Definition FDCouetteSolver.h:100
void update()
update the velocity in the cells which are flagged as FLUID
Definition FDCouetteSolver.h:202
double getDensity(tarch::la::Vector< 3, double > pos) const override
returns density at a certain position
Definition FDCouetteSolver.h:131
is a virtual base class for the interface for a numerical fluid solver for the Couette scenario
Definition NumericalSolver.h:33
const int _domainSizeX
domain size in x-direction
Definition NumericalSolver.h:554
int _counter
time step counter
Definition NumericalSolver.h:569
int get(int i) const
returns i and performs checks in debug mode
Definition NumericalSolver.h:360
const int _yO
offset for z-direction
Definition NumericalSolver.h:593
const int _avgDomainSizeZ
avg. domain size in MPI-parallel simulation in z-direction
Definition NumericalSolver.h:564
NumericalSolver(const double channelheight, const double dx, const double dt, const double kinVisc, const int plotEveryTimestep, const std::string filestem, const tarch::la::Vector< 3, unsigned int > processes, const Scenario *scen=nullptr)
a simple constructor
Definition NumericalSolver.h:46
Flag * _flag
flag field
Definition NumericalSolver.h:575
const int _avgDomainSizeY
avg. domain size in MPI-parallel simulation in y-direction
Definition NumericalSolver.h:562
const tarch::la::Vector< 3, unsigned int > _coords
coordinates of this process (=1,1,1, unless parallel run of the solver )
Definition NumericalSolver.h:567
const int _domainSizeY
domain size in y-direction
Definition NumericalSolver.h:556
const double _dt
time step
Definition NumericalSolver.h:543
tarch::la::Vector< 3, unsigned int > _processes
domain decomposition on MPI rank basis; total number is given by multipling all entries
Definition NumericalSolver.h:548
double * _density
density field
Definition NumericalSolver.h:573
@ MD_BOUNDARY
a cell on the boundary to md
Definition NumericalSolver.h:524
@ FLUID
a normal fluid cell
Definition NumericalSolver.h:520
double * _vel
velocity field
Definition NumericalSolver.h:571
const int _avgDomainSizeX
avg. domain size in MPI-parallel simulation in x-direction
Definition NumericalSolver.h:560
bool skipRank() const
returns true, if this rank is not of relevance for the LB simulation
Definition NumericalSolver.h:509
tarch::la::Vector< 3, int > _offset
offset of the md domain
Definition NumericalSolver.h:597
const double _dx
mesh size, dx=dy=dz
Definition NumericalSolver.h:541
const int _domainSizeZ
domain size in z-direction
Definition NumericalSolver.h:558
all numerical solvers are defined in the namespace, and their interfaces
Definition CouetteSolver.h:14
everything necessary for coupling operations, is defined in here
Definition AdditiveMomentumInsertion.h:15