OGS
SmallDeformationNonlocalProcess.cpp
Go to the documentation of this file.
1
12
13#include <iostream>
14
18
19// Reusing local assembler creation code.
21
22namespace ProcessLib
23{
24namespace SmallDeformationNonlocal
25{
26template <int DisplacementDim>
29 std::string name,
30 MeshLib::Mesh& mesh,
31 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&&
32 jacobian_assembler,
33 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const&
34 parameters,
35 unsigned const integration_order,
36 std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>&&
37 process_variables,
39 SecondaryVariableCollection&& secondary_variables)
40 : Process(std::move(name), mesh, std::move(jacobian_assembler), parameters,
41 integration_order, std::move(process_variables),
42 std::move(secondary_variables)),
43 _process_data(std::move(process_data))
44{
46 mesh, "NodalForces", MeshLib::MeshItemType::Node, DisplacementDim);
47
48 _integration_point_writer.emplace_back(
49 std::make_unique<MeshLib::IntegrationPointWriter>(
50 "sigma_ip",
51 static_cast<int>(mesh.getDimension() == 2 ? 4 : 6) /*n components*/,
52 integration_order, _local_assemblers,
54
55 _integration_point_writer.emplace_back(
56 std::make_unique<MeshLib::IntegrationPointWriter>(
57 "kappa_d_ip", 1 /*n_components*/, integration_order,
59}
60
61template <int DisplacementDim>
66
67template <int DisplacementDim>
70 MeshLib::Mesh const& mesh,
71 unsigned const integration_order)
72{
73 // Reusing local assembler creation code.
76 mesh.getElements(), dof_table, _local_assemblers,
77 NumLib::IntegrationOrder{integration_order}, mesh.isAxiallySymmetric(),
78 _process_data);
79
80 // TODO move the two data members somewhere else.
81 // for extrapolation of secondary variables
82 std::vector<MeshLib::MeshSubset> all_mesh_subsets_single_component{
83 *_mesh_subset_all_nodes};
84 _local_to_global_index_map_single_component =
85 std::make_unique<NumLib::LocalToGlobalIndexMap>(
86 std::move(all_mesh_subsets_single_component),
87 // by location order is needed for output
89
91 "sigma",
93 DisplacementDim>::RowsAtCompileTime,
94 getExtrapolator(), _local_assemblers,
95 &LocalAssemblerInterface::getIntPtSigma));
96
98 "epsilon",
100 DisplacementDim>::RowsAtCompileTime,
101 getExtrapolator(), _local_assemblers,
102 &LocalAssemblerInterface::getIntPtEpsilon));
103
105 "eps_p_V",
106 makeExtrapolator(1, getExtrapolator(), _local_assemblers,
107 &LocalAssemblerInterface::getIntPtEpsPV));
109 "eps_p_D_xx",
110 makeExtrapolator(1, getExtrapolator(), _local_assemblers,
111 &LocalAssemblerInterface::getIntPtEpsPDXX));
112
114 "damage",
115 makeExtrapolator(1, getExtrapolator(), _local_assemblers,
116 &LocalAssemblerInterface::getIntPtDamage));
117
119 &LocalAssemblerInterface::nonlocal, _local_assemblers,
120 _local_assemblers);
121
122 setIPDataInitialConditions(_integration_point_writer, mesh.getProperties(),
123 _local_assemblers);
124
125 // Set initial conditions for integration point from cell mesh properties.
126 for (auto const& ip_writer : _integration_point_writer)
127 {
128 auto const& name = ip_writer->name();
129 if (mesh.getProperties().existsPropertyVector<double>(name + "_ic"))
130 { // Try to find cell data with '_ic' suffix
131 auto const& mesh_property =
132 *mesh.getProperties().template getPropertyVector<double>(name +
133 "_ic");
134 if (mesh_property.getMeshItemType() != MeshLib::MeshItemType::Cell)
135 {
136 continue;
137 }
138
139 // Disallow setting ip-data from both, the e.g. sigma_ip and
140 // sigma_ip_ic fields simultaneously.
141 if (mesh.getProperties().existsPropertyVector<double>(
143 mesh_property.getNumberOfGlobalComponents()))
144 {
145 OGS_FATAL(
146 "Both, the field-data ({:s}) and cell-data ({:s}) "
147 "properties are available in the mesh for integration "
148 "point initialization, but only one can be used.",
149 name, name + "_ic");
150 }
151 // Now we have a vtk's cell data array containing the initial
152 // conditions for the corresponding integration point writer.
153
154 // For each assembler use the single cell value for all
155 // integration points.
156 for (std::size_t i = 0; i < _local_assemblers.size(); ++i)
157 {
158 auto& local_asm = _local_assemblers[i];
159
160 std::vector<double> value(
161 &mesh_property[i],
162 &mesh_property[i] +
163 mesh_property.getNumberOfGlobalComponents());
164 // TODO (naumov) Check sizes / read size / etc.
165 // OR reconstruct dimensions from size / component =
166 // ip_points
167 local_asm->setIPDataInitialConditionsFromCellData(name, value);
168 }
169 }
170 }
171
172 // Initialize local assemblers after all variables have been set.
174 &LocalAssemblerInterface::initialize, _local_assemblers,
175 *_local_to_global_index_map);
176}
177
178template <int DisplacementDim>
180 const double t, double const dt, std::vector<GlobalVector*> const& x,
181 std::vector<GlobalVector*> const& x_prev, int const process_id,
183{
184 DBUG("Assemble SmallDeformationNonlocalProcess.");
185
186 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_table = {
187 _local_to_global_index_map.get()};
188
189 // Call global assembler for each local assembly item.
191 _global_assembler, &VectorMatrixAssembler::assemble, _local_assemblers,
192 getActiveElementIDs(), dof_table, t, dt, x, x_prev, process_id, &M, &K,
193 &b);
194}
195
196template <int DisplacementDim>
198 DisplacementDim>::preAssembleConcreteProcess(const double t,
199 double const dt,
200 GlobalVector const& x)
201{
202 DBUG("preAssemble SmallDeformationNonlocalProcess.");
203
204 // Call global assembler for each local assembly item.
206 _global_assembler, &VectorMatrixAssembler::preAssemble,
207 _local_assemblers, getActiveElementIDs(), *_local_to_global_index_map,
208 t, dt, x);
209}
210
211template <int DisplacementDim>
214 const double t, double const dt, std::vector<GlobalVector*> const& x,
215 std::vector<GlobalVector*> const& x_prev, int const process_id,
216 GlobalVector& b, GlobalMatrix& Jac)
217{
218 DBUG("AssembleWithJacobian SmallDeformationNonlocalProcess.");
219
220 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_table = {
221 _local_to_global_index_map.get()};
222
223 // Call global assembler for each local assembly item.
226 _local_assemblers, getActiveElementIDs(), dof_table, t, dt, x, x_prev,
227 process_id, &b, &Jac);
228
229 b.copyValues(*_nodal_forces);
230 std::transform(_nodal_forces->begin(), _nodal_forces->end(),
231 _nodal_forces->begin(), [](double val) { return -val; });
232}
233
234template <int DisplacementDim>
236 postTimestepConcreteProcess(std::vector<GlobalVector*> const& x,
237 std::vector<GlobalVector*> const& x_prev,
238 double const t,
239 double const dt,
240 int const process_id)
241{
242 DBUG("PostTimestep SmallDeformationNonlocalProcess.");
243 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_tables;
244 dof_tables.reserve(x.size());
245 std::generate_n(std::back_inserter(dof_tables), x.size(),
246 [&]() { return _local_to_global_index_map.get(); });
247
249 &LocalAssemblerInterface::postTimestep, _local_assemblers,
250 getActiveElementIDs(), dof_tables, x, x_prev, t, dt, process_id);
251}
252
253template <int DisplacementDim>
256 GlobalVector const& x)
257{
258 _process_data.crack_volume_old = _process_data.crack_volume;
259 _process_data.crack_volume = 0.0;
260
261 DBUG("PostNonLinearSolver crack volume computation.");
262
264 &LocalAssemblerInterface::computeCrackIntegral, _local_assemblers,
265 getActiveElementIDs(), *_local_to_global_index_map, x,
266 _process_data.crack_volume);
267
268 INFO("Integral of crack: {:g}", _process_data.crack_volume);
269
271}
272
275
276} // namespace SmallDeformationNonlocal
277} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:26
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
Global vector based on Eigen vector.
Definition EigenVector.h:25
void copyValues(std::vector< double > &u) const
bool isAxiallySymmetric() const
Definition Mesh.h:137
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:109
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition Mesh.h:88
Properties & getProperties()
Definition Mesh.h:134
bool existsPropertyVector(std::string_view name) const
Definition Properties.h:74
virtual void postTimestep(std::size_t const mesh_item_id, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, double const t, double const dt, int const process_id)
virtual void initialize(std::size_t const mesh_item_id, NumLib::LocalToGlobalIndexMap const &dof_table)
std::vector< std::unique_ptr< MeshLib::IntegrationPointWriter > > _integration_point_writer
Definition Process.h:390
SecondaryVariableCollection _secondary_variables
Definition Process.h:370
Handles configuration of several secondary variables from the project file.
void addSecondaryVariable(std::string const &internal_name, SecondaryVariableFunctions &&fcts)
SmallDeformationNonlocalProcess(std::string name, MeshLib::Mesh &mesh, std::unique_ptr< ProcessLib::AbstractJacobianAssembler > &&jacobian_assembler, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, unsigned const integration_order, std::vector< std::vector< std::reference_wrapper< ProcessVariable > > > &&process_variables, SmallDeformationNonlocalProcessData< DisplacementDim > &&process_data, SecondaryVariableCollection &&secondary_variables)
void postTimestepConcreteProcess(std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, double const t, double const dt, int const process_id) override
void assembleWithJacobianConcreteProcess(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalVector &b, GlobalMatrix &Jac) override
std::vector< std::unique_ptr< LocalAssemblerInterface > > _local_assemblers
void assembleConcreteProcess(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b) override
void initializeConcreteProcess(NumLib::LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh, unsigned const integration_order) override
Process specific initialization called by initialize().
NumLib::IterationResult postIterationConcreteProcess(GlobalVector const &x) override
void assemble(std::size_t const mesh_item_id, LocalAssemblerInterface &local_assembler, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, double const t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalMatrix *M, GlobalMatrix *K, GlobalVector *b)
void preAssemble(const std::size_t mesh_item_id, LocalAssemblerInterface &local_assembler, const NumLib::LocalToGlobalIndexMap &dof_table, const double t, double const dt, const GlobalVector &x)
void assembleWithJacobian(std::size_t const mesh_item_id, LocalAssemblerInterface &local_assembler, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalVector *b, GlobalMatrix *Jac)
IterationResult
Status flags telling the NonlinearSolver if an iteration succeeded.
Eigen::Matrix< double, kelvin_vector_dimensions(DisplacementDim), 1, Eigen::ColMajor > KelvinVectorType
PropertyVector< T > * getOrCreateMeshProperty(Mesh &mesh, std::string const &property_name, MeshItemType const item_type, int const number_of_components)
@ BY_LOCATION
Ordering data by spatial location.
void createLocalAssemblers(std::vector< MeshLib::Element * > const &mesh_elements, NumLib::LocalToGlobalIndexMap const &dof_table, std::vector< std::unique_ptr< LocalAssemblerInterface > > &local_assemblers, ProviderOrOrder const &provider_or_order, ExtraCtorArgs &&... extra_ctor_args)
SecondaryVariableFunctions makeExtrapolator(const unsigned num_components, NumLib::Extrapolator &extrapolator, LocalAssemblerCollection const &local_assemblers, typename NumLib::ExtrapolatableLocalAssemblerCollection< LocalAssemblerCollection >::IntegrationPointValuesMethod integration_point_values_method)
void setIPDataInitialConditions(std::vector< std::unique_ptr< MeshLib::IntegrationPointWriter > > const &_integration_point_writer, MeshLib::Properties const &mesh_properties, LocalAssemblersVector &local_assemblers)
static void executeSelectedMemberOnDereferenced(Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)
static void executeSelectedMemberDereferenced(Object &object, Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)
static void executeMemberOnDereferenced(Method method, Container const &container, Args &&... args)