File: contact_models.cpp

package info (click to toggle)
liggghts 3.8.0%2Brepack1-14
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,368 kB
  • sloc: cpp: 151,203; javascript: 9,132; sh: 858; python: 676; makefile: 456; ansic: 411
file content (297 lines) | stat: -rw-r--r-- 9,812 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/* ----------------------------------------------------------------------
    This is the

    ██╗     ██╗ ██████╗  ██████╗  ██████╗ ██╗  ██╗████████╗███████╗
    ██║     ██║██╔════╝ ██╔════╝ ██╔════╝ ██║  ██║╚══██╔══╝██╔════╝
    ██║     ██║██║  ███╗██║  ███╗██║  ███╗███████║   ██║   ███████╗
    ██║     ██║██║   ██║██║   ██║██║   ██║██╔══██║   ██║   ╚════██║
    ███████╗██║╚██████╔╝╚██████╔╝╚██████╔╝██║  ██║   ██║   ███████║
    ╚══════╝╚═╝ ╚═════╝  ╚═════╝  ╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚══════╝®

    DEM simulation engine, released by
    DCS Computing Gmbh, Linz, Austria
    http://www.dcs-computing.com, office@dcs-computing.com

    LIGGGHTS® is part of CFDEM®project:
    http://www.liggghts.com | http://www.cfdem.com

    Core developer and main author:
    Christoph Kloss, christoph.kloss@dcs-computing.com

    LIGGGHTS® is open-source, distributed under the terms of the GNU Public
    License, version 2 or later. It is distributed in the hope that it will
    be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
    of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. You should have
    received a copy of the GNU General Public License along with LIGGGHTS®.
    If not, see http://www.gnu.org/licenses . See also top-level README
    and LICENSE files.

    LIGGGHTS® and CFDEM® are registered trade marks of DCS Computing GmbH,
    the producer of the LIGGGHTS® software and the CFDEM®coupling software
    See http://www.cfdem.com/terms-trademark-policy for details.

-------------------------------------------------------------------------
    Contributing author and copyright for this file:

    Christoph Kloss (DCS Computing GmbH, Linz)
    Christoph Kloss (JKU Linz)
    Richard Berger (JKU Linz)
    Arno Mayrhofer (CFDEMresearch GmbH, Linz)

    Copyright 2012-     DCS Computing GmbH, Linz
    Copyright 2009-2012 JKU Linz
    Copyright 2016-     CFDEMresearch GmbH, Linz
------------------------------------------------------------------------- */

#include <mpi.h>
#include "ctype.h"
#include "float.h"
#include "limits.h"
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pair.h"
#include "atom.h"
#include "neighbor.h"
#include "neigh_list.h"
#include "domain.h"
#include "comm.h"
#include "force.h"
#include "kspace.h"
#include "update.h"
#include "accelerator_cuda.h"
#include "suffix.h"
#include "atom_masks.h"
#include "memory.h"
#include "error.h"
#include "utils.h"

#include <string>
#include <iostream>
#include "contact_models.h"

