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"
38 const unsigned int numThreads = 1)
45 std::cout <<
"The FiniteDifferenceSolver was requested in a parallel manner. It will be run sequentially, since it doesn't support parallel runs. "
54 omp_set_num_threads(numThreads);
56#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
58 std::cout <<
"tau=" << 1.0 /
_omega << std::endl;
63 std::cout << x <<
"," << y <<
"," << z <<
"FLAG=" <<
_flag[
get(x, y, z)] << std::endl;
70 std::cout <<
"ERROR FiniteDifferenceSolver: nullptr!" << std::endl;
89 const int timesteps = floor(dt /
_dt + 0.5);
90 if (fabs(timesteps *
_dt - dt) /
_dt > 1.0e-8) {
91 std::cout <<
"ERROR FiniteDifferenceSolver::advance(): time steps and dt do not match!" << std::endl;
94 for (
int i = 0; i < timesteps; i++) {
107#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
108 if ((pos[0] < domainOffset[0]) || (pos[0] > domainOffset[0] +
_domainSizeX *
_dx) || (pos[1] < domainOffset[1]) ||
110 std::cout <<
"ERROR FiniteDifferenceSolver::getVelocity(): Position " << pos <<
" out of range!" << std::endl;
117 for (
unsigned int d = 0; d < 3; d++) {
118 coords[d] = (
unsigned int)((
_dx + pos[d] - domainOffset[d]) /
_dx);
120 const int index =
get(coords[0], coords[1], coords[2]);
123 for (
int d = 0; d < 3; d++) {
124 vel[d] =
_vel[3 * index + d];
139#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
140 if ((pos[0] < domainOffset[0]) || (pos[0] > domainOffset[0] +
_domainSizeX *
_dx) || (pos[1] < domainOffset[1]) ||
142 std::cout <<
"ERROR FiniteDifferenceSolver::getDensity(): Position " << pos <<
" out of range!" << std::endl;
146 for (
unsigned int d = 0; d < 3; d++) {
147 coords[d] = (
unsigned int)((
_dx + pos[d] - domainOffset[d]) /
_dx);
149 const int index =
get(coords[0], coords[1], coords[2]);
163#pragma omp parallel for
164 for (
auto pair : md2macroBuffer) {
167 std::tie(couplingCell, idx) = pair;
173#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
174 std::cout <<
"Process coords: " <<
_coords <<
": GlobalCellCoords for index ";
175 std::cout << I01{idx} <<
": " << globalCellCoords << std::endl;
177 const int index =
get(globalCellCoords[0], globalCellCoords[1], globalCellCoords[2]);
178#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
180 std::cout <<
"ERROR FiniteDifferenceSolver::setMDBoundaryValues(): Cell " << index <<
" is no MD boundary cell!" << std::endl;
188 for (
unsigned int d = 0; d < 3; d++) {
189 _vel[3 * index + d] = localVel[d];
201#pragma omp parallel for
202 for (
int i = 0; i <
_yO; i++) {
212#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:200
virtual void setWallVelocity(const tarch::la::Vector< 3, double > wallVelocity) override
changes the velocity at the moving wall (z=0)
Definition FDCouetteSolver.h:131
double * _velold
the velocity field from the last time step
Definition FDCouetteSolver.h:225
const double _omega
factor for the finite difference stencil = dt*kinVisc/(dx*dx)
Definition FDCouetteSolver.h:221
void setMDBoundaryValues(coupling::datastructures::FlexibleCellContainer< 3 > &md2macroBuffer) override
applies the values received from the MD-solver within the conntinuum solver
Definition FDCouetteSolver.h:159
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, const unsigned int numThreads=1)
a simple constructor
Definition FDCouetteSolver.h:36
tarch::la::Vector< 3, double > _wallVelocity
velocity of moving wall of Couette flow
Definition FDCouetteSolver.h:223
~FiniteDifferenceSolver()
a simple destructor
Definition FDCouetteSolver.h:76
void advance(double dt) override
advances one time step dt in time and triggers vtk plot if required
Definition FDCouetteSolver.h:85
tarch::la::Vector< 3, double > getVelocity(tarch::la::Vector< 3, double > pos) const override
gets the velocity at a given position
Definition FDCouetteSolver.h:105
void update()
update the velocity in the cells which are flagged as FLUID
Definition FDCouetteSolver.h:208
double getDensity(tarch::la::Vector< 3, double > pos) const override
returns density at a certain position
Definition FDCouetteSolver.h:136
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