Skip to content

Commit 2cee9b1

Browse files
committed
Add option to check scale of material properties when getting values from spatial database.
1 parent 77bfcc8 commit 2cee9b1

16 files changed

+262
-103
lines changed

libsrc/pylith/materials/AuxiliaryFactoryElastic.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pylith::materials::AuxiliaryFactoryElastic::addShearModulus(void) {
5555
description.componentNames[0] = subfieldName;
5656
description.scale = pressureScale;
5757
description.validator = pylith::topology::FieldQuery::validatorNonnegative;
58+
description.validatorTolerance = 25.0;
5859

5960
_field->subfieldAdd(description, getSubfieldDiscretization(subfieldName));
6061
pylith::materials::Query::shearModulusFromVM(subfieldName, this);

libsrc/pylith/materials/AuxiliaryFactoryElasticity.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ pylith::materials::AuxiliaryFactoryElasticity::addBodyForce(void) {
7272
PYLITH_JOURNAL_DEBUG("addBodyForce(void)");
7373

7474
const char* subfieldName = "body_force";
75-
const char* componentNames[3] = { "body_force_x", "body_force_y", "body_force_z" };
75+
const char* componentNames[3] = {
76+
"body_force_x",
77+
"body_force_y",
78+
"body_force_z",
79+
};
7680

7781
const PylithReal forceScale = _normalizer->getPressureScale() / _normalizer->getLengthScale();
7882

libsrc/pylith/materials/AuxiliaryFactoryPoroelastic.cc

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pylith::materials::AuxiliaryFactoryPoroelastic::~AuxiliaryFactoryPoroelastic(voi
3939
// ----------------------------------------------------------------------------
4040
// Add isotropic permeability subfield to auxiliary fields.
4141
void
42-
pylith::materials::AuxiliaryFactoryPoroelastic::addIsotropicPermeability(void) { // isotropicPermeablity
42+
pylith::materials::AuxiliaryFactoryPoroelastic::addIsotropicPermeability(void) {
4343
PYLITH_METHOD_BEGIN;
4444
PYLITH_JOURNAL_DEBUG("addIsotropicPermeability(void)");
4545

@@ -56,7 +56,8 @@ pylith::materials::AuxiliaryFactoryPoroelastic::addIsotropicPermeability(void) {
5656
description.componentNames.resize(1);
5757
description.componentNames[0] = subfieldName;
5858
description.scale = permeabilityScale;
59-
description.validator = NULL;
59+
// description.validator = pylith::topology::FieldQuery::validatorScale;
60+
// description.validatorTolerance = 10.0;
6061

6162
_field->subfieldAdd(description, getSubfieldDiscretization(subfieldName));
6263
this->setSubfieldQuery(subfieldName);
@@ -68,7 +69,7 @@ pylith::materials::AuxiliaryFactoryPoroelastic::addIsotropicPermeability(void) {
6869
// ----------------------------------------------------------------------------
6970
// Add isotropic permeability subfield to auxiliary fields.
7071
void
71-
pylith::materials::AuxiliaryFactoryPoroelastic::addTensorPermeability(void) { // tensorPermeablity
72+
pylith::materials::AuxiliaryFactoryPoroelastic::addTensorPermeability(void) {
7273
PYLITH_METHOD_BEGIN;
7374
PYLITH_JOURNAL_DEBUG("addTensorPermeability(void)");
7475

@@ -95,7 +96,8 @@ pylith::materials::AuxiliaryFactoryPoroelastic::addTensorPermeability(void) { //
9596
description.componentNames[i] = componentNames[i];
9697
} // for
9798
description.scale = permeabilityScale;
98-
description.validator = NULL;
99+
// description.validator = pylith::topology::FieldQuery::validatorScale;
100+
// description.validatorTolerance = 10.0;
99101

100102
_field->subfieldAdd(description, getSubfieldDiscretization(subfieldName));
101103
this->setSubfieldQuery(subfieldName);
@@ -107,7 +109,7 @@ pylith::materials::AuxiliaryFactoryPoroelastic::addTensorPermeability(void) { //
107109
// --------------------------------------------------------------------
108110
// Add drained bulk modulus subfield to auxiliary fields.
109111
void
110-
pylith::materials::AuxiliaryFactoryPoroelastic::addDrainedBulkModulus(void) { // DrainedBulkModulus
112+
pylith::materials::AuxiliaryFactoryPoroelastic::addDrainedBulkModulus(void) {
111113
PYLITH_METHOD_BEGIN;
112114
PYLITH_JOURNAL_DEBUG("addDrainedBulkModulus(void)");
113115

@@ -123,6 +125,7 @@ pylith::materials::AuxiliaryFactoryPoroelastic::addDrainedBulkModulus(void) { //
123125
description.componentNames[0] = subfieldName;
124126
description.scale = pressureScale;
125127
description.validator = pylith::topology::FieldQuery::validatorPositive;
128+
description.validatorTolerance = 25.0;
126129

127130
_field->subfieldAdd(description, getSubfieldDiscretization(subfieldName));
128131
this->setSubfieldQuery(subfieldName);
@@ -134,7 +137,7 @@ pylith::materials::AuxiliaryFactoryPoroelastic::addDrainedBulkModulus(void) { //
134137
// ---------------------------------------------------------------------
135138
// Add biot coefficient subfield to auxiliary fields.
136139
void
137-
pylith::materials::AuxiliaryFactoryPoroelastic::addBiotCoefficient(void) { // biotCoefficient
140+
pylith::materials::AuxiliaryFactoryPoroelastic::addBiotCoefficient(void) {
138141
PYLITH_METHOD_BEGIN;
139142
PYLITH_JOURNAL_DEBUG("addBiotCoefficient(void)");
140143

@@ -149,6 +152,7 @@ pylith::materials::AuxiliaryFactoryPoroelastic::addBiotCoefficient(void) { // bi
149152
description.componentNames[0] = subfieldName;
150153
description.scale = 1.0;
151154
description.validator = pylith::topology::FieldQuery::validatorPositive;
155+
description.validatorTolerance = 10.0;
152156

153157
_field->subfieldAdd(description, getSubfieldDiscretization(subfieldName));
154158
this->setSubfieldQuery(subfieldName);
@@ -160,7 +164,7 @@ pylith::materials::AuxiliaryFactoryPoroelastic::addBiotCoefficient(void) { // bi
160164
// ---------------------------------------------------------------------
161165
// Add biot modulus subfield to auxiliary fields.
162166
void
163-
pylith::materials::AuxiliaryFactoryPoroelastic::addBiotModulus(void) { // biotCoefficient
167+
pylith::materials::AuxiliaryFactoryPoroelastic::addBiotModulus(void) {
164168
PYLITH_METHOD_BEGIN;
165169
PYLITH_JOURNAL_DEBUG("addBiotModulus(void)");
166170

@@ -176,6 +180,7 @@ pylith::materials::AuxiliaryFactoryPoroelastic::addBiotModulus(void) { // biotCo
176180
description.componentNames[0] = subfieldName;
177181
description.scale = pressureScale;
178182
description.validator = pylith::topology::FieldQuery::validatorPositive;
183+
description.validatorTolerance = 25.0;
179184

180185
_field->subfieldAdd(description, getSubfieldDiscretization(subfieldName));
181186
pylith::materials::Query::biotModulusFromInput(subfieldName, this);
@@ -187,7 +192,7 @@ pylith::materials::AuxiliaryFactoryPoroelastic::addBiotModulus(void) { // biotCo
187192
// ----------------------------------------------------------------------
188193
// Add reference stress subfield to auxiliary fields.
189194
void
190-
pylith::materials::AuxiliaryFactoryPoroelastic::addReferenceStress(void) { // referenceStress
195+
pylith::materials::AuxiliaryFactoryPoroelastic::addReferenceStress(void) {
191196
PYLITH_METHOD_BEGIN;
192197
PYLITH_JOURNAL_DEBUG("addReferenceStress(void)");
193198

@@ -225,7 +230,7 @@ pylith::materials::AuxiliaryFactoryPoroelastic::addReferenceStress(void) { // re
225230
// ----------------------------------------------------------------------
226231
// Add reference strain subfield to auxiliary fields.
227232
void
228-
pylith::materials::AuxiliaryFactoryPoroelastic::addReferenceStrain(void) { // addReferenceStrain
233+
pylith::materials::AuxiliaryFactoryPoroelastic::addReferenceStrain(void) {
229234
PYLITH_METHOD_BEGIN;
230235
PYLITH_JOURNAL_DEBUG("addRefrenceStrain(void)");
231236

libsrc/pylith/materials/AuxiliaryFactoryPoroelasticity.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pylith::materials::AuxiliaryFactoryPoroelasticity::addPorosity(void) { // porosi
116116
PYLITH_JOURNAL_DEBUG("addPorosity(void)");
117117

118118
const char* subfieldName = "porosity";
119-
const PylithReal noScale = 1;
119+
const PylithReal noScale = 1.0;
120120

121121
pylith::topology::Field::Description description;
122122
description.label = subfieldName;

libsrc/pylith/materials/AuxiliaryFactoryPoroelasticity.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
#pragma once
1111

1212
#include "pylith/materials/materialsfwd.hh" // forward declarations
13-
#include "pylith/feassemble/AuxiliaryFactory.hh" // ISA AuxiliaryFactory
13+
#include "pylith/materials/AuxiliaryFactoryElasticity.hh" // ISA AuxiliaryFactory
1414

1515
#include "spatialdata/spatialdb/spatialdbfwd.hh" // USES GravityField
1616

17-
class pylith::materials::AuxiliaryFactoryPoroelasticity : public pylith::feassemble::AuxiliaryFactory {
17+
class pylith::materials::AuxiliaryFactoryPoroelasticity : public pylith::materials::AuxiliaryFactoryElasticity {
1818
friend class TestAuxiliaryFactoryPoroelasticity; // unit testing
1919

2020
// PUBLIC METHODS //////////////////////////////////////////////////////////////////////////////////////////////////

libsrc/pylith/materials/AuxiliaryFactoryViscoelastic.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,11 @@ pylith::materials::AuxiliaryFactoryViscoelastic::addShearModulusRatioGeneralized
114114
description.vectorFieldType = pylith::topology::Field::OTHER;
115115
description.numComponents = 3;
116116
description.componentNames.resize(3);
117-
const char* componentNames[3] = { "shear_modulus_ratio_1", "shear_modulus_ratio_2",
118-
"shear_modulus_ratio_3" };
117+
const char* componentNames[3] = {
118+
"shear_modulus_ratio_1",
119+
"shear_modulus_ratio_2",
120+
"shear_modulus_ratio_3",
121+
};
119122
for (int i = 0; i < 3; ++i) {
120123
description.componentNames[i] = componentNames[i];
121124
} // for

libsrc/pylith/materials/Query.cc

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ pylith::materials::_Query::vmToShearModulus(PylithScalar valueSubfield[],
222222

223223
std::ostringstream msg;
224224
if (density <= 0) {
225-
msg << "Found negative density (" << density << ").";
225+
msg << "Found non-positive density (" << density << ").";
226226
} // if
227-
if (vs <= 0) {
227+
if (vs < 0) {
228228
msg << "Found negative shear wave speed (" << vs << ").";
229229
} // if
230230

@@ -257,13 +257,13 @@ pylith::materials::_Query::vmToBulkModulus(PylithScalar valueSubfield[],
257257

258258
std::ostringstream msg;
259259
if (density <= 0) {
260-
msg << "Found nonpositive density (" << density << ").";
260+
msg << "Found non-positive density (" << density << ").";
261261
} // if
262262
if (vs < 0) {
263263
msg << "Found negative shear wave speed (" << vs << ").";
264264
} // if
265265
if (vp <= 0) {
266-
msg << "Found nonpositive dilatational wave speed (" << vp << ").";
266+
msg << "Found non-positive dilatational wave speed (" << vp << ").";
267267
} // if
268268

269269
PYLITH_METHOD_RETURN(msg.str());
@@ -296,13 +296,13 @@ pylith::materials::_Query::vmToMaxwellTime(PylithScalar valueSubfield[],
296296

297297
std::ostringstream msg;
298298
if (density <= 0) {
299-
msg << "Found negative density (" << density << ").";
299+
msg << "Found non-positive density (" << density << ").";
300300
} // if
301301
if (vs <= 0) {
302-
msg << "Found negative shear wave speed (" << vs << ").";
302+
msg << "Found non-positive shear wave speed (" << vs << ").";
303303
} // if
304304
if (viscosity <= 0) {
305-
msg << "Found nonpositive viscosity (" << viscosity << ").";
305+
msg << "Found non-positive viscosity (" << viscosity << ").";
306306
} // if
307307

308308
PYLITH_METHOD_RETURN(msg.str());
@@ -351,28 +351,28 @@ pylith::materials::_Query::vmToGeneralizedMaxwellTimes(PylithScalar valueSubfiel
351351

352352
std::ostringstream msg;
353353
if (density <= 0) {
354-
msg << "Found negative density (" << density << ").";
354+
msg << "Found non-positive density (" << density << ").";
355355
} // if
356356
if (vs <= 0) {
357-
msg << "Found negative shear wave speed (" << vs << ").";
357+
msg << "Found non-positive shear wave speed (" << vs << ").";
358358
} // if
359359
if (viscosity1 <= 0) {
360-
msg << "Found nonpositive viscosity 1 (" << viscosity1 << ").";
360+
msg << "Found non-positive viscosity 1 (" << viscosity1 << ").";
361361
} // if
362362
if (viscosity2 <= 0) {
363-
msg << "Found nonpositive viscosity 2 (" << viscosity2 << ").";
363+
msg << "Found non-positive viscosity 2 (" << viscosity2 << ").";
364364
} // if
365365
if (viscosity3 <= 0) {
366-
msg << "Found nonpositive viscosity 3 (" << viscosity3 << ").";
366+
msg << "Found non-positive viscosity 3 (" << viscosity3 << ").";
367367
} // if
368368
if (shearModulusRatio1 <= 0) {
369-
msg << "Found negative shear modulus ratio 1 (" << shearModulusRatio1 << ").";
369+
msg << "Found non-positive shear modulus ratio 1 (" << shearModulusRatio1 << ").";
370370
} // if
371371
if (shearModulusRatio2 <= 0) {
372-
msg << "Found negative shear modulus ratio 2 (" << shearModulusRatio2 << ").";
372+
msg << "Found non-positive shear modulus ratio 2 (" << shearModulusRatio2 << ").";
373373
} // if
374374
if (shearModulusRatio3 <= 0) {
375-
msg << "Found negative shear modulus ratio 3 (" << shearModulusRatio3 << ").";
375+
msg << "Found non-positive shear modulus ratio 3 (" << shearModulusRatio3 << ").";
376376
} // if
377377

378378
const double ratioSum = shearModulusRatio1 + shearModulusRatio2 + shearModulusRatio3;
@@ -409,13 +409,13 @@ pylith::materials::_Query::vmToGeneralizedMaxwellShearModulusRatios(PylithScalar
409409

410410
std::ostringstream msg;
411411
if (shearModulusRatio1 <= 0) {
412-
msg << "Found negative shear modulus ratio 1 (" << shearModulusRatio1 << ").";
412+
msg << "Found non-positive shear modulus ratio 1 (" << shearModulusRatio1 << ").";
413413
} // if
414414
if (shearModulusRatio2 <= 0) {
415-
msg << "Found negative shear modulus ratio 2 (" << shearModulusRatio2 << ").";
415+
msg << "Found non-positive shear modulus ratio 2 (" << shearModulusRatio2 << ").";
416416
} // if
417417
if (shearModulusRatio3 <= 0) {
418-
msg << "Found negative shear modulus ratio 3 (" << shearModulusRatio3 << ").";
418+
msg << "Found non-positive shear modulus ratio 3 (" << shearModulusRatio3 << ").";
419419
} // if
420420
const double ratioSum = shearModulusRatio1 + shearModulusRatio2 + shearModulusRatio3;
421421
if (ratioSum > 1) {
@@ -498,7 +498,7 @@ pylith::materials::_Query::inputToBiotModulus(PylithScalar valueSubfield[],
498498
msg << "Found negative porosity (" << porosity << ").";
499499
} // if
500500
if (biot_coefficient <= 0) {
501-
msg << "Found negative biot coefficient (" << biot_coefficient << ").";
501+
msg << "Found non-positive biot coefficient (" << biot_coefficient << ").";
502502
} // if
503503

504504
// Debug

libsrc/pylith/topology/FieldBase.hh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ public:
4646
public:
4747

4848
/// Function prototype for validator functions.
49-
typedef const char* (*validatorfn_type)(const PylithReal);
49+
typedef std::string (*validatorfn_type)(const PylithReal /*value */,
50+
const PylithReal /* scale */,
51+
const PylithReal /* tolerance */);
5052

5153
// PUBLIC STRUCTS ///////////////////////////////////////////////////////
5254
public:
@@ -58,6 +60,7 @@ public:
5860
pylith::string_vector componentNames; ///< Names of components.
5961
size_t numComponents; ///< Number of components.
6062
PylithReal scale; ///< Dimension scale associated with values.
63+
PylithReal validatorTolerance; ///< Tolerance relative to scale for validation.
6164
validatorfn_type validator; ///< Validator for values in field;
6265
bool hasHistory; ///< Has subfields with history, i.e., state variables.
6366
size_t historySize; ///< Number of points in time history (currently only).
@@ -68,6 +71,7 @@ public:
6871
vectorFieldType(OTHER),
6972
numComponents(0),
7073
scale(1.0),
74+
validatorTolerance(0.0),
7175
validator(NULL),
7276
hasHistory(false),
7377
historySize(0) {}
@@ -79,6 +83,7 @@ public:
7983
const size_t numComponentsValue=0,
8084
const VectorFieldEnum vectorFieldTypeValue=SCALAR,
8185
const PylithReal scaleValue=1.0,
86+
const PylithReal validatorToleranceValue=0.0,
8287
const validatorfn_type validatorValue=NULL,
8388
bool isFaultOnlyValue=false,
8489
bool hasHistoryValue=false,
@@ -89,6 +94,7 @@ public:
8994
componentNames(componentNamesValue),
9095
numComponents(numComponentsValue),
9196
scale(scaleValue),
97+
validatorTolerance(validatorToleranceValue),
9298
validator(validatorValue),
9399
hasHistory(hasHistoryValue),
94100
historySize(historySizeValue) {}

0 commit comments

Comments
 (0)