Flow123d  release_3.0.0-506-g34af125
vec_seq_double.cc
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file vec_seq_double.cc
15  * @brief
16  */
17 
18 
19 #include "fields/vec_seq_double.hh"
21 #include "fields/field_fe.hh"
22 #include "fem/fe_p.hh"
23 #include "fem/mapping_p1.hh"
24 #include "fem/fe_system.hh"
25 
26 template <int spacedim, class Value>
27 std::shared_ptr<FieldFE<spacedim, Value> > VectorSeqDouble::create_field(Mesh & mesh, unsigned int n_comp)
28 {
29  static MappingP1<1,3> map1;
30  static MappingP1<2,3> map2;
31  static MappingP1<3,3> map3;
32 
33  if ( (dh_ == nullptr) || (dh_->mesh()->n_elements() != mesh.n_elements()) ) {
34  switch (n_comp) { // by number of components
35  case 1: { // scalar
36  fe0_ = new FE_P_disc<0>(0);
37  fe1_ = new FE_P_disc<1>(0);
38  fe2_ = new FE_P_disc<2>(0);
39  fe3_ = new FE_P_disc<3>(0);
40  break;
41  }
42  case 3: { // vector
43  std::shared_ptr< FiniteElement<0> > fe0_ptr = std::make_shared< FE_P_disc<0> >(0);
44  std::shared_ptr< FiniteElement<1> > fe1_ptr = std::make_shared< FE_P_disc<1> >(0);
45  std::shared_ptr< FiniteElement<2> > fe2_ptr = std::make_shared< FE_P_disc<2> >(0);
46  std::shared_ptr< FiniteElement<3> > fe3_ptr = std::make_shared< FE_P_disc<3> >(0);
47  fe0_ = new FESystem<0>(fe0_ptr, FEType::FEVector, 3);
48  fe1_ = new FESystem<1>(fe1_ptr, FEType::FEVector, 3);
49  fe2_ = new FESystem<2>(fe2_ptr, FEType::FEVector, 3);
50  fe3_ = new FESystem<3>(fe3_ptr, FEType::FEVector, 3);
51  break;
52  }
53  case 9: { // tensor
54  std::shared_ptr< FiniteElement<0> > fe0_ptr = std::make_shared< FE_P_disc<0> >(0);
55  std::shared_ptr< FiniteElement<1> > fe1_ptr = std::make_shared< FE_P_disc<1> >(0);
56  std::shared_ptr< FiniteElement<2> > fe2_ptr = std::make_shared< FE_P_disc<2> >(0);
57  std::shared_ptr< FiniteElement<3> > fe3_ptr = std::make_shared< FE_P_disc<3> >(0);
58  fe0_ = new FESystem<0>(fe0_ptr, FEType::FETensor, 9);
59  fe1_ = new FESystem<1>(fe1_ptr, FEType::FETensor, 9);
60  fe2_ = new FESystem<2>(fe2_ptr, FEType::FETensor, 9);
61  fe3_ = new FESystem<3>(fe3_ptr, FEType::FETensor, 9);
62  break;
63  }
64  default:
65  ASSERT(false).error("Should not happen!\n");
66  }
67 
68  dh_ = std::make_shared<DOFHandlerMultiDim>(mesh);
69  //dh_->distribute_dofs(*fe0_, *fe1_, *fe2_, *fe3_);
70  std::shared_ptr<DiscreteSpace> ds = std::make_shared<EqualOrderDiscreteSpace>( &mesh, fe0_, fe1_, fe2_, fe3_);
71  dh_->distribute_dofs(ds, true);
72  }
73 
74  VectorSeqDouble *data_vec = new VectorSeqDouble();
75  data_vec->resize( this->size() );
76  std::shared_ptr< FieldFE<spacedim, Value> > field_ptr = std::make_shared< FieldFE<spacedim, Value> >();
77  field_ptr->set_fe_data(dh_, &map1, &map2, &map3, data_vec);
78  return field_ptr;
79 }
80 
81 template <int spacedim, class Value>
83 {
84  ASSERT_EQ(field_ptr->dh_->hash(), dh_->hash());
85  unsigned int ndofs = dh_->max_elem_dofs();
86  unsigned int idof; // iterate over indices
87  std::vector<LongIdx> indices(ndofs);
88 
89  for (auto ele : dh_->mesh()->elements_range()) {
90  dh_->get_dof_indices(ele, indices);
91  for(idof=0; idof<ndofs; idof++) (*field_ptr->data_vec_)[ indices[idof] ] = (*data_ptr_)[ ndofs*ele.idx()+idof ];
92  }
93 }
94 
95 
96 // Instantiations of templated methods
97 template std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar>> VectorSeqDouble::create_field(Mesh & mesh, unsigned int n_comp);
98 template std::shared_ptr<FieldFE<3, FieldValue<3>::VectorFixed>> VectorSeqDouble::create_field(Mesh & mesh, unsigned int n_comp);
99 template void VectorSeqDouble::fill_output_data(std::shared_ptr<FieldFE<3, FieldValue<3>::Scalar>> field_ptr);
100 template void VectorSeqDouble::fill_output_data(std::shared_ptr<FieldFE<3, FieldValue<3>::VectorFixed>> field_ptr);
Class MappingP1 implements the affine transformation of the unit cell onto the actual cell...
FiniteElement< 1 > * fe1_
Definition: mesh.h:80
FiniteElement< 0 > * fe0_
Finite element objects (allow to create DOF handler)
Class FESystem for compound finite elements.
VectorSeqDouble()
Constructor.
std::shared_ptr< FieldFE< spacedim, Value > > create_field(Mesh &mesh, unsigned int n_comp)
Create and return shared pointer to FieldFE object.
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
Definition: asserts.hh:346
void fill_output_data(std::shared_ptr< FieldFE< spacedim, Value > > field_ptr)
unsigned int size()
Getter for shared pointer of output data.
Compound finite element on dim dimensional simplex.
Definition: fe_system.hh:99
FiniteElement< 3 > * fe3_
Definitions of basic Lagrangean finite elements with polynomial shape functions.
void resize(unsigned int size)
Create shared pointer and PETSC vector with given size.
virtual unsigned int n_elements(bool boundary=false) const
Returns count of boundary or bulk elements.
Definition: mesh.h:346
FiniteElement< 2 > * fe2_
std::shared_ptr< DOFHandlerMultiDim > dh_
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual)
Definition: asserts.hh:327
Definition: field.hh:56