Skip to content

Commit

Permalink
define normal direction as general dynamics
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiangyu-Hu committed Sep 12, 2023
1 parent 3d3c929 commit 2412371
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "general_bounding.h"
#include "general_dynamics.h"
#include "general_dynamics_refinement.h"
#include "general_geometric.h"
#include "general_interaction.h"
#include "general_interpolation.h"
#include "general_life_time_dynamics.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "general_geometric.h"
#include "base_particles.hpp"

namespace SPH
{
//=============================================================================================//
NormalDirectionFromBodyShape::NormalDirectionFromBodyShape(SPHBody &sph_body)
: LocalDynamics(sph_body), GeneralDataDelegateSimple(sph_body),
body_shape_(*sph_body.body_shape_), pos_(particles_->pos_),
n_(*particles_->registerSharedVariable<Vecd>("NormalDirection")),
n0_(*particles_->registerSharedVariable<Vecd>("InitialNormalDirection")) {}
//=============================================================================================//
void NormalDirectionFromBodyShape::update(size_t index_i, Real dt)
{
Vecd normal_direction = body_shape_.findNormalDirection(pos_[index_i]);
n_[index_i] = normal_direction;
n0_[index_i] = normal_direction;
}
//=============================================================================================//
NormalDirectionFromShapeAndOp::
NormalDirectionFromShapeAndOp(SPHBody &sph_body, const std::string &shape_name)
: LocalDynamics(sph_body), GeneralDataDelegateSimple(sph_body),
shape_and_op_(DynamicCast<ComplexShape>(this, sph_body.body_shape_)->getShapeAndOpByName(shape_name)),
shape_(shape_and_op_->first),
switch_sign_(shape_and_op_->second == ShapeBooleanOps::add ? 1.0 : -1.0),
pos_(particles_->pos_),
n_(*particles_->registerSharedVariable<Vecd>("NormalDirection")),
n0_(*particles_->registerSharedVariable<Vecd>("InitialNormalDirection")) {}
//=============================================================================================//
void NormalDirectionFromShapeAndOp::update(size_t index_i, Real dt)
{
Vecd normal_direction = switch_sign_ * shape_->findNormalDirection(pos_[index_i]);
n_[index_i] = normal_direction;
n0_[index_i] = normal_direction;
}
//=================================================================================================//
} // namespace SPH
70 changes: 70 additions & 0 deletions src/shared/particle_dynamics/general_dynamics/general_geometric.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* ------------------------------------------------------------------------- *
* SPHinXsys *
* ------------------------------------------------------------------------- *
* SPHinXsys (pronunciation: s'finksis) is an acronym from Smoothed Particle *
* Hydrodynamics for industrial compleX systems. It provides C++ APIs for *
* physical accurate simulation and aims to model coupled industrial dynamic *
* systems including fluid, solid, multi-body dynamics and beyond with SPH *
* (smoothed particle hydrodynamics), a meshless computational method using *
* particle discretization. *
* *
* SPHinXsys is partially funded by German Research Foundation *
* (Deutsche Forschungsgemeinschaft) DFG HU1527/6-1, HU1527/10-1, *
* HU1527/12-1 and HU1527/12-4. *
* *
* Portions copyright (c) 2017-2023 Technical University of Munich and *
* the authors' affiliations. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may *
* not use this file except in compliance with the License. You may obtain a *
* copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
* *
* ------------------------------------------------------------------------- */
/**
* @file general_geometric.h
* @brief This is the particle dynamics applicable for all type bodies
* @author Xiangyu Hu
*/

#ifndef GENERAL_GEOMETRIC_H
#define GENERAL_GEOMETRIC_H

#include "general_dynamics.h"

namespace SPH
{
/**
* @class NormalDirectionFromBodyShape
* @brief normal direction at particles
*/
class NormalDirectionFromBodyShape : public LocalDynamics, public GeneralDataDelegateSimple
{
public:
explicit NormalDirectionFromBodyShape(SPHBody &sph_body);
virtual ~NormalDirectionFromBodyShape(){};
void update(size_t index_i, Real dt = 0.0);

protected:
Shape &body_shape_;
StdLargeVec<Vecd> &pos_, &n_, &n0_;
};

/**
* @class NormalDirectionFromShapeAndOp
* @brief normal direction at particles
*/
class NormalDirectionFromShapeAndOp : public LocalDynamics, public GeneralDataDelegateSimple
{
public:
explicit NormalDirectionFromShapeAndOp(SPHBody &sph_body, const std::string &shape_name);
virtual ~NormalDirectionFromShapeAndOp(){};
void update(size_t index_i, Real dt = 0.0);

protected:
ShapeAndOp *shape_and_op_;
Shape *shape_;
const Real switch_sign_;
StdLargeVec<Vecd> &pos_, &n_, &n0_;
};
} // namespace SPH
#endif // GENERAL_GEOMETRIC_H
26 changes: 0 additions & 26 deletions src/shared/particles/solid_particles_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,6 @@ void TranslationAndRotation::update(size_t index_i, Real dt)
pos0_[index_i] = transform_.shiftFrameStationToBase(pos0_[index_i]);
}
//=============================================================================================//
NormalDirectionFromBodyShape::NormalDirectionFromBodyShape(SPHBody &sph_body)
: SolidDataSimple(sph_body), LocalDynamics(sph_body), body_shape_(*sph_body.body_shape_),
pos_(particles_->pos_), n_(particles_->n_), n0_(particles_->n0_) {}
//=============================================================================================//
void NormalDirectionFromBodyShape::update(size_t index_i, Real dt)
{
Vecd normal_direction = body_shape_.findNormalDirection(pos_[index_i]);
n_[index_i] = normal_direction;
n0_[index_i] = normal_direction;
}
//=============================================================================================//
NormalDirectionFromShapeAndOp::
NormalDirectionFromShapeAndOp(SPHBody &sph_body, const std::string &shape_name)
: SolidDataSimple(sph_body), LocalDynamics(sph_body),
shape_and_op_(DynamicCast<ComplexShape>(this, sph_body.body_shape_)->getShapeAndOpByName(shape_name)),
shape_(shape_and_op_->first),
switch_sign_(shape_and_op_->second == ShapeBooleanOps::add ? 1.0 : -1.0),
pos_(particles_->pos_), n_(particles_->n_), n0_(particles_->n0_) {}
//=============================================================================================//
void NormalDirectionFromShapeAndOp::update(size_t index_i, Real dt)
{
Vecd normal_direction = switch_sign_ * shape_->findNormalDirection(pos_[index_i]);
n_[index_i] = normal_direction;
n0_[index_i] = normal_direction;
}
//=============================================================================================//
GreenLagrangeStrain::GreenLagrangeStrain(SPHBody &sph_body)
: BaseDerivedVariable<Matd>(sph_body, "GreenLagrangeStrain"), ElasticSolidDataSimple(sph_body),
LocalDynamics(sph_body), F_(particles_->F_) {}
Expand Down
36 changes: 0 additions & 36 deletions src/shared/particles/solid_particles_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,42 +93,6 @@ class TranslationAndRotation : public SolidDataSimple,
StdLargeVec<Vecd> &pos_, &pos0_;
};

/**
* @class NormalDirectionFromBodyShape
* @brief normal direction at particles
*/
class NormalDirectionFromBodyShape : public SolidDataSimple,
public LocalDynamics
{
public:
explicit NormalDirectionFromBodyShape(SPHBody &sph_body);
virtual ~NormalDirectionFromBodyShape(){};
void update(size_t index_i, Real dt = 0.0);

protected:
Shape &body_shape_;
StdLargeVec<Vecd> &pos_, &n_, &n0_;
};

/**
* @class NormalDirectionFromBodyShape
* @brief normal direction at particles
*/
class NormalDirectionFromShapeAndOp : public SolidDataSimple,
public LocalDynamics
{
public:
explicit NormalDirectionFromShapeAndOp(SPHBody &sph_body, const std::string &shape_name);
virtual ~NormalDirectionFromShapeAndOp(){};
void update(size_t index_i, Real dt = 0.0);

protected:
ShapeAndOp *shape_and_op_;
Shape *shape_;
const Real switch_sign_;
StdLargeVec<Vecd> &pos_, &n_, &n0_;
};

//----------------------------------------------------------------------
// for general elastic solid dynamics variables
//----------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ NonReflectiveBoundaryCorrection::NonReflectiveBoundaryCorrection(BaseInnerRelati
rho_(particles_->rho_), p_(*particles_->getVariableByName<Real>("Pressure")),
Vol_(particles_->Vol_), vel_(particles_->vel_),
mom_(*particles_->getVariableByName<Vecd>("Momentum")), pos_(particles_->pos_),
indicator_(*particles_->getVariableByName<int>("Indicator"))
indicator_(*particles_->getVariableByName<int>("Indicator")),
n_(*particles_->getVariableByName<Vecd>("NormalDirection"))
{
particles_->registerVariable(n_, "NormalDirection");
particles_->registerVariable(inner_weight_summation_, "InnerWeightSummation");
particles_->registerVariable(rho_average_, "DensityAverage");
particles_->registerVariable(vel_normal_average_, "VelocityNormalAverage");
Expand All @@ -64,11 +64,8 @@ NonReflectiveBoundaryCorrection::NonReflectiveBoundaryCorrection(BaseInnerRelati
//=================================================================================================//
void NonReflectiveBoundaryCorrection::interaction(size_t index_i, Real dt)
{
Shape &body_shape = *sph_body_.body_shape_;
if (indicator_[index_i] == 1 || smeared_surface_[index_i] == 1)
{
Vecd normal_direction = body_shape.findNormalDirection(pos_[index_i]);
n_[index_i] = normal_direction;
Real velocity_boundary_normal = vel_[index_i].dot(n_[index_i]);
// judge it is the inflow condition
if (n_[index_i][0] <= 0.0 || fabs(n_[index_i][1]) > fabs(n_[index_i][0]))
Expand Down Expand Up @@ -153,11 +150,8 @@ void NonReflectiveBoundaryCorrection::interaction(size_t index_i, Real dt)
//=================================================================================================//
void NonReflectiveBoundaryCorrection::update(size_t index_i, Real dt)
{
Shape &body_shape = *sph_body_.body_shape_;
if (indicator_[index_i] == 1 || smeared_surface_[index_i] == 1)
{
Vecd normal_direction = body_shape.findNormalDirection(pos_[index_i]);
n_[index_i] = normal_direction;
Real velocity_farfield_normal = vel_farfield_.dot(n_[index_i]);
Real velocity_boundary_normal = vel_[index_i].dot(n_[index_i]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ class NonReflectiveBoundaryCorrection : public LocalDynamics, public DataDelegat
Vecd vel_farfield_;
StdLargeVec<Real> &rho_, &p_, &Vol_;
StdLargeVec<Vecd> &vel_, &mom_, &pos_;
StdLargeVec<Vecd> n_;
StdLargeVec<Real> inner_weight_summation_, rho_average_, vel_normal_average_;
StdLargeVec<Vecd> vel_tangential_average_, vel_average_;
StdLargeVec<int> &indicator_, smeared_surface_;
StdLargeVec<Vecd> &n_;
};
} // namespace fluid_dynamics
} // namespace SPH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ int main(int ac, char *av[])
SimpleDynamics<TimeStepInitialization> initialize_a_fluid_step(water_block);
SimpleDynamics<NormalDirectionFromBodyShape> cylinder_normal_direction(cylinder);
InteractionDynamics<fluid_dynamics::ViscousAccelerationWithWall> viscous_acceleration(water_block_complex);
SimpleDynamics<NormalDirectionFromBodyShape> water_block_normal_direction(water_block);
ReduceDynamics<fluid_dynamics::AcousticTimeStepSize> get_fluid_time_step_size(water_block, 0.5);
InteractionWithUpdate<FarFieldBoundary> variable_reset_in_boundary_condition(water_block_complex.getInnerRelation());
InteractionWithUpdate<fluid_dynamics::FreeSurfaceIndicationComplex> surface_indicator(water_block_complex);
Expand Down Expand Up @@ -197,6 +198,7 @@ int main(int ac, char *av[])
cylinder_normal_direction.exec();
surface_indicator.exec();
smeared_surface.exec();
water_block_normal_direction.exec();
variable_reset_in_boundary_condition.exec();
kernel_correction_matrix.exec();
kernel_gradient_update.exec();
Expand Down

0 comments on commit 2412371

Please sign in to comment.