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
e002034a
Commit
e002034a
authored
8 years ago
by
Patrick Dular
Browse files
Options
Downloads
Patches
Plain Diff
Examples of functions Exists(.) and GetForced(.)
parent
5b370c88
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
demos/struct/Exists_GetForced.geo
+55
-0
55 additions, 0 deletions
demos/struct/Exists_GetForced.geo
with
55 additions
and
0 deletions
demos/struct/Exists_GetForced.geo
0 → 100644
+
55
−
0
View file @
e002034a
//
// Functions: Exists(.) and GetForced(.)
// (for both Gmsh and GetDP)
//
val_real
=
12
;
list_of_real
()
=
{
11
,
22
,
33
};
Struct
namespace
::
struct_name
[
Dim
2
,
Ref
5
];
// See file struct.geo for Struct definitions
// Look at the Current Workspace for checking the variables contents.
//
// Function Exists(name_variable):
// returns 1 if variable 'name_variable' exists, 0 if not
If
(
Exists
(
val_real
))
Printf
(
"Variable 'val_real' exists"
);
EndIf
If
(
!
Exists
(
other_val_real
))
Printf
(
"Variable 'other_val_real' does not exist"
);
EndIf
If
(
Exists
(
list_of_real
))
Printf
(
"List 'list_of_real()' exists"
);
EndIf
If
(
Exists
(
namespace
::
struct_name
.
Dim
))
Printf
(
"Member 'Dim' of structure 'namespace::struct_name' exists"
);
EndIf
If
(
!
Exists
(
namespace
::
struct_name
.
Thickness
))
Printf
(
"Member 'Thickness' of structure 'namespace::struct_name' does not exist"
);
Struct
namespace
::
struct_name
(
Append
)
[
Thickness
0.01
];
// This member is added to the structure
If
(
Exists
(
namespace
::
struct_name
.
Thickness
))
Printf
(
"Member 'Thickness' of structure 'namespace::struct_name' now exists"
);
EndIf
EndIf
//
// GetForced(name_variable, default_value):
// returns value of 'name_variable' if it exists, default_value if not
// GetForced(name_variable):
// returns value of 'name_variable' if it exists, 0 (zero) if not
get_forced_val_real
=
GetForced
(
val_real
,
1
);
// Will be 12, the value of the existing variable
get_forced_other_val_real_with_defined_default_value
=
GetForced
(
other_val_real
,
1
);
// Will be 1 (defined default value) because variable does not exist
get_forced_other_val_real_with_zero_default_value
=
GetForced
(
other_val_real
);
// Will be 0 (default value) because variable does not exist
get_forced_struct_member_with_default
=
GetForced
(
namespace
::
struct_name
.
InexistingMember
,
-
1
);
// Will be the defined default value -1
//
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