Allium  0.1.0
petsc_mesh.impl.hpp
1 // Copyright 2020 Hannah Rittich
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "petsc_mesh.hpp"
16 
17 #ifdef ALLIUM_USE_PETSC
18 
19 namespace allium {
20 
21  template <typename N, int D>
22  PetscMesh<N, D>::PetscMesh(std::shared_ptr<PetscMeshSpec<D>> spec)
23  : PetscAbstractVectorStorage<N>(spec->vector_spec()),
24  m_spec(spec)
25  {
26  using namespace petsc;
27  PetscErrorCode ierr;
28 
29  PetscObjectPtr<Vec> ptr;
30  ierr = DMCreateGlobalVector(spec->dm(), ptr.writable_ptr());
31  this->native(ptr);
32 
33  chkerr(ierr);
34  }
35 
36  template <typename N, int D>
37  PetscMesh<N, D>::PetscMesh(std::shared_ptr<PetscMeshSpec<D>> spec,
38  PetscObjectPtr<Vec> ptr)
39  : PetscAbstractVectorStorage<N>(spec->vector_spec()),
40  m_spec(spec)
41  {
42  this->native(ptr);
43  }
44 
45  template <typename N, int D>
46  PetscMesh<N, D>* PetscMesh<N, D>::allocate_like() const& {
47  return new PetscMesh(m_spec);
48  }
49 
50  template <typename N, int D>
51  PetscMesh<N, D>* PetscMesh<N, D>::clone() const& {
52  std::unique_ptr<PetscMesh> cloned(allocate_like());
53  cloned->assign(*this);
54  return cloned.release();
55  }
56 }
57 
58 #endif