ImplicitStepFluidVariationalFormulationInit.cpp 19.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
//! \file
//
//
//  ImplicitStepFluidVariationalFormulation.cpp
//  HappyHeart
//
//  Created by Sebastien Gilles on 24/03/16.
//  Copyright © 2016 Inria. All rights reserved.
//

11 12
#include "FiniteElement/FiniteElementSpace/GodOfDofManager.hpp"

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
#include "ModelInstances/UnderDevelopment/Poromechanics/ImplicitStepFluidVariationalFormulation.hpp"


namespace HappyHeart
{
    
    
    namespace PoromechanicsNS
    {
        
        
        namespace ImplicitStepFluidNS
        {
            
            
            VariationalFormulation
            ::VariationalFormulation(const Wrappers::Mpi& mpi,
                                     const TimeManager& time_manager,
                                     const GodOfDof& god_of_dof,
                                     const ScalarParameter<>& fluid_density,
                                     const ParameterAtDof<ParameterNS::Type::scalar, ParameterNS::TimeDependencyNS::None, 2u>::type& porosity,
                                     const Parameter<ParameterNS::Type::vector, ParameterNS::TimeDependencyNS::None>& inlet_pressure,
                                     DirichletBoundaryCondition::vector_shared_ptr&& boundary_condition_list)
            : parent(mpi,
                     time_manager,
                     god_of_dof,
                     std::move(boundary_condition_list)),
            porosity_parent(porosity),
            fluid_density_(fluid_density),
            inlet_pressure_(inlet_pressure)
            { }
            
            
                     
