Flow123d  release_3.0.0-973-g92f55e826
generic_field.impl.hh
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 generic_field.impl.hh
15  * @brief
16  */
17 
18 #ifndef GENERIC_FIELD_IMPL_HH_
19 #define GENERIC_FIELD_IMPL_HH_
20 
21 #include <memory>
22 #include "mesh/mesh.h"
23 #include "mesh/partitioning.hh"
24 #include "mesh/accessors.hh"
25 
26 #include "fields/generic_field.hh"
27 #include "fields/field_fe.hh"
28 #include "la/vector_mpi.hh"
30 
31 #include "fem/mapping_p1.hh"
32 #include "fem/fe_p.hh"
33 #include "fem/dofhandler.hh"
34 #include "fem/discrete_space.hh"
35 
36 
37 template <int spacedim>
39  IndexField region_id;
40  region_id.name("region_id");
41  region_id.units( UnitSI::dimensionless() );
42  region_id.set_mesh(mesh);
43 
44  RegionSet all_regions=mesh.region_db().get_region_set("ALL");
45  for(Region reg : all_regions) {
46  auto field_algo=std::make_shared<FieldConstant<spacedim, DoubleScalar>>();
47  field_algo->set_value(reg.id());
48  region_id.set_field(
49  {reg} ,
50  field_algo,
51  0.0); // time=0.0
52  }
53  return region_id;
54 }
55 
56 template <int spacedim>
58  static FE_P_disc<0> fe0(0);
59  static FE_P_disc<1> fe1(0);
60  static FE_P_disc<2> fe2(0);
61  static FE_P_disc<3> fe3(0);
62  DOFHandlerMultiDim dh_par(mesh);
63  std::shared_ptr<DiscreteSpace> ds = std::make_shared<EqualOrderDiscreteSpace>( &mesh, &fe0, &fe1, &fe2, &fe3);
64  dh_par.distribute_dofs(ds);
65  std::shared_ptr<DOFHandlerMultiDim> dh = dh_par.sequential();
66 
67  auto field_subdomain_data = mesh.get_part()->subdomain_id_field_data();
68  std::vector<LongIdx> indices(1);
69  VectorMPI *data_vec = new VectorMPI(mesh.n_elements());
70  ASSERT_EQ(dh->max_elem_dofs(), 1);
71  unsigned int i_ele=0;
72  for (auto cell : dh->own_range()) {
73  cell.get_loc_dof_indices(indices);
74  (*data_vec)[ indices[0] ] = (*field_subdomain_data)[i_ele];
75  ++i_ele;
76  }
77  std::shared_ptr< FieldFE<spacedim, DoubleScalar> > field_ptr = std::make_shared< FieldFE<spacedim, DoubleScalar> >();
78  field_ptr->set_fe_data(dh);
79 
80  IndexField subdomain;
81  subdomain.name("subdomain");
82  subdomain.units( UnitSI::dimensionless() );
83  subdomain.set_mesh(mesh);
84 
85  subdomain.set_field(
86  mesh.region_db().get_region_set("ALL"),
87  field_ptr,
88  0.0); // time=0.0
89 
90  return subdomain;
91 }
92 
93 
94 
95 #endif /* GENERAL_FIELD_IMPL_HH_ */
FieldCommon::units
FieldCommon & units(const UnitSI &units)
Set basic units of the field.
Definition: field_common.hh:140
UnitSI::dimensionless
static UnitSI & dimensionless()
Returns dimensionless unit.
Definition: unit_si.cc:55
vector_mpi.hh
discrete_space.hh
Declaration of class which provides the finite element for every mesh cell.
std::vector< Region >
field_fe.hh
dofhandler.hh
Declaration of class which handles the ordering of degrees of freedom (dof) and mappings between loca...
fe_p.hh
Definitions of basic Lagrangean finite elements with polynomial shape functions.
Region
Definition: region.hh:146
accessors.hh
DOFHandlerMultiDim
Provides the numbering of the finite element degrees of freedom on the computational mesh.
Definition: dofhandler.hh:152
DOFHandlerMultiDim::distribute_dofs
void distribute_dofs(std::shared_ptr< DiscreteSpace > ds)
Distributes degrees of freedom on the mesh needed for the given discrete space.
Definition: dofhandler.cc:242
GenericField::subdomain
static auto subdomain(Mesh &mesh) -> IndexField
Definition: generic_field.impl.hh:57
ASSERT_EQ
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual)
Definition: asserts.hh:327
DOFHandlerMultiDim::sequential
std::shared_ptr< DOFHandlerMultiDim > sequential()
Returns sequential version of the current dof handler.
Definition: dofhandler.cc:54
mesh.h
generic_field.hh
Field::set_field
void set_field(const RegionSet &domain, FieldBasePtr field, double time=0.0)
Definition: field.impl.hh:196
partitioning.hh
GenericField::region_id
static auto region_id(Mesh &mesh) -> IndexField
Definition: generic_field.impl.hh:38
Mesh
Definition: mesh.h:80
Field::set_mesh
void set_mesh(const Mesh &mesh) override
Definition: field.impl.hh:157
fe_value_handler.hh
mapping_p1.hh
Class MappingP1 implements the affine transformation of the unit cell onto the actual cell.
VectorMPI
Definition: vector_mpi.hh:42
Field
Class template representing a field with values dependent on: point, element, and region.
Definition: field.hh:83
FE_P_disc< 0 >
FieldCommon::name
FieldCommon & name(const string &name)
Definition: field_common.hh:108