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{
45 _nodal_forces = MeshLib::getOrCreateMeshProperty<double>(
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<std::reference_wrapper<NumLib::LocalToGlobalIndexMap>>
187 dof_table = {std::ref(*_local_to_global_index_map)};
188
189 ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
190
191 // Call global assembler for each local assembly item.
193 _global_assembler, &VectorMatrixAssembler::assemble, _local_assemblers,
194 pv.getActiveElementIDs(), dof_table, t, dt, x, x_prev, process_id, M, K,
195 b);
196}
197
198template <int DisplacementDim>
200 DisplacementDim>::preAssembleConcreteProcess(const double t,
201 double const dt,
202 GlobalVector const& x)
203{
204 DBUG("preAssemble SmallDeformationNonlocalProcess.");
205
206 const int process_id = 0;
207 ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
208
209 // Call global assembler for each local assembly item.
211 _global_assembler, &VectorMatrixAssembler::preAssemble,
212 _local_assemblers, pv.getActiveElementIDs(),
213 *_local_to_global_index_map, t, dt, x);
214}
215
216template <int DisplacementDim>
219 const double t, double const dt, std::vector<GlobalVector*> const& x,
220 std::vector<GlobalVector*> const& x_prev, int const process_id,
222{
223 DBUG("AssembleWithJacobian SmallDeformationNonlocalProcess.");
224
225 std::vector<std::reference_wrapper<NumLib::LocalToGlobalIndexMap>>
226 dof_table = {std::ref(*_local_to_global_index_map)};
227
228 ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
229
230 // Call global assembler for each local assembly item.
233 _local_assemblers, pv.getActiveElementIDs(), dof_table, t, dt, x,
234 x_prev, process_id, M, K, b, Jac);
235
236 b.copyValues(*_nodal_forces);
237 std::transform(_nodal_forces->begin(), _nodal_forces->end(),
238 _nodal_forces->begin(), [](double val) { return -val; });
239}
240
241template <int DisplacementDim>
243 postTimestepConcreteProcess(std::vector<GlobalVector*> const& x,
244 std::vector<GlobalVector*> const& x_prev,
245 double const t,
246 double const dt,
247 int const process_id)
248{
249 DBUG("PostTimestep SmallDeformationNonlocalProcess.");
250 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_tables;
251 dof_tables.reserve(x.size());
252 std::generate_n(std::back_inserter(dof_tables), x.size(),
253 [&]() { return _local_to_global_index_map.get(); });
254
255 ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
257 &LocalAssemblerInterface::postTimestep, _local_assemblers,
258 pv.getActiveElementIDs(), dof_tables, x, x_prev, t, dt, process_id);
259}
260
261template <int DisplacementDim>
264 GlobalVector const& x)
265{
266 _process_data.crack_volume_old = _process_data.crack_volume;
267 _process_data.crack_volume = 0.0;
268
269 DBUG("PostNonLinearSolver crack volume computation.");
270
271 const int process_id = 0;
272 ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
273
275 &LocalAssemblerInterface::computeCrackIntegral, _local_assemblers,
276 pv.getActiveElementIDs(), *_local_to_global_index_map, x,
277 _process_data.crack_volume);
278
279 INFO("Integral of crack: {:g}", _process_data.crack_volume);
280
282}
283
286
287} // namespace SmallDeformationNonlocal
288} // 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
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::size_t > const & getActiveElementIDs() const
std::vector< std::unique_ptr< MeshLib::IntegrationPointWriter > > _integration_point_writer
Definition Process.h:377
SecondaryVariableCollection _secondary_variables
Definition Process.h:359
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
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 assembleWithJacobianConcreteProcess(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, GlobalMatrix &Jac) override
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< std::reference_wrapper< NumLib::LocalToGlobalIndexMap > > const &dof_tables, 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, GlobalMatrix &Jac)
void assemble(std::size_t const mesh_item_id, LocalAssemblerInterface &local_assembler, std::vector< std::reference_wrapper< NumLib::LocalToGlobalIndexMap > > 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)
IterationResult
Status flags telling the NonlinearSolver if an iteration succeeded.
Eigen::Matrix< double, kelvin_vector_dimensions(DisplacementDim), 1, Eigen::ColMajor > KelvinVectorType
@ 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)