Xiangyu-Hu / SPHinXsys

SPHinXsys provides C++ APIs for engineering simulation and optimization. It aims at complex systems driven by fluid, structure, multi-body dynamics and beyond. The multi-physics library is based on a unique and unified computational framework by which strong coupling has been achieved for all involved physics.
https://www.sphinxsys.org/
Apache License 2.0
259 stars 199 forks source link

Problems when Implementing code framework for general continuum #313

Closed Shuaihao-Zhang closed 1 month ago

Shuaihao-Zhang commented 11 months ago

As we discussed before, we just need continuum_dynamics for mechanical relaxation and general_continuum for material properties. For the particle and body, we just used the BaseParticles and RealBody.

I encountered with a problem here.

Normally, there will be a member variable to record the material in the class *Particles, such as in the fluid: https://github.com/Xiangyu-Hu/SPHinXsys/blob/350ef8fc04637c0b51bbb2ad9b839224c09afb35/src/shared/particles/fluid_particles.h#L54 Then, we can get the material type in the relaxation process based on the particle type, like what we do in the fluid: https://github.com/Xiangyu-Hu/SPHinXsys/blob/350ef8fc04637c0b51bbb2ad9b839224c09afb35/src/shared/particle_dynamics/fluid_dynamics/fluid_dynamics_inner.cpp#L59 We use fluid_(particles_->fluid_) to get the material type based on the particle type. So that we can use the functions defined in the materials through the variable fluid_.

The problem is that if we use BaseParticles, we can only get 'BaseMaterial' through the particle type, and we cannot get the material GeneralContinuum. Then I don't know how can we use the member functions and variables defined in the material GeneralContinuum.

Xiangyu-Hu commented 11 months ago

It can be obtained by dynamic cast if you have base material pointer. https://github.com/Xiangyu-Hu/SPHinXsys/blob/350ef8fc04637c0b51bbb2ad9b839224c09afb35/src/shared/particle_dynamics/base_particle_dynamics.hpp#L40-L52

Shuaihao-Zhang commented 11 months ago

I see. Thanks!

Shuaihao-Zhang commented 11 months ago

Hi, I got another question.

We use BaseParticles here. If I want to use the Classes defined in fluid_dynamics, I need the member variable pressure p_ and many other variables. p_ is registered in FluidParticles. I cannot use p_(DynamicCast<FluidParticles>(this, particles_)->p_) to get the variable p_, because I don't use FluidParticles and p_ is not registered yet.

So, should I register pressure p_ by my self in the continuum_dynamics? This way seems not very good, because I need to register many variables same to those registered in the FluidParticlesand SolidParticles.

DrChiZhang commented 11 months ago

Hi, I got another question.

We use BaseParticles here. If I want to use the Classes defined in fluid_dynamics, I need the member variable pressure p_ and many other variables. p_ is registered in FluidParticles. I cannot use p_(DynamicCast<FluidParticles>(this, particles_)->p_) to get the variable p_, because I don't use FluidParticles and p_ is not registered yet.

So, should I register pressure p_ by my self in the continuum_dynamics? This way seems not very good, because I need to register many variables same to those registered in the FluidParticlesand SolidParticles. One option maybe: Try to use some register variables only in dynamics, viz. these variables are registered when specific dynamics are used.

Shuaihao-Zhang commented 11 months ago

Thanks, Chi. I guess this can solve the current issue. But we need to re-organize the previous code framework. I think we should delete the FluidParticlesand SolidParticles, and register all the variables in the fluid_dynamicsand solid_dynamics. I'm not sure if this will lead to any other issues.

DrChiZhang commented 11 months ago

Thanks, Chi. I guess this can solve the current issue. But we need to re-organize the previous code framework. I think we should delete the FluidParticlesand SolidParticles, and register all the variables in the fluid_dynamicsand solid_dynamics. I'm not sure if this will lead to any other issues.

For this kind of fundamental change, we need careful discussion with Xiangyu and other contributors. You can initialize a Issue to talk this, meanwhile implement your algorithm with independent registered variables in dynamics.

Shuaihao-Zhang commented 11 months ago

For this kind of fundamental change, we need careful discussion with Xiangyu and other contributors. You can initialize a Issue to talk this, meanwhile implement your algorithm with independent registered variables in dynamics.

Thanks, I will discuss with Prof. Hu next week.

Xiangyu-Hu commented 11 months ago

After the discussion, it seems that we need make fluid and solid class virtually inherited from base material.

Shuaihao-Zhang commented 11 months ago

After the discussion, it seems that we need make fluid and solid class virtually inherited from base material.

Sure. I will try this way.

Xiangyu-Hu commented 1 month ago

Now the continuum media is implelemented.