Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gmsh
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
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Larry Price
gmsh
Commits
e5af9cce
Commit
e5af9cce
authored
13 years ago
by
Christophe Geuzaine
Browse files
Options
Downloads
Patches
Plain Diff
update
parent
61e28f1f
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
utils/solvers/c++/GmshSocket.h
+8
-6
8 additions, 6 deletions
utils/solvers/c++/GmshSocket.h
utils/solvers/c++/onelab.h
+50
-11
50 additions, 11 deletions
utils/solvers/c++/onelab.h
utils/solvers/c++/solver.cpp
+9
-7
9 additions, 7 deletions
utils/solvers/c++/solver.cpp
with
67 additions
and
24 deletions
utils/solvers/c++/GmshSocket.h
+
8
−
6
View file @
e5af9cce
...
...
@@ -21,7 +21,7 @@
// WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
// ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
// OF THIS SOFTWARE.
//
//
// Please report all bugs and problems to <gmsh@geuz.org>.
#ifndef _GMSH_SOCKET_H_
...
...
@@ -61,7 +61,7 @@ class GmshSocket{
// that 65535: if we receive a type > 65535 we assume that we
// receive data from a machine with a different byte ordering, and
// we swap the bytes in the payload)
enum
MessageType
{
enum
MessageType
{
GMSH_START
=
1
,
GMSH_STOP
=
2
,
GMSH_INFO
=
10
,
...
...
@@ -73,6 +73,8 @@ class GmshSocket{
GMSH_VERTEX_ARRAY
=
22
,
GMSH_PARAMETER
=
23
,
GMSH_PARAMETER_QUERY
=
24
,
GMSH_PARAM_QUERY_ALL
=
25
,
GMSH_PARAM_QUERY_END
=
26
,
GMSH_SPEED_TEST
=
30
,
GMSH_OPTION_1
=
100
,
GMSH_OPTION_2
=
101
,
...
...
@@ -91,7 +93,7 @@ class GmshSocket{
int
sofar
=
0
;
int
remaining
=
bytes
;
do
{
int
len
=
send
(
_sock
,
buf
+
sofar
,
remaining
,
0
);
int
len
=
send
(
_sock
,
buf
+
sofar
,
remaining
,
0
);
sofar
+=
len
;
remaining
-=
len
;
}
while
(
remaining
>
0
);
...
...
@@ -193,7 +195,7 @@ class GmshSocket{
*
swap
=
0
;
if
(
_ReceiveData
(
type
,
sizeof
(
int
))){
if
(
*
type
<
0
)
return
0
;
if
(
*
type
>
65535
){
if
(
*
type
>
65535
){
// the data comes from a machine with different endianness and
// we must swap the bytes
*
swap
=
1
;
...
...
@@ -403,7 +405,7 @@ class GmshServer : public GmshSocket{
CloseSocket
(
tmpsock
);
throw
"Socket listen failed"
;
}
// wait until we get data
int
ret
=
NonBlockingWait
(
tmpsock
,
0.5
,
timeout
);
if
(
ret
){
...
...
@@ -445,6 +447,6 @@ class GmshServer : public GmshSocket{
CloseSocket
(
_sock
);
return
0
;
}
};
};
#endif
This diff is collapsed.
Click to expand it.
utils/solvers/c++/onelab.h
+
50
−
11
View file @
e5af9cce
...
...
@@ -91,6 +91,19 @@ namespace onelab{
const
std
::
string
&
getName
()
const
{
return
_name
;
}
const
std
::
string
&
getShortHelp
()
const
{
return
_shortHelp
;
}
const
std
::
string
&
getHelp
()
const
{
return
_help
;
}
std
::
string
getShortName
()
const
{
if
(
_shortHelp
.
size
())
return
_shortHelp
;
std
::
string
s
=
_name
;
// remove path
std
::
string
::
size_type
last
=
_name
.
find_last_of
(
'/'
);
if
(
last
!=
std
::
string
::
npos
)
s
=
_name
.
substr
(
last
+
1
);
// remove starting numbers
while
(
s
.
size
()
&&
s
[
0
]
>=
'0'
&&
s
[
0
]
<=
'9'
)
s
=
s
.
substr
(
1
);
return
s
;
}
bool
getChanged
()
const
{
return
_changed
;
}
bool
getVisible
()
const
{
return
_visible
;
}
std
::
string
getAttribute
(
const
std
::
string
&
key
)
const
...
...
@@ -110,6 +123,7 @@ namespace onelab{
static
std
::
string
getNextToken
(
const
std
::
string
&
msg
,
std
::
string
::
size_type
&
first
)
{
if
(
first
==
std
::
string
::
npos
)
return
""
;
std
::
string
::
size_type
last
=
msg
.
find_first_of
(
charSep
(),
first
);
std
::
string
next
=
msg
.
substr
(
first
,
last
-
first
);
first
=
(
last
==
std
::
string
::
npos
)
?
last
:
last
+
1
;
...
...
@@ -311,15 +325,18 @@ namespace onelab{
// regions will include union, intersection, etc.
class
region
:
public
parameter
{
private:
std
::
string
_value
;
// TODO: change this into std::set<std::string>
std
::
vector
<
std
::
string
>
_choices
;
std
::
set
<
std
::
string
>
_value
;
std
::
vector
<
std
::
set
<
std
::
string
>
>
_choices
;
// optional geometrical dimension
int
_dimension
;
public:
region
(
const
std
::
string
&
name
=
""
,
const
std
::
string
&
value
=
""
,
region
(
const
std
::
string
&
name
=
""
,
const
std
::
set
<
std
::
string
>
&
value
=
std
::
set
<
std
::
string
>
(),
const
std
::
string
&
shortHelp
=
""
,
const
std
::
string
&
help
=
""
)
:
parameter
(
name
,
shortHelp
,
help
),
_value
(
value
)
{}
void
setValue
(
const
std
::
string
&
value
){
_value
=
value
;
}
void
setValue
(
const
std
::
set
<
std
::
string
>
&
value
){
_value
=
value
;
}
std
::
string
getType
()
const
{
return
"region"
;
}
const
std
::
string
&
getValue
()
const
{
return
_value
;
}
const
std
::
set
<
std
::
string
>
&
getValue
()
const
{
return
_value
;
}
void
update
(
const
region
&
p
)
{
addClients
(
p
.
getClients
());
...
...
@@ -333,12 +350,15 @@ namespace onelab{
}
std
::
string
toChar
()
const
{
/*
std::ostringstream sstream;
sstream << parameter::toChar() << _value << charSep()
<< _choices.size() << charSep();
for(unsigned int i = 0; i < _choices.size(); i++)
sstream << sanitize(_choices[i]) << charSep();
return sstream.str();
*/
return
""
;
}
};
...
...
@@ -493,6 +513,10 @@ namespace onelab{
const
std
::
string
&
client
=
""
){
return
_get
(
ps
,
name
,
client
,
_regions
);
}
bool
get
(
std
::
vector
<
function
>
&
ps
,
const
std
::
string
&
name
=
""
,
const
std
::
string
&
client
=
""
){
return
_get
(
ps
,
name
,
client
,
_functions
);
}
unsigned
int
getNumParameters
()
{
return
_numbers
.
size
()
+
_strings
.
size
()
+
_regions
.
size
()
+
_functions
.
size
();
}
// check if at least one parameter depends on the given client
bool
hasClient
(
const
std
::
string
&
client
)
const
{
...
...
@@ -556,7 +580,7 @@ namespace onelab{
int
getId
(){
return
_id
;
}
void
setIndex
(
int
index
){
_index
=
index
;
}
int
getIndex
(){
return
_index
;
}
virtual
bool
run
(
const
std
::
string
&
what
){
return
false
;
}
virtual
bool
run
(){
return
false
;
}
virtual
bool
isNetworkClient
(){
return
false
;
}
virtual
bool
kill
(){
return
false
;
}
virtual
void
sendInfo
(
const
std
::
string
&
msg
){
std
::
cout
<<
msg
<<
std
::
endl
;
}
...
...
@@ -580,7 +604,7 @@ namespace onelab{
// and interacts with onelab clients.
class
server
{
private:
// the unique server
// the unique server
(singleton behaviour due to the "static" specifier)
static
server
*
_server
;
// the address of the server
std
::
string
_address
;
...
...
@@ -609,6 +633,7 @@ namespace onelab{
typedef
std
::
map
<
std
::
string
,
client
*>::
iterator
citer
;
citer
firstClient
(){
return
_clients
.
begin
();
}
citer
lastClient
(){
return
_clients
.
end
();
}
int
getNumClients
()
{
return
_clients
.
size
();
};
citer
findClient
(
const
std
::
string
&
name
){
return
_clients
.
find
(
name
);
}
void
registerClient
(
client
*
c
)
{
...
...
@@ -627,7 +652,8 @@ namespace onelab{
std
::
string
toChar
(
const
std
::
string
&
client
=
""
)
{
return
_parameterSpace
.
toChar
(
client
);
}
}
unsigned
int
getNumParameters
(){
return
_parameterSpace
.
getNumParameters
();
}
};
class
localClient
:
public
client
{
...
...
@@ -687,7 +713,7 @@ namespace onelab{
void
setPid
(
int
pid
){
_pid
=
pid
;
}
GmshServer
*
getGmshServer
(){
return
_gmshServer
;
}
void
setGmshServer
(
GmshServer
*
server
){
_gmshServer
=
server
;
}
virtual
bool
run
(
const
std
::
string
&
what
);
virtual
bool
run
();
virtual
bool
kill
();
};
...
...
@@ -711,7 +737,11 @@ namespace onelab{
if
(
!
_gmshClient
)
return
false
;
T
p
(
name
);
std
::
string
msg
=
p
.
toChar
();
_gmshClient
->
SendMessage
(
GmshSocket
::
GMSH_PARAMETER_QUERY
,
msg
.
size
(),
&
msg
[
0
]);
if
(
name
.
size
())
_gmshClient
->
SendMessage
(
GmshSocket
::
GMSH_PARAMETER_QUERY
,
msg
.
size
(),
&
msg
[
0
]);
else
//get all parameters
_gmshClient
->
SendMessage
(
GmshSocket
::
GMSH_PARAM_QUERY_ALL
,
msg
.
size
(),
&
msg
[
0
]);
while
(
1
){
// stop if we have no communications for 10 secs
int
ret
=
_gmshClient
->
Select
(
10
,
0
);
...
...
@@ -739,8 +769,17 @@ namespace onelab{
ps
.
push_back
(
p
);
return
true
;
}
if
(
type
==
GmshSocket
::
GMSH_PARAM_QUERY_ALL
){
T
p
;
p
.
fromChar
(
msg
);
ps
.
push_back
(
p
);
// do NOT return until all parameters have been downloaded
}
else
if
(
type
==
GmshSocket
::
GMSH_PARAM_QUERY_END
){
return
true
;
}
else
if
(
type
==
GmshSocket
::
GMSH_INFO
){
// parameter not found
// parameter not found
or all aparameters have been sent
return
true
;
}
else
{
...
...
This diff is collapsed.
Click to expand it.
utils/solvers/c++/solver.cpp
+
9
−
7
View file @
e5af9cce
...
...
@@ -6,34 +6,36 @@
// 1) Compile this solver: g++ solver.cpp
//
// 2) Add it to Gmsh:
// - launch Gmsh and open Tools->OneLab
// - launch Gmsh and open Tools->OneLab
// - In the gear menu, select "Add new client"
// - Enter "My Solver" as client name, then choose the exe in the dialog
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
onelab
::
remoteNetworkClient
*
client
=
0
;
for
(
int
i
=
0
;
i
<
argc
;
i
++
){
if
(
std
::
string
(
argv
[
i
])
==
"-onelab"
&&
i
<
argc
-
1
)
client
=
new
onelab
::
remoteNetworkClient
(
"My solver"
,
argv
[
i
+
1
]);
if
(
std
::
string
(
argv
[
i
])
==
"-onelab"
&&
i
+
2
<
argc
){
client
=
new
onelab
::
remoteNetworkClient
(
argv
[
i
+
1
],
argv
[
i
+
2
]);
break
;
}
}
if
(
!
client
){
printf
(
"usage: %s -onelab socket
\n
"
,
argv
[
0
]);
printf
(
"usage: %s -onelab
name
socket
\n
"
,
argv
[
0
]);
exit
(
1
);
}
std
::
vector
<
onelab
::
string
>
strings
;
// try to get the string variable "My solver/My string" from the server
client
->
get
(
strings
,
"My
solver/My
string"
);
client
->
get
(
strings
,
"My string"
);
if
(
strings
.
size
()){
std
::
cout
<<
"Got string from server: '"
<<
strings
[
0
].
getValue
()
<<
"'
\n
"
;
}
else
{
// send a value to the server
onelab
::
string
s
(
"My
solver/My
string"
,
"Hello!"
);
onelab
::
string
s
(
"My string"
,
"Hello!"
);
client
->
set
(
s
);
}
...
...
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