Skip to content

Commit 7c0021d

Browse files
committed
WIP: modular library. Progress: added mesh_gen folder to define Gmsh-based mesh generation for particles; better organization of libraries; test/test_data/peridem/twop_circ/main.cpp implements twop_circ test without needing any input file. Our main goal is to minimize the complex input file preparation. We want to define the problem in a main.cpp file without less efforts. Everytime, we want to create a new simulation, we can either define main.cpp or reuse json file.
1 parent 3af8869 commit 7c0021d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1027
-147
lines changed

CMakeLists.txt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ if(${Enable_Documentation})
150150
find_package(Doxygen)
151151
endif()
152152

153+
# Add Gmsh
154+
find_package(Gmsh REQUIRED)
155+
include_directories(${GMSH_INCLUDE_DIRS})
156+
153157
#----------------------------------#
154158
#<<<<<<<<<< Include directories >>>>>>>>>>#
155159
#----------------------------------#
@@ -167,17 +171,19 @@ include_directories(src)
167171
add_subdirectory(external/)
168172

169173
# PeriDEM sub-directories
170-
add_subdirectory(src/util)
174+
add_subdirectory(src/fe)
175+
add_subdirectory(src/fracture)
171176
add_subdirectory(src/geom)
172-
add_subdirectory(src/rw)
173177
add_subdirectory(src/inp)
174-
add_subdirectory(src/material)
175178
add_subdirectory(src/loading)
176-
add_subdirectory(src/fracture)
177-
add_subdirectory(src/fe)
178-
add_subdirectory(src/particle)
179-
add_subdirectory(src/nsearch)
179+
add_subdirectory(src/material)
180+
add_subdirectory(src/mesh)
181+
add_subdirectory(src/mesh_gen)
180182
add_subdirectory(src/model)
183+
add_subdirectory(src/nsearch)
184+
add_subdirectory(src/particle)
185+
add_subdirectory(src/rw)
186+
add_subdirectory(src/util)
181187

182188
# test directory
183189
if(${Enable_Tests})

