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
03939410
Commit
03939410
authored
1 year ago
by
数学の武士
Browse files
Options
Downloads
Patches
Plain Diff
some bugs fixed
parent
02f256cf
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
main.cpp
+140
-9
140 additions, 9 deletions
main.cpp
mesh/include/mesh.hpp
+1
-2
1 addition, 2 deletions
mesh/include/mesh.hpp
mesh/src/matvec.cpp
+5
-3
5 additions, 3 deletions
mesh/src/matvec.cpp
mesh/src/mesh.cpp
+4
-12
4 additions, 12 deletions
mesh/src/mesh.cpp
with
150 additions
and
26 deletions
main.cpp
+
140
−
9
View file @
03939410
#include
"mesh.hpp"
#include
"TemplateParameters.h"
#include
"MemoryProcessing.h"
#ifdef INCLUDE_CUDA
#include
"MemoryProcessing.cuh"
#endif
using
namespace
icethermo
;
int
main
(
void
)
{
Mesh
<
float
,
MemType
::
GPU
>
mesh1
(
10
,
1.0
f
);
// 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
Mesh
<
float
,
MemType
::
CPU
>
mesh1
(
1.0
f
);
#endif
// how to create cells data (lhs is shared ptr to vector)
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
);
// one can modify cell data
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
printf
(
"%f
\n
"
,
mesh1
.
SubBuffer
[
i
]);
}
#ifdef INCLUDE_CUDA
float
*
farray
;
size_t
farray_size
=
0
;
memproc
::
realloc
<
MemType
::
CPU
>
((
void
*&
)(
farray
),
farray_size
,
mesh1
.
GetCellsNum
()
*
sizeof
(
float
));
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
(
*
cells_temp
)[
0
]
=
1.0
f
;
(
*
cells_temp
)[
1
]
=
2.0
f
;
(
*
cells_temp
)[
2
]
=
3.0
f
;
#endif
// how to create nodes data (lhs is shared ptr to vector)
auto
nodes_k
=
mesh1
.
CreateNodesData
(
"nodes_k"
);
auto
nodes_enthalpy
=
mesh1
.
CreateNodesData
(
"nodes_enthalpy"
,
false
);
// one can modify nodes data
#ifdef INCLUDE_CUDA
memproc
::
realloc
<
MemType
::
CPU
>
((
void
*&
)(
farray
),
farray_size
,
mesh1
.
GetNodesNum
()
*
sizeof
(
float
));
farray
[
0
]
=
-
5.0
f
;
farray
[
mesh1
.
GetNodesNum
()
-
1
]
=
-
3.0
f
;
memproc
::
memcopy
<
MemType
::
GPU
,
MemType
::
CPU
>
((
*
nodes_k
),
farray
,
farray_size
);
#else
(
*
nodes_k
)[
0
]
=
-
5.0
f
;
(
*
nodes_k
)[
mesh1
.
GetNodesNum
()
-
1
]
=
-
3.0
f
;
#endif
// how to create single data
auto
temp_ib
=
mesh1
.
CreateSingleData
(
"temp_ib"
);
auto
temp_is
=
mesh1
.
CreateSingleData
(
"temp_is"
);
// one can modify single data
(
*
temp_ib
)
=
-
1.0
f
;
(
*
temp_is
)
=
2.0
f
;
// one can delete cells, nodes or single data
mesh1
.
DeleteCellsData
(
"cells_enthalpy"
);
mesh1
.
DeleteNodesData
(
"nodes_enthalpy"
);
mesh1
.
DeleteSingleData
(
"temp_is"
);
// its is better to avoid this, but one can get another pointer to created data
auto
another_cells_temp
=
mesh1
.
GetCellsData
(
"cells_temperature"
);
auto
another_nodes_k
=
mesh1
.
GetNodesData
(
"nodes_k"
);
auto
another_temp_ib
=
mesh1
.
GetSingleData
(
"temp_ib"
);
#ifdef INCLUDE_CUDA
memproc
::
realloc
<
MemType
::
CPU
>
((
void
*&
)(
farray
),
farray_size
,
mesh1
.
GetCellsNum
()
*
sizeof
(
float
));
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
));
farray
[
0
]
*=
2.0
f
;
memproc
::
memcopy
<
MemType
::
GPU
,
MemType
::
CPU
>
((
*
another_nodes_k
),
farray
,
farray_size
);
#else
(
*
another_cells_temp
)[
0
]
=
-
5.0
f
;
(
*
another_nodes_k
)[
0
]
*=
2.0
f
;
(
*
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
;
// one could manually mute and unmute variables (muted variables will not be writed to the output)
mesh1
.
MuteCellData
(
"cells_temperature"
);
mesh1
.
UnmuteCellData
(
"cells_temperature"
);
mesh1
.
MuteNodeData
(
"nodes_enthalpy"
);
mesh1
.
UnmuteNodeData
(
"nodes_enthalpy"
);
// one can save mesh to .txt file
mesh1
.
SaveTXT
(
"./mesh"
);
// one can save mesh to .txt file with postfix number (relevant for time series)
mesh1
.
SaveTXT
(
"./mesh"
,
1488
);
// ### examples of another Mesh class constructor ###
// construct uniform mesh with given cells num and total thickness
#ifdef INCLUDE_CUDA
Mesh
<
double
,
MemType
::
GPU
>
mesh2
(
15
,
1.0
);
#else
Mesh
<
double
,
MemType
::
CPU
>
mesh2
(
15
,
1.0
);
#endif
mesh2
.
SaveTXT
(
"./mesh2"
);
// construct arbitrary mesh with given unit segment partition and total thickness
#ifdef INCLUDE_CUDA
double
dsegment_partition
[
2
]
=
{
0.5
,
0.5
};
double
*
dev_segment_partition
;
size_t
dev_segment_partition_size
=
0
;
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
>
mesh3
(
dev_segment_partition
,
2
,
5.0
);
#else
double
dsegment_partition
[
2
]
=
{
0.5
,
0.5
};
Mesh
<
double
,
MemType
::
CPU
>
mesh3
(
dsegment_partition
,
2
,
5.0
);
#endif
mesh3
.
SaveTXT
(
"./mesh3"
);
mesh1
.
SaveTXT
(
"./mesh1"
);
#ifdef INCLUDE_CUDA
memproc
::
dealloc
<
MemType
::
GPU
>
((
void
*&
)(
farray
));
memproc
::
dealloc
<
MemType
::
GPU
>
((
void
*&
)(
dev_segment_partition
));
#endif
return
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
mesh/include/mesh.hpp
+
1
−
2
View file @
03939410
...
...
@@ -96,8 +96,7 @@ namespace icethermo
std
::
map
<
std
::
string
,
std
::
pair
<
std
::
shared_ptr
<
NumType
*>
,
bool
>>
nodes_data
;
std
::
map
<
std
::
string
,
size_t
>
nodes_data_size_t
;
// Check GPU results subtools
public:
// sub-bufer for data output (needs if data on the GPU)
NumType
*
SubBuffer
;
size_t
SubBuffer_size
;
};
...
...
This diff is collapsed.
Click to expand it.
mesh/src/matvec.cpp
+
5
−
3
View file @
03939410
...
...
@@ -20,11 +20,12 @@ namespace icethermo
size_t
cpu_holder_size
=
0
;
memproc
::
realloc
<
MemType
::
CPU
>
((
void
*&
)(
cpu_holder
),
cpu_holder_size
,
size
*
sizeof
(
NumType
));
memproc
::
memcopy
<
MemType
::
CPU
,
MemType
::
CPU
>
(
cpu_holder
,
vec
,
cpu_holder_size
);
memproc
::
memcopy
<
MemType
::
CPU
,
MemType
::
GPU
>
(
cpu_holder
,
vec
,
cpu_holder_size
);
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
accumulate_res
+=
cpu_holder
[
i
];
}
memproc
::
dealloc
<
MemType
::
CPU
>
((
void
*&
)(
cpu_holder
));
...
...
@@ -50,7 +51,7 @@ namespace icethermo
const
int
size
=
end
-
start
;
memproc
::
realloc
<
MemType
::
CPU
>
((
void
*&
)(
cpu_holder
),
cpu_holder_size
,
size
*
sizeof
(
NumType
));
memproc
::
memcopy
<
MemType
::
CPU
,
MemType
::
C
PU
>
(
cpu_holder
,
vec
+
start
,
cpu_holder_size
);
memproc
::
memcopy
<
MemType
::
CPU
,
MemType
::
G
PU
>
(
cpu_holder
,
vec
+
start
,
cpu_holder_size
);
for
(
int
i
=
start
;
i
<
end
;
i
++
)
accumulate_res
+=
cpu_holder
[
i
];
...
...
@@ -99,6 +100,7 @@ namespace icethermo
if
(
memtype
==
MemType
::
GPU
)
{
icethermo_gpu
::
mul_vec
(
vec
,
num
,
size
);
return
;
}
#endif
...
...
This diff is collapsed.
Click to expand it.
mesh/src/mesh.cpp
+
4
−
12
View file @
03939410
...
...
@@ -61,15 +61,11 @@ namespace icethermo
Mesh
<
NumType
,
memtype
>::
Mesh
(
const
NumType
*
unit_segment_decomposition
,
const
int
unit_segment_decomposition_size
,
NumType
thickness
)
{
NumType
sum_decomp
=
sum_vec
<
NumType
,
memtype
>
(
unit_segment_decomposition
,
unit_segment_decomposition_size
);
if
(
std
::
abs
(
sum_decomp
-
1.0
)
>
1e-5
)
{
THERMO_ERR
(
"Unit segment decomposition of length 1.0 should be given!"
);
}
// NumType* thicknesses = unit_segment_decomposition*thickness;
// cells_thickness = std::make_shared<NumType*>(thicknesses);
NumType
*
thicknesses
;
cells_thickness_size_t
=
0
;
...
...
@@ -77,6 +73,9 @@ namespace icethermo
memproc
::
memcopy
<
memtype
,
memtype
>
(
thicknesses
,
unit_segment_decomposition
,
cells_thickness_size_t
);
mul_vec
<
NumType
,
memtype
>
(
thicknesses
,
thickness
,
unit_segment_decomposition_size
);
cells_thickness
=
std
::
make_shared
<
NumType
*>
(
std
::
move
(
thicknesses
));
SubBuffer
=
nullptr
;
SubBuffer_size
=
0
;
}
template
<
typename
NumType
,
MemType
memtype
>
...
...
@@ -137,13 +136,6 @@ namespace icethermo
{
memproc
::
dealloc
<
memtype
>
((
void
*&
)(
*
cells_thickness
.
get
()),
cells_thickness_size_t
);
//for (auto item: this->single_data)
//{
// auto value = item.second;
// delete (value.first).get();
//}
for
(
auto
item
:
this
->
cells_data
)
{
auto
value
=
item
.
second
;
...
...
@@ -173,7 +165,6 @@ namespace icethermo
int
Mesh
<
NumType
,
memtype
>::
GetNodesNum
()
const
{
return
int
(
cells_thickness_size_t
/
sizeof
(
NumType
))
+
1
;
// return cells_thickness->size() + 1;
}
template
<
typename
NumType
,
MemType
memtype
>
...
...
@@ -374,6 +365,7 @@ namespace icethermo
int
count
=
cells_thickness_size_t
/
sizeof
(
NumType
);
PullCPUArray
(
*
cells_thickness
.
get
(),
count
);
*
ofs
<<
"### cells_thickness_array ###
\n
"
;
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
if
(
i
!=
count
-
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