            void VariationalFormulation::AllocateMatricesAndVectors()
            {
                decltype(auto) god_of_dof = parent::GetGodOfDof();
                
                decltype(auto) numbering_subset =
                god_of_dof.GetNumberingSubset(EnumUnderlyingType(NumberingSubsetIndex::fluid_mass_velocity_pressure));

                
                parent::AllocateSystemMatrix(numbering_subset, numbering_subset);
                parent::AllocateSystemVector(numbering_subset);
                
                decltype(auto) system_matrix = parent::GetSystemMatrix(numbering_subset, numbering_subset);
                mass_matrix_ = std::make_unique<GlobalMatrix>(system_matrix);
                
61 62 63 64 65
                // \todo #888 - #820 Ideally it should be something like that but as long as MatMatMatMultNumeric doesn't
                //work I have to not allocate at all the matrix.
                //work_matrix_system_like_ = std::make_unique<GlobalMatrix>(system_matrix);
                work_matrix_system_like_ = std::make_unique<GlobalMatrix>(numbering_subset, numbering_subset);
                
66 67 68 69 70 71 72 73 74 75
                work_fluid_mass_ =
                    std::make_unique<GlobalVector>(god_of_dof.GetNumberingSubset(EnumUnderlyingType(NumberingSubsetIndex::fluid_mass)));
                
                AllocateGlobalVector(god_of_dof, GetNonCstWorkFluidMass());
                
                work_fluid_velocity_ =
                    std::make_unique<GlobalVector>(god_of_dof.GetNumberingSubset(EnumUnderlyingType(NumberingSubsetIndex::fluid_velocity)));
                
                AllocateGlobalVector(god_of_dof, GetNonCstWorkFluidVelocity());
                
76 77 78 79 80 81 82 83 84
                {
                    decltype(auto) god_of_dof_manager = GodOfDofManager::GetInstance();
                    
                    decltype(auto) solid_god_of_dof =
                        god_of_dof_manager.GetGodOfDof(EnumUnderlyingType(MeshIndex::solid));
                    
                    decltype(auto) fluid_mass_numbering_subset =
                        solid_god_of_dof.GetNumberingSubset(EnumUnderlyingType(NumberingSubsetIndex::fluid_mass_on_solid));
                    
85 86 87 88 89 90 91 92
                    fluid_mass_matrix_on_solid_mesh_ =
                        std::make_unique<GlobalMatrix>(fluid_mass_numbering_subset, fluid_mass_numbering_subset);
                    AllocateGlobalMatrix(solid_god_of_dof, GetNonCstFluidMassMatrixOnSolidMesh());
                    
                    // Do not allocate this one on purpose: it will be set by a result of MatMatMult operation.
                    fluid_mass_interpolation_matrix_ =
                        std::make_unique<GlobalMatrix>(numbering_subset, fluid_mass_numbering_subset);
                    
93 94 95
                    inverse_fluid_mass_interpolation_matrix_ =
                        std::make_unique<GlobalMatrix>(fluid_mass_numbering_subset, numbering_subset);
                    
96 97 98 99 100 101
                }
                
                {
                    decltype(auto) fluid_mass_numbering_subset =
                        god_of_dof.GetNumberingSubset(EnumUnderlyingType(NumberingSubsetIndex::fluid_mass));
                    
102 103 104
                    // The matrix is not yet allocated: it will be at the end of SupplInit() through a call
                    // to MatMatMultSymbolic.
                    // It can't be performed yet as the operators are not yet defined.
105
                    fluid_mass_matrix_on_fluid_mesh_ =
106
                        std::make_unique<GlobalMatrix>(fluid_mass_numbering_subset, fluid_mass_numbering_subset);
107 108
                    
                    
109 110
                    work_matrix_fluid_mass_matrix_on_fluid_mesh_ =
                        std::make_unique<GlobalMatrix>(fluid_mass_numbering_subset, fluid_mass_numbering_subset);
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
            }
            
            
            void VariationalFormulation::SupplInit(const InputParameterList& input_parameter_data)
            {
                static_cast<void>(input_parameter_data);
                
                {
                    // \todo #583: Temporary to make code work; quite stupid nonetheless!
                    const auto degree_of_exactness = DEFAULT_DEGREE_OF_EXACTNESS;
                    auto&& default_rule = DetermineDefaultQuadratureRule(degree_of_exactness);
                    this->GetNonCstQuadratureRulePerTopology().emplace_back(std::move(default_rule));
                    assert(this->GetNonCstQuadratureRulePerTopology().size() == 1ul);
                }
                
                decltype(auto) god_of_dof = parent::GetGodOfDof();
                
                decltype(auto) unknown_manager = UnknownManager::GetInstance();
                decltype(auto) fluid_velocity =
                    unknown_manager.GetUnknown(EnumUnderlyingType(UnknownIndex::fluid_velocity));
                
                const auto mesh_dimension = god_of_dof.GetGeometricMeshRegion().GetDimension();
                
                const auto& default_quadrature_rule_set = this->GetQuadratureRulePerTopologyType();
                
                 const auto& inlet_border_felt_space =
                    god_of_dof.GetFEltSpace(EnumUnderlyingType(FEltSpaceIndex::inlet_border));

                namespace GVO = GlobalVariationalOperatorNS;
                
                decltype(auto) porosity = GetPorosity();

                inlet_pressure_source_operator_ =
                    std::make_unique<GVO::TransientSource<>>(inlet_border_felt_space,
                                                             fluid_velocity,
                                                             mesh_dimension,
                                                             default_quadrature_rule_set,
                                                             porosity,
                                                             DoComputeProcessorWiseLocal2Global::yes,
                                                             GetInletPressure());
                
                const auto& fluid_felt_space =
                    god_of_dof.GetFEltSpace(EnumUnderlyingType(FEltSpaceIndex::fluid));

                
160
                mass_operator_fluid_velocity_
161 162 163 164 165 166 167 168 169 170 171 172
                    = std::make_unique<GVO::Mass>(fluid_felt_space,
                                                  fluid_velocity,
                                                  mesh_dimension,
                                                  default_quadrature_rule_set,
                                                  porosity,
                                                  DoComputeProcessorWiseLocal2Global::yes); // \todo #820 Check if no is ok.
                
                decltype(auto) monolithic_felt_space = god_of_dof.GetFEltSpace(EnumUnderlyingType(FEltSpaceIndex::fluid_monolithic));
                
                {
                    using type = GVO::ScalarDivVectorial;
                    
173 174
                    decltype(auto) fluid_mass =
                        unknown_manager.GetUnknown(EnumUnderlyingType(UnknownIndex::fluid_mass));
175 176

                    
177
                    mass_div_velocity_
178 179
                        = std::make_unique<type>(monolithic_felt_space,
                                                 fluid_velocity,
180
                                                 fluid_mass,
181
                                                 0.,
182
                                                 1.,
183 184 185 186
                                                 mesh_dimension,
                                                 default_quadrature_rule_set,
                                                 porosity,
                                                 DoComputeProcessorWiseLocal2Global::yes); // \todo #820 Check if no is ok.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
                    
                }
                
                {
                    using type = GVO::ScalarDivVectorial;
                
                    decltype(auto) fluid_pressure =
                        unknown_manager.GetUnknown(EnumUnderlyingType(UnknownIndex::fluid_pressure));
                    
                    
                    pressure_div_velocity_
                        = std::make_unique<type>(monolithic_felt_space,
                                                 fluid_velocity,
                                                 fluid_pressure,
                                                 1.,
                                                 0.,
                                                 mesh_dimension,
                                                 default_quadrature_rule_set,
                                                 porosity,
                                                 DoComputeProcessorWiseLocal2Global::yes); // \todo #820 Check if no is ok.

208 209
                }
                
210 211 212 213 214 215
                {
                    using type = NonConformInterpolatorNS::FromVertexMatching;
                    interp_mass_from_solid_mesh_ =
                        std::make_unique<type>(input_parameter_data,
                                               EnumUnderlyingType(InitVertexMatchingInterpolator::solid_mass),
                                               EnumUnderlyingType(InitVertexMatchingInterpolator::fluid_mass));
216 217 218 219 220 221 222
                    
                    inverse_interp_mass_from_solid_mesh_ =
                        std::make_unique<type>(input_parameter_data,
                                               EnumUnderlyingType(InitVertexMatchingInterpolator::fluid_mass),
                                               EnumUnderlyingType(InitVertexMatchingInterpolator::solid_mass));
                    
                    
223 224
                }
                
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
                {
                    decltype(auto) god_of_dof_manager = GodOfDofManager::GetInstance();
                    
                    decltype(auto) solid_god_of_dof =
                        god_of_dof_manager.GetGodOfDof(EnumUnderlyingType(MeshIndex::solid));
                    
                    decltype(auto) felt_space =
                        solid_god_of_dof.GetFEltSpace(EnumUnderlyingType(FEltSpaceIndex::solid));
                    
                    decltype(auto) fluid_mass =
                        unknown_manager.GetUnknown(EnumUnderlyingType(UnknownIndex::fluid_mass));
                    
                    mass_operator_fluid_mass_on_solid_mesh_ =
                        std::make_unique<::HappyHeart::GlobalVariationalOperatorNS::Mass>(felt_space,
                                                                                          fluid_mass,
                                                                                          mesh_dimension,
                                                                                          default_quadrature_rule_set,
                                                                                          DoComputeProcessorWiseLocal2Global::yes); // \todo #820 Check if no is ok.
                }
                
245 246 247 248
                
                {
                    using type = ConformInterpolatorNS::SubsetOrSuperset;
                    
249 250 251 252 253 254 255
                    expand_mass_ =
                        std::make_unique<type>(fluid_felt_space,
                                               god_of_dof.GetNumberingSubset(EnumUnderlyingType(NumberingSubsetIndex::fluid_mass)),
                                               monolithic_felt_space,
                                               god_of_dof.GetNumberingSubset(EnumUnderlyingType(NumberingSubsetIndex::fluid_mass_velocity_pressure)));
                    
                    expand_mass_->Init();
256 257 258 259 260 261 262 263 264
                    
                    
                    reduce_to_mass_ =
                        std::make_unique<type>(monolithic_felt_space,
                                               god_of_dof.GetNumberingSubset(EnumUnderlyingType(NumberingSubsetIndex::fluid_mass_velocity_pressure)),
                                               fluid_felt_space,
                                               god_of_dof.GetNumberingSubset(EnumUnderlyingType(NumberingSubsetIndex::fluid_mass)));
                    
                    reduce_to_mass_->Init();
265 266
                }
                
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
                
                {
//                    auto& interpolator = GetNonCstFluidMassInterpolationMatrix();
//                    
//                    Wrappers::Petsc::MatMatMult(GetExpandMass().GetInterpolationMatrix(),
//                                                GetInterpMassFromSolidMesh().GetInterpolationMatrix(),
//                                                interpolator,
//                                                __FILE__, __LINE__);
//                    
//                    
//                    auto& inverse_interpolator = GetNonCstInverseFluidMassInterpolationMatrix();
//                    
//                    Wrappers::Petsc::MatMatMult(GetInterpMassFromSolidMesh().GetInterpolationMatrix(),
//                                                GetReduceToMass().GetInterpolationMatrix(),
//                                                inverse_interpolator,
//                                                __FILE__, __LINE__);
//                    
                    
                }

287

288 289 290
                {
                    // Allocate the pattern of a matrix from the result of the product of two other matrices.
                    const auto& fluid_mass_matrix_on_solid_mesh = GetFluidMassMatrixOnSolidMesh();
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

                    auto& t11 = GetNonCstFluidMassMatrixOnFluidMesh();
                    auto& intermediate = GetNonCstWorkMatrixFluidMassMatrixOnFluidMesh();
                    
//                    decltype(auto) interp_matrix = GetInterpMassFromSolidMesh().GetInterpolationMatrix();
//
//                    decltype(auto) size1 = fluid_mass_matrix_on_solid_mesh.GetProcessorWiseSize(__FILE__, __LINE__);
//                    decltype(auto) size2 = interp_matrix.GetProcessorWiseSize(__FILE__, __LINE__);
//                  //  decltype(auto) size3 = intermediate.GetProcessorWiseSize(__FILE__, __LINE__);
//                    
//                    Utilities::PrintTuple(size1, std::cout, ", ", MpiHappyHeart().GetRankPreffix() + " Matrix1 -> [");
//                    Utilities::PrintTuple(size2, std::cout, ", ", MpiHappyHeart().GetRankPreffix() + " Matrix2 -> [");
//                  //  Utilities::PrintTuple(size3, std::cout, ", ", MpiHappyHeart().GetRankPreffix() + " Matrix3 -> [");
//                    
//                    Wrappers::Petsc::MatMatMultSymbolic(interp_matrix,
//                                                        fluid_mass_matrix_on_solid_mesh,
//                                                        intermediate,
//                                                        __FILE__, __LINE__);
//                    
//                    Wrappers::Petsc::MatMatMultNumeric(interp_matrix,
//                                                       fluid_mass_matrix_on_solid_mesh,
//                                                       intermediate,
//                                                       __FILE__, __LINE__);
//                    
//                    Wrappers::Petsc::MatTransposeMatMultSymbolic(interp_matrix,
//                                                                 intermediate,
//                                                                 t11,
//                                                                 __FILE__, __LINE__);
319
                }
320
                
321
                
322 323 324
                {
                    // \todo #820 Only for dev purposes (comparison with freefem output).
                    using type = ConformInterpolatorNS::SubsetOrSuperset;
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
                    
                    reduce_to_pressure_ =
                        std::make_unique<type>(monolithic_felt_space,
                                               god_of_dof.GetNumberingSubset(EnumUnderlyingType(NumberingSubsetIndex::fluid_mass_velocity_pressure)),
                                               fluid_felt_space,
                                               god_of_dof.GetNumberingSubset(EnumUnderlyingType(NumberingSubsetIndex::fluid_pressure)));
                    
                    reduce_to_pressure_->Init();
                    
                    reduce_to_velocity_ =
                        std::make_unique<type>(monolithic_felt_space,
                                               god_of_dof.GetNumberingSubset(EnumUnderlyingType(NumberingSubsetIndex::fluid_mass_velocity_pressure)),
                                               fluid_felt_space,
                                               god_of_dof.GetNumberingSubset(EnumUnderlyingType(NumberingSubsetIndex::fluid_velocity)));
                    
                    reduce_to_velocity_->Init();
                    
                    
                    expand_pressure_ =
                        std::make_unique<type>(fluid_felt_space,
                                               god_of_dof.GetNumberingSubset(EnumUnderlyingType(NumberingSubsetIndex::fluid_pressure)),
                                               monolithic_felt_space,
                                               god_of_dof.GetNumberingSubset(EnumUnderlyingType(NumberingSubsetIndex::fluid_mass_velocity_pressure)));
                                               
                    
                    expand_pressure_->Init();
351 352
                    
                    
353 354 355 356 357 358 359 360
                    expand_velocity_ =
                        std::make_unique<type>(fluid_felt_space,
                                               god_of_dof.GetNumberingSubset(EnumUnderlyingType(NumberingSubsetIndex::fluid_velocity)),
                                               monolithic_felt_space,
                                               god_of_dof.GetNumberingSubset(EnumUnderlyingType(NumberingSubsetIndex::fluid_mass_velocity_pressure)));
                    
                    expand_velocity_->Init();

361 362 363

                }
                
364
             
365 366 367 368 369 370 371 372 373 374
            }
            
            
        } // namespace ImplicitStepFluidNS
        
        
    } // namespace PoromechanicsNS
    
    
} // namespace HappyHeart