28#ifndef DUMUX_CHECK_FLUIDSYSTEM_HH
29#define DUMUX_CHECK_FLUIDSYSTEM_HH
34#include <dune/common/classname.hh>
68template<
class ScalarType,
class Flu
idSystem,
class BaseFlu
idState = CompositionalFlu
idState<ScalarType, Flu
idSystem> >
73 using typename BaseFluidState::Scalar;
75 static constexpr int numPhases = FluidSystem::numPhases;
81 BaseFluidState::setTemperature(293.15);
82 for (
int phaseIdx = 0; phaseIdx <
numPhases; ++phaseIdx)
84 BaseFluidState::setSaturation(phaseIdx, 1.0 /
numPhases);
85 BaseFluidState::setPressure(phaseIdx, 1e5);
86 BaseFluidState::setDensity(phaseIdx, 1.0);
87 BaseFluidState::setMolarDensity(phaseIdx, 1.0);
90 BaseFluidState::setMoleFraction(phaseIdx, compIdx, 1.0 /
numComponents);
105 allowTemperature_ = yesno;
110 allowPressure_ = yesno;
115 allowComposition_ = yesno;
120 allowDensity_ = yesno;
125 restrictPhaseIdx_ = phaseIdx;
130 assert(allowTemperature_);
131 assert(restrictPhaseIdx_ < 0 || restrictPhaseIdx_ == phaseIdx);
137 assert(allowComposition_);
138 return BaseFluidState::wettingPhase();
143 assert(allowComposition_);
144 assert(restrictPhaseIdx_ < 0 || restrictPhaseIdx_ == phaseIdx);
145 return BaseFluidState::partialPressure(phaseIdx, compIdx);
152 std::cout <<
"HairSplittingFluidState: pressure called but not allowed" << std::endl;
154 assert(restrictPhaseIdx_ < 0 || restrictPhaseIdx_ == phaseIdx);
160 assert(allowComposition_);
161 assert(restrictPhaseIdx_ < 0 || restrictPhaseIdx_ == phaseIdx);
167 assert(allowComposition_);
168 assert(restrictPhaseIdx_ < 0 || restrictPhaseIdx_ == phaseIdx);
174 assert(allowComposition_);
175 assert(restrictPhaseIdx_ < 0 || restrictPhaseIdx_ == phaseIdx);
176 return BaseFluidState::averageMolarMass(phaseIdx);
181 assert(allowDensity_ && allowComposition_);
182 assert(restrictPhaseIdx_ < 0 || restrictPhaseIdx_ == phaseIdx);
183 return BaseFluidState::molarity(phaseIdx, compIdx);
188 assert(allowDensity_);
189 assert(restrictPhaseIdx_ < 0 || restrictPhaseIdx_ == phaseIdx);
195 assert(allowDensity_);
196 assert(restrictPhaseIdx_ < 0 || restrictPhaseIdx_ == phaseIdx);
197 return BaseFluidState::molarVolume(phaseIdx);
202 assert(allowDensity_);
203 assert(restrictPhaseIdx_ < 0 || restrictPhaseIdx_ == phaseIdx);
216 return BaseFluidState::fugacity(phaseIdx, compIdx);
222 return BaseFluidState::fugacityCoefficient(phaseIdx, compIdx);
228 return BaseFluidState::enthalpy(phaseIdx);
234 return BaseFluidState::internalEnergy(phaseIdx);
244 bool allowSaturation_;
245 bool allowTemperature_;
247 bool allowComposition_;
249 int restrictPhaseIdx_;
252template<
class Scalar,
class BaseFlu
idState>
255 std::cout <<
"Testing fluid state '" << Dune::className<BaseFluidState>() <<
"'\n";
258 BaseFluidState tmpFs(fs);
262 std::string collectedErrors;
263 std::string collectedWarnings;
266 Scalar DUNE_UNUSED val;
270 val = fs.temperature(0);
273 collectedErrors +=
"error: fluidState.temperature() throws exception!\n";
277 val = fs.pressure(0);
280 collectedErrors +=
"error: fluidState.pressure() throws exception!\n";
284 val = fs.moleFraction(0, 0);
287 collectedErrors +=
"error: fluidState.moleFraction() throws exception!\n";
291 val = fs.massFraction(0, 0);
294 collectedErrors +=
"error: fluidState.massFraction() throws exception!\n";
298 val = fs.averageMolarMass(0);
301 collectedErrors +=
"error: fluidState.averageMolarMass() throws exception!\n";
305 val = fs.molarity(0, 0);
308 collectedErrors +=
"error: fluidState.molarity() throws exception!\n";
312 val = fs.molarDensity(0);
315 collectedErrors +=
"error: fluidState.molarDensity() throws exception!\n";
319 val = fs.molarVolume(0);
322 collectedErrors +=
"error: fluidState.molarVolume() throws exception!\n";
329 collectedErrors +=
"error: fluidState.density() throws exception!\n";
333 val = fs.saturation(0);
336 collectedErrors +=
"error: fluidState.saturation() throws exception!\n";
340 val = fs.fugacity(0, 0);
343 collectedErrors +=
"error: fluidState.fugacity() throws exception!\n";
347 val = fs.fugacityCoefficient(0, 0);
350 collectedErrors +=
"error: fluidState.fugacityCoefficient() throws exception!\n";
354 val = fs.enthalpy(0);
355 }
catch (Dune::NotImplemented&)
357 collectedWarnings +=
"warning: fluidState.enthalpy() is not implemented\n";
360 collectedErrors +=
"error: fluidState.enthalpy() throws exception!\n";
364 val = fs.internalEnergy(0);
365 }
catch (Dune::NotImplemented&)
367 collectedWarnings +=
"warning: fluidState.internalEnergy() is not implemented\n";
370 collectedErrors +=
"error: fluidState.internalEnergy() throws exception!\n";
374 val = fs.viscosity(0);
377 collectedErrors +=
"error: fluidState.viscosity() throws exception!\n";
380 std::cout << collectedErrors;
382 if (collectedErrors.empty())
384 std::cout <<
"... successfull" << std::endl;
385 std::cout <<
"----------------------------------" << std::endl;
390 std::cout <<
"... failed" << std::endl;
391 std::cout <<
"----------------------------------" << std::endl;
405template<
class Scalar,
class Flu
idSystem>
409 std::cout <<
"Testing fluid system '" << Dune::className<FluidSystem>() <<
"'\n";
413 std::string collectedErrors;
414 std::string collectedWarnings;
420 numPhases = FluidSystem::numPhases
424 numComponents = FluidSystem::numComponents
434 using PC =
typename FluidSystem::ParameterCache;
438 paramCache.updateAll(fs);
441 collectedErrors +=
"error: paramCache.updateAll() throws exception!\n";
445 paramCache.updateAll(fs, PC::None);
448 collectedErrors +=
"error: paramCache.updateAll(none) throws exception!\n";
452 paramCache.updateAll(fs, PC::Temperature | PC::Pressure | PC::Composition);
455 collectedErrors +=
"error: paramCache.updateAll(T, p, x) throws exception!\n";
459 paramCache.updateAllPressures(fs);
462 collectedErrors +=
"error: paramCache.updateAllPressures() throws exception!\n";
465 for (
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
467 if (enablePhaseRestriction)
471 paramCache.updatePhase(fs, phaseIdx);
474 collectedErrors +=
"error: paramCache.updatePhase() throws exception!\n";
478 paramCache.updatePhase(fs, phaseIdx, PC::None);
481 collectedErrors +=
"error: paramCache.updatePhase(none) throws exception!\n";
485 paramCache.updatePhase(fs, phaseIdx, PC::Temperature | PC::Pressure | PC::Composition);
488 collectedErrors +=
"error: paramCache.updatePhase(T, p , x) throws exception!\n";
492 paramCache.updateTemperature(fs, phaseIdx);
495 collectedErrors +=
"error: paramCache.updateTemperature() throws exception!\n";
499 paramCache.updatePressure(fs, phaseIdx);
502 collectedErrors +=
"error: paramCache.updatePressure() throws exception!\n";
506 paramCache.updateComposition(fs, phaseIdx);
509 collectedErrors +=
"error: paramCache.updateComposition() throws exception!\n";
513 paramCache.updateSingleMoleFraction(fs, phaseIdx, 0);
516 collectedErrors +=
"error: paramCache.updateSingleMoleFraction() throws exception!\n";
522 Scalar DUNE_UNUSED val;
525 for (
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
530 if (enablePhaseRestriction)
535 }
catch (
const std::exception& e)
537 collectedErrors +=
"error: FluidSystem::density() throws exception: " + std::string(e.what()) +
"\n";
542 }
catch (
const std::exception& e)
544 collectedErrors +=
"error: FluidSystem::molarDensity() throws exception: " + std::string(e.what()) +
"\n";
551 }
catch (
const std::exception& e)
553 collectedErrors +=
"error: FluidSystem::viscosity() throws exception: " + std::string(e.what()) +
"\n";
557 val = FluidSystem::enthalpy(fs, paramCache, phaseIdx);
558 }
catch (Dune::NotImplemented&)
560 collectedWarnings +=
"warning: FluidSystem::enthalpy() is not implemented\n";
561 }
catch (
const std::exception& e)
563 collectedErrors +=
"error: FluidSystem::enthalpy() throws exception: " + std::string(e.what()) +
"\n";
567 val = FluidSystem::heatCapacity(fs, paramCache, phaseIdx);
568 }
catch (Dune::NotImplemented&)
570 collectedWarnings +=
"warning: FluidSystem::heatCapacity() is not implemented\n";
571 }
catch (
const std::exception& e)
573 collectedErrors +=
"error: FluidSystem::heatCapacity() throws exception: " + std::string(e.what()) +
"\n";
577 val = FluidSystem::thermalConductivity(fs, paramCache, phaseIdx);
578 }
catch (Dune::NotImplemented&)
580 collectedWarnings +=
"warning: FluidSystem::thermalConductivity() is not implemented\n";
581 }
catch (
const std::exception& e)
583 collectedErrors +=
"error: FluidSystem::thermalConductivity() throws exception: " + std::string(e.what()) +
"\n";
586 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
591 val = FluidSystem::fugacityCoefficient(fs, paramCache, phaseIdx, compIdx);
592 }
catch (Dune::NotImplemented&)
594 collectedWarnings +=
"warning: FluidSystem::fugacityCoefficient() is not implemented\n";
595 }
catch (
const std::exception& e)
597 collectedErrors +=
"error: FluidSystem::fugacityCoefficient() throws exception: " + std::string(e.what()) +
"\n";
602 val = FluidSystem::diffusionCoefficient(fs, paramCache, phaseIdx, compIdx);
603 }
catch (Dune::NotImplemented&)
605 collectedWarnings +=
"warning: FluidSystem::diffusionCoefficient() is not implemented\n";
606 }
catch (Dune::InvalidStateException&)
608 collectedWarnings +=
"warning: FluidSystem::diffusionCoefficient() gives invalid state exception\n";
609 }
catch (
const std::exception& e)
611 collectedErrors +=
"error: FluidSystem::diffusionCoefficient() throws exception: " + std::string(e.what()) +
"\n";
613 for (
int comp2Idx = 0; comp2Idx < numComponents; ++comp2Idx)
617 val = FluidSystem::binaryDiffusionCoefficient(fs, paramCache, phaseIdx, compIdx, comp2Idx);
618 }
catch (Dune::NotImplemented&)
620 collectedWarnings +=
"warning: FluidSystem::binaryDiffusionCoefficient() is not implemented\n";
621 }
catch (Dune::InvalidStateException&)
623 collectedWarnings +=
"warning: FluidSystem::binaryDiffusionCoefficient() gives invalid state exception\n";
624 }
catch (
const std::exception& e)
626 collectedErrors +=
"error: FluidSystem::binaryDiffusionCoefficient() throws exception: " + std::string(e.what()) +
"\n";
633 for (
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
636 DUNE_UNUSED name = FluidSystem::phaseName(phaseIdx);
638 bVal = FluidSystem::isGas(phaseIdx);
639 bVal = FluidSystem::isIdealGas(phaseIdx);
643 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
645 val = FluidSystem::molarMass(compIdx);
647 DUNE_UNUSED name = FluidSystem::componentName(compIdx);
650 std::cout << collectedErrors;
652 if (collectedErrors.empty())
654 std::cout <<
"... successful" << std::endl;
655 std::cout <<
"----------------------------------" << std::endl;
660 std::cout <<
"... failed" << std::endl;
661 std::cout <<
"----------------------------------" << std::endl;
664 std::cout <<
"----------------------------------\n";
Represents all relevant thermodynamic quantities of a multi-phase, multi-component fluid system assum...
Represents all relevant thermodynamic quantities of a multi-phase fluid system assuming immiscibility...
Represents all relevant thermodynamic quantities of a isothermal immiscible multi-phase fluid system.
Represents all relevant thermodynamic quantities of a multi-phase, multi-component fluid system witho...
Represents all relevant thermodynamic quantities of a multi-phase, multi-component fluid system witho...
This is a fluid state which allows to set the fluid pressures and takes all other quantities from an ...
Calculates phase state for a single phase but two-component state.
This is a fluid state which allows to set the fluid saturations and takes all other quantities from a...
This is a fluid state which allows to set the fluid temperatures and takes all other quantities from ...
A gaseous phase consisting of a single component.
A liquid phase consisting of a single component.
A fluid system for two-phase models assuming immiscibility and thermodynamic equilibrium.
A compositional two-phase fluid system with a liquid and a gaseous phase and , and (dissolved miner...
A compositional fluid with brine (H2O & NaCl) and carbon dioxide as components in both the liquid and...
A compositional two-phase fluid system with water and air as components in both, the liquid and the g...
A three-phase fluid system featuring gas, NAPL and water as phases and distilled water and air (Pseu...
A three-phase fluid system featuring gas, NAPL and water as phases and distilled water and air (Pseu...
A two-phase (water and air) fluid system with water, nitrogen and oxygen as components.
The fluid system for the SPE-5 benchmark problem.
bool success
Definition: test_tabulation.cc:34
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
int checkFluidSystem(bool enablePhaseRestriction=true)
This is a consistency check for FluidSystems.
Definition: checkfluidsystem.hh:406
int checkFluidState(const BaseFluidState &fs)
Definition: checkfluidsystem.hh:253
std::string temperature() noexcept
I/O name of temperature for equilibrium models.
Definition: name.hh:51
std::string saturation(int phaseIdx) noexcept
I/O name of saturation for multiphase systems.
Definition: name.hh:43
std::string moleFraction(int phaseIdx, int compIdx) noexcept
I/O name of mole fraction.
Definition: name.hh:110
std::string viscosity(int phaseIdx) noexcept
I/O name of viscosity for multiphase systems.
Definition: name.hh:74
std::string molarDensity(int phaseIdx) noexcept
I/O name of molar density for multiphase systems.
Definition: name.hh:83
std::string pressure(int phaseIdx) noexcept
I/O name of pressure for multiphase systems.
Definition: name.hh:34
std::string density(int phaseIdx) noexcept
I/O name of density for multiphase systems.
Definition: name.hh:65
std::string massFraction(int phaseIdx, int compIdx) noexcept
I/O name of mass fraction.
Definition: name.hh:115
ScalarType Scalar
export the scalar type
Definition: compositional.hh:53
This fluid state ensures that only the allowed quantities are accessed.
Definition: checkfluidsystem.hh:70
void restrictToPhase(int phaseIdx)
Definition: checkfluidsystem.hh:123
static constexpr int numPhases
Definition: checkfluidsystem.hh:75
void allowTemperature(bool yesno)
Definition: checkfluidsystem.hh:103
Scalar density(int phaseIdx) const
Definition: checkfluidsystem.hh:200
Scalar fugacity(int phaseIdx, int compIdx) const
Definition: checkfluidsystem.hh:213
Scalar temperature(int phaseIdx) const
Definition: checkfluidsystem.hh:128
Scalar molarVolume(int phaseIdx) const
Definition: checkfluidsystem.hh:193
static constexpr int numComponents
Definition: checkfluidsystem.hh:76
Scalar viscosity(int phaseIdx) const
Definition: checkfluidsystem.hh:237
void allowComposition(bool yesno)
Definition: checkfluidsystem.hh:113
void allowPressure(bool yesno)
Definition: checkfluidsystem.hh:108
HairSplittingFluidState()
Definition: checkfluidsystem.hh:78
void allowDensity(bool yesno)
Definition: checkfluidsystem.hh:118
Scalar fugacityCoefficient(int phaseIdx, int compIdx) const
Definition: checkfluidsystem.hh:219
Scalar moleFraction(int phaseIdx, int compIdx) const
Definition: checkfluidsystem.hh:158
Scalar molarDensity(int phaseIdx) const
Definition: checkfluidsystem.hh:186
Scalar partialPressure(int phaseIdx, int compIdx) const
Definition: checkfluidsystem.hh:141
Scalar pressure(int phaseIdx) const
Definition: checkfluidsystem.hh:148
Scalar enthalpy(int phaseIdx) const
Definition: checkfluidsystem.hh:225
Scalar saturation(int phaseIdx) const
Definition: checkfluidsystem.hh:207
Scalar wettingPhase() const
Definition: checkfluidsystem.hh:135
Scalar internalEnergy(int phaseIdx) const
Definition: checkfluidsystem.hh:231
Scalar averageMolarMass(int phaseIdx) const
Definition: checkfluidsystem.hh:172
Scalar massFraction(int phaseIdx, int compIdx) const
Definition: checkfluidsystem.hh:165
Scalar molarity(int phaseIdx, int compIdx) const
Definition: checkfluidsystem.hh:179