Skip to content

Commit

Permalink
add field.setconstraint flavor
Browse files Browse the repository at this point in the history
  • Loading branch information
halbux committed Nov 18, 2021
1 parent dd4fddb commit 90ef7cb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
3 changes: 1 addition & 2 deletions examples/magnetodynamics-av-induction-3d/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ int main(void)
// Also ground v on face 'vout':
v.setconstraint(vout);
// Set v to 1V on face 'vin' for the in-phase component and to 0 for the quadrature component:
v.harmonic(2).setconstraint(vin, 1);
v.harmonic(3).setconstraint(vin);
v.setconstraint(vin, {1,0});

// Define the weak magnetodynamic formulation:
formulation magdyn;
Expand Down
32 changes: 32 additions & 0 deletions src/field/field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,38 @@ void field::setconstraint(int physreg, expression meshdeform, expression input,
rawfieldptr->setdisjregconstraint(physreg, -1, &meshdeform, input, extraintegrationdegree);
}

void field::setconstraint(int physreg, std::vector<expression> input, int extraintegrationdegree)
{
errorifpointerisnull();
universe::getrawmesh()->getphysicalregions()->errorundefined({physreg});

std::vector<int> harms = rawfieldptr->getharmonics();
if (input.size() != harms.size())
{
std::cout << "Error in 'field' object: expected an expression vector of length " << harms.size() << " to set the field constraint" << std::endl;
abort();
}

for (int i = 0; i < harms.size(); i++)
rawfieldptr->harmonic(harms[i])->setdisjregconstraint(physreg, -1, NULL, input[i], extraintegrationdegree);
}

void field::setconstraint(int physreg, expression meshdeform, std::vector<expression> input, int extraintegrationdegree)
{
errorifpointerisnull();
universe::getrawmesh()->getphysicalregions()->errorundefined({physreg});

std::vector<int> harms = rawfieldptr->getharmonics();
if (input.size() != harms.size())
{
std::cout << "Error in 'field' object: expected an expression vector of length " << harms.size() << " to set the field constraint" << std::endl;
abort();
}

for (int i = 0; i < harms.size(); i++)
rawfieldptr->harmonic(harms[i])->setdisjregconstraint(physreg, -1, &meshdeform, input[i], extraintegrationdegree);
}

void field::setconstraint(int physreg, int numfftharms, expression input, int extraintegrationdegree)
{
errorifpointerisnull();
Expand Down
3 changes: 3 additions & 0 deletions src/field/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class field
void setconstraint(int physreg, expression input, int extraintegrationdegree = 0);
// The 'input' expression is evaluated on the mesh deformed by 'meshdeform':
void setconstraint(int physreg, expression meshdeform, expression input, int extraintegrationdegree = 0);
// Set a constraint on each harmonic:
void setconstraint(int physreg, std::vector<expression> input, int extraintegrationdegree = 0);
void setconstraint(int physreg, expression meshdeform, std::vector<expression> input, int extraintegrationdegree = 0);
// An FFT is used to project the 'input' expression:
void setconstraint(int physreg, int numfftharms, expression input, int extraintegrationdegree = 0);
void setconstraint(int physreg, int numfftharms, expression meshdeform, expression input, int extraintegrationdegree = 0);
Expand Down

0 comments on commit 90ef7cb

Please sign in to comment.