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