Skip to content

Commit

Permalink
Merge pull request #672 from Xiangyu-Hu/dev/mesh_dynamics
Browse files Browse the repository at this point in the history
implement mesh dynamics
  • Loading branch information
Xiangyu-Hu authored Nov 21, 2024
2 parents 62a6a9c + dbc1421 commit 8c5994e
Show file tree
Hide file tree
Showing 15 changed files with 1,553 additions and 1,063 deletions.

Large diffs are not rendered by default.

38 changes: 9 additions & 29 deletions src/for_2D_build/meshes/mesh_with_data_packages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#define MESH_WITH_DATA_PACKAGES_2D_HPP

#include "mesh_with_data_packages.h"
#include "mesh_iterators.hpp"

//=================================================================================================//
namespace SPH
{
//=================================================================================================//
Expand All @@ -33,15 +33,15 @@ DataType MeshWithGridDataPackages<PKG_SIZE>::
}
//=================================================================================================//
template <int PKG_SIZE>
void MeshWithGridDataPackages<PKG_SIZE>::allocateMetaDataMatrix()
void MeshWithGridDataPackages<PKG_SIZE>::allocateIndexDataMatrix()
{
Allocate2dArray(meta_data_mesh_, all_cells_);
Allocate2dArray(index_data_mesh_, all_cells_);
}
//=================================================================================================//
template <int PKG_SIZE>
void MeshWithGridDataPackages<PKG_SIZE>::deleteMetaDataMatrix()
void MeshWithGridDataPackages<PKG_SIZE>::deleteIndexDataMatrix()
{
Delete2dArray(meta_data_mesh_, all_cells_);
Delete2dArray(index_data_mesh_, all_cells_);
}
//=================================================================================================//
template <int PKG_SIZE>
Expand Down Expand Up @@ -71,48 +71,28 @@ template <int PKG_SIZE>
void MeshWithGridDataPackages<PKG_SIZE>::
assignDataPackageIndex(const Arrayi &cell_index, const size_t package_index)
{
MetaData &metadata = meta_data_mesh_[cell_index[0]][cell_index[1]];
metadata.second = package_index;
index_data_mesh_[cell_index[0]][cell_index[1]] = package_index;
}
//=================================================================================================//
template <int PKG_SIZE>
size_t MeshWithGridDataPackages<PKG_SIZE>::
PackageIndexFromCellIndex(const Arrayi &cell_index)
{
MetaData &metadata = meta_data_mesh_[cell_index[0]][cell_index[1]];
return metadata.second;
}
//=================================================================================================//
template <int PKG_SIZE>
void MeshWithGridDataPackages<PKG_SIZE>::
assignCategoryOnMetaDataMesh(const Arrayi &cell_index, const int category)
{
MetaData &metadata = meta_data_mesh_[cell_index[0]][cell_index[1]];
metadata.first = category;
return index_data_mesh_[cell_index[0]][cell_index[1]];
}
//=================================================================================================//
template <int PKG_SIZE>
bool MeshWithGridDataPackages<PKG_SIZE>::
isSingularDataPackage(const Arrayi &cell_index)
{
MetaData &metadata = meta_data_mesh_[cell_index[0]][cell_index[1]];
return metadata.first == 0;
return index_data_mesh_[cell_index[0]][cell_index[1]] < 2;
}
//=================================================================================================//
template <int PKG_SIZE>
bool MeshWithGridDataPackages<PKG_SIZE>::
isInnerDataPackage(const Arrayi &cell_index)
{
MetaData &metadata = meta_data_mesh_[cell_index[0]][cell_index[1]];
return metadata.first != 0;
}
//=================================================================================================//
template <int PKG_SIZE>
bool MeshWithGridDataPackages<PKG_SIZE>::
isCoreDataPackage(const Arrayi &cell_index)
{
MetaData &metadata = meta_data_mesh_[cell_index[0]][cell_index[1]];
return metadata.first == 2;
return index_data_mesh_[cell_index[0]][cell_index[1]] > 1;
}
//=================================================================================================//
template <int PKG_SIZE>
Expand Down

