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
87bdce18
Commit
87bdce18
authored
15 years ago
by
Samuel Melchior
Browse files
Options
Downloads
Patches
Plain Diff
dgMainSam
parent
9bf05e39
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
Solver/dgMainSam.cpp
+110
-0
110 additions, 0 deletions
Solver/dgMainSam.cpp
with
110 additions
and
0 deletions
Solver/dgMainSam.cpp
0 → 100644
+
110
−
0
View file @
87bdce18
#include
<stdio.h>
#include
<vector>
#include
"GModel.h"
#include
"dgGroupOfElements.h"
#include
"dgAlgorithm.h"
#include
"dgConservationLaw.h"
#include
"Gmsh.h"
#include
"function.h"
#include
"MElement.h"
void
print
(
const
char
*
filename
,
const
dgGroupOfElements
&
els
,
double
*
v
);
class
dgConservationLawInitialCondition
:
public
dgConservationLaw
{
class
gaussian
:
public
dataCacheDouble
{
dataCacheDouble
&
xyz
;
double
_xc
;
public:
gaussian
(
dataCacheMap
&
cacheMap
,
double
xc
)
:
xyz
(
cacheMap
.
get
(
"XYZ"
,
this
)),
_xc
(
xc
){};
void
_eval
()
{
if
(
_value
.
size1
()
!=
xyz
().
size1
())
_value
=
fullMatrix
<
double
>
(
xyz
().
size1
(),
1
);
for
(
int
i
=
0
;
i
<
_value
.
size1
();
i
++
)
{
_value
(
i
,
0
)
=
exp
(
-
pow
(
xyz
(
i
,
0
)
-
_xc
,
2
)
*
100
);
//1.0-xyz(i,0);//
}
}
};
public
:
dgConservationLawInitialCondition
()
{
_nbf
=
1
;
}
dataCacheDouble
*
newSourceTerm
(
dataCacheMap
&
cacheMap
)
const
{
return
new
gaussian
(
cacheMap
,
-
0.8
);
}
};
int
main
(
int
argc
,
char
**
argv
){
GmshMergeFile
(
"input/edge.msh"
);
//we probably need a class to group those three ones
std
::
vector
<
dgGroupOfElements
*>
elementGroups
;
std
::
vector
<
dgGroupOfFaces
*>
faceGroups
;
std
::
vector
<
dgGroupOfFaces
*>
boundaryGroups
;
int
order
=
1
;
int
dimension
=
1
;
dgAlgorithm
algo
;
function
::
registerDefaultFunctions
();
algo
.
buildGroups
(
GModel
::
current
(),
dimension
,
order
,
elementGroups
,
faceGroups
,
boundaryGroups
);
//for now, we suppose there is only one group of elements
int
nbNodes
=
elementGroups
[
0
]
->
getNbNodes
();
fullMatrix
<
double
>
sol
(
nbNodes
,
elementGroups
[
0
]
->
getNbElements
());
fullMatrix
<
double
>
residu
(
nbNodes
,
elementGroups
[
0
]
->
getNbElements
());
// initial condition
{
dgConservationLawInitialCondition
initLaw
;
algo
.
residualVolume
(
initLaw
,
*
elementGroups
[
0
],
sol
,
residu
);
algo
.
multAddInverseMassMatrix
(
*
elementGroups
[
0
],
residu
,
sol
);
}
fullMatrix
<
double
>
advectionSpeed
(
3
,
1
);
advectionSpeed
(
0
,
0
)
=
1.0
;
advectionSpeed
(
1
,
0
)
=
0
;
advectionSpeed
(
2
,
0
)
=
0.
;
function
::
add
(
"advectionSpeed"
,
function
::
newFunctionConstant
(
advectionSpeed
));
dgConservationLaw
*
law
=
dgNewConservationLawAdvection
(
"advectionSpeed"
);
fullMatrix
<
double
>
outsideValue
(
1
,
1
);
outsideValue
(
0
,
0
)
=
0
;
function
::
add
(
"outsideValue"
,
function
::
newFunctionConstant
(
outsideValue
));
law
->
addBoundaryCondition
(
"Left"
,
dgBoundaryCondition
::
newOutsideValueCondition
(
*
law
,
"outsideValue"
));
law
->
addBoundaryCondition
(
"Right"
,
dgBoundaryCondition
::
newOutsideValueCondition
(
*
law
,
"outsideValue"
));
print
(
"output/init.pos"
,
*
elementGroups
[
0
],
&
sol
(
0
,
0
));
int
n_visu
=
10
;
for
(
int
iT
=
0
;
iT
<
100
*
n_visu
;
iT
++
)
{
algo
.
rungeKutta
(
*
law
,
elementGroups
,
faceGroups
,
boundaryGroups
,
0.002
,
residu
,
sol
);
if
(
iT
%
n_visu
==
0
){
char
name
[
100
];
sprintf
(
name
,
"output/test_%05i.pos"
,
iT
/
n_visu
);
printf
(
"%i
\n
"
,
iT
);
print
(
name
,
*
elementGroups
[
0
],
&
sol
(
0
,
0
));
}
}
delete
law
;
}
void
print
(
const
char
*
filename
,
const
dgGroupOfElements
&
els
,
double
*
v
)
{
FILE
*
file
=
fopen
(
filename
,
"w"
);
fprintf
(
file
,
"View
\"
%s
\"
{
\n
"
,
filename
);
for
(
int
iel
=
0
;
iel
<
els
.
getNbElements
();
iel
++
){
MElement
*
el
=
els
.
getElement
(
iel
);
fprintf
(
file
,
"SL ("
);
for
(
int
iv
=
0
;
iv
<
el
->
getNumVertices
();
iv
++
)
{
MVertex
*
vertex
=
el
->
getVertex
(
iv
);
SPoint3
coord
=
vertex
->
point
();
fprintf
(
file
,
"%e, %e, %e%c "
,
coord
.
x
(),
coord
.
y
(),
coord
.
z
(),
iv
==
el
->
getNumVertices
()
-
1
?
')'
:
','
);
}
fprintf
(
file
,
"{"
);
for
(
int
iv
=
0
;
iv
<
el
->
getNumVertices
();
iv
++
)
fprintf
(
file
,
"%e%c "
,
*
(
v
++
),
iv
==
el
->
getNumVertices
()
-
1
?
'}'
:
','
);
fprintf
(
file
,
";
\n
"
);
}
fprintf
(
file
,
"};"
);
fclose
(
file
);
}
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