NimbleSM
NimbleSM is a solid mechanics simulation code for dynamic systems
Loading...
Searching...
No Matches
nimble_contact_interface.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 SRC_NIMBLE_CONTACT_INTERFACE_H_
45#define SRC_NIMBLE_CONTACT_INTERFACE_H_
46
47#include <iostream>
48
49#include "nimble_defs.h"
50
51#ifdef NIMBLE_HAVE_KOKKOS
53#endif
54
55namespace nimble {
56
57#ifdef NIMBLE_HAVE_KOKKOS
58
59struct KokkosPenaltyContactEnforcement
60{
61 KokkosPenaltyContactEnforcement() : penalty(0.0) {}
62
63 ~KokkosPenaltyContactEnforcement() = default;
64
65 KOKKOS_FORCEINLINE_FUNCTION
66 void
67 EnforceContact(
68 ContactEntity& node,
69 ContactEntity& face,
70 int numNodeFaces,
71 const double gap,
72 const double direction[3],
73 const double closest_pt[3]) const
74 {
75 if (gap < 0.0) {
76 double contact_force[3]{};
77 const double scale = penalty * gap / numNodeFaces;
78 for (int i = 0; i < 3; ++i) { contact_force[i] = scale * direction[i]; }
79 face.ComputeNodalContactForces(contact_force, closest_pt);
80 for (double& ff : contact_force) { ff *= -1.0; }
81 node.ComputeNodalContactForces(contact_force, closest_pt);
82 node.ScatterForceToContactManagerForceVector(contact_manager_force);
83 face.ScatterForceToContactManagerForceVector(contact_manager_force);
84 }
85 }
86
87 double penalty;
88 nimble_kokkos::DeviceScalarNodeView contact_manager_force;
89};
90
91#endif
92
94{
95 public:
96 ContactInterface() = default;
97 virtual ~ContactInterface() = default;
98
99 void
100 SetUpPenaltyEnforcement(const double penalty_param)
101 {
102#ifdef NIMBLE_HAVE_KOKKOS
103 enforcement.penalty = penalty_param;
104#endif
105 }
106
107#ifdef NIMBLE_HAVE_KOKKOS
108 /// \brief Set the contact force manager to a specific Kokkos::View
109 void
110 SetContactForce(nimble_kokkos::DeviceScalarNodeView contact_manager_force)
111 {
112 enforcement.contact_manager_force = contact_manager_force;
113 }
114
115 void
116 ComputeContact(
119 nimble_kokkos::DeviceScalarNodeView contact_manager_force)
120 {
121 ZeroContactForces(contact_manager_force);
122 enforcement.contact_manager_force = contact_manager_force;
123 DoSearchAndEnforcement(contact_nodes, contact_faces, enforcement);
124 }
125
126 protected:
127 inline void
128 ZeroContactForces(nimble_kokkos::DeviceScalarNodeView contact_manager_force) const
129 {
130 Kokkos::deep_copy(contact_manager_force, 0.0);
131 }
132
133 virtual void
134 DoSearchAndEnforcement(
137 KokkosPenaltyContactEnforcement contact_enforcement)
138 {
139 std::cerr << "Warning: running no-op contact---no interface enabled!" << std::endl;
140 }
141
142 KOKKOS_FORCEINLINE_FUNCTION
143 void
144 EnforceNodeFaceInteraction(
145 ContactEntity& node,
146 ContactEntity& face,
147 int numNodeFaces,
148 const double gap,
149 const double direction[3],
150 const double closest_pt[3]) const
151 {
152 if (gap < 0.0) { enforcement.EnforceContact(node, face, numNodeFaces, gap, direction, closest_pt); }
153 }
154
155 protected:
156 KokkosPenaltyContactEnforcement enforcement;
157
158#endif
159};
160
161} // namespace nimble
162
163#endif /* SRC_NIMBLE_CONTACT_INTERFACE_H_ */
void SetUpPenaltyEnforcement(const double penalty_param)
Definition nimble_contact_interface.h:100
virtual ~ContactInterface()=default
Kokkos::View< nimble::ContactEntity *, nimble_kokkos::kokkos_layout, nimble_kokkos::kokkos_device > DeviceContactEntityArrayView
Definition nimble_kokkos_contact_defs.h:15
Field< FieldType::DeviceScalarNode >::View DeviceScalarNodeView
Definition nimble_kokkos_defs.h:582
Definition kokkos_contact_manager.h:49