From fc3f3ad76d7e7736a0c3581fc84ba54cc5537a9c Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Tue, 19 Jan 2016 19:55:58 +0100 Subject: [PATCH] [PL] Move BCs to Process. Small generalizations. - initializeNeumannBcs() is no longer needed. - make _neumann_bcs a vector of unique_ptr's. --- ProcessLib/GroundwaterFlowProcess.h | 27 +++++---------------------- ProcessLib/Process.h | 23 ++++++++++++++++++----- ProcessLib/ProcessVariable.h | 5 +++-- 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/ProcessLib/GroundwaterFlowProcess.h b/ProcessLib/GroundwaterFlowProcess.h index b9bbdf2df5a..02be590d2cc 100644 --- a/ProcessLib/GroundwaterFlowProcess.h +++ b/ProcessLib/GroundwaterFlowProcess.h @@ -24,8 +24,6 @@ #include "FileIO/VtkIO/VtuInterface.h" -#include "MathLib/LinAlg/ApplyKnownSolution.h" - #include "MeshLib/MeshSubset.h" #include "MeshGeoToolsLib/MeshNodeSearcher.h" @@ -153,14 +151,17 @@ public: _local_assemblers, *_hydraulic_conductivity, _integration_order); + } + void initializeBoundaryConditions() override + { DBUG("Initialize boundary conditions."); MeshGeoToolsLib::MeshNodeSearcher& hydraulic_head_mesh_node_searcher = MeshGeoToolsLib::MeshNodeSearcher::getMeshNodeSearcher( _hydraulic_head->getMesh()); _hydraulic_head->initializeDirichletBCs( - std::back_inserter(_dirichlet_bcs), + std::back_inserter(this->_dirichlet_bcs), hydraulic_head_mesh_node_searcher, *this->_local_to_global_index_map, 0); @@ -176,7 +177,7 @@ public: // Create a neumann BC for the hydraulic head storing them in the // _neumann_bcs vector. _hydraulic_head->createNeumannBcs( - std::back_inserter(_neumann_bcs), + std::back_inserter(this->_neumann_bcs), hydraulic_head_mesh_element_searcher, this->_global_setup, _integration_order, @@ -184,8 +185,6 @@ public: 0, *_mesh_subset_all_nodes); } - - Process<GlobalSetup>::initializeNeumannBcs(_neumann_bcs); } void initializeMeshSubsets(MeshLib::Mesh const& mesh) override @@ -230,14 +229,6 @@ public: this->_global_setup.execute(*this->_global_assembler, _local_assemblers); - // Call global assembler for each Neumann boundary local assembler. - for (auto bc : _neumann_bcs) - bc->integrate(this->_global_setup); - - for (auto const& bc : _dirichlet_bcs) - MathLib::applyKnownSolution(*this->_A, *this->_rhs, *this->_x, - bc.global_ids, bc.values); - return true; } @@ -294,13 +285,8 @@ public: ~GroundwaterFlowProcess() { - for (auto p : _neumann_bcs) - delete p; - for (auto p : _local_assemblers) delete p; - - delete _mesh_subset_all_nodes; } private: @@ -314,9 +300,6 @@ private: typename GlobalSetup::MatrixType, typename GlobalSetup::VectorType>; std::vector<LocalAssembler*> _local_assemblers; - - std::vector<DirichletBc<GlobalIndexType>> _dirichlet_bcs; - std::vector<NeumannBc<GlobalSetup>*> _neumann_bcs; }; } // namespace ProcessLib diff --git a/ProcessLib/Process.h b/ProcessLib/Process.h index 9de6e4ac5a5..cdc9f36bea4 100644 --- a/ProcessLib/Process.h +++ b/ProcessLib/Process.h @@ -13,9 +13,10 @@ #include <string> #include "AssemblerLib/ComputeSparsityPattern.h" -#include "AssemblerLib/VectorMatrixAssembler.h" #include "AssemblerLib/LocalToGlobalIndexMap.h" +#include "AssemblerLib/VectorMatrixAssembler.h" #include "BaseLib/ConfigTreeNew.h" +#include "MathLib/LinAlg/ApplyKnownSolution.h" #include "MathLib/LinAlg/SetMatrixSparsity.h" #include "MeshLib/MeshSubsets.h" @@ -59,6 +60,8 @@ public: /// Creates mesh subsets, i.e. components, for given mesh. virtual void initializeMeshSubsets(MeshLib::Mesh const& mesh) = 0; + virtual void initializeBoundaryConditions() = 0; + void initialize() { DBUG("Initialize process."); @@ -83,11 +86,10 @@ public: new GlobalAssembler(*_A, *_rhs, *_local_to_global_index_map)); init(); // Execute proces specific initialization. - } - void initializeNeumannBcs(std::vector<NeumannBc<GlobalSetup>*> const& bcs) - { - for (auto bc : bcs) + initializeBoundaryConditions(); + + for (auto& bc : _neumann_bcs) bc->initialize(_global_setup, *_A, *_rhs, _mesh.getDimension()); } @@ -98,6 +100,14 @@ public: bool const result = assemble(delta_t); + // Call global assembler for each Neumann boundary local assembler. + for (auto const& bc : _neumann_bcs) + bc->integrate(_global_setup); + + for (auto const& bc : _dirichlet_bcs) + MathLib::applyKnownSolution(*_A, *_rhs, *_x, + bc.global_ids, bc.values); + _linear_solver->solve(*_rhs, *_x); return result; } @@ -184,6 +194,9 @@ protected: std::unique_ptr<typename GlobalSetup::VectorType> _x; AssemblerLib::SparsityPattern _sparsity_pattern; + + std::vector<DirichletBc<GlobalIndexType>> _dirichlet_bcs; + std::vector<std::unique_ptr<NeumannBc<GlobalSetup>>> _neumann_bcs; }; } // namespace ProcessLib diff --git a/ProcessLib/ProcessVariable.h b/ProcessLib/ProcessVariable.h index f67506765f0..565768a8070 100644 --- a/ProcessLib/ProcessVariable.h +++ b/ProcessLib/ProcessVariable.h @@ -81,8 +81,9 @@ public: for (auto& config : _neumann_bc_configs) { config->initialize(searcher); - bcs++ = new NeumannBc<GlobalSetup>(*config, - std::forward<Args>(args)...); + bcs++ = std::unique_ptr<NeumannBc<GlobalSetup>>{ + new NeumannBc<GlobalSetup>(*config, + std::forward<Args>(args)...)}; } } -- GitLab