OGS
TwoPhaseFlowWithPPLocalAssembler-impl.h
Go to the documentation of this file.
1
31#pragma once
32
38
39namespace ProcessLib
40{
41namespace TwoPhaseFlowWithPP
42{
43namespace MPL = MaterialPropertyLib;
44
45template <typename ShapeFunction, int GlobalDim>
47 double const t, double const dt, std::vector<double> const& local_x,
48 std::vector<double> const& /*local_x_prev*/,
49 std::vector<double>& local_M_data, std::vector<double>& local_K_data,
50 std::vector<double>& local_b_data)
51{
52 auto const local_matrix_size = local_x.size();
53
54 assert(local_matrix_size == ShapeFunction::NPOINTS * NUM_NODAL_DOF);
55
57 local_M_data, local_matrix_size, local_matrix_size);
59 local_K_data, local_matrix_size, local_matrix_size);
61 local_b_data, local_matrix_size);
62
63 auto Mgp =
64 local_M.template block<nonwet_pressure_size, nonwet_pressure_size>(
65 nonwet_pressure_matrix_index, nonwet_pressure_matrix_index);
66 auto Mgpc = local_M.template block<nonwet_pressure_size, cap_pressure_size>(
67 nonwet_pressure_matrix_index, cap_pressure_matrix_index);
68
69 auto Mlpc = local_M.template block<cap_pressure_size, cap_pressure_size>(
70 cap_pressure_matrix_index, cap_pressure_matrix_index);
71
72 NodalMatrixType laplace_operator =
73 NodalMatrixType::Zero(ShapeFunction::NPOINTS, ShapeFunction::NPOINTS);
74
75 auto Kgp =
76 local_K.template block<nonwet_pressure_size, nonwet_pressure_size>(
77 nonwet_pressure_matrix_index, nonwet_pressure_matrix_index);
78
79 auto Klp = local_K.template block<cap_pressure_size, nonwet_pressure_size>(
80 cap_pressure_matrix_index, nonwet_pressure_matrix_index);
81
82 auto Klpc = local_K.template block<cap_pressure_size, cap_pressure_size>(
83 cap_pressure_matrix_index, cap_pressure_matrix_index);
84
85 auto Bg = local_b.template segment<nonwet_pressure_size>(
86 nonwet_pressure_matrix_index);
87
88 auto Bl =
89 local_b.template segment<cap_pressure_size>(cap_pressure_matrix_index);
90
91 auto const& medium = *_process_data.media_map.getMedium(_element.getID());
92 auto const& liquid_phase = medium.phase("AqueousLiquid");
93 auto const& gas_phase = medium.phase("Gas");
94
95 unsigned const n_integration_points =
96 _integration_method.getNumberOfPoints();
97
99 pos.setElementID(_element.getID());
100
101 for (unsigned ip = 0; ip < n_integration_points; ip++)
102 {
103 pos.setIntegrationPoint(ip);
104 auto const& w = _ip_data[ip].integration_weight;
105 auto const& dNdx = _ip_data[ip].dNdx;
106 auto const& M = _ip_data[ip].massOperator;
107
108 double pc_int_pt = 0.;
109 double pn_int_pt = 0.;
110 NumLib::shapeFunctionInterpolate(local_x, _ip_data[ip].N, pn_int_pt,
111 pc_int_pt);
112
113 _pressure_wet[ip] = pn_int_pt - pc_int_pt;
114 MPL::VariableArray variables;
115
116 variables.gas_phase_pressure = pn_int_pt;
117 variables.capillary_pressure = pc_int_pt;
118 variables.temperature = _process_data.temperature(t, pos)[0];
119 variables.molar_mass =
120 gas_phase.property(MPL::PropertyType::molar_mass)
121 .template value<double>(variables, pos, t, dt);
122
123 auto const rho_nonwet =
124 gas_phase.property(MPL::PropertyType::density)
125 .template value<double>(variables, pos, t, dt);
126
127 auto const rho_wet = liquid_phase.property(MPL::PropertyType::density)
128 .template value<double>(variables, pos, t, dt);
129 auto& Sw = _saturation[ip];
130 Sw = medium.property(MPL::PropertyType::saturation)
131 .template value<double>(variables, pos, t, dt);
132
133 auto const dSw_dpc =
134 medium.property(MPL::PropertyType::saturation)
135 .template dValue<double>(
136 variables, MPL::Variable::capillary_pressure, pos, t, dt);
137
138 auto const porosity =
139 medium.property(MPL::PropertyType::porosity)
140 .template value<double>(variables, pos, t, dt);
141
142 auto const drhononwet_dpn =
143 gas_phase.property(MPL::PropertyType::density)
144 .template dValue<double>(
145 variables, MPL::Variable::gas_phase_pressure, pos, t, dt);
146
147 auto const k_rel_wet =
148 medium.property(MPL::PropertyType::relative_permeability)
149 .template value<double>(variables, pos, t, dt);
150 auto const k_rel_nonwet =
151 medium
152 .property(
153 MPL::PropertyType::relative_permeability_nonwetting_phase)
154 .template value<double>(variables, pos, t, dt);
155
156 auto const mu_nonwet =
157 gas_phase.property(MPL::PropertyType::viscosity)
158 .template value<double>(variables, pos, t, dt);
159
160 auto const lambda_nonwet = k_rel_nonwet / mu_nonwet;
161
162 auto const mu_wet = liquid_phase.property(MPL::PropertyType::viscosity)
163 .template value<double>(variables, pos, t, dt);
164
165 auto const lambda_wet = k_rel_wet / mu_wet;
166
167 auto const K = MPL::formEigenTensor<GlobalDim>(
168 medium.property(MPL::PropertyType::permeability)
169 .template value<double>(variables, pos, t, dt));
170
171 Mgp.noalias() += porosity * (1 - Sw) * drhononwet_dpn * M;
172 Mgpc.noalias() += -porosity * rho_nonwet * dSw_dpc * M;
173 Mlpc.noalias() += porosity * dSw_dpc * rho_wet * M;
174
175 laplace_operator.noalias() = dNdx.transpose() * K * dNdx * w;
176
177 Kgp.noalias() += rho_nonwet * lambda_nonwet * laplace_operator;
178 Klp.noalias() += rho_wet * lambda_wet * laplace_operator;
179 Klpc.noalias() += -rho_wet * lambda_wet * laplace_operator;
180
181 if (_process_data.has_gravity)
182 {
183 auto const& b = _process_data.specific_body_force;
184
185 NodalVectorType gravity_operator = dNdx.transpose() * K * b * w;
186 Bg.noalias() +=
187 rho_nonwet * rho_nonwet * lambda_nonwet * gravity_operator;
188 Bl.noalias() += rho_wet * rho_wet * lambda_wet * gravity_operator;
189 } // end of has gravity
190 }
191 if (_process_data.has_mass_lumping)
192 {
193 for (unsigned row = 0; row < Mgpc.cols(); row++)
194 {
195 for (unsigned column = 0; column < Mgpc.cols(); column++)
196 {
197 if (row != column)
198 {
199 Mgpc(row, row) += Mgpc(row, column);
200 Mgpc(row, column) = 0.0;
201 Mgp(row, row) += Mgp(row, column);
202 Mgp(row, column) = 0.0;
203 Mlpc(row, row) += Mlpc(row, column);
204 Mlpc(row, column) = 0.0;
205 }
206 }
207 }
208 } // end of mass-lumping
209}
210
211} // namespace TwoPhaseFlowWithPP
212} // namespace ProcessLib
Definition of the PiecewiseLinearInterpolation class.
void setElementID(std::size_t element_id)
void setIntegrationPoint(unsigned integration_point)
void assemble(double const t, double const dt, std::vector< double > const &local_x, std::vector< double > const &local_x_prev, std::vector< double > &local_M_data, std::vector< double > &local_K_data, std::vector< double > &local_b_data) override
Eigen::Matrix< double, GlobalDim, GlobalDim > formEigenTensor(MaterialPropertyLib::PropertyDataType const &values)
Eigen::Map< Vector > createZeroedVector(std::vector< double > &data, Eigen::VectorXd::Index size)
Eigen::Map< Matrix > createZeroedMatrix(std::vector< double > &data, Eigen::MatrixXd::Index rows, Eigen::MatrixXd::Index cols)
void shapeFunctionInterpolate(const NodalValues &, const ShapeMatrix &)