Commit 4079ab5a authored by Alain O' Miniussi's avatar Alain O' Miniussi
Browse files

Move cuda stuff in hidden base class in disk

parent d3a727bc
...@@ -39,10 +39,86 @@ namespace fargOCA { ...@@ -39,10 +39,86 @@ namespace fargOCA {
class DiskPhysic; class DiskPhysic;
class Planet; class Planet;
class Disk class DiskPrivate {
: public std::enable_shared_from_this<Disk> { protected:
DiskPrivate(shptr<PlanetarySystem> sys,
shptr<DiskPhysic const> physic,
shptr<GridDispatch const> grid);
~DiskPrivate();
public: public:
template<class T> using opt = std::optional<T>; template<class T> using opt = std::optional<T>;
GridDispatch const& grid() const { return *myGrid; }
DiskPhysic const& physic() const { return *myPhysic; }
ScalarField const& density() const { return myDensity; }
ScalarField& mdensity();
opt<ScalarField> const& deadDensity() const;
opt<ScalarField> const& energy() const { return myEnergy; }
opt<ScalarField>& menergy();
ScalarField const& soundSpeed() const;
ScalarField const& pressure() const;
ScalarField const& viscosity() const;
opt<ScalarField>& radiativeEnergy() { return myRadiativeEnergy; }
opt<ScalarField> const& radiativeEnergy() const { return myRadiativeEnergy; }
opt<ScalarField>& radiativeEnergyDerivative() { return myRadiativeEnergyDerivative; }
opt<ScalarField> const& radiativeEnergyDerivative() const { return myRadiativeEnergyDerivative; }
public:
void computeSoundSpeed();
void computePressure();
void computeViscosity();
void computeTemperature();
void computeDeadDensity();
void cleanGasMinimums();
void initRadialVelocity();
void trashSoundSpeed();
void trashDensity();
void trashEnergy();
void trashPressure();
void trashViscosity();
void trashTemperature();
void trashDeadDensity();
void trashDerivedFields();
protected:
shptr<PlanetarySystem> mySystem;
shptr<DiskPhysic const> myPhysic;
shptr<GridDispatch const> myGrid;
VectorField myVelocity;
ScalarField myDensity;
ScalarField mySoundSpeed;
ScalarField myPressure;
ScalarField myViscosity;
opt<ScalarField> myTemperature;
opt<ScalarField> myDeadDensity;
opt<ScalarField> myEnergy;
opt<ScalarField> myRadiativeEnergy;
opt<ScalarField> myRadiativeEnergyDerivative;
bool mySoundSpeedClean;
bool myPressureClean;
bool myViscosityClean;
Triplet myGasAcceleration;
std::unique_ptr<DiskProfiles> myProfiles;
std::map<std::string, ScalarField> myUserFields;
std::map<std::string, ScalarField> myTracers;
real myFrameOmega;
real myPhysicalTime;
};
class Disk
: public std::enable_shared_from_this<Disk>,
private DiskPrivate {
public:
typedef DiskPrivate base;
/// \brief Load from file. /// \brief Load from file.
static shptr<Disk> make(fmpi::communicator const& comm, H5::Group const& root); static shptr<Disk> make(fmpi::communicator const& comm, H5::Group const& root);
/// \brief Make a disk in it's initial user specified state. /// \brief Make a disk in it's initial user specified state.
...@@ -51,9 +127,11 @@ namespace fargOCA { ...@@ -51,9 +127,11 @@ namespace fargOCA {
shptr<Disk> shared() { return shared_from_this(); } shptr<Disk> shared() { return shared_from_this(); }
shptr<Disk const> shared() const { return shared_from_this(); } shptr<Disk const> shared() const { return shared_from_this(); }
GridDispatch const& grid() const { return *myGrid; } /// \brief The grid on which the disk is dispatched
DiskPhysic const& physic() const { return *myPhysic; } GridDispatch const& grid() const { return base::grid(); }
/// \brief The requested physic
DiskPhysic const& physic() const { return base::physic(); }
/// \brief The frame rotation velocity /// \brief The frame rotation velocity
real frameVelocity() const; real frameVelocity() const;
...@@ -73,22 +151,26 @@ namespace fargOCA { ...@@ -73,22 +151,26 @@ namespace fargOCA {
VectorField& velocity() { return myVelocity; } VectorField& velocity() { return myVelocity; }
VectorField const& velocity() const { return myVelocity; } VectorField const& velocity() const { return myVelocity; }
ScalarField& mdensity(); /// \brief The modifiable density field
ScalarField const& density() const { return myDensity; } ScalarField& mdensity() { return base::mdensity(); }
opt<ScalarField>& menergy(); /// \brief The non modifiable density field
opt<ScalarField> const& energy() const { return myEnergy; } ScalarField const& density() const { return base::density(); }
opt<ScalarField>& radiativeEnergy() { return myRadiativeEnergy; } /// \brief The modifiable energy field
opt<ScalarField> const& radiativeEnergy() const { return myRadiativeEnergy; } opt<ScalarField>& menergy() { return base::menergy(); }
opt<ScalarField>& radiativeEnergyDerivative() { return myRadiativeEnergyDerivative; } /// \brief The non modifiable energy field
opt<ScalarField> const& radiativeEnergyDerivative() const { return myRadiativeEnergyDerivative; } opt<ScalarField> const& energy() const { return base::energy(); }
opt<ScalarField>& radiativeEnergy() { return base::radiativeEnergy(); }
opt<ScalarField> const& radiativeEnergy() const { return base::radiativeEnergy(); }
opt<ScalarField>& radiativeEnergyDerivative() { return base::radiativeEnergyDerivative(); }
opt<ScalarField> const& radiativeEnergyDerivative() const { return base::radiativeEnergyDerivative(); }
void setGhosts(); void setGhosts();
bool checkPhysicalQuantities() const; bool checkPhysicalQuantities() const;
ScalarField const& soundSpeed() const; ScalarField const& soundSpeed() const { return base::soundSpeed(); }
ScalarField const& pressure() const; ScalarField const& pressure() const { return base::pressure(); }
ScalarField const& viscosity() const; ScalarField const& viscosity() const { return base::viscosity(); }
DiskProfiles const& profiles() const { return *myProfiles; } DiskProfiles const& profiles() const { return *myProfiles; }
void flashProfiles(); void flashProfiles();
...@@ -105,7 +187,7 @@ namespace fargOCA { ...@@ -105,7 +187,7 @@ namespace fargOCA {
/// \brief No idea /// \brief No idea
/// Will be none if star accretion type is ot WIND /// Will be none if star accretion type is ot WIND
/// The returned reference will be invalidated by anny modification of density /// The returned reference will be invalidated by anny modification of density
opt<ScalarField> const& deadDensity() const; opt<ScalarField> const& deadDensity() const { return base::deadDensity(); }
/// \brief Compute some potential based on the system. /// \brief Compute some potential based on the system.
ScalarField computeSystemPotential() const; ScalarField computeSystemPotential() const;
...@@ -202,33 +284,7 @@ namespace fargOCA { ...@@ -202,33 +284,7 @@ namespace fargOCA {
void mapStateFields(std::function<void (ScalarField const&)> f) const; void mapStateFields(std::function<void (ScalarField const&)> f) const;
void mapStateFields(std::function<void (ScalarField&)> f); void mapStateFields(std::function<void (ScalarField&)> f);
public:
void cudaComputeSoundSpeed();
void cudaComputePressure();
void cudaComputeViscosity();
void cudaComputeTemperature();
void cudaComputeDeadDensity();
void cudaCleanGasMinimums();
void cudaInitRadialVelocity();
private:
void computeSoundSpeed() { return cudaComputeSoundSpeed(); }
void computePressure() { return cudaComputePressure(); }
void computeViscosity() { return cudaComputeViscosity(); }
void computeTemperature() { return cudaComputeTemperature(); }
void computeDeadDensity() { return cudaComputeDeadDensity(); }
void cleanGasMinimums() { return cudaCleanGasMinimums(); }
void trashSoundSpeed();
void trashDensity();
void trashEnergy();
void trashPressure();
void trashViscosity();
void trashTemperature();
void trashDeadDensity();
void trashDerivedFields();
void initRadialVelocity() { return cudaInitRadialVelocity(); }
void initThetaVelocity(); void initThetaVelocity();
void initDensity(); void initDensity();
void initEnergy(); void initEnergy();
...@@ -237,36 +293,10 @@ namespace fargOCA { ...@@ -237,36 +293,10 @@ namespace fargOCA {
void initGasValue(); void initGasValue();
private: private:
shptr<PlanetarySystem> mySystem;
shptr<DiskPhysic const> myPhysic;
shptr<GridDispatch const> myGrid;
VectorField myVelocity;
ScalarField myDensity;
ScalarField mySoundSpeed;
ScalarField myPressure;
ScalarField myViscosity;
opt<ScalarField> myTemperature;
opt<ScalarField> myDeadDensity;
opt<ScalarField> myEnergy;
opt<ScalarField> myRadiativeEnergy;
opt<ScalarField> myRadiativeEnergyDerivative;
bool mySoundSpeedClean;
bool myPressureClean;
bool myViscosityClean;
Triplet myGasAcceleration;
std::unique_ptr<DiskProfiles> myProfiles;
typedef std::function<void(BoundaryConditions*)> BCDeleter; typedef std::function<void(BoundaryConditions*)> BCDeleter;
typedef std::unique_ptr<BoundaryConditions, BCDeleter> BCPtr; typedef std::unique_ptr<BoundaryConditions, BCDeleter> BCPtr;
std::list<BCPtr> myBoundaryConditions; std::list<BCPtr> myBoundaryConditions;
std::map<std::string, ScalarField> myUserFields;
std::map<std::string, ScalarField> myTracers;
real myFrameOmega;
real myPhysicalTime;
}; };
/// \brief A range of string->scalar field pairs extracted from a disc. /// \brief A range of string->scalar field pairs extracted from a disc.
......
...@@ -51,10 +51,9 @@ namespace fargOCA { ...@@ -51,10 +51,9 @@ namespace fargOCA {
Disk::~Disk() {} Disk::~Disk() {}
Disk::Disk(NoInit, DiskPrivate::DiskPrivate(shptr<PlanetarySystem> sys,
shptr<PlanetarySystem> sys, shptr<DiskPhysic const> physic,
shptr<DiskPhysic const> physic, shptr<GridDispatch const> grid)
shptr<GridDispatch const> grid)
: mySystem(sys), : mySystem(sys),
myPhysic(physic), myPhysic(physic),
myGrid(grid), myGrid(grid),
...@@ -75,9 +74,18 @@ namespace fargOCA { ...@@ -75,9 +74,18 @@ namespace fargOCA {
myPhysicalTime(0) myPhysicalTime(0)
{ {
assert(!mySystem || mySystem->physic().shared() == myPhysic->shared()); assert(!mySystem || mySystem->physic().shared() == myPhysic->shared());
initGasMemory();
} }
DiskPrivate::~DiskPrivate() {}
Disk::Disk(NoInit,
shptr<PlanetarySystem> sys,
shptr<DiskPhysic const> physic,
shptr<GridDispatch const> grid)
: DiskPrivate(sys, physic, grid) {
initGasMemory();
}
Disk::Disk(shptr<PlanetarySystem> sys, Disk::Disk(shptr<PlanetarySystem> sys,
shptr<DiskPhysic const> physic, shptr<DiskPhysic const> physic,
shptr<GridDispatch const> grid) shptr<GridDispatch const> grid)
...@@ -89,7 +97,7 @@ namespace fargOCA { ...@@ -89,7 +97,7 @@ namespace fargOCA {
shptr<Disk> shptr<Disk>
Disk::make(DiskPhysic const& physic, Disk::make(DiskPhysic const& physic,
GridDispatch const& grid) { GridDispatch const& grid) {
return shptr<Disk>(new Disk(PlanetarySystem::make(physic), physic.shared(), grid.shared())); return shptr<Disk>(new Disk(PlanetarySystem::make(physic), physic.shared(), grid.shared()));
} }
...@@ -199,7 +207,7 @@ namespace fargOCA { ...@@ -199,7 +207,7 @@ namespace fargOCA {
} }
void void
Disk::cudaComputeSoundSpeed() { DiskPrivate::computeSoundSpeed() {
assert(checkPhysicalQuantities()); assert(checkPhysicalQuantities());
// We compute the sound speed, for the isothermal case remember that // We compute the sound speed, for the isothermal case remember that
// the disk.physic().flaringIndex is included in the aspectratio vector // the disk.physic().flaringIndex is included in the aspectratio vector
...@@ -226,15 +234,15 @@ namespace fargOCA { ...@@ -226,15 +234,15 @@ namespace fargOCA {
} }
ScalarField const& ScalarField const&
Disk::soundSpeed() const { DiskPrivate::soundSpeed() const {
if (!mySoundSpeedClean) { if (!mySoundSpeedClean) {
const_cast<Disk&>(*this).computeSoundSpeed(); const_cast<DiskPrivate&>(*this).computeSoundSpeed();
} }
return mySoundSpeed; return mySoundSpeed;
} }
void void
Disk::cudaComputeViscosity() { DiskPrivate::computeViscosity() {
int const nr = grid().nbRadius(); int const nr = grid().nbRadius();
int const ni = grid().nbLayer(); int const ni = grid().nbLayer();
int const ns = grid().nbSector(); int const ns = grid().nbSector();
...@@ -267,9 +275,9 @@ namespace fargOCA { ...@@ -267,9 +275,9 @@ namespace fargOCA {
} }
ScalarField const& ScalarField const&
Disk::viscosity() const { DiskPrivate::viscosity() const {
if (!myViscosityClean) { if (!myViscosityClean) {
const_cast<Disk&>(*this).computeViscosity(); const_cast<DiskPrivate&>(*this).computeViscosity();
} }
return myViscosity; return myViscosity;
} }
...@@ -364,7 +372,7 @@ namespace fargOCA { ...@@ -364,7 +372,7 @@ namespace fargOCA {
} }
void void
Disk::cudaComputeTemperature() { DiskPrivate::computeTemperature() {
assert(!myTemperature); assert(!myTemperature);
if (physic().radiative()) { if (physic().radiative()) {
int const nr = grid().nbRadius(); int const nr = grid().nbRadius();
...@@ -398,12 +406,12 @@ namespace fargOCA { ...@@ -398,12 +406,12 @@ namespace fargOCA {
} }
void void
Disk::trashTemperature() { DiskPrivate::trashTemperature() {
myTemperature = std::nullopt; myTemperature = std::nullopt;
} }
void void
Disk::cudaComputePressure() { DiskPrivate::computePressure() {
arr3d<real> pressure = myPressure.data(); arr3d<real> pressure = myPressure.data();
if (physic().adiabatic) { if (physic().adiabatic) {
real indexm = physic().adiabatic->index-1; real indexm = physic().adiabatic->index-1;
...@@ -420,9 +428,9 @@ namespace fargOCA { ...@@ -420,9 +428,9 @@ namespace fargOCA {
} }
ScalarField const& ScalarField const&
Disk::pressure() const { DiskPrivate::pressure() const {
if (!myPressureClean) { if (!myPressureClean) {
const_cast<Disk&>(*this).computePressure(); const_cast<DiskPrivate&>(*this).computePressure();
} }
return myPressure; return myPressure;
} }
...@@ -661,7 +669,7 @@ namespace fargOCA { ...@@ -661,7 +669,7 @@ namespace fargOCA {
} }
void void
Disk::cudaCleanGasMinimums() { DiskPrivate::cleanGasMinimums() {
// rebind can introduce weird values through interpolation. // rebind can introduce weird values through interpolation.
// check some basic properties: // check some basic properties:
real densityMin = physic().density.minimum/RHO0; real densityMin = physic().density.minimum/RHO0;
...@@ -1016,7 +1024,7 @@ namespace fargOCA { ...@@ -1016,7 +1024,7 @@ namespace fargOCA {
} }
void void
Disk::cudaComputeDeadDensity() { DiskPrivate::computeDeadDensity() {
ScalarField dead("dead_density", grid()); ScalarField dead("dead_density", grid());
int const nr = grid().nbRadius(); int const nr = grid().nbRadius();
...@@ -1053,31 +1061,31 @@ namespace fargOCA { ...@@ -1053,31 +1061,31 @@ namespace fargOCA {
} }
std::optional<ScalarField> const& std::optional<ScalarField> const&
Disk::deadDensity() const { DiskPrivate::deadDensity() const {
if (physic().starAccretion.type == SA_WIND if (physic().starAccretion.type == SA_WIND
&& !myDeadDensity) { && !myDeadDensity) {
const_cast<Disk&>(*this).computeDeadDensity(); const_cast<DiskPrivate&>(*this).computeDeadDensity();
} }
return myDeadDensity; return myDeadDensity;
} }
void void
Disk::trashViscosity() { DiskPrivate::trashViscosity() {
myViscosityClean = false; myViscosityClean = false;
} }
void void
Disk::trashPressure() { DiskPrivate::trashPressure() {
myPressureClean = false; myPressureClean = false;
} }
void void
Disk::trashDeadDensity() { DiskPrivate::trashDeadDensity() {
myDeadDensity = std::nullopt; myDeadDensity = std::nullopt;
} }
void void
Disk::trashDensity() { DiskPrivate::trashDensity() {
if (physic().adiabatic) { if (physic().adiabatic) {
trashSoundSpeed(); trashSoundSpeed();
if (physic().radiative()) { if (physic().radiative()) {
...@@ -1093,13 +1101,13 @@ namespace fargOCA { ...@@ -1093,13 +1101,13 @@ namespace fargOCA {
ScalarField& ScalarField&
Disk::mdensity() { DiskPrivate::mdensity() {
trashDensity(); trashDensity();
return myDensity; return myDensity;
} }
void void
Disk::trashSoundSpeed() { DiskPrivate::trashSoundSpeed() {
mySoundSpeedClean = false; mySoundSpeedClean = false;
if (!physic().adiabatic) { if (!physic().adiabatic) {
trashPressure(); trashPressure();
...@@ -1110,7 +1118,7 @@ namespace fargOCA { ...@@ -1110,7 +1118,7 @@ namespace fargOCA {
} }
void void
Disk::trashEnergy() { DiskPrivate::trashEnergy() {
if (physic().adiabatic) { if (physic().adiabatic) {
trashSoundSpeed(); trashSoundSpeed();
trashPressure(); trashPressure();
...@@ -1121,13 +1129,13 @@ namespace fargOCA { ...@@ -1121,13 +1129,13 @@ namespace fargOCA {
} }
std::optional<ScalarField>& std::optional<ScalarField>&
Disk::menergy() { DiskPrivate::menergy() {
trashEnergy(); trashEnergy();
return myEnergy; return myEnergy;
} }
void void
Disk::trashDerivedFields() { DiskPrivate::trashDerivedFields() {
trashPressure(); trashPressure();
trashSoundSpeed(); trashSoundSpeed();
trashViscosity(); trashViscosity();
...@@ -1135,7 +1143,7 @@ namespace fargOCA { ...@@ -1135,7 +1143,7 @@ namespace fargOCA {
} }
void void
Disk::cudaInitRadialVelocity() { DiskPrivate::initRadialVelocity() {
int const nr = grid().nbRadius(); int const nr = grid().nbRadius();
int const ni = grid().nbLayer(); int const ni = grid().nbLayer();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment