celldatamultiphysics.hh 10.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*****************************************************************************
 *   See the file COPYING for full copying permissions.                      *
 *                                                                           *
 *   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 2 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/>.   *
 *****************************************************************************/
#ifndef DUMUX_ELEMENTDATA2P2C_MULTYPHYSICS_HH
#define DUMUX_ELEMENTDATA2P2C_MULTYPHYSICS_HH

#include "properties.hh"
#include "celldata.hh"

/**
 * @file
 * @brief  Storage container for discretized data for multiphysics models
 */

namespace Dumux
{
/*!
 * \ingroup multiphysics multiphase
 */
//! Storage container for discretized data for multiphysics models
/*! For multiphysics models, we divide the model in seperate sub-domains. Being a cell-based
 * information, this is also stored in the cellData. In addition, a simpler version of a
 * fluidState can be stored in cells being in the simpler subdomain.
 * Hence, acess functions either direct to the full fluidstate, or to the simple fluidstate.
 *
 * @tparam TypeTag The Type Tag
 */
template<class TypeTag>
class CellData2P2CMultiPhysics : public CellData2P2C<TypeTag>
{
private:
    typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
    typedef typename GET_PROP_TYPE(TypeTag, FluidState) FluidState;
    typedef PseudoOnePTwoCFluidState<TypeTag> SimpleFluidState;

    typedef typename GET_PROP_TYPE(TypeTag, Indices) Indices;

    enum
    {
        wPhaseIdx = Indices::wPhaseIdx, nPhaseIdx = Indices::nPhaseIdx
    };
    enum
    {
        complex = 0, simple = 1
    };
private:
    int subdomain_;
    int fluidStateType_;
    std::shared_ptr<SimpleFluidState> simpleFluidState_;

//    FluxData fluxData_;
public:

    //! Constructor for a local storage object
    CellData2P2CMultiPhysics() : CellData2P2C<TypeTag>(),
        subdomain_(2), fluidStateType_(complex)
    {
    }

    /*! \name Acess to primary variables */
    //@{
    //! \copydoc Dumux::TwoPTwoCFluidState::pressure()
    Scalar pressure(int phaseIdx)
    {
        if(fluidStateType_ == simple)
        {
            return simpleFluidState_->pressure(phaseIdx);
        }
        else
            return this->fluidState_->pressure(phaseIdx);
    }
    //! \copydoc Dumux::TwoPTwoCFluidState::pressure()
    const Scalar pressure(int phaseIdx) const
    {
        if(fluidStateType_ == simple)
        {
            return simpleFluidState_->pressure(phaseIdx);
        }
        else
            return this->fluidState_->pressure(phaseIdx);
    }
    //! \copydoc Dumux::CellData2P2C::setPressure()
    void setPressure(int phaseIdx, Scalar value)
    {
        if(fluidStateType_ == simple)
            manipulateSimpleFluidState().setPressure(phaseIdx, value);
        else
            manipulateFluidState().setPressure(phaseIdx, value);
    }
    //@}


    //////////////////////////////////////////////////////////////
    // functions returning the vectors of secondary variables
    //////////////////////////////////////////////////////////////

    //! Return subdomain information
    /** Acess function to store subdomain information
     */
    int& subdomain()
    {
        return subdomain_;
    }
    //! Return subdomain information
    /** Acess function to get subdomain information
     */
    const int& subdomain() const
    {
        return subdomain_;
    }
    //! Specify subdomain information and fluidStateType
    /** This function is only called if
     */
    void setSubdomainAndFluidStateType(int index)
    {
        subdomain_ = index;
        if(index == 2)
            fluidStateType_ = complex;
        else
            fluidStateType_ = simple;
    }

    /*! \name Acess to secondary variables */
    //@{
    //! \copydoc Dumux::TwoPTwoCFluidState::setSaturation()
    void setSaturation(int phaseIdx, Scalar value)
    {
        if(fluidStateType_ == simple)
        {
            // saturation is triggered by presentPhaseIdx
            manipulateSimpleFluidState().setPresentPhaseIdx((value==0.) ? nPhaseIdx : wPhaseIdx);
        }
        else
            manipulateFluidState().setSaturation(phaseIdx, value);
    }
    //! \copydoc Dumux::TwoPTwoCFluidState::saturation()
    const Scalar saturation(int phaseIdx) const
    {
        if(fluidStateType_ == simple)
        {
            return simpleFluidState_->saturation(phaseIdx);
        }
        else
            return this->fluidState_->saturation(phaseIdx);
    }

