OGS
ProcessLib::ProcessVariable Class Reference

Detailed Description

A named process variable. Its properties includes the mesh, and the initial and boundary conditions as well as the source terms.

Definition at line 61 of file ProcessVariable.h.

#include <ProcessVariable.h>

Collaboration diagram for ProcessLib::ProcessVariable:
[legend]

Public Member Functions

 ProcessVariable (BaseLib::ConfigTree const &config, MeshLib::Mesh &mesh, std::vector< std::unique_ptr< MeshLib::Mesh > > const &meshes, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves)
 
 ProcessVariable (ProcessVariable &&)
 
std::string const & getName () const
 
MeshLib::Mesh const & getMesh () const
 Returns a mesh on which the process variable is defined.
 
std::vector< DeactivatedSubdomain > const & getDeactivatedSubdomains () const
 
void updateDeactivatedSubdomains (double const time)
 
std::vector< std::size_t > const & getActiveElementIDs () const
 
int getNumberOfGlobalComponents () const
 Returns the number of components of the process variable.
 
std::vector< std::unique_ptr< BoundaryCondition > > createBoundaryConditions (const NumLib::LocalToGlobalIndexMap &dof_table, const int variable_id, unsigned const integration_order, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, Process const &process, std::vector< std::reference_wrapper< ProcessVariable > > const &all_process_variables_for_this_process, std::map< int, std::shared_ptr< MaterialPropertyLib::Medium > > const &media)
 
std::vector< std::unique_ptr< SourceTermBase > > createSourceTerms (const NumLib::LocalToGlobalIndexMap &dof_table, const int variable_id, unsigned const integration_order, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, std::vector< std::reference_wrapper< ProcessVariable > > const &all_process_variables_for_this_process, const MeshLib::Mesh &bulk_mesh)
 
ParameterLib::Parameter< double > const & getInitialCondition () const
 
unsigned getShapeFunctionOrder () const
 
bool compensateNonEquilibriumInitialResiduum () const
 
 ~ProcessVariable ()
 

Private Member Functions

void createBoundaryConditionsForDeactivatedSubDomains (const NumLib::LocalToGlobalIndexMap &dof_table, const int variable_id, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, std::vector< std::unique_ptr< BoundaryCondition > > &bcs)
 

Private Attributes

std::string const _name
 
MeshLib::Mesh_mesh
 
const int _n_components
 
unsigned _shapefunction_order
 
std::vector< DeactivatedSubdomain_deactivated_subdomains
 
std::vector< std::size_t > _ids_of_active_elements
 
MeshLib::PropertyVector< unsigned char > * _is_active = nullptr
 
ParameterLib::Parameter< double > const & _initial_condition
 
std::vector< BoundaryConditionConfig_bc_configs
 
std::vector< SourceTermConfig_source_term_configs
 
const bool _compensate_non_equilibrium_initial_residuum
 

Constructor & Destructor Documentation

◆ ProcessVariable() [1/2]

ProcessLib::ProcessVariable::ProcessVariable ( BaseLib::ConfigTree const & config,
MeshLib::Mesh & mesh,
std::vector< std::unique_ptr< MeshLib::Mesh > > const & meshes,
std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const & parameters,
std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const & curves )
Input File Parameter
prj__process_variables__process_variable__boundary_conditions
Input File Parameter
prj__process_variables__process_variable__boundary_conditions__boundary_condition
Input File Parameter
prj__process_variables__process_variable__boundary_conditions__boundary_condition__component
Input File Parameter
prj__process_variables__process_variable__source_terms
Input File Parameter
prj__process_variables__process_variable__source_terms__source_term
Input File Parameter
prj__process_variables__process_variable__source_terms__source_term__component
Input File Parameter
prj__process_variables__process_variable__source_terms__source_term__type

Definition at line 90 of file ProcessVariable.cpp.