Large diffs are not rendered by default.

37 changes: 9 additions & 28 deletions src/for_3D_build/meshes/mesh_with_data_packages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define MESH_WITH_DATA_PACKAGES_3D_HPP

#include "mesh_with_data_packages.h"
#include "mesh_iterators.hpp"

namespace SPH
{
Expand All @@ -32,15 +33,15 @@ DataType MeshWithGridDataPackages<PKG_SIZE>::
}
//=================================================================================================//
template <int PKG_SIZE>
void MeshWithGridDataPackages<PKG_SIZE>::allocateMetaDataMatrix()
void MeshWithGridDataPackages<PKG_SIZE>::allocateIndexDataMatrix()
{
Allocate3dArray(meta_data_mesh_, all_cells_);
Allocate3dArray(index_data_mesh_, all_cells_);
}
//=================================================================================================//
template <int PKG_SIZE>
void MeshWithGridDataPackages<PKG_SIZE>::deleteMetaDataMatrix()
void MeshWithGridDataPackages<PKG_SIZE>::deleteIndexDataMatrix()
{
Delete3dArray(meta_data_mesh_, all_cells_);
Delete3dArray(index_data_mesh_, all_cells_);
}
//=================================================================================================//
template <int PKG_SIZE>
Expand Down Expand Up @@ -71,48 +72,28 @@ template <int PKG_SIZE>
void MeshWithGridDataPackages<PKG_SIZE>::
assignDataPackageIndex(const Arrayi &cell_index, const size_t package_index)
{
MetaData &metadata = meta_data_mesh_[cell_index[0]][cell_index[1]][cell_index[2]];
metadata.second = package_index;
index_data_mesh_[cell_index[0]][cell_index[1]][cell_index[2]] = package_index;
}
//=================================================================================================//
template <int PKG_SIZE>
size_t MeshWithGridDataPackages<PKG_SIZE>::
PackageIndexFromCellIndex(const Arrayi &cell_index)
{
MetaData &metadata = meta_data_mesh_[cell_index[0]][cell_index[1]][cell_index[2]];
return metadata.second;
}
//=================================================================================================//
template <int PKG_SIZE>
void MeshWithGridDataPackages<PKG_SIZE>::
assignCategoryOnMetaDataMesh(const Arrayi &cell_index, const int category)
{
MetaData &metadata = meta_data_mesh_[cell_index[0]][cell_index[1]][cell_index[2]];
metadata.first = category;
return index_data_mesh_[cell_index[0]][cell_index[1]][cell_index[2]];
}
//=================================================================================================//
template <int PKG_SIZE>
bool MeshWithGridDataPackages<PKG_SIZE>::
isSingularDataPackage(const Arrayi &cell_index)
{
MetaData &metadata = meta_data_mesh_[cell_index[0]][cell_index[1]][cell_index[2]];
return metadata.first == 0;
return index_data_mesh_[cell_index[0]][cell_index[1]][cell_index[2]] < 2;
}
//=================================================================================================//
template <int PKG_SIZE>
bool MeshWithGridDataPackages<PKG_SIZE>::
isInnerDataPackage(const Arrayi &cell_index)
{
MetaData &metadata = meta_data_mesh_[cell_index[0]][cell_index[1]][cell_index[2]];
return metadata.first != 0;
}
//=================================================================================================//
template <int PKG_SIZE>
bool MeshWithGridDataPackages<PKG_SIZE>::
isCoreDataPackage(const Arrayi &cell_index)
{
MetaData &metadata = meta_data_mesh_[cell_index[0]][cell_index[1]][cell_index[2]];
return metadata.first == 2;
return index_data_mesh_[cell_index[0]][cell_index[1]][cell_index[2]] > 1;
}
//=================================================================================================//
template <int PKG_SIZE>
Expand Down
6 changes: 3 additions & 3 deletions src/shared/adaptations/adaptation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ UniquePtr<BaseCellLinkedList> SPHAdaptation::
return makeUnique<CellLinkedList>(domain_bounds, kernel_ptr_->CutOffRadius(), base_particles, *this);
}
//=================================================================================================//
UniquePtr<BaseLevelSet> SPHAdaptation::createLevelSet(Shape &shape, Real refinement_ratio)
UniquePtr<MultilevelLevelSet> SPHAdaptation::createLevelSet(Shape &shape, Real refinement_ratio)
{
// estimate the required mesh levels
int total_levels = (int)log10(MinimumDimension(shape.getBounds()) / ReferenceSpacing()) + 2;
Real coarsest_spacing = ReferenceSpacing() * pow(2.0, total_levels - 1);
MultilevelLevelSet coarser_level_sets(shape.getBounds(), coarsest_spacing / refinement_ratio,
total_levels - 1, shape, *this);
// return the finest level set only
return makeUnique<RefinedMesh<LevelSet>>(shape.getBounds(), *coarser_level_sets.getMeshLevels().back(), shape, *this);
return makeUnique<MultilevelLevelSet>(shape.getBounds(), coarser_level_sets.getMeshLevels().back(), shape, *this);
}
//=================================================================================================//
ParticleWithLocalRefinement::
Expand Down Expand Up @@ -139,7 +139,7 @@ UniquePtr<BaseCellLinkedList> ParticleWithLocalRefinement::
getCellLinkedListTotalLevel(), base_particles, *this);
}
//=================================================================================================//
UniquePtr<BaseLevelSet> ParticleWithLocalRefinement::createLevelSet(Shape &shape, Real refinement_ratio)
UniquePtr<MultilevelLevelSet> ParticleWithLocalRefinement::createLevelSet(Shape &shape, Real refinement_ratio)
{
return makeUnique<MultilevelLevelSet>(shape.getBounds(), ReferenceSpacing() / refinement_ratio,
getLevelSetTotalLevel(), shape, *this);
Expand Down
6 changes: 3 additions & 3 deletions src/shared/adaptations/adaptation.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace SPH
class Shape;
class BaseParticles;
class BodyRegionByCell;
class BaseLevelSet;
class MultilevelLevelSet;
class BaseCellLinkedList;

/**
Expand Down Expand Up @@ -81,7 +81,7 @@ class SPHAdaptation
virtual void initializeAdaptationVariables(BaseParticles &base_particles) {};

virtual UniquePtr<BaseCellLinkedList> createCellLinkedList(const BoundingBox &domain_bounds, BaseParticles &base_particles);
virtual UniquePtr<BaseLevelSet> createLevelSet(Shape &shape, Real refinement_ratio);
virtual UniquePtr<MultilevelLevelSet> createLevelSet(Shape &shape, Real refinement_ratio);

template <class MeshType, typename... Args>
MeshType createBackGroundMesh(SPHBody &sph_body, Args &&...args);
Expand Down Expand Up @@ -122,7 +122,7 @@ class ParticleWithLocalRefinement : public SPHAdaptation

virtual void initializeAdaptationVariables(BaseParticles &base_particles) override;
virtual UniquePtr<BaseCellLinkedList> createCellLinkedList(const BoundingBox &domain_bounds, BaseParticles &base_particles) override;
virtual UniquePtr<BaseLevelSet> createLevelSet(Shape &shape, Real refinement_ratio) override;
virtual UniquePtr<MultilevelLevelSet> createLevelSet(Shape &shape, Real refinement_ratio) override;

protected:
Real finest_spacing_bound_; /**< the adaptation bound for finest particles */
Expand Down
1 change: 0 additions & 1 deletion src/shared/common/sphinxsys_containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ typedef DataContainerAddressAssemble<SingularVariable> SingularVariables;

/** Generalized mesh data type */
// template <typename DataType>
// using MeshVariable = DiscreteVariable<DataType>;
typedef DataContainerAddressAssemble<MeshVariable> MeshVariableAssemble;

} // namespace SPH
Expand Down
Loading

0 comments on commit 8c5994e

Please sign in to comment.