/** * \file * \copyright * Copyright (c) 2012-2023, OpenGeoSys Community (http://www.opengeosys.org) * Distributed under a Modified BSD License. * See accompanying file LICENSE.txt or * http://www.opengeosys.org/project/license * */ #include "HeatConductionProcess.h" #include #include "MathLib/LinAlg/FinalizeMatrixAssembly.h" #include "MathLib/LinAlg/FinalizeVectorAssembly.h" #include "NumLib/DOF/DOFTableUtil.h" #include "ProcessLib/Utils/ComputeResiduum.h" #include "ProcessLib/Utils/CreateLocalAssemblers.h" namespace ProcessLib { namespace HeatConduction { HeatConductionProcess::HeatConductionProcess( std::string name, MeshLib::Mesh& mesh, std::unique_ptr&& jacobian_assembler, std::vector> const& parameters, unsigned const integration_order, std::vector>>&& process_variables, HeatConductionProcessData&& process_data, SecondaryVariableCollection&& secondary_variables) : Process(std::move(name), mesh, std::move(jacobian_assembler), parameters, integration_order, std::move(process_variables), std::move(secondary_variables)), _process_data(std::move(process_data)) { _heat_flux = MeshLib::getOrCreateMeshProperty( mesh, "HeatFlowRate", MeshLib::MeshItemType::Node, 1); } void HeatConductionProcess::initializeConcreteProcess( NumLib::LocalToGlobalIndexMap const& dof_table, MeshLib::Mesh const& mesh, unsigned const integration_order) { int const mesh_space_dimension = _process_data.mesh_space_dimension; ProcessLib::createLocalAssemblers( mesh_space_dimension, mesh.getElements(), dof_table, _local_assemblers, NumLib::IntegrationOrder{integration_order}, mesh.isAxiallySymmetric(), _process_data); _secondary_variables.addSecondaryVariable( "heat_flux", makeExtrapolator( mesh_space_dimension, getExtrapolator(), _local_assemblers, &HeatConductionLocalAssemblerInterface::getIntPtHeatFlux)); } void HeatConductionProcess::assembleConcreteProcess( const double t, double const dt, std::vector const& x, std::vector const& xdot, int const process_id, GlobalMatrix& M, GlobalMatrix& K, GlobalVector& b) { DBUG("Assemble HeatConductionProcess."); ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0]; std::vector> dof_table = {std::ref(*_local_to_global_index_map)}; // Call global assembler for each local assembly item. GlobalExecutor::executeSelectedMemberDereferenced( _global_assembler, &VectorMatrixAssembler::assemble, _local_assemblers, pv.getActiveElementIDs(), dof_table, t, dt, x, xdot, process_id, M, K, b); MathLib::finalizeMatrixAssembly(M); MathLib::finalizeMatrixAssembly(K); MathLib::finalizeVectorAssembly(b); auto const residuum = computeResiduum(*x[0], *xdot[0], M, K, b); transformVariableFromGlobalVector(residuum, 0 /*variable id*/, *_local_to_global_index_map, *_heat_flux, std::negate()); } void HeatConductionProcess::assembleWithJacobianConcreteProcess( const double t, double const dt, std::vector const& x, std::vector const& xdot, int const process_id, GlobalMatrix& M, GlobalMatrix& K, GlobalVector& b, GlobalMatrix& Jac) { DBUG("AssembleWithJacobian HeatConductionProcess."); ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0]; std::vector> dof_table = {std::ref(*_local_to_global_index_map)}; // Call global assembler for each local assembly item. GlobalExecutor::executeSelectedMemberDereferenced( _global_assembler, &VectorMatrixAssembler::assembleWithJacobian, _local_assemblers, pv.getActiveElementIDs(), dof_table, t, dt, x, xdot, process_id, M, K, b, Jac); transformVariableFromGlobalVector(b, 0 /*variable id*/, *_local_to_global_index_map, *_heat_flux, std::negate()); } void HeatConductionProcess::computeSecondaryVariableConcrete( double const t, double const dt, std::vector const& x, GlobalVector const& x_dot, int const process_id) { DBUG("Compute heat flux for HeatConductionProcess."); std::vector dof_tables; dof_tables.reserve(x.size()); std::generate_n(std::back_inserter(dof_tables), x.size(), [&]() { return _local_to_global_index_map.get(); }); ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0]; GlobalExecutor::executeSelectedMemberOnDereferenced( &HeatConductionLocalAssemblerInterface::computeSecondaryVariable, _local_assemblers, pv.getActiveElementIDs(), dof_tables, t, dt, x, x_dot, process_id); } } // namespace HeatConduction } // namespace ProcessLib