Flow123d  JB_transport-112d700
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 #include "fields/field_constant.hh"
31 
32 #include "fem/mapping_p1.hh"
33 #include "fem/fe_p.hh"
34 #include "fem/dofhandler.hh"
35 #include "fem/discrete_space.hh"
36 
37 
38 template <int spacedim>
40  IndexField region_id;
41  region_id.name("region_id");
42  region_id.units( UnitSI::dimensionless() );
43  region_id.set_mesh(mesh);
44 
45  RegionSet all_regions=mesh.region_db().get_region_set("ALL");
46  for(Region reg : all_regions) {
47  auto field_algo=std::make_shared<FieldConstant<spacedim, DoubleScalar>>();
48  field_algo->set_value(reg.id());
49  region_id.set(
50  field_algo,
51  0.0, // time=0.0
52  { reg.label() }); // set to region by its name
53  }
54  return region_id;
55 }
56 
57 template <int spacedim>
59  MixedPtr<FE_P_disc> fe(0);
60  std::shared_ptr<DOFHandlerMultiDim> dh = std::make_shared<DOFHandlerMultiDim>(mesh);
61  std::shared_ptr<DiscreteSpace> ds = std::make_shared<EqualOrderDiscreteSpace>( &mesh, fe);
62  dh->distribute_dofs(ds);
63 
64  auto field_subdomain_data = mesh.get_part()->subdomain_id_field_data();
65  unsigned int data_size = field_subdomain_data->size();
66  VectorMPI data_vec(data_size);
67  ASSERT_EQ(dh->max_elem_dofs(), 1);
68  unsigned int i_ele=0;
69  for (auto cell : dh->own_range()) {
70  data_vec.set( cell.get_loc_dof_indices()(0), (*field_subdomain_data)[i_ele] );
71  ++i_ele;
72  }
73  std::shared_ptr< FieldFE<spacedim, DoubleScalar> > field_ptr = std::make_shared< FieldFE<spacedim, DoubleScalar> >();
74  field_ptr->set_fe_data(dh, data_vec);
75 
76  IndexField subdomain;
77  subdomain.name("subdomain");
78  subdomain.units( UnitSI::dimensionless() );
79  subdomain.set_mesh(mesh);
80 
81  subdomain.set(
82  field_ptr,
83  0.0, // time=0.0
84  { "ALL" }); // ALL regions
85 
86  return subdomain;
87 }
88 
89 
90 template <int spacedim>
92  MixedPtr<FE_P_disc> fe(0);
93  std::shared_ptr<DOFHandlerMultiDim> dh = std::make_shared<DOFHandlerMultiDim>(mesh);
94  std::shared_ptr<DiscreteSpace> ds = std::make_shared<EqualOrderDiscreteSpace>( &mesh, fe);
95  dh->distribute_dofs(ds);
96 
97  VectorMPI data_vec(dh->lsize());
98  ASSERT_EQ(dh->max_elem_dofs(), 1);
99  unsigned int i_ele=0;
100  for (auto cell : dh->own_range()) {
101  data_vec.set( cell.get_loc_dof_indices()(0), cell.elm().measure() );
102  ++i_ele;
103  }
104  std::shared_ptr< FieldFE<spacedim, DoubleScalar> > field_ptr = std::make_shared< FieldFE<spacedim, DoubleScalar> >();
105  field_ptr->set_fe_data(dh, data_vec);
106 
107  IndexField measure;
108  measure.name("element_measure");
109  measure.units( UnitSI().md() );
110  measure.set_mesh(mesh);
111 
112  measure.set(
113  field_ptr,
114  0.0, // time=0.0
115  { "ALL" }); // ALL regions
116 
117  return measure;
118 }
119 
120 
121 template <int spacedim>
123  MixedPtr<FE_P_disc> fe(0);
124  std::shared_ptr<DOFHandlerMultiDim> dh = std::make_shared<DOFHandlerMultiDim>(mesh);
125  std::shared_ptr<DiscreteSpace> ds = std::make_shared<EqualOrderDiscreteSpace>( &mesh, fe);
126  dh->distribute_dofs(ds);
127 
128  VectorMPI data_vec(dh->lsize());
129  ASSERT_EQ(dh->max_elem_dofs(), 1);
130  unsigned int i_ele=0;
131  for (auto cell : dh->own_range()) {
132  double h = 0;
133  for (auto side : cell.side_range())
134  h = max(h, side.diameter());
135  data_vec.set( cell.get_loc_dof_indices()(0), h );
136  ++i_ele;
137  }
138  std::shared_ptr< FieldFE<spacedim, DoubleScalar> > field_ptr = std::make_shared< FieldFE<spacedim, DoubleScalar> >();
139  field_ptr->set_fe_data(dh, data_vec);
140 
141  IndexField diam;
142  diam.name("element_diameter");
143  diam.units( UnitSI().m() );
144  diam.set_mesh(mesh);
145 
146  diam.set(
147  field_ptr,
148  0.0, // time=0.0
149  { "ALL" }); // ALL regions
150 
151  return diam;
152 }
153 
154 
155 #endif /* GENERAL_FIELD_IMPL_HH_ */
FieldCommon::units
FieldCommon & units(const UnitSI &units)
Set basic units of the field.
Definition: field_common.hh:153
GenericField::element_diameter
static auto element_diameter(Mesh &mesh) -> IndexField
Definition: generic_field.impl.hh:122
UnitSI::dimensionless
static UnitSI & dimensionless()
Returns dimensionless unit.
Definition: unit_si.cc:55
field_constant.hh
vector_mpi.hh
UnitSI::md
UnitSI & md(int exp=-1)
The dimension dependent meter: md^y = m^(yd), where 'd' is dimension.
Definition: unit_si.cc:106
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...
UnitSI::m
UnitSI & m(int exp=1)
Methods set values of exponents for SI units with similar name.
Definition: unit_si.cc:64
fe_p.hh
Definitions of basic Lagrangean finite elements with polynomial shape functions.
VectorMPI::set
void set(unsigned int pos, double val)
Set value on given position.
Definition: vector_mpi.hh:111
Region
Definition: region.hh:145
accessors.hh
Field::set
void set(FieldBasePtr field, double time, std::vector< std::string > region_set_names={"ALL"})
Definition: field.impl.hh:244
GenericField::subdomain
static auto subdomain(Mesh &mesh) -> IndexField
Definition: generic_field.impl.hh:58
UnitSI
Class for representation SI units of Fields.
Definition: unit_si.hh:40
ASSERT_EQ
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual) only for debug mode.
Definition: asserts.hh:333
mesh.h
generic_field.hh
partitioning.hh
GenericField::region_id
static auto region_id(Mesh &mesh) -> IndexField
Definition: generic_field.impl.hh:39
Mesh
Definition: mesh.h:362
Field::set_mesh
void set_mesh(const Mesh &mesh) override
Definition: field.impl.hh:205
fe_value_handler.hh
MixedPtr< FE_P_disc >
mapping_p1.hh
Class MappingP1 implements the affine transformation of the unit cell onto the actual cell.
VectorMPI
Definition: vector_mpi.hh:43
Field
Class template representing a field with values dependent on: point, element, and region.
Definition: field.hh:92
GenericField::element_measure
static auto element_measure(Mesh &mesh) -> IndexField
Definition: generic_field.impl.hh:91
FieldCommon::name
FieldCommon & name(const string &name)
Definition: field_common.hh:121