Skip to content

Commit

Permalink
Merge pull request #584 from maxence-wz/582-cast3m-interface-add-expl…
Browse files Browse the repository at this point in the history
…icit-names-and-4-letter-mapping-of-internal-variables-to-the-castem-file

582 cast3m interface add explicit names and 4 letter mapping of internal variables to the castem file
  • Loading branch information
thelfer authored Jun 25, 2024
2 parents d7be1ae + dae214b commit bdd5f27
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 3 deletions.
10 changes: 10 additions & 0 deletions mfront/include/MFront/CastemInterface.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@ namespace mfront {
const VariableDescriptionContainer::const_iterator,
const VariableDescriptionContainer::const_iterator) const;

virtual void writeGibianeMappingComments(
std::ostream &,
const Hypothesis,
const VariableDescriptionContainer &) const;

virtual void writeGibianeMappingComments(
std::ostream &,
const std::pair<std::vector<BehaviourMaterialProperty>,
SupportedTypes::TypeSize> &) const;

virtual void writeGibianeInstruction(std::ostream &,
const std::string &) const;

Expand Down
104 changes: 101 additions & 3 deletions mfront/src/CastemInterface.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2373,6 +2373,92 @@ namespace mfront {
}
}

void CastemInterface::writeGibianeMappingComments(
std::ostream& out,
const Hypothesis h,
const VariableDescriptionContainer& v) const {
for (const auto& pv : v) {
const auto flag = SupportedTypes::getTypeFlag(pv.type);
std::string tmp;
tmp += "** - ";
if (flag == SupportedTypes::SCALAR) {
if (pv.arraySize == 1) {
tmp += pv.getExternalName();
tmp += ": " + treatScalar(pv.name) + "\n";
} else {
for (unsigned short j = 0; j != pv.arraySize;) {
tmp += pv.getExternalName();
tmp += ": " + treatScalar(pv.name, j) + "\n";
}
}
} else if (flag == SupportedTypes::TVECTOR) {
if (pv.arraySize == 1) {
tmp += pv.getExternalName();
tmp += ": " + treatTVector(h, pv.name);
} else {
for (unsigned short j = 0; j != pv.arraySize;) {
tmp += pv.getExternalName();
tmp += ": " + treatTVector(h, pv.name, j) + "\n";
}
}
} else if (flag == SupportedTypes::STENSOR) {
if (pv.arraySize == 1) {
tmp += pv.getExternalName();
tmp += ": " + treatStensor(h, pv.name) + "\n";
} else {
for (unsigned short j = 0; j != pv.arraySize;) {
tmp += pv.getExternalName();
tmp += ": " + treatStensor(h, pv.name, j) + "\n";
}
}
} else if (flag == SupportedTypes::TENSOR) {
if (pv.arraySize == 1) {
tmp += pv.getExternalName();
tmp += ": " + treatTensor(h, pv.name) + "\n";
} else {
for (unsigned short j = 0; j != pv.arraySize;) {
tmp += pv.getExternalName();
tmp += ": " + treatTensor(h, pv.name, j) + "\n";
}
}
} else {
tfel::raise(
"CastemInterface::writeVariableDescriptionContainerToGibiane: "
"internal error, tag unsupported");
}
out << tmp;
}
}

void CastemInterface::writeGibianeMappingComments(
std::ostream& out,
const std::pair<std::vector<BehaviourMaterialProperty>,
SupportedTypes::TypeSize>& mprops) const {
auto throw_if = [](const bool c, const std::string& msg) {
tfel::raise_if(c,
"checkFiniteStrainStrategyDefinitionConsistency "
"(CastemInterface): " +
msg);
};
for (const auto& pm : mprops.first) {
const auto flag = SupportedTypes::getTypeFlag(pm.type);
throw_if(flag != SupportedTypes::SCALAR,
"material properties shall be scalars");
std::string tmp;
tmp += "** - ";
if (pm.arraySize == 1) {
tmp += pm.getExternalName();
tmp += ": " + treatScalar(pm.name) + "\n";
} else {
for (unsigned short j = 0; j != pm.arraySize;) {
tmp += pm.getExternalName();
tmp += treatScalar(pm.name, j) + "\n";
}
}
out << tmp;
}
}

void CastemInterface::writeGibianeInstruction(std::ostream& out,
const std::string& i) const {
std::istringstream in(i);
Expand Down Expand Up @@ -2450,6 +2536,10 @@ namespace mfront {
out << "** 'OPTION' 'DIMENSION' " << getSpaceDimension(h)
<< " 'MODELISER' " << mo.at(h) << " ;\n\n";
}

out << "** List of material properties:\n**\n";
this->writeGibianeMappingComments(out, mprops);

std::ostringstream mcoel;
mcoel << "coel = 'MOTS' ";
for (auto pm = mprops.first.cbegin(); pm != mprops.first.cend();) {
Expand All @@ -2473,7 +2563,11 @@ namespace mfront {
mcoel << ";";
writeGibianeInstruction(out, mcoel.str());
out << '\n';

if (!persistentVarsHolder.empty()) {
out << "** List of state variables:\n**\n";
this->writeGibianeMappingComments(out, persistentVarsHolder);

std::ostringstream mstatev;
mstatev << "statev = 'MOTS' ";
this->writeVariableDescriptionContainerToGibiane(mstatev, h,
Expand All @@ -2482,6 +2576,10 @@ namespace mfront {
writeGibianeInstruction(out, mstatev.str());
out << '\n';
}

std::ostringstream mappingexternalStateVarsComment;
out << "** List of external state variables:\n**\n";
this->writeGibianeMappingComments(out, h, externalStateVarsHolder);
std::ostringstream mparam;
mparam << "params = 'MOTS' 'T'";
if (!externalStateVarsHolder.empty()) {
Expand All @@ -2496,7 +2594,7 @@ namespace mfront {
std::ostringstream mmod;
mmod << "MO = 'MODELISER' v 'MECANIQUE' 'ELASTIQUE' ";
if (bd.getSymmetryType() == mfront::ORTHOTROPIC) {
mmod << "'ORTHOTROPE'";
mmod << "'ORTHOTROPE' ";
}
mmod << nonlin << "\n"
<< "'LIB_LOI' 'lib" + this->getLibraryName(bd) + ".so'\n"
Expand Down Expand Up @@ -2758,8 +2856,8 @@ namespace mfront {
<< "tfel::material::ModellingHypothesisToSpaceDimension<H>;\n";
}
if (h != ModellingHypothesis::UNDEFINEDHYPOTHESIS) {
out << "static " << constexpr_c << " ModellingHypothesis::Hypothesis H = "
<< "ModellingHypothesis::"
out << "static " << constexpr_c
<< " ModellingHypothesis::Hypothesis H = " << "ModellingHypothesis::"
<< ModellingHypothesis::toUpperCaseString(h) << ";\n";
}
if (mb.isModel()) {
Expand Down

0 comments on commit bdd5f27

Please sign in to comment.