1 /* ----------------------------------------------------------------------
2 This is the
3
4 ██╗ ██╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗████████╗███████╗
5 ██║ ██║██╔════╝ ██╔════╝ ██╔════╝ ██║ ██║╚══██╔══╝██╔════╝
6 ██║ ██║██║ ███╗██║ ███╗██║ ███╗███████║ ██║ ███████╗
7 ██║ ██║██║ ██║██║ ██║██║ ██║██╔══██║ ██║ ╚════██║
8 ███████╗██║╚██████╔╝╚██████╔╝╚██████╔╝██║ ██║ ██║ ███████║
9 ╚══════╝╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝®
10
11 DEM simulation engine, released by
12 DCS Computing Gmbh, Linz, Austria
13 http://www.dcs-computing.com, office@dcs-computing.com
14
15 LIGGGHTS® is part of CFDEM®project:
16 http://www.liggghts.com | http://www.cfdem.com
17
18 Core developer and main author:
19 Christoph Kloss, christoph.kloss@dcs-computing.com
20
21 LIGGGHTS® is open-source, distributed under the terms of the GNU Public
22 License, version 2 or later. It is distributed in the hope that it will
23 be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
24 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. You should have
25 received a copy of the GNU General Public License along with LIGGGHTS®.
26 If not, see http://www.gnu.org/licenses . See also top-level README
27 and LICENSE files.
28
29 LIGGGHTS® and CFDEM® are registered trade marks of DCS Computing GmbH,
30 the producer of the LIGGGHTS® software and the CFDEM®coupling software
31 See http://www.cfdem.com/terms-trademark-policy for details.
32
33 -------------------------------------------------------------------------
34 Contributing author and copyright for this file:
35 (if not contributing author is listed, this file has been contributed
36 by the core developer)
37
38 Copyright 2012- DCS Computing GmbH, Linz
39 Copyright 2009-2012 JKU Linz
40 ------------------------------------------------------------------------- */
41
42 #include <mpi.h>
43 #include <string.h>
44 #include "library_cfd_coupling.h"
45 #include "lammps.h"
46 #include "input.h"
47 #include "atom.h"
48 #include "update.h"
49 #include "domain.h"
50 #include "modify.h"
51 #include "fix_cfd_coupling.h"
52 #include "fix_multisphere.h"
53 #include "cfd_regionmodel.h"
54 #include "memory.h"
55 #include "error.h"
56 #include "comm.h"
57 #include "cfd_datacoupling.h"
58
59 using namespace LAMMPS_NS;
60
61 #define LMP_GROW_DELTA 11000
62
63 /* ---------------------------------------------------------------------- */
64
liggghts_get_maxtag(void * ptr)65 int liggghts_get_maxtag(void *ptr)
66 {
67 LAMMPS *lmp = (LAMMPS *) ptr;
68 return lmp->atom->tag_max();
69 }
70
71 /* ---------------------------------------------------------------------- */
72
liggghts_get_maxtag_ms(void * ptr)73 int liggghts_get_maxtag_ms(void *ptr)
74 {
75 // currently no possibility to delete multisphere bodies
76 // so just return # of bodies
77
78 LAMMPS *lmp = (LAMMPS *) ptr;
79 FixMultisphere *fix_ms = static_cast<FixMultisphere*>(lmp->modify->find_fix_style("multisphere",0));
80 if(!fix_ms) return 0;
81 return fix_ms->tag_max_body();
82 }
83
84 /* ---------------------------------------------------------------------- */
85
liggghts_get_ntypes_ms(void * ptr)86 int liggghts_get_ntypes_ms(void *ptr)
87 {
88 // currently no possibility to delete multisphere bodies
89 // so just return # of bodies
90
91 LAMMPS *lmp = (LAMMPS *) ptr;
92 FixMultisphere *fix_ms = static_cast<FixMultisphere*>(lmp->modify->find_fix_style("multisphere",0));
93 if(!fix_ms) return 0;
94 return fix_ms->ntypes();
95 }
96
97 /* ---------------------------------------------------------------------- */
98
liggghts_get_vclump_ms(void * ptr)99 double* liggghts_get_vclump_ms(void *ptr)
100 {
101 // currently no possibility to delete multisphere bodies
102 // so just return # of bodies
103
104 LAMMPS *lmp = (LAMMPS *) ptr;
105 FixMultisphere *fix_ms = static_cast<FixMultisphere*>(lmp->modify->find_fix_style("multisphere",0));
106 if(!fix_ms) return 0;
107 return fix_ms->vclump();
108 }
109
110 /* ---------------------------------------------------------------------- */
111
locate_coupling_fix(void * ptr)112 void* locate_coupling_fix(void *ptr)
113 {
114 LAMMPS *lmp = (LAMMPS *) ptr;
115 int ifix = -1;
116 for(int i=0;i<lmp->modify->nfix;i++)
117 if(strcmp(lmp->modify->fix[i]->style,"couple/cfd") == 0)
118 ifix = i;
119
120 if(ifix ==-1) lmp->error->all(FLERR,"No fix of style 'couple/cfd' found, aborting.");
121
122 return ((void*)lmp->modify->fix[ifix]);
123 }
124
125 /* ---------------------------------------------------------------------- */
126
data_liggghts_to_of(const char * name,const char * type,void * ptr,void * & data,const char * datatype)127 void data_liggghts_to_of(const char *name,const char *type,void *ptr,void *&data,const char* datatype)
128 {
129 //LAMMPS *lmp = (LAMMPS *) ptr;
130 FixCfdCoupling* fcfd = (FixCfdCoupling*)locate_coupling_fix(ptr);
131 fcfd->get_dc()->push(name,type,data,datatype);
132 }
133
134 /* ---------------------------------------------------------------------- */
135
data_of_to_liggghts(const char * name,const char * type,void * ptr,void * data,const char * datatype)136 void data_of_to_liggghts(const char *name,const char *type,void *ptr,void *data,const char* datatype)
137 {
138 //LAMMPS *lmp = (LAMMPS *) ptr;
139 FixCfdCoupling* fcfd = (FixCfdCoupling*)locate_coupling_fix(ptr);
140 fcfd->get_dc()->pull(name,type,data,datatype);
141 }
142
143 /* ---------------------------------------------------------------------- */
144
update_rm(void * ptr)145 void update_rm(void *ptr)
146 {
147 LAMMPS *lmp = (LAMMPS *) ptr;
148 //FixCfdCoupling* fcfd = (FixCfdCoupling*)locate_coupling_fix(ptr);
149 locate_coupling_fix(ptr);
150 //CfdRegionmodel *rm = fcfd->rm;
151
152 //if(rm) rm->rm_update();
153 lmp->error->all(FLERR,"Region model update not implemented aborting.");
154 }
155
156 /* ---------------------------------------------------------------------- */
157
allocate_external_int(int ** & data,int len2,int len1,int initvalue,void * ptr)158 void allocate_external_int(int **&data, int len2,int len1,int initvalue,void *ptr)
159 {
160 //LAMMPS *lmp = (LAMMPS *) ptr;
161 FixCfdCoupling* fcfd = (FixCfdCoupling*)locate_coupling_fix(ptr);
162 fcfd->get_dc()->allocate_external(data,len2,len1,initvalue);
163 }
164 /* ---------------------------------------------------------------------- */
165
allocate_external_int(int ** & data,int len2,const char * keyword,int initvalue,void * ptr)166 void allocate_external_int(int **&data, int len2,const char *keyword,int initvalue,void *ptr)
167 {
168 //LAMMPS *lmp = (LAMMPS *) ptr;
169 FixCfdCoupling* fcfd = (FixCfdCoupling*)locate_coupling_fix(ptr);
170 fcfd->get_dc()->allocate_external(data,len2,keyword,initvalue);
171 }
172
173 /* ---------------------------------------------------------------------- */
174
allocate_external_double(double ** & data,int len2,int len1,double initvalue,void * ptr)175 void allocate_external_double(double **&data, int len2,int len1,double initvalue,void *ptr)
176 {
177 //LAMMPS *lmp = (LAMMPS *) ptr;
178 FixCfdCoupling* fcfd = (FixCfdCoupling*)locate_coupling_fix(ptr);
179 fcfd->get_dc()->allocate_external(data,len2,len1,initvalue);
180 }
181
182 /* ---------------------------------------------------------------------- */
183
allocate_external_double(double ** & data,int len2,const char * keyword,double initvalue,void * ptr)184 void allocate_external_double(double **&data, int len2,const char* keyword,double initvalue,void *ptr)
185 {
186 //LAMMPS *lmp = (LAMMPS *) ptr;
187 FixCfdCoupling* fcfd = (FixCfdCoupling*)locate_coupling_fix(ptr);
188 fcfd->get_dc()->allocate_external(data,len2,keyword,initvalue);
189 }
190
191 /* ---------------------------------------------------------------------- */
192
check_datatransfer(void * ptr)193 void check_datatransfer(void *ptr)
194 {
195 //LAMMPS *lmp = (LAMMPS *) ptr;
196 FixCfdCoupling* fcfd = (FixCfdCoupling*)locate_coupling_fix(ptr);
197 fcfd->get_dc()->check_datatransfer();
198 }
199