Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/structural_simulation/structural_simulation_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ StructuralSimulation::StructuralSimulation(const StructuralSimulationInput &inpu
// default system, optional: particle relaxation, scale_system_boundaries
particle_relaxation_list_(input.particle_relaxation_list_),
write_particle_relaxation_data_(input.write_particle_relaxation_data_),
system_resolution_(0.0),
system_(SPHSystem(BoundingBoxd(Vec3d::Zero(), Vec3d::Zero()), system_resolution_)),
system_resolution_(Eps),
system_(SPHSystem(BoundingBoxd(Vec3d::Constant(-Eps), Vec3d::Constant(Eps)), system_resolution_)),
scale_system_boundaries_(input.scale_system_boundaries_),
physical_time_(*system_.getSystemVariableDataByName<Real>("PhysicalTime")),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
#include "base_body_part.h"
#include "geometric_shape.h"

#include "complex_geometry.h"
#include "io_environment.h"
#include "sph_system.h"

namespace SPH
{
//=================================================================================================//
void AlignedBoxPart::writeShapeProxy()
void GeometricShapeBox::writeProxy()
{
std::string filefullpath = IO::getEnvironment().OutputFolder() + "/" + svAlignedBox()->Name() + "Proxy.vtp";
std::string filefullpath = IO::getEnvironment().OutputFolder() + "/" + getName() + "Proxy.vtp";

if (fs::exists(filefullpath))
{
fs::remove(filefullpath);
}
std::ofstream out_file(filefullpath.c_str(), std::ios::trunc);

Vecd halfsize = aligned_box_.HalfSize();
Transform transform = aligned_box_.getTransform();
Vecd halfsize = HalfSize();
Transform transform = getTransform();

// 4 corners in local frame (z=0 for 2D)
Vecd local_corners[4] = {
Expand Down Expand Up @@ -62,4 +60,4 @@ void AlignedBoxPart::writeShapeProxy()
out_file.close();
}
//=================================================================================================//
} // namespace SPH
} // namespace SPH
16 changes: 0 additions & 16 deletions src/for_3D_build/bodies/base_body_part_3d.cpp

This file was deleted.

15 changes: 15 additions & 0 deletions src/for_3D_build/geometries/geometric_shape_3d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "geometric_shape.h"

#include "triangle_mesh_shape.h"
#include "io_environment.h"

namespace SPH
{
//=================================================================================================//
void GeometricShapeBox::writeProxy()
{
TriangleMeshShapeBrick shape_proxy(HalfSize(), 1, Vecd::Zero(), getName() + "Proxy");
shape_proxy.writeMeshToFile(getTransform());
}
//=================================================================================================//
} // namespace SPH
8 changes: 8 additions & 0 deletions src/shared/bodies/base_body_part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "base_particles.hpp"
#include "cell_linked_list.hpp"
#include "complex_geometry.h"
#include "geometric_shape.h"
#include "sphinxsys_variable.h"

namespace SPH
Expand Down Expand Up @@ -224,6 +225,13 @@ AlignedBoxPart::AlignedBoxPart(const std::string &part_name, const AlignedBox &a
//=================================================================================================//
AlignedBoxPart::~AlignedBoxPart() = default;
//=================================================================================================//
void AlignedBoxPart::writeShapeProxy()
{
GeometricShapeBox domain_shape(
aligned_box_.getTransform(), aligned_box_.HalfSize(), svAlignedBox()->Name());
domain_shape.writeProxy();
}
//=================================================================================================//
AlignedBoxByParticle::AlignedBoxByParticle(RealBody &real_body, const AlignedBox &aligned_box)
: BodyPartByParticle(real_body), AlignedBoxPart(part_name_, aligned_box)
{
Expand Down
88 changes: 83 additions & 5 deletions src/shared/common/sphinxsys_entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
#include "base_data_type.h"
#include "ownership.h"

#include <memory>
#include <algorithm>
#include <memory>
#include <typeindex>
#include <unordered_map>
#include <utility>

namespace SPH
{
Expand All @@ -55,13 +56,18 @@ class Entity
class EntityManager
{
std::unordered_map<std::type_index, std::unordered_map<std::string, void *>> all_entities_;
std::unordered_map<std::type_index, std::unordered_map<std::string, SharedPtr<void>>> owned_entities_;

public:
EntityManager() = default;
~EntityManager() {};

/** Remove all registered entities (non-owning registry reset). */
void clear() { all_entities_.clear(); }
/** Remove all registered entities and release manager-owned entities. */
void clear()
{
all_entities_.clear();
owned_entities_.clear();
}

template <typename T>
T *addEntity(const std::string &name, T *entity)
Expand All @@ -87,14 +93,85 @@ class EntityManager
return entity;
}

template <typename T>
T *addEntity(const std::string &name, SharedPtr<T> entity)
{
T *existing_entity = findEntityByName<T>(name);
if (existing_entity == nullptr)
{
all_entities_[typeid(T)][name] = entity.get();
owned_entities_[typeid(T)][name] = std::static_pointer_cast<void>(std::move(entity));
return static_cast<T *>(all_entities_[typeid(T)][name]);
}
return existing_entity;
}

template <typename T>
T *addEntityOrThrow(const std::string &name, SharedPtr<T> entity)
{
T *existing_entity = findEntityByName<T>(name);
if (existing_entity != nullptr)
{
throw std::runtime_error(std::string(type_name<T>()) + ": duplicated entity name '" + name + "'");
}
all_entities_[typeid(T)][name] = entity.get();
owned_entities_[typeid(T)][name] = std::static_pointer_cast<void>(std::move(entity));
return static_cast<T *>(all_entities_[typeid(T)][name]);
}

template <typename T, typename... Args>
T *emplaceEntity(const std::string &name, Args &&...args)
{
T *existing_entity = findEntityByName<T>(name);
if (existing_entity == nullptr)
{
SharedPtr<T> entity = makeShared<T>(std::forward<Args>(args)...);
all_entities_[typeid(T)][name] = entity.get();
owned_entities_[typeid(T)][name] = std::static_pointer_cast<void>(std::move(entity));
return static_cast<T *>(all_entities_[typeid(T)][name]);
}
return existing_entity;
}

template <typename T, typename... Args>
T *emplaceEntityOrThrow(const std::string &name, Args &&...args)
{
T *existing_entity = findEntityByName<T>(name);
if (existing_entity != nullptr)
{
throw std::runtime_error(std::string(type_name<T>()) + ": duplicated entity name '" + name + "'");
}
SharedPtr<T> entity = makeShared<T>(std::forward<Args>(args)...);
all_entities_[typeid(T)][name] = entity.get();
owned_entities_[typeid(T)][name] = std::static_pointer_cast<void>(std::move(entity));
return static_cast<T *>(all_entities_[typeid(T)][name]);
}

template <typename T>
bool removeEntity(const std::string &name)
{
auto type_it = all_entities_.find(typeid(T));
if (type_it == all_entities_.end())
return false;

return type_it->second.erase(name) > 0;
bool removed = type_it->second.erase(name) > 0;

auto owned_type_it = owned_entities_.find(typeid(T));
if (owned_type_it != owned_entities_.end())
{
owned_type_it->second.erase(name);
if (owned_type_it->second.empty())
{
owned_entities_.erase(owned_type_it);
}
}

if (type_it->second.empty())
{
all_entities_.erase(type_it);
}

return removed;
}

template <typename T>
Expand Down Expand Up @@ -156,7 +233,8 @@ class EntityManager
}

std::sort(named_entities.begin(), named_entities.end(),
[](const auto &a, const auto &b) { return a.first < b.first; });
[](const auto &a, const auto &b)
{ return a.first < b.first; });

std::vector<T *> result;
result.reserve(named_entities.size());
Expand Down
6 changes: 3 additions & 3 deletions src/shared/geometries/complex_geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace SPH
class ComplexShape : public BinaryShapes
{
public:
explicit ComplexShape(const std::string &shape_name)
explicit ComplexShape(const std::string &shape_name = "ComplexShape")
: BinaryShapes(shape_name) {};
virtual ~ComplexShape() {};

Expand All @@ -76,8 +76,8 @@ class AlignedBox : public TransformGeometry<GeometricBox>
public:
/** construct directly */
template <typename... Args>
explicit AlignedBox(int upper_bound_axis, const Transform &transform, Args &&...args)
: TransformGeometry<GeometricBox>(transform, std::forward<Args>(args)...),
explicit AlignedBox(int upper_bound_axis, Args &&...args)
: TransformGeometry<GeometricBox>(std::forward<Args>(args)...),
alignment_axis_(upper_bound_axis){};
/** construct from a shape already has aligned boundaries */
template <typename... Args>
Expand Down
1 change: 1 addition & 0 deletions src/shared/geometries/geometric_element.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class GeometricBox

Vecd findClosestPoint(const Vecd &probe_point);
BoundingBoxd findBounds();
Vecd HalfSize() const { return halfsize_; }

protected:
Vecd halfsize_;
Expand Down
4 changes: 4 additions & 0 deletions src/shared/geometries/geometric_shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ GeometricShapeBox::GeometricShapeBox(
const Transform &transform, const Vecd &halfsize, const std::string &name)
: TransformShape<GeometricBox>(name, transform, halfsize) {}
//=================================================================================================//
GeometricShapeBox::GeometricShapeBox(
const TransformGeometryBox &transformed_box, const std::string &name)
: GeometricShapeBox(Transform(transformed_box.initialTransform()), transformed_box.HalfSize(), name) {}
//=================================================================================================//
GeometricShapeBox::GeometricShapeBox(const BoundingBoxd &bounding_box, const std::string &name)
: TransformShape<GeometricBox>(
name,
Expand Down
3 changes: 3 additions & 0 deletions src/shared/geometries/geometric_shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ class GeometricShapeBox : public TransformShape<GeometricBox>
public:
GeometricShapeBox(const Transform &transform, const Vecd &halfsize,
const std::string &name = "GeometricShapeBox");
GeometricShapeBox(const TransformGeometryBox &transformed_box,
const std::string &name = "GeometricShapeBox");
explicit GeometricShapeBox(const BoundingBoxd &bounding_box,
const std::string &name = "GeometricShapeBox");
virtual ~GeometricShapeBox() {};
void writeProxy();
};

class GeometricShapeBall : public GeometricBall, public Shape
Expand Down
8 changes: 7 additions & 1 deletion src/shared/geometries/transform_geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ class TransformGeometry : public GeometryType
public:
template <typename... Args>
explicit TransformGeometry(const Transform &transform, Args &&...args)
: GeometryType(std::forward<Args>(args)...), transform_(transform){};
: GeometryType(std::forward<Args>(args)...),
initial_transform_(transform), transform_(transform){};
~TransformGeometry() {};

/** variable transform is introduced here */
Transform &getTransform() { return transform_; };
Transform initialTransform() const { return initial_transform_; };
void setTransform(const Transform &transform) { transform_ = transform; };

bool checkContain(const Vecd &probe_point)
Expand Down Expand Up @@ -92,9 +94,13 @@ class TransformGeometry : public GeometryType
};

protected:
Transform initial_transform_;
Transform transform_;
};

using TransformGeometryBox = TransformGeometry<GeometricBox>;
using TransformGeometryCylinder = TransformGeometry<GeometricCylinder>;

/**
* @class TransformShape
* @brief A template shape in which coordinate transformation is applied
Expand Down
Loading
Loading