Skip to content

Commit

Permalink
[feat] use self-contained json input including mesh data
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Mar 8, 2024
1 parent 10edc27 commit 242ce05
Show file tree
Hide file tree
Showing 9 changed files with 570 additions and 125 deletions.
61 changes: 61 additions & 0 deletions examples/validation/cube2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"Domain": {
"MeshNode": [
[ 0, 0, 0],
[60, 0, 0],
[ 0,60, 0],
[60,60, 0],
[ 0, 0,60],
[60, 0,60],
[ 0,60,60],
[60,60,60]
],
"MeshElem": [
[1, 2, 8, 4, 1],
[1, 3, 4, 8, 1],
[1, 2, 6, 8, 1],
[1, 5, 8, 6, 1],
[1, 3, 8, 7, 1],
[1, 5, 7, 8, 1]
],
"InitElem": 2,
"Media": [
{"mua": 0.00, "mus": 0.0, "g": 1.00, "n": 1.0},
{"mua": 0.005,"mus": 1.0, "g": 0.01, "n": 1.37}
]
},
"Session": {
"Photons": 30000000,
"RNGSeed": 27182818,
"ID": "cube"
},
"Forward": {
"T0": 0.0e+00,
"T1": 5.0e-09,
"Dt": 1.0e-10
},
"Optode": {
"Source": {
"Pos": [30.1, 30.2, 0.0],
"Dir": [0.0, 0.0, 1.0]
},
"Detector": [
{
"Pos": [30.0, 20.0, 0.0],
"R": 1.0
},
{
"Pos": [30.0, 40.0, 0.0],
"R": 1.0
},
{
"Pos": [20.0, 30.0, 0.0],
"R": 1.0
},
{
"Pos": [40.0, 30.0, 0.0],
"R": 1.0
}
]
}
}
54 changes: 54 additions & 0 deletions src/mmc_highorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@

#include <set>
#include <list>
#include <vector>
#include <map>
#include <algorithm>
#include <string.h>

#include "mmc_mesh.h"
#include "mmc_highorder.h"
#include "mmc_utils.h"
Expand All @@ -41,6 +44,8 @@

const int edgepair[TETEDGE][2] = {{0, 1}, {0, 2}, {0, 3}, {1, 2}, {1, 3}, {2, 3}};

const int facelist[4][3] = {{0, 1, 2}, {0, 1, 3}, {0, 2, 3}, {1, 2, 3}};

#ifdef __cplusplus
extern "C"
#endif
Expand Down Expand Up @@ -99,3 +104,52 @@ void mesh_10nodetet(tetmesh* mesh, mcconfig* cfg) {
pos++;
}
}

std::string face_to_string(int a, int b, int c) {
int ar[3];
ar[0] = MIN(MIN(a, b), c);
ar[2] = MAX(MAX(a, b), c);
ar[1] = - ar[0] - ar[2] + a + b + c;

return std::to_string(ar[0]) + "," + std::to_string(ar[1]) + "," + std::to_string(ar[2]);
}

#ifdef __cplusplus
extern "C"
#endif
void mesh_getfacenb(tetmesh* mesh, mcconfig* cfg) {
std::vector<std::string> faces;
std::map<std::string, std::pair<unsigned int, unsigned int>> facenb;

faces.reserve(mesh->ne << 2);

for (int i = 0; i < mesh->ne; i++) {
int* ee = mesh->elem + i * mesh->elemlen;

for (int j = 0; j < 4; j++) {
faces.push_back(face_to_string(ee[facelist[j][0]], ee[facelist[j][1]], ee[facelist[j][2]]));
}
}

for (unsigned int i = 0; i < faces.size(); i++) {
if (facenb.count(faces[i])) {
facenb[faces[i]].second = (i >> 2) + 1;
} else {
facenb[faces[i]] = std::make_pair((i >> 2) + 1, 0);
}
}

if (mesh->facenb) {
free(mesh->facenb);
}

mesh->facenb = (int*)calloc(sizeof(int) * mesh->elemlen, mesh->ne);

for (unsigned int i = 0; i < faces.size(); i++) {
std::pair<unsigned int, unsigned int> item = facenb[faces[i]];

if (item.second != 0) {
mesh->facenb[i] = ((i >> 2) + 1 == item.first ? item.second : item.first);
}
}
}
7 changes: 6 additions & 1 deletion src/mmc_highorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@
#define _MCEXTREME_LOGISTIC_RAND_H

#ifdef __cplusplus
extern "C"
extern "C" {
#endif
void mesh_10nodetet(tetmesh* mesh, mcconfig* cfg);
void mesh_getfacenb(tetmesh* mesh, mcconfig* cfg);

#ifdef __cplusplus
}
#endif

#endif
2 changes: 1 addition & 1 deletion src/mmc_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ int mmc_reset(mcconfig* cfg, tetmesh* mesh, raytracer* tracer) {

int mmc_cleanup(mcconfig* cfg, tetmesh* mesh, raytracer* tracer) {
tracer_clear(tracer);
mesh_clear(mesh);
mesh_clear(mesh, cfg);
mcx_clearcfg(cfg);
return 0;
}
Expand Down
Loading

0 comments on commit 242ce05

Please sign in to comment.