15 #ifndef CORE_DIFFUSION_DIFFUSION_GRID_H_
16 #define CORE_DIFFUSION_DIFFUSION_GRID_H_
95 real_t mu,
int resolution = 10);
159 bool scale_with_resolution =
false);
164 bool scale_with_resolution =
false);
171 const Real3& position)
const {
209 bool normalize =
true)
const;
218 size_t GetBoxIndex(
const std::array<uint32_t, 3>& box_coord)
const;
234 size_t index,
const std::array<uint32_t, 3>& box_coord)
const;
261 std::array<size_t, 3> ret;
276 [[deprecated(
"Use GetContinuumName() instead.")]]
const std::string&
286 std::array<int32_t, 6> ret;
297 std::array<int32_t, 3> ret;
310 template <
typename F>
317 return (
mu_ == 0 &&
dc_[1] == 0 &&
dc_[2] == 0 &&
dc_[3] == 0 &&
318 dc_[4] == 0 &&
dc_[5] == 0 &&
dc_[6] == 0);
337 void PrintInfo(std::ostream& out = std::cout);
372 size_t old_resolution);
392 std::array<real_t, 7>
dc_ = {{0}};
This class implements the boundary conditions. It is integrated into the diffusion grid as a smart po...
BoundaryCondition()=default
BoundaryCondition(const TRootIOCtor *)
virtual ~BoundaryCondition()=default
BDM_CLASS_DEF(BoundaryCondition, 1)
virtual real_t Evaluate(real_t x, real_t y, real_t z, real_t time) const =0
Boundary condition for Neumann and Dirichlet boundary conditions.
This class implements constant boundary conditions (Dirichlet and Neumann). The value of the boundary...
ConstantBoundaryCondition(real_t value)
Constructor for a constant boundary condition.
real_t value_
Constant value of the boundary condition for all positions and times.
real_t Evaluate(real_t x, real_t y, real_t z, real_t time) const final
see BoundaryCondition::Evaluate()
BDM_CLASS_DEF_OVERRIDE(ConstantBoundaryCondition, 1)
int GetContinuumId() const
Returns the ID of the continuum.
const std::string & GetContinuumName() const
Returns the name of the continuum.
int GetSubstanceId() const
const std::string & GetSubstanceName() const
bool IsFixedSubstance()
Return if a substance is stationary, e.g. (mu == 0 && dc == 0)
real_t box_volume_
the volume of each box
void Step(real_t dt) override
DiffusionGrid(DiffusionGrid &&)=delete
void ChangeConcentrationBy(const Real3 &position, real_t amount, InteractionMode mode=InteractionMode::kAdditive, bool scale_with_resolution=false)
real_t upper_threshold_
The maximum concentration value that a box can have.
real_t GetDecayConstant() const
size_t GetResolution() const
std::array< real_t, 7 > dc_
The diffusion coefficients [cc, cw, ce, cs, cn, cb, ct].
bool precompute_gradients_
DiffusionGrid(const DiffusionGrid &)=delete
std::array< int32_t, 6 > GetDimensions() const
real_t last_dt_
The last timestep dt used for the diffusion grid update Diffuse(dt)
ParallelResizeVector< Real3 > gradients_
The array of gradients (x, y, z)
bool parity_
If false, grid dimensions are even; if true, they are odd.
size_t GetNumBoxes() const
virtual void DiffuseWithPeriodic(real_t dt)=0
bool initialized_
Flag to indicate if the grid is initialized.
std::array< int32_t, 2 > grid_dimensions_
The grid dimensions of the diffusion grid (cubic shaped)
real_t lower_threshold_
The minimum concentration value that a box can have.
virtual void DiffuseWithNeumann(real_t dt)=0
real_t GetValue(const Real3 &position) const override
Get the value of the scalar field at specified position.
void SetUpperThreshold(real_t t)
const std::array< real_t, 7 > & GetDiffusionCoefficients() const
void PrintInfo(std::ostream &out=std::cout)
Print information about the Diffusion Grid.
void TurnOffGradientCalculation()
void PrintInfoWithInitialization()
Print the information after initialization.
BoundaryConditionType GetBoundaryConditionType() const
Returns the BoundaryConditionType, see BoundaryConditionType
~DiffusionGrid() override=default
const int32_t * GetDimensionsPtr() const
void SetBoundaryCondition(std::unique_ptr< BoundaryCondition > bc)
Set the boundary condition, takes ownership of the object.
std::array< size_t, 6 > GetNeighboringBoxes(size_t index) const
ParallelResizeVector< real_t > c2_
An extra concentration data buffer for faster value updating.
DiffusionGrid & operator=(const DiffusionGrid &)=delete
void AddInitializer(F function)
void SetDecayConstant(real_t mu)
std::unique_ptr< BoundaryCondition > boundary_condition_
Object that implements the boundary conditions.
std::vector< std::function< real_t(real_t, real_t, real_t)> > initializers_
DiffusionGrid(const TRootIOCtor *)
ParallelResizeVector< Spinlock > locks_
bool print_info_with_initialization_
virtual void DiffuseWithDirichlet(real_t dt)=0
virtual void DiffuseWithOpenEdge(real_t dt)=0
const real_t * GetAllGradients() const
BDM_CLASS_DEF_OVERRIDE(DiffusionGrid, 1)
real_t GetBoxLength() const
std::array< size_t, 3 > GetNumBoxesArray() const
real_t GetLowerThreshold() const
void ParametersCheck(real_t dt)
real_t GetBoxVolume() const
void Initialize() override
virtual void DiffuseWithClosedEdge(real_t dt)=0
std::array< uint32_t, 3 > GetBoxCoordinates(const Real3 &position) const
Get the coordinates of the box at the specified position.
real_t mu_
The decay constant.
uint64_t num_boxes_axis_
The number of boxes at each axis [x, y, z] (same along each axis)
bool IsInitialized() const
Returns if the grid has been initialized.
BoundaryCondition * GetBoundaryCondition() const
Returns the boundary condition. Does not transfer ownership.
const real_t * GetAllConcentrations() const
ParallelResizeVector< real_t > c1_
The array of concentration values.
real_t GetLastTimestep() const
Return the last timestep dt that was used to run Diffuse(dt)
std::array< int32_t, 3 > GetGridSize() const
DiffusionGrid & operator=(DiffusionGrid &&)=delete
size_t total_num_boxes_
The total number of boxes in the diffusion grid.
void CopyOldData(const ParallelResizeVector< real_t > &old_c1, const ParallelResizeVector< Real3 > &old_gradients, size_t old_resolution)
Real3 GetGradient(const Real3 &position) const override
size_t GetBoxIndex(const std::array< uint32_t, 3 > &box_coord) const
Calculates the box index at specified box coordinates.
real_t box_length_
The side length of each box.
real_t GetConcentration(const Real3 &position) const
BoundaryConditionType bc_type_
Type of boundary conditions.
void SetBoundaryConditionType(BoundaryConditionType bc_type)
Sets boundary condition type.
void SetLowerThreshold(real_t t)
real_t GetUpperThreshold() const
Continuum model for the 3D diffusion equation with exponential decay and substance depletion .
Continuum model for the 3D heat equation with exponential decay .
Interface for scalar fields. See Continuum for more information.
BoundaryConditionType
Available boundary conditions.