Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inmcm_ice_thermodynamics
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
数学の武士
inmcm_ice_thermodynamics
Commits
9ad0552b
Commit
9ad0552b
authored
1 year ago
by
数学の武士
Browse files
Options
Downloads
Patches
Plain Diff
.
parent
03939410
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
CMakeLists.txt
+0
-2
0 additions, 2 deletions
CMakeLists.txt
main.cpp
+46
-28
46 additions, 28 deletions
main.cpp
with
46 additions
and
30 deletions
CMakeLists.txt
+
0
−
2
View file @
9ad0552b
...
...
@@ -11,8 +11,6 @@ if(INCLUDE_CUDA)
endif
(
INCLUDE_CUDA
)
add_subdirectory
(
mesh/
)
# set_property(DIRECTORY mesh/ APPEND PROPERTY COMPILE_DEFINITIONS "-DINCLUDE_CUDA=${INCLUDE_CUDA}")
# target_compile_definitions(mesh PRIVATE INCLUDE_CUDA=${INCLUDE_CUDA})
set
(
SOURCE main.cpp
)
add_executable
(
mesh_test
${
SOURCE
}
)
...
...
This diff is collapsed.
Click to expand it.
main.cpp
+
46
−
28
View file @
9ad0552b
...
...
@@ -10,29 +10,6 @@ using namespace icethermo;
int
main
(
void
)
{
// Mesh<float, MemType::CPU> mesh1(10, 1.0f);
// auto cells_temp = mesh1.CreateCellsData("cells_temperature");
// auto cells_capacity = mesh1.CreateCellsData("cells_capacity", true);
// auto cells_enthalpy = mesh1.CreateCellsData("cells_enthalpy", false);
// auto cells_thickness = mesh1.GetCellsThickness();
// const int n = mesh1.GetCellsNum();
// mesh1.PullCPUArray(*cells_thickness.get(), n);
// for (int i = 0; i < n; i++)
// {
// printf("%f\n", mesh1.SubBuffer[i]);
// }
// mesh1.SaveTXT("./mesh1");
// auto res = std::accumulate(mesh1.SubBuffer, mesh1.SubBuffer + n, float(0));
// printf("accumulate %f\n", res);
// ### examples of Mesh class ###
// constructor with given total thickness (default is 10 cells)
#ifdef INCLUDE_CUDA
Mesh
<
float
,
MemType
::
GPU
>
mesh1
(
1.0
f
);
#else
...
...
@@ -45,11 +22,11 @@ int main(void)
auto
cells_enthalpy
=
mesh1
.
CreateCellsData
(
"cells_enthalpy"
,
false
);
// one can modify cell data
#ifdef INCLUDE_CUDA
float
*
farray
;
size_t
farray_size
=
0
;
memproc
::
realloc
<
MemType
::
CPU
>
((
void
*&
)(
farray
),
farray_size
,
mesh1
.
GetCellsNum
()
*
sizeof
(
float
));
memproc
::
memcopy
<
MemType
::
CPU
,
MemType
::
GPU
>
(
farray
,
(
*
cells_temp
),
farray_size
);
farray
[
0
]
=
1.0
f
;
farray
[
1
]
=
2.0
f
;
farray
[
2
]
=
3.0
f
;
memproc
::
memcopy
<
MemType
::
GPU
,
MemType
::
CPU
>
((
*
cells_temp
),
farray
,
farray_size
);
#else
...
...
@@ -63,6 +40,7 @@ int main(void)
// one can modify nodes data
#ifdef INCLUDE_CUDA
memproc
::
realloc
<
MemType
::
CPU
>
((
void
*&
)(
farray
),
farray_size
,
mesh1
.
GetNodesNum
()
*
sizeof
(
float
));
memproc
::
memcopy
<
MemType
::
CPU
,
MemType
::
GPU
>
(
farray
,
(
*
nodes_k
),
farray_size
);
farray
[
0
]
=
-
5.0
f
;
farray
[
mesh1
.
GetNodesNum
()
-
1
]
=
-
3.0
f
;
memproc
::
memcopy
<
MemType
::
GPU
,
MemType
::
CPU
>
((
*
nodes_k
),
farray
,
farray_size
);
#else
...
...
@@ -89,10 +67,12 @@ int main(void)
#ifdef INCLUDE_CUDA
memproc
::
realloc
<
MemType
::
CPU
>
((
void
*&
)(
farray
),
farray_size
,
mesh1
.
GetCellsNum
()
*
sizeof
(
float
));
memproc
::
memcopy
<
MemType
::
CPU
,
MemType
::
GPU
>
(
farray
,
(
*
another_cells_temp
),
farray_size
);
farray
[
0
]
=
-
5.0
f
;
memproc
::
memcopy
<
MemType
::
GPU
,
MemType
::
CPU
>
((
*
another_cells_temp
),
farray
,
farray_size
);
memproc
::
realloc
<
MemType
::
CPU
>
((
void
*&
)(
farray
),
farray_size
,
mesh1
.
GetNodesNum
()
*
sizeof
(
float
));
memproc
::
memcopy
<
MemType
::
CPU
,
MemType
::
GPU
>
(
farray
,
(
*
another_nodes_k
),
farray_size
);
farray
[
0
]
*=
2.0
f
;
memproc
::
memcopy
<
MemType
::
GPU
,
MemType
::
CPU
>
((
*
another_nodes_k
),
farray
,
farray_size
);
#else
...
...
@@ -101,9 +81,6 @@ int main(void)
(
*
another_temp_ib
)
=
-
30.0
f
;
#endif
// one can get vector with cell thickness
// std::cout << "current cell thickness array: " << (*mesh1.GetCellsThickness()) << std::endl;
// one can get total thickness
std
::
cout
<<
"current total cell thickness: "
<<
mesh1
.
GetTotalThickness
()
<<
std
::
endl
;
...
...
@@ -148,8 +125,49 @@ int main(void)
mesh3
.
SaveTXT
(
"./mesh3"
);
#ifdef INCLUDE_CUDA
memproc
::
dealloc
<
MemType
::
GPU
>
((
void
*&
)(
farray
));
Mesh
<
double
,
MemType
::
GPU
>
mesh_vis
(
15
,
4.0
);
#else
Mesh
<
double
,
MemType
::
CPU
>
mesh_vis
(
15
,
4.0
);
#endif
auto
cells_thick
=
mesh_vis
.
CreateCellsData
(
"cells_temp_array"
);
int
N
=
mesh_vis
.
GetCellsNum
();
#ifdef INCLUDE_CUDA
double
*
darray
;
size_t
darray_size
=
0
;
memproc
::
realloc
<
MemType
::
CPU
>
((
void
*&
)(
darray
),
darray_size
,
N
*
sizeof
(
double
));
memproc
::
memcopy
<
MemType
::
CPU
,
MemType
::
GPU
>
(
darray
,
*
cells_thick
,
N
);
for
(
int
i
=
0
;
i
<
N
;
++
i
)
darray
[
i
]
=
-
5.0
+
i
*
1.0
/
N
*
(
-
5.0
);
memproc
::
memcopy
<
MemType
::
GPU
,
MemType
::
CPU
>
(
*
cells_thick
,
darray
,
N
);
#else
for
(
int
i
=
0
;
i
<
N
;
++
i
)
(
*
cells_thick
)[
i
]
=
-
5.0
+
i
*
1.0
/
N
*
(
-
5.0
);
#endif
mesh_vis
.
SaveTXT
(
"./mesh_vis"
);
// wrong constructor (it should be unit segment partition 0.5 + 0.4 != 1.0)
#ifdef INCLUDE_CUDA
dsegment_partition
[
0
]
=
0.5
;
dsegment_partition
[
1
]
=
0.4
;
memproc
::
realloc
<
MemType
::
GPU
>
((
void
*&
)(
dev_segment_partition
),
dev_segment_partition_size
,
2
*
sizeof
(
double
));
memproc
::
memcopy
<
MemType
::
GPU
,
MemType
::
CPU
>
(
dev_segment_partition
,
dsegment_partition
,
dev_segment_partition_size
);
Mesh
<
double
,
MemType
::
GPU
>
mesh4
(
dev_segment_partition
,
2
,
5.0
);
#else
dsegment_partition
[
0
]
=
0.5
;
dsegment_partition
[
1
]
=
0.4
;
Mesh
<
double
,
MemType
::
CPU
>
mesh4
(
dsegment_partition
,
2
,
5.0
);
#endif
#ifdef INCLUDE_CUDA
memproc
::
dealloc
<
MemType
::
CPU
>
((
void
*&
)(
farray
));
memproc
::
dealloc
<
MemType
::
GPU
>
((
void
*&
)(
dev_segment_partition
));
memproc
::
dealloc
<
MemType
::
CPU
>
((
void
*&
)(
darray
));
#endif
return
0
;
...
...
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