97 :
98 _name(config.getConfigParameter<std::string>("name")),
99 _mesh(mesh),
101 _n_components(config.getConfigParameter<int>("components")),
103 _shapefunction_order(config.getConfigParameter<unsigned>("order")),
105 createDeactivatedSubdomains(config, mesh, parameters, curves)),
108 config.getConfigParameter<std::string>("initial_condition"),
109 parameters, _n_components, &mesh)),
112 config.getConfigParameter<bool>(
113 "compensate_non_equilibrium_initial_residuum", false))
114{
115 DBUG("Constructing process variable {:s}", _name);
116
118 {
119 OGS_FATAL("The given shape function order {:d} is not supported",
121 }
122
123 // Boundary conditions
124 if (auto bcs_config =
126 config.getConfigSubtreeOptional("boundary_conditions"))
127 {
128 for (
129 auto bc_config :
131 bcs_config->getConfigSubtreeList("boundary_condition"))
132 {
133 auto const& bc_mesh = findMeshInConfig(bc_config, meshes);
134 auto component_id =
136 bc_config.getConfigParameterOptional<int>("component");
137
138 if (!component_id && _n_components == 1)
139 {
140 // default value for single component vars.
141 component_id = 0;
142 }
143
144 _bc_configs.emplace_back(
145 std::move(bc_config), bc_mesh, component_id,
147 }
148 }
149 else
150 {
151 INFO("No boundary conditions for process variable '{:s}' found.",
152 _name);
153 }
154
155 // Source terms
157 if (auto sts_config = config.getConfigSubtreeOptional("source_terms"))
158 {
159 for (
160 auto st_config :
162 sts_config->getConfigSubtreeList("source_term"))
163 {
164 MeshLib::Mesh const& st_mesh = findMeshInConfig(st_config, meshes);
165 auto component_id =
167 st_config.getConfigParameterOptional<int>("component");
168 auto const type =
170 st_config.peekConfigParameter<std::string>("type");
171
172 if (!component_id)
173 {
174 if (_n_components == 1)
175 {
176 // default value for single component vars.
177 component_id = 0;
178 }
179 else if (type == "Anchor")
180 {
181 // dummy value
182 component_id = 0;
183 }
184 else if (type == "EmbeddedAnchor")
185 {
186 // dummy value
187 component_id = 0;
188 }
189 else
190 {
191 OGS_FATAL(
192 "Specifying the component id (<component>) for a "
193 "source term for a non-scalar process variable is "
194 "mandatory.");
195 }
196 }
197
198 _source_term_configs.emplace_back(std::move(st_config), st_mesh,
199 *component_id);
200 }
201 }
202 else
203 {
204 INFO("No source terms for process variable '{:s}' found.", _name);
205 }
206
207 if (!_deactivated_subdomains.empty())
208 {
209 _is_active = getOrCreateMeshProperty<unsigned char>(
210 _mesh, _name + "_active", MeshLib::MeshItemType::Cell, 1);
211 std::fill(std::begin(*_is_active), std::end(*_is_active), 1u);
212 }
213}
#define OGS_FATAL(...)
Definition Error.h:26
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:36
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
ParameterLib::Parameter< double > const & _initial_condition
std::vector< BoundaryConditionConfig > _bc_configs
std::vector< DeactivatedSubdomain > _deactivated_subdomains
const bool _compensate_non_equilibrium_initial_residuum
MeshLib::PropertyVector< unsigned char > * _is_active
std::vector< SourceTermConfig > _source_term_configs
OGS_NO_DANGLING Parameter< ParameterDataType > & findParameter(std::string const &parameter_name, std::vector< std::unique_ptr< ParameterBase > > const &parameters, int const num_components, MeshLib::Mesh const *const mesh=nullptr)
Definition Utils.h:102
std::vector< DeactivatedSubdomain > createDeactivatedSubdomains(BaseLib::ConfigTree const &config, MeshLib::Mesh const &mesh, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves)
MeshLib::Mesh const & findMeshInConfig(BaseLib::ConfigTree const &config, std::vector< std::unique_ptr< MeshLib::Mesh > > const &meshes)

References _bc_configs, _compensate_non_equilibrium_initial_residuum, _deactivated_subdomains, _is_active, _mesh, _n_components, _name, _shapefunction_order, _source_term_configs, MeshLib::Cell, DBUG(), BaseLib::ConfigTree::getConfigSubtreeOptional(), INFO(), and OGS_FATAL.

◆ ProcessVariable() [2/2]

ProcessLib::ProcessVariable::ProcessVariable ( ProcessVariable && )
default

◆ ~ProcessVariable()

ProcessLib::ProcessVariable::~ProcessVariable ( )
default

Member Function Documentation

◆ compensateNonEquilibriumInitialResiduum()

bool ProcessLib::ProcessVariable::compensateNonEquilibriumInitialResiduum ( ) const
inline

◆ createBoundaryConditions()

std::vector< std::unique_ptr< BoundaryCondition > > ProcessLib::ProcessVariable::createBoundaryConditions ( const NumLib::LocalToGlobalIndexMap & dof_table,
const int variable_id,
unsigned const integration_order,
std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const & parameters,
Process const & process,
std::vector< std::reference_wrapper< ProcessVariable > > const & all_process_variables_for_this_process,
std::map< int, std::shared_ptr< MaterialPropertyLib::Medium > > const & media )

Definition at line 223 of file ProcessVariable.cpp.

232{
233 std::vector<std::unique_ptr<BoundaryCondition>> bcs;
234 bcs.reserve(_bc_configs.size());
235
236 for (auto const& config : _bc_configs)
237 {
238 auto bc = createBoundaryCondition(
239 config, dof_table, _mesh, variable_id, integration_order,
240 _shapefunction_order, parameters, process,
241 all_process_variables_for_this_process, media);
242#ifdef USE_PETSC
243 if (bc == nullptr)
244 {
245 continue;
246 }
247#endif // USE_PETSC
248 bcs.push_back(std::move(bc));
249 }
250
252 parameters, bcs);
253
254 return bcs;
255}
void createBoundaryConditionsForDeactivatedSubDomains(const NumLib::LocalToGlobalIndexMap &dof_table, const int variable_id, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, std::vector< std::unique_ptr< BoundaryCondition > > &bcs)
std::unique_ptr< BoundaryCondition > createBoundaryCondition(const BoundaryConditionConfig &config, const NumLib::LocalToGlobalIndexMap &dof_table, const MeshLib::Mesh &bulk_mesh, const int variable_id, const unsigned integration_order, const unsigned shapefunction_order, const std::vector< std::unique_ptr< ParameterLib::ParameterBase > > &parameters, const Process &process, std::vector< std::reference_wrapper< ProcessVariable > > const &all_process_variables_for_this_process, std::map< int, std::shared_ptr< MaterialPropertyLib::Medium > > const &media)

References _bc_configs, _mesh, _shapefunction_order, ProcessLib::createBoundaryCondition(), and createBoundaryConditionsForDeactivatedSubDomains().

Referenced by ProcessLib::BoundaryConditionCollection::addBCsForProcessVariables().

◆ createBoundaryConditionsForDeactivatedSubDomains()

void ProcessLib::ProcessVariable::createBoundaryConditionsForDeactivatedSubDomains ( const NumLib::LocalToGlobalIndexMap & dof_table,
const int variable_id,
std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const & parameters,
std::vector< std::unique_ptr< BoundaryCondition > > & bcs )
private

Definition at line 257 of file ProcessVariable.cpp.

261{
262 for (auto const& deactivated_subdomain : _deactivated_subdomains)
263 {
264 auto const& deactivated_subdomain_mesh =
265 deactivated_subdomain.deactivated_subdomain_mesh;
266 auto const* parameter = &ParameterLib::findParameter<double>(
268 bool const set_outer_nodes_dirichlet_values =
269 deactivated_subdomain.boundary_value_parameter != nullptr;
270 if (set_outer_nodes_dirichlet_values)
271 {
272 parameter = deactivated_subdomain.boundary_value_parameter;
273 }
274
275 for (int component_id = 0;
276 component_id <
277 dof_table.getNumberOfVariableComponents(variable_id);
278 component_id++)
279 {
280 auto bc = std::make_unique<DeactivatedSubdomainDirichlet>(
281 *_is_active, deactivated_subdomain.time_interval, *parameter,
282 set_outer_nodes_dirichlet_values, deactivated_subdomain_mesh,
283 dof_table, variable_id, component_id);
284
285#ifdef USE_PETSC
286 // TODO: make it work under PETSc too.
287 if (bc == nullptr)
288 {
289 continue;
290 }
291#endif // USE_PETSC
292 bcs.push_back(std::move(bc));
293 }
294 }
295}
int getNumberOfVariableComponents(int variable_id) const
static PROCESSLIB_EXPORT const std::string zero_parameter_name

References _deactivated_subdomains, _is_active, ParameterLib::findParameter(), NumLib::LocalToGlobalIndexMap::getNumberOfVariableComponents(), and ProcessLib::DeactivatedSubdomain::zero_parameter_name.

Referenced by createBoundaryConditions().

◆ createSourceTerms()

std::vector< std::unique_ptr< SourceTermBase > > ProcessLib::ProcessVariable::createSourceTerms ( const NumLib::LocalToGlobalIndexMap & dof_table,
const int variable_id,
unsigned const integration_order,
std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const & parameters,
std::vector< std::reference_wrapper< ProcessVariable > > const & all_process_variables_for_this_process,
const MeshLib::Mesh & bulk_mesh )

Definition at line 353 of file ProcessVariable.cpp.

360{
361 std::vector<std::unique_ptr<SourceTermBase>> source_terms;
362
363 transform(cbegin(_source_term_configs), cend(_source_term_configs),
364 back_inserter(source_terms),
365 [&](auto const& config)
366 {
367 return createSourceTerm(
368 config, dof_table, config.mesh, variable_id,
369 integration_order, _shapefunction_order, parameters,
370 all_process_variables_for_this_process, bulk_mesh);
371 });
372
373 return source_terms;
374}
std::unique_ptr< SourceTermBase > createSourceTerm(const SourceTermConfig &config, const NumLib::LocalToGlobalIndexMap &dof_table_bulk, const MeshLib::Mesh &source_term_mesh, const int variable_id, const unsigned integration_order, const unsigned shapefunction_order, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, std::vector< std::reference_wrapper< ProcessVariable > > const &all_process_variables_for_this_process, const MeshLib::Mesh &bulk_mesh)

References _shapefunction_order, _source_term_configs, and ProcessLib::createSourceTerm().

Referenced by ProcessLib::SourceTermCollection::addSourceTermsForProcessVariables().

◆ getActiveElementIDs()

std::vector< std::size_t > const & ProcessLib::ProcessVariable::getActiveElementIDs ( ) const
inline

Definition at line 87 of file ProcessVariable.h.

88 {
90 }
std::vector< std::size_t > _ids_of_active_elements

References _ids_of_active_elements.

◆ getDeactivatedSubdomains()

std::vector< DeactivatedSubdomain > const & ProcessLib::ProcessVariable::getDeactivatedSubdomains ( ) const
inline

Definition at line 80 of file ProcessVariable.h.

81 {
83 }

References _deactivated_subdomains.

◆ getInitialCondition()

ParameterLib::Parameter< double > const & ProcessLib::ProcessVariable::getInitialCondition ( ) const
inline

◆ getMesh()

MeshLib::Mesh const & ProcessLib::ProcessVariable::getMesh ( ) const

Returns a mesh on which the process variable is defined.

Definition at line 217 of file ProcessVariable.cpp.

218{
219 return _mesh;
220}

References _mesh.

◆ getName()

◆ getNumberOfGlobalComponents()

◆ getShapeFunctionOrder()

◆ updateDeactivatedSubdomains()

void ProcessLib::ProcessVariable::updateDeactivatedSubdomains ( double const time)

Definition at line 297 of file ProcessVariable.cpp.

298{
299 if (_deactivated_subdomains.empty())
300 {
301 return;
302 }
303
305
306 // If none of the deactivated subdomains is active at current time, then the
307 // _ids_of_active_elements remain empty.
308 if (std::none_of(begin(_deactivated_subdomains),
309 end(_deactivated_subdomains), [&](auto const& ds)
310 { return ds.isInTimeSupportInterval(time); }))
311 {
312 // Also mark all of the elements as active.
313 assert(_is_active != nullptr); // guaranteed by constructor
314 std::fill(std::begin(*_is_active), std::end(*_is_active), 1u);
315
316 return;
317 }
318
319 auto is_active_in_subdomain = [&](std::size_t const element_id,
320 DeactivatedSubdomain const& ds) -> bool
321 {
322 return (!ds.isInTimeSupportInterval(time)) ||
323 !ds.isDeactivated(*_mesh.getElement(element_id), time);
324 };
325
326 auto is_active_in_all_subdomains = [&](std::size_t const element_id) -> bool
327 {
328 return std::all_of(begin(_deactivated_subdomains),
330 [&](auto const& ds)
331 { return is_active_in_subdomain(element_id, ds); });
332 };
333
334 auto const number_of_elements = _mesh.getNumberOfElements();
335 for (std::size_t element_id = 0; element_id < number_of_elements;
336 element_id++)
337 {
338 if (is_active_in_all_subdomains(element_id))
339 {
340 _ids_of_active_elements.push_back(element_id);
341 }
342 }
343
344 // all elements are deactivated
345 std::fill(std::begin(*_is_active), std::end(*_is_active), 0u);
346
347 for (auto const id : _ids_of_active_elements)
348 {
349 (*_is_active)[id] = 1u;
350 }
351}
const Element * getElement(std::size_t idx) const
Get the element with the given index.
Definition Mesh.h:96
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:99

References _deactivated_subdomains, _ids_of_active_elements, _is_active, _mesh, MeshLib::Mesh::getElement(), and MeshLib::Mesh::getNumberOfElements().

Member Data Documentation

◆ _bc_configs

std::vector<BoundaryConditionConfig> ProcessLib::ProcessVariable::_bc_configs
private

Definition at line 163 of file ProcessVariable.h.

Referenced by ProcessVariable(), and createBoundaryConditions().

◆ _compensate_non_equilibrium_initial_residuum

const bool ProcessLib::ProcessVariable::_compensate_non_equilibrium_initial_residuum
private

Definition at line 166 of file ProcessVariable.h.

Referenced by ProcessVariable(), and compensateNonEquilibriumInitialResiduum().

◆ _deactivated_subdomains

std::vector<DeactivatedSubdomain> ProcessLib::ProcessVariable::_deactivated_subdomains
private

◆ _ids_of_active_elements

std::vector<std::size_t> ProcessLib::ProcessVariable::_ids_of_active_elements
mutableprivate

IDs of the active elements. It is initialized only if there are deactivated subdomains.

Definition at line 152 of file ProcessVariable.h.

Referenced by getActiveElementIDs(), and updateDeactivatedSubdomains().

◆ _initial_condition

ParameterLib::Parameter<double> const& ProcessLib::ProcessVariable::_initial_condition
private

Definition at line 161 of file ProcessVariable.h.

Referenced by getInitialCondition().

◆ _is_active

MeshLib::PropertyVector<unsigned char>* ProcessLib::ProcessVariable::_is_active = nullptr
private

◆ _mesh

MeshLib::Mesh& ProcessLib::ProcessVariable::_mesh
private

◆ _n_components

const int ProcessLib::ProcessVariable::_n_components
private

Definition at line 132 of file ProcessVariable.h.

Referenced by ProcessVariable(), and getNumberOfGlobalComponents().

◆ _name

std::string const ProcessLib::ProcessVariable::_name
private

Definition at line 130 of file ProcessVariable.h.

Referenced by ProcessVariable(), and getName().

◆ _shapefunction_order

unsigned ProcessLib::ProcessVariable::_shapefunction_order
private

The polynomial order of the process variable's shape functions.

Requires an appropriate mesh.

The order of the shape functions can not be higher than the maximum available order for the underlying geometric elements. For example the second order shape functions for a hexahedron are only possible if the geometric element is at least a 20-node hexahedron element (MeshLib::TemplateElement<MeshLib::HexRule20>), whereas linear shape functions are also available on the 8-node hexahedron (MeshLib::TemplateElement<MeshLib::HexRule8>).

See also
MeshLib::CellRule MeshLib::FaceRule MeshLib::EdgeRule.

Definition at line 146 of file ProcessVariable.h.

Referenced by ProcessVariable(), createBoundaryConditions(), createSourceTerms(), and getShapeFunctionOrder().

◆ _source_term_configs

std::vector<SourceTermConfig> ProcessLib::ProcessVariable::_source_term_configs
private

Definition at line 164 of file ProcessVariable.h.

Referenced by ProcessVariable(), and createSourceTerms().


The documentation for this class was generated from the following files: