-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from kjetil-lye/master
Adding entropy functional
- Loading branch information
Showing
7 changed files
with
706 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* Copyright (c) 2018 ETH Zurich, Kjetil Olsen Lye | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
#include "alsfvm/functional/Functional.hpp" | ||
|
||
namespace alsfvm { | ||
namespace functional { | ||
|
||
//! | ||
//! Computes the thermodynamic entropy, see | ||
//! | ||
//! Fjordholm, U. S., Mishra, S., & Tadmor, E. (2012). Arbitrarily high-order accurate entropy stable essentially nonoscillatory schemes for systems of conservation laws, 50(2), 544–573. | ||
//! | ||
//! for a definition (2.16), E. | ||
//! | ||
//! Note that we compute the spatial integral of the entropy at all points. | ||
//! | ||
//! Specifically, we set | ||
//! | ||
//! \f[ s = \log(p)-\gamma\log(p)\f] | ||
//! | ||
//! where \f$\gamma>0\f$ is the gas constant. We set the entropy $E$ to be | ||
//! | ||
//! \f[E=\frac{-\rho s}{\gamma-1}\f] | ||
//! | ||
//! This functional computes | ||
//! | ||
//! \f[\int_D E \;dx\f] | ||
//! | ||
//! | ||
//! | ||
//! | ||
class LogEntropy : public Functional { | ||
public: | ||
|
||
//! Uses no parameter | ||
LogEntropy(const Parameters& parameters); | ||
|
||
//! Computes the operator value on the given input data | ||
//! | ||
//! @note In order to support time integration, the result should be | ||
//! added to conservedVolumeOut and extraVolumeOut, not overriding | ||
//! it. | ||
//! | ||
//! @param[out] conservedVolumeOut at the end, should have the contribution | ||
//! of the functional for the conservedVariables | ||
//! | ||
//! | ||
//! @param[in] conservedVolumeIn the state of the conserved variables | ||
//! | ||
//! @param[in] weight the current weight to be applied to the functional. Ie, the functional should compute | ||
//! \code{.cpp} | ||
//! conservedVolumeOut += weight + f(conservedVolumeIn) | ||
//! \endcode | ||
//! | ||
//! @param[in] grid the grid to use | ||
//! | ||
virtual void operator()(volume::Volume& conservedVolumeOut, | ||
const volume::Volume& conservedVolumeIn, | ||
const real weight, | ||
const grid::Grid& grid | ||
) override; | ||
|
||
//! Returns grid.getDimensions() | ||
virtual ivec3 getFunctionalSize(const grid::Grid& grid) const override; | ||
|
||
|
||
private: | ||
|
||
const real gamma; | ||
|
||
}; | ||
} // namespace functional | ||
} // namespace alsfvm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* Copyright (c) 2018 ETH Zurich, Kjetil Olsen Lye | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
#include "alsfvm/functional/Functional.hpp" | ||
#include "alsfvm/cuda/CudaMemory.hpp" | ||
|
||
|
||
namespace alsfvm { | ||
namespace functional { | ||
|
||
//! | ||
//! Computes the thermodynamic entropy, see | ||
//! | ||
//! Fjordholm, U. S., Mishra, S., & Tadmor, E. (2012). Arbitrarily high-order accurate entropy stable essentially nonoscillatory schemes for systems of conservation laws, 50(2), 544–573. | ||
//! | ||
//! for a definition (2.16), E. | ||
//! | ||
//! Note that we compute the spatial integral of the entropy at all points. | ||
//! | ||
//! Specifically, we set | ||
//! | ||
//! \f[ s = \log(p)-\gamma\log(p)\f] | ||
//! | ||
//! where \f$\gamma>0\f$ is the gas constant. We set the entropy $E$ to be | ||
//! | ||
//! \f[E=\frac{-\rho s}{\gamma-1}\f] | ||
//! | ||
//! This functional computes | ||
//! | ||
//! \f[\int_D E \;dx\f] | ||
//! | ||
//! | ||
//! | ||
//! | ||
class LogEntropyCUDA : public Functional { | ||
public: | ||
|
||
//! Uses no parameter | ||
LogEntropyCUDA(const Parameters& parameters); | ||
|
||
//! Computes the operator value on the given input data | ||
//! | ||
//! @note In order to support time integration, the result should be | ||
//! added to conservedVolumeOut and extraVolumeOut, not overriding | ||
//! it. | ||
//! | ||
//! @param[out] conservedVolumeOut at the end, should have the contribution | ||
//! of the functional for the conservedVariables | ||
//! | ||
//! | ||
//! @param[in] conservedVolumeIn the state of the conserved variables | ||
//! | ||
//! @param[in] weight the current weight to be applied to the functional. Ie, the functional should compute | ||
//! \code{.cpp} | ||
//! conservedVolumeOut += weight + f(conservedVolumeIn) | ||
//! \endcode | ||
//! | ||
//! @param[in] grid the grid to use | ||
//! | ||
virtual void operator()(volume::Volume& conservedVolumeOut, | ||
const volume::Volume& conservedVolumeIn, | ||
const real weight, | ||
const grid::Grid& grid | ||
) override; | ||
|
||
//! Returns grid.getDimensions() | ||
virtual ivec3 getFunctionalSize(const grid::Grid& grid) const override; | ||
|
||
|
||
private: | ||
|
||
const real gamma; | ||
|
||
alsfvm::shared_ptr<cuda::CudaMemory<real>> buffer = nullptr; | ||
alsfvm::shared_ptr<cuda::CudaMemory<real>> bufferOut = nullptr; | ||
alsfvm::shared_ptr<cuda::CudaMemory<real>> temporaryReductionMemory = nullptr; | ||
size_t temporaryReductionMemoryStorageSizeBytes = 0; | ||
|
||
}; | ||
} // namespace functional | ||
} // namespace alsfvm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include "alsfvm/functional/LogEntropy.hpp" | ||
#include "alsfvm/volume/volume_foreach.hpp" | ||
#include "alsfvm/functional/register_functional.hpp" | ||
#include <iostream> | ||
namespace alsfvm { | ||
namespace functional { | ||
|
||
LogEntropy::LogEntropy(const Functional::Parameters& parameters) | ||
: gamma(parameters.getDouble("gamma")) { | ||
|
||
|
||
} | ||
|
||
void LogEntropy::operator()(volume::Volume& conservedVolumeOut, | ||
const volume::Volume& conservedVolumeIn, const real weight, | ||
const grid::Grid& grid) { | ||
|
||
const auto lengths = grid.getCellLengths(); | ||
|
||
const real dxdydz = lengths.x * lengths.y * lengths.z; | ||
|
||
|
||
real integral = 0.0; | ||
|
||
const auto& densityView = conservedVolumeIn.getScalarMemoryArea( | ||
"rho")->getView(); | ||
|
||
const auto& energyView = conservedVolumeIn.getScalarMemoryArea( | ||
"E")->getView(); | ||
|
||
const size_t numberOfComponents = grid.getActiveDimension(); | ||
|
||
std::vector<const real*> momentumPointers; | ||
|
||
|
||
momentumPointers.push_back( | ||
conservedVolumeIn.getScalarMemoryArea("mx")->getPointer()); | ||
|
||
if (numberOfComponents > 1) { | ||
momentumPointers.push_back( | ||
conservedVolumeIn.getScalarMemoryArea("my")->getPointer()); | ||
} | ||
|
||
if (numberOfComponents > 2) { | ||
momentumPointers.push_back( | ||
conservedVolumeIn.getScalarMemoryArea("mz")->getPointer()); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
volume::for_each_midpoint(conservedVolumeIn, grid, [&](real, real, real, | ||
size_t i) { | ||
|
||
const real density = densityView.at(i); | ||
const real energy = energyView.at(i); | ||
|
||
double momentumSquared = 0.0; | ||
|
||
for (size_t component = 0; component < numberOfComponents; ++component) { | ||
const auto momentum = momentumPointers[component][i]; | ||
momentumSquared += momentum * momentum; | ||
} | ||
|
||
const real pressure = (gamma - 1) * (energy - 1.0 / (2 * density) * | ||
momentumSquared); | ||
|
||
|
||
const real s = log(pressure) - gamma * log(density); | ||
const real E = (-density * s) / (gamma - 1); | ||
|
||
integral += E * dxdydz; | ||
}); | ||
|
||
conservedVolumeOut.getScalarMemoryArea("E")->getPointer()[0] += weight | ||
* integral; | ||
} | ||
|
||
ivec3 LogEntropy::getFunctionalSize(const grid::Grid&) const { | ||
return {1, 1, 1}; | ||
} | ||
REGISTER_FUNCTIONAL(cpu, log_entropy, LogEntropy) | ||
} | ||
} |
Oops, something went wrong.