    //! \copydoc Dumux::TwoPTwoCFluidState::setViscosity()
    void setViscosity(int phaseIdx, Scalar value)
    {
        if(fluidStateType_ == simple)
        {
            assert(phaseIdx == simpleFluidState_->presentPhaseIdx());
            manipulateSimpleFluidState().setViscosity(phaseIdx, value);
        }
        else
            manipulateFluidState().setViscosity(phaseIdx, value);
    }
    //! \copydoc Dumux::TwoPTwoCFluidState::viscosity()
    const Scalar viscosity(int phaseIdx) const
    {
        if(fluidStateType_ == simple)
        {
            if(phaseIdx != simpleFluidState_->presentPhaseIdx())
                return 0.; // This should only happend for output
            return simpleFluidState_->viscosity(phaseIdx);
        }
        else
            return this->fluidState_->viscosity(phaseIdx);
    }


    //! \copydoc Dumux::TwoPTwoCFluidState::capillaryPressure()
    const Scalar capillaryPressure() const
    {
        if(fluidStateType_ == simple)
            return simpleFluidState_->pressure(nPhaseIdx) - simpleFluidState_->pressure(wPhaseIdx);
        else
            return this->fluidState_->pressure(nPhaseIdx) - this->fluidState_->pressure(wPhaseIdx);
    }

    //! \copydoc Dumux::TwoPTwoCFluidState::density()
    const Scalar density(int phaseIdx) const
    {
        if(fluidStateType_ == simple)
        {
            return simpleFluidState_->density(phaseIdx);
        }
        else
            return this->fluidState_->density(phaseIdx);
    }

    //! \copydoc Dumux::TwoPTwoCFluidState::massFraction()
    const Scalar massFraction(int phaseIdx, int compIdx) const
    {
        if(fluidStateType_ == simple)
        {
            return simpleFluidState_->massFraction(phaseIdx, compIdx);
        }
        else
            return this->fluidState_->massFraction(phaseIdx, compIdx);
    }

    //! \copydoc Dumux::TwoPTwoCFluidState::moleFraction()
    const Scalar moleFraction(int phaseIdx, int compIdx) const
    {
        if(fluidStateType_ == simple)
        {
            return simpleFluidState_->moleFraction(phaseIdx, compIdx);
        }
        else
            return this->fluidState_->moleFraction(phaseIdx, compIdx);
    }
    //! \copydoc Dumux::TwoPTwoCFluidState::temperature()
    const Scalar temperature(int phaseIdx) const
    {
        if(fluidStateType_ == simple)
        {
            return simpleFluidState_->temperature(phaseIdx);
        }
        else
            return this->fluidState_->temperature(phaseIdx);
    }

    //! \copydoc Dumux::TwoPTwoCFluidState::phaseMassFraction()
    const Scalar phaseMassFraction(int phaseIdx) const
    {
        if(fluidStateType_ == simple)
        {
            if(phaseIdx == simpleFluidState_->presentPhaseIdx())
                return 1.; // phase is present => nu = 1
            else
                return 0.;
        }
        else
            return this->fluidState_->phaseMassFraction(phaseIdx);
    }

    //! Returns a reference to the cells simple fluid state
    const SimpleFluidState& simpleFluidState() const
    {
        assert(simpleFluidState_);
        return *simpleFluidState_;
    }

    //@}

    //! Set a simple fluidstate for a cell in the simple domain
    /** Uses a simplified fluidstate with less storage capacity
     * and functionality.
     * Makes shure the fluidStateType_ flag is set appropriately in this
     * cell.
     * @param simpleFluidState A fluidstate storing a 1p2c mixture
     */
    void setSimpleFluidState(SimpleFluidState& simpleFluidState)
    {
        assert (this->subdomain() != 2);
        fluidStateType_ = simple;
        simpleFluidState_ = &simpleFluidState;
    }
    //! Manipulates a simple fluidstate for a cell in the simple domain
    SimpleFluidState& manipulateSimpleFluidState()
    {
        fluidStateType_ = simple;
        if(this->fluidState_)
        {
            this->fluidState_.template reset<FluidState>(0);
        }

        if(!simpleFluidState_)
            simpleFluidState_ = std::make_shared<SimpleFluidState>();
        return *simpleFluidState_;
    }
    //! Allows manipulation of the complex fluid state
    /** Fluidstate is stored as a pointer, initialized as a null-pointer.
     * Enshure that if no FluidState is present, a new one is created.
     * Also enshure that we are in the complex subdomain.
     */
    FluidState& manipulateFluidState()
    {
        fluidStateType_ = complex;
        if(simpleFluidState_)
        {
            simpleFluidState_.template reset<SimpleFluidState>(0);
        }

        if(!this->fluidState_)
        {
            this->fluidState_ = std::make_shared<FluidState>();
            // properly initialize pressure, since it is evaluated later:
            this->fluidState_->setPressure(wPhaseIdx, 1e5);
            this->fluidState_->setPressure(nPhaseIdx, 1e5);
        }

        return *this->fluidState_;
    }

    //! Returns the type of the fluidState
    const bool fluidStateType() const
    { return fluidStateType_;}

};

}
#endif