NimbleSM
NimbleSM is a solid mechanics simulation code for dynamic systems
Loading...
Searching...
No Matches
nimble_boundary_condition_manager.h
Go to the documentation of this file.
1/*
2//@HEADER
3// ************************************************************************
4//
5// NimbleSM
6// Copyright 2018
7// National Technology & Engineering Solutions of Sandia, LLC (NTESS)
8//
9// Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government
10// retains certain rights in this software.
11//
12// Redistribution and use in source and binary forms, with or without
13// modification, are permitted provided that the following conditions are
14// met:
15//
16// 1. Redistributions of source code must retain the above copyright
17// notice, this list of conditions and the following disclaimer.
18//
19// 2. Redistributions in binary form must reproduce the above copyright
20// notice, this list of conditions and the following disclaimer in the
21// documentation and/or other materials provided with the distribution.
22//
23// 3. Neither the name of the Corporation nor the names of the
24// contributors may be used to endorse or promote products derived from
25// this software without specific prior written permission.
26//
27// THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY EXPRESS OR IMPLIED
28// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
29// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
30// NO EVENT SHALL NTESS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
32// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact David Littlewood (djlittl@sandia.gov)
39//
40// ************************************************************************
41//@HEADER
42*/
43
44#ifndef NIMBLE_BOUNDARY_CONDITION_MANAGER_H
45#define NIMBLE_BOUNDARY_CONDITION_MANAGER_H
46
48#include "nimble_view.h"
49
50#ifdef NIMBLE_HAVE_DARMA
51#include "darma.h"
52#else
53#include <map>
54#include <vector>
55#endif
56
57namespace nimble {
58
60{
61 public:
68
70
71 void
73 std::map<int, std::string> const& node_set_names,
74 std::map<int, std::vector<int>> const& node_sets,
75 std::map<int, std::string> const& side_set_names,
76 std::map<int, std::vector<int>> const& side_sets,
77 std::vector<std::string> const& bc_strings,
78 int dim,
79 std::string time_integration_scheme);
80
81 virtual ~BoundaryConditionManager() = default;
82
83#ifdef NIMBLE_HAVE_DARMA
84 template <typename ArchiveType>
85 void
86 serialize(ArchiveType& ar)
87 {
88 ar | node_set_names_ | node_sets_ | side_set_names_ | side_sets_ | boundary_conditions_ | dim_ |
89 time_integration_scheme_;
90 }
91#endif
92
93 template <typename ViewT>
94 void
95 ApplyInitialConditions(const ViewT reference_coordinates, ViewT velocity, std::vector<ViewT>& offnom_velocities)
96 {
97 for (auto& bc : boundary_conditions_) {
98 if (bc.bc_type_ == BoundaryCondition::INITIAL_VELOCITY) {
99 int node_set_id = bc.node_set_id_;
100 int coordinate = bc.coordinate_;
101 bool has_expression = bc.has_expression_;
102 std::vector<int> const& node_set = node_sets_[node_set_id];
103 if (!has_expression) {
104 double magnitude = bc.magnitude_;
105 for (int n : node_set) {
106 velocity(n, coordinate) = magnitude;
107 for (int nuq = 0; nuq < offnom_velocities.size(); nuq++) {
108 offnom_velocities[nuq](n, coordinate) = magnitude;
109 }
110 }
111 } else {
112 for (int n : node_set) {
113 bc.expression_.x = reference_coordinates(n, 0);
114 bc.expression_.y = reference_coordinates(n, 1);
115 bc.expression_.z = 0.0;
116 if (dim_ == 3) { bc.expression_.z = reference_coordinates(n, 2); }
117 bc.expression_.t = 0.0;
118 velocity(n, coordinate) = bc.expression_.eval();
119 for (int nuq = 0; nuq < offnom_velocities.size(); nuq++) {
120 offnom_velocities[nuq](n, coordinate) = bc.expression_.eval();
121 }
122 }
123 }
124 }
125 }
126 }
127
128 template <typename ViewT>
129 void
130 ApplyInitialConditions(const ViewT reference_coordinates, ViewT velocity)
131 {
132 std::vector<ViewT> empty;
133 ApplyInitialConditions<ViewT>(reference_coordinates, velocity, empty);
134 }
135
136 template <typename ViewT>
137 void
139 double time_current,
140 double time_previous,
141 const ViewT reference_coordinates,
142 ViewT displacement,
143 ViewT velocity,
144 std::vector<ViewT>& offnom_velocities)
145 {
146 double delta_t = time_current - time_previous;
147
148 for (auto& bc : boundary_conditions_) {
149 int node_set_id = bc.node_set_id_;
150 int coordinate = bc.coordinate_;
151 bool has_expression = bc.has_expression_;
152 std::vector<int> const& node_set = node_sets_[node_set_id];
153
154 if (bc.bc_type_ == BoundaryCondition::PRESCRIBED_VELOCITY) {
155 if (!has_expression) {
156 double velocity_magnitude = bc.magnitude_;
157 for (int n : node_set) {
158 velocity(n, coordinate) = velocity_magnitude;
159 for (int nuq = 0; nuq < offnom_velocities.size(); nuq++) {
160 offnom_velocities[nuq](n, coordinate) = velocity_magnitude;
161 }
162 if (time_integration_scheme_ == QUASISTATIC) {
163 displacement(n, coordinate) += velocity_magnitude * delta_t;
164 }
165 }
166 } else {
167 for (int n : node_set) {
168 bc.expression_.x = reference_coordinates(n, 0);
169 bc.expression_.y = reference_coordinates(n, 1);
170 bc.expression_.z = 0.0;
171 if (dim_ == 3) { bc.expression_.z = reference_coordinates(n, 2); }
172 bc.expression_.t = time_current;
173 double velocity_magnitude = bc.expression_.eval();
174 velocity(n, coordinate) = velocity_magnitude;
175 for (int nuq = 0; nuq < offnom_velocities.size(); nuq++) {
176 offnom_velocities[nuq](n, coordinate) = velocity_magnitude;
177 }
178 if (time_integration_scheme_ == QUASISTATIC) {
179 displacement(n, coordinate) += velocity_magnitude * delta_t;
180 }
181 }
182 }
183 } else if (bc.bc_type_ == BoundaryCondition::PRESCRIBED_DISPLACEMENT && delta_t > 0.0) {
184 if (!has_expression) {
185 double displacement_magnitude = bc.magnitude_;
186 for (int n : node_set) {
187 velocity(n, coordinate) = (displacement_magnitude - displacement(n, coordinate)) / delta_t;
188 if (time_integration_scheme_ == QUASISTATIC) { displacement(n, coordinate) = displacement_magnitude; }
189 }
190 } else {
191 for (int n : node_set) {
192 bc.expression_.x = reference_coordinates(n, 0);
193 bc.expression_.y = reference_coordinates(n, 1);
194 bc.expression_.z = 0.0;
195 if (dim_ == 3) { bc.expression_.z = reference_coordinates(n, 2); }
196 bc.expression_.t = time_current;
197 double displacement_magnitude = bc.expression_.eval();
198 velocity(n, coordinate) = (displacement_magnitude - displacement(n, coordinate)) / delta_t;
199 if (time_integration_scheme_ == QUASISTATIC) { displacement(n, coordinate) = displacement_magnitude; }
200 }
201 }
202 }
203 }
204 }
205
206 template <typename ViewT>
207 void
209 double time_current,
210 double time_previous,
211 const ViewT reference_coordinates,
212 ViewT displacement,
213 ViewT velocity)
214 {
215 std::vector<ViewT> empty;
216 ApplyKinematicBC(time_current, time_previous, reference_coordinates, displacement, velocity, empty);
217 }
218
219 template <typename MatT>
220 void
222 int num_unknowns,
223 const int* global_node_ids,
224 double diagonal_entry,
225 MatT& tangent_stiffness) const;
226
227 void
228 ModifyRHSForKinematicBC(const int* global_node_ids, double* rhs) const;
229
230 template <typename ViewT>
231 void
232 ApplyTractionBC(double time_current, const ViewT reference_coordinates, ViewT internal_force)
233 {
234 for (auto& bc : boundary_conditions_) {
235 int side_set_id = bc.side_set_id_;
236 int coordinate = bc.coordinate_;
237 bool has_expression = bc.has_expression_;
238 std::vector<int> const& side_set = side_sets_[side_set_id];
239 if (bc.bc_type_ == BoundaryCondition::PRESCRIBED_TRACTION) {
240 if (has_expression == true) {
241 for (int ss : side_set) {}
242 } else {
243 for (int ss : side_set) {}
244 }
245 }
246 }
247 }
248
249 private:
250 std::map<int, std::string> node_set_names_;
251 std::map<int, std::vector<int>> node_sets_;
252 std::map<int, std::string> side_set_names_;
253 std::map<int, std::vector<int>> side_sets_;
254 std::vector<BoundaryCondition> boundary_conditions_;
255 int dim_{0};
256 Time_Integration_Scheme time_integration_scheme_{UNDEFINED};
257};
258
259} // namespace nimble
260
261#endif // NIMBLE_BOUNDARY_CONDITION_MANAGER_H
@ PRESCRIBED_VELOCITY
Definition nimble_boundary_condition.h:66
@ PRESCRIBED_DISPLACEMENT
Definition nimble_boundary_condition.h:67
@ PRESCRIBED_TRACTION
Definition nimble_boundary_condition.h:68
@ INITIAL_VELOCITY
Definition nimble_boundary_condition.h:65
BoundaryConditionManager()
Definition nimble_boundary_condition_manager.h:69
void ModifyRHSForKinematicBC(const int *global_node_ids, double *rhs) const
Definition nimble_boundary_condition_manager.cc:121
void Initialize(std::map< int, std::string > const &node_set_names, std::map< int, std::vector< int > > const &node_sets, std::map< int, std::string > const &side_set_names, std::map< int, std::vector< int > > const &side_sets, std::vector< std::string > const &bc_strings, int dim, std::string time_integration_scheme)
Definition nimble_boundary_condition_manager.cc:51
void ApplyKinematicBC(double time_current, double time_previous, const ViewT reference_coordinates, ViewT displacement, ViewT velocity)
Definition nimble_boundary_condition_manager.h:208
void ApplyKinematicBC(double time_current, double time_previous, const ViewT reference_coordinates, ViewT displacement, ViewT velocity, std::vector< ViewT > &offnom_velocities)
Definition nimble_boundary_condition_manager.h:138
void ApplyInitialConditions(const ViewT reference_coordinates, ViewT velocity)
Definition nimble_boundary_condition_manager.h:130
Time_Integration_Scheme
Definition nimble_boundary_condition_manager.h:63
@ UNDEFINED
Definition nimble_boundary_condition_manager.h:66
@ EXPLICIT
Definition nimble_boundary_condition_manager.h:64
@ QUASISTATIC
Definition nimble_boundary_condition_manager.h:65
void ApplyInitialConditions(const ViewT reference_coordinates, ViewT velocity, std::vector< ViewT > &offnom_velocities)
Definition nimble_boundary_condition_manager.h:95
void ApplyTractionBC(double time_current, const ViewT reference_coordinates, ViewT internal_force)
Definition nimble_boundary_condition_manager.h:232
virtual ~BoundaryConditionManager()=default
void ModifyTangentStiffnessMatrixForKinematicBC(int num_unknowns, const int *global_node_ids, double diagonal_entry, MatT &tangent_stiffness) const
Definition nimble_boundary_condition_manager.cc:81
Definition kokkos_contact_manager.h:49