namespace LIGGGHTS {
namespace ContactModels {

Factory::Factory() {
  // register contact model string to contact mappings
  #define SURFACE_MODEL(identifier,str,constant) \
  addSurfaceModel(#str, identifier);
  #include "style_surface_model.h"
  #undef SURFACE_MODEL

  addNormalModel("off", NORMAL_OFF);
  #define NORMAL_MODEL(identifier,str,constant) \
  addNormalModel(#str, identifier);
  #include "style_normal_model.h"
  #undef NORMAL_MODEL

  addTangentialModel("off", TANGENTIAL_OFF);
  #define TANGENTIAL_MODEL(identifier,str,constant) \
  addTangentialModel(#str, identifier);
  #include "style_tangential_model.h"
  #undef TANGENTIAL_MODEL

  addCohesionModel("off", COHESION_OFF);
  #define COHESION_MODEL(identifier,str,constant) \
  addCohesionModel(#str, identifier);
  #include "style_cohesion_model.h"
  #undef COHESION_MODEL

  addRollingModel("off", ROLLING_OFF);
  #define ROLLING_MODEL(identifier,str,constant) \
  addRollingModel(#str, identifier);
  #include "style_rolling_model.h"
  #undef ROLLING_MODEL
}

Factory & Factory::instance() {
    static Factory _instance;
    return _instance;
}

void Factory::addNormalModel(const std::string & name, int identifier) {
  normal_models[name] = identifier;
}

void Factory::addTangentialModel(const std::string & name, int identifier){
  tangential_models[name] = identifier;
}

void Factory::addCohesionModel(const std::string & name, int identifier) {
  cohesion_models[name] = identifier;
}

void Factory::addRollingModel(const std::string & name, int identifier) {
  rolling_models[name] = identifier;
}

void Factory::addSurfaceModel(const std::string & name, int identifier) {
  surface_models[name] = identifier;
}

int Factory::getNormalModelId(const std::string & name) {
  return normal_models[name];
}

int Factory::getTangentialModelId(const std::string & name) {
  return tangential_models[name];
}

int Factory::getCohesionModelId(const std::string & name) {
  return cohesion_models[name];
}

int Factory::getRollingModelId(const std::string & name) {
  return rolling_models[name];
}

int Factory::getSurfaceModelId(const std::string & name) {
  return surface_models[name];
}

int64_t Factory::select(int & narg, char ** & args,Custom_contact_models ccm) {
  return instance().select_model(narg, args,ccm);
}

int64_t Factory::select_model(int & narg, char ** & args, Custom_contact_models ccm)
{
    // this method will consume arguments to determine which granular contact model is active

    // default configuration
    int model = NORMAL_OFF;
    int tangential = TANGENTIAL_OFF;
    int cohesion = COHESION_OFF;
    int rolling = ROLLING_OFF;
    int surface = SURFACE_DEFAULT;

    // select normal model
    if (narg > 1 && strcmp(args[0], "model") == 0)
    {
        if (normal_models.find(args[1]) != normal_models.end())
            model = normal_models[args[1]];
        else if (0 == strcmp(args[1],"custom"))
        {
            if (normal_models.find(ccm.custom_normal_model) != normal_models.end())
               model = normal_models[ccm.custom_normal_model];
            else
               model = -1;
        }
        else
            model = -1;

        if(narg > 2)
            args = &args[2];
        narg -= 2;
    }

    // OPTIONAL: select tangential model
    if (narg > 1 && strcmp(args[0], "tangential") == 0)
    {
        if (tangential_models.find(args[1]) != tangential_models.end())
            tangential = tangential_models[args[1]];
        else if (0 == strcmp(args[1],"custom"))
        {
            if (tangential_models.find(ccm.custom_tangential_model) != tangential_models.end())
               tangential = tangential_models[ccm.custom_tangential_model];
            else
               tangential = -1;
        }
        else
            tangential = -1;

        if(narg > 2)
            args = &args[2];
        narg -= 2;
    }

    // OPTIONAL: select cohesion model
    if (narg > 1 && strcmp(args[0], "cohesion") == 0)
    {
        if (cohesion_models.find(args[1]) != cohesion_models.end())
            cohesion = cohesion_models[args[1]];
        else if (0 == strcmp(args[1],"custom"))
        {
            if (cohesion_models.find(ccm.custom_cohesion_model) != cohesion_models.end())
               cohesion = cohesion_models[ccm.custom_cohesion_model];
            else
               cohesion = -1;
        }
        else
            cohesion = -1;

        if(narg > 2)
            args = &args[2];
        narg -= 2;
    }

    // OPTIONAL: select rolling model
    if (narg > 1 && strcmp(args[0], "rolling_friction") == 0)
    {
        if (rolling_models.find(args[1]) != rolling_models.end())
            rolling = rolling_models[args[1]];
        else if (0 == strcmp(args[1],"custom"))
        {
            if (rolling_models.find(ccm.custom_rolling_model) != rolling_models.end())
               rolling = rolling_models[ccm.custom_rolling_model];
            else
               rolling = -1;
        }
        else
          rolling = -1;

        if(narg > 2)
            args = &args[2];
        narg -= 2;
    }

    // OPTIONAL: select surface model
    if (narg > 1 && strcmp(args[0], "surface") == 0)
    {
        if (surface_models.find(args[1]) != surface_models.end())
            surface = surface_models[args[1]];
        else if (0 == strcmp(args[1],"custom"))
        {
            if (surface_models.find(ccm.custom_surface_model) != surface_models.end())
               surface = surface_models[ccm.custom_surface_model];
            else
               surface = -1;
        }
        else
          surface = -1;

        if(narg > 2)
            args = &args[2];
        narg -= 2;
    }

    if((model != -1 && tangential != -1 && cohesion != -1 && rolling != -1 && surface != -1) &&
       !(model == NORMAL_OFF && tangential == TANGENTIAL_OFF && cohesion == COHESION_OFF && rolling == ROLLING_OFF))
        return Utils::generate_gran_hashcode(model, tangential, cohesion, rolling, surface);
    return -1;
}

int ContactModelBase::get_history_offset(const string hname)
{
    std::map<std::string, int>::iterator it = history_offsets.find(hname);
    if (it != history_offsets.end())
        return it->second;
    return -1;
}

void ContactModelBase::add_history_offset(const string hname, const int offset, const bool overwrite)
{
    std::map<std::string, int>::iterator it = history_offsets.find(hname);
    if (it == history_offsets.end() || overwrite)
    {
        
        history_offsets[hname] = offset;
    }
    else
       error->one(FLERR, "Could not add history offset as key exists already and overwrite is not set");
    return;
}

} // ContactModels
} // LIGGGHTS