apps/example-modular/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,15 @@ int main(int argc, char *argv[]) {
216216
pGenJson["Data"]["N"] = 3; // three particles
217217

218218
// p1
219-
pGenJson["Data"]["0"] = {{"x", 0.}, {"y", 0.}, {"z", 0.}, {"o", 0.}, {"s", 1.},
219+
pGenJson["Data"]["0"] = {{"x", 0.}, {"y", 0.}, {"z", 0.}, {"theta", 0.}, {"s", 1.},
220220
{"geom_id", 0}, {"mat_id", 0}, {"contact_id", 0}};
221221

222222
// p1
223-
pGenJson["Data"]["1"] = {{"x", 0.}, {"y", 0.}, {"z", 0.}, {"o", 0.}, {"s", 1.},
223+
pGenJson["Data"]["1"] = {{"x", 0.}, {"y", 0.}, {"z", 0.}, {"theta", 0.}, {"s", 1.},
224224
{"geom_id", 1}, {"mat_id", 1}, {"contact_id", 1}};
225225

226226
// p1
227-
pGenJson["Data"]["2"] = {{"x", 0.}, {"y", 0.}, {"z", 0.}, {"o", 0.}, {"s", 1.},
227+
pGenJson["Data"]["2"] = {{"x", 0.}, {"y", 0.}, {"z", 0.}, {"theta", 0.}, {"s", 1.},
228228
{"geom_id", 2}, {"mat_id", 1}, {"contact_id", 1}};
229229

230230
// add to json

apps/peridynamics/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "rw/vtkParticleWriter.h"
3333
#include "rw/vtkParticleReader.h"
3434
#include "fe/elemIncludes.h"
35-
#include "fe/meshUtil.h"
35+
#include "mesh/meshUtil.h"
3636

3737
#include <format>
3838
#include <print>

apps/twoparticle_demo/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "rw/vtkParticleWriter.h"
2929
#include "rw/vtkParticleReader.h"
3030
#include "fe/elemIncludes.h"
31-
#include "fe/meshUtil.h"
31+
#include "mesh/meshUtil.h"
3232

3333
#include <format>
3434
#include <fstream>

cmake/FindGmsh.cmake

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# -------------------------------------------
2+
# Copyright (c) 2021 - 2024 Prashant K. Jha
3+
# -------------------------------------------
4+
# PeriDEM https://github.com/prashjha/PeriDEM
5+
#
6+
# Distributed under the Boost Software License, Version 1.0. (See accompanying
7+
# file LICENSE)
8+
9+
# Find Gmsh
10+
#
11+
# This sets the following variables:
12+
# GMSH_FOUND - True if Gmsh was found.
13+
# GMSH_INCLUDE_DIRS - Directories containing the Gmsh include files.
14+
# GMSH_LIBRARIES - Libraries needed to use Gmsh.
15+
# GMSH_VERSION - The version of Gmsh found.
16+
17+
find_path(GMSH_INCLUDE_DIR
18+
NAMES gmsh.h
19+
PATHS
20+
${GMSH_DIR}/include
21+
$ENV{GMSH_DIR}/include
22+
/usr/include
23+
/usr/local/include
24+
/opt/local/include
25+
)
26+
27+
find_library(GMSH_LIBRARY
28+
NAMES gmsh libgmsh
29+
PATHS
30+
${GMSH_DIR}/lib
31+
${GMSH_DIR}/lib64
32+
$ENV{GMSH_DIR}/lib
33+
$ENV{GMSH_DIR}/lib64
34+
/usr/lib
35+
/usr/lib64
36+
/usr/local/lib
37+
/usr/local/lib64
38+
/opt/local/lib
39+
)
40+
41+
# Try to find Gmsh version
42+
if(GMSH_INCLUDE_DIR AND EXISTS "${GMSH_INCLUDE_DIR}/gmsh.h")
43+
file(STRINGS "${GMSH_INCLUDE_DIR}/gmsh.h" gmsh_version_str
44+
REGEX "^#define[\t ]+GMSH_VERSION[\t ]+\".*\"")
45+
46+
string(REGEX REPLACE "^#define[\t ]+GMSH_VERSION[\t ]+\"([^\"]*)\".*" "\\1"
47+
GMSH_VERSION "${gmsh_version_str}")
48+
unset(gmsh_version_str)
49+
endif()
50+
51+
include(FindPackageHandleStandardArgs)
52+
find_package_handle_standard_args(Gmsh
53+
REQUIRED_VARS
54+
GMSH_LIBRARY
55+
GMSH_INCLUDE_DIR
56+
VERSION_VAR
57+
GMSH_VERSION
58+
)
59+
60+
if(GMSH_FOUND)
61+
set(GMSH_LIBRARIES ${GMSH_LIBRARY})
62+
set(GMSH_INCLUDE_DIRS ${GMSH_INCLUDE_DIR})
63+
endif()
64+
65+
mark_as_advanced(
66+
GMSH_INCLUDE_DIR
67+
GMSH_LIBRARY
68+
)

src/fe/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
AUX_SOURCE_DIRECTORY(./ SOURCES)
1010

11-
add_library(FE ${SOURCES}
12-
elemIncludes.h)
11+
add_library(FE ${SOURCES})
1312

14-
target_link_libraries(FE PUBLIC Util RW ${METIS_LIB})
13+
target_link_libraries(FE PUBLIC
14+
Util
15+
Geom)

src/inp/input.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* *
2727
* Each deck is unique and is designed to initialize the higher level object
2828
* associated to it without needing information from other decks. For example,
29-
* fe::Mesh is initialized by inp::MeshDeck.
29+
* mesh::Mesh is initialized by inp::MeshDeck.
3030
*
3131
* The namespace consists of Input and Policy member classes. Input class is
3232
* the main class responsible of reading input data into various decks.

src/loading/particleFLoading.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void loading::ParticleFLoading::apply(const double &time,
4747
continue;
4848

4949
// get bounding box (quite possibly be generic)
50-
auto reg_box = bc.d_regionGeomData.d_geom_p->box();
50+
auto reg_box = bc.d_regionGeomData.d_geom_p == nullptr ? std::pair<util::Point, util::Point>(util::Point(), util::Point()) : bc.d_regionGeomData.d_geom_p->box();
5151

5252
// for (size_t i = 0; i < particle->getNumNodes(); i++) {
5353
tf::Executor executor(util::parallel::getNThreads());

src/loading/particleIC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void loading::applyIC(particle::BaseParticle *particle, const std::vector<inp::B
2828
continue;
2929

3030
// get bounding box (quite possibly be generic)
31-
auto reg_box = bc.d_regionGeomData.d_geom_p->box();
31+
auto reg_box = bc.d_regionGeomData.d_geom_p == nullptr ? std::pair<util::Point, util::Point>(util::Point(), util::Point()) : bc.d_regionGeomData.d_geom_p->box();
3232

3333
tf::Executor executor(util::parallel::getNThreads());
3434
tf::Taskflow taskflow;

src/loading/particleULoading.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,16 @@ void loading::ParticleULoading::apply(const double &time,
5858
// get alias for bc data
5959
const auto &bc = d_bcData[s];
6060

61-
// if this is zero displacement condition, and if we have already applied
62-
// displacement then do not need to reapply this
63-
if (bc.d_isDisplacementZero && d_pZeroDisplacementApplied[s])
64-
continue;
65-
66-
// set to true so that next time this is not called
61+
// if this is zero displacement condition, we do not apply displacement
6762
if (bc.d_isDisplacementZero)
68-
d_pZeroDisplacementApplied[s] = true;
63+
continue;
6964

7065
// check if we need to process this particle
7166
if (!needToProcessParticle(particle->getId(), bc))
7267
continue;
7368

7469
// get bounding box (quite possibly be generic)
75-
auto reg_box = bc.d_regionGeomData.d_geom_p->box();
70+
auto reg_box = bc.d_regionGeomData.d_geom_p == nullptr ? std::pair<util::Point, util::Point>(util::Point(), util::Point()) : bc.d_regionGeomData.d_geom_p->box();
7671

7772
// for (size_t i = 0; i < particle->getNumNodes(); i++) {
7873
tf::Executor executor(util::parallel::getNThreads());

0 commit comments

Comments
 (0)