PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
pNeighborDeck.h
Go to the documentation of this file.
1/*
2 * -------------------------------------------
3 * Copyright (c) 2021 - 2026 Prashant K. Jha
4 * -------------------------------------------
5 * PeriDEM https://github.com/prashjha/PeriDEM
6 *
7 * Distributed under the Boost Software License, Version 1.0. (See accompanying
8 * file LICENSE)
9 */
10
11#ifndef INP_PNEIGHBORDECK_H
12#define INP_PNEIGHBORDECK_H
13
14#include "util/io.h"
15#include "deckField.h"
16#include "util/json.h"
17
18namespace inp {
19
24
26 std::string d_updateCriteria;
27
30 double d_sFactor;
31
34
37
41 PNeighborDeck(const json &j = json({}))
42 : d_updateCriteria("simple_all"),
43 d_sFactor(1.),
45 d_nearBdNodesTol(0.5) {
46 readFromJson(j);
47 };
48
52 PNeighborDeck(std::string updateCriteria, double sFactor = 1.,
53 size_t neighUpdateInterval = 1, double nearBdNodesTol = 0.5)
54 : d_updateCriteria(updateCriteria),
55 d_sFactor(sFactor),
56 d_neighUpdateInterval(neighUpdateInterval),
57 d_nearBdNodesTol(nearBdNodesTol) {};
58
65 static const std::vector<Field<PNeighborDeck>> &fields() {
66 static const std::vector<Field<PNeighborDeck>> f = {
67 field(&PNeighborDeck::d_updateCriteria, "Update_Criteria",
68 std::string("simple_all"),
69 "When the contact neighbor list is rebuilt"),
70 field(&PNeighborDeck::d_sFactor, "Search_Factor", 1.,
71 "Search length as a multiple of the largest particle radius"),
73 size_t(1), "Steps between contact neighbor list updates"),
74 field(&PNeighborDeck::d_nearBdNodesTol, "Near_Bd_Nodes_Tol", 0.5,
75 "Depth within which a node counts as near the boundary"),
76 };
77 return f;
78 }
79
85 static json getExampleJson(const json &given = json::object()) {
86 return applyGiven(given, fields());
87 }
88
97 static json getExampleJson(const std::string &) = delete;
99 static json getExampleJson(const char *) = delete;
100
105 void readFromJson(const json &j) {
106 if (j.empty())
107 return;
108 readFields(*this, j, fields());
109 }
110
116 json j = json::object();
117 writeFields(*this, j, fields());
118 return j;
119 }
120
128 std::string printStr(int nt = 0, int lvl = 0) const {
129
130 auto tabS = util::io::getTabS(nt);
131 std::ostringstream oss;
132 oss << tabS << "------- PNeighborDeck --------" << std::endl << std::endl;
133 printFields(*this, oss, fields(), tabS);
134 oss << tabS << std::endl;
135
136 return oss.str();
137 }
138
145 void print(int nt = 0, int lvl = 0) const { std::cout << printStr(nt, lvl); }
146};
147
150} // namespace inp
151
152#endif // INP_PNEIGHBORDECK_H
nlohmann::ordered_json json
Collection of methods and database related to input.
Definition pairForce.h:20
Field< Deck > field(T Deck::*m, std::string key, T def, std::string doc, Accepts< T > accepts={}, std::function< bool(const T &)> emitIf=[](const T &) { return true;})
Declares a field that maps one key to one member.
Definition deckField.h:144
void readFields(Deck &d, const json &j, const std::vector< Field< Deck > > &fs)
Reads every field of the table from the block.
Definition deckField.h:230
void writeFields(const Deck &d, json &j, const std::vector< Field< Deck > > &fs)
Writes every field of the table into the block.
Definition deckField.h:237
void printFields(const Deck &d, std::ostringstream &oss, const std::vector< Field< Deck > > &fs, const std::string &tab="")
Appends every field of the table to a stream.
Definition deckField.h:251
json applyGiven(const json &given, const std::vector< Field< Deck > > &fs, const std::vector< std::string > &extra={})
The default block with the given keys replaced.
Definition deckField.h:443
std::string getTabS(int nt)
Returns tab spaces of a given size.
Definition io.h:82
User-input data for particle neighbor search.
void print(int nt=0, int lvl=0) const
Prints the information about the object.
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
std::string d_updateCriteria
Neighbor search update criteria (if any)
void readFromJson(const json &j)
Reads from json object.
json writeToJson() const
Returns this deck as a JSON object.
double d_nearBdNodesTol
Specify how deep we search for nodes near boundary for contact calculations.
static const std::vector< Field< PNeighborDeck > > & fields()
The fields of this deck, declared once.
static json getExampleJson(const json &given=json::object())
Returns the block with the given fields set.
static json getExampleJson(const char *)=delete
Rejects a value given where a set of named values is expected.
double d_sFactor
Neighbor search factor (search length is factor times biggest radius of particle)
static json getExampleJson(const std::string &)=delete
Rejects a value given where a set of named values is expected.
size_t d_neighUpdateInterval
Neighbor update time interval (for contact)
PNeighborDeck(std::string updateCriteria, double sFactor=1., size_t neighUpdateInterval=1, double nearBdNodesTol=0.5)
Constructor.
PNeighborDeck(const json &j=json({}))
Constructor.