20#ifndef _MDCORE_SOURCE_TF_BOUNDARY_EVAL_H_
21#define _MDCORE_SOURCE_TF_BOUNDARY_EVAL_H_
27#include "tf_dpd_eval.h"
28#include "tf_potential_eval.h"
46 TF_ALWAYS_INLINE
bool apply_update_pos_vel(Particle *p,
space_cell *c,
const FPTYPE* h,
int* delta) {
48 #define ENFORCE_FREESLIP_LOW(i) \
49 p->position[i] = std::max<FPTYPE>(-p->position[i] * restitution, FPTYPE_ZERO); \
50 p->velocity[i] *= -restitution; \
53 #define ENFORCE_FREESLIP_HIGH(i) \
54 p->position[i] = c->dim[i] - std::max<FPTYPE>((p->position[i] - c->dim[i]) * restitution, FPTYPE_EPSILON); \
55 p->velocity[i] *= -restitution; \
58 #define ENFORCE_VELOCITY_LOW(i, bc) \
59 p->position[i] = std::max<FPTYPE>(-p->position[i] * bc.restore, FPTYPE_ZERO); \
60 p->velocity = bc.velocity - ((p->velocity - bc.velocity) * bc.restore); \
63 #define ENFORCE_VELOCITY_HIGH(i, bc) \
64 p->position[i] = c->dim[i] - std::max<FPTYPE>((p->position[i] - c->dim[i]) * bc.restore, FPTYPE_EPSILON); \
65 p->velocity = bc.velocity - ((p->velocity - bc.velocity) * bc.restore); \
68 static const BoundaryConditions *bc = &
_Engine.boundary_conditions;
70 static const FPTYPE restitution = 1.0;
73 bool enforced =
false;
75 if(c->flags & cell_active_left && p->x[0] <= 0) {
76 if(bc->left.kind & BOUNDARY_FREESLIP) {
77 ENFORCE_FREESLIP_LOW(0);
79 else if(bc->left.kind & BOUNDARY_VELOCITY) {
80 ENFORCE_VELOCITY_LOW(0, bc->left);
84 if(c->flags & cell_active_right && p->x[0] >= c->dim[0]) {
85 if(bc->right.kind & BOUNDARY_FREESLIP) {
86 ENFORCE_FREESLIP_HIGH(0);
88 else if(bc->right.kind & BOUNDARY_VELOCITY) {
89 ENFORCE_VELOCITY_HIGH(0, bc->right);
93 if(c->flags & cell_active_front && p->x[1] <= 0) {
94 if(bc->front.kind & BOUNDARY_FREESLIP) {
95 ENFORCE_FREESLIP_LOW(1);
97 else if(bc->front.kind & BOUNDARY_VELOCITY) {
98 ENFORCE_VELOCITY_LOW(1, bc->front);
102 if(c->flags & cell_active_back && p->x[1] >= c->dim[1]) {
103 if(bc->back.kind & BOUNDARY_FREESLIP) {
104 ENFORCE_FREESLIP_HIGH(1);
106 else if(bc->back.kind & BOUNDARY_VELOCITY) {
107 ENFORCE_VELOCITY_HIGH(1, bc->back);
111 if(c->flags & cell_active_bottom && p->x[2] <= 0) {
112 if(bc->bottom.kind & BOUNDARY_FREESLIP) {
113 ENFORCE_FREESLIP_LOW(2);
115 else if(bc->bottom.kind & BOUNDARY_VELOCITY) {
116 ENFORCE_VELOCITY_LOW(2, bc->bottom);
120 if(c->flags & cell_active_top && p->x[2] >= c->dim[2]) {
121 if(bc->top.kind & BOUNDARY_FREESLIP) {
122 ENFORCE_FREESLIP_HIGH(2);
124 else if(bc->top.kind & BOUNDARY_VELOCITY) {
125 ENFORCE_VELOCITY_HIGH(2, bc->top);
130 for (
int k = 0 ; k < 3 ; k++ ) {
131 delta[k] = std::isgreaterequal( p->x[k], h[k] ) - std::isless( p->x[k], 0.0 );
135 return delta[0] == 0 && delta[1] == 0 && delta[2] == 0;
138 TF_ALWAYS_INLINE
bool boundary_potential_eval_ex(
const struct space_cell *cell,
139 Potential *pot, Particle *part, BoundaryCondition *bc,
140 FPTYPE *dx, FPTYPE r2, FPTYPE *epot);
142 static bool _boundary_potential_eval_ex(
const struct space_cell *cell,
143 Potential *pot, Particle *part, BoundaryCondition *bc,
144 FPTYPE *dx, FPTYPE r2, FPTYPE *epot)
146 return boundary_potential_eval_ex(cell, pot, part, bc, dx, r2, epot);
149 bool boundary_potential_eval_ex(
const struct space_cell *cell,
150 Potential *pot, Particle *part, BoundaryCondition *bc,
151 FPTYPE *dx, FPTYPE r2, FPTYPE *epot)
156 if(pot->kind == POTENTIAL_KIND_DPD) {
158 if (dpd_boundary_eval((DPDPotential*)pot,
space_cell_gaussian(cell->id), part, bc->radius, bc->velocity.data(), dx, r2, &e)) {
164 else if(pot->kind == POTENTIAL_KIND_BYPARTICLES) {
165 FPTYPE fv[3] = {0., 0., 0.};
167 pot->eval_bypart(pot, part, dx, r2, &e, fv);
169 for (
int k = 0 ; k < 3 ; k++ ) {
177 else if(pot->kind == POTENTIAL_KIND_COMBINATION) {
178 if(pot->flags & POTENTIAL_SUM) {
179 _boundary_potential_eval_ex(cell, pot->pca, part, bc, dx, r2, epot);
180 _boundary_potential_eval_ex(cell, pot->pcb, part, bc, dx, r2, epot);
188 if (potential_eval_ex(pot, part->radius, bc->radius, r2, &e, &f )) {
190 for (
int k = 0 ; k < 3 ; k++ ) {
191 FPTYPE w = f * dx[k];
204 TF_ALWAYS_INLINE
bool boundary_eval(BoundaryConditions *bc,
const struct space_cell *cell, Particle *part, FPTYPE *epot ) {
210 FPTYPE dx[3] = {0.f, 0.f, 0.f};
212 if((cell->flags & cell_active_left) &&
213 (pot = bc->left.potenntials[part->typeId]) &&
214 ((r = part->x[0]) <= pot->b)) {
216 result |= boundary_potential_eval_ex(cell, pot, part, &bc->left, dx, r*r, epot);
219 if((cell->flags & cell_active_right) &&
220 (pot = bc->right.potenntials[part->typeId]) &&
221 ((r = cell->dim[0] - part->x[0]) <= pot->b)) {
223 result |= boundary_potential_eval_ex(cell, pot, part, &bc->right, dx, r*r, epot);
226 if((cell->flags & cell_active_front) &&
227 (pot = bc->front.potenntials[part->typeId]) &&
228 ((r = part->x[1]) <= pot->b)) {
230 result |= boundary_potential_eval_ex(cell, pot, part, &bc->front, dx, r*r, epot);
233 if((cell->flags & cell_active_back) &&
234 (pot = bc->back.potenntials[part->typeId]) &&
235 ((r = cell->dim[1] - part->x[1]) <= pot->b)) {
237 result |= boundary_potential_eval_ex(cell, pot, part, &bc->back, dx, r*r, epot);
240 if((cell->flags & cell_active_bottom) &&
241 (pot = bc->bottom.potenntials[part->typeId]) &&
242 ((r = part->x[2]) <= pot->b)) {
244 result |= boundary_potential_eval_ex(cell, pot, part, &bc->bottom, dx, r*r, epot);
247 if((cell->flags & cell_active_top) &&
248 (pot = bc->top.potenntials[part->typeId]) &&
249 ((r = cell->dim[2] - part->x[2]) <= pot->b)) {
251 result |= boundary_potential_eval_ex(cell, pot, part, &bc->top, dx, r*r, epot);
Include Python header, disable linking to pythonX_d.lib on Windows in debug mode.
Definition tfAngleConfig.h:26
FPTYPE space_cell_gaussian(int cell_id)
struct TissueForge::space_cell space_cell
the space_cell structure