Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lammps
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
multiscale
lammps
Commits
85c13294
Commit
85c13294
authored
8 years ago
by
Richard Berger
Browse files
Options
Downloads
Patches
Plain Diff
Use factory for integrate style creation
parent
55260ad5
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/info.cpp
+5
-4
5 additions, 4 deletions
src/info.cpp
src/update.cpp
+36
-34
36 additions, 34 deletions
src/update.cpp
src/update.h
+7
-0
7 additions, 0 deletions
src/update.h
with
48 additions
and
38 deletions
src/info.cpp
+
5
−
4
View file @
85c13294
...
@@ -582,10 +582,11 @@ void Info::integrate_styles(FILE * out)
...
@@ -582,10 +582,11 @@ void Info::integrate_styles(FILE * out)
fprintf
(
out
,
"
\n
Integrate styles:
\n
"
);
fprintf
(
out
,
"
\n
Integrate styles:
\n
"
);
vector
<
string
>
styles
;
vector
<
string
>
styles
;
#define INTEGRATE_CLASS
#define IntegrateStyle(key,Class) styles.push_back(#key);
for
(
Update
::
IntegrateCreatorMap
::
iterator
it
=
update
->
integrate_map
->
begin
();
it
!=
update
->
integrate_map
->
end
();
++
it
)
{
#include
"style_integrate.h"
styles
.
push_back
(
it
->
first
);
#undef INTEGRATE_CLASS
}
print_columns
(
out
,
styles
);
print_columns
(
out
,
styles
);
fprintf
(
out
,
"
\n\n\n
"
);
fprintf
(
out
,
"
\n\n\n
"
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/update.cpp
+
36
−
34
View file @
85c13294
...
@@ -61,6 +61,15 @@ Update::Update(LAMMPS *lmp) : Pointers(lmp)
...
@@ -61,6 +61,15 @@ Update::Update(LAMMPS *lmp) : Pointers(lmp)
minimize_style
=
NULL
;
minimize_style
=
NULL
;
minimize
=
NULL
;
minimize
=
NULL
;
integrate_map
=
new
IntegrateCreatorMap
();
#define INTEGRATE_CLASS
#define IntegrateStyle(key,Class) \
(*integrate_map)[#key] = &integrate_creator<Class>;
#include
"style_integrate.h"
#undef IntegrateStyle
#undef INTEGRATE_CLASS
str
=
(
char
*
)
"verlet"
;
str
=
(
char
*
)
"verlet"
;
create_integrate
(
1
,
&
str
,
1
);
create_integrate
(
1
,
&
str
,
1
);
...
@@ -79,6 +88,8 @@ Update::~Update()
...
@@ -79,6 +88,8 @@ Update::~Update()
delete
[]
minimize_style
;
delete
[]
minimize_style
;
delete
minimize
;
delete
minimize
;
delete
integrate_map
;
}
}
/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
...
@@ -319,52 +330,43 @@ void Update::new_integrate(char *style, int narg, char **arg,
...
@@ -319,52 +330,43 @@ void Update::new_integrate(char *style, int narg, char **arg,
sflag
=
1
;
sflag
=
1
;
char
estyle
[
256
];
char
estyle
[
256
];
sprintf
(
estyle
,
"%s/%s"
,
style
,
lmp
->
suffix
);
sprintf
(
estyle
,
"%s/%s"
,
style
,
lmp
->
suffix
);
int
success
=
1
;
if
(
integrate_map
->
find
(
estyle
)
!=
integrate_map
->
end
())
{
IntegrateCreator
integrate_creator
=
(
*
integrate_map
)[
estyle
];
if
(
0
)
return
;
integrate
=
integrate_creator
(
lmp
,
narg
,
arg
);
return
;
#define INTEGRATE_CLASS
}
#define IntegrateStyle(key,Class) \
else if (strcmp(estyle,#key) == 0) integrate = new Class(lmp,narg,arg);
#include
"style_integrate.h"
#undef IntegrateStyle
#undef INTEGRATE_CLASS
else
success
=
0
;
if
(
success
)
return
;
}
}
if
(
lmp
->
suffix2
)
{
if
(
lmp
->
suffix2
)
{
sflag
=
2
;
sflag
=
2
;
char
estyle
[
256
];
char
estyle
[
256
];
sprintf
(
estyle
,
"%s/%s"
,
style
,
lmp
->
suffix2
);
sprintf
(
estyle
,
"%s/%s"
,
style
,
lmp
->
suffix2
);
int
success
=
1
;
if
(
integrate_map
->
find
(
estyle
)
!=
integrate_map
->
end
())
{
IntegrateCreator
integrate_creator
=
(
*
integrate_map
)[
estyle
];
if
(
0
)
return
;
integrate
=
integrate_creator
(
lmp
,
narg
,
arg
);
return
;
#define INTEGRATE_CLASS
}
#define IntegrateStyle(key,Class) \
else if (strcmp(estyle,#key) == 0) integrate = new Class(lmp,narg,arg);
#include
"style_integrate.h"
#undef IntegrateStyle
#undef INTEGRATE_CLASS
else
success
=
0
;
if
(
success
)
return
;
}
}
}
}
sflag
=
0
;
sflag
=
0
;
if
(
0
)
return
;
if
(
integrate_map
->
find
(
style
)
!=
integrate_map
->
end
())
{
IntegrateCreator
integrate_creator
=
(
*
integrate_map
)[
style
];
integrate
=
integrate_creator
(
lmp
,
narg
,
arg
);
return
;
}
#define INTEGRATE_CLASS
error
->
all
(
FLERR
,
"Illegal integrate style"
);
#define IntegrateStyle(key,Class) \
}
else if (strcmp(style,#key) == 0) integrate = new Class(lmp,narg,arg);
#include
"style_integrate.h"
#undef IntegrateStyle
#undef INTEGRATE_CLASS
else
error
->
all
(
FLERR
,
"Illegal integrate style"
);
/* ----------------------------------------------------------------------
one instance per integrate style in style_integrate.h
------------------------------------------------------------------------- */
template
<
typename
T
>
Integrate
*
Update
::
integrate_creator
(
LAMMPS
*
lmp
,
int
narg
,
char
**
arg
)
{
return
new
T
(
lmp
,
narg
,
arg
);
}
}
/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
...
...
This diff is collapsed.
Click to expand it.
src/update.h
+
7
−
0
View file @
85c13294
...
@@ -15,6 +15,8 @@
...
@@ -15,6 +15,8 @@
#define LMP_UPDATE_H
#define LMP_UPDATE_H
#include
"pointers.h"
#include
"pointers.h"
#include
<map>
#include
<string>
namespace
LAMMPS_NS
{
namespace
LAMMPS_NS
{
...
@@ -46,6 +48,10 @@ class Update : protected Pointers {
...
@@ -46,6 +48,10 @@ class Update : protected Pointers {
class
Min
*
minimize
;
class
Min
*
minimize
;
char
*
minimize_style
;
char
*
minimize_style
;
typedef
Integrate
*
(
*
IntegrateCreator
)(
LAMMPS
*
,
int
,
char
**
);
typedef
std
::
map
<
std
::
string
,
IntegrateCreator
>
IntegrateCreatorMap
;
IntegrateCreatorMap
*
integrate_map
;
Update
(
class
LAMMPS
*
);
Update
(
class
LAMMPS
*
);
~
Update
();
~
Update
();
void
init
();
void
init
();
...
@@ -60,6 +66,7 @@ class Update : protected Pointers {
...
@@ -60,6 +66,7 @@ class Update : protected Pointers {
private:
private:
void
new_integrate
(
char
*
,
int
,
char
**
,
int
,
int
&
);
void
new_integrate
(
char
*
,
int
,
char
**
,
int
,
int
&
);
template
<
typename
T
>
static
Integrate
*
integrate_creator
(
LAMMPS
*
,
int
,
char
**
);
};